[PATCH v2] mm: annotate data race in update_hiwater_rss

From: Ignacio Encinas
Date: Mon Mar 31 2025 - 15:57:27 EST


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@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://lore.kernel.org/all/67e3390c.050a0220.1ec46.0001.GAE@xxxxxxxxxx/
Suggested-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
Signed-off-by: Ignacio Encinas <ignacio@xxxxxxxxxxxx>
---
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@xxxxxxxxxxxx
---
include/linux/mm.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

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;
}


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

Best regards,
--
Ignacio Encinas <ignacio@xxxxxxxxxxxx>