Skip to content

Commit 5593cb9

Browse files
q2vengregkh
authored andcommitted
af_unix: Bulk update unix_tot_inflight/unix_inflight when queuing skb.
commit 22c3c0c52d32f41cc38cd936ea0c93f22ced3315 upstream. Currently, we track the number of inflight sockets in two variables. unix_tot_inflight is the total number of inflight AF_UNIX sockets on the host, and user->unix_inflight is the number of inflight fds per user. We update them one by one in unix_inflight(), which can be done once in batch. Also, sendmsg() could fail even after unix_inflight(), then we need to acquire unix_gc_lock only to decrement the counters. Let's bulk update the counters in unix_add_edges() and unix_del_edges(), which is called only for successfully passed fds. Signed-off-by: Kuniyuki Iwashima <[email protected]> Acked-by: Paolo Abeni <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Lee Jones <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f8194e5 commit 5593cb9

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

net/unix/garbage.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static void unix_free_vertices(struct scm_fp_list *fpl)
144144
}
145145

146146
DEFINE_SPINLOCK(unix_gc_lock);
147+
unsigned int unix_tot_inflight;
147148

148149
void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver)
149150
{
@@ -168,7 +169,10 @@ void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver)
168169
unix_add_edge(fpl, edge);
169170
} while (i < fpl->count_unix);
170171

172+
WRITE_ONCE(unix_tot_inflight, unix_tot_inflight + fpl->count_unix);
171173
out:
174+
WRITE_ONCE(fpl->user->unix_inflight, fpl->user->unix_inflight + fpl->count);
175+
172176
spin_unlock(&unix_gc_lock);
173177

174178
fpl->inflight = true;
@@ -191,7 +195,10 @@ void unix_del_edges(struct scm_fp_list *fpl)
191195
unix_del_edge(fpl, edge);
192196
} while (i < fpl->count_unix);
193197

198+
WRITE_ONCE(unix_tot_inflight, unix_tot_inflight - fpl->count_unix);
194199
out:
200+
WRITE_ONCE(fpl->user->unix_inflight, fpl->user->unix_inflight - fpl->count);
201+
195202
spin_unlock(&unix_gc_lock);
196203

197204
fpl->inflight = false;
@@ -234,7 +241,6 @@ void unix_destroy_fpl(struct scm_fp_list *fpl)
234241
unix_free_vertices(fpl);
235242
}
236243

237-
unsigned int unix_tot_inflight;
238244
static LIST_HEAD(gc_candidates);
239245
static LIST_HEAD(gc_inflight_list);
240246

@@ -255,13 +261,8 @@ void unix_inflight(struct user_struct *user, struct file *filp)
255261
WARN_ON_ONCE(list_empty(&u->link));
256262
}
257263
u->inflight++;
258-
259-
/* Paired with READ_ONCE() in wait_for_unix_gc() */
260-
WRITE_ONCE(unix_tot_inflight, unix_tot_inflight + 1);
261264
}
262265

263-
WRITE_ONCE(user->unix_inflight, user->unix_inflight + 1);
264-
265266
spin_unlock(&unix_gc_lock);
266267
}
267268

@@ -278,13 +279,8 @@ void unix_notinflight(struct user_struct *user, struct file *filp)
278279
u->inflight--;
279280
if (!u->inflight)
280281
list_del_init(&u->link);
281-
282-
/* Paired with READ_ONCE() in wait_for_unix_gc() */
283-
WRITE_ONCE(unix_tot_inflight, unix_tot_inflight - 1);
284282
}
285283

286-
WRITE_ONCE(user->unix_inflight, user->unix_inflight - 1);
287-
288284
spin_unlock(&unix_gc_lock);
289285
}
290286

0 commit comments

Comments
 (0)