From patchwork Thu Jun 2 18:18:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 12868051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2252BC43334 for ; Thu, 2 Jun 2022 18:18:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237990AbiFBSSj (ORCPT ); Thu, 2 Jun 2022 14:18:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234209AbiFBSSY (ORCPT ); Thu, 2 Jun 2022 14:18:24 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38A7F4D253; Thu, 2 Jun 2022 11:18:22 -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=RvulF/aPuXxyCuEJPCKiOovtKEBhHz6qdq0wafSQodo=; b=kcDBAN8L4di3KxazFd36A5jm1H yDFf8Q6RmPwlEKPjwz/DzZzHf4uiwoqV4GC9yKVzQmUyo6zNSxpbmAqKPoDDnbUJEvzw00pHAbKJh exSFBTqWc55bGxwKB7FXmZgY0gFUvPub/o53CJofhl4CJbKHb5Ev0boIS9ACuiXwB8QZVik01+5Rs sx1bOSGC+42DOc0ko+dRHBbFzxFP/Jp1pBtvqt6mu0HYBfNu1DxPImYT/gZFzOVc+hV/3zUlS4xcj BMm7DND0rJHuP7SE6N0XhNfkRF0HmiGCPt2zp7TzOx9x19PrrA7XOoivNyEXPkSTKguJqg/FMpKez oomb8zFA==; 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 1nwpOm-00EPmY-Pz; Thu, 02 Jun 2022 12:18:21 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1nwpOl-000DDJ-Py; Thu, 02 Jun 2022 12:18:19 -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: Thu, 2 Jun 2022 12:18:09 -0600 Message-Id: <20220602181818.50729-4-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220602181818.50729-1-logang@deltatee.com> References: <20220602181818.50729-1-logang@deltatee.com> MIME-Version: 1.0 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 Subject: [PATCH v3 03/11] md/raid5: Ensure array is suspended for calls to log_exit() 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-raid@vger.kernel.org The raid5-cache code relies on there being no IO in flight when log_exit() is called. There are two places where this is not guaranteed so add mddev_suspend() and mddev_resume() calls to these sites. The site in raid5_remove_disk() has a comment saying that it is called in raid5d and thus cannot wait for pending writes; however that does not appear to be correct anymore (if it ever was) as raid5_remove_disk() is called from hot_remove_disk() which only appears to be called in the md_ioctl(). Thus, the comment is removed, as well as the racy check and replaced with calls to suspend/resume. The site in raid5_change_consistency_policy() is in the error path, and another similar call site already has suspend/resume calls just below it; so it should be equally safe to make that change here. Signed-off-by: Logan Gunthorpe Reviewed-by: Christoph Hellwig --- drivers/md/raid5.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 5d09256d7f81..3ad37dd4c5cd 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -7938,18 +7938,9 @@ static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev) print_raid5_conf(conf); if (test_bit(Journal, &rdev->flags) && conf->log) { - /* - * we can't wait pending write here, as this is called in - * raid5d, wait will deadlock. - * neilb: there is no locking about new writes here, - * so this cannot be safe. - */ - if (atomic_read(&conf->active_stripes) || - atomic_read(&conf->r5c_cached_full_stripes) || - atomic_read(&conf->r5c_cached_partial_stripes)) { - return -EBUSY; - } + mddev_suspend(mddev); log_exit(conf); + mddev_resume(mddev); return 0; } if (rdev == rcu_access_pointer(p->rdev)) @@ -8697,8 +8688,11 @@ static int raid5_change_consistency_policy(struct mddev *mddev, const char *buf) err = log_init(conf, NULL, true); if (!err) { err = resize_stripes(conf, conf->pool_size); - if (err) + if (err) { + mddev_suspend(mddev); log_exit(conf); + mddev_resume(mddev); + } } } else err = -EINVAL;