Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp927001imw; Fri, 15 Jul 2022 16:01:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t1SDf0QU2UODzVNO0MWZZKxjLJhflsIPCaRAH6wUHTQCyEtNY9geWY0lRtKV+EGTBe2CPM X-Received: by 2002:a63:2a4e:0:b0:419:c606:96d with SMTP id q75-20020a632a4e000000b00419c606096dmr7774648pgq.239.1657926089822; Fri, 15 Jul 2022 16:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657926089; cv=none; d=google.com; s=arc-20160816; b=wCALqMnZsq641b2lqMg9/iHCgMZUKBxPBkNS29Ez+Rj215DoLLiHFO4jRwIeKXJa7E bdtSDE9Hzspih/3CU199q6w02hVIc3mLAII/BgFb8LhIk/V6C4DBOc0odZlYHWypRasH aS56Q8BY8Fvwhf5oqiKVJCp5CnzWUBeEjNAK8t+KXmO+W54Kadovspsa9raHfzWbgHN6 GLMeNvf21+a8Oni/sAzwiAx3JvFDMEFGsTiUi7Wc2oG/Nllw3pPYbq4x/FzNTFUhJxiA gylmbM/xvlw75AbJVdjiZiNR68tokXZzv235agSjOsz69bFMMnBkmz57GkCOvxlIHvvh M0NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h4MCYvsqnFmMTtsQGU9rhIDUKaHK8py2jjweYjlSYWg=; b=QgcC5aAlXlVW65PwRj7t+uiQplX2iPVYzuPdVbAoKtPP5mOzgmNxz9SaudlQrtpI9a 9ml2j7yh6zQxUDRXpfMDYuyCcc7z7vJEoVCWv4lHtkKQckz5PPW/4kO1qRPpjOwAsOGj /xsAE8QjTPd7C9CCo0B/BFeQVUkHmWkCHsxBLrAev8rHHKqzU/2Wozq8q24YZK3ogoK2 c5yvfUtOTyxPk2Glj06+xWcPhYEc2Sdw95J3ExMAFC6abrcMglkrT0DuKbYKCKoWO9vM EeyEnieYwSXXizRhrkkhcbRxHiurDD0npogzjToB5RdQgQSY+/Htvm6oSEr15JoHKULM 1NnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Zfee0JPa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u10-20020a170902e5ca00b0016c058d72b2si7997479plf.238.2022.07.15.16.01.11; Fri, 15 Jul 2022 16:01:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Zfee0JPa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231410AbiGOWv2 (ORCPT + 99 others); Fri, 15 Jul 2022 18:51:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbiGOWvW (ORCPT ); Fri, 15 Jul 2022 18:51:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C5C14331E; Fri, 15 Jul 2022 15:51:21 -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 ams.source.kernel.org (Postfix) with ESMTPS id C37EAB82EF5; Fri, 15 Jul 2022 22:51:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E7B9C341C6; Fri, 15 Jul 2022 22:51:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657925478; bh=dlKaQtwg6yYz18rR7yrtedCSXkIPHob7qvry1GivQwU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zfee0JPaAo7oMHjphPshW1SCisXCB26lmUDf4+N5Lfa3ZXWP/1h9AYnrlFDyOnNGa 8CZCtlA0YcgiyS66d8rMWfTaDRK7BIaeNQsTXBSIJBWZcdIXsm6wJMbEebhJ0AHuHQ E7ljrx5Vc/3IEsYX/sJTdT+2WNJtr8q4TKoP2iBaDXH8ARh4/17mMXAxgC2RbBf/K2 d5QfzG48sV1dKnSkxRUMsXwBfgW5WnZrxs8QqGVmfjqa477pJcj5R1aKWjoD/dg20e pGpPpMEEltiWk3QRupHXiLvkIvon2u4J27h7ydm+P58QnbX7Wq0/CPCdq771cV88PS wvmYZSwRdGvyQ== From: SeongJae Park To: roger.pau@citrix.com Cc: axboe@kernel.dk, boris.ostrovsky@oracle.com, jgross@suse.com, olekstysh@gmail.com, andrii.chepurnyi82@gmail.com, mheyne@amazon.de, xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, SeongJae Park Subject: [PATCH v4 1/3] xen-blkback: fix persistent grants negotiation Date: Fri, 15 Jul 2022 22:51:06 +0000 Message-Id: <20220715225108.193398-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220715225108.193398-1-sj@kernel.org> References: <20220715225108.193398-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 persistent grants") Cc: # 5.10.x Signed-off-by: Maximilian Heyne Signed-off-by: SeongJae Park --- drivers/block/xen-blkback/xenbus.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 97de13b14175..16c6785d260c 100644 --- 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 xen_blkif *blkif) return 0; } +/* Enable the persistent grants feature. */ +static bool feature_persistent = true; +module_param(feature_persistent, bool, 0644); +MODULE_PARM_DESC(feature_persistent, "Enables the persistent grants feature"); + 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(domid_t domid) __module_get(THIS_MODULE); INIT_WORK(&blkif->free_work, xen_blkif_deferred_free); + blkif->vbd.feature_gnt_persistent = feature_persistent; + return blkif; } @@ -472,12 +479,6 @@ static void xen_vbd_free(struct xen_vbd *vbd) vbd->bdev = NULL; } -/* Enable the persistent grants feature. */ -static bool feature_persistent = 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_blkif *blkif, blkif_vdev_t handle, if (bdev_max_secure_erase_sectors(bdev)) vbd->discard_secure = true; - vbd->feature_gnt_persistent = feature_persistent; - pr_debug("Successful creation of handle=%04x (dom=%u)\n", handle, blkif->domid); return 0; -- 2.25.1