Message ID | 20240130021843.3608859-14-yukuai1@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-43818-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp957653dyb; Mon, 29 Jan 2024 18:27:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnqF1LtHuLRXJ0nds4oMJhiDkrIVDY40lBatVtJmgoOwKfpg/AOFsyDhUXaIS51pczsWgY X-Received: by 2002:a05:6214:2681:b0:686:9641:4ea0 with SMTP id gm1-20020a056214268100b0068696414ea0mr8656319qvb.77.1706581666563; Mon, 29 Jan 2024 18:27:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706581666; cv=pass; d=google.com; s=arc-20160816; b=Q2wf9UKb7tfc+ZYZK2aYMb0sR5sFj+DPehqVwam7U8bgN8Fm2VWltGzF8eB6K8J6ku uoZMJT+HKGIUGrKUuQatcqTWfLLmC0Key/leIIfs05HxnMfBNVylY17rpr1fMjXpMCMV cMjTbv+aEkC71c/YIeVU83Osbqa7rlmOspGrZ/Y5vNiddArF1p0+lIMI6Yy/dyfxnuIO utIZlqHNaJRQWP26V1qk6kSRG1ZkJHQEo4q7azTlh94awllkXjvfLQlKCAka1GScN6kO WLaxx/na3PGn6ACIzfdvKHiuFGSpaUCKJ6vcKgbPXvfVkiccI9kBXcoUaUfwX/PEAGHB 5FNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=5je7DXjlS71CV3FJEKNFh7pGpon6xEdnXDko1q92XM0=; fh=FtirvJJ13L8gehLQ375a0lCTkAroffAi0JfnF40Fa78=; b=x06+Eagt7dgsOUr/+qOHMQzsV8JUg2Qh9tptWAvCPjJyLXJXyh4+7iegmBKueIRYo6 FXBy0SfPCOGfFIAK2Xd8fN42W+uPHGXd4mPa2n4+6kzDoXB853x4nk7MoZCYrUgoVgJ4 0DBCujj1aOBU8T4UxFjzJ7Wdo69B4FmGlykBSyg8kq46+T6WYn7i9fxtWV5VIYDp2TTX vwOOchiXYar33OvC0nyhX33QSm5gfcVQUa44ZaQYmygeBqsvImqTA7B6lTbTKLDk+4HI YabigzNzMZQRmyIkeQHhevz7QFLaxexb0dYmbgvbgNQfwvcJFy8ndhnhozSCpJ4fE590 SCmQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-43818-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43818-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id r6-20020a0562140c8600b006800eced41asi8935934qvr.614.2024.01.29.18.27.46 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 18:27:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43818-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-43818-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43818-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5AE761C24CCF for <ouuuleilei@gmail.com>; Tue, 30 Jan 2024 02:27:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D88A15B110; Tue, 30 Jan 2024 02:23:16 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B501A53E3B; Tue, 30 Jan 2024 02:23:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706581394; cv=none; b=e28vdG5VK5NTzg4wYD4v6qpm5bHwoRO4rVRlSlAcXlchQjEygwx65YyC6I2D16rkGDIj1vwK+/s6OM4F9iwfIFuPph5Xg1vW4oZ9kJVTWI2x9xXmI7oZuz3puKHy7ahQVt4df6Ra2iQ9S8FMyq0GWMrrtMMVI7YXd1ewjrSlEss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706581394; c=relaxed/simple; bh=BcYpGvuVymYjsYzO5oAZoUEk24DPF79BmnHTgMndg6g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X2SvmRzwslc2ZboWsx7VFY9MRtvzrMlEKsnGSZoZGaHqrZatDyBzKv/r7D6HVi4cdwR4wUQIzhyrclUZQ60c3bNrVGnzOcUR5fibwYfR5/9Xi/NNJXPOBY7Uu7sQiRVntm/ia94gSDbZPwraNXapFZPb54t1mZpmFPxVygrX9KU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TP88q1CxKz4f3kKY; Tue, 30 Jan 2024 10:23:07 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id AB8691A0232; Tue, 30 Jan 2024 10:23:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBHGBGBXbhlrAigCQ--.55484S17; Tue, 30 Jan 2024 10:23:09 +0800 (CST) From: Yu Kuai <yukuai1@huaweicloud.com> To: mpatocka@redhat.com, heinzm@redhat.com, xni@redhat.com, agk@redhat.com, snitzer@kernel.org, dm-devel@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, jbrassow@f14.redhat.com, neilb@suse.de, shli@fb.com, akpm@osdl.org Cc: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH RFC v4 13/14] dm: wait for IO completion before removing dm device Date: Tue, 30 Jan 2024 10:18:42 +0800 Message-Id: <20240130021843.3608859-14-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240130021843.3608859-1-yukuai1@huaweicloud.com> References: <20240130021843.3608859-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgBHGBGBXbhlrAigCQ--.55484S17 X-Coremail-Antispam: 1UD129KBjvJXoW7KFy3tr1rGFWxAw4UGw1rZwb_yoW8Gw4xpF 4aqay5KrW5XrWjkw4Ut3yUCF1FyFs3K3yxCrW29w1fu3W5Gr9xXF48tF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789480577843841987 X-GMAIL-MSGID: 1789480577843841987 |
Series |
dm-raid: fix v6.7 regressions
|
|
Commit Message
Yu Kuai
Jan. 30, 2024, 2:18 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com> __dm_destroy() guarantee that device openers is zero, and then only call 'presuspend' and 'postsuspend' for the target. For request-based dm, 'md->holders' will be grabbed for each rq and __dm_destroy() will wait for 'md->holders' to be zero. However, for bio-based device, __dm_destroy() doesn't wait for all bios to be done. Fix this problem by calling dm_wait_for_completion() to wail for all inflight IO to be done, like what dm_suspend() does. Signed-off-by: Yu Kuai <yukuai3@huawei.com> --- drivers/md/dm.c | 3 +++ 1 file changed, 3 insertions(+)
Comments
On Tue, 30 Jan 2024, Yu Kuai wrote: > From: Yu Kuai <yukuai3@huawei.com> > > __dm_destroy() guarantee that device openers is zero, and then > only call 'presuspend' and 'postsuspend' for the target. For > request-based dm, 'md->holders' will be grabbed for each rq and > __dm_destroy() will wait for 'md->holders' to be zero. However, for > bio-based device, __dm_destroy() doesn't wait for all bios to be done. > > Fix this problem by calling dm_wait_for_completion() to wail for all > inflight IO to be done, like what dm_suspend() does. If the number of openers is zero, it is guaranteed that there are no bios in flight. Therefore, we don't have to wait for them. If there are bios in flight, it is a bug in the code that issues the bios. You can put WARN_ON(dm_in_flight_bios(md)) there. Mikulas > Signed-off-by: Yu Kuai <yukuai3@huawei.com> > --- > drivers/md/dm.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/md/dm.c b/drivers/md/dm.c > index 8dcabf84d866..2c0eae67d0f1 100644 > --- a/drivers/md/dm.c > +++ b/drivers/md/dm.c > @@ -58,6 +58,7 @@ static DEFINE_IDR(_minor_idr); > static DEFINE_SPINLOCK(_minor_lock); > > static void do_deferred_remove(struct work_struct *w); > +static int dm_wait_for_completion(struct mapped_device *md, unsigned int task_state); > > static DECLARE_WORK(deferred_remove_work, do_deferred_remove); > > @@ -2495,6 +2496,8 @@ static void __dm_destroy(struct mapped_device *md, bool wait) > if (!dm_suspended_md(md)) { > dm_table_presuspend_targets(map); > set_bit(DMF_SUSPENDED, &md->flags); > + if (wait) > + dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); > set_bit(DMF_POST_SUSPENDING, &md->flags); > dm_table_postsuspend_targets(map); > } > -- > 2.39.2 >
Hi, 在 2024/01/30 19:46, Mikulas Patocka 写道: > > > On Tue, 30 Jan 2024, Yu Kuai wrote: > >> From: Yu Kuai <yukuai3@huawei.com> >> >> __dm_destroy() guarantee that device openers is zero, and then >> only call 'presuspend' and 'postsuspend' for the target. For >> request-based dm, 'md->holders' will be grabbed for each rq and >> __dm_destroy() will wait for 'md->holders' to be zero. However, for >> bio-based device, __dm_destroy() doesn't wait for all bios to be done. >> >> Fix this problem by calling dm_wait_for_completion() to wail for all >> inflight IO to be done, like what dm_suspend() does. > > If the number of openers is zero, it is guaranteed that there are no bios > in flight. Therefore, we don't have to wait for them. > > If there are bios in flight, it is a bug in the code that issues the bios. > You can put WARN_ON(dm_in_flight_bios(md)) there. I add this patch because while testing, there is a problem that is hard to reporduce, as I mentioned in the other thread. I'll add BUG_ON() and try if I can still reporduce this problem without triggering it. Thanks, Kuai [12504.959682] BUG bio-296 (Not tainted): Object already free [12504.960239] ----------------------------------------------------------------------------- [12504.960239] [12504.961209] Allocated in mempool_alloc+0xe8/0x270 age=30 cpu=1 pid=203288 [12504.961905] kmem_cache_alloc+0x36a/0x3b0 [12504.962324] mempool_alloc+0xe8/0x270 [12504.962712] bio_alloc_bioset+0x3b5/0x920 [12504.963129] bio_alloc_clone+0x3e/0x160 [12504.963533] alloc_io+0x3d/0x1f0 [12504.963876] dm_submit_bio+0x12f/0xa30 [12504.964267] __submit_bio+0x9c/0xe0 [12504.964639] submit_bio_noacct_nocheck+0x25a/0x570 [12504.965136] submit_bio_wait+0xc2/0x160 [12504.965535] blkdev_issue_zeroout+0x19b/0x2e0 [12504.965991] ext4_init_inode_table+0x246/0x560 [12504.966462] ext4_lazyinit_thread+0x750/0xbe0 [12504.966922] kthread+0x1b4/0x1f0 > > Mikulas > >> Signed-off-by: Yu Kuai <yukuai3@huawei.com> >> --- >> drivers/md/dm.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/drivers/md/dm.c b/drivers/md/dm.c >> index 8dcabf84d866..2c0eae67d0f1 100644 >> --- a/drivers/md/dm.c >> +++ b/drivers/md/dm.c >> @@ -58,6 +58,7 @@ static DEFINE_IDR(_minor_idr); >> static DEFINE_SPINLOCK(_minor_lock); >> >> static void do_deferred_remove(struct work_struct *w); >> +static int dm_wait_for_completion(struct mapped_device *md, unsigned int task_state); >> >> static DECLARE_WORK(deferred_remove_work, do_deferred_remove); >> >> @@ -2495,6 +2496,8 @@ static void __dm_destroy(struct mapped_device *md, bool wait) >> if (!dm_suspended_md(md)) { >> dm_table_presuspend_targets(map); >> set_bit(DMF_SUSPENDED, &md->flags); >> + if (wait) >> + dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); >> set_bit(DMF_POST_SUSPENDING, &md->flags); >> dm_table_postsuspend_targets(map); >> } >> -- >> 2.39.2 >> > > . >
Hi, 在 2024/01/30 21:05, Yu Kuai 写道: > Hi, > > 在 2024/01/30 19:46, Mikulas Patocka 写道: >> >> >> On Tue, 30 Jan 2024, Yu Kuai wrote: >> >>> From: Yu Kuai <yukuai3@huawei.com> >>> >>> __dm_destroy() guarantee that device openers is zero, and then >>> only call 'presuspend' and 'postsuspend' for the target. For >>> request-based dm, 'md->holders' will be grabbed for each rq and >>> __dm_destroy() will wait for 'md->holders' to be zero. However, for >>> bio-based device, __dm_destroy() doesn't wait for all bios to be done. >>> >>> Fix this problem by calling dm_wait_for_completion() to wail for all >>> inflight IO to be done, like what dm_suspend() does. >> >> If the number of openers is zero, it is guaranteed that there are no bios >> in flight. Therefore, we don't have to wait for them. >> >> If there are bios in flight, it is a bug in the code that issues the >> bios. >> You can put WARN_ON(dm_in_flight_bios(md)) there. > > I add this patch because while testing, there is a problem that is > hard to reporduce, as I mentioned in the other thread. I'll add BUG_ON() > and try if I can still reporduce this problem without triggering it. > > Thanks, > Kuai > > [12504.959682] BUG bio-296 (Not tainted): Object already free > [12504.960239] > ----------------------------------------------------------------------------- > > [12504.960239] > [12504.961209] Allocated in mempool_alloc+0xe8/0x270 age=30 cpu=1 > pid=203288 > [12504.961905] kmem_cache_alloc+0x36a/0x3b0 > [12504.962324] mempool_alloc+0xe8/0x270 > [12504.962712] bio_alloc_bioset+0x3b5/0x920 > [12504.963129] bio_alloc_clone+0x3e/0x160 > [12504.963533] alloc_io+0x3d/0x1f0 > [12504.963876] dm_submit_bio+0x12f/0xa30 > [12504.964267] __submit_bio+0x9c/0xe0 > [12504.964639] submit_bio_noacct_nocheck+0x25a/0x570 > [12504.965136] submit_bio_wait+0xc2/0x160 > [12504.965535] blkdev_issue_zeroout+0x19b/0x2e0 > [12504.965991] ext4_init_inode_table+0x246/0x560 > [12504.966462] ext4_lazyinit_thread+0x750/0xbe0 > [12504.966922] kthread+0x1b4/0x1f0 After adding the BUG_ON(), I can still reporducing this BUG, this really looks like a BUG, and I don't think this is related to dm-raid. Perhaps you guys can take a look? Thanks, Kuai >> >> Mikulas >> >>> Signed-off-by: Yu Kuai <yukuai3@huawei.com> >>> --- >>> drivers/md/dm.c | 3 +++ >>> 1 file changed, 3 insertions(+) >>> >>> diff --git a/drivers/md/dm.c b/drivers/md/dm.c >>> index 8dcabf84d866..2c0eae67d0f1 100644 >>> --- a/drivers/md/dm.c >>> +++ b/drivers/md/dm.c >>> @@ -58,6 +58,7 @@ static DEFINE_IDR(_minor_idr); >>> static DEFINE_SPINLOCK(_minor_lock); >>> static void do_deferred_remove(struct work_struct *w); >>> +static int dm_wait_for_completion(struct mapped_device *md, unsigned >>> int task_state); >>> static DECLARE_WORK(deferred_remove_work, do_deferred_remove); >>> @@ -2495,6 +2496,8 @@ static void __dm_destroy(struct mapped_device >>> *md, bool wait) >>> if (!dm_suspended_md(md)) { >>> dm_table_presuspend_targets(map); >>> set_bit(DMF_SUSPENDED, &md->flags); >>> + if (wait) >>> + dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); >>> set_bit(DMF_POST_SUSPENDING, &md->flags); >>> dm_table_postsuspend_targets(map); >>> } >>> -- >>> 2.39.2 >>> >> >> . >> > > . >
diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 8dcabf84d866..2c0eae67d0f1 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -58,6 +58,7 @@ static DEFINE_IDR(_minor_idr); static DEFINE_SPINLOCK(_minor_lock); static void do_deferred_remove(struct work_struct *w); +static int dm_wait_for_completion(struct mapped_device *md, unsigned int task_state); static DECLARE_WORK(deferred_remove_work, do_deferred_remove); @@ -2495,6 +2496,8 @@ static void __dm_destroy(struct mapped_device *md, bool wait) if (!dm_suspended_md(md)) { dm_table_presuspend_targets(map); set_bit(DMF_SUSPENDED, &md->flags); + if (wait) + dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); set_bit(DMF_POST_SUSPENDING, &md->flags); dm_table_postsuspend_targets(map); }