On Thu, Nov 12, 2020 at 12:41 PM Björn Töpel <bjorn.topel@xxxxxxxxx> wrote: > > From: Björn Töpel <bjorn.topel@xxxxxxxxx> > > This option lets a user set a per socket NAPI budget for > busy-polling. If the options is not set, it will use the default of 8. > > Signed-off-by: Björn Töpel <bjorn.topel@xxxxxxxxx> > --- > ... > #else /* CONFIG_NET_RX_BUSY_POLL */ > static inline unsigned long net_busy_loop_on(void) > @@ -106,7 +108,8 @@ static inline void sk_busy_loop(struct sock *sk, int nonblock) > > if (napi_id >= MIN_NAPI_ID) > napi_busy_loop(napi_id, nonblock ? NULL : sk_busy_loop_end, sk, > - READ_ONCE(sk->sk_prefer_busy_poll)); > + READ_ONCE(sk->sk_prefer_busy_poll), > + sk->sk_busy_poll_budget ?: BUSY_POLL_BUDGET); Please use : READ_ONCE(sk->sk_busy_poll_budget) ?: BUSY_POLL_BUDGET Because sk_busy_loop() is usually called without socket lock being held. This will prevent yet another KCSAN report. > #endif > } > ... > --- a/net/core/sock.c > +++ b/net/core/sock.c > @@ -1165,6 +1165,16 @@ int sock_setsockopt(struct socket *sock, int level, int optname, > else > sk->sk_prefer_busy_poll = valbool; > break; > + case SO_BUSY_POLL_BUDGET: > + if (val > sk->sk_busy_poll_budget && !capable(CAP_NET_ADMIN)) { > + ret = -EPERM; > + } else { > + if (val < 0) if (val < 0 || val > (u16)~0) > + ret = -EINVAL; > + else > + sk->sk_busy_poll_budget = val; WRITE_ONCE(sk->sk_busy_poll_budget, val); > + } > + break; > #endif > > case SO_MAX_PACING_RATE: > -- > 2.27.0 >