summaryrefslogtreecommitdiff
path: root/drivers/xen/xenbus/xenbus_probe_backend.c
diff options
context:
space:
mode:
authorSeongJae Park <sjpark@amazon.de>2020-01-27 11:18:09 +0300
committerBoris Ostrovsky <boris.ostrovsky@oracle.com>2020-01-29 16:35:49 +0300
commit060eabe8fbe726aca341b518366da4d79e338100 (patch)
treede0003cb6dc543be114115605aae0f3e518803ac /drivers/xen/xenbus/xenbus_probe_backend.c
parent8a105678fb3ec4763352db84745968bf2cb4aa65 (diff)
downloadlinux-060eabe8fbe726aca341b518366da4d79e338100.tar.xz
xenbus/backend: Protect xenbus callback with lock
A driver's 'reclaim_memory' callback can race with 'probe' or 'remove' because it will be called whenever memory pressure is detected. To avoid such race, this commit embeds a spinlock in each 'xenbus_device' and make 'xenbus' to hold the lock while the corresponded callbacks are running. Reviewed-by: Juergen Gross <jgross@suse.com> Signed-off-by: SeongJae Park <sjpark@amazon.de> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Diffstat (limited to 'drivers/xen/xenbus/xenbus_probe_backend.c')
-rw-r--r--drivers/xen/xenbus/xenbus_probe_backend.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/xen/xenbus/xenbus_probe_backend.c b/drivers/xen/xenbus/xenbus_probe_backend.c
index 3b5cb7a5a7e4..791f6fe01e91 100644
--- a/drivers/xen/xenbus/xenbus_probe_backend.c
+++ b/drivers/xen/xenbus/xenbus_probe_backend.c
@@ -250,12 +250,18 @@ static int backend_probe_and_watch(struct notifier_block *notifier,
static int backend_reclaim_memory(struct device *dev, void *data)
{
const struct xenbus_driver *drv;
+ struct xenbus_device *xdev;
if (!dev->driver)
return 0;
drv = to_xenbus_driver(dev->driver);
- if (drv && drv->reclaim_memory)
- drv->reclaim_memory(to_xenbus_device(dev));
+ if (drv && drv->reclaim_memory) {
+ xdev = to_xenbus_device(dev);
+ if (!spin_trylock(&xdev->reclaim_lock))
+ return 0;
+ drv->reclaim_memory(xdev);
+ spin_unlock(&xdev->reclaim_lock);
+ }
return 0;
}