Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32961725rwd; Sat, 8 Jul 2023 02:27:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlH9M28CASUm8jNLVW4zI6idyJtvibCsRZBzi6DuEzt/FVwhcrAIxcAFO685T0ouU2+zBtfo X-Received: by 2002:a92:c142:0:b0:343:c8b1:b7f0 with SMTP id b2-20020a92c142000000b00343c8b1b7f0mr8488382ilh.23.1688808432669; Sat, 08 Jul 2023 02:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688808432; cv=none; d=google.com; s=arc-20160816; b=hnJZSw+DUKmO7stAi/DLzUmKE8DVYCfKSHeDiSOkHu1w6HBnfRLeXkoxVCetTG3CMz OTtfC98ZByYZ0G+ZH7OSGDtO1H4KNQJMeOirHWpqGWBaNZ6T8hXRdmLFv6CqUVzHhQ8x 9lCyA+NpCKT0eAHyB7sy+2xNy350DHY4sNWx555wHPNKkUZR1VTUl34/51K73j8HbU+F wfRGdmNqxRukyj1JgloYV07DEa6OSAxfxuqFBCj2sbq4O5WBLvf+DwZlt452+sHNmG+l qD3Ck5fYWWxDEH+3S8J0jPpDsnpjFOWIkt7X+9VjCPgq9KRtTzouVtpq2AIs6G/S9TA/ uDcQ== 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 :message-id:date:subject:cc:to:from; bh=ZGB0d0Mg1rOGHLPmQ+bDUyw+QZ8KHddGJy9GY2aqKuk=; fh=DdeujBP5/hj10TbLTdzXlgENoYZYxoCgmrkukAJ1qJA=; b=rRLPcWJRFvy0pStFDNVUI/ygr8AxvedYCqVujnHCe8ZA+eQSV2EVwtYtWj7TEROtdF ihEmF7NndSB8FqPfdsSLAFYMCKZHA/P643ojeZpjl9RRKIRhNLHvipQnf2RLq7OtCN/X c3UFEF3jS94lCPDdRPc23LeLjJ/hsXCtuq3pND5BrQ9z2g/R2yLdPpuvxBjL9kPwS7Hy 4ggTfSigZCKHPg/+rACn61TKSLit/yK5RtZSvW3M+UcY+LaWYxJngw7/UOFsbBc0XL1J w6OjdyJlrrWE7evhGZQo/K5ISaQF1hwQX9ZM9NP7wqAiHlw1dDVSAgNEbK4riiJ8aZo4 Vgjw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a170902c94600b001b81a9aa3d1si5782235pla.223.2023.07.08.02.27.00; Sat, 08 Jul 2023 02:27:12 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230346AbjGHJTD (ORCPT + 99 others); Sat, 8 Jul 2023 05:19:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbjGHJTD (ORCPT ); Sat, 8 Jul 2023 05:19:03 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D74291BD2; Sat, 8 Jul 2023 02:19:01 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Qyl7f58Kmz4f3nbk; Sat, 8 Jul 2023 17:18:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgA30JP9KalkALTwNQ--.64171S4; Sat, 08 Jul 2023 17:18:55 +0800 (CST) From: Yu Kuai To: song@kernel.org, logang@deltatee.com, axboe@kernel.dk 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 -next v3] md/raid5-cache: fix a deadlock in r5l_exit_log() Date: Sat, 8 Jul 2023 17:17:27 +0800 Message-Id: <20230708091727.1417894-1-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgA30JP9KalkALTwNQ--.64171S4 X-Coremail-Antispam: 1UD129KBjvJXoW7uw45Ar4DAw4UJF1kJFy5Arb_yoW8AF1Upa ySqrWaq3y8uFyjvF4DC3WUCFyrCw48KryfGr15Cw4Yva4fWry8Gay8Ka409FWvyr4rtrWI vFWFg34rGr10yr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyG14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26c xKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x02 67AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbXdbUUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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: Yu Kuai Commit b13015af94cf ("md/raid5-cache: Clear conf->log after finishing work") introduce a new problem: // caller hold reconfig_mutex r5l_exit_log flush_work(&log->disable_writeback_work) r5c_disable_writeback_async wait_event /* * conf->log is not NULL, and mddev_trylock() * will fail, wait_event() can never pass. */ conf->log = NULL Fix this problem by setting 'config->log' to NULL before wake_up() as it used to be, so that wait_event() from r5c_disable_writeback_async() can exist. In the meantime, move forward md_unregister_thread() so that null-ptr-deref this commit fixed can still be fixed. Fixes: b13015af94cf ("md/raid5-cache: Clear conf->log after finishing work") Signed-off-by: Yu Kuai --- Changes in v3: - Use a different solution. drivers/md/raid5-cache.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c index 47ba7d9e81e1..2eac4a50d99b 100644 --- a/drivers/md/raid5-cache.c +++ b/drivers/md/raid5-cache.c @@ -3168,12 +3168,15 @@ void r5l_exit_log(struct r5conf *conf) { struct r5l_log *log = conf->log; - /* Ensure disable_writeback_work wakes up and exits */ - wake_up(&conf->mddev->sb_wait); - flush_work(&log->disable_writeback_work); md_unregister_thread(&log->reclaim_thread); + /* + * 'reconfig_mutex' is held by caller, set 'confg->log' to NULL to + * ensure disable_writeback_work wakes up and exits. + */ conf->log = NULL; + wake_up(&conf->mddev->sb_wait); + flush_work(&log->disable_writeback_work); mempool_exit(&log->meta_pool); bioset_exit(&log->bs); -- 2.39.2