From patchwork Fri Jul 15 17:55:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12919547 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A293EC43334 for ; Fri, 15 Jul 2022 17:56:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.368435.599728 (Exim 4.92) (envelope-from ) id 1oCPXj-0007Kv-Vh; Fri, 15 Jul 2022 17:55:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 368435.599728; Fri, 15 Jul 2022 17:55:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oCPXj-0007Kk-SF; Fri, 15 Jul 2022 17:55:59 +0000 Received: by outflank-mailman (input) for mailman id 368435; Fri, 15 Jul 2022 17:55:58 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oCPXi-0006p6-PI for xen-devel@lists.xenproject.org; Fri, 15 Jul 2022 17:55:58 +0000 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6110c7d3-0467-11ed-924f-1f966e50362f; Fri, 15 Jul 2022 19:55:57 +0200 (CEST) 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 F2FC5B82DC6; Fri, 15 Jul 2022 17:55:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDD7AC341C0; Fri, 15 Jul 2022 17:55:52 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6110c7d3-0467-11ed-924f-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657907753; bh=diKv2YzAoxgEDY60qc5gR9piIzmslAMbkYmuxNqe/ZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fw1MINtcSM4pJAG0nsuh8IAM8Wr7uRi8M3aS0vjGeLT1EI/GVh6OJWZ+YVlJJwqqx bM31L0AeRA4WLQ9md1tQ0nTXsFrGX8PRpdBlV+Mh/AbOiXhcSxgsfY0uLaQr3XlkIO lm3ZnegDZ8aEwlUzyysoHyiFREQSZgaZAAJNQV3qoDJ76NGHY8DQcY07ZiqqweNjaY G+7nZLFKyemUMbTY0JMT0GhNes72Ig0BZbgNeHry5ztF4VwzS912XIIAoMZ27jI2vJ alwxG/kpfOJENpxe0eeEepmWBoXTsABm/JvzJ7CLVdQ+uyrz56qF7TI3qFXUVgNgn6 4Ru1qOB1bZO1A== 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 1/2] xen, blkback: fix persistent grants negotiation Date: Fri, 15 Jul 2022 17:55:20 +0000 Message-Id: <20220715175521.126649-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220715175521.126649-1-sj@kernel.org> References: <20220715175521.126649-1-sj@kernel.org> MIME-Version: 1.0 From: Maximilian Heyne Given dom0 supports persistent grants but the guest does not. Then, when attaching a block device during runtime of the guest, dom0 will enable persistent grants for this newly attached block device: $ xenstore-ls -f | grep 20674 | grep persistent /local/domain/0/backend/vbd/20674/768/feature-persistent = "0" /local/domain/0/backend/vbd/20674/51792/feature-persistent = "1" Here disk 768 was attached during guest creation while 51792 was attached at runtime. If the guest would have advertised the persistent grant feature, there would be a xenstore entry like: /local/domain/20674/device/vbd/51792/feature-persistent = "1" Persistent grants are also used when the guest tries to access the disk which can be seen when enabling log stats: $ echo 1 > /sys/module/xen_blkback/parameters/log_stats $ dmesg xen-blkback: (20674.xvdf-0): oo 0 | rd 0 | wr 0 | f 0 | ds 0 | pg: 1/1056 The "pg: 1/1056" shows that one persistent grant is used. Before commit aac8a70db24b ("xen-blkback: add a parameter for disabling of persistent grants") vbd->feature_gnt_persistent was set in connect_ring. After the commit it was intended to be initialized in xen_vbd_create and then set according to the guest feature availability in connect_ring. However, with a running guest, connect_ring might be called before xen_vbd_create and vbd->feature_gnt_persistent will be incorrectly initialized. xen_vbd_create will overwrite it with the value of feature_persistent regardless whether the guest actually supports persistent grants. With this commit, vbd->feature_gnt_persistent is set only in connect_ring and this is the only use of the module parameter feature_persistent. This avoids races when the module parameter changes during the block attachment process. Note that vbd->feature_gnt_persistent doesn't need to be initialized in xen_vbd_create. It's next use is in connect which can only be called once connect_ring has initialized the rings. xen_update_blkif_status is checking for this. Please also note that this commit makes a behavioral change of the parameter. That is, the parameter made effect on only newly created backends before this commit, but it makes the effect for every new connection after this commit. Therefore, this commit also updates the document. 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 --- Documentation/ABI/testing/sysfs-driver-xen-blkback | 2 +- drivers/block/xen-blkback/xenbus.c | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-xen-blkback b/Documentation/ABI/testing/sysfs-driver-xen-blkback index 7faf719af165..fac0f429a869 100644 --- a/Documentation/ABI/testing/sysfs-driver-xen-blkback +++ b/Documentation/ABI/testing/sysfs-driver-xen-blkback @@ -42,5 +42,5 @@ KernelVersion: 5.10 Contact: Maximilian Heyne Description: Whether to enable the persistent grants feature or not. Note - that this option only takes effect on newly created backends. + that this option only takes effect on newly connected backends. The default is Y (enable). diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 97de13b14175..874b846fb622 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -520,8 +520,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; @@ -1087,10 +1085,9 @@ static int connect_ring(struct backend_info *be) xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol); return -ENOSYS; } - if (blkif->vbd.feature_gnt_persistent) - blkif->vbd.feature_gnt_persistent = - xenbus_read_unsigned(dev->otherend, - "feature-persistent", 0); + + blkif->vbd.feature_gnt_persistent = feature_persistent && + xenbus_read_unsigned(dev->otherend, "feature-persistent", 0); blkif->vbd.overflow_max_grants = 0; From patchwork Fri Jul 15 17:55:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12919548 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CBF64CCA482 for ; Fri, 15 Jul 2022 17:56:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.368434.599717 (Exim 4.92) (envelope-from ) id 1oCPXi-00074q-Ne; Fri, 15 Jul 2022 17:55:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 368434.599717; Fri, 15 Jul 2022 17:55:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oCPXi-00074j-JR; Fri, 15 Jul 2022 17:55:58 +0000 Received: by outflank-mailman (input) for mailman id 368434; Fri, 15 Jul 2022 17:55:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oCPXi-0006sk-2C for xen-devel@lists.xenproject.org; Fri, 15 Jul 2022 17:55:58 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 600a1b96-0467-11ed-bd2d-47488cf2e6aa; Fri, 15 Jul 2022 19:55:56 +0200 (CEST) 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 6C364622BC; Fri, 15 Jul 2022 17:55:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E73DBC341C6; Fri, 15 Jul 2022 17:55:53 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 600a1b96-0467-11ed-bd2d-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657907754; bh=glq1x5HjisMX5ci0YsvyB4Ygu//43duXbX0NbnuWshE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hwiOW9YiIbTCMdE0Tf/wDkTu2UsIH14atZA/yHy8G06FnwGKtOvtYIp7JmSM860P4 m+G2KTFISLmBB0n/oEn8K3iH1lIn6aH1fWMLr7ww7PITjexJM6W7ZiuqU1DabSZBq6 ZkcjxYbTGCjxLiP6g/cFeKH/FkCdsABIN2KAKfZMBEOIvPbq2P2UCQEPLEtUiPMz9J bLjFGcCRLmlNFaclKw6IP4+80g51MAYkepMQwlXy4XO8/e3VSueMCLT0xHfCpQw5WP 8V1Pa5gDFUAvwHJgrms8TjifJPJ4u8v1dljABKadLQRH9bMyMnHIve039sDnxUTegP cIcw+eyH/Bk9A== 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 2/2] xen-blkfront: Apply 'feature_persistent' parameter when connect Date: Fri, 15 Jul 2022 17:55:21 +0000 Message-Id: <20220715175521.126649-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220715175521.126649-1-sj@kernel.org> References: <20220715175521.126649-1-sj@kernel.org> MIME-Version: 1.0 Previous commit made xen-blkback's 'feature_persistent' parameter to make effect for not only newly created backends but also for every reconnected backends. This commit makes xen-blkfront's counterpart parameter to works in same manner and update the document to avoid any confusion due to inconsistent behavior of same-named parameters. Cc: # 5.10.x Signed-off-by: SeongJae Park --- Documentation/ABI/testing/sysfs-driver-xen-blkfront | 2 +- drivers/block/xen-blkfront.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-xen-blkfront b/Documentation/ABI/testing/sysfs-driver-xen-blkfront index 7f646c58832e..4d36c5a10546 100644 --- a/Documentation/ABI/testing/sysfs-driver-xen-blkfront +++ b/Documentation/ABI/testing/sysfs-driver-xen-blkfront @@ -15,5 +15,5 @@ KernelVersion: 5.10 Contact: Maximilian Heyne Description: Whether to enable the persistent grants feature or not. Note - that this option only takes effect on newly created frontends. + that this option only takes effect on newly connected frontends. The default is Y (enable). diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 3646c0cae672..4e763701b372 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1988,8 +1988,6 @@ static int blkfront_probe(struct xenbus_device *dev, info->vdevice = vdevice; info->connected = BLKIF_STATE_DISCONNECTED; - info->feature_persistent = feature_persistent; - /* Front end dir is a number, which is used as the id. */ info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0); dev_set_drvdata(&dev->dev, info); @@ -2283,7 +2281,7 @@ static void blkfront_gather_backend_features(struct blkfront_info *info) if (xenbus_read_unsigned(info->xbdev->otherend, "feature-discard", 0)) blkfront_setup_discard(info); - if (info->feature_persistent) + if (feature_persistent) info->feature_persistent = !!xenbus_read_unsigned(info->xbdev->otherend, "feature-persistent", 0);