Skip to content

Commit f74fd13

Browse files
committed
Merge tag 'for-linus-5.5b-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull more xen updates from Juergen Gross: - a patch to fix a build warning - a cleanup of no longer needed code in the Xen event handling - a small series for the Xen grant driver avoiding high order allocations and replacing an insane global limit by a per-call one - a small series fixing Xen frontend/backend module referencing * tag 'for-linus-5.5b-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: xen-blkback: allow module to be cleanly unloaded xen/xenbus: reference count registered modules xen/gntdev: switch from kcalloc() to kvcalloc() xen/gntdev: replace global limit of mapped pages by limit per call xen/gntdev: remove redundant non-zero check on ret xen/events: remove event handling recursion detection
2 parents 6dc517a + 1485595 commit f74fd13

File tree

8 files changed

+66
-62
lines changed

8 files changed

+66
-62
lines changed

drivers/block/xen-blkback/blkback.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,5 +1506,13 @@ static int __init xen_blkif_init(void)
15061506

15071507
module_init(xen_blkif_init);
15081508

1509+
static void __exit xen_blkif_fini(void)
1510+
{
1511+
xen_blkif_xenbus_fini();
1512+
xen_blkif_interface_fini();
1513+
}
1514+
1515+
module_exit(xen_blkif_fini);
1516+
15091517
MODULE_LICENSE("Dual BSD/GPL");
15101518
MODULE_ALIAS("xen-backend:vbd");

drivers/block/xen-blkback/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,12 @@ struct phys_req {
375375
struct block_device *bdev;
376376
blkif_sector_t sector_number;
377377
};
378+
378379
int xen_blkif_interface_init(void);
380+
void xen_blkif_interface_fini(void);
379381

380382
int xen_blkif_xenbus_init(void);
383+
void xen_blkif_xenbus_fini(void);
381384

382385
irqreturn_t xen_blkif_be_int(int irq, void *dev_id);
383386
int xen_blkif_schedule(void *arg);

drivers/block/xen-blkback/xenbus.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ int __init xen_blkif_interface_init(void)
333333
return 0;
334334
}
335335

336+
void xen_blkif_interface_fini(void)
337+
{
338+
kmem_cache_destroy(xen_blkif_cachep);
339+
xen_blkif_cachep = NULL;
340+
}
341+
336342
/*
337343
* sysfs interface for VBD I/O requests
338344
*/
@@ -1122,3 +1128,8 @@ int xen_blkif_xenbus_init(void)
11221128
{
11231129
return xenbus_register_backend(&xen_blkbk_driver);
11241130
}
1131+
1132+
void xen_blkif_xenbus_fini(void)
1133+
{
1134+
xenbus_unregister_driver(&xen_blkbk_driver);
1135+
}

drivers/xen/events/events_base.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,31 +1213,21 @@ void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector)
12131213
notify_remote_via_irq(irq);
12141214
}
12151215

1216-
static DEFINE_PER_CPU(unsigned, xed_nesting_count);
1217-
12181216
static void __xen_evtchn_do_upcall(void)
12191217
{
12201218
struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu);
1221-
int cpu = get_cpu();
1222-
unsigned count;
1219+
int cpu = smp_processor_id();
12231220

12241221
do {
12251222
vcpu_info->evtchn_upcall_pending = 0;
12261223

1227-
if (__this_cpu_inc_return(xed_nesting_count) - 1)
1228-
goto out;
1229-
12301224
xen_evtchn_handle_events(cpu);
12311225

12321226
BUG_ON(!irqs_disabled());
12331227

1234-
count = __this_cpu_read(xed_nesting_count);
1235-
__this_cpu_write(xed_nesting_count, 0);
1236-
} while (count != 1 || vcpu_info->evtchn_upcall_pending);
1237-
1238-
out:
1228+
virt_rmb(); /* Hypervisor can set upcall pending. */
12391229

1240-
put_cpu();
1230+
} while (vcpu_info->evtchn_upcall_pending);
12411231
}
12421232

12431233
void xen_evtchn_do_upcall(struct pt_regs *regs)

drivers/xen/gntdev-common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void gntdev_add_map(struct gntdev_priv *priv, struct gntdev_grant_map *add);
8181

8282
void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map);
8383

84-
bool gntdev_account_mapped_pages(int count);
84+
bool gntdev_test_page_count(unsigned int count);
8585

8686
int gntdev_map_grant_pages(struct gntdev_grant_map *map);
8787

drivers/xen/gntdev-dmabuf.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ dmabuf_exp_alloc_backing_storage(struct gntdev_priv *priv, int dmabuf_flags,
446446
{
447447
struct gntdev_grant_map *map;
448448

449-
if (unlikely(count <= 0))
449+
if (unlikely(gntdev_test_page_count(count)))
450450
return ERR_PTR(-EINVAL);
451451

452452
if ((dmabuf_flags & GNTDEV_DMA_FLAG_WC) &&
@@ -459,11 +459,6 @@ dmabuf_exp_alloc_backing_storage(struct gntdev_priv *priv, int dmabuf_flags,
459459
if (!map)
460460
return ERR_PTR(-ENOMEM);
461461

462-
if (unlikely(gntdev_account_mapped_pages(count))) {
463-
pr_debug("can't map %d pages: over limit\n", count);
464-
gntdev_put_map(NULL, map);
465-
return ERR_PTR(-ENOMEM);
466-
}
467462
return map;
468463
}
469464

@@ -771,7 +766,7 @@ long gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv, int use_ptemod,
771766
if (copy_from_user(&op, u, sizeof(op)) != 0)
772767
return -EFAULT;
773768

774-
if (unlikely(op.count <= 0))
769+
if (unlikely(gntdev_test_page_count(op.count)))
775770
return -EINVAL;
776771

777772
refs = kcalloc(op.count, sizeof(*refs), GFP_KERNEL);
@@ -818,7 +813,7 @@ long gntdev_ioctl_dmabuf_imp_to_refs(struct gntdev_priv *priv,
818813
if (copy_from_user(&op, u, sizeof(op)) != 0)
819814
return -EFAULT;
820815

821-
if (unlikely(op.count <= 0))
816+
if (unlikely(gntdev_test_page_count(op.count)))
822817
return -EINVAL;
823818

824819
gntdev_dmabuf = dmabuf_imp_to_refs(priv->dmabuf_priv,

drivers/xen/gntdev.c

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ MODULE_AUTHOR("Derek G. Murray <[email protected]>, "
5555
"Gerd Hoffmann <[email protected]>");
5656
MODULE_DESCRIPTION("User-space granted page access driver");
5757

58-
static int limit = 1024*1024;
59-
module_param(limit, int, 0644);
60-
MODULE_PARM_DESC(limit, "Maximum number of grants that may be mapped by "
61-
"the gntdev device");
62-
63-
static atomic_t pages_mapped = ATOMIC_INIT(0);
58+
static unsigned int limit = 64*1024;
59+
module_param(limit, uint, 0644);
60+
MODULE_PARM_DESC(limit,
61+
"Maximum number of grants that may be mapped by one mapping request");
6462

6563
static int use_ptemod;
6664

@@ -71,9 +69,9 @@ static struct miscdevice gntdev_miscdev;
7169

7270
/* ------------------------------------------------------------------ */
7371

74-
bool gntdev_account_mapped_pages(int count)
72+
bool gntdev_test_page_count(unsigned int count)
7573
{
76-
return atomic_add_return(count, &pages_mapped) > limit;
74+
return !count || count > limit;
7775
}
7876

7977
static void gntdev_print_maps(struct gntdev_priv *priv,
@@ -114,14 +112,14 @@ static void gntdev_free_map(struct gntdev_grant_map *map)
114112
gnttab_free_pages(map->count, map->pages);
115113

116114
#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
117-
kfree(map->frames);
115+
kvfree(map->frames);
118116
#endif
119-
kfree(map->pages);
120-
kfree(map->grants);
121-
kfree(map->map_ops);
122-
kfree(map->unmap_ops);
123-
kfree(map->kmap_ops);
124-
kfree(map->kunmap_ops);
117+
kvfree(map->pages);
118+
kvfree(map->grants);
119+
kvfree(map->map_ops);
120+
kvfree(map->unmap_ops);
121+
kvfree(map->kmap_ops);
122+
kvfree(map->kunmap_ops);
125123
kfree(map);
126124
}
127125

@@ -135,12 +133,13 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
135133
if (NULL == add)
136134
return NULL;
137135

138-
add->grants = kcalloc(count, sizeof(add->grants[0]), GFP_KERNEL);
139-
add->map_ops = kcalloc(count, sizeof(add->map_ops[0]), GFP_KERNEL);
140-
add->unmap_ops = kcalloc(count, sizeof(add->unmap_ops[0]), GFP_KERNEL);
141-
add->kmap_ops = kcalloc(count, sizeof(add->kmap_ops[0]), GFP_KERNEL);
142-
add->kunmap_ops = kcalloc(count, sizeof(add->kunmap_ops[0]), GFP_KERNEL);
143-
add->pages = kcalloc(count, sizeof(add->pages[0]), GFP_KERNEL);
136+
add->grants = kvcalloc(count, sizeof(add->grants[0]), GFP_KERNEL);
137+
add->map_ops = kvcalloc(count, sizeof(add->map_ops[0]), GFP_KERNEL);
138+
add->unmap_ops = kvcalloc(count, sizeof(add->unmap_ops[0]), GFP_KERNEL);
139+
add->kmap_ops = kvcalloc(count, sizeof(add->kmap_ops[0]), GFP_KERNEL);
140+
add->kunmap_ops = kvcalloc(count,
141+
sizeof(add->kunmap_ops[0]), GFP_KERNEL);
142+
add->pages = kvcalloc(count, sizeof(add->pages[0]), GFP_KERNEL);
144143
if (NULL == add->grants ||
145144
NULL == add->map_ops ||
146145
NULL == add->unmap_ops ||
@@ -159,8 +158,8 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
159158
if (dma_flags & (GNTDEV_DMA_FLAG_WC | GNTDEV_DMA_FLAG_COHERENT)) {
160159
struct gnttab_dma_alloc_args args;
161160

162-
add->frames = kcalloc(count, sizeof(add->frames[0]),
163-
GFP_KERNEL);
161+
add->frames = kvcalloc(count, sizeof(add->frames[0]),
162+
GFP_KERNEL);
164163
if (!add->frames)
165164
goto err;
166165

@@ -241,8 +240,6 @@ void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map)
241240
if (!refcount_dec_and_test(&map->users))
242241
return;
243242

244-
atomic_sub(map->count, &pages_mapped);
245-
246243
if (map->notify.flags & UNMAP_NOTIFY_SEND_EVENT) {
247244
notify_remote_via_evtchn(map->notify.event);
248245
evtchn_put(map->notify.event);
@@ -506,7 +503,6 @@ static const struct mmu_interval_notifier_ops gntdev_mmu_ops = {
506503
static int gntdev_open(struct inode *inode, struct file *flip)
507504
{
508505
struct gntdev_priv *priv;
509-
int ret = 0;
510506

511507
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
512508
if (!priv)
@@ -518,16 +514,12 @@ static int gntdev_open(struct inode *inode, struct file *flip)
518514
#ifdef CONFIG_XEN_GNTDEV_DMABUF
519515
priv->dmabuf_priv = gntdev_dmabuf_init(flip);
520516
if (IS_ERR(priv->dmabuf_priv)) {
521-
ret = PTR_ERR(priv->dmabuf_priv);
522-
kfree(priv);
523-
return ret;
524-
}
525-
#endif
517+
int ret = PTR_ERR(priv->dmabuf_priv);
526518

527-
if (ret) {
528519
kfree(priv);
529520
return ret;
530521
}
522+
#endif
531523

532524
flip->private_data = priv;
533525
#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
@@ -573,20 +565,14 @@ static long gntdev_ioctl_map_grant_ref(struct gntdev_priv *priv,
573565
if (copy_from_user(&op, u, sizeof(op)) != 0)
574566
return -EFAULT;
575567
pr_debug("priv %p, add %d\n", priv, op.count);
576-
if (unlikely(op.count <= 0))
568+
if (unlikely(gntdev_test_page_count(op.count)))
577569
return -EINVAL;
578570

579571
err = -ENOMEM;
580572
map = gntdev_alloc_map(priv, op.count, 0 /* This is not a dma-buf. */);
581573
if (!map)
582574
return err;
583575

584-
if (unlikely(gntdev_account_mapped_pages(op.count))) {
585-
pr_debug("can't map: over limit\n");
586-
gntdev_put_map(NULL, map);
587-
return err;
588-
}
589-
590576
if (copy_from_user(map->grants, &u->refs,
591577
sizeof(map->grants[0]) * op.count) != 0) {
592578
gntdev_put_map(NULL, map);

drivers/xen/xenbus/xenbus_probe.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,16 @@ int xenbus_dev_probe(struct device *_dev)
232232
return err;
233233
}
234234

235+
if (!try_module_get(drv->driver.owner)) {
236+
dev_warn(&dev->dev, "failed to acquire module reference on '%s'\n",
237+
drv->driver.name);
238+
err = -ESRCH;
239+
goto fail;
240+
}
241+
235242
err = drv->probe(dev, id);
236243
if (err)
237-
goto fail;
244+
goto fail_put;
238245

239246
err = watch_otherend(dev);
240247
if (err) {
@@ -244,6 +251,8 @@ int xenbus_dev_probe(struct device *_dev)
244251
}
245252

246253
return 0;
254+
fail_put:
255+
module_put(drv->driver.owner);
247256
fail:
248257
xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename);
249258
xenbus_switch_state(dev, XenbusStateClosed);
@@ -263,6 +272,8 @@ int xenbus_dev_remove(struct device *_dev)
263272
if (drv->remove)
264273
drv->remove(dev);
265274

275+
module_put(drv->driver.owner);
276+
266277
free_otherend_details(dev);
267278

268279
xenbus_switch_state(dev, XenbusStateClosed);

0 commit comments

Comments
 (0)