From patchwork Mon Aug 14 08:51:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xueshi Hu X-Patchwork-Id: 13352577 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 331ECEB64DD for ; Mon, 14 Aug 2023 08:52:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231706AbjHNIvb (ORCPT ); Mon, 14 Aug 2023 04:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234072AbjHNIv3 (ORCPT ); Mon, 14 Aug 2023 04:51:29 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6301BF for ; Mon, 14 Aug 2023 01:51:28 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-686ba97e4feso3959974b3a.0 for ; Mon, 14 Aug 2023 01:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1692003088; x=1692607888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JYH9G+Wt6Ub5OE4dUzW+0/2J+mzsvG/nR+TsZwqDITw=; b=JQO8nPP8tAnsFE77Kf75i+mjqeukEdDjug3P4Ol03TUmYpMuFw08d6qmjt8z85xX84 DhAJ1cWO3ml+FTvguVtxQcEDgxtV/vbXlea6TL7TpmYbaxW3UnLG6ajVROQwlwf7fG6D Y87BcshvQeHHfoqMX2rcvbhNyqoLUk5i7gbOuh6eAebrOc/tSe8A4vo/5xwJ/6Qbowr4 NvNYSFidlYFOPMdAaaiFTZiUTgaG9MXk7H9nyBxsAa/N/27xuT6pgV2/5p/ssR1DKBdY YAEpzBGP/o48F6icTFiu14y3MW7ujidz0Dy/+KBkEyZ8zrI2+1aqamCi0S1DK0PBraEK xrEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692003088; x=1692607888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JYH9G+Wt6Ub5OE4dUzW+0/2J+mzsvG/nR+TsZwqDITw=; b=LvJD0Km9EC0p32PHwlG2g+pL9pgcwakGzGE01oqm76BZZCvVD9fcM1Ty/NvxIBtzXN EIavmhgUFuVpOMXn5Kaz5+/fQNsEzKT3SYQmoNcm28Ksg/Ix6oDTDPQUYY+nEhyS0cOV yaMHwOmT7aCH4Q4YIkorv91jpojxRFqsQlsVnEi5ttoXDqKOWjixlB0XLP2h98rXIeJU LSHOtERnj7pQYCYxjWd9MUJIlVmMbvTBrsQCMYQEDrAAcHYOYdlbLTyJGx00Uprjz6D2 chx10OiKoI+hPjGPcCy8WND4ewU4HMBSa29gXahq1FqGnPcz9FT9Lq9Mv4643YdxC+pv aNTQ== X-Gm-Message-State: AOJu0YzyyND42AJcovPkuXxWUXNT3mfo3YduGQn3H7lh8eXezQjhXm6X 9ljvBubSvMnWW0Nj9hHJtoZTkaTXgU9wJm7Z+yUCTGXY X-Google-Smtp-Source: AGHT+IHZDM8HenNPnRE++mOH5+KBAfHhah9kpsKQN6+Zf0AaG1BybiZV0OMykyj25Id8DA8VUNSLEw== X-Received: by 2002:a05:6a20:431a:b0:13f:9232:fd39 with SMTP id h26-20020a056a20431a00b0013f9232fd39mr13073181pzk.53.1692003087859; Mon, 14 Aug 2023 01:51:27 -0700 (PDT) Received: from nixos.tailf4e9e.ts.net ([47.75.78.161]) by smtp.googlemail.com with ESMTPSA id fk1-20020a056a003a8100b006765cb3255asm7439668pfb.68.2023.08.14.01.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 01:51:27 -0700 (PDT) From: Xueshi Hu To: song@kernel.org, djeffery@redhat.com, dan.j.williams@intel.com, neilb@suse.de, akpm@linux-foundation.org, neilb@suse.com Cc: linux-raid@vger.kernel.org, Xueshi Hu Subject: [PATCH v5 1/3] md/raid1: call free_r1bio() before allow_barrier() Date: Mon, 14 Aug 2023 16:51:06 +0800 Message-Id: <20230814085108.991040-2-xueshi.hu@smartx.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230814085108.991040-1-xueshi.hu@smartx.com> References: <20230814085108.991040-1-xueshi.hu@smartx.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org After allow_barrier(), an concurrent raid1_reshape() will replace old mempool and r1conf::raid_disks, which are necessary when freeing the r1bio. Change the execution order of free_r1bio() and allow_barrier() so that kernel can free r1bio safely. Fixes: c91114c2b89d ("md/raid1: release pending accounting for an I/O only after write-behind is also finished") Signed-off-by: Xueshi Hu Reviewed-by: Yu Kuai --- drivers/md/raid1.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index dd25832eb045..dbbee0c14a5b 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -313,6 +313,7 @@ static void raid_end_bio_io(struct r1bio *r1_bio) { struct bio *bio = r1_bio->master_bio; struct r1conf *conf = r1_bio->mddev->private; + sector_t sector = r1_bio->sector; /* if nobody has done the final endio yet, do it now */ if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) { @@ -323,13 +324,13 @@ static void raid_end_bio_io(struct r1bio *r1_bio) call_bio_endio(r1_bio); } + + free_r1bio(r1_bio); /* * Wake up any possible resync thread that waits for the device * to go idle. All I/Os, even write-behind writes, are done. */ - allow_barrier(conf, r1_bio->sector); - - free_r1bio(r1_bio); + allow_barrier(conf, sector); } /* From patchwork Mon Aug 14 08:51:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xueshi Hu X-Patchwork-Id: 13352580 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 2111BC04FE0 for ; Mon, 14 Aug 2023 08:52:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232958AbjHNIwE (ORCPT ); Mon, 14 Aug 2023 04:52:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231764AbjHNIvb (ORCPT ); Mon, 14 Aug 2023 04:51:31 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E4D791 for ; Mon, 14 Aug 2023 01:51:31 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-687ca37628eso3950705b3a.1 for ; Mon, 14 Aug 2023 01:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1692003090; x=1692607890; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CWWBCzOt57+qvyHkw3KX99OkaI9d/CMtTn9A66pF5gI=; b=mejzojIkIqugIpRepLf04mfYDF9dICV+jihyazhmfuNWTFgqoBNxuTrdmMhIDGrwRb 2WKpadrJQJ6ZW0z8GrlhlNHbQP5vhYpfqcUTfBMD4iwAUaNlSSTpQg4XCI6MV5IIDs8j HDpf2dg5fw8vHjkL1swaV6h6VpNJ9UKA3RkOyiJeLOXS+V3WWfAA3sYkWja4cftgFi58 WX0Tj5BPkX3eKNpDCJBr+Cz0TLl7IXjOCt5JdR528qBwLllra+DMC0oq61N8pg5E3zg0 2d04B5812Fn51nMku/euwQXDXilj+WsFPI45Pf2fWm6SPfLuCqTejE5LZoKuTjYaryqi ohyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692003090; x=1692607890; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CWWBCzOt57+qvyHkw3KX99OkaI9d/CMtTn9A66pF5gI=; b=CoUzxRFo0ukTsP/vkwX5Zp75iWaemrj98Oxh0r+71o2jbLQxXEVEvgOsDS/Vg70C8P anY1/PyAjZ/yFJ6qjdHEgIvHwVW1Ac2Y8glHYk+1U8mQvht6Wi+FKGoEojNRQn2iD6CH dUYJBUyqifLjttnWP5K2PtVJq0Lxa6cYG7O8ofAzwqSpSl8BwE4UW6GvGddaBVbQxgBo b8XrO8R0YRXBcqAuOYfMMoZB7gKgooS9rvZwre0KhWp8AFsF68wWiqTFdQBAbiWfzYgj foJx/FLA90aRoBZwzOtUW067HR50Z1oE1NjUfgvh3pUzHMLZY1tBQbeuD1NIk7LUSpUY z8vA== X-Gm-Message-State: AOJu0YzVasxJRrqIdhH2XBk3E5Ra6XyksTuk+0siO3m+QhfABL18BwZT yIqU0ZKVh+ZDu10+hSMG9C9Wag== X-Google-Smtp-Source: AGHT+IH7woDi33QaVWN03ikKJs4yTs6CqRRl+gJUknPZ0PQEYbDodRnzDK9Yj9n6uUL3IsDWkLJbWA== X-Received: by 2002:a05:6a20:938c:b0:13a:6bca:7a84 with SMTP id x12-20020a056a20938c00b0013a6bca7a84mr14198342pzh.44.1692003090509; Mon, 14 Aug 2023 01:51:30 -0700 (PDT) Received: from nixos.tailf4e9e.ts.net ([47.75.78.161]) by smtp.googlemail.com with ESMTPSA id fk1-20020a056a003a8100b006765cb3255asm7439668pfb.68.2023.08.14.01.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 01:51:30 -0700 (PDT) From: Xueshi Hu To: song@kernel.org, djeffery@redhat.com, dan.j.williams@intel.com, neilb@suse.de, akpm@linux-foundation.org, neilb@suse.com Cc: linux-raid@vger.kernel.org, Xueshi Hu Subject: [PATCH v5 2/3] md/raid1: free the r1bio firstly before waiting for blocked rdev Date: Mon, 14 Aug 2023 16:51:07 +0800 Message-Id: <20230814085108.991040-3-xueshi.hu@smartx.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230814085108.991040-1-xueshi.hu@smartx.com> References: <20230814085108.991040-1-xueshi.hu@smartx.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org Raid1 reshape will change mempool and r1conf::raid_disks which are necessary when freeing r1bio. allow_barrier() make an concurrent raid1_reshape() possible. So, free the in-flight r1bio firstly before waiting blocked rdev. Fixes: 6bfe0b499082 ("md: support blocking writes to an array on device failure") Signed-off-by: Xueshi Hu Reviewed-by: Yu Kuai --- drivers/md/raid1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index dbbee0c14a5b..5f17f30a00a9 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1374,6 +1374,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, return; } + retry_write: r1_bio = alloc_r1bio(mddev, bio); r1_bio->sectors = max_write_sectors; @@ -1389,7 +1390,6 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, */ disks = conf->raid_disks * 2; - retry_write: blocked_rdev = NULL; rcu_read_lock(); max_sectors = r1_bio->sectors; @@ -1469,7 +1469,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, for (j = 0; j < i; j++) if (r1_bio->bios[j]) rdev_dec_pending(conf->mirrors[j].rdev, mddev); - r1_bio->state = 0; + free_r1bio(r1_bio); allow_barrier(conf, bio->bi_iter.bi_sector); if (bio->bi_opf & REQ_NOWAIT) { From patchwork Mon Aug 14 08:51:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xueshi Hu X-Patchwork-Id: 13352579 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 0A738C04E69 for ; Mon, 14 Aug 2023 08:52:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233147AbjHNIwG (ORCPT ); Mon, 14 Aug 2023 04:52:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232618AbjHNIvf (ORCPT ); Mon, 14 Aug 2023 04:51:35 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DFD7BB for ; Mon, 14 Aug 2023 01:51:33 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-686b643df5dso2703260b3a.1 for ; Mon, 14 Aug 2023 01:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1692003093; x=1692607893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YxJk6xFqYMyd2Arn2NrhuCFZq+WpZgkUoQ8LNr9Tn9U=; b=z5A8Mq4DNvfueMGNESjXSgyINye8JiOBGqS52Pev9HPBvM92wTI5rIirLp4+3Ba05K mYt/q7CW4HAw2q0lf0j5Nf+tPk3yLojMzTgROrMiDcReIaHgN+yxF4YFIZ3ZoRoHzi75 n7Y7/euENKy16U3HhoVU505CIJRsYCyFljQyHZztAtfNYP/vkUlVNwIbWTehA66cgw7H Jskl+CS9hW0ydPYxtN/F5ppz0GHVkVUGfp1YrdaFZHRC5w9aofpLh2ZLvm8HrrwMGJTD eUwfonluEOKh4q1XEV88otDrmiT9I6ZLDrMzHjs4NulcH/amhMGJeV7+E6S6M1l1Mvfy UeNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692003093; x=1692607893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YxJk6xFqYMyd2Arn2NrhuCFZq+WpZgkUoQ8LNr9Tn9U=; b=Lt2ANGo8a3NnwV0mWMNagQATagt3GhnanfLzT9WJxRUlvr9ExJrNRU9HpDyu5lQ7GN cakDLKH6npvwxRAJ+rOP4VrvRgtVCWwVu//Zg/rFKsIslWQS/jz09/p1ED+gVFx04G0t +IbIsUfijQRjwtBPFrKlcsLm1PMzbHJiusbZy0/+l9t1AJVh7RJ36HVcYrKHtFEmoMVg gtm6dShmIaibwl2mlw+PzVFLznPyvq0U4i+jHEfFoj7F17Wm40jAs7XDKuiT+GlBBogY SWxjrhanjIKpsXS8XHR1ArVIUgC8okr+3zr5cs245bI25LAeX3puGL9w54LGte4gExcA zaWA== X-Gm-Message-State: AOJu0Yx8xQbuBLzAdgPC/3PAQ9R1zt9FodpmVx7ECZExXyiMHkzbxZe1 HxTRr7B5q/FAviAtsLbQKZb5/+UXpHOsOvdOGw10yHaI X-Google-Smtp-Source: AGHT+IGHQVtpLPTqgN4QjmWjMMR3idbTYDD0RytfRBFJfQYjuDrXNv9n5xJ+Ib0oOBvhsxKvIxQt3Q== X-Received: by 2002:a05:6a20:3947:b0:135:293b:efaf with SMTP id r7-20020a056a20394700b00135293befafmr10826465pzg.10.1692003092968; Mon, 14 Aug 2023 01:51:32 -0700 (PDT) Received: from nixos.tailf4e9e.ts.net ([47.75.78.161]) by smtp.googlemail.com with ESMTPSA id fk1-20020a056a003a8100b006765cb3255asm7439668pfb.68.2023.08.14.01.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 01:51:32 -0700 (PDT) From: Xueshi Hu To: song@kernel.org, djeffery@redhat.com, dan.j.williams@intel.com, neilb@suse.de, akpm@linux-foundation.org, neilb@suse.com Cc: linux-raid@vger.kernel.org, Xueshi Hu Subject: [PATCH v5 3/3] md/raid1: keep the barrier held until handle_read_error() finished Date: Mon, 14 Aug 2023 16:51:08 +0800 Message-Id: <20230814085108.991040-4-xueshi.hu@smartx.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230814085108.991040-1-xueshi.hu@smartx.com> References: <20230814085108.991040-1-xueshi.hu@smartx.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org handle_read_error() will call allow_barrier() to match the former barrier raising. However, it should put the allow_barrier() at the end to avoid an concurrent raid reshape. Fixes: 689389a06ce7 ("md/raid1: simplify handle_read_error().") Signed-off-by: Xueshi Hu Reviewed-by: Yu Kuai --- drivers/md/raid1.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 5f17f30a00a9..5a5eb5f1a224 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -2499,6 +2499,7 @@ static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio) struct mddev *mddev = conf->mddev; struct bio *bio; struct md_rdev *rdev; + sector_t sector; clear_bit(R1BIO_ReadError, &r1_bio->state); /* we got a read error. Maybe the drive is bad. Maybe just @@ -2528,12 +2529,13 @@ static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio) } rdev_dec_pending(rdev, conf->mddev); - allow_barrier(conf, r1_bio->sector); + sector = r1_bio->sector; bio = r1_bio->master_bio; /* Reuse the old r1_bio so that the IO_BLOCKED settings are preserved */ r1_bio->state = 0; raid1_read_request(mddev, bio, r1_bio->sectors, r1_bio); + allow_barrier(conf, sector); } static void raid1d(struct md_thread *thread)