mirror of
https://github.com/torvalds/linux.git
synced 2026-05-28 00:53:34 +02:00
net: msg_zerocopy: elide page accounting if RLIM_INFINITY
MSG_ZEROCOPY ensures that pinned user pages do not exceed the limit.
If no limit is set, skip this accounting as otherwise expensive
atomic_long operations are called for no reason.
This accounting is already skipped for privileged (CAP_IPC_LOCK)
users. Rely on the same mechanism: if no mmp->user is set,
mm_unaccount_pinned_pages does not decrement either.
Tested by running tools/testing/selftests/net/msg_zerocopy.sh with
an unprivileged user for the TXMODE binary:
ip netns exec "${NS1}" sudo -u "{$USER}" "${BIN}" "-${IP}" ...
Signed-off-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20230214155740.3448763-1-willemdebruijn.kernel@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
c24a34f5a3
commit
14ade6ba41
|
|
@ -1406,14 +1406,18 @@ EXPORT_SYMBOL_GPL(skb_morph);
|
|||
|
||||
int mm_account_pinned_pages(struct mmpin *mmp, size_t size)
|
||||
{
|
||||
unsigned long max_pg, num_pg, new_pg, old_pg;
|
||||
unsigned long max_pg, num_pg, new_pg, old_pg, rlim;
|
||||
struct user_struct *user;
|
||||
|
||||
if (capable(CAP_IPC_LOCK) || !size)
|
||||
return 0;
|
||||
|
||||
rlim = rlimit(RLIMIT_MEMLOCK);
|
||||
if (rlim == RLIM_INFINITY)
|
||||
return 0;
|
||||
|
||||
num_pg = (size >> PAGE_SHIFT) + 2; /* worst case */
|
||||
max_pg = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
|
||||
max_pg = rlim >> PAGE_SHIFT;
|
||||
user = mmp->user ? : current_user();
|
||||
|
||||
old_pg = atomic_long_read(&user->locked_vm);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user