Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2322947rwb; Sat, 29 Jul 2023 04:53:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlE34gHD0CZMrI9Zj3QoBm3Z/eSFDZTsaaRG4PSQSVjPgVaYIGqaxku6XPtHlOGhG1LX5pcV X-Received: by 2002:a17:907:770b:b0:997:ea90:96b4 with SMTP id kw11-20020a170907770b00b00997ea9096b4mr1893675ejc.61.1690631610443; Sat, 29 Jul 2023 04:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690631610; cv=none; d=google.com; s=arc-20160816; b=rZyBCrJJzjg15mJcu+x9mc6V0m4oXoCbl/URQS/4IwGKT8jsf8aj/mWkof7NKdtI5V rTk8oezojYVKrWORoxQiAJ0JrtL0/BZ92IJd7FPx5AyPKOKDE5qhQbK/xuPrtcO8Hm/3 bFJXdovKWU/75UwL7Vf2xGI6jMVAY9zfV0cg/nwRICi60UlQyzPQvKC3fkK5d3InK/hS x1LAkqQdq9ZnzSr4Ca5mYfKBjpwYYKIm8Et3rahbiOJMQBmNQqRTuiKx7tqCZ28xsRxw qA/+EhDqA9iX8GiNeSmim/YG1fJAmp9Krq0KESm8TxeUWU5kDdHtm+4Di4yv55ywo33R nhPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=snKN2lNn/yyPZyoJRh9EHUImfA80DNIRQrHau2pM2mY=; fh=I2PQKrhCKF5V6h+/fmpFVGAtQRFx8zlhflMLylpNFDo=; b=ytuP3Q2K48fZDxfnUUfEigVleos2B4NFSXTy4htrLKF+lFpT6iO9Ejhydao6Xn6Tzb s78E3uvC7H36C7t2PSOCpAvaJZrB9WpoS6NwBfRMNfODHXe3MD5Ps2Ky0sOBk4piiP3W O+nKmYF6lOAekw/2+AxZTQW6znRujfQ3gj2XZjJ2UpnqgglVQ9Chum0kmV68pwYPPcDL t/DwWqrGy72t2vYU3cOWBsuHeo4PRVPRVmh5KWtV2Gps0dGc8/mnFsoTej987IPtMPvv RyciI+QPdErgOvUpz0pba6qXZH52Eq8j+CG3bbNbIJ76MhzNUjVDNEvfq+sW8BLjTIg/ PWNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DgFa1ZUU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20-20020a056402161400b0051ffa9193f8si3975613edv.445.2023.07.29.04.53.06; Sat, 29 Jul 2023 04:53:30 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DgFa1ZUU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230108AbjG2KpH (ORCPT + 99 others); Sat, 29 Jul 2023 06:45:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjG2KpF (ORCPT ); Sat, 29 Jul 2023 06:45:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 239068F; Sat, 29 Jul 2023 03:45:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AB62C60B75; Sat, 29 Jul 2023 10:45:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18F91C433C7; Sat, 29 Jul 2023 10:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690627503; bh=QKrBqbolOOxaTiWGKT2BMxkYZZvn5TZqjT8KkvNIpMM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=DgFa1ZUUCoB3uXmxgqMIsCn4DNQLTYwZ9Hna06Khvpbx7Y3wJDWjdEnjto1Ep9X4i n6XBlRZfFrQKUB/ujZbD7s5A1iJ3/GCPukISXKtrIhWtEQ7VbXejZ7C9RABRtGQMvQ 085Av922ZQCrR6j/VxP0CAqVZ92QEQ12erN+QM1QoSUMasJtbobwr1wOKs9hYX0H+6 Hpxg2PGl39tyfQWEp5J61tVrUXLFjcgIkDY+1g+pYCEMgW8CU4MS39AJmEwiWGmkM9 bl6BrjEB387/Pt4t4en7zmugIBRfoZ1c524+XtOUe5ldG7iq3h06dbYVBuTrH1lBQB nKbOiNd/2qnKw== Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2b962c226ceso43611701fa.3; Sat, 29 Jul 2023 03:45:03 -0700 (PDT) X-Gm-Message-State: ABy/qLY23KJBA6knnGjbkVo3wP6aE8qkykmRbNEknwEzFnlNWihg3tcG GED3ciOoPY6zMC+AKeIyYie0IOfw7IZPZ4Z7lgQ= X-Received: by 2002:a2e:96cd:0:b0:2b9:d266:85ac with SMTP id d13-20020a2e96cd000000b002b9d26685acmr2333016ljj.48.1690627501117; Sat, 29 Jul 2023 03:45:01 -0700 (PDT) MIME-Version: 1.0 References: <20230708091727.1417894-1-yukuai1@huaweicloud.com> In-Reply-To: <20230708091727.1417894-1-yukuai1@huaweicloud.com> From: Song Liu Date: Sat, 29 Jul 2023 18:44:48 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH -next v3] md/raid5-cache: fix a deadlock in r5l_exit_log() To: Yu Kuai Cc: logang@deltatee.com, axboe@kernel.dk, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 On Sat, Jul 8, 2023 at 5:19=E2=80=AFPM Yu Kuai wr= ote: > > 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 =3D 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 wor= k") > Signed-off-by: Yu Kuai Applied to md-next. Thanks! Song > --- > > 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 =3D 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 t= o > + * ensure disable_writeback_work wakes up and exits. > + */ > conf->log =3D 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 >