Skip to contentSkip to conversation

md: protect read mddev->recovery in md_sync_action()

PATCH In review Chen Cheng 3 participants 5 messages Jun 27 – Jul 11 MD RAID

lore
Share & tools
lore

Chen Cheng

author
#0 lore raw

PATCH 1/1 md: protect read mddev->recovery in md_sync_action()

From: Chen Cheng <[email protected]>

md_sync_action() read mddev->recovery in lockless path, use READ_ONCE() instead of u64 plain read.

Fixes e792a4c2156a3 ("md: add new helpers for sync_action")
---
 drivers/md/md.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md.c +1 -1
index c5c50640b684..f4415c1a79d9 100644
@@ -5074,11 +5074,11 @@ static enum sync_action md_get_active_sync_action(struct mddev *mddev)
 	return is_recover ? ACTION_RECOVER : ACTION_IDLE;
 }
 
 enum sync_action md_sync_action(struct mddev *mddev)
 {
-	unsigned long recovery = mddev->recovery;
+	unsigned long recovery = READ_ONCE(mddev->recovery);
 	enum sync_action active_action;
 
 	/*
 	 * frozen has the highest priority, means running sync_thread will be
 	 * stopped immediately, and no new sync_thread can start.
Signature · 1 line
2.54.0
#1 lore raw
Quoted 5 lines · Chen Cheng

From: Chen Cheng <[email protected]>

md_sync_action() read mddev->recovery in lockless path, use READ_ONCE() instead of u64 plain read.

unisgned long is not always u64...
I can not see what it fixes, is this just to silence KCSAN? If so, please say so in the commit message.

Quoted 27 lines
Fixes e792a4c2156a3 ("md: add new helpers for sync_action")
---
 drivers/md/md.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md.c +1 -1
index c5c50640b684..f4415c1a79d9 100644
@@ -5074,11 +5074,11 @@ static enum sync_action md_get_active_sync_action(struct mddev *mddev)
 	return is_recover ? ACTION_RECOVER : ACTION_IDLE;
 }
 
 enum sync_action md_sync_action(struct mddev *mddev)
 {
-	unsigned long recovery = mddev->recovery;
+	unsigned long recovery = READ_ONCE(mddev->recovery);
 	enum sync_action active_action;
 
 	/*
 	 * frozen has the highest priority, means running sync_thread will be
 	 * stopped immediately, and no new sync_thread can start.
Signature · 1 line
2.54.0
Signature · 2 lines
Best Regards,
Abd-Alrhman
#2 lore raw
Quoted 9 lines · Abd-Alrhman Masalkhi
Quoted 5 lines · Chen Cheng

From: Chen Cheng <[email protected]>

md_sync_action() read mddev->recovery in lockless path, use READ_ONCE() instead of u64 plain read.

unisgned long is not always u64...
I can not see what it fixes, is this just to silence KCSAN? If so, please say so in the commit message.

I need to find KCSAN report , I lost this one, but I think it's easy to find locklessly path to call md_sync_action(), so. READ_ONCE is need.

Quoted 29 lines
Quoted 28 lines
Fixes e792a4c2156a3 ("md: add new helpers for sync_action")
---
  drivers/md/md.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md.c +1 -1
index c5c50640b684..f4415c1a79d9 100644
@@ -5074,11 +5074,11 @@ static enum sync_action md_get_active_sync_action(struct mddev *mddev)
  	return is_recover ? ACTION_RECOVER : ACTION_IDLE;
  }
 
  enum sync_action md_sync_action(struct mddev *mddev)
  {
-	unsigned long recovery = mddev->recovery;
+	unsigned long recovery = READ_ONCE(mddev->recovery);
  	enum sync_action active_action;
 
  	/*
  	 * frozen has the highest priority, means running sync_thread will be
  	 * stopped immediately, and no new sync_thread can start.
Signature · 1 line
2.54.0
#3 lore raw

Hi Chen,

Quoted 7 lines · Chen Cheng
Quoted 6 lines · Abd-Alrhman Masalkhi
Quoted 5 lines · Chen Cheng

From: Chen Cheng <[email protected]>

md_sync_action() read mddev->recovery in lockless path, use READ_ONCE() instead of u64 plain read.

Quoted 7 lines
Quoted 3 lines

unisgned long is not always u64...
I can not see what it fixes, is this just to silence KCSAN? If so, please say so in the commit message.

I need to find KCSAN report , I lost this one, but I think it's easy to find locklessly path to call md_sync_action(), so. READ_ONCE is need.

Thanks. Adding the KCSAN report would be helpful.

Quoted 30 lines
Quoted 29 lines
Quoted 28 lines
Fixes e792a4c2156a3 ("md: add new helpers for sync_action")
---
  drivers/md/md.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md.c +1 -1
index c5c50640b684..f4415c1a79d9 100644
@@ -5074,11 +5074,11 @@ static enum sync_action md_get_active_sync_action(struct mddev *mddev)
  	return is_recover ? ACTION_RECOVER : ACTION_IDLE;
  }
 
  enum sync_action md_sync_action(struct mddev *mddev)
  {
-	unsigned long recovery = mddev->recovery;
+	unsigned long recovery = READ_ONCE(mddev->recovery);
  	enum sync_action active_action;
 
  	/*
  	 * frozen has the highest priority, means running sync_thread will be
  	 * stopped immediately, and no new sync_thread can start.
Signature · 1 line
2.54.0
Signature · 2 lines
Best Regards,
Abd-Alrhman
author
#4 lore raw
Quoted 11 lines · Abd-Alrhman Masalkhi

Hi Chen,

Quoted 7 lines · Chen Cheng
Quoted 6 lines · Abd-Alrhman Masalkhi
Quoted 5 lines · Chen Cheng

From: Chen Cheng <[email protected]>

md_sync_action() read mddev->recovery in lockless path, use READ_ONCE() instead of u64 plain read.

Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

unisgned long is not always u64...
I can not see what it fixes, is this just to silence KCSAN? If so, please say so in the commit message.

I need to find KCSAN report , I lost this one, but I think it's easy to find locklessly path to call md_sync_action(), so. READ_ONCE is need.

Thanks. Adding the KCSAN report would be helpful.

hi Abd-Alrhman

Uh... a apologize for my mislead . it's truelly report by review-bot , and after double check , I think it wouldn't be reproduce in my x86-64 machine , because 8B in x64-arch load is atomic +align..

thanks,
cheng.

Quoted 31 lines
Quoted 30 lines
Quoted 29 lines
Quoted 28 lines
Fixes e792a4c2156a3 ("md: add new helpers for sync_action")
---
   drivers/md/md.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md.c +1 -1
index c5c50640b684..f4415c1a79d9 100644
@@ -5074,11 +5074,11 @@ static enum sync_action md_get_active_sync_action(struct mddev *mddev)
   	return is_recover ? ACTION_RECOVER : ACTION_IDLE;
   }
 
   enum sync_action md_sync_action(struct mddev *mddev)
   {
-	unsigned long recovery = mddev->recovery;
+	unsigned long recovery = READ_ONCE(mddev->recovery);
   	enum sync_action active_action;
 
   	/*
   	 * frozen has the highest priority, means running sync_thread will be
   	 * stopped immediately, and no new sync_thread can start.
Signature · 1 line
2.54.0