Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 May 2020 04:22:27 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r360600 - head/sys/cam/nvme
Message-ID:  <202005030422.0434MRLN055619@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Sun May  3 04:22:27 2020
New Revision: 360600
URL: https://svnweb.freebsd.org/changeset/base/360600

Log:
  We need to hold the periph lock when we release the ccb (and when we
  run it). Make sure that we do. Simplify the flow a bit, and fix a
  comment since we do need to do these things.
  
  Noticed by: cperciva (not sure why my invariants kernel didn't trigger)

Modified:
  head/sys/cam/nvme/nvme_da.c

Modified: head/sys/cam/nvme/nvme_da.c
==============================================================================
--- head/sys/cam/nvme/nvme_da.c	Sun May  3 04:03:05 2020	(r360599)
+++ head/sys/cam/nvme/nvme_da.c	Sun May  3 04:22:27 2020	(r360600)
@@ -426,26 +426,26 @@ ndaioctl(struct disk *dp, u_long cmd, void *data, int 
 		 */
 		memset(&mapinfo, 0, sizeof(mapinfo));
 		error = cam_periph_mapmem(ccb, &mapinfo, maxmap);
-		if (error) {
-			xpt_release_ccb(ccb);
-			return (error);
-		}
+		if (error)
+			goto out;
 
 		/*
-		 * Lock the periph and run the command. XXX do we need
-		 * to lock the periph?
+		 * Lock the periph and run the command.
 		 */
 		cam_periph_lock(periph);
-		cam_periph_runccb(ccb, NULL, CAM_RETRY_SELTO, SF_RETRY_UA | SF_NO_PRINT,
-		    NULL);
-		cam_periph_unlock(periph);
+		cam_periph_runccb(ccb, NULL, CAM_RETRY_SELTO,
+		    SF_RETRY_UA | SF_NO_PRINT, NULL);
 
 		/*
 		 * Tear down mapping and return status.
 		 */
+		cam_periph_unlock(periph);
 		cam_periph_unmapmem(ccb, &mapinfo);
 		error = (ccb->ccb_h.status == CAM_REQ_CMP) ? 0 : EIO;
+out:
+		cam_periph_lock(periph);
 		xpt_release_ccb(ccb);
+		cam_periph_unlock(periph);
 		return (error);
 	}
 	default:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005030422.0434MRLN055619>