linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] allow xen-blkback to be cleanly unloaded
@ 2019-11-29 13:43 Paul Durrant
  2019-11-29 13:43 ` [PATCH v2 1/2] xen/xenbus: reference count registered modules Paul Durrant
  2019-11-29 13:43 ` [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded Paul Durrant
  0 siblings, 2 replies; 10+ messages in thread
From: Paul Durrant @ 2019-11-29 13:43 UTC (permalink / raw)
  To: linux-block, linux-kernel, xen-devel; +Cc: Paul Durrant

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(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/2] xen/xenbus: reference count registered modules
  2019-11-29 13:43 [PATCH v2 0/2] allow xen-blkback to be cleanly unloaded Paul Durrant
@ 2019-11-29 13:43 ` Paul Durrant
  2019-11-29 15:46   ` Jürgen Groß
  2019-11-29 16:00   ` Jan Beulich
  2019-11-29 13:43 ` [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded Paul Durrant
  1 sibling, 2 replies; 10+ messages in thread
From: Paul Durrant @ 2019-11-29 13:43 UTC (permalink / raw)
  To: linux-block, linux-kernel, xen-devel
  Cc: Paul Durrant, Jan Beulich, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini

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.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>

v2:
 - New in v2
---
 drivers/xen/xenbus/xenbus_probe.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 5b471889d723..5a4947690500 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -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);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded
  2019-11-29 13:43 [PATCH v2 0/2] allow xen-blkback to be cleanly unloaded Paul Durrant
  2019-11-29 13:43 ` [PATCH v2 1/2] xen/xenbus: reference count registered modules Paul Durrant
@ 2019-11-29 13:43 ` Paul Durrant
  2019-11-29 15:00   ` Roger Pau Monné
  1 sibling, 1 reply; 10+ messages in thread
From: Paul Durrant @ 2019-11-29 13:43 UTC (permalink / raw)
  To: linux-block, linux-kernel, xen-devel
  Cc: Paul Durrant, Konrad Rzeszutek Wilk, Roger Pau Monné, Jens Axboe

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

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Jens Axboe <axboe@kernel.dk>

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(+)

diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index fd1e19f1a49f..e562a7e20c3c 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -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");
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h
index 1d3002d773f7..49132b0adbbe 100644
--- a/drivers/block/xen-blkback/common.h
+++ b/drivers/block/xen-blkback/common.h
@@ -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);
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index b90dbcd99c03..e8c5c54e1d26 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -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);
+}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded
  2019-11-29 13:43 ` [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded Paul Durrant
@ 2019-11-29 15:00   ` Roger Pau Monné
  2019-11-29 15:02     ` Durrant, Paul
  0 siblings, 1 reply; 10+ messages in thread
From: Roger Pau Monné @ 2019-11-29 15:00 UTC (permalink / raw)
  To: Paul Durrant
  Cc: linux-block, linux-kernel, xen-devel, Konrad Rzeszutek Wilk, Jens Axboe

On Fri, Nov 29, 2019 at 01:43:06PM +0000, Paul Durrant wrote:
> Add a module_exit() to perform the necessary clean-up.
> 
> Signed-off-by: Paul Durrant <pdurrant@amazon.com>

LGTM:

Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded
  2019-11-29 15:00   ` Roger Pau Monné
@ 2019-11-29 15:02     ` Durrant, Paul
  2019-11-29 15:07       ` Roger Pau Monné
  0 siblings, 1 reply; 10+ messages in thread
From: Durrant, Paul @ 2019-11-29 15:02 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: linux-block, linux-kernel, xen-devel, Konrad Rzeszutek Wilk, Jens Axboe

> -----Original Message-----
> From: Roger Pau Monné <roger.pau@citrix.com>
> Sent: 29 November 2019 15:00
> To: Durrant, Paul <pdurrant@amazon.com>
> Cc: linux-block@vger.kernel.org; linux-kernel@vger.kernel.org; xen-
> devel@lists.xenproject.org; Konrad Rzeszutek Wilk
> <konrad.wilk@oracle.com>; Jens Axboe <axboe@kernel.dk>
> Subject: Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly
> unloaded
> 
> On Fri, Nov 29, 2019 at 01:43:06PM +0000, Paul Durrant wrote:
> > Add a module_exit() to perform the necessary clean-up.
> >
> > Signed-off-by: Paul Durrant <pdurrant@amazon.com>
> 
> LGTM:
> 
> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
> 

Thanks.

> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded
  2019-11-29 15:02     ` Durrant, Paul
@ 2019-11-29 15:07       ` Roger Pau Monné
  2019-11-29 15:45         ` Jürgen Groß
  0 siblings, 1 reply; 10+ messages in thread
From: Roger Pau Monné @ 2019-11-29 15:07 UTC (permalink / raw)
  To: Durrant, Paul
  Cc: linux-block, linux-kernel, xen-devel, Konrad Rzeszutek Wilk,
	Jens Axboe, Juergen Gross, boris.ostrovsky

On Fri, Nov 29, 2019 at 03:02:37PM +0000, Durrant, Paul wrote:
> > -----Original Message-----
> > From: Roger Pau Monné <roger.pau@citrix.com>
> > Sent: 29 November 2019 15:00
> > To: Durrant, Paul <pdurrant@amazon.com>
> > Cc: linux-block@vger.kernel.org; linux-kernel@vger.kernel.org; xen-
> > devel@lists.xenproject.org; Konrad Rzeszutek Wilk
> > <konrad.wilk@oracle.com>; Jens Axboe <axboe@kernel.dk>
> > Subject: Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly
> > unloaded
> > 
> > On Fri, Nov 29, 2019 at 01:43:06PM +0000, Paul Durrant wrote:
> > > Add a module_exit() to perform the necessary clean-up.
> > >
> > > Signed-off-by: Paul Durrant <pdurrant@amazon.com>
> > 
> > LGTM:
> > 
> > Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
> > 
> 
> Thanks.
> 
> > 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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded
  2019-11-29 15:07       ` Roger Pau Monné
@ 2019-11-29 15:45         ` Jürgen Groß
  0 siblings, 0 replies; 10+ messages in thread
From: Jürgen Groß @ 2019-11-29 15:45 UTC (permalink / raw)
  To: Roger Pau Monné, Durrant, Paul
  Cc: linux-block, linux-kernel, xen-devel, Konrad Rzeszutek Wilk,
	Jens Axboe, boris.ostrovsky

On 29.11.19 16:07, Roger Pau Monné wrote:
> On Fri, Nov 29, 2019 at 03:02:37PM +0000, Durrant, Paul wrote:
>>> -----Original Message-----
>>> From: Roger Pau Monné <roger.pau@citrix.com>
>>> Sent: 29 November 2019 15:00
>>> To: Durrant, Paul <pdurrant@amazon.com>
>>> Cc: linux-block@vger.kernel.org; linux-kernel@vger.kernel.org; xen-
>>> devel@lists.xenproject.org; Konrad Rzeszutek Wilk
>>> <konrad.wilk@oracle.com>; Jens Axboe <axboe@kernel.dk>
>>> Subject: Re: [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly
>>> unloaded
>>>
>>> On Fri, Nov 29, 2019 at 01:43:06PM +0000, Paul Durrant wrote:
>>>> Add a module_exit() to perform the necessary clean-up.
>>>>
>>>> Signed-off-by: Paul Durrant <pdurrant@amazon.com>
>>>
>>> LGTM:
>>>
>>> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
>>>
>>
>> Thanks.
>>
>>> 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.

I'm fine with that.

And:

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] xen/xenbus: reference count registered modules
  2019-11-29 13:43 ` [PATCH v2 1/2] xen/xenbus: reference count registered modules Paul Durrant
@ 2019-11-29 15:46   ` Jürgen Groß
  2019-11-29 16:00   ` Jan Beulich
  1 sibling, 0 replies; 10+ messages in thread
From: Jürgen Groß @ 2019-11-29 15:46 UTC (permalink / raw)
  To: Paul Durrant, linux-block, linux-kernel, xen-devel
  Cc: Jan Beulich, Boris Ostrovsky, Stefano Stabellini

On 29.11.19 14:43, Paul Durrant wrote:
> 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.
> 
> Suggested-by: Jan Beulich <jbeulich@suse.com>
> Signed-off-by: Paul Durrant <pdurrant@amazon.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] xen/xenbus: reference count registered modules
  2019-11-29 13:43 ` [PATCH v2 1/2] xen/xenbus: reference count registered modules Paul Durrant
  2019-11-29 15:46   ` Jürgen Groß
@ 2019-11-29 16:00   ` Jan Beulich
  2019-11-29 16:08     ` Durrant, Paul
  1 sibling, 1 reply; 10+ messages in thread
From: Jan Beulich @ 2019-11-29 16:00 UTC (permalink / raw)
  To: Paul Durrant
  Cc: xen-devel, linux-block, linux-kernel, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross

On 29.11.2019 14:43, Paul Durrant wrote:
> To prevent a module being removed whilst attached to a frontend, and

Why only frontend?

> 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.
> 
> Suggested-by: Jan Beulich <jbeulich@suse.com>
> Signed-off-by: Paul Durrant <pdurrant@amazon.com>
> 
> --- a/drivers/xen/xenbus/xenbus_probe.c
> +++ b/drivers/xen/xenbus/xenbus_probe.c
> @@ -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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH v2 1/2] xen/xenbus: reference count registered modules
  2019-11-29 16:00   ` Jan Beulich
@ 2019-11-29 16:08     ` Durrant, Paul
  0 siblings, 0 replies; 10+ messages in thread
From: Durrant, Paul @ 2019-11-29 16:08 UTC (permalink / raw)
  To: Jan Beulich
  Cc: xen-devel, linux-block, linux-kernel, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross

> -----Original Message-----
> From: Jan Beulich <jbeulich@suse.com>
> Sent: 29 November 2019 16:01
> To: Durrant, Paul <pdurrant@amazon.com>
> Cc: xen-devel@lists.xenproject.org; linux-block@vger.kernel.org; linux-
> kernel@vger.kernel.org; Stefano Stabellini <sstabellini@kernel.org>; Boris
> Ostrovsky <boris.ostrovsky@oracle.com>; Juergen Gross <jgross@suse.com>
> Subject: Re: [PATCH v2 1/2] xen/xenbus: reference count registered modules
> 
> On 29.11.2019 14:43, Paul Durrant wrote:
> > 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.

> > 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.
> >
> > Suggested-by: Jan Beulich <jbeulich@suse.com>
> > Signed-off-by: Paul Durrant <pdurrant@amazon.com>
> >
> > --- a/drivers/xen/xenbus/xenbus_probe.c
> > +++ b/drivers/xen/xenbus/xenbus_probe.c
> > @@ -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.
> 

Perhaps, yes.

  Paul

> Jan

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-11-29 16:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-29 13:43 [PATCH v2 0/2] allow xen-blkback to be cleanly unloaded Paul Durrant
2019-11-29 13:43 ` [PATCH v2 1/2] xen/xenbus: reference count registered modules Paul Durrant
2019-11-29 15:46   ` Jürgen Groß
2019-11-29 16:00   ` Jan Beulich
2019-11-29 16:08     ` Durrant, Paul
2019-11-29 13:43 ` [PATCH v2 2/2] block/xen-blkback: allow module to be cleanly unloaded Paul Durrant
2019-11-29 15:00   ` Roger Pau Monné
2019-11-29 15:02     ` Durrant, Paul
2019-11-29 15:07       ` Roger Pau Monné
2019-11-29 15:45         ` Jürgen Groß

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).