Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp37714pxh; Thu, 7 Apr 2022 13:15:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrwcSrl2AN++DW65vs7i9tA8NnXk9gkzCpmRH7bU2cTFqXEtyYeYIv0jhb4eRoUD7eAt8M X-Received: by 2002:a17:902:9304:b0:155:eb5a:8dd4 with SMTP id bc4-20020a170902930400b00155eb5a8dd4mr15760483plb.117.1649362513454; Thu, 07 Apr 2022 13:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649362513; cv=none; d=google.com; s=arc-20160816; b=v0WXmRWNsu2RRyS5IbSAFxanj22itdyTxI2jTdg08JDZHNl18S89z+VQtf2xwM5GpV 0dXBUhiZ074zhA/08I5gw3gSJ1PsuLPV2gDYA831p5uII8U0iJFuxB7yMZH1gM1aeDBi jGpbk3WrPeycWyiCX6dQ/zwrO6K+jCTXY3P79yreLos73zJa4JhWZknqyGY1CiCLwuNH MUugrTC5D11Gdefio+Wg9FRxwb8fxM1llbjmCTfVOfx7VZSt4F9l8QHLHId1YHH8v/h3 9k4a+Q5beRFDopWr6VdzoX1XmFTgmUZE0Rie47v6tP+jK8+FQehcx0u/CUhkcNgSk0rY vOMQ== 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=635ylQUcdfFmtEy7PfYRtKd/q8+5RGAxrk1aQwRlsw8=; b=XzZIHdXnGjxOgpyrIe8oTCRC/EHKInfkbKSNDggbYNm8RceK2roOUTRBCWvk615EVV nqxrie3G5Gi5rzDaEBOmg1Ry5iAhq/0hlF1nqi5Id3OciITYDrsANwrONsZdO6TJ1gBg H5wpCouqvp/7s6cDHtF2zcqefJtGcYO/A8o8bUd5T4jVbUcnY3cbfsmRbxtDKV5cfC2D oDz/L55Buc08yUl+z1Iw1KMCrkLkou+whV1Z3iZgHro7fjXzRzrD5kY8NkUC6SOibNwO 7rOl/JsSSEqeHlLMfb308LsTnDzNF4Qc5/17oy5IuI1U9I6HElUJkY9CBwyYg5Aejpws BVUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=PzXQRQYp; 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 f137-20020a62388f000000b004fa3a8e00c4si18579861pfa.379.2022.04.07.13.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:15:13 -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=PzXQRQYp; 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 678BE2E5C46; Thu, 7 Apr 2022 12:35:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346073AbiDGRYJ (ORCPT + 99 others); Thu, 7 Apr 2022 13:24:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346071AbiDGRXz (ORCPT ); Thu, 7 Apr 2022 13:23:55 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1380BE08; Thu, 7 Apr 2022 10:21:54 -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=635ylQUcdfFmtEy7PfYRtKd/q8+5RGAxrk1aQwRlsw8=; b=PzXQRQYpXdXhwt9mfTGGsdnyJz l0BTLXXaGHofw2ZqsBOF7SczKDAW+vTZzKlHQinURnmsNceWmWlSSy6xK8dCOTdA4dReoI3ZaTwe5 whstDVfyrbkTNi2b3ycXVvkM/6RRecLsobqgJl9Q5ZWuuSTErhuTFXCbEZFIAZTcPU+BWZ4O3qShp 7PAkXTLp1UjrnzfEOFMMbLg09XP/LUbsZwx/j79QQQMxjBFrw/dZGtMuorww51II/7Qju2ltmyiH9 SPdif6fNoXFELntKTQmXINf9ZvM7uxbjHEn6E1o1xJ6bwhEcp/L52LDzTfPLuVwibdw1aNg3Ujtgh l6RzzhTg==; 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 1ncVRf-002CRm-Ow; Thu, 07 Apr 2022 10:57:22 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1ncVRf-0002QA-Aw; Thu, 07 Apr 2022 10:57:19 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, Song Liu Cc: Guoqing Jiang , Logan Gunthorpe Date: Thu, 7 Apr 2022 10:57:10 -0600 Message-Id: <20220407165713.9243-5-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220407165713.9243-1-logang@deltatee.com> References: <20220407165713.9243-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, guoqing.jiang@linux.dev, logang@deltatee.com 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, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Subject: [PATCH v1 4/7] md/raid5: Annotate rdev/replacement accesses when nr_pending is elevated 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 There are a number of accesses to __rcu variables that should be safe because nr_pending in the disk is known to be elevated. Create a wrapper around rcu_dereference_protected() to annotate these accesses and verify that nr_pending is non-zero. This fixes a number of sparse warnings. Signed-off-by: Logan Gunthorpe --- drivers/md/raid5.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 4815f5351818..0f29a2769cb3 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2648,6 +2648,16 @@ static void shrink_stripes(struct r5conf *conf) conf->slab_cache = NULL; } +/* + * This helper wraps rcu_dereference_protected() and can be used when + * it is known that the nr_pending of the rdev is elevated. + */ +static struct md_rdev *rdev_pend_deref(struct md_rdev __rcu *rdev) +{ + return rcu_dereference_protected(rdev, + atomic_read(&rcu_access_pointer(rdev)->nr_pending)); +} + static void raid5_end_read_request(struct bio * bi) { struct stripe_head *sh = bi->bi_private; @@ -2674,9 +2684,9 @@ static void raid5_end_read_request(struct bio * bi) * In that case it moved down to 'rdev'. * rdev is not removed until all requests are finished. */ - rdev = conf->disks[i].replacement; + rdev = rdev_pend_deref(conf->disks[i].replacement); if (!rdev) - rdev = conf->disks[i].rdev; + rdev = rdev_pend_deref(conf->disks[i].rdev); if (use_new_offset(conf, sh)) s = sh->sector + rdev->new_data_offset; @@ -2790,11 +2800,11 @@ static void raid5_end_write_request(struct bio *bi) for (i = 0 ; i < disks; i++) { if (bi == &sh->dev[i].req) { - rdev = conf->disks[i].rdev; + rdev = rdev_pend_deref(conf->disks[i].rdev); break; } if (bi == &sh->dev[i].rreq) { - rdev = conf->disks[i].replacement; + rdev = rdev_pend_deref(conf->disks[i].replacement); if (rdev) replacement = 1; else @@ -2802,7 +2812,7 @@ static void raid5_end_write_request(struct bio *bi) * replaced it. rdev is not removed * until all requests are finished. */ - rdev = conf->disks[i].rdev; + rdev = rdev_pend_deref(conf->disks[i].rdev); break; } } @@ -5213,23 +5223,23 @@ static void handle_stripe(struct stripe_head *sh) struct r5dev *dev = &sh->dev[i]; if (test_and_clear_bit(R5_WriteError, &dev->flags)) { /* We own a safe reference to the rdev */ - rdev = conf->disks[i].rdev; + rdev = rdev_pend_deref(conf->disks[i].rdev); if (!rdev_set_badblocks(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0)) md_error(conf->mddev, rdev); rdev_dec_pending(rdev, conf->mddev); } if (test_and_clear_bit(R5_MadeGood, &dev->flags)) { - rdev = conf->disks[i].rdev; + rdev = rdev_pend_deref(conf->disks[i].rdev); rdev_clear_badblocks(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0); rdev_dec_pending(rdev, conf->mddev); } if (test_and_clear_bit(R5_MadeGoodRepl, &dev->flags)) { - rdev = conf->disks[i].replacement; + rdev = rdev_pend_deref(conf->disks[i].replacement); if (!rdev) /* rdev have been moved down */ - rdev = conf->disks[i].rdev; + rdev = rdev_pend_deref(conf->disks[i].rdev); rdev_clear_badblocks(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0); rdev_dec_pending(rdev, conf->mddev); -- 2.30.2