Skip to contentSkip to conversation

af_unix: Set gc_in_progress to true in unix_gc().

PATCH In review Igor Ushakov 2 participants 3 messages Jun 29 – Jul 1

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 af_unix: Set gc_in_progress to true in unix_gc().

From: Kuniyuki Iwashima <[email protected]>

[ Upstream commit d82ba05263c69fa2437fe93e4e561cc40f4c03af ]

Igor Ushakov reported that unix_gc() could run with gc_in_progress being false if the work is scheduled while running:

  Thread 1         Thread 2                     Thread 3
  --------         --------                     --------
                   unix_schedule_gc()           unix_schedule_gc()
                   `- if (!gc_in_progress)      `- if (!gc_in_progress)
                      |- gc_in_progress = true     |
                      `- queue_work()              |
  unix_gc() <----------------/                     |
  |                                                |- gc_in_progress = true
  ...                                              `- queue_work()
  |                                                       |
  `- gc_in_progress = false                               |
                                                          |

unix_gc() <---------------------------------------------' |
... /* gc_in_progress == false */
|
`- gc_in_progress = false

unix_peek_fpl() relies on gc_in_progress not to confuse GC by MSG_PEEK.

Let's set gc_in_progress to true in unix_gc().

Fixes 8b90a9f819dc ("af_unix: Run GC on only one CPU.")
[ move WRITE_ONCE(gc_in_progress, true) into the __unix_gc() work function and drop it from unix_gc(). ]
---
 net/unix/garbage.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/unix/garbage.c +2 -1
index 1cdb54c616..82dfb1ad34 100644
@@ -583,6 +583,8 @@ static void __unix_gc(struct work_struct *work)
 	struct sk_buff_head hitlist;
 	struct sk_buff *skb;
 
+	WRITE_ONCE(gc_in_progress, true);
+
 	spin_lock(&unix_gc_lock);
 
 	if (!unix_graph_maybe_cyclic) {
@@ -613,7 +615,6 @@ static DECLARE_WORK(unix_gc_work, __unix_gc);
 
 void unix_gc(void)
 {
-	WRITE_ONCE(gc_in_progress, true);
 	queue_work(system_unbound_wq, &unix_gc_work);
 }
 
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 1 line

[ move WRITE_ONCE(gc_in_progress, true) into the __unix_gc() work function and drop it from unix_gc(). ]

Dropping the set from unix_gc() and doing it in the work function is fine upstream, but only because later refactors made wait_for_unix_gc() gate flush_work() on unix_graph_cyclic_sccs. On these trees it still gates on gc_in_progress, so this brings back a window where the over-limit throttle stops waiting for GC.

Can you respin keeping gc_in_progress set in unix_gc() before queue_work()? The code is identical across all three, so one version covers them.

--
Thanks,
Sasha

#2 lore raw

PATCH v2 1/1 af_unix: Set gc_in_progress to true in unix_gc().

From: Kuniyuki Iwashima <[email protected]>

[ Upstream commit d82ba05263c69fa2437fe93e4e561cc40f4c03af ]

Igor Ushakov reported that unix_gc() could run with gc_in_progress being false if the work is scheduled while running:

  Thread 1         Thread 2                     Thread 3
  --------         --------                     --------
                   unix_schedule_gc()           unix_schedule_gc()
                   `- if (!gc_in_progress)      `- if (!gc_in_progress)
                      |- gc_in_progress = true     |
                      `- queue_work()              |
  unix_gc() <----------------/                     |
  |                                                |- gc_in_progress = true
  ...                                              `- queue_work()
  |                                                       |
  `- gc_in_progress = false                               |
                                                          |

unix_gc() <---------------------------------------------' |
... /* gc_in_progress == false */
|
`- gc_in_progress = false

unix_peek_fpl() relies on gc_in_progress not to confuse GC by MSG_PEEK.

Let's set gc_in_progress to true in unix_gc().

[ Add setting gc_in_progress in __unix_gc(). Keep the existing
set in unix_gc() for wait_for_unix_gc() over-limit throttling. ]

---
 net/unix/garbage.c | 2 ++
 1 file changed, 2 insertions(+)
net/unix/garbage.c +2 -0
index 1cdb54c616..fa6983dc31 100644
@@ -583,6 +583,8 @@ static void __unix_gc(struct work_struct *work)
 	struct sk_buff_head hitlist;
 	struct sk_buff *skb;
 
+	WRITE_ONCE(gc_in_progress, true);
+
 	spin_lock(&unix_gc_lock);
 
 	if (!unix_graph_maybe_cyclic) {
Signature · 1 line
2.47.3