From patchwork Mon May 22 11:54:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 97348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1395146vqo; Mon, 22 May 2023 05:05:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Gh4F1nS9vgJn7ryU9wpjsfbA6R3D8rEADTVr1JBwZ78z69//MVRxNx0TrqgOnHkJd8H20 X-Received: by 2002:a17:902:a5c7:b0:1ae:50a4:78da with SMTP id t7-20020a170902a5c700b001ae50a478damr9295673plq.67.1684757151143; Mon, 22 May 2023 05:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684757151; cv=none; d=google.com; s=arc-20160816; b=CumR1wEKLIiuacy1z9q+ORMQ/sLVPUh1ZTx17/g+1h9B8hqCRe4UQt3upQ/WyxUCb1 +XiLEC5VZvtGIoslB6v2h01aJB3+HX2blClcxyQBOMCMYahZT3TWCc2WLIN/BOJHDYm6 sl5AsCP7azoRYSoh2Y09v9nj+sI5DoamTm6lNDLnQ3r/Nd3v2hNZ6iuDmYhYd5utcCAL LDn4A88jHBSDNo+1ZcxQAzNjS8SoUJSf7VkSk6jSWKTyhE+HjczLqAK4pftm9J83EAJv R/FFdsxuNXfu+ouNoPvHh1wtQKSRVdnA4z+x/A+Y0Xg+0/188YvScpa5QIs/sMF6YHxS 3b2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9BIXTH8HgeQvXbqRB35mFbw8wytZBMoHlNvOIQ1DOrU=; b=qPFp/Hsb6Hxeq72iLDV3S5cw0UAY3oNgmSftbMehl1kLuFf09ZpHHyAUaqSAuMgdMB XqqY/22aZ+/nB17/NvnUWnaEL16WrBsbAikp7/dZVyjKm1wE7iEpGsjt7cxcsLZKSIQA TIVuWu+dUv6iZ5Di4RMUKZ7D+jyNlz7wGEQA53ZY8UtI3X/PT92fixY/in6MqMsl9OYa tw8fgVfhQZN++1r2YxVSHB+jL2/zfy541GoTfshZWBBjT0aSYMIWSbubQGrMqL7r73ga V4YKRwIpLBhfV6YsYhS7gu/48lp3UcnU0Url8se33uS0npywPHQSNJofH1CwXmw8JDck M1lQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020a170902b61300b001a51368b098si28612pls.209.2023.05.22.05.05.38; Mon, 22 May 2023 05:05:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233560AbjEVL4m (ORCPT + 99 others); Mon, 22 May 2023 07:56:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233179AbjEVL41 (ORCPT ); Mon, 22 May 2023 07:56:27 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 005F4AB; Mon, 22 May 2023 04:56:24 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QPws03b1Gz4f3lwx; Mon, 22 May 2023 19:56:20 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBXwLNiWGtk2XrkJw--.28031S7; Mon, 22 May 2023 19:56:22 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, shli@fb.com, allenpeng@synology.com, alexwu@synology.com, bingjingc@synology.com, neilb@suse.de Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan122@huawei.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH 3/3] md/raid10: fix io loss while replacement replace rdev Date: Mon, 22 May 2023 19:54:49 +0800 Message-Id: <20230522115449.2203939-4-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230522115449.2203939-1-linan666@huaweicloud.com> References: <20230522115449.2203939-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBXwLNiWGtk2XrkJw--.28031S7 X-Coremail-Antispam: 1UD129KBjvJXoW7tFWkCrWkKr4xKrykJry8AFb_yoW8tFyfpF 4DK3W5Zr1UJwsFgFs8AF4DJa4SvrWxtFs5Jry3W343ua1rtrW8Aay7GrW3Zrs8ZFWDXryY qa13Kws5u3W29FDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmYb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjxUwfHjUUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766595914185565129?= X-GMAIL-MSGID: =?utf-8?q?1766595914185565129?= From: Li Nan When we remove a disk which has replacement, first set rdev to NULL and then set replacement to rdev, finally set replacement to NULL (see raid10_remove_disk()). If io is submitted during the same time, it might read both rdev and replacement as NULL, and io will not be submitted. rdev -> NULL read rdev replacement -> NULL read replacement Fix it by reading replacement first and rdev later, meanwhile, use smp_mb() to prevent memory reordering. Fixes: 475b0321a4df ("md/raid10: writes should get directed to replacement as well as original.") Signed-off-by: Li Nan Reviewed-by: Yu Kuai --- drivers/md/raid10.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 70cc87c7ee57..25a5a7b1e95c 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -779,8 +779,16 @@ static struct md_rdev *read_balance(struct r10conf *conf, disk = r10_bio->devs[slot].devnum; rdev = rcu_dereference(conf->mirrors[disk].replacement); if (rdev == NULL || test_bit(Faulty, &rdev->flags) || - r10_bio->devs[slot].addr + sectors > rdev->recovery_offset) + r10_bio->devs[slot].addr + sectors > + rdev->recovery_offset) { + /* + * Read replacement first to prevent reading both rdev + * and replacement as NULL during replacement replace + * rdev. + */ + smp_mb(); rdev = rcu_dereference(conf->mirrors[disk].rdev); + } if (rdev == NULL || test_bit(Faulty, &rdev->flags)) continue; @@ -1479,9 +1487,15 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio, for (i = 0; i < conf->copies; i++) { int d = r10_bio->devs[i].devnum; - struct md_rdev *rdev = rcu_dereference(conf->mirrors[d].rdev); - struct md_rdev *rrdev = rcu_dereference( - conf->mirrors[d].replacement); + struct md_rdev *rdev, *rrdev; + + rrdev = rcu_dereference(conf->mirrors[d].replacement); + /* + * Read replacement first to Prevent reading both rdev and + * replacement as NULL during replacement replace rdev. + */ + smp_mb(); + rdev = rcu_dereference(conf->mirrors[d].rdev); if (rdev == rrdev) rrdev = NULL; if (rdev && (test_bit(Faulty, &rdev->flags)))