Re: [PATCH 3/7] maccess: Skip setup for zero-sized kernel nofault copies
From: David Hildenbrand (Arm)
Date: Thu Oct 01 2026 - 07:34:48 EST
On 8/24/26 18:04, Muhammad Usama Anjum wrote:
> A zero-sized kernel nofault copy does not enter an access loop, but it
> still disables and re-enables page faults.
>
> Zero sizes are valid. BPF probe-read helpers accept them, and KGDB memory
> packets may carry a zero length.
>
> Return before changing page-fault state when there is nothing to copy.
> For reads, keep architecture-specific address validation before the fast
> path so its behavior is unchanged.
>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@xxxxxxx>
> ---
> mm/maccess.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/mm/maccess.c b/mm/maccess.c
> index 486559d688583..c59a0e092d24a 100644
> --- a/mm/maccess.c
> +++ b/mm/maccess.c
> @@ -35,6 +35,8 @@ long copy_from_kernel_nofault(void *dst, const void *src, size_t size)
>
> if (!copy_from_kernel_nofault_allowed(src, size))
> return -ERANGE;
> + if (!size)
> + return 0;
>
> pagefault_disable();
> if (!(align & 7))
> @@ -65,6 +67,9 @@ long copy_to_kernel_nofault(void *dst, const void *src, size_t size)
> {
> unsigned long align = 0;
>
> + if (!size)
> + return 0;
> +
Worth an unlikely() ? It's the corner case.
--
Cheers,
David