2018-11-11 17:40:18 +00:00
|
|
|
From 98231d38e75826534ef10b0ea06ecde796b89c3c Mon Sep 17 00:00:00 2001
|
2016-05-08 18:45:02 +00:00
|
|
|
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
|
|
|
|
<marmarek@invisiblethingslab.com>
|
|
|
|
Date: Wed, 16 Dec 2015 06:07:14 +0100
|
2018-08-15 12:57:19 +00:00
|
|
|
Subject: [PATCH] xen-blkfront: prepare request locally, only then put it on
|
|
|
|
the shared ring
|
2016-05-08 18:45:02 +00:00
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
Do not reuse data which theoretically might be already modified by the
|
|
|
|
backend. This is mostly about private copy of the request
|
|
|
|
(info->shadow[id].req) - make sure the request saved there is really the
|
|
|
|
one just filled.
|
|
|
|
|
|
|
|
This is part of XSA155.
|
|
|
|
|
|
|
|
CC: stable@vger.kernel.org
|
|
|
|
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
|
|
|
|
---
|
2018-08-15 12:57:19 +00:00
|
|
|
drivers/block/xen-blkfront.c | 76 +++++++++++++++++++++---------------
|
|
|
|
1 file changed, 44 insertions(+), 32 deletions(-)
|
2016-05-08 18:45:02 +00:00
|
|
|
|
|
|
|
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
|
2018-11-11 17:40:18 +00:00
|
|
|
index e520bc6f6007..8132836e225b 100644
|
2016-05-08 18:45:02 +00:00
|
|
|
--- a/drivers/block/xen-blkfront.c
|
|
|
|
+++ b/drivers/block/xen-blkfront.c
|
2018-11-11 17:40:18 +00:00
|
|
|
@@ -527,19 +527,16 @@ static int blkif_ioctl(struct block_device *bdev, fmode_t mode,
|
2016-11-11 13:28:22 +00:00
|
|
|
|
|
|
|
static unsigned long blkif_ring_get_request(struct blkfront_ring_info *rinfo,
|
|
|
|
struct request *req,
|
|
|
|
- struct blkif_request **ring_req)
|
|
|
|
+ struct blkif_request *ring_req)
|
|
|
|
{
|
|
|
|
unsigned long id;
|
|
|
|
|
|
|
|
- *ring_req = RING_GET_REQUEST(&rinfo->ring, rinfo->ring.req_prod_pvt);
|
|
|
|
- rinfo->ring.req_prod_pvt++;
|
|
|
|
-
|
|
|
|
id = get_id_from_freelist(rinfo);
|
|
|
|
rinfo->shadow[id].request = req;
|
|
|
|
rinfo->shadow[id].status = REQ_WAITING;
|
|
|
|
rinfo->shadow[id].associated_id = NO_ASSOCIATED_ID;
|
|
|
|
|
|
|
|
- (*ring_req)->u.rw.id = id;
|
|
|
|
+ ring_req->u.rw.id = id;
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2018-11-11 17:40:18 +00:00
|
|
|
@@ -547,23 +544,28 @@ static unsigned long blkif_ring_get_request(struct blkfront_ring_info *rinfo,
|
2016-11-11 13:28:22 +00:00
|
|
|
static int blkif_queue_discard_req(struct request *req, struct blkfront_ring_info *rinfo)
|
2016-05-08 18:45:02 +00:00
|
|
|
{
|
2016-11-11 13:28:22 +00:00
|
|
|
struct blkfront_info *info = rinfo->dev_info;
|
2016-05-08 18:45:02 +00:00
|
|
|
- struct blkif_request *ring_req;
|
2016-11-11 13:28:22 +00:00
|
|
|
+ struct blkif_request ring_req = { 0 };
|
2016-05-08 18:45:02 +00:00
|
|
|
unsigned long id;
|
|
|
|
|
|
|
|
/* Fill out a communications ring structure. */
|
2016-11-11 13:28:22 +00:00
|
|
|
id = blkif_ring_get_request(rinfo, req, &ring_req);
|
2016-05-08 18:45:02 +00:00
|
|
|
|
|
|
|
- ring_req->operation = BLKIF_OP_DISCARD;
|
|
|
|
- ring_req->u.discard.nr_sectors = blk_rq_sectors(req);
|
|
|
|
- ring_req->u.discard.id = id;
|
|
|
|
- ring_req->u.discard.sector_number = (blkif_sector_t)blk_rq_pos(req);
|
|
|
|
+ ring_req.operation = BLKIF_OP_DISCARD;
|
|
|
|
+ ring_req.u.discard.nr_sectors = blk_rq_sectors(req);
|
|
|
|
+ ring_req.u.discard.id = id;
|
|
|
|
+ ring_req.u.discard.sector_number = (blkif_sector_t)blk_rq_pos(req);
|
2016-11-11 13:28:22 +00:00
|
|
|
if (req_op(req) == REQ_OP_SECURE_ERASE && info->feature_secdiscard)
|
2016-05-08 18:45:02 +00:00
|
|
|
- ring_req->u.discard.flag = BLKIF_DISCARD_SECURE;
|
|
|
|
+ ring_req.u.discard.flag = BLKIF_DISCARD_SECURE;
|
|
|
|
else
|
|
|
|
- ring_req->u.discard.flag = 0;
|
|
|
|
+ ring_req.u.discard.flag = 0;
|
2016-11-11 13:28:22 +00:00
|
|
|
+
|
2016-05-08 18:45:02 +00:00
|
|
|
+ /* make the request available to the backend */
|
2016-11-11 13:28:22 +00:00
|
|
|
+ *RING_GET_REQUEST(&rinfo->ring, rinfo->ring.req_prod_pvt) = ring_req;
|
2016-05-08 18:45:02 +00:00
|
|
|
+ wmb();
|
2016-11-11 13:28:22 +00:00
|
|
|
+ rinfo->ring.req_prod_pvt++;
|
2016-05-08 18:45:02 +00:00
|
|
|
|
|
|
|
/* Keep a private copy so we can reissue requests when recovering. */
|
2016-11-11 13:28:22 +00:00
|
|
|
- rinfo->shadow[id].req = *ring_req;
|
|
|
|
+ rinfo->shadow[id].req = ring_req;
|
2016-05-08 18:45:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-11-11 17:40:18 +00:00
|
|
|
@@ -695,7 +697,7 @@ static void blkif_setup_extra_req(struct blkif_request *first,
|
2016-11-11 13:28:22 +00:00
|
|
|
static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *rinfo)
|
2016-05-08 18:45:02 +00:00
|
|
|
{
|
2016-11-11 13:28:22 +00:00
|
|
|
struct blkfront_info *info = rinfo->dev_info;
|
|
|
|
- struct blkif_request *ring_req, *extra_ring_req = NULL;
|
|
|
|
+ struct blkif_request ring_req = { 0 }, extra_ring_req = { 0 };
|
|
|
|
unsigned long id, extra_id = NO_ASSOCIATED_ID;
|
|
|
|
bool require_extra_req = false;
|
2016-05-08 18:45:02 +00:00
|
|
|
int i;
|
2018-11-11 17:40:18 +00:00
|
|
|
@@ -760,16 +762,16 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
|
2016-05-08 18:45:02 +00:00
|
|
|
* BLKIF_OP_WRITE
|
|
|
|
*/
|
2016-11-11 13:28:22 +00:00
|
|
|
BUG_ON(req_op(req) == REQ_OP_FLUSH || req->cmd_flags & REQ_FUA);
|
2016-05-08 18:45:02 +00:00
|
|
|
- ring_req->operation = BLKIF_OP_INDIRECT;
|
|
|
|
- ring_req->u.indirect.indirect_op = rq_data_dir(req) ?
|
|
|
|
+ ring_req.operation = BLKIF_OP_INDIRECT;
|
|
|
|
+ ring_req.u.indirect.indirect_op = rq_data_dir(req) ?
|
|
|
|
BLKIF_OP_WRITE : BLKIF_OP_READ;
|
|
|
|
- ring_req->u.indirect.sector_number = (blkif_sector_t)blk_rq_pos(req);
|
|
|
|
- ring_req->u.indirect.handle = info->handle;
|
|
|
|
- ring_req->u.indirect.nr_segments = num_grant;
|
|
|
|
+ ring_req.u.indirect.sector_number = (blkif_sector_t)blk_rq_pos(req);
|
|
|
|
+ ring_req.u.indirect.handle = info->handle;
|
|
|
|
+ ring_req.u.indirect.nr_segments = num_grant;
|
|
|
|
} else {
|
|
|
|
- ring_req->u.rw.sector_number = (blkif_sector_t)blk_rq_pos(req);
|
|
|
|
- ring_req->u.rw.handle = info->handle;
|
|
|
|
- ring_req->operation = rq_data_dir(req) ?
|
|
|
|
+ ring_req.u.rw.sector_number = (blkif_sector_t)blk_rq_pos(req);
|
|
|
|
+ ring_req.u.rw.handle = info->handle;
|
|
|
|
+ ring_req.operation = rq_data_dir(req) ?
|
|
|
|
BLKIF_OP_WRITE : BLKIF_OP_READ;
|
2016-11-11 13:28:22 +00:00
|
|
|
if (req_op(req) == REQ_OP_FLUSH || req->cmd_flags & REQ_FUA) {
|
2016-05-08 18:45:02 +00:00
|
|
|
/*
|
2018-11-11 17:40:18 +00:00
|
|
|
@@ -780,15 +782,15 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
|
2016-11-11 13:28:22 +00:00
|
|
|
* since it is guaranteed ordered WRT previous writes.)
|
|
|
|
*/
|
|
|
|
if (info->feature_flush && info->feature_fua)
|
2016-05-08 18:45:02 +00:00
|
|
|
- ring_req->operation =
|
|
|
|
+ ring_req.operation =
|
|
|
|
BLKIF_OP_WRITE_BARRIER;
|
2016-11-11 13:28:22 +00:00
|
|
|
else if (info->feature_flush)
|
2016-05-08 18:45:02 +00:00
|
|
|
- ring_req->operation =
|
|
|
|
+ ring_req.operation =
|
|
|
|
BLKIF_OP_FLUSH_DISKCACHE;
|
2016-11-11 13:28:22 +00:00
|
|
|
else
|
2016-05-08 18:45:02 +00:00
|
|
|
- ring_req->operation = 0;
|
|
|
|
+ ring_req.operation = 0;
|
|
|
|
}
|
|
|
|
- ring_req->u.rw.nr_segments = num_grant;
|
|
|
|
+ ring_req.u.rw.nr_segments = num_grant;
|
2016-11-11 13:28:22 +00:00
|
|
|
if (unlikely(require_extra_req)) {
|
|
|
|
extra_id = blkif_ring_get_request(rinfo, req,
|
|
|
|
&extra_ring_req);
|
2018-11-11 17:40:18 +00:00
|
|
|
@@ -798,7 +800,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
|
2016-11-11 13:28:22 +00:00
|
|
|
*/
|
|
|
|
rinfo->shadow[extra_id].num_sg = 0;
|
|
|
|
|
|
|
|
- blkif_setup_extra_req(ring_req, extra_ring_req);
|
|
|
|
+ blkif_setup_extra_req(&ring_req, &extra_ring_req);
|
|
|
|
|
|
|
|
/* Link the 2 requests together */
|
|
|
|
rinfo->shadow[extra_id].associated_id = id;
|
2018-11-11 17:40:18 +00:00
|
|
|
@@ -806,12 +808,12 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
|
2016-11-11 13:28:22 +00:00
|
|
|
}
|
2016-05-08 18:45:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- setup.ring_req = ring_req;
|
|
|
|
+ setup.ring_req = &ring_req;
|
|
|
|
setup.id = id;
|
2016-11-11 13:28:22 +00:00
|
|
|
|
|
|
|
setup.require_extra_req = require_extra_req;
|
|
|
|
if (unlikely(require_extra_req))
|
|
|
|
- setup.extra_ring_req = extra_ring_req;
|
|
|
|
+ setup.extra_ring_req = &extra_ring_req;
|
|
|
|
|
|
|
|
for_each_sg(rinfo->shadow[id].sg, sg, num_sg, i) {
|
2016-05-08 18:45:02 +00:00
|
|
|
BUG_ON(sg->offset + sg->length > PAGE_SIZE);
|
2018-11-11 17:40:18 +00:00
|
|
|
@@ -833,10 +835,20 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
|
2016-05-08 18:45:02 +00:00
|
|
|
if (setup.segments)
|
|
|
|
kunmap_atomic(setup.segments);
|
|
|
|
|
|
|
|
+ /* make the request available to the backend */
|
2016-11-11 13:28:22 +00:00
|
|
|
+ *RING_GET_REQUEST(&rinfo->ring, rinfo->ring.req_prod_pvt) = ring_req;
|
2016-05-08 18:45:02 +00:00
|
|
|
+ wmb();
|
2016-11-11 13:28:22 +00:00
|
|
|
+ rinfo->ring.req_prod_pvt++;
|
2016-05-08 18:45:02 +00:00
|
|
|
/* Keep a private copy so we can reissue requests when recovering. */
|
2016-11-11 13:28:22 +00:00
|
|
|
- rinfo->shadow[id].req = *ring_req;
|
|
|
|
- if (unlikely(require_extra_req))
|
|
|
|
- rinfo->shadow[extra_id].req = *extra_ring_req;
|
|
|
|
+ rinfo->shadow[id].req = ring_req;
|
|
|
|
+
|
|
|
|
+ if (unlikely(require_extra_req)) {
|
|
|
|
+ *RING_GET_REQUEST(&rinfo->ring, rinfo->ring.req_prod_pvt) = extra_ring_req;
|
|
|
|
+ wmb();
|
|
|
|
+ rinfo->ring.req_prod_pvt++;
|
|
|
|
+ /* Keep a private copy so we can reissue requests when recovering. */
|
|
|
|
+ rinfo->shadow[extra_id].req = extra_ring_req;
|
|
|
|
+ }
|
2016-05-08 18:45:02 +00:00
|
|
|
|
2017-10-02 03:04:33 +00:00
|
|
|
if (new_persistent_gnts)
|
2016-05-08 18:45:02 +00:00
|
|
|
gnttab_free_grant_references(setup.gref_head);
|
2018-08-15 12:57:19 +00:00
|
|
|
--
|
|
|
|
2.17.1
|
|
|
|
|