diff mbox series

[v2] mm: annotate data race in update_hiwater_rss

Message ID 20250331-mm-maxrss-data-race-v2-1-cf958e6205bf@iencinas.com (mailing list archive)
State New
Headers show
Series [v2] mm: annotate data race in update_hiwater_rss | expand

Commit Message

Ignacio Encinas March 31, 2025, 7:57 p.m. UTC
mm_struct.hiwater_rss can be accessed concurrently without proper
synchronization as reported by KCSAN.

This data race is benign as it only affects accounting information.
Annotate it with data_race() to make KCSAN happy.

Reported-by: syzbot+419c4b42acc36c420ad3@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/67e3390c.050a0220.1ec46.0001.GAE@google.com/
Suggested-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Signed-off-by: Ignacio Encinas <ignacio@iencinas.com>
---
Changes in v2:
- Annotate the actual race with data_race() instead of marking the
  struct field as __data_racy as suggested by Lorenzo. The commit title
  and description has been updated accordingly

  I also changed (mm) to mm as the parenthesis are no longer necessary
  (this particular snippet of code comes from an old macro)

- Add missing Closes tag for the syzbot report
- Link to v1: https://lore.kernel.org/r/20250330-mm-maxrss-data-race-v1-1-2fe0ba6b8482@iencinas.com
---
 include/linux/mm.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


---
base-commit: 3571e8b091f4270d869dda7a6cc43616c6ad6897
change-id: 20250315-mm-maxrss-data-race-6ce86b0deb14

Best regards,

Comments

Pedro Falcato March 31, 2025, 8:08 p.m. UTC | #1
On Mon, Mar 31, 2025 at 09:57:05PM +0200, Ignacio Encinas wrote:
> mm_struct.hiwater_rss can be accessed concurrently without proper
> synchronization as reported by KCSAN.
> 
> This data race is benign as it only affects accounting information.
> Annotate it with data_race() to make KCSAN happy.
> 
> Reported-by: syzbot+419c4b42acc36c420ad3@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/67e3390c.050a0220.1ec46.0001.GAE@google.com/
> Suggested-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Signed-off-by: Ignacio Encinas <ignacio@iencinas.com>

Looks good, thank you for the contribution!
Acked-by: Pedro Falcato <pfalcato@suse.de>

--
Pedro
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7b1068ddcbb70b732a4f2843e6b55fd73cc3e320..572b2001588b8afe68a468840cc75cd63cd4b543 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -32,6 +32,7 @@ 
 #include <linux/memremap.h>
 #include <linux/slab.h>
 #include <linux/cacheinfo.h>
+#include <linux/compiler.h>
 
 struct mempolicy;
 struct anon_vma;
@@ -2665,7 +2666,7 @@  static inline void update_hiwater_rss(struct mm_struct *mm)
 {
 	unsigned long _rss = get_mm_rss(mm);
 
-	if ((mm)->hiwater_rss < _rss)
+	if (data_race(mm->hiwater_rss) < _rss)
 		(mm)->hiwater_rss = _rss;
 }