From: Paul Durrant <pdurrant@amazon.com>
To: <linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<xen-devel@lists.xenproject.org>
Cc: Paul Durrant <pdurrant@amazon.com>,
Jan Beulich <jbeulich@suse.com>,
"Boris Ostrovsky" <boris.ostrovsky@oracle.com>,
Juergen Gross <jgross@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: [PATCH v2 1/2] xen/xenbus: reference count registered modules
Date: Fri, 29 Nov 2019 13:43:05 +0000 [thread overview]
Message-ID: <20191129134306.2738-2-pdurrant@amazon.com> (raw)
In-Reply-To: <20191129134306.2738-1-pdurrant@amazon.com>
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
next prev parent reply other threads:[~2019-11-29 13:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2019-11-29 15:46 ` [PATCH v2 1/2] xen/xenbus: reference count registered modules 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ß
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191129134306.2738-2-pdurrant@amazon.com \
--to=pdurrant@amazon.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox