Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/tls-maxphys]: src/sys/uvm Fix panic "bad chunksize ..." in read-ahead code:



details:   https://anonhg.NetBSD.org/src/rev/01e97a009acf
branches:  tls-maxphys
changeset: 852925:01e97a009acf
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Tue Oct 09 20:07:28 2012 +0000

description:
Fix panic "bad chunksize ..." in read-ahead code:
- off comes from the pager, so should already be page-aligned.
  KASSERT() that it is, and remove the off = trunc_page(off)
- as off is not changed any more, the size of the transfer is chunksize.
  Don't compute bytelen any more,  which is what required chunksize
  to be a power of 2. KASSERT() that chunksize is a multiple of page size.

diffstat:

 sys/uvm/uvm_readahead.c |  30 +++++++++++++-----------------
 1 files changed, 13 insertions(+), 17 deletions(-)

diffs (76 lines):

diff -r de5a2079f36d -r 01e97a009acf sys/uvm/uvm_readahead.c
--- a/sys/uvm/uvm_readahead.c   Tue Oct 09 13:36:04 2012 +0000
+++ b/sys/uvm/uvm_readahead.c   Tue Oct 09 20:07:28 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_readahead.c,v 1.8.12.1 2012/09/12 06:15:36 tls Exp $       */
+/*     $NetBSD: uvm_readahead.c,v 1.8.12.2 2012/10/09 20:07:28 bouyer Exp $    */
 
 /*-
  * Copyright (c)2003, 2005, 2009 YAMAMOTO Takashi,
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_readahead.c,v 1.8.12.1 2012/09/12 06:15:36 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_readahead.c,v 1.8.12.2 2012/10/09 20:07:28 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/pool.h>
@@ -109,30 +109,23 @@
 
        DPRINTF(("%s: uobj=%p, off=%" PRIu64 ", endoff=%" PRIu64 "\n",
            __func__, uobj, off, endoff));
-       off = trunc_page(off);
+
+       KASSERT((off & (PAGE_SIZE - 1)) == 0);
+       KASSERT((chunksz & (PAGE_SIZE - 1)) == 0);
        while (off < endoff) {
                const size_t chunksize = MIN(chunksz, round_page(sz));
                int error;
                size_t donebytes;
                int npages;
                int orignpages;
-               size_t bytelen;
 
-               if ((chunksize & (chunksize - 1)) != 0) {
+               if ((chunksize & (PAGE_SIZE - 1)) != 0) {
                    panic("bad chunksize %d, iochunk %d, request size %d",
                          (int)chunksize, (int)chunksz, (int)sz);
                }
-               /* KASSERT((chunksize & (chunksize - 1)) == 0); */
+               /* KASSERT((chunksize & (PAGE_SIZE - 1)) == 0); */
                KASSERT((off & PAGE_MASK) == 0);
-               bytelen = ((off + chunksize) & -(off_t)chunksize) - off;
-               if ((bytelen & PAGE_MASK) != 0) {
-                       panic("bad bytelen %d with off %d, chunksize %d"
-                             "(iochunk %d, sz %d)",
-                             (int)bytelen, (int)off, (int)chunksize,
-                             (int)chunksz, (int)sz);
-               }
-               KASSERT((bytelen & PAGE_MASK) == 0);
-               npages = orignpages = bytelen >> PAGE_SHIFT;
+               npages = orignpages = chunksize >> PAGE_SHIFT;
                KASSERT(npages != 0);
 
                /*
@@ -142,8 +135,8 @@
                mutex_enter(uobj->vmobjlock);
                error = (*uobj->pgops->pgo_get)(uobj, off, NULL,
                    &npages, 0, VM_PROT_READ, UVM_ADV_RANDOM, 0);
-               DPRINTF(("%s:  off=%" PRIu64 ", bytelen=%zu -> %d\n",
-                   __func__, off, bytelen, error));
+               DPRINTF(("%s:  off=%" PRIu64 ", chunksize=%zu -> %d\n",
+                   __func__, off, chunksize, error));
                if (error != 0 && error != EBUSY) {
                        if (error != EINVAL) { /* maybe past EOF */
                                DPRINTF(("%s: error=%d\n", __func__, error));
@@ -204,6 +197,9 @@
 
        KASSERT(mutex_owned(uobj->vmobjlock));
 
+       KASSERT((reqoff & (PAGE_SIZE - 1)) == 0);
+       KASSERT((reqsize & (PAGE_SIZE - 1)) == 0);
+
        if (ra == NULL || advice == UVM_ADV_RANDOM) {
                return;
        }



Home | Main Index | Thread Index | Old Index