Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-linus-5.6b-rc5-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip

Pull xen fixes from Juergen Gross:
"Four fixes and a small cleanup patch:

- two fixes by Dongli Zhang fixing races in the xenbus driver

- two fixes by me fixing issues introduced in 5.6

- a small cleanup by Gustavo Silva replacing a zero-length array with
a flexible-array"

* tag 'for-linus-5.6b-rc5-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip:
xen/blkfront: fix ring info addressing
xen/xenbus: fix locking
xenbus: req->err should be updated before req->state
xenbus: req->body should be updated before req->state
xen: Replace zero-length array with flexible-array member

+64 -51
+42 -38
drivers/block/xen-blkfront.c
··· 213 213 struct blk_mq_tag_set tag_set; 214 214 struct blkfront_ring_info *rinfo; 215 215 unsigned int nr_rings; 216 + unsigned int rinfo_size; 216 217 /* Save uncomplete reqs and bios for migration. */ 217 218 struct list_head requests; 218 219 struct bio_list bio_list; ··· 259 258 static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo); 260 259 static void blkfront_gather_backend_features(struct blkfront_info *info); 261 260 static int negotiate_mq(struct blkfront_info *info); 261 + 262 + #define for_each_rinfo(info, ptr, idx) \ 263 + for ((ptr) = (info)->rinfo, (idx) = 0; \ 264 + (idx) < (info)->nr_rings; \ 265 + (idx)++, (ptr) = (void *)(ptr) + (info)->rinfo_size) 266 + 267 + static inline struct blkfront_ring_info * 268 + get_rinfo(const struct blkfront_info *info, unsigned int i) 269 + { 270 + BUG_ON(i >= info->nr_rings); 271 + return (void *)info->rinfo + i * info->rinfo_size; 272 + } 262 273 263 274 static int get_id_from_freelist(struct blkfront_ring_info *rinfo) 264 275 { ··· 896 883 struct blkfront_info *info = hctx->queue->queuedata; 897 884 struct blkfront_ring_info *rinfo = NULL; 898 885 899 - BUG_ON(info->nr_rings <= qid); 900 - rinfo = &info->rinfo[qid]; 886 + rinfo = get_rinfo(info, qid); 901 887 blk_mq_start_request(qd->rq); 902 888 spin_lock_irqsave(&rinfo->ring_lock, flags); 903 889 if (RING_FULL(&rinfo->ring)) ··· 1193 1181 static void xlvbd_release_gendisk(struct blkfront_info *info) 1194 1182 { 1195 1183 unsigned int minor, nr_minors, i; 1184 + struct blkfront_ring_info *rinfo; 1196 1185 1197 1186 if (info->rq == NULL) 1198 1187 return; ··· 1201 1188 /* No more blkif_request(). */ 1202 1189 blk_mq_stop_hw_queues(info->rq); 1203 1190 1204 - for (i = 0; i < info->nr_rings; i++) { 1205 - struct blkfront_ring_info *rinfo = &info->rinfo[i]; 1206 - 1191 + for_each_rinfo(info, rinfo, i) { 1207 1192 /* No more gnttab callback work. */ 1208 1193 gnttab_cancel_free_callback(&rinfo->callback); 1209 1194 ··· 1350 1339 static void blkif_free(struct blkfront_info *info, int suspend) 1351 1340 { 1352 1341 unsigned int i; 1342 + struct blkfront_ring_info *rinfo; 1353 1343 1354 1344 /* Prevent new requests being issued until we fix things up. */ 1355 1345 info->connected = suspend ? ··· 1359 1347 if (info->rq) 1360 1348 blk_mq_stop_hw_queues(info->rq); 1361 1349 1362 - for (i = 0; i < info->nr_rings; i++) 1363 - blkif_free_ring(&info->rinfo[i]); 1350 + for_each_rinfo(info, rinfo, i) 1351 + blkif_free_ring(rinfo); 1364 1352 1365 1353 kvfree(info->rinfo); 1366 1354 info->rinfo = NULL; ··· 1787 1775 int err; 1788 1776 unsigned int i, max_page_order; 1789 1777 unsigned int ring_page_order; 1778 + struct blkfront_ring_info *rinfo; 1790 1779 1791 1780 if (!info) 1792 1781 return -ENODEV; ··· 1801 1788 if (err) 1802 1789 goto destroy_blkring; 1803 1790 1804 - for (i = 0; i < info->nr_rings; i++) { 1805 - struct blkfront_ring_info *rinfo = &info->rinfo[i]; 1806 - 1791 + for_each_rinfo(info, rinfo, i) { 1807 1792 /* Create shared ring, alloc event channel. */ 1808 1793 err = setup_blkring(dev, rinfo); 1809 1794 if (err) ··· 1826 1815 1827 1816 /* We already got the number of queues/rings in _probe */ 1828 1817 if (info->nr_rings == 1) { 1829 - err = write_per_ring_nodes(xbt, &info->rinfo[0], dev->nodename); 1818 + err = write_per_ring_nodes(xbt, info->rinfo, dev->nodename); 1830 1819 if (err) 1831 1820 goto destroy_blkring; 1832 1821 } else { ··· 1848 1837 goto abort_transaction; 1849 1838 } 1850 1839 1851 - for (i = 0; i < info->nr_rings; i++) { 1840 + for_each_rinfo(info, rinfo, i) { 1852 1841 memset(path, 0, pathsize); 1853 1842 snprintf(path, pathsize, "%s/queue-%u", dev->nodename, i); 1854 - err = write_per_ring_nodes(xbt, &info->rinfo[i], path); 1843 + err = write_per_ring_nodes(xbt, rinfo, path); 1855 1844 if (err) { 1856 1845 kfree(path); 1857 1846 goto destroy_blkring; ··· 1879 1868 goto destroy_blkring; 1880 1869 } 1881 1870 1882 - for (i = 0; i < info->nr_rings; i++) { 1871 + for_each_rinfo(info, rinfo, i) { 1883 1872 unsigned int j; 1884 - struct blkfront_ring_info *rinfo = &info->rinfo[i]; 1885 1873 1886 1874 for (j = 0; j < BLK_RING_SIZE(info); j++) 1887 1875 rinfo->shadow[j].req.u.rw.id = j + 1; ··· 1910 1900 { 1911 1901 unsigned int backend_max_queues; 1912 1902 unsigned int i; 1903 + struct blkfront_ring_info *rinfo; 1913 1904 1914 1905 BUG_ON(info->nr_rings); 1915 1906 ··· 1922 1911 if (!info->nr_rings) 1923 1912 info->nr_rings = 1; 1924 1913 1925 - info->rinfo = kvcalloc(info->nr_rings, 1926 - struct_size(info->rinfo, shadow, 1927 - BLK_RING_SIZE(info)), 1928 - GFP_KERNEL); 1914 + info->rinfo_size = struct_size(info->rinfo, shadow, 1915 + BLK_RING_SIZE(info)); 1916 + info->rinfo = kvcalloc(info->nr_rings, info->rinfo_size, GFP_KERNEL); 1929 1917 if (!info->rinfo) { 1930 1918 xenbus_dev_fatal(info->xbdev, -ENOMEM, "allocating ring_info structure"); 1931 1919 info->nr_rings = 0; 1932 1920 return -ENOMEM; 1933 1921 } 1934 1922 1935 - for (i = 0; i < info->nr_rings; i++) { 1936 - struct blkfront_ring_info *rinfo; 1937 - 1938 - rinfo = &info->rinfo[i]; 1923 + for_each_rinfo(info, rinfo, i) { 1939 1924 INIT_LIST_HEAD(&rinfo->indirect_pages); 1940 1925 INIT_LIST_HEAD(&rinfo->grants); 1941 1926 rinfo->dev_info = info; ··· 2024 2017 int rc; 2025 2018 struct bio *bio; 2026 2019 unsigned int segs; 2020 + struct blkfront_ring_info *rinfo; 2027 2021 2028 2022 blkfront_gather_backend_features(info); 2029 2023 /* Reset limits changed by blk_mq_update_nr_hw_queues(). */ ··· 2032 2024 segs = info->max_indirect_segments ? : BLKIF_MAX_SEGMENTS_PER_REQUEST; 2033 2025 blk_queue_max_segments(info->rq, segs / GRANTS_PER_PSEG); 2034 2026 2035 - for (r_index = 0; r_index < info->nr_rings; r_index++) { 2036 - struct blkfront_ring_info *rinfo = &info->rinfo[r_index]; 2037 - 2027 + for_each_rinfo(info, rinfo, r_index) { 2038 2028 rc = blkfront_setup_indirect(rinfo); 2039 2029 if (rc) 2040 2030 return rc; ··· 2042 2036 /* Now safe for us to use the shared ring */ 2043 2037 info->connected = BLKIF_STATE_CONNECTED; 2044 2038 2045 - for (r_index = 0; r_index < info->nr_rings; r_index++) { 2046 - struct blkfront_ring_info *rinfo; 2047 - 2048 - rinfo = &info->rinfo[r_index]; 2039 + for_each_rinfo(info, rinfo, r_index) { 2049 2040 /* Kick any other new requests queued since we resumed */ 2050 2041 kick_pending_request_queues(rinfo); 2051 2042 } ··· 2075 2072 struct blkfront_info *info = dev_get_drvdata(&dev->dev); 2076 2073 int err = 0; 2077 2074 unsigned int i, j; 2075 + struct blkfront_ring_info *rinfo; 2078 2076 2079 2077 dev_dbg(&dev->dev, "blkfront_resume: %s\n", dev->nodename); 2080 2078 2081 2079 bio_list_init(&info->bio_list); 2082 2080 INIT_LIST_HEAD(&info->requests); 2083 - for (i = 0; i < info->nr_rings; i++) { 2084 - struct blkfront_ring_info *rinfo = &info->rinfo[i]; 2081 + for_each_rinfo(info, rinfo, i) { 2085 2082 struct bio_list merge_bio; 2086 2083 struct blk_shadow *shadow = rinfo->shadow; 2087 2084 ··· 2340 2337 unsigned int binfo; 2341 2338 char *envp[] = { "RESIZE=1", NULL }; 2342 2339 int err, i; 2340 + struct blkfront_ring_info *rinfo; 2343 2341 2344 2342 switch (info->connected) { 2345 2343 case BLKIF_STATE_CONNECTED: ··· 2398 2394 "physical-sector-size", 2399 2395 sector_size); 2400 2396 blkfront_gather_backend_features(info); 2401 - for (i = 0; i < info->nr_rings; i++) { 2402 - err = blkfront_setup_indirect(&info->rinfo[i]); 2397 + for_each_rinfo(info, rinfo, i) { 2398 + err = blkfront_setup_indirect(rinfo); 2403 2399 if (err) { 2404 2400 xenbus_dev_fatal(info->xbdev, err, "setup_indirect at %s", 2405 2401 info->xbdev->otherend); ··· 2420 2416 2421 2417 /* Kick pending requests. */ 2422 2418 info->connected = BLKIF_STATE_CONNECTED; 2423 - for (i = 0; i < info->nr_rings; i++) 2424 - kick_pending_request_queues(&info->rinfo[i]); 2419 + for_each_rinfo(info, rinfo, i) 2420 + kick_pending_request_queues(rinfo); 2425 2421 2426 2422 device_add_disk(&info->xbdev->dev, info->gd, NULL); 2427 2423 ··· 2656 2652 { 2657 2653 unsigned int i; 2658 2654 unsigned long flags; 2655 + struct blkfront_ring_info *rinfo; 2659 2656 2660 - for (i = 0; i < info->nr_rings; i++) { 2661 - struct blkfront_ring_info *rinfo = &info->rinfo[i]; 2657 + for_each_rinfo(info, rinfo, i) { 2662 2658 struct grant *gnt_list_entry, *tmp; 2663 2659 2664 2660 spin_lock_irqsave(&rinfo->ring_lock, flags);
+1 -1
drivers/xen/xen-pciback/pciback.h
··· 52 52 unsigned int ack_intr:1; /* .. and ACK-ing */ 53 53 unsigned long handled; 54 54 unsigned int irq; /* Saved in case device transitions to MSI/MSI-X */ 55 - char irq_name[0]; /* xen-pcibk[000:04:00.0] */ 55 + char irq_name[]; /* xen-pcibk[000:04:00.0] */ 56 56 }; 57 57 58 58 /* Used by XenBus and xen_pcibk_ops.c */
+4
drivers/xen/xenbus/xenbus_comms.c
··· 313 313 req->msg.type = state.msg.type; 314 314 req->msg.len = state.msg.len; 315 315 req->body = state.body; 316 + /* write body, then update state */ 317 + virt_wmb(); 316 318 req->state = xb_req_state_got_reply; 317 319 req->cb(req); 318 320 } else ··· 397 395 if (state.req->state == xb_req_state_aborted) 398 396 kfree(state.req); 399 397 else { 398 + /* write err, then update state */ 399 + virt_wmb(); 400 400 state.req->state = xb_req_state_got_reply; 401 401 wake_up(&state.req->wq); 402 402 }
+5 -5
drivers/xen/xenbus/xenbus_probe.c
··· 239 239 goto fail; 240 240 } 241 241 242 - spin_lock(&dev->reclaim_lock); 242 + down(&dev->reclaim_sem); 243 243 err = drv->probe(dev, id); 244 - spin_unlock(&dev->reclaim_lock); 244 + up(&dev->reclaim_sem); 245 245 if (err) 246 246 goto fail_put; 247 247 ··· 271 271 free_otherend_watch(dev); 272 272 273 273 if (drv->remove) { 274 - spin_lock(&dev->reclaim_lock); 274 + down(&dev->reclaim_sem); 275 275 drv->remove(dev); 276 - spin_unlock(&dev->reclaim_lock); 276 + up(&dev->reclaim_sem); 277 277 } 278 278 279 279 module_put(drv->driver.owner); ··· 473 473 goto fail; 474 474 475 475 dev_set_name(&xendev->dev, "%s", devname); 476 - spin_lock_init(&xendev->reclaim_lock); 476 + sema_init(&xendev->reclaim_sem, 1); 477 477 478 478 /* Register with generic device framework. */ 479 479 err = device_register(&xendev->dev);
+3 -2
drivers/xen/xenbus/xenbus_probe_backend.c
··· 45 45 #include <linux/mm.h> 46 46 #include <linux/notifier.h> 47 47 #include <linux/export.h> 48 + #include <linux/semaphore.h> 48 49 49 50 #include <asm/page.h> 50 51 #include <asm/pgtable.h> ··· 258 257 drv = to_xenbus_driver(dev->driver); 259 258 if (drv && drv->reclaim_memory) { 260 259 xdev = to_xenbus_device(dev); 261 - if (!spin_trylock(&xdev->reclaim_lock)) 260 + if (down_trylock(&xdev->reclaim_sem)) 262 261 return 0; 263 262 drv->reclaim_memory(xdev); 264 - spin_unlock(&xdev->reclaim_lock); 263 + up(&xdev->reclaim_sem); 265 264 } 266 265 return 0; 267 266 }
+6 -3
drivers/xen/xenbus/xenbus_xs.c
··· 191 191 192 192 static bool test_reply(struct xb_req_data *req) 193 193 { 194 - if (req->state == xb_req_state_got_reply || !xenbus_ok()) 194 + if (req->state == xb_req_state_got_reply || !xenbus_ok()) { 195 + /* read req->state before all other fields */ 196 + virt_rmb(); 195 197 return true; 198 + } 196 199 197 200 /* Make sure to reread req->state each time. */ 198 201 barrier(); ··· 205 202 206 203 static void *read_reply(struct xb_req_data *req) 207 204 { 208 - while (req->state != xb_req_state_got_reply) { 205 + do { 209 206 wait_event(req->wq, test_reply(req)); 210 207 211 208 if (!xenbus_ok()) ··· 219 216 if (req->err) 220 217 return ERR_PTR(req->err); 221 218 222 - } 219 + } while (req->state != xb_req_state_got_reply); 223 220 224 221 return req->body; 225 222 }
+1 -1
include/xen/interface/io/tpmif.h
··· 46 46 uint8_t pad; 47 47 48 48 uint8_t nr_extra_pages; /* extra pages for long packets; may be zero */ 49 - uint32_t extra_pages[0]; /* grant IDs; length in nr_extra_pages */ 49 + uint32_t extra_pages[]; /* grant IDs; length in nr_extra_pages */ 50 50 }; 51 51 52 52 #endif
+2 -1
include/xen/xenbus.h
··· 42 42 #include <linux/completion.h> 43 43 #include <linux/init.h> 44 44 #include <linux/slab.h> 45 + #include <linux/semaphore.h> 45 46 #include <xen/interface/xen.h> 46 47 #include <xen/interface/grant_table.h> 47 48 #include <xen/interface/io/xenbus.h> ··· 77 76 enum xenbus_state state; 78 77 struct completion down; 79 78 struct work_struct work; 80 - spinlock_t reclaim_lock; 79 + struct semaphore reclaim_sem; 81 80 }; 82 81 83 82 static inline struct xenbus_device *to_xenbus_device(struct device *dev)