Skip to contentSkip to conversation

allow xen-blkback to be cleanly unloaded

PATCH Superseded Paul Durrant 4 participants 10 messages Nov 29, 2019

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover allow xen-blkback to be cleanly unloaded

Paul Durrant (2):
xen/xenbus: reference count registered modules block/xen-blkback: allow module to be cleanly unloaded

 drivers/block/xen-blkback/blkback.c |  8 ++++++++
 drivers/block/xen-blkback/common.h  |  3 +++
 drivers/block/xen-blkback/xenbus.c  | 11 +++++++++++
 drivers/xen/xenbus/xenbus_probe.c   |  8 +++++++-
 4 files changed, 29 insertions(+), 1 deletion(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/2 xen/xenbus: reference count registered modules

To prevent a module being removed whilst attached to a frontend, and hence xenbus calling into potentially invalid text, take a reference on the module before calling the probe() method (dropping it if unsuccessful) and drop the reference after returning from the remove() method.

NOTE: This allows the ad-hoc reference counting in xen-netback to be
removed. This will be done in a subsequent patch.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>

v2:
- New in v2

---
 drivers/xen/xenbus/xenbus_probe.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_probe.c +7 -1
index 5b471889d723..5a4947690500 100644
@@ -232,9 +232,11 @@ int xenbus_dev_probe(struct device *_dev)
 		return err;
 	}
 
+	__module_get(drv->driver.owner);
+
 	err = drv->probe(dev, id);
 	if (err)
-		goto fail;
+		goto fail_put;
 
 	err = watch_otherend(dev);
 	if (err) {
@@ -244,6 +246,8 @@ int xenbus_dev_probe(struct device *_dev)
 	}
 
 	return 0;
+fail_put:
+	module_put(drv->driver.owner);
 fail:
 	xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename);
 	xenbus_switch_state(dev, XenbusStateClosed);
@@ -263,6 +267,8 @@ int xenbus_dev_remove(struct device *_dev)
 	if (drv->remove)
 		drv->remove(dev);
 
+	module_put(drv->driver.owner);
+
 	free_otherend_details(dev);
 
 	xenbus_switch_state(dev, XenbusStateClosed);
Signature · 1 line
2.20.1
maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] xen/xenbus: reference count registered modules

Quoted 10 lines · Paul Durrant

To prevent a module being removed whilst attached to a frontend, and hence xenbus calling into potentially invalid text, take a reference on the module before calling the probe() method (dropping it if unsuccessful) and drop the reference after returning from the remove() method.

NOTE: This allows the ad-hoc reference counting in xen-netback to be
removed. This will be done in a subsequent patch.

Juergen

#3 lore raw

Re: [PATCH v2 1/2] xen/xenbus: reference count registered modules

In reply to Paul Durrant
Quoted 1 line · Paul Durrant

To prevent a module being removed whilst attached to a frontend, and

Why only frontend?

Quoted 13 lines

hence xenbus calling into potentially invalid text, take a reference on the module before calling the probe() method (dropping it if unsuccessful) and drop the reference after returning from the remove() method.

NOTE: This allows the ad-hoc reference counting in xen-netback to be
removed. This will be done in a subsequent patch.

drivers/xen/xenbus/xenbus_probe.c int xenbus_dev_probe(struct device *_dev) · line 235

Quoted 4 lines
drivers/xen/xenbus/xenbus_probe.c +1 -0
@@ -232,9 +232,11 @@ int xenbus_dev_probe(struct device *_dev)
 		return err;
 	}
 
+	__module_get(drv->driver.owner);

I guess you really want try_module_get() and deal with it returning false.

Jan

#4 lore raw

RE: [PATCH v2 1/2] xen/xenbus: reference count registered modules

Quoted 9 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 29 November 2019 16:01
To: Durrant, Paul <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; Stefano Stabellini <[email protected]>; Boris Ostrovsky <[email protected]>; Juergen Gross <[email protected]>
Subject: Re: [PATCH v2 1/2] xen/xenbus: reference count registered modules

Quoted 5 lines
Quoted 1 line · Paul Durrant

To prevent a module being removed whilst attached to a frontend, and

Why only frontend?

True. Originally this was only intended for backends, but I guess this should now be 'otherend' or some equivalent form of words.

Quoted 17 lines
Quoted 2 lines

hence xenbus calling into potentially invalid text, take a reference on the module before calling the probe() method (dropping it if

unsuccessful)

Quoted 14 lines

and drop the reference after returning from the remove() method.

NOTE: This allows the ad-hoc reference counting in xen-netback to be
removed. This will be done in a subsequent patch.

drivers/xen/xenbus/xenbus_probe.c +0 -0
@@ -232,9 +232,11 @@ int xenbus_dev_probe(struct device *_dev)
 		return err;
 	}
 
Quoted 5 lines

drivers/xen/xenbus/xenbus_probe.c int xenbus_dev_probe(struct device *_dev) · line 235

Quoted 1 line
drivers/xen/xenbus/xenbus_probe.c +1 -0
+	__module_get(drv->driver.owner);

I guess you really want try_module_get() and deal with it returning false.

Perhaps, yes.

Paul

Quoted 1 line

Jan

#5 lore raw

PATCH v2 2/2 block/xen-blkback: allow module to be cleanly unloaded

In reply to Paul Durrant

Add a module_exit() to perform the necessary clean-up.

---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Jens Axboe <[email protected]>

v2:
- Drop the addition of ad-hoc reference counting as this is now done centrally in xenbus

---
 drivers/block/xen-blkback/blkback.c |  8 ++++++++
 drivers/block/xen-blkback/common.h  |  3 +++
 drivers/block/xen-blkback/xenbus.c  | 11 +++++++++++
 3 files changed, 22 insertions(+)
drivers/block/xen-blkback/blkback.c +8 -0
index fd1e19f1a49f..e562a7e20c3c 100644
@@ -1504,5 +1504,13 @@ static int __init xen_blkif_init(void)
 
 module_init(xen_blkif_init);
 
+static void __exit xen_blkif_fini(void)
+{
+	xen_blkif_xenbus_fini();
+	xen_blkif_interface_fini();
+}
+
+module_exit(xen_blkif_fini);
+
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_ALIAS("xen-backend:vbd");
drivers/block/xen-blkback/common.h +3 -0
index 1d3002d773f7..49132b0adbbe 100644
@@ -375,9 +375,12 @@ struct phys_req {
 	struct block_device	*bdev;
 	blkif_sector_t		sector_number;
 };
+
 int xen_blkif_interface_init(void);
+void xen_blkif_interface_fini(void);
 
 int xen_blkif_xenbus_init(void);
+void xen_blkif_xenbus_fini(void);
 
 irqreturn_t xen_blkif_be_int(int irq, void *dev_id);
 int xen_blkif_schedule(void *arg);
drivers/block/xen-blkback/xenbus.c +11 -0
index b90dbcd99c03..e8c5c54e1d26 100644
@@ -333,6 +333,12 @@ int __init xen_blkif_interface_init(void)
 	return 0;
 }
 
+void xen_blkif_interface_fini(void)
+{
+	kmem_cache_destroy(xen_blkif_cachep);
+	xen_blkif_cachep = NULL;
+}
+
 /*
  *  sysfs interface for VBD I/O requests
  */
@@ -1122,3 +1128,8 @@ int xen_blkif_xenbus_init(void)
 {
 	return xenbus_register_backend(&xen_blkbk_driver);
 }
+
+void xen_blkif_xenbus_fini(void)
+{
+	xenbus_unregister_driver(&xen_blkbk_driver);
+}
Signature · 1 line
2.20.1
Reviewed-by on v2 2/2
#6 lore raw

Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded

Quoted 3 lines · Paul Durrant

Add a module_exit() to perform the necessary clean-up.

LGTM:

AFAICT we should make sure this is not committed before patch 1, or else you could unload a blkback module that's still in use?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

RE: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded

Quoted 10 lines

-----Original Message-----
From: Roger Pau Monné <[email protected]>
Sent: 29 November 2019 15:00
To: Durrant, Paul <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Konrad Rzeszutek Wilk <[email protected]>; Jens Axboe <[email protected]>
Subject: Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded

Quoted 9 lines
Quoted 3 lines · Paul Durrant

Add a module_exit() to perform the necessary clean-up.

LGTM:

Thanks.

Quoted 3 lines

AFAICT we should make sure this is not committed before patch 1, or else you could unload a blkback module that's still in use?

Yes, that's correct.

Paul

#8 lore raw

Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded

Quoted 20 lines · Paul
Quoted 10 lines

-----Original Message-----
From: Roger Pau Monné <[email protected]>
Sent: 29 November 2019 15:00
To: Durrant, Paul <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Konrad Rzeszutek Wilk <[email protected]>; Jens Axboe <[email protected]>
Subject: Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded

Quoted 9 lines
Quoted 3 lines · Paul Durrant

Add a module_exit() to perform the necessary clean-up.

LGTM:

Quoted 7 lines

Thanks.

Quoted 3 lines

AFAICT we should make sure this is not committed before patch 1, or else you could unload a blkback module that's still in use?

Yes, that's correct.

Given this is a very small change, and not really block related I think it would be better for both patches to be committed from the Xen tree, if Jens, Juergen and Boris agree.

Thanks, Roger.

maintainer Reviewed-by
#9 lore raw

Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded

Quoted 27 lines · Roger Pau Monné
Quoted 26 lines · Paul
Quoted 10 lines

-----Original Message-----
From: Roger Pau Monné <[email protected]>
Sent: 29 November 2019 15:00
To: Durrant, Paul <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Konrad Rzeszutek Wilk <[email protected]>; Jens Axboe <[email protected]>
Subject: Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded

Quoted 9 lines
Quoted 3 lines · Paul Durrant

Add a module_exit() to perform the necessary clean-up.

LGTM:

Thanks.

Quoted 3 lines

AFAICT we should make sure this is not committed before patch 1, or else you could unload a blkback module that's still in use?

Quoted 5 lines
Quoted 1 line

Yes, that's correct.

Given this is a very small change, and not really block related I think it would be better for both patches to be committed from the Xen tree, if Jens, Juergen and Boris agree.

I'm fine with that.

And:

Juergen