| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: xbd_xenbus.c,v 1.107 2020/04/13 20:09:13 jdolecek Exp $ */ | | 1 | /* $NetBSD: xbd_xenbus.c,v 1.108 2020/04/14 08:21:59 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.107 2020/04/13 20:09:13 jdolecek Exp $"); | | 53 | __KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.108 2020/04/14 08:21:59 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> |
| @@ -1039,26 +1039,32 @@ xbd_diskstart(device_t self, struct buf | | | @@ -1039,26 +1039,32 @@ xbd_diskstart(device_t self, struct buf |
1039 | nsects = nbytes >> XEN_BSHIFT; | | 1039 | nsects = nbytes >> XEN_BSHIFT; |
1040 | | | 1040 | |
1041 | req->seg[seg].first_sect = off >> XEN_BSHIFT; | | 1041 | req->seg[seg].first_sect = off >> XEN_BSHIFT; |
1042 | req->seg[seg].last_sect = (off >> XEN_BSHIFT) + nsects - 1; | | 1042 | req->seg[seg].last_sect = (off >> XEN_BSHIFT) + nsects - 1; |
1043 | KASSERT(req->seg[seg].first_sect <= req->seg[seg].last_sect); | | 1043 | KASSERT(req->seg[seg].first_sect <= req->seg[seg].last_sect); |
1044 | KASSERT(req->seg[seg].last_sect < (PAGE_SIZE / XEN_BSIZE)); | | 1044 | KASSERT(req->seg[seg].last_sect < (PAGE_SIZE / XEN_BSIZE)); |
1045 | | | 1045 | |
1046 | if (__predict_false(xengnt_grant_access( | | 1046 | if (__predict_false(xengnt_grant_access( |
1047 | sc->sc_xbusd->xbusd_otherend_id, | | 1047 | sc->sc_xbusd->xbusd_otherend_id, |
1048 | (ma & ~PAGE_MASK), (bp->b_flags & B_READ) == 0, | | 1048 | (ma & ~PAGE_MASK), (bp->b_flags & B_READ) == 0, |
1049 | &xbdreq->req_gntref[seg]))) { | | 1049 | &xbdreq->req_gntref[seg]))) { |
1050 | printf("%s: %s: xengnt_grant_access failed", | | 1050 | printf("%s: %s: xengnt_grant_access failed", |
1051 | device_xname(sc->sc_dksc.sc_dev), __func__); | | 1051 | device_xname(sc->sc_dksc.sc_dev), __func__); |
| | | 1052 | if (seg > 0) { |
| | | 1053 | for (; --seg >= 0; ) { |
| | | 1054 | xengnt_revoke_access( |
| | | 1055 | xbdreq->req_gntref[seg]); |
| | | 1056 | } |
| | | 1057 | } |
1052 | bus_dmamap_unload(sc->sc_xbusd->xbusd_dmat, | | 1058 | bus_dmamap_unload(sc->sc_xbusd->xbusd_dmat, |
1053 | xbdreq->req_dmamap); | | 1059 | xbdreq->req_dmamap); |
1054 | SLIST_INSERT_HEAD(&sc->sc_xbdreq_head, xbdreq, | | 1060 | SLIST_INSERT_HEAD(&sc->sc_xbdreq_head, xbdreq, |
1055 | req_next); | | 1061 | req_next); |
1056 | error = EFAULT; | | 1062 | error = EFAULT; |
1057 | goto out; | | 1063 | goto out; |
1058 | } | | 1064 | } |
1059 | | | 1065 | |
1060 | req->seg[seg].gref = xbdreq->req_gntref[seg]; | | 1066 | req->seg[seg].gref = xbdreq->req_gntref[seg]; |
1061 | } | | 1067 | } |
1062 | req->nr_segments = seg; | | 1068 | req->nr_segments = seg; |
1063 | sc->sc_ring.req_prod_pvt++; | | 1069 | sc->sc_ring.req_prod_pvt++; |
1064 | | | 1070 | |