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>
This commit is contained in:

committed by
Boris Ostrovsky

parent
8a105678fb
commit
060eabe8fb
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user