Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2360406lqp; Sun, 24 Mar 2024 15:41:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXgMpNQeevxejyuichvdDZz6hxVnTtS+h2jL70WkJ52MtlzbAQFT78E4+38KliAQGRmY6p6lffGNnHzr4N2dtBNs4xFcMBtGabWQjXYNg== X-Google-Smtp-Source: AGHT+IGjPqlQyUA1HPBNwqb8m27ltKVSogl4O+yOcTL2luLZeuxDUBC+6Hp2MfVf0PwEQLNsx9FO X-Received: by 2002:a05:622a:1ba1:b0:431:14cf:d62a with SMTP id bp33-20020a05622a1ba100b0043114cfd62amr7202613qtb.19.1711320095175; Sun, 24 Mar 2024 15:41:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711320095; cv=pass; d=google.com; s=arc-20160816; b=duZ9YgT0FEKg1z7a+C7yYHEUyIgTngXn/Oe5IoifDzTdYjVzbnC27NrT2IDD6YqF9S JvFxYhy0bHIWIobIhqnxLA6YLwhTjJzOuysXFyVbPP0ylPvkAw/FwWpmV+smgbxRvME0 eB3khE69BEXtyfBVH/eWdq+16E0ZeFQVzuxdaAy/FQA7TtRS280cRN2zNxf5J8cS9NQF npMYlKxJ9L8KUJcK8kLD4SW2roibrh3IT4/VtYLjd9PY/lfoKy3c1h0bzrAaMptJAenn VgiB+MhzkGsK/7kT7jedMcMGu/i+bg7z1hS7cWocoT19JT0cPvpelD7gGJITWZHklvwb pl0Q== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=oVe0Lg7QLgWv6EyUf1LJ2ZbXKQGw94by7XJF6R36DV0=; fh=f8pXtFtHJr1IoxyyJRUxDnmQXZ3ygLliteBvJMPm/Ww=; b=zKHG7XAv99IsX3B52tta5fWoSSGXxygkFXDzTMi4tHP8sOkMjeQ8XsXTOR2sSELkst gzDgRA32aep6Htb6VudyEx6DbpZUzO4jWL1baztHDEop0XqtuFno5sPZHtNO/RlUT7eV em3tbtp9azqsDD4btQOG9uU7bgHtwc/3mIpYibN7HDCY0eIMIgWjVAQ80aNn+FUM7afJ EuN5lbNtNCApoWccNLAZtFvrrrFmNQ6HFZEkXfA5goOK01CTq1fVQLeC/uuRohBXioVi syrWOU4LET9AysFLIiKV6TpbqyzSAo9grTmQTFXm5bWIbGYkfIhZ7rvIx1EEHYwBDAKA nljw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uPohn6xB; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112912-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112912-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id hb11-20020a05622a2b4b00b0042f3074099esi4086038qtb.495.2024.03.24.15.41.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:41:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112912-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uPohn6xB; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112912-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112912-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D76551C2118C for ; Sun, 24 Mar 2024 22:41:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 363906BFB0; Sun, 24 Mar 2024 22:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uPohn6xB" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5788C5D8E1; Sun, 24 Mar 2024 22:35:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319723; cv=none; b=BgKzkS8y7yiGqJYzZpX/xfXJV/Lq8jXAu8VYY+2UFK3DPM4jD7d7vScXc53LfDS+teNMNKV+2//7uenEl5YdCA6i3LvPUZ9AwLa03l/63Er0VhpRyFZFMu/7O+UDfdYO9Snmn/dLfMmwR7Sq0abfiqxUZoqsXqUud38CwOQZ+FE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319723; c=relaxed/simple; bh=9ow4d0I8ykKepUEvPvrJCVgpBOAMKiYp+QNhUH5Nfv8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fW7twq92qh4WjZKPTNwVLZ7F5hHXDA0RXz1obcHfLn5gTMGA5O29f8S7rqvDGYI4a9qE4Ta+v3JdxdywgMWr+8iByS69Woq7iJPamBUoBiWYB8e+3+H44JEMtl5B7oiCh/3Q1ScLoWxtcGdVXb7eRWktxjBRsaNvG5inZQrxUco= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uPohn6xB; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BF80C433B1; Sun, 24 Mar 2024 22:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319723; bh=9ow4d0I8ykKepUEvPvrJCVgpBOAMKiYp+QNhUH5Nfv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uPohn6xBclq1NYKNUfcswXshr1jgGuSBPqmff3GMCPSYHEGQCGVnJsTsUBAGtT9aF vr1OtAeMPBRsycmJmsIScehY1GAXMg/ulwTnQaduGxvRIdTvkPUyeZgqG5kJiwEivv ixzuIfj8Tu7c9AnrV4eF+KDkrScHIN5poDNUFH3cqyE4yduoLe35Lu7D/F62nXY7xx K2JOWrzqkilr82Ic/MC9O+1l4C5fkbuX2KAQ9XVTaDDeodrIpGOm/qyAwSAs65JrfG yZdbtDcvToiUoEvdGqXtlj69xPUWfvEZT2Lbp7f4KX8N/RjScdQAMj02OLB3bFlgju C6axcDvfbPbdQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Li Nan , Yu Kuai , Song Liu , Sasha Levin Subject: [PATCH 6.8 025/715] md: Don't clear MD_CLOSING when the raid is about to stop Date: Sun, 24 Mar 2024 18:23:24 -0400 Message-ID: <20240324223455.1342824-26-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Li Nan [ Upstream commit 9674f54e41fffaf06f6a60202e1fa4cc13de3cf5 ] The raid should not be opened anymore when it is about to be stopped. However, other processes can open it again if the flag MD_CLOSING is cleared before exiting. From now on, this flag will not be cleared when the raid will be stopped. Fixes: 065e519e71b2 ("md: MD_CLOSING needs to be cleared after called md_set_readonly or do_md_stop") Signed-off-by: Li Nan Reviewed-by: Yu Kuai Signed-off-by: Song Liu Link: https://lore.kernel.org/r/20240226031444.3606764-6-linan666@huaweicloud.com Signed-off-by: Sasha Levin --- drivers/md/md.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index bfd04a9e80796..d344e6fa3b26f 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -6279,7 +6279,15 @@ static void md_clean(struct mddev *mddev) mddev->persistent = 0; mddev->level = LEVEL_NONE; mddev->clevel[0] = 0; - mddev->flags = 0; + /* + * Don't clear MD_CLOSING, or mddev can be opened again. + * 'hold_active != 0' means mddev is still in the creation + * process and will be used later. + */ + if (mddev->hold_active) + mddev->flags = 0; + else + mddev->flags &= BIT_ULL_MASK(MD_CLOSING); mddev->sb_flags = 0; mddev->ro = MD_RDWR; mddev->metadata_type[0] = 0; @@ -7625,7 +7633,6 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, int err = 0; void __user *argp = (void __user *)arg; struct mddev *mddev = NULL; - bool did_set_md_closing = false; if (!md_ioctl_valid(cmd)) return -ENOTTY; @@ -7709,7 +7716,6 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, err = -EBUSY; goto out; } - did_set_md_closing = true; mutex_unlock(&mddev->open_mutex); sync_blockdev(bdev); } @@ -7851,7 +7857,7 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, mddev_unlock(mddev); out: - if(did_set_md_closing) + if (cmd == STOP_ARRAY_RO || (err && cmd == STOP_ARRAY)) clear_bit(MD_CLOSING, &mddev->flags); return err; } -- 2.43.0