Skip to content

Commit fc9be61

Browse files
sjp38jgross1
authored andcommitted
xen-blkback: fix persistent grants negotiation
Persistent grants feature can be used only when both backend and the frontend supports the feature. The feature was always supported by 'blkback', but commit aac8a70 ("xen-blkback: add a parameter for disabling of persistent grants") has introduced a parameter for disabling it runtime. To avoid the parameter be updated while being used by 'blkback', the commit caches the parameter into 'vbd->feature_gnt_persistent' in 'xen_vbd_create()', and then check if the guest also supports the feature and finally updates the field in 'connect_ring()'. However, 'connect_ring()' could be called before 'xen_vbd_create()', so later execution of 'xen_vbd_create()' can wrongly overwrite 'true' to 'vbd->feature_gnt_persistent'. As a result, 'blkback' could try to use 'persistent grants' feature even if the guest doesn't support the feature. This commit fixes the issue by moving the parameter value caching to 'xen_blkif_alloc()', which allocates the 'blkif'. Because the struct embeds 'vbd' object, which will be used by 'connect_ring()' later, this should be called before 'connect_ring()' and therefore this should be the right and safe place to do the caching. Fixes: aac8a70 ("xen-blkback: add a parameter for disabling of persistent grants") Cc: <stable@vger.kernel.org> # 5.10.x Signed-off-by: Maximilian Heyne <mheyne@amazon.de> Signed-off-by: SeongJae Park <sj@kernel.org> Reviewed-by: Maximilian Heyne <mheyne@amazon.de> Reviewed-by: Juergen Gross <jgross@suse.com> Link: https://lore.kernel.org/r/20220715225108.193398-2-sj@kernel.org Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent b1c3497 commit fc9be61

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

drivers/block/xen-blkback/xenbus.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ static int xen_blkif_alloc_rings(struct xen_blkif *blkif)
157157
return 0;
158158
}
159159

160+
/* Enable the persistent grants feature. */
161+
static bool feature_persistent = true;
162+
module_param(feature_persistent, bool, 0644);
163+
MODULE_PARM_DESC(feature_persistent, "Enables the persistent grants feature");
164+
160165
static struct xen_blkif *xen_blkif_alloc(domid_t domid)
161166
{
162167
struct xen_blkif *blkif;
@@ -181,6 +186,8 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
181186
__module_get(THIS_MODULE);
182187
INIT_WORK(&blkif->free_work, xen_blkif_deferred_free);
183188

189+
blkif->vbd.feature_gnt_persistent = feature_persistent;
190+
184191
return blkif;
185192
}
186193

@@ -472,12 +479,6 @@ static void xen_vbd_free(struct xen_vbd *vbd)
472479
vbd->bdev = NULL;
473480
}
474481

475-
/* Enable the persistent grants feature. */
476-
static bool feature_persistent = true;
477-
module_param(feature_persistent, bool, 0644);
478-
MODULE_PARM_DESC(feature_persistent,
479-
"Enables the persistent grants feature");
480-
481482
static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
482483
unsigned major, unsigned minor, int readonly,
483484
int cdrom)
@@ -520,8 +521,6 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
520521
if (bdev_max_secure_erase_sectors(bdev))
521522
vbd->discard_secure = true;
522523

523-
vbd->feature_gnt_persistent = feature_persistent;
524-
525524
pr_debug("Successful creation of handle=%04x (dom=%u)\n",
526525
handle, blkif->domid);
527526
return 0;

0 commit comments

Comments
 (0)