From nobody Mon Sep 29 20:14:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64C6CC3F6B0 for ; Tue, 16 Aug 2022 01:07:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349371AbiHPBGP (ORCPT ); Mon, 15 Aug 2022 21:06:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346211AbiHPBBN (ORCPT ); Mon, 15 Aug 2022 21:01:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C185DC0A5; Mon, 15 Aug 2022 13:50:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 97F7060FC4; Mon, 15 Aug 2022 20:50:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D753C433D6; Mon, 15 Aug 2022 20:50:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596604; bh=5j2KuWonkoHSeWK7y5ufQE4sFwnUv1xlQ/jR811XzXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZRPQtKx4HU7liKdDiKkZACt5es8773YIWNKInHYo/2yz+WRqAbZkPq/N8xUgwowTr BLI0AqYhj0qt0mo7qNnV1F4fY7PMrPdMI0Jq8gOafFd1Xm6oOEoiWV0rH77wGh3Z74 B6+qTl//bU7pYP41w/Tl+9N6aQrnyQSMwUZL/zL8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maximilian Heyne , SeongJae Park , Juergen Gross Subject: [PATCH 5.19 1133/1157] xen-blkback: fix persistent grants negotiation Date: Mon, 15 Aug 2022 20:08:09 +0200 Message-Id: <20220815180525.738619555@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: SeongJae Park commit fc9be616bb8f3ed9cf560308f86904f5c06be205 upstream. 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 aac8a70db24b ("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: aac8a70db24b ("xen-blkback: add a parameter for disabling of persist= ent grants") Cc: # 5.10.x Signed-off-by: Maximilian Heyne Signed-off-by: SeongJae Park Reviewed-by: Maximilian Heyne Reviewed-by: Juergen Gross Link: https://lore.kernel.org/r/20220715225108.193398-2-sj@kernel.org Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- drivers/block/xen-blkback/xenbus.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -157,6 +157,11 @@ static int xen_blkif_alloc_rings(struct return 0; } =20 +/* Enable the persistent grants feature. */ +static bool feature_persistent =3D true; +module_param(feature_persistent, bool, 0644); +MODULE_PARM_DESC(feature_persistent, "Enables the persistent grants featur= e"); + static struct xen_blkif *xen_blkif_alloc(domid_t domid) { struct xen_blkif *blkif; @@ -181,6 +186,8 @@ static struct xen_blkif *xen_blkif_alloc __module_get(THIS_MODULE); INIT_WORK(&blkif->free_work, xen_blkif_deferred_free); =20 + blkif->vbd.feature_gnt_persistent =3D feature_persistent; + return blkif; } =20 @@ -472,12 +479,6 @@ static void xen_vbd_free(struct xen_vbd vbd->bdev =3D NULL; } =20 -/* Enable the persistent grants feature. */ -static bool feature_persistent =3D true; -module_param(feature_persistent, bool, 0644); -MODULE_PARM_DESC(feature_persistent, - "Enables the persistent grants feature"); - static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, unsigned major, unsigned minor, int readonly, int cdrom) @@ -520,8 +521,6 @@ static int xen_vbd_create(struct xen_blk if (bdev_max_secure_erase_sectors(bdev)) vbd->discard_secure =3D true; =20 - vbd->feature_gnt_persistent =3D feature_persistent; - pr_debug("Successful creation of handle=3D%04x (dom=3D%u)\n", handle, blkif->domid); return 0;