Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp850248rdb; Mon, 29 Jan 2024 23:37:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHuoouFzPYcZbZ4RAL1SOP97u8TiDIQ1oS5P0WWVHJT7f73aWZizp3O2mH1oQz/NTfvlRv8 X-Received: by 2002:a17:902:a3cf:b0:1d8:fff8:bed3 with SMTP id q15-20020a170902a3cf00b001d8fff8bed3mr1592352plb.36.1706600276628; Mon, 29 Jan 2024 23:37:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706600276; cv=pass; d=google.com; s=arc-20160816; b=EyozckMioPhAEkVeNj0cI5bCCpvLTyXCcqy5vp12u8IZTGVBX3DaBdUcCi3XyCYs5s 8AHj1L+WoD2rHXcUNN2wNweGDrPhBqVjUo+stc7kGoEBqlpDaI+37uBn0p9pI5JrFOHi b9u6M9+cOUHaVhJdLZlvWE24b32sIHxeht0VcnfCO4JVTqe4BAtFJ0nb9/zxDmI7AN/Q WhQy9wuC9/1odpXcBZdPs6+42rwiVJWdG+wbaSiqGZVelMXzKM58MbxtZY6MVwY4Vr4g o1YrDGFDsVc47gQqA+N2nFF+ZDbWDw4sfyAioOusDtlJ616lNZ5Gto8EJeZ9Xhr+UIlM 7g7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=llSbcwy7jhnUcdk1t07c0X7hycXGBa1tDBbwMFFdu5E=; fh=sdaT0iUnPamiEQ8xSiIKGUkdmm9CtNa+ftbkF1mKUdU=; b=T4rnPQO2m+cOEdFf+kgeku74mayBb3OzTHk9zDPrJ0JUQhZZwTjcm71k4thNDtW885 w8czTe4iPR2ZrehOJuPf4FPk5aEvh0BuTSiVbLUkKdjx799R1kQEpoMgcYXye8bVBXHU ybmfEn4DydnGy6ORgw3qbIT7uiFNgdmsCHPKYQyWxf14Xf9rWrzcIblNb8brxj4bL0qB qLFhsCdg5nlv/0XKHirFCAQiQMcjncFyWzZcDAk1eA0Q90Ym2MpX0bZ3i3djx/vZaFTA kLdh8UoQCjbwRG7KhANYxfIarfv3w2gNvqHM7+GEa8TuTAIs0sqWqdD+eO5OH5h2zX65 xtdA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="c6/UpI4X"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44054-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44054-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j11-20020a170902da8b00b001d704e2da3dsi7292411plx.407.2024.01.29.23.37.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 23:37:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44054-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="c6/UpI4X"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44054-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44054-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8F45DB25114 for ; Tue, 30 Jan 2024 07:37:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD1CD55C33; Tue, 30 Jan 2024 07:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c6/UpI4X" 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 024195467E; Tue, 30 Jan 2024 07:37:24 +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=1706600245; cv=none; b=NOGj3+axLibIbymFpYf3b3yN4eiZzAITwXR4JRov+rnGNVJhnW+TcVHF9WeQRsi6OZ+/On0UY0AxDzkTxCKTRAM5Z/vY0LuLz3Xj6/tUWrQEdN/FLD+En/OmZd4+NPb2igwFZ1Ozfwf7VBbvY5RkoYXJy++8xT6lL0C50IaGIuk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706600245; c=relaxed/simple; bh=VyBIx8uQjXCjBEuFOuaNwLSr8JVTC+Gwm801hDkovvw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=O+XluhdCUiB7cKgRID0T8yojpxGcuREQ4LpXbdPAvpwluzhUuAFISH3Cy+0LS+X9bVP+pMGlx27ZipsIk0cDIyyuMlpltJt12FkqRY06vMNM0rSqJtuIoTVouF/2JHnTfzFKjFSmavA5Wx/BkHiQ7NrD6mtJVLrIUn2JecQxeks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c6/UpI4X; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75D2CC433A6; Tue, 30 Jan 2024 07:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706600244; bh=VyBIx8uQjXCjBEuFOuaNwLSr8JVTC+Gwm801hDkovvw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=c6/UpI4Xlwxn8S8duuYTlyDfqIin31dM449IdxjYIb8RRq4UucKboaw3JF7crCuMU Ehp6I2OjXtbRfdxcypCiIoKxYrCPSLKxg7y6qjSaZB3Y5H7nYrCMiWPMHOCgy3AWD3 Ewyz6KBuarXkFJ/BWofKFftz5mkGDHFSkuSECjNHUFHItV0ACw/k50klbzzSFptuuD iis8NG9+eoa+jSxggjfFK0/0VvF3y3UuJgCJypBZJ0SJ8ROP5cWm/NkG3xNVT7+Bl+ S2LOLM9neOcZWd203SQHjiOJKw8EGdKrh5rJvd+Qz+E55ecSXy1nA4jdWCGj1gEong 0Uz2Qmkx/uBKQ== Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-51114557c77so1890180e87.0; Mon, 29 Jan 2024 23:37:24 -0800 (PST) X-Gm-Message-State: AOJu0YwaQO0XZUhY9/XbujZ59qLbphmbVitjp1UAGZoY6v2TbjezObg2 VFqTEKIg9zqgtgKEaTFPJTCmwomPDZaM65+HTraXUYRLzlKG1+dbSRhIb1SyTe8xgifWB2SUMoS 8SwZzBUoj1BXsM36hi4cothXGgTQ= X-Received: by 2002:a05:6512:10c2:b0:510:1487:bcb with SMTP id k2-20020a05651210c200b0051014870bcbmr6081674lfg.64.1706600242683; Mon, 29 Jan 2024 23:37:22 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240112071017.16313-1-2045gemini@gmail.com> In-Reply-To: <20240112071017.16313-1-2045gemini@gmail.com> From: Song Liu Date: Mon, 29 Jan 2024 23:37:11 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4] md/raid5: fix atomicity violation in raid5_cache_count To: Gui-Dong Han <2045gemini@gmail.com> Cc: yukuai3@huawei.com, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@outlook.com, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 11, 2024 at 11:10=E2=80=AFPM Gui-Dong Han <2045gemini@gmail.com= > wrote: > [...] > > raid5_release_stripe(sh); > - conf->max_nr_stripes++; > + WRITE_ONCE(conf->max_nr_stripes, conf->max_nr_stripes + 1); This is weird. We are reading max_nr_stripes without READ_ONCE. > return 1; > } > > @@ -2707,7 +2707,7 @@ static int drop_one_stripe(struct r5conf *conf) > shrink_buffers(sh); > free_stripe(conf->slab_cache, sh); > atomic_dec(&conf->active_stripes); > - conf->max_nr_stripes--; > + WRITE_ONCE(conf->max_nr_stripes, conf->max_nr_stripes - 1); Same here. > return 1; > } > > @@ -6820,7 +6820,7 @@ raid5_set_cache_size(struct mddev *mddev, int size) > if (size <=3D 16 || size > 32768) > return -EINVAL; > > - conf->min_nr_stripes =3D size; > + WRITE_ONCE(conf->min_nr_stripes, size); > mutex_lock(&conf->cache_size_mutex); > while (size < conf->max_nr_stripes && > drop_one_stripe(conf)) > @@ -6832,7 +6832,7 @@ raid5_set_cache_size(struct mddev *mddev, int size) > mutex_lock(&conf->cache_size_mutex); > while (size > conf->max_nr_stripes) > if (!grow_one_stripe(conf, GFP_KERNEL)) { > - conf->min_nr_stripes =3D conf->max_nr_stripes; > + WRITE_ONCE(conf->min_nr_stripes, conf->max_nr_str= ipes); And here. > result =3D -ENOMEM; > break; > } Thanks, Song