From patchwork Mon Jan 24 17:37:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12722738 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 1C850C433EF for ; Mon, 24 Jan 2022 18:24:39 +0000 (UTC) Received: from localhost ([::1]:51364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nC417-0004YM-W7 for qemu-devel@archiver.kernel.org; Mon, 24 Jan 2022 13:24:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nC3KX-0003gH-W2; Mon, 24 Jan 2022 12:40:39 -0500 Received: from mail-eopbgr70112.outbound.protection.outlook.com ([40.107.7.112]:48772 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nC3KT-0002yT-9Y; Mon, 24 Jan 2022 12:40:36 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FOD+wJaxNjwJcr8FQkWbu6vqYsSnWQJ1tJhnths0/VKEBU3HYLxowdjtkNSqtQIm1qt7VQOXa4HyBI+yXakVx5W/olPUhFeQutTpJ6GZfAw0Dk4pybHncBYp2FmHtx59OYW9aqq2l1uD1NsIPzbQQx9lTrgavpsVHvrN5FwP6DRbeBf9h3TuIxKU+j+bBQsvaod5HCnfCtNKjM9IctkEm03vLLY5I91eb/8prrZcK0yzOR3Up2++wPH2N2S/8qiIF7a/MYjUcim0HkIDeBG/PdbtggHq5SyZXzIP16vK/51my6X/3OgougMl7g6tgd1E5LX6gbvsdeOk68vG5+a0cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tVzxO3caD4IM2ACB7cqEQbPTZMpvIMQ+YIoLgiz5KuQ=; b=nl4jZtmoDlvXbTTizoQNlmxG8o+6/58pKriwR8aplPHko/+4PGoLX1cN2IQlJSUkguMSX0h48gh4xtTFYvwHVF6N7ZyF2zQ34/99ODS1oOKp/8o5xWL2dr1TR0ralkrcpUn2KeBB4NNIYd26Ie1Iv2/e0vc1EAFsBQvQ7lf4UUklovJnGOVHHbe2g2bOEw0dnTSXTCFeh8ZM5/KR8NbP8/u0pGSFBIh46pb005eUe2UhiHdgiumCymWwLzcPmxNEScGmNEmt9wtYwjxvLeFvDK20QkpVoY0pG0kO3m/064Ca8VPmu5gdy2/BVnCnEkxSD25jgXPlhQLRxrqSIDofRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tVzxO3caD4IM2ACB7cqEQbPTZMpvIMQ+YIoLgiz5KuQ=; b=l65mEc4eKNYtUZELqUNBCTgpwyvyZTZnYKrTEdzr7GULYJKPsZYj66OMKzIbMjeAr5vBTB104hin969pfJGby4jYfgRBmmQmbkHu59y3t1H1BGBBe57jkLBP0OH3cx9e1J+Z/PUmphsO1/U4FvfIXY1LbngiCg3t6r17FjOjXQE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by DBBPR08MB4316.eurprd08.prod.outlook.com (2603:10a6:10:c6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.12; Mon, 24 Jan 2022 17:40:19 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4def:4b08:dfe6:b4bd]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4def:4b08:dfe6:b4bd%3]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 17:40:19 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH] block: bdrv_set_backing_hd(): use drained section Date: Mon, 24 Jan 2022 18:37:41 +0100 Message-Id: <20220124173741.2984056-1-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: AS9PR06CA0172.eurprd06.prod.outlook.com (2603:10a6:20b:45c::35) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2d59268b-c5e2-4f57-9f85-08d9df609704 X-MS-TrafficTypeDiagnostic: DBBPR08MB4316:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RcRS/kysMA5QaYd6o9ef3+4p/ffpHjPzKoU1abWvBmaxm6ajqZa7IHQ7rLt9uzfpVbr943sirsHI0iXvLaX+PdjR8ORETSLlG+Yzi2CZ7kKk33Qy1SsO/ow2sQ3frp4RckrwYL8HDfkKVmylQR1yfsO5NND66wwDMGMYejTC2/746eWUv3BBivvaOsU6wGtvYW3db3NCDxrBDfNvHFsmYyDh928OSIXfPomlNXHk+rVULQNYb/7iFd5uHzyAbdtCkwJEbUKtflyBr3/K/guctBYharVaSx4Mn2oeCG7jMzY+tDWjiLDoByTRM6TnvmdNijGjktnFw42OZoiGTaOPag3oov/rywpYTG/rYYxtjV/eads4tBZ0bu8EFjL5+s5STt8OwmR0oGb+XBbNQLgt8zrpq65gJ4snjcOKUImdE0It/NQYzdjKxsiEdGC+VAgwMjnraBgUlco0qGBTj2unYgyP7MmJR68shIqhJAFVosbJqTXTZ0gl4WlHrz7rWncjQbS9yyyiTmABnXet2OXMJBp6h2vNyRsJfdDLWA5diYUvSTKRG3db/8jTnDn05U0bF8k2L+BRocmq4tEd7WqJmSiplRPD4ZhbpnjrfAzy6wvCmapgsXGHCVhlkcSU24HCsmAs8fbIkxaOj5mJM3mEigUGSB6t6DXDSLykV8bSrS+fkoahajQ6EN1G/Atsgz982CUFnppphlPDoEh4N8xl/NBT3rx9Aqnnyp8r7mBarKkD2C8UIvajedQEm9ZIV/rH X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(36756003)(66556008)(5660300002)(66946007)(66476007)(508600001)(186003)(2906002)(83380400001)(316002)(6916009)(4326008)(1076003)(8676002)(8936002)(38350700002)(6666004)(38100700002)(2616005)(6506007)(6512007)(52116002)(26005)(6486002)(107886003)(86362001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OQjkQzEaez+AbmYukJAgHT9i1BBIy9Tu6NgNNc19gNjIDwuZa2B4pE8l44q52jzlYgRJSozDAgEKX4ODL3AwJXQuZb9SpCyaSxoUiGtLtU5HQeIH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ZYyZXrjAdm7iPlK6Lbl9qtUwoYdg8wl2ayp+tZmRlKIK9/Agt4bf+Cj1sJW9SBwScWFUBlB6GNml0mLsQGj1NyaX19rfiputDw0DBuuHSqxxrakTuitIE3RlrRcyMMcnYH0il+uIsfETI7mo4d4qo48XnXS7p2FlE08UcOSyCAGlEGMCDpDp0v0rpWxQOBoh2Mg7U3wbbN5jZ4kSuzEYICV/CeqJE3vJfVBOpv1RcUaNG6N/K5fnF8sTRU1TOEWukvW3VtUNKZq0Drgc++Nm/GSiJZxn/Dhce16S3Thu7Hg8ZwLUu/lBHBBN2WLHEWG5PJC/NayTxIt8SJfNyaxnTUSONgWcEBBRLJlvDG1xGbaczA7O9bEZBzDiqpVeQwvauqDVIOw4c0sPCCkCEpH538PnqPQOoIrJDBnIt4rr07z7XG/z7yGtF08lJS8EkPeiozwwGjcIzESNdBs/ZcEnUsD1QO9sjyYaDl/MTtLWg+d8xGJv+B62o9nw4T61w== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d59268b-c5e2-4f57-9f85-08d9df609704 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2022 17:40:19.7214 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HPMrj6439BJEtAfcbxUuLTrGI/AP5TNjSXzT0jnkzhQggGOAJdos4ypSxAdryxRJLf7EWiucqxVH1cBoJAy159xRO4oTa/m31Q6lIX5sPYU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4316 Received-SPF: pass client-ip=40.107.7.112; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Graph modifications should be done in drained section. stream_prepare() handler of block stream job call bdrv_set_backing_hd() without using drained section and it's theoretically possible that some IO request will interleave with graph modification and will use outdated pointers to removed block nodes. Some other callers use bdrv_set_backing_hd() not caring about drained sections too. So it seems good to make a drained section exactly in bdrv_set_backing_hd(). Signed-off-by: Vladimir Sementsov-Ogievskiy --- Hi all! We faced the following bug in our Rhel7-based downstream: read request crashes because backing bs is NULL unexpectedly (honestly, it crashes inside bdrv_is_allocated(), which is called during read and it's a downstream-only code, but that doesn't make real sense). In gdb I also see block-stream job in state "refcnt = 0, status = JOB_STATUS_NULL", but it's still in jobs list. So, I assume that backing file was disappeared exactly as final step of block-stream job. And the problem is that this step should be done in drained section, but seems that it isn't. If we have a drained section, we'd wait for finish of read request before removing the backing node. I don't have a reproducer. I spent some time to write a test, but there are problems that makes hard to use blkdebug's break-points: we have drained section at block-stream start, and we do have drained section at block-stream finish: bdrv_cor_filter_drop() called from stream_prepare() does drained section (unlike bdrv_set_backing_hd()). So, the fix is intuitive. I think, it's correct) Note also, that alternative would be to make a drained section in stream_prepare() and don't touch bdrv_set_backing_hd() function. But it seems good to make a public graph-modification function more safe. block.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block.c b/block.c index 7b3ce415d8..b54d59d1fa 100644 --- a/block.c +++ b/block.c @@ -3341,6 +3341,8 @@ int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, int ret; Transaction *tran = tran_new(); + bdrv_drained_begin(bs); + ret = bdrv_set_backing_noperm(bs, backing_hd, tran, errp); if (ret < 0) { goto out; @@ -3350,6 +3352,8 @@ int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, out: tran_finalize(tran, ret); + bdrv_drained_end(bs); + return ret; }