hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/block/xen-blkfront.c
....@@ -151,11 +151,12 @@
151151 module_param_named(max_ring_page_order, xen_blkif_max_ring_order, int, 0444);
152152 MODULE_PARM_DESC(max_ring_page_order, "Maximum order of pages to be used for the shared ring");
153153
154
+static bool __read_mostly xen_blkif_trusted = true;
155
+module_param_named(trusted, xen_blkif_trusted, bool, 0644);
156
+MODULE_PARM_DESC(trusted, "Is the backend trusted");
157
+
154158 #define BLK_RING_SIZE(info) \
155159 __CONST_RING_SIZE(blkif, XEN_PAGE_SIZE * (info)->nr_ring_pages)
156
-
157
-#define BLK_MAX_RING_SIZE \
158
- __CONST_RING_SIZE(blkif, XEN_PAGE_SIZE * XENBUS_MAX_RING_GRANTS)
159160
160161 /*
161162 * ring-ref%u i=(-1UL) would take 11 characters + 'ring-ref' is 8, so 19
....@@ -180,12 +181,12 @@
180181 unsigned int evtchn, irq;
181182 struct work_struct work;
182183 struct gnttab_free_callback callback;
183
- struct blk_shadow shadow[BLK_MAX_RING_SIZE];
184184 struct list_head indirect_pages;
185185 struct list_head grants;
186186 unsigned int persistent_gnts_c;
187187 unsigned long shadow_free;
188188 struct blkfront_info *dev_info;
189
+ struct blk_shadow shadow[];
189190 };
190191
191192 /*
....@@ -210,7 +211,11 @@
210211 unsigned int feature_fua:1;
211212 unsigned int feature_discard:1;
212213 unsigned int feature_secdiscard:1;
214
+ /* Connect-time cached feature_persistent parameter */
215
+ unsigned int feature_persistent_parm:1;
216
+ /* Persistent grants feature negotiation result */
213217 unsigned int feature_persistent:1;
218
+ unsigned int bounce:1;
214219 unsigned int discard_granularity;
215220 unsigned int discard_alignment;
216221 /* Number of 4KB segments handled */
....@@ -219,6 +224,7 @@
219224 struct blk_mq_tag_set tag_set;
220225 struct blkfront_ring_info *rinfo;
221226 unsigned int nr_rings;
227
+ unsigned int rinfo_size;
222228 /* Save uncomplete reqs and bios for migration. */
223229 struct list_head requests;
224230 struct bio_list bio_list;
....@@ -265,6 +271,18 @@
265271 static void blkfront_gather_backend_features(struct blkfront_info *info);
266272 static int negotiate_mq(struct blkfront_info *info);
267273
274
+#define for_each_rinfo(info, ptr, idx) \
275
+ for ((ptr) = (info)->rinfo, (idx) = 0; \
276
+ (idx) < (info)->nr_rings; \
277
+ (idx)++, (ptr) = (void *)(ptr) + (info)->rinfo_size)
278
+
279
+static inline struct blkfront_ring_info *
280
+get_rinfo(const struct blkfront_info *info, unsigned int i)
281
+{
282
+ BUG_ON(i >= info->nr_rings);
283
+ return (void *)info->rinfo + i * info->rinfo_size;
284
+}
285
+
268286 static int get_id_from_freelist(struct blkfront_ring_info *rinfo)
269287 {
270288 unsigned long free = rinfo->shadow_free;
....@@ -300,8 +318,8 @@
300318 if (!gnt_list_entry)
301319 goto out_of_memory;
302320
303
- if (info->feature_persistent) {
304
- granted_page = alloc_page(GFP_NOIO);
321
+ if (info->bounce) {
322
+ granted_page = alloc_page(GFP_NOIO | __GFP_ZERO);
305323 if (!granted_page) {
306324 kfree(gnt_list_entry);
307325 goto out_of_memory;
....@@ -320,7 +338,7 @@
320338 list_for_each_entry_safe(gnt_list_entry, n,
321339 &rinfo->grants, node) {
322340 list_del(&gnt_list_entry->node);
323
- if (info->feature_persistent)
341
+ if (info->bounce)
324342 __free_page(gnt_list_entry->page);
325343 kfree(gnt_list_entry);
326344 i--;
....@@ -366,7 +384,7 @@
366384 /* Assign a gref to this page */
367385 gnt_list_entry->gref = gnttab_claim_grant_reference(gref_head);
368386 BUG_ON(gnt_list_entry->gref == -ENOSPC);
369
- if (info->feature_persistent)
387
+ if (info->bounce)
370388 grant_foreign_access(gnt_list_entry, info);
371389 else {
372390 /* Grant access to the GFN passed by the caller */
....@@ -390,7 +408,7 @@
390408 /* Assign a gref to this page */
391409 gnt_list_entry->gref = gnttab_claim_grant_reference(gref_head);
392410 BUG_ON(gnt_list_entry->gref == -ENOSPC);
393
- if (!info->feature_persistent) {
411
+ if (!info->bounce) {
394412 struct page *indirect_page;
395413
396414 /* Fetch a pre-allocated page to use for indirect grefs */
....@@ -705,7 +723,7 @@
705723 .grant_idx = 0,
706724 .segments = NULL,
707725 .rinfo = rinfo,
708
- .need_copy = rq_data_dir(req) && info->feature_persistent,
726
+ .need_copy = rq_data_dir(req) && info->bounce,
709727 };
710728
711729 /*
....@@ -774,7 +792,8 @@
774792 ring_req->u.rw.handle = info->handle;
775793 ring_req->operation = rq_data_dir(req) ?
776794 BLKIF_OP_WRITE : BLKIF_OP_READ;
777
- if (req_op(req) == REQ_OP_FLUSH || req->cmd_flags & REQ_FUA) {
795
+ if (req_op(req) == REQ_OP_FLUSH ||
796
+ (req_op(req) == REQ_OP_WRITE && (req->cmd_flags & REQ_FUA))) {
778797 /*
779798 * Ideally we can do an unordered flush-to-disk.
780799 * In case the backend onlysupports barriers, use that.
....@@ -898,8 +917,7 @@
898917 struct blkfront_info *info = hctx->queue->queuedata;
899918 struct blkfront_ring_info *rinfo = NULL;
900919
901
- BUG_ON(info->nr_rings <= qid);
902
- rinfo = &info->rinfo[qid];
920
+ rinfo = get_rinfo(info, qid);
903921 blk_mq_start_request(qd->rq);
904922 spin_lock_irqsave(&rinfo->ring_lock, flags);
905923 if (RING_FULL(&rinfo->ring))
....@@ -990,7 +1008,7 @@
9901008 } else
9911009 info->tag_set.queue_depth = BLK_RING_SIZE(info);
9921010 info->tag_set.numa_node = NUMA_NO_NODE;
993
- info->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE;
1011
+ info->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
9941012 info->tag_set.cmd_size = sizeof(struct blkif_req);
9951013 info->tag_set.driver_data = info;
9961014
....@@ -1026,11 +1044,12 @@
10261044 {
10271045 blk_queue_write_cache(info->rq, info->feature_flush ? true : false,
10281046 info->feature_fua ? true : false);
1029
- pr_info("blkfront: %s: %s %s %s %s %s\n",
1047
+ pr_info("blkfront: %s: %s %s %s %s %s %s %s\n",
10301048 info->gd->disk_name, flush_info(info),
10311049 "persistent grants:", info->feature_persistent ?
10321050 "enabled;" : "disabled;", "indirect descriptors:",
1033
- info->max_indirect_segments ? "enabled;" : "disabled;");
1051
+ info->max_indirect_segments ? "enabled;" : "disabled;",
1052
+ "bounce buffer:", info->bounce ? "enabled" : "disabled;");
10341053 }
10351054
10361055 static int xen_translate_vdev(int vdevice, int *minor, unsigned int *offset)
....@@ -1197,6 +1216,7 @@
11971216 static void xlvbd_release_gendisk(struct blkfront_info *info)
11981217 {
11991218 unsigned int minor, nr_minors, i;
1219
+ struct blkfront_ring_info *rinfo;
12001220
12011221 if (info->rq == NULL)
12021222 return;
....@@ -1204,9 +1224,7 @@
12041224 /* No more blkif_request(). */
12051225 blk_mq_stop_hw_queues(info->rq);
12061226
1207
- for (i = 0; i < info->nr_rings; i++) {
1208
- struct blkfront_ring_info *rinfo = &info->rinfo[i];
1209
-
1227
+ for_each_rinfo(info, rinfo, i) {
12101228 /* No more gnttab callback work. */
12111229 gnttab_cancel_free_callback(&rinfo->callback);
12121230
....@@ -1265,7 +1283,7 @@
12651283 if (!list_empty(&rinfo->indirect_pages)) {
12661284 struct page *indirect_page, *n;
12671285
1268
- BUG_ON(info->feature_persistent);
1286
+ BUG_ON(info->bounce);
12691287 list_for_each_entry_safe(indirect_page, n, &rinfo->indirect_pages, lru) {
12701288 list_del(&indirect_page->lru);
12711289 __free_page(indirect_page);
....@@ -1282,7 +1300,7 @@
12821300 0, 0UL);
12831301 rinfo->persistent_gnts_c--;
12841302 }
1285
- if (info->feature_persistent)
1303
+ if (info->bounce)
12861304 __free_page(persistent_gnt->page);
12871305 kfree(persistent_gnt);
12881306 }
....@@ -1303,7 +1321,7 @@
13031321 for (j = 0; j < segs; j++) {
13041322 persistent_gnt = rinfo->shadow[i].grants_used[j];
13051323 gnttab_end_foreign_access(persistent_gnt->gref, 0, 0UL);
1306
- if (info->feature_persistent)
1324
+ if (info->bounce)
13071325 __free_page(persistent_gnt->page);
13081326 kfree(persistent_gnt);
13091327 }
....@@ -1344,7 +1362,8 @@
13441362 rinfo->ring_ref[i] = GRANT_INVALID_REF;
13451363 }
13461364 }
1347
- free_pages((unsigned long)rinfo->ring.sring, get_order(info->nr_ring_pages * XEN_PAGE_SIZE));
1365
+ free_pages_exact(rinfo->ring.sring,
1366
+ info->nr_ring_pages * XEN_PAGE_SIZE);
13481367 rinfo->ring.sring = NULL;
13491368
13501369 if (rinfo->irq)
....@@ -1355,6 +1374,7 @@
13551374 static void blkif_free(struct blkfront_info *info, int suspend)
13561375 {
13571376 unsigned int i;
1377
+ struct blkfront_ring_info *rinfo;
13581378
13591379 /* Prevent new requests being issued until we fix things up. */
13601380 info->connected = suspend ?
....@@ -1363,8 +1383,8 @@
13631383 if (info->rq)
13641384 blk_mq_stop_hw_queues(info->rq);
13651385
1366
- for (i = 0; i < info->nr_rings; i++)
1367
- blkif_free_ring(&info->rinfo[i]);
1386
+ for_each_rinfo(info, rinfo, i)
1387
+ blkif_free_ring(rinfo);
13681388
13691389 kvfree(info->rinfo);
13701390 info->rinfo = NULL;
....@@ -1406,7 +1426,6 @@
14061426 case BLKIF_RSP_EOPNOTSUPP:
14071427 return REQ_EOPNOTSUPP;
14081428 case BLKIF_RSP_ERROR:
1409
- /* Fallthrough. */
14101429 default:
14111430 return REQ_ERROR;
14121431 }
....@@ -1428,9 +1447,15 @@
14281447 return BLKIF_RSP_OKAY;
14291448 }
14301449
1431
-static bool blkif_completion(unsigned long *id,
1432
- struct blkfront_ring_info *rinfo,
1433
- struct blkif_response *bret)
1450
+/*
1451
+ * Return values:
1452
+ * 1 response processed.
1453
+ * 0 missing further responses.
1454
+ * -1 error while processing.
1455
+ */
1456
+static int blkif_completion(unsigned long *id,
1457
+ struct blkfront_ring_info *rinfo,
1458
+ struct blkif_response *bret)
14341459 {
14351460 int i = 0;
14361461 struct scatterlist *sg;
....@@ -1453,7 +1478,7 @@
14531478
14541479 /* Wait the second response if not yet here. */
14551480 if (s2->status < REQ_DONE)
1456
- return false;
1481
+ return 0;
14571482
14581483 bret->status = blkif_get_final_status(s->status,
14591484 s2->status);
....@@ -1486,7 +1511,7 @@
14861511 data.s = s;
14871512 num_sg = s->num_sg;
14881513
1489
- if (bret->operation == BLKIF_OP_READ && info->feature_persistent) {
1514
+ if (bret->operation == BLKIF_OP_READ && info->bounce) {
14901515 for_each_sg(s->sg, sg, num_sg, i) {
14911516 BUG_ON(sg->offset + sg->length > PAGE_SIZE);
14921517
....@@ -1504,47 +1529,48 @@
15041529 }
15051530 /* Add the persistent grant into the list of free grants */
15061531 for (i = 0; i < num_grant; i++) {
1507
- if (gnttab_query_foreign_access(s->grants_used[i]->gref)) {
1532
+ if (!gnttab_try_end_foreign_access(s->grants_used[i]->gref)) {
15081533 /*
15091534 * If the grant is still mapped by the backend (the
15101535 * backend has chosen to make this grant persistent)
15111536 * we add it at the head of the list, so it will be
15121537 * reused first.
15131538 */
1514
- if (!info->feature_persistent)
1515
- pr_alert_ratelimited("backed has not unmapped grant: %u\n",
1516
- s->grants_used[i]->gref);
1539
+ if (!info->feature_persistent) {
1540
+ pr_alert("backed has not unmapped grant: %u\n",
1541
+ s->grants_used[i]->gref);
1542
+ return -1;
1543
+ }
15171544 list_add(&s->grants_used[i]->node, &rinfo->grants);
15181545 rinfo->persistent_gnts_c++;
15191546 } else {
15201547 /*
1521
- * If the grant is not mapped by the backend we end the
1522
- * foreign access and add it to the tail of the list,
1523
- * so it will not be picked again unless we run out of
1524
- * persistent grants.
1548
+ * If the grant is not mapped by the backend we add it
1549
+ * to the tail of the list, so it will not be picked
1550
+ * again unless we run out of persistent grants.
15251551 */
1526
- gnttab_end_foreign_access(s->grants_used[i]->gref, 0, 0UL);
15271552 s->grants_used[i]->gref = GRANT_INVALID_REF;
15281553 list_add_tail(&s->grants_used[i]->node, &rinfo->grants);
15291554 }
15301555 }
15311556 if (s->req.operation == BLKIF_OP_INDIRECT) {
15321557 for (i = 0; i < INDIRECT_GREFS(num_grant); i++) {
1533
- if (gnttab_query_foreign_access(s->indirect_grants[i]->gref)) {
1534
- if (!info->feature_persistent)
1535
- pr_alert_ratelimited("backed has not unmapped grant: %u\n",
1536
- s->indirect_grants[i]->gref);
1558
+ if (!gnttab_try_end_foreign_access(s->indirect_grants[i]->gref)) {
1559
+ if (!info->feature_persistent) {
1560
+ pr_alert("backed has not unmapped grant: %u\n",
1561
+ s->indirect_grants[i]->gref);
1562
+ return -1;
1563
+ }
15371564 list_add(&s->indirect_grants[i]->node, &rinfo->grants);
15381565 rinfo->persistent_gnts_c++;
15391566 } else {
15401567 struct page *indirect_page;
15411568
1542
- gnttab_end_foreign_access(s->indirect_grants[i]->gref, 0, 0UL);
15431569 /*
15441570 * Add the used indirect page back to the list of
15451571 * available pages for indirect grefs.
15461572 */
1547
- if (!info->feature_persistent) {
1573
+ if (!info->bounce) {
15481574 indirect_page = s->indirect_grants[i]->page;
15491575 list_add(&indirect_page->lru, &rinfo->indirect_pages);
15501576 }
....@@ -1554,7 +1580,7 @@
15541580 }
15551581 }
15561582
1557
- return true;
1583
+ return 1;
15581584 }
15591585
15601586 static irqreturn_t blkif_interrupt(int irq, void *dev_id)
....@@ -1620,12 +1646,17 @@
16201646 }
16211647
16221648 if (bret.operation != BLKIF_OP_DISCARD) {
1649
+ int ret;
1650
+
16231651 /*
16241652 * We may need to wait for an extra response if the
16251653 * I/O request is split in 2
16261654 */
1627
- if (!blkif_completion(&id, rinfo, &bret))
1655
+ ret = blkif_completion(&id, rinfo, &bret);
1656
+ if (!ret)
16281657 continue;
1658
+ if (unlikely(ret < 0))
1659
+ goto err;
16291660 }
16301661
16311662 if (add_id_to_freelist(rinfo, id)) {
....@@ -1673,7 +1704,7 @@
16731704 info->feature_flush = 0;
16741705 xlvbd_flush(info);
16751706 }
1676
- /* fall through */
1707
+ fallthrough;
16771708 case BLKIF_OP_READ:
16781709 case BLKIF_OP_WRITE:
16791710 if (unlikely(bret.status != BLKIF_RSP_OKAY))
....@@ -1686,7 +1717,8 @@
16861717 BUG();
16871718 }
16881719
1689
- blk_mq_complete_request(req);
1720
+ if (likely(!blk_should_fake_timeout(req->q)))
1721
+ blk_mq_complete_request(req);
16901722 }
16911723
16921724 rinfo->ring.rsp_cons = i;
....@@ -1731,8 +1763,7 @@
17311763 for (i = 0; i < info->nr_ring_pages; i++)
17321764 rinfo->ring_ref[i] = GRANT_INVALID_REF;
17331765
1734
- sring = (struct blkif_sring *)__get_free_pages(GFP_NOIO | __GFP_HIGH,
1735
- get_order(ring_size));
1766
+ sring = alloc_pages_exact(ring_size, GFP_NOIO | __GFP_ZERO);
17361767 if (!sring) {
17371768 xenbus_dev_fatal(dev, -ENOMEM, "allocating shared ring");
17381769 return -ENOMEM;
....@@ -1742,7 +1773,7 @@
17421773
17431774 err = xenbus_grant_ring(dev, rinfo->ring.sring, info->nr_ring_pages, gref);
17441775 if (err < 0) {
1745
- free_pages((unsigned long)sring, get_order(ring_size));
1776
+ free_pages_exact(sring, ring_size);
17461777 rinfo->ring.sring = NULL;
17471778 goto fail;
17481779 }
....@@ -1822,6 +1853,12 @@
18221853 kfree(info);
18231854 }
18241855
1856
+/* Enable the persistent grants feature. */
1857
+static bool feature_persistent = true;
1858
+module_param(feature_persistent, bool, 0644);
1859
+MODULE_PARM_DESC(feature_persistent,
1860
+ "Enables the persistent grants feature");
1861
+
18251862 /* Common code used when first setting up, and when resuming. */
18261863 static int talk_to_blkback(struct xenbus_device *dev,
18271864 struct blkfront_info *info)
....@@ -1831,9 +1868,14 @@
18311868 int err;
18321869 unsigned int i, max_page_order;
18331870 unsigned int ring_page_order;
1871
+ struct blkfront_ring_info *rinfo;
18341872
18351873 if (!info)
18361874 return -ENODEV;
1875
+
1876
+ /* Check if backend is trusted. */
1877
+ info->bounce = !xen_blkif_trusted ||
1878
+ !xenbus_read_unsigned(dev->nodename, "trusted", 1);
18371879
18381880 max_page_order = xenbus_read_unsigned(info->xbdev->otherend,
18391881 "max-ring-page-order", 0);
....@@ -1844,9 +1886,7 @@
18441886 if (err)
18451887 goto destroy_blkring;
18461888
1847
- for (i = 0; i < info->nr_rings; i++) {
1848
- struct blkfront_ring_info *rinfo = &info->rinfo[i];
1849
-
1889
+ for_each_rinfo(info, rinfo, i) {
18501890 /* Create shared ring, alloc event channel. */
18511891 err = setup_blkring(dev, rinfo);
18521892 if (err)
....@@ -1871,7 +1911,7 @@
18711911
18721912 /* We already got the number of queues/rings in _probe */
18731913 if (info->nr_rings == 1) {
1874
- err = write_per_ring_nodes(xbt, &info->rinfo[0], dev->nodename);
1914
+ err = write_per_ring_nodes(xbt, info->rinfo, dev->nodename);
18751915 if (err)
18761916 goto destroy_blkring;
18771917 } else {
....@@ -1893,10 +1933,10 @@
18931933 goto abort_transaction;
18941934 }
18951935
1896
- for (i = 0; i < info->nr_rings; i++) {
1936
+ for_each_rinfo(info, rinfo, i) {
18971937 memset(path, 0, pathsize);
18981938 snprintf(path, pathsize, "%s/queue-%u", dev->nodename, i);
1899
- err = write_per_ring_nodes(xbt, &info->rinfo[i], path);
1939
+ err = write_per_ring_nodes(xbt, rinfo, path);
19001940 if (err) {
19011941 kfree(path);
19021942 goto destroy_blkring;
....@@ -1910,8 +1950,9 @@
19101950 message = "writing protocol";
19111951 goto abort_transaction;
19121952 }
1913
- err = xenbus_printf(xbt, dev->nodename,
1914
- "feature-persistent", "%u", 1);
1953
+ info->feature_persistent_parm = feature_persistent;
1954
+ err = xenbus_printf(xbt, dev->nodename, "feature-persistent", "%u",
1955
+ info->feature_persistent_parm);
19151956 if (err)
19161957 dev_warn(&dev->dev,
19171958 "writing persistent grants feature to xenbus");
....@@ -1924,9 +1965,8 @@
19241965 goto destroy_blkring;
19251966 }
19261967
1927
- for (i = 0; i < info->nr_rings; i++) {
1968
+ for_each_rinfo(info, rinfo, i) {
19281969 unsigned int j;
1929
- struct blkfront_ring_info *rinfo = &info->rinfo[i];
19301970
19311971 for (j = 0; j < BLK_RING_SIZE(info); j++)
19321972 rinfo->shadow[j].req.u.rw.id = j + 1;
....@@ -1956,6 +1996,7 @@
19561996 {
19571997 unsigned int backend_max_queues;
19581998 unsigned int i;
1999
+ struct blkfront_ring_info *rinfo;
19592000
19602001 BUG_ON(info->nr_rings);
19612002
....@@ -1967,19 +2008,16 @@
19672008 if (!info->nr_rings)
19682009 info->nr_rings = 1;
19692010
1970
- info->rinfo = kvcalloc(info->nr_rings,
1971
- sizeof(struct blkfront_ring_info),
1972
- GFP_KERNEL);
2011
+ info->rinfo_size = struct_size(info->rinfo, shadow,
2012
+ BLK_RING_SIZE(info));
2013
+ info->rinfo = kvcalloc(info->nr_rings, info->rinfo_size, GFP_KERNEL);
19732014 if (!info->rinfo) {
19742015 xenbus_dev_fatal(info->xbdev, -ENOMEM, "allocating ring_info structure");
19752016 info->nr_rings = 0;
19762017 return -ENOMEM;
19772018 }
19782019
1979
- for (i = 0; i < info->nr_rings; i++) {
1980
- struct blkfront_ring_info *rinfo;
1981
-
1982
- rinfo = &info->rinfo[i];
2020
+ for_each_rinfo(info, rinfo, i) {
19832021 INIT_LIST_HEAD(&rinfo->indirect_pages);
19842022 INIT_LIST_HEAD(&rinfo->grants);
19852023 rinfo->dev_info = info;
....@@ -1988,6 +2026,7 @@
19882026 }
19892027 return 0;
19902028 }
2029
+
19912030 /**
19922031 * Entry point to this code when a new device is created. Allocate the basic
19932032 * structures and the ring buffer for communication with the backend, and
....@@ -2072,6 +2111,7 @@
20722111 int rc;
20732112 struct bio *bio;
20742113 unsigned int segs;
2114
+ struct blkfront_ring_info *rinfo;
20752115
20762116 blkfront_gather_backend_features(info);
20772117 /* Reset limits changed by blk_mq_update_nr_hw_queues(). */
....@@ -2079,9 +2119,7 @@
20792119 segs = info->max_indirect_segments ? : BLKIF_MAX_SEGMENTS_PER_REQUEST;
20802120 blk_queue_max_segments(info->rq, segs / GRANTS_PER_PSEG);
20812121
2082
- for (r_index = 0; r_index < info->nr_rings; r_index++) {
2083
- struct blkfront_ring_info *rinfo = &info->rinfo[r_index];
2084
-
2122
+ for_each_rinfo(info, rinfo, r_index) {
20852123 rc = blkfront_setup_indirect(rinfo);
20862124 if (rc)
20872125 return rc;
....@@ -2091,10 +2129,7 @@
20912129 /* Now safe for us to use the shared ring */
20922130 info->connected = BLKIF_STATE_CONNECTED;
20932131
2094
- for (r_index = 0; r_index < info->nr_rings; r_index++) {
2095
- struct blkfront_ring_info *rinfo;
2096
-
2097
- rinfo = &info->rinfo[r_index];
2132
+ for_each_rinfo(info, rinfo, r_index) {
20982133 /* Kick any other new requests queued since we resumed */
20992134 kick_pending_request_queues(rinfo);
21002135 }
....@@ -2127,13 +2162,13 @@
21272162 struct blkfront_info *info = dev_get_drvdata(&dev->dev);
21282163 int err = 0;
21292164 unsigned int i, j;
2165
+ struct blkfront_ring_info *rinfo;
21302166
21312167 dev_dbg(&dev->dev, "blkfront_resume: %s\n", dev->nodename);
21322168
21332169 bio_list_init(&info->bio_list);
21342170 INIT_LIST_HEAD(&info->requests);
2135
- for (i = 0; i < info->nr_rings; i++) {
2136
- struct blkfront_ring_info *rinfo = &info->rinfo[i];
2171
+ for_each_rinfo(info, rinfo, i) {
21372172 struct bio_list merge_bio;
21382173 struct blk_shadow *shadow = rinfo->shadow;
21392174
....@@ -2261,17 +2296,18 @@
22612296 if (err)
22622297 goto out_of_memory;
22632298
2264
- if (!info->feature_persistent && info->max_indirect_segments) {
2299
+ if (!info->bounce && info->max_indirect_segments) {
22652300 /*
2266
- * We are using indirect descriptors but not persistent
2267
- * grants, we need to allocate a set of pages that can be
2301
+ * We are using indirect descriptors but don't have a bounce
2302
+ * buffer, we need to allocate a set of pages that can be
22682303 * used for mapping indirect grefs
22692304 */
22702305 int num = INDIRECT_GREFS(grants) * BLK_RING_SIZE(info);
22712306
22722307 BUG_ON(!list_empty(&rinfo->indirect_pages));
22732308 for (i = 0; i < num; i++) {
2274
- struct page *indirect_page = alloc_page(GFP_KERNEL);
2309
+ struct page *indirect_page = alloc_page(GFP_KERNEL |
2310
+ __GFP_ZERO);
22752311 if (!indirect_page)
22762312 goto out_of_memory;
22772313 list_add(&indirect_page->lru, &rinfo->indirect_pages);
....@@ -2360,9 +2396,12 @@
23602396 if (xenbus_read_unsigned(info->xbdev->otherend, "feature-discard", 0))
23612397 blkfront_setup_discard(info);
23622398
2363
- info->feature_persistent =
2364
- !!xenbus_read_unsigned(info->xbdev->otherend,
2365
- "feature-persistent", 0);
2399
+ if (info->feature_persistent_parm)
2400
+ info->feature_persistent =
2401
+ !!xenbus_read_unsigned(info->xbdev->otherend,
2402
+ "feature-persistent", 0);
2403
+ if (info->feature_persistent)
2404
+ info->bounce = true;
23662405
23672406 indirect_segments = xenbus_read_unsigned(info->xbdev->otherend,
23682407 "feature-max-indirect-segments", 0);
....@@ -2389,8 +2428,8 @@
23892428 unsigned long sector_size;
23902429 unsigned int physical_sector_size;
23912430 unsigned int binfo;
2392
- char *envp[] = { "RESIZE=1", NULL };
23932431 int err, i;
2432
+ struct blkfront_ring_info *rinfo;
23942433
23952434 switch (info->connected) {
23962435 case BLKIF_STATE_CONNECTED:
....@@ -2404,10 +2443,7 @@
24042443 return;
24052444 printk(KERN_INFO "Setting capacity to %Lu\n",
24062445 sectors);
2407
- set_capacity(info->gd, sectors);
2408
- revalidate_disk(info->gd);
2409
- kobject_uevent_env(&disk_to_dev(info->gd)->kobj,
2410
- KOBJ_CHANGE, envp);
2446
+ set_capacity_revalidate_and_notify(info->gd, sectors, true);
24112447
24122448 return;
24132449 case BLKIF_STATE_SUSPENDED:
....@@ -2448,8 +2484,8 @@
24482484 "physical-sector-size",
24492485 sector_size);
24502486 blkfront_gather_backend_features(info);
2451
- for (i = 0; i < info->nr_rings; i++) {
2452
- err = blkfront_setup_indirect(&info->rinfo[i]);
2487
+ for_each_rinfo(info, rinfo, i) {
2488
+ err = blkfront_setup_indirect(rinfo);
24532489 if (err) {
24542490 xenbus_dev_fatal(info->xbdev, err, "setup_indirect at %s",
24552491 info->xbdev->otherend);
....@@ -2470,10 +2506,10 @@
24702506
24712507 /* Kick pending requests. */
24722508 info->connected = BLKIF_STATE_CONNECTED;
2473
- for (i = 0; i < info->nr_rings; i++)
2474
- kick_pending_request_queues(&info->rinfo[i]);
2509
+ for_each_rinfo(info, rinfo, i)
2510
+ kick_pending_request_queues(rinfo);
24752511
2476
- device_add_disk(&info->xbdev->dev, info->gd);
2512
+ device_add_disk(&info->xbdev->dev, info->gd, NULL);
24772513
24782514 info->is_ready = 1;
24792515 return;
....@@ -2530,7 +2566,7 @@
25302566 case XenbusStateClosed:
25312567 if (dev->state == XenbusStateClosed)
25322568 break;
2533
- /* fall through */
2569
+ fallthrough;
25342570 case XenbusStateClosing:
25352571 if (info)
25362572 blkfront_closing(info);
....@@ -2684,6 +2720,7 @@
26842720 .release = blkif_release,
26852721 .getgeo = blkif_getgeo,
26862722 .ioctl = blkif_ioctl,
2723
+ .compat_ioctl = blkdev_compat_ptr_ioctl,
26872724 };
26882725
26892726
....@@ -2705,9 +2742,9 @@
27052742 {
27062743 unsigned int i;
27072744 unsigned long flags;
2745
+ struct blkfront_ring_info *rinfo;
27082746
2709
- for (i = 0; i < info->nr_rings; i++) {
2710
- struct blkfront_ring_info *rinfo = &info->rinfo[i];
2747
+ for_each_rinfo(info, rinfo, i) {
27112748 struct grant *gnt_list_entry, *tmp;
27122749
27132750 spin_lock_irqsave(&rinfo->ring_lock, flags);
....@@ -2720,11 +2757,10 @@
27202757 list_for_each_entry_safe(gnt_list_entry, tmp, &rinfo->grants,
27212758 node) {
27222759 if (gnt_list_entry->gref == GRANT_INVALID_REF ||
2723
- gnttab_query_foreign_access(gnt_list_entry->gref))
2760
+ !gnttab_try_end_foreign_access(gnt_list_entry->gref))
27242761 continue;
27252762
27262763 list_del(&gnt_list_entry->node);
2727
- gnttab_end_foreign_access(gnt_list_entry->gref, 0, 0UL);
27282764 rinfo->persistent_gnts_c--;
27292765 gnt_list_entry->gref = GRANT_INVALID_REF;
27302766 list_add_tail(&gnt_list_entry->node, &rinfo->grants);
....@@ -2739,6 +2775,13 @@
27392775 struct blkfront_info *info;
27402776 bool need_schedule_work = false;
27412777
2778
+ /*
2779
+ * Note that when using bounce buffers but not persistent grants
2780
+ * there's no need to run blkfront_delay_work because grants are
2781
+ * revoked in blkif_completion or else an error is reported and the
2782
+ * connection is closed.
2783
+ */
2784
+
27422785 mutex_lock(&blkfront_mutex);
27432786
27442787 list_for_each_entry(info, &info_list, info_list) {