svn commit: r356390 - stable/12/sys/cam

Alexander Motin mav at FreeBSD.org
Mon Jan 6 01:12:16 UTC 2020


Author: mav
Date: Mon Jan  6 01:12:15 2020
New Revision: 356390
URL: https://svnweb.freebsd.org/changeset/base/356390

Log:
  MFC r356042: Make pass(4) handle misaligned buffers of MAXPHYS size.
  
  Since we are already using malloc()+copyin()/copyout() for smaller data
  blocks, and since new asynchronous API does it always, I see no reason
  to keep this ugly artificial size/alignment limitation in old API.
  
  Tape applications suffer enough from the MAXPHYS limitations by itself,
  and additional alignment requirement, often halving effectively usable
  block size, does not help.
  
  It would be good to use unmapped I/O here instead, but it require some
  HBA drivers polishing first to support non-BIO unmapped buffers.

Modified:
  stable/12/sys/cam/cam_periph.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/cam/cam_periph.c
==============================================================================
--- stable/12/sys/cam/cam_periph.c	Sun Jan  5 22:54:25 2020	(r356389)
+++ stable/12/sys/cam/cam_periph.c	Mon Jan  6 01:12:15 2020	(r356390)
@@ -786,6 +786,7 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_ma
 	u_int8_t **data_ptrs[CAM_PERIPH_MAXMAPS];
 	u_int32_t lengths[CAM_PERIPH_MAXMAPS];
 	u_int32_t dirs[CAM_PERIPH_MAXMAPS];
+	bool misaligned[CAM_PERIPH_MAXMAPS];
 
 	bzero(mapinfo, sizeof(*mapinfo));
 	if (maxmap == 0)
@@ -897,6 +898,12 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_ma
 	 * have to unmap any previously mapped buffers.
 	 */
 	for (i = 0; i < numbufs; i++) {
+		if (lengths[i] > maxmap) {
+			printf("cam_periph_mapmem: attempt to map %lu bytes, "
+			       "which is greater than %lu\n",
+			       (long)(lengths[i]), (u_long)maxmap);
+			return (E2BIG);
+		}
 
 		/*
 		 * The userland data pointer passed in may not be page
@@ -906,15 +913,8 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_ma
 		 * whatever extra space is necessary to make it to the page
 		 * boundary.
 		 */
-		if ((lengths[i] +
-		    (((vm_offset_t)(*data_ptrs[i])) & PAGE_MASK)) > maxmap){
-			printf("cam_periph_mapmem: attempt to map %lu bytes, "
-			       "which is greater than %lu\n",
-			       (long)(lengths[i] +
-			       (((vm_offset_t)(*data_ptrs[i])) & PAGE_MASK)),
-			       (u_long)maxmap);
-			return(E2BIG);
-		}
+		misaligned[i] = (lengths[i] +
+		    (((vm_offset_t)(*data_ptrs[i])) & PAGE_MASK) > MAXPHYS);
 	}
 
 	/*
@@ -938,7 +938,7 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_ma
 		 * small allocations malloc is backed by UMA, and so much
 		 * cheaper on SMP systems.
 		 */
-		if (lengths[i] <= periph_mapmem_thresh &&
+		if ((lengths[i] <= periph_mapmem_thresh || misaligned[i]) &&
 		    ccb->ccb_h.func_code != XPT_MMC_IO) {
 			*data_ptrs[i] = malloc(lengths[i], M_CAMPERIPH,
 			    M_WAITOK);


More information about the svn-src-all mailing list