Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2689914iof; Wed, 8 Jun 2022 10:00:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynOYIuY/M6sYPR9wzoRdmNI+p27a3Z4zT7hsAkK2TNbisSBu4J970HPDLby0y46ZxUaLd6 X-Received: by 2002:a63:4844:0:b0:3fc:c299:a7a4 with SMTP id x4-20020a634844000000b003fcc299a7a4mr30570075pgk.510.1654707619601; Wed, 08 Jun 2022 10:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707619; cv=none; d=google.com; s=arc-20160816; b=aXqODpxvWrSIkm9OsL2nU5GgzinSzurX7LxIlddysDTyqCKI7n44jJzAtT3Z4dtskS MEI4o+HYCaJLPj/ledVQYo4A5pxRvxw30WEoOfYVXkHt4/uD/q0Ip6uc82zHcTHoNP6x XjehPVKtxEtazfM/w1WlyYT2IoB3By/mlEISJ9IjrszYBnSIcJtlxNlx/eg/LPicCAeL Oa3lhVpzXa/kXu1QjbkkZnE3AQgdshU1f4oeNR47Dy2vSkUjJAIc58xZC7JasXqFtruv 1zgHlVEXO+Ep3cBD+yZHMrKqDv02BcHPqgZY5XwzUprMqn7pSrEu8vP12b8XO7rofXlf 8jNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=MiCPhTWWfi3d1Han0tZIW/P4zdztR1K7Ax/z77ioJXs=; b=C2X8yJWHmGAKRsLqA53wCZDq8kgYepopkMCeeKKXpfKu2YHiWep/+EMchwGKKwOlu7 O9I9N3IjeahyIs+m6imhdULDztDztYd9LHqvKUx5elYQEZKrjHWoyezH69snUbizTrme dHnLCFPcwQfnsE+cNUjRwjFbyVbktDiz25Cw5emO2fl4E7ommJEVu11/oqwQ120juJbt 5lTQ3k3ag3/wNKwSIWO4UL3uM1VEfFliGkZLCyj66xPyccpYWYntWaWvDs3NSfV6eKUE SkNkRxYVMo0Okbmf2ncuRFNUlGkUdMkUEwoEPRQqQka7r1Zg16Mf0pyOJmD3Clv071mb 3icw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=Ikr+r7qG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h1-20020a170902f54100b0015eb10a9f67si34859877plf.379.2022.06.08.09.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 10:00:19 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=Ikr+r7qG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C25F726EE9D; Wed, 8 Jun 2022 09:30:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245159AbiFHQ2r (ORCPT + 99 others); Wed, 8 Jun 2022 12:28:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245178AbiFHQ2I (ORCPT ); Wed, 8 Jun 2022 12:28:08 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00AB01FE8C2; Wed, 8 Jun 2022 09:28:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=MiCPhTWWfi3d1Han0tZIW/P4zdztR1K7Ax/z77ioJXs=; b=Ikr+r7qGi3R7CGGV5QudeUQyj0 aiv3j6f0hDZssW68VZ/cb6ff7X4zqa2lnU1P+3qfx4lGOH4BywiZhQs7OiG4yDtKyFjKihYkYyiUN Ho4RbMKkl7e9BNNC96dAFz22E6WZBElOc5vhehSGMQEaLnJwyXtReKHDCiaQQ/D93prb8UYizX5IH 3cHoYn/f5NFmTJ+5nkZoaHkA5KyoOgkgiLEPxvyxxSxeB5PtiltCfgGuzni+02Y813BTT1JRGPZ39 wOA/GkPP6NJ2Am5Bmbhe9S1UJj8LaE4I5efueiePh3kaLME5hv/6e09rNuKnT3iPbGV6szqw/2juV H97nIw3Q==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nyyXN-0026n5-Ft; Wed, 08 Jun 2022 10:28:06 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1nyyXG-000bdS-Pt; Wed, 08 Jun 2022 10:27:59 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, Song Liu Cc: Christoph Hellwig , Donald Buczek , Guoqing Jiang , Xiao Ni , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe , Christoph Hellwig Date: Wed, 8 Jun 2022 10:27:50 -0600 Message-Id: <20220608162756.144600-6-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220608162756.144600-1-logang@deltatee.com> References: <20220608162756.144600-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, song@kernel.org, hch@infradead.org, buczek@molgen.mpg.de, guoqing.jiang@linux.dev, xni@redhat.com, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com, hch@lst.de X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 Subject: [PATCH v4 05/11] md/raid5-cache: Take mddev_lock in r5c_journal_mode_show() X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The mddev->lock spinlock doesn't protect against the removal of conf->log in r5l_exit_log() so conf->log may be freed before it is used. To fix this, take the mddev_lock() insteaad of the mddev->lock spinlock. Signed-off-by: Logan Gunthorpe Reviewed-by: Christoph Hellwig --- drivers/md/raid5-cache.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c index 83c184eddbda..ca8fc317da95 100644 --- a/drivers/md/raid5-cache.c +++ b/drivers/md/raid5-cache.c @@ -2534,12 +2534,13 @@ static ssize_t r5c_journal_mode_show(struct mddev *mddev, char *page) struct r5conf *conf; int ret; - spin_lock(&mddev->lock); + ret = mddev_lock(mddev); + if (ret) + return ret; + conf = mddev->private; - if (!conf || !conf->log) { - spin_unlock(&mddev->lock); - return 0; - } + if (!conf || !conf->log) + goto out_unlock; switch (conf->log->r5c_journal_mode) { case R5C_JOURNAL_MODE_WRITE_THROUGH: @@ -2557,7 +2558,9 @@ static ssize_t r5c_journal_mode_show(struct mddev *mddev, char *page) default: ret = 0; } - spin_unlock(&mddev->lock); + +out_unlock: + mddev_unlock(mddev); return ret; } -- 2.30.2