Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/xen/xen fix calculation of remaining bytes in xbd_d...



details:   https://anonhg.NetBSD.org/src/rev/2c04738b35ce
branches:  trunk
changeset: 971249:2c04738b35ce
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sun Apr 19 16:45:08 2020 +0000

description:
fix calculation of remaining bytes in xbd_diskstart_submit() for second
part of exactly I/O over 32KB when the remaining size was less than 1 page,
loop just finished without filling the last segment

triggered by anita run by Manuel

diffstat:

 sys/arch/xen/xen/xbd_xenbus.c |  13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diffs (76 lines):

diff -r 41840e5f2e37 -r 2c04738b35ce sys/arch/xen/xen/xbd_xenbus.c
--- a/sys/arch/xen/xen/xbd_xenbus.c     Sun Apr 19 15:58:53 2020 +0000
+++ b/sys/arch/xen/xen/xbd_xenbus.c     Sun Apr 19 16:45:08 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: xbd_xenbus.c,v 1.120 2020/04/18 23:24:49 jdolecek Exp $      */
+/*      $NetBSD: xbd_xenbus.c,v 1.121 2020/04/19 16:45:08 jdolecek Exp $      */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.120 2020/04/18 23:24:49 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.121 2020/04/19 16:45:08 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -850,6 +850,7 @@
                if (bp->b_error == 0)
                        bp->b_resid = 0;
 
+               KASSERT(xbdreq->req_dmamap->dm_nsegs > 0);
                for (seg = 0; seg < xbdreq->req_dmamap->dm_nsegs; seg++) {
                        /*
                         * We are not allowing persistent mappings, so
@@ -1045,6 +1046,7 @@
                mutex_enter(&sc->sc_lock);
                while ((xbdreq = SLIST_FIRST(&sc->sc_xbdreq_head)) == NULL)
                        cv_wait(&sc->sc_req_cv, &sc->sc_lock);
+               KASSERT(!RING_FULL(&sc->sc_ring));
 
                SLIST_REMOVE_HEAD(&sc->sc_xbdreq_head, req_next);
                req = RING_GET_REQUEST(&sc->sc_ring,
@@ -1139,6 +1141,7 @@
                error = EAGAIN;
                goto out;
        }
+       KASSERT(!RING_FULL(&sc->sc_ring));
 
        if ((sc->sc_features & BLKIF_FEATURE_INDIRECT) == 0
            && bp->b_bcount > XBD_MAX_CHUNK) {
@@ -1170,6 +1173,8 @@
                error = EINVAL;
                goto out;
        }
+       KASSERTMSG(xbdreq->req_dmamap->dm_nsegs > 0,
+           "dm_nsegs == 0 with bcount %d", bp->b_bcount);
 
        for (int seg = 0; seg < xbdreq->req_dmamap->dm_nsegs; seg++) {
                KASSERT(seg < __arraycount(xbdreq->req_gntref));
@@ -1212,6 +1217,7 @@
            bp, 0, xbdreq->req_dmamap, xbdreq->req_gntref);
 
        if (bp->b_bcount > XBD_MAX_CHUNK) {
+               KASSERT(!RING_FULL(&sc->sc_ring));
                struct xbd_req *xbdreq2 = SLIST_FIRST(&sc->sc_xbdreq_head);
                KASSERT(xbdreq2 != NULL); /* Checked earlier */
                SLIST_REMOVE_HEAD(&sc->sc_xbdreq_head, req_next);
@@ -1258,7 +1264,7 @@
                bus_dma_segment_t *ds = &dmamap->dm_segs[dmaseg];
 
                ma = ds->ds_addr;
-               nbytes = imin(ds->ds_len, size);
+               nbytes = ds->ds_len;
 
                if (start > 0) {
                        if (start >= nbytes) {
@@ -1285,6 +1291,7 @@
 
                reqseg->gref = gntref[dmaseg];
        }
+       KASSERT(segidx > 0);
        req->nr_segments = segidx;
        sc->sc_ring.req_prod_pvt++;
 }



Home | Main Index | Thread Index | Old Index