Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp973762lqp; Fri, 22 Mar 2024 01:21:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXaZ9B74QqhDKKRptjosnojdkFN3tZLF68KYxZMaOCXRvuVbH1YzkIhBrI4WUYtlAAE+0QxgWs8SrNQoQYfgF3NVXan1DeogJs4pkH4Uw== X-Google-Smtp-Source: AGHT+IGy4jg54ZilsEVvEvZd+4dVQhxtcnFEyN+QEiXF+8MWVf8W/c9YdnPs/RBbLilQTJUt6GAu X-Received: by 2002:a17:903:2cb:b0:1e0:3347:5b4 with SMTP id s11-20020a17090302cb00b001e0334705b4mr1973853plk.8.1711095685274; Fri, 22 Mar 2024 01:21:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711095685; cv=pass; d=google.com; s=arc-20160816; b=d9a7oJLK1zDDjs/kOLxHLf7u5S8HTKV1lJH4IC3DeIZguuE3FlwKBb3h5IKULOj++T 3E6CI63aSpsrr+6rXYK8pnYAoAkskoR7O2BRFHsltmbkMaVNaRj8TiljmSKJjUpi1oW6 8v2O8E/+UgB/rZNjHPKJgPXIFJlt0IqJf4OiIb5AtCJTfX/4Xn2vPOvvO5Hd54+9fvw0 dvkiwPXaNwuNMgfMq5tECCsIoBTYkvY8zoO3H/cIYMkvdB2G4x05pjIe/62eubTH/PSk wycmhMj3ACq9hmcDnEElIpKe3LWu1qM9MTZP6I1O38sjhxY9IGciN/4hRGtYHw5smoMW yWRw== 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:message-id:date:subject:cc:to :from; bh=lhMB7JHE4rHFY5V4v3vCkOLTxbkkl+bqKETMhc+ZEy4=; fh=h44OL8+gHei+R0LONCna2zSa5NuE5ZmRaG26olyYk3o=; b=rgyFo9AVCTtv67NnS51lfsv17PD9D0ymraf+t13YKYXjN0RpxcgWE4RrDIAe+9VsCF bL6RYLOSQO0YuU2nmEHaRl6LsHSMfNnkL/9+KoNWbleJPhHHqlaB1MwDTRcc1CxP0izJ Ha/dN4Lc756+K3lCpXhY6ZZ8xrVuqPL0GtMv6DzyaeAG4mSvw6437VUpIGaNJscDCnAe eYNp4yeuWJ7u48vMk1T2TEHRLqRPeH4sTTY5v0DM7rc7wJWTndlJBYUoOeOj1yWuZzva 4sFCF3BqZeAF2f0jaXfuVuxBoTF+HmjOocYQPT/OT40mxChVEFKnVC9+rVQO1sgtF11z n5NQ==; dara=google.com 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-111115-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111115-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e10-20020a170902784a00b001dd56860832si1373986pln.518.2024.03.22.01.21.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 01:21:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111115-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-111115-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111115-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 9B248B24179 for ; Fri, 22 Mar 2024 08:17:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6EBED17731; Fri, 22 Mar 2024 08:17:32 +0000 (UTC) Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (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 4F7FE18AE8; Fri, 22 Mar 2024 08:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711095451; cv=none; b=OVHAmvWsr1bH6WSJHEXFOUt/A80pydsIlBRQBOXzKAO6/Tz+HPuOvVcqRv0OAhlnwQxjzkSy+LQVAQXXwu4vFK35eVNdfkXDXlybjB+ZzP/CPfqFQgLZ1B2L6Q1IWW56SBvulOy5R84F+rsxA2HQCrR6thiQ2EI6T+b6S4hG1ys= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711095451; c=relaxed/simple; bh=s4XNSovHtSMoBIu/QGtMEdY/hgRXDsNSpZP95H+CZ9A=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=nJMC3dm660GoYjTYurfD09Qcp3e3koMd0FXVHB8QzGZgF8bUnMl2xyHfIPnXqSgo2ykq1q71g7eMgGx9eN38JCpRT11PNRr2K+Q/w18Z7lzLVeu1L3ZEWADMtBu4tHQ6uuJmCyKnU4DaSLZEnatSfc0ZdXZtswko0xTs26ATwQk= 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.56 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 dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4V1FYV2XJKz4f3jYJ; Fri, 22 Mar 2024 16:17:18 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 664211A0B2D; Fri, 22 Mar 2024 16:17:24 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RGRPv1lh7rgHg--.49644S4; Fri, 22 Mar 2024 16:17:23 +0800 (CST) From: Yu Kuai To: song@kernel.org, logang@deltatee.com, dan@danm.net, junxiao.bi@oracle.com, xni@redhat.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH] md/raid5: fix deadlock that raid5d() wait for itself to clear MD_SB_CHANGE_PENDING Date: Fri, 22 Mar 2024 16:10:05 +0800 Message-Id: <20240322081005.1112401-1-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAX6RGRPv1lh7rgHg--.49644S4 X-Coremail-Antispam: 1UD129KBjvJXoWxZFy5uFykAw1kWF4kAr1rCrg_yoW5WFW8pr Z3ZFsIgrWUGrykua1DCa4UWFWjvF9F9rWjqrW7K3WkZ3WIvrWSq34rArWDtrykAFZYvFWq q3W5GrnxXw18u3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvY14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4 xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43 MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I 0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE14v2 6r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0J UdHUDUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Xiao reported that lvm2 test lvconvert-raid-takeover.sh can hang with small possibility, the root cause is exactly the same as commit bed9e27baf52 ("Revert "md/raid5: Wait for MD_SB_CHANGE_PENDING in raid5d"") However, Dan reported another hang after that, and junxiao investigated the problem and found out that this is caused by plugged bio can't issue from raid5d(). Current implementation in raid5d() has a weird dependence: 1) md_check_recovery() from raid5d() must hold 'reconfig_mutex' to clear MD_SB_CHANGE_PENDING; 2) raid5d() handles IO in a deadloop, until all IO are issued; 3) IO from raid5d() must wait for MD_SB_CHANGE_PENDING to be cleared; This behaviour is introduce before v2.6, and for consequence, if other context hold 'reconfig_mutex', and md_check_recovery() can't update super_block, then raid5d() will waste one cpu 100% by the deadloop, until 'reconfig_mutex' is released. Refer to the implementation from raid1 and raid10, fix this problem by skipping issue IO if MD_SB_CHANGE_PENDING is still set after md_check_recovery(), daemon thread will be woken up when 'reconfig_mutex' is released. Meanwhile, the hang problem will be fixed as well. Fixes: 5e2cf333b7bd ("md/raid5: Wait for MD_SB_CHANGE_PENDING in raid5d") Reported-and-tested-by: Dan Moulding Closes: https://lore.kernel.org/all/20240123005700.9302-1-dan@danm.net/ Investigated-by: Junxiao Bi Signed-off-by: Yu Kuai --- drivers/md/raid5.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index d874abfc1836..2bd1ce9b3922 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -36,7 +36,6 @@ */ #include -#include #include #include #include @@ -6734,6 +6733,9 @@ static void raid5d(struct md_thread *thread) int batch_size, released; unsigned int offset; + if (test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) + break; + released = release_stripe_list(conf, conf->temp_inactive_list); if (released) clear_bit(R5_DID_ALLOC, &conf->cache_state); @@ -6770,18 +6772,7 @@ static void raid5d(struct md_thread *thread) spin_unlock_irq(&conf->device_lock); md_check_recovery(mddev); spin_lock_irq(&conf->device_lock); - - /* - * Waiting on MD_SB_CHANGE_PENDING below may deadlock - * seeing md_check_recovery() is needed to clear - * the flag when using mdmon. - */ - continue; } - - wait_event_lock_irq(mddev->sb_wait, - !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags), - conf->device_lock); } pr_debug("%d stripes handled\n", handled); -- 2.39.2