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 3D8D7C3600B for ; Mon, 31 Mar 2025 18:08:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5598280003; Mon, 31 Mar 2025 14:08:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E0546280001; Mon, 31 Mar 2025 14:08:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF2FA280003; Mon, 31 Mar 2025 14:08:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B23F3280001 for ; Mon, 31 Mar 2025 14:08:21 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 19C5C59269 for ; Mon, 31 Mar 2025 18:08:22 +0000 (UTC) X-FDA: 83282630844.07.417D2B5 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) by imf03.hostedemail.com (Postfix) with ESMTP id 414FB20010 for ; Mon, 31 Mar 2025 18:08:20 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=iencinas.com header.s=key1 header.b=kXoXtbAI; dmarc=pass (policy=quarantine) header.from=iencinas.com; spf=pass (imf03.hostedemail.com: domain of ignacio@iencinas.com designates 91.218.175.171 as permitted sender) smtp.mailfrom=ignacio@iencinas.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743444500; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xMxVAW58ZGEdGtUEe1CpsbQ+/ZdYRFfAzvIfiSdeIb8=; b=7I6RwxxZagTRbycIUCPZICZWHSLjBPzNCXJ/KTaSPFgYa5DjzOutawOJYwRUOux10cjPU0 hxtq+3ac/0eWoMXD9q1Q16FvE//Wkgf5BOHjGK/0168WQUUjd4HPlg6ArpVfyAtx1fgi1r I1iIuPQG0XiG/FoxF/ktGYez57p60R8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=iencinas.com header.s=key1 header.b=kXoXtbAI; dmarc=pass (policy=quarantine) header.from=iencinas.com; spf=pass (imf03.hostedemail.com: domain of ignacio@iencinas.com designates 91.218.175.171 as permitted sender) smtp.mailfrom=ignacio@iencinas.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743444500; a=rsa-sha256; cv=none; b=s7O2i+hAZg4tGP3BCRQLNLI/TU7YE75ZD0gJQwDF9puSSCN3FqMXkNuu+idE1GTkf34uwC oqkiTGWakXFgfQh0WdiC8OEvmN+hmQMcwelGzL5SZmr/xv0vTbFxFfwwaE2gNlivnJyg5O iPRkLQjP51UYx6fBr4XjzI0rtn5I3BA= Message-ID: <8c946f46-6453-4537-ab41-0e9dbde684e8@iencinas.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iencinas.com; s=key1; t=1743444497; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xMxVAW58ZGEdGtUEe1CpsbQ+/ZdYRFfAzvIfiSdeIb8=; b=kXoXtbAIYlU/d1AcCclIw9VvUi/juJd37CHBeQaSwvCKnkew4KV8H79p2j5u5UW1Btasjp PEFO13d/Hui4qxnzyeDLeDEwpK0g7AHXfHVYNcHiKNkoTfX8eHL8ercKcrr4Pq4t/pdbL7 PhyyLLw/+R9zekUIIBUCZ2zlGu4/h3G10rqgHqwUWUR01dWr7GjKkszR0ZLH5nEZS64fbv BEKJXEcDBrmwDgO3JsZK9mZFeD63yrfRDZSL4Id+kQmnGFto6N06xZ//P/Vzi462+NoALh /KMxXqbzlOWujMsE24nXHMnVndYhcyFJADcXeODjJeqWucNQ2FLSpAvCpsFX3w== Date: Mon, 31 Mar 2025 20:08:12 +0200 MIME-Version: 1.0 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ignacio Encinas Rubio Subject: Re: [PATCH] mm: mark mm_struct.hiwater_rss as data racy To: Lorenzo Stoakes Cc: Andrew Morton , linux-mm@kvack.org, "Liam R. Howlett" , linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org, linux-kernel@vger.kernel.org, syzbot+419c4b42acc36c420ad3@syzkaller.appspotmail.com References: <20250330-mm-maxrss-data-race-v1-1-2fe0ba6b8482@iencinas.com> <2c15f7bf-7852-4aa5-98f1-c8604fe8fc00@lucifer.local> Content-Language: en-US In-Reply-To: <2c15f7bf-7852-4aa5-98f1-c8604fe8fc00@lucifer.local> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam01 X-Stat-Signature: ie95p4zfztam3sbkwu4iqk7botep5zyc X-Rspam-User: X-Rspamd-Queue-Id: 414FB20010 X-HE-Tag: 1743444500-137541 X-HE-Meta: U2FsdGVkX1+KdnIOvFCI7kN7ZxKEZSU3qqBFetyeoie/lWqd+NYh964KmyGej5UcpXWthtWcOPq4cQqehiPteISVrTNb1vTh9vrveWgviYM9mgzaoD4/5LoA5Qt1rSNIYb2mFQy07beujmBVmx43z/S7mfsCmS8yNoPjvRXS1HTRmjlpTSwZAVno5z4nbkgEi5NKoIpLexRWV8RA8YMChzMDlk1OtTExwvYjB26wDxii0IMAa0Wzz/XHWWeKuMEXb8KmlJn89VgQy+M2J5yp9/DXNeCmSNY4/ElhLU7NiTtGRNbvOsVoJqbsCBRYhJUByrLfsATZimtaye4rxUa+RB+OxLaLkvAIKEMuumXXEaAvXtPd1pJJInoVt7QplN3NaLh0bpMO4jSBO5286Fe/HkemJmmnuomQz/yd+qB0bcrQvWE2ngWQIfgoux/JbB4sxoWbsP8jAeH4PIvJDPOtQKHiAqrgL3g4lQY4NXJIHFDhIeD+4hUda7U4SVflTjAJ96RO3bOH1ld2ZARWBWPi/T8+fa5PhJ+E4sU16zMBQI9R69BgMrT+X7tUXLHZxlj/rJAK3bCC9xWI5pg5zGSKgSfM8KTQW/GyofU3ogJ44ZnDLEXPPoXYhExytgwagejneVMaHYFAmE8o1jC4rfMUIKdXO75hUMzheulAzXEfxt3czj/SjCMeFL0x0rsAgVD48n3chJSRTfe5a6/K8AOa3uOJi7aQ3OLstk8AvYUtFrNIUQqJtSYuPBaBXF65K0vk3TgwFSNQDe7o4/3rQp+PADNPKWkCYx7KrFIsffOLeswrmNihQmWw+uFbx67FNaU8C0cr4gOrv5cpZKpClAH/r8Bf+ByekPiCDFbKTktKFb4qxiPJKHSvgb1NuyRfBmF2KSZgZpuDz/bZwVmWMKXkTT1eEkTN6PCm3Weg1pyFGpkom7XepbtQWX7w99xut6IaRaCoEyygyqO+aI2M9lg kB1L3oNn 525h10rjseGAKdRLyI+dJ7e2WgiP08jzwSKq50ckQWuzDvKLQRLrRLwTewg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.002774, 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 31/3/25 13:48, Lorenzo Stoakes wrote: > On Sun, Mar 30, 2025 at 02:02:04PM +0200, Ignacio Encinas wrote: >> mm_struct.hiwater_rss can be accessed concurrently without proper >> synchronization as reported by KCSAN. >> >> Given that this just provides accounting information and that the extra >> accuracy isn't worth the potential slowdown, let's annotate is >> __data_racy to make KCSAN happy. >> >> Reported-by: syzbot+419c4b42acc36c420ad3@syzkaller.appspotmail.com > > You'll want a: > Closes: https://lore.kernel.org/all/67e3390c.050a0220.1ec46.0001.GAE@google.com/ > > Here too. Thanks for pointing it out. I saw some people didn't use it, but I'll add it. >> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h >> index 0234f14f2aa6bea42a8a62ccb915c94f556cd3cc..84c86951a978aad07ab4ecefbfff77e7418d8402 100644 >> --- a/include/linux/mm_types.h >> +++ b/include/linux/mm_types.h >> @@ -19,6 +19,7 @@ >> #include >> #include >> #include >> +#include >> >> #include >> >> @@ -939,7 +940,7 @@ struct mm_struct { >> #endif >> >> >> - unsigned long hiwater_rss; /* High-watermark of RSS usage */ >> + unsigned long __data_racy hiwater_rss; /* High-watermark of RSS usage */ > > This translates to volatile if KCSAN is enabled, and I really don't want to > apply that unnecessarily given the impliciations/any weirdness we might > observe as a result that might be confounding. > > I also don't want to _across the board_ say 'hey we don't care about races > for this'. > > I think use of data_race() would make more sense. Makes sense. The logic behind using __data_racy was to convey that data races were fine in this case because it's just statistical information. >From what you're saying I misinterpreted the situation :) > Probably we're fine doing this in update_hiwater_rss(), so something like: > > static inline void update_hiwater_rss(struct mm_struct *mm) > { > unsigned long _rss = get_mm_rss(mm); > > if (data_race(mm->hiwater_rss) < _rss) > mm->hiwater_rss = _rss; > } > > This labels it as 'we don't care', is a no-op if KCSAN is disabled and > abstracts the decision to this specific point. Thanks for the suggestion. I agree this looks fine. If there are other races (for which get_mm_hiwater_rss seems the only candidate) these can be examined on their own. I'll adapt your suggestion, reword the commit and send a v2. Thanks!