Module Name:    src
Committed By:   ad
Date:           Mon May 25 19:29:09 UTC 2020

Modified Files:
        src/sys/uvm: uvm_bio.c

Log Message:
ubc_uiomove_direct(): if UBC_FAULTBUSY, the left-over portion of the final
page needs to be zeroed.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/uvm/uvm_bio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_bio.c
diff -u src/sys/uvm/uvm_bio.c:1.116 src/sys/uvm/uvm_bio.c:1.117
--- src/sys/uvm/uvm_bio.c:1.116	Sun May 24 20:05:53 2020
+++ src/sys/uvm/uvm_bio.c	Mon May 25 19:29:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.116 2020/05/24 20:05:53 ad Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.117 2020/05/25 19:29:08 ad Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.116 2020/05/24 20:05:53 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.117 2020/05/25 19:29:08 ad Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -997,22 +997,40 @@ ubc_uiomove_direct(struct uvm_object *uo
 			error = uvm_direct_process(pgs, npages, off, bytelen,
 			    ubc_uiomove_process, uio);
 		}
-		if (error != 0 && overwrite) {
+
+		if (overwrite) {
+			voff_t endoff;
+
 			/*
-			 * if we haven't initialized the pages yet,
-			 * do it now.  it's safe to use memset here
-			 * because we just mapped the pages above.
+			 * if we haven't initialized the pages yet due to an
+			 * error above, do it now.
 			 */
-			printf("%s: error=%d\n", __func__, error);
-			(void) uvm_direct_process(pgs, npages, off, bytelen,
-			    ubc_zerorange_process, NULL);
+			if (error != 0) {
+				printf("%s: error=%d\n", __func__, error);
+				(void) uvm_direct_process(pgs, npages, off,
+				    bytelen, ubc_zerorange_process, NULL);
+			}
+
+			off += bytelen;
+			todo -= bytelen;
+			endoff = off & (PAGE_SIZE - 1);
+
+			/*
+			 * zero out the remaining portion of the final page
+			 * (if any).
+			 */
+			if (todo == 0 && endoff != 0) {
+				vsize_t zlen = PAGE_SIZE - endoff;
+				(void) uvm_direct_process(pgs + npages - 1, 1,
+				    off, zlen, ubc_zerorange_process, NULL);
+			}
+		} else {
+			off += bytelen;
+			todo -= bytelen;
 		}
 
 		ubc_direct_release(uobj, flags, pgs, npages);
 
-		off += bytelen;
-		todo -= bytelen;
-
 		if (error != 0 && ISSET(flags, UBC_PARTIALOK)) {
 			break;
 		}

Reply via email to