diff mbox series

[net-next] net: msg_zerocopy: elide page accounting if RLIM_INFINITY

Message ID 20230214155740.3448763-1-willemdebruijn.kernel@gmail.com (mailing list archive)
State Accepted
Commit 14ade6ba4120fb38fcb5033998882c5b3d591194
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: msg_zerocopy: elide page accounting if RLIM_INFINITY | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 1 this patch: 1
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Willem de Bruijn Feb. 14, 2023, 3:57 p.m. UTC
From: Willem de Bruijn <willemb@google.com>

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 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>
---
 net/core/skbuff.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Eric Dumazet Feb. 15, 2023, 9:08 a.m. UTC | #1
On Tue, Feb 14, 2023 at 4:57 PM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> From: Willem de Bruijn <willemb@google.com>
>
> 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 users.

 (privileged as in CAP_IPC_LOCK)

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>
patchwork-bot+netdevbpf@kernel.org Feb. 16, 2023, 5:30 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 14 Feb 2023 10:57:40 -0500 you wrote:
> From: Willem de Bruijn <willemb@google.com>
> 
> 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 users. Rely on the
> same mechanism: if no mmp->user is set, mm_unaccount_pinned_pages does
> not decrement either.
> 
> [...]

Here is the summary with links:
  - [net-next] net: msg_zerocopy: elide page accounting if RLIM_INFINITY
    https://git.kernel.org/netdev/net-next/c/14ade6ba4120

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 13ea10cf8544..98ebce9f6a51 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -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);