Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3041690rwb; Mon, 15 Aug 2022 16:44:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR5temDwsjjg3x48wAyBcGITsF3UcUj9/kv8BVroI83Qiz9OwebHnMxtCuLG2QFJwhNv87L/ X-Received: by 2002:a17:906:2245:b0:715:7c81:e39d with SMTP id 5-20020a170906224500b007157c81e39dmr12134681ejr.262.1660607048809; Mon, 15 Aug 2022 16:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660607048; cv=none; d=google.com; s=arc-20160816; b=m28DPB2s1s/3oZOgqmwIWquIiqgBRMhURmKyL+OqG1vA0MFI7HbImjxgrGYXmajNas WAxu8ag1xit96dbHGNeMgD2j4PmelzFN3SVIFFeEmhmKTeH8wRlNqGQES1nF0UnHCw5H NOrb0zLZeh+dfejOqb6sNLA8D93rZ+TC8cu98Eg/aAzJ3sP9FKrLpip21tQMUIQ8evG2 l+ajCvncKWXVAqx2yPFF7qnYd1JjTYOimBaf8hlj816rOKwMZHpT75zLqJK3R0gFEnYB r2f3EbWdoQd3v/xbIiBmGmMOP/h28DaCI1YxGBs60NJC0ruCOBV7hXDVidFoZqR2uX0n Shsw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LHsQY3bJ3ZN4Dqxu4tEZUArfsnvavBpjcw50CHRhy6Y=; b=K/uyRpi25Ts8avDf0GGhYJ9PlNci8ntMO3SPnDRBvldi+BZA+X6P/YfK9Xjrxxj8L/ bE3QC4c3yDZbhpi4eVDsQYuzQj7686O0isLrQngikaZ64T4WAuDikjZmWCLvhXnfhQcb GIj2ieLycyLXVs0LJJFmoJEWbnhIeysWg8KDCzvUEr75CzU4NyYqCXRXVnHPFsVKfkXZ uhVmd9ceTl+jlfkfaKtJliD8sG4qLzagTW61oUAEsnEyUkPOfBauvdkSgVKkabiORtDB bejckV3xt1CyVlSjPqTBu9pYYtpBJEGBc4z7ZXj3FKHuc5q5mGOV5Tvfyg73/2LHn9V5 gezg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="uk/o8MJ0"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x2-20020a1709064a8200b00734c8b99826si9119250eju.803.2022.08.15.16.43.39; Mon, 15 Aug 2022 16:44:08 -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=@linuxfoundation.org header.s=korg header.b="uk/o8MJ0"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354021AbiHOXku (ORCPT + 99 others); Mon, 15 Aug 2022 19:40:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353643AbiHOXhs (ORCPT ); Mon, 15 Aug 2022 19:37:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 804ADBD1D6; Mon, 15 Aug 2022 13:09:57 -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 1DA80B80EA9; Mon, 15 Aug 2022 20:09:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6760DC433D6; Mon, 15 Aug 2022 20:09:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594194; bh=Sc7BqZDk1f59iz6GdHTuaXWtnjTzvHo7f/8963wEQ2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uk/o8MJ03ySba3xU45X7uYcpcz6Dr1JGx+y/NbVYdnse7UaBNZ2HVHiTCLEePgYRx ZH/BJFPWEXyStDaZ0P6tq6Ofcj84NuDln8mnWjSx9WFRo98Ke/gCN73GJTh3uREbuA qIwmvDNTUC6DM9rbB0En5VlIKVLk9nWSPVX1/zeM= 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.18 1070/1095] xen-blkback: fix persistent grants negotiation Date: Mon, 15 Aug 2022 20:07:49 +0200 Message-Id: <20220815180513.313695090@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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 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 persistent 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; } +/* 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 __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->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) @@ -523,8 +524,6 @@ static int xen_vbd_create(struct xen_blk if (q && blk_queue_secure_erase(q)) 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;