From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B26FEC3DA63 for ; Tue, 23 Jul 2024 21:14:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CFEE6B007B; Tue, 23 Jul 2024 17:14:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 280C86B0082; Tue, 23 Jul 2024 17:14:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 121196B0083; Tue, 23 Jul 2024 17:14:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E871D6B007B for ; Tue, 23 Jul 2024 17:14:08 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6884A160160 for ; Tue, 23 Jul 2024 21:14:08 +0000 (UTC) X-FDA: 82372270176.16.3E61B29 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by imf07.hostedemail.com (Postfix) with ESMTP id 314C84000F for ; Tue, 23 Jul 2024 21:14:05 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fxC4scA1; spf=pass (imf07.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.219.53 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721769222; a=rsa-sha256; cv=none; b=scH9Cm4EyKu+4/sUOYSdq2A1y5Qp1OU0GxICvG5W0T2wH99H3B3UknzgrnUr++SzgRyBnk NZILI6DRvkAfPiXQEk8dOjyXAek9eJ4avo4l7IUffAsIeTgPDoRhWUybvmRq3Ckh9s9ba1 hNpV/nx7XtnyPGUh4JwQzk82N+OxVTY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fxC4scA1; spf=pass (imf07.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.219.53 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721769222; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v/7hLmssIAAEjIHO1+cGxc/393ZdhjH3wSNqOUr79Ys=; b=Y/vi1PKfzNbC0kr0vbqz3/Zq7Y3KdXPYl5ANC2rIuo6RfW67X4A1pVCPNvkk3ZEecRhAJj 02j06ho4w7wDnRbIofu3YaVntQi0sY/NZCPcABMPLcKzgUvlVj28yc94/h6LnyBPSp4o7D fvRx7f+I3bDRx6c0fCWpsJEwqYPlpK8= Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6b79b93a4c9so2197176d6.1 for ; Tue, 23 Jul 2024 14:14:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721769245; x=1722374045; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=v/7hLmssIAAEjIHO1+cGxc/393ZdhjH3wSNqOUr79Ys=; b=fxC4scA14ZOVzszvZHIAadZRNxdMCxrUJ5YoGgO/Y3AAPJvUCR45xpt8mP/7Wve5gS nV2m3cxn45Bnkzu5NezTGQnVOJpOK8NX5okR6XTQDAEbFZZcjHQMS3/OhcODrtk4x4SD 3Jx1YaFI++BjOodLvRJXNN+7VLbTYTxf1HRs/5ujT5iqpbdANJMD5GS4ahHuoNZ5/dh2 01lSBIrQLqj7p7uP0Oo+pjcx3XKX3Wsm07PCfSHKl/SiYKaCbfBsxcjuqIekyAQ+zX0a /XKZhYTU1NX4T5Z23/OpA9KHJtRL/Qcni510yB++ghlo3xCQ9P3s7hu5OAdMptgcg5Gb 0IDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721769245; x=1722374045; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v/7hLmssIAAEjIHO1+cGxc/393ZdhjH3wSNqOUr79Ys=; b=R8Ze8c79uaX8h1wnwpuSQFINZshFfrhe9fGDPd9qhTqU9PA/h1kmu/cXc+0ns6sj7+ ztQDYdF4iv1d5ApSgsDpmTJjzDrHO/vA5vPxfA93tRgdeUe5rFugvtfSSzL5qkE4zwwZ svreyPPBRZNphkyTaBlZCie/vRe3cnNBRLRLAtEeoQoRuGcaNAlOgRWMLY9mgwNfIWgT QyMtZhjDvB2erkqeQoWIe2dkEYPb98+n2T9HCEXBGZXZAbIsT4UkbAQvMyF8d1ev7E65 aNIv5SNEKzDKmDaGTRvNFuXbRNjCwQWskWTslObbzIVYmXP6YrZcvrMZKcLNz4nkjrBv iA6g== X-Forwarded-Encrypted: i=1; AJvYcCVxH7rXJDc91eKX+Les1R7xmDXDRbg5M9+xFjAwWIorkOqXDTSyz0pxsW5boQhhVqghkafI70t/xtFKxE1iaWkoEAI= X-Gm-Message-State: AOJu0YzuYa8PVA2GAHMYNwHTFPJ9PR63wnTW1+tf0VMTfUvW++BmzRk6 Zdx3RBU51LB1Ec4mH0nvK6f2C2CjXJh8icAW+kdxSyd1uUfKq7WS X-Google-Smtp-Source: AGHT+IGTry2e+jrdjK9teV2i9t7dlX6iuJTX6lh/JsjsJBDQe6e5gOfVVeWNHImQUonDn2OKKLE42w== X-Received: by 2002:a05:6214:5ecf:b0:6b5:2a29:cd08 with SMTP id 6a1803df08f44-6b9843b6a0cmr53240996d6.27.1721769245065; Tue, 23 Jul 2024 14:14:05 -0700 (PDT) Received: from fauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b7acb0972csm50981126d6.136.2024.07.23.14.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 14:14:04 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfauth.nyi.internal (Postfix) with ESMTP id F29CF1200068; Tue, 23 Jul 2024 17:14:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 23 Jul 2024 17:14:02 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrheelgdduheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeehudfgudffffetuedtvdehueevledvhfelleeivedtgeeuhfegueeviedu ffeivdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvgdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 23 Jul 2024 17:14:01 -0400 (EDT) Date: Tue, 23 Jul 2024 14:14:00 -0700 From: Boqun Feng To: Dennis Zhou Cc: Tejun Heo , kernel test robot , Suren Baghdasaryan , oe-lkp@lists.linux.dev, lkp@intel.com, linux-kernel@vger.kernel.org, Andrew Morton , Kent Overstreet , Kees Cook , Alexander Viro , Alex Gaynor , Alice Ryhl , Andreas Hindborg , Benno Lossin , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Christoph Lameter , Gary Guo , Miguel Ojeda , Pasha Tatashin , Peter Zijlstra , Vlastimil Babka , Wedson Almeida Filho , linux-mm@kvack.org, lkmm@lists.linux.dev Subject: Re: [linus:master] [mm] 24e44cc22a: BUG:KCSAN:data-race_in_pcpu_alloc_noprof/pcpu_block_update_hint_alloc Message-ID: References: <202407191651.f24e499d-oliver.sang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: 9j6th661extb7bmiqhrrd7wfuxgsi6s9 X-Rspamd-Queue-Id: 314C84000F X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1721769245-725731 X-HE-Meta: U2FsdGVkX1/v1xkA6rD8BaPGgWdrwWDTK6fuoNTe+vpXd6lKA9sKFzh31AJgZkdF8avL8Ze1ixbzdnU9MmB5IRBgr3pmoms4Y4W82Yrv/yytT1jIoLsj6EvCojt6d0M63fyitjOHb78powepZn1TOhXNVKRo6GVb6A5xuO+sOfEpK7WHFmW2pKSdOA9Fg7min7EcKvwsuTXX9qrPUJR9RVy0ksjrzWd8qBW9AtziM1K+CJ1oej9wbP1ps+rsGHB+bGJVL5pABY+z/wc0UqzvUSGwA0oNi3ullrTGNRfHeYdWeAbfnMtp+z+MIxYX2ZasiVBrpCdekXgUh7B2bbVL+MHyv69aewHBmpZu4Z7F+7nTTpjxWiMe8z3IrfkbCknqDh0odOgF6jSc1ttKPrFjALyR/8E7UK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IFC35Hz6eabC X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Jul 22, 2024 at 10:50:53PM -0700, Dennis Zhou wrote: > On Mon, Jul 22, 2024 at 01:53:52PM -0700, Boqun Feng wrote: > > On Mon, Jul 22, 2024 at 11:27:48AM -0700, Dennis Zhou wrote: > > > Hello, > > > > > > On Mon, Jul 22, 2024 at 11:03:00AM -0700, Boqun Feng wrote: > > > > On Mon, Jul 22, 2024 at 07:52:22AM -1000, Tejun Heo wrote: > > > > > On Mon, Jul 22, 2024 at 10:47:30AM -0700, Boqun Feng wrote: > > > > > > This looks like a data race because we read pcpu_nr_empty_pop_pages out > > > > > > of the lock for a best effort checking, @Tejun, maybe you could confirm > > > > > > on this? > > > > > > > > > > That does sound plausible. > > > > > > > > > > > - if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW) > > > > > > + /* > > > > > > + * Checks pcpu_nr_empty_pop_pages out of the pcpu_lock, data races may > > > > > > + * occur but this is just a best-effort checking, everything is synced > > > > > > + * in pcpu_balance_work. > > > > > > + */ > > > > > > + if (data_race(pcpu_nr_empty_pop_pages) < PCPU_EMPTY_POP_PAGES_LOW) > > > > > > pcpu_schedule_balance_work(); > > > > > > > > > > Would it be better to use READ/WRITE_ONCE() for the variable? > > > > > > > > > > > > > For READ/WRITE_ONCE(), we will need to replace all write accesses and > > > > all out-of-lock read accesses to pcpu_nr_empty_pop_pages, like below. > > > > It's better in the sense that it doesn't rely on compiler behaviors on > > > > data races, not sure about the performance impact though. > > > > > > > > > > I think a better alternative is we can move it up into the lock under > > > area_found. The value gets updated as part of pcpu_alloc_area() as the > > > code above populates percpu memory that is already allocated. > > > > > > > Not sure I followed what exactly you suggested here because I'm not > > familiar with the logic, but a simpler version would be: > > > > > > I believe that's the only naked access of pcpu_nr_empty_pop_pages. So > I was thinking this'll fix this problem. > > I also don't know how to rerun this CI tho.. > > --- > diff --git a/mm/percpu.c b/mm/percpu.c > index 20d91af8c033..325fb8412e90 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -1864,6 +1864,10 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved, > > area_found: > pcpu_stats_area_alloc(chunk, size); > + > + if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW) > + pcpu_schedule_balance_work(); > + But the pcpu_chunk_populated() afterwards could modify the pcpu_nr_empty_pop_pages again, wouldn't this be a behavior changing? Regards, Boqun > spin_unlock_irqrestore(&pcpu_lock, flags); > > /* populate if not all pages are already there */ > @@ -1891,9 +1895,6 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved, > mutex_unlock(&pcpu_alloc_mutex); > } > > - if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW) > - pcpu_schedule_balance_work(); > - > /* clear the areas and return address relative to base address */ > for_each_possible_cpu(cpu) > memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size);