svn commit: r360600 - head/sys/cam/nvme

Warner Losh imp at FreeBSD.org
Sun May 3 04:22:27 UTC 2020


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:


More information about the svn-src-all mailing list