Thu Apr 16 09:51:40 2020 UTC ()
when checking for physio request check for B_PHYS in b_flags rather
than an internal field, so this works when the original buf is
wrapped by another one by e.g. dk(4)

fixes misfired assert when doing newfs on a wedge, reported by Manuel Bouyer


(jdolecek)
diff -r1.114 -r1.115 src/sys/arch/xen/xen/xbd_xenbus.c

cvs diff -r1.114 -r1.115 src/sys/arch/xen/xen/xbd_xenbus.c (expand / switch to unified diff)

--- src/sys/arch/xen/xen/xbd_xenbus.c 2020/04/15 10:16:47 1.114
+++ src/sys/arch/xen/xen/xbd_xenbus.c 2020/04/16 09:51:40 1.115
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: xbd_xenbus.c,v 1.114 2020/04/15 10:16:47 jdolecek Exp $ */ 1/* $NetBSD: xbd_xenbus.c,v 1.115 2020/04/16 09:51:40 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Manuel Bouyer. 4 * Copyright (c) 2006 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -40,27 +40,27 @@ @@ -40,27 +40,27 @@
40 * - initiate request: xbdread/write/open/ioctl/.. 40 * - initiate request: xbdread/write/open/ioctl/..
41 * - depending on operation, it is handled directly by disk(9) subsystem or 41 * - depending on operation, it is handled directly by disk(9) subsystem or
42 * goes through physio(9) first. 42 * goes through physio(9) first.
43 * - the request is ultimately processed by xbd_diskstart() that prepares the 43 * - the request is ultimately processed by xbd_diskstart() that prepares the
44 * xbd requests, post them in the ring I/O queue, then signal the backend. 44 * xbd requests, post them in the ring I/O queue, then signal the backend.
45 * 45 *
46 * When a response is available in the queue, the backend signals the frontend 46 * When a response is available in the queue, the backend signals the frontend
47 * via its event channel. This triggers xbd_handler(), which will link back 47 * via its event channel. This triggers xbd_handler(), which will link back
48 * the response to its request through the request ID, and mark the I/O as 48 * the response to its request through the request ID, and mark the I/O as
49 * completed. 49 * completed.
50 */ 50 */
51 51
52#include <sys/cdefs.h> 52#include <sys/cdefs.h>
53__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.114 2020/04/15 10:16:47 jdolecek Exp $"); 53__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.115 2020/04/16 09:51:40 jdolecek Exp $");
54 54
55#include "opt_xen.h" 55#include "opt_xen.h"
56 56
57 57
58#include <sys/param.h> 58#include <sys/param.h>
59#include <sys/buf.h> 59#include <sys/buf.h>
60#include <sys/bufq.h> 60#include <sys/bufq.h>
61#include <sys/device.h> 61#include <sys/device.h>
62#include <sys/disk.h> 62#include <sys/disk.h>
63#include <sys/disklabel.h> 63#include <sys/disklabel.h>
64#include <sys/conf.h> 64#include <sys/conf.h>
65#include <sys/fcntl.h> 65#include <sys/fcntl.h>
66#include <sys/kernel.h> 66#include <sys/kernel.h>
@@ -1197,28 +1197,31 @@ xbd_diskstart_submit(struct xbd_xenbus_s @@ -1197,28 +1197,31 @@ xbd_diskstart_submit(struct xbd_xenbus_s
1197 reqseg->last_sect = first_sect + nsects - 1; 1197 reqseg->last_sect = first_sect + nsects - 1;
1198 KASSERT(reqseg->first_sect <= reqseg->last_sect); 1198 KASSERT(reqseg->first_sect <= reqseg->last_sect);
1199 KASSERT(reqseg->last_sect < (PAGE_SIZE / XEN_BSIZE)); 1199 KASSERT(reqseg->last_sect < (PAGE_SIZE / XEN_BSIZE));
1200 1200
1201 reqseg->gref = gntref[dmaseg]; 1201 reqseg->gref = gntref[dmaseg];
1202 } 1202 }
1203 req->nr_segments = segidx; 1203 req->nr_segments = segidx;
1204 sc->sc_ring.req_prod_pvt++; 1204 sc->sc_ring.req_prod_pvt++;
1205} 1205}
1206 1206
1207static int 1207static int
1208xbd_map_align(struct xbd_xenbus_softc *sc, struct xbd_req *req) 1208xbd_map_align(struct xbd_xenbus_softc *sc, struct xbd_req *req)
1209{ 1209{
1210 /* Only can get here if this is physio() request */ 1210 /*
1211 KASSERT(req->req_bp->b_saveaddr != NULL); 1211 * Only can get here if this is physio() request, block I/O
 1212 * uses DEV_BSIZE-aligned buffers.
 1213 */
 1214 KASSERT((req->req_bp->b_flags & B_PHYS) != 0);
1212 1215
1213 sc->sc_cnt_map_unalign.ev_count++; 1216 sc->sc_cnt_map_unalign.ev_count++;
1214 1217
1215 if (sc->sc_unalign_used) { 1218 if (sc->sc_unalign_used) {
1216 sc->sc_cnt_unalign_busy.ev_count++; 1219 sc->sc_cnt_unalign_busy.ev_count++;
1217 return EAGAIN; 1220 return EAGAIN;
1218 } 1221 }
1219 sc->sc_unalign_used = req; 1222 sc->sc_unalign_used = req;
1220 1223
1221 KASSERT(req->req_bp->b_bcount <= MAXPHYS); 1224 KASSERT(req->req_bp->b_bcount <= MAXPHYS);
1222 req->req_data = (void *)sc->sc_unalign_buffer; 1225 req->req_data = (void *)sc->sc_unalign_buffer;
1223 if ((req->req_bp->b_flags & B_READ) == 0) 1226 if ((req->req_bp->b_flags & B_READ) == 0)
1224 memcpy(req->req_data, req->req_bp->b_data, 1227 memcpy(req->req_data, req->req_bp->b_data,