[PATCH 5/7] maccess: Batch TCO handling in kernel nofault loops

David Hildenbrand (Arm) david at kernel.org
Thu Oct 1 04:36:28 PDT 2026


On 8/24/26 18:04, Muhammad Usama Anjum wrote:
> With Hardware Tag-Based KASAN in asynchronous or asymmetric mode, every
> arm64 kernel nofault access sets and clears PSTATE.TCO. Copy and string
> loops repeat that pair even though tag checking can stay disabled for the
> whole operation.
> 
> Cover each non-empty operation with one bare nofault region and use bare
> accessors in the loop. Leaving the region restores TCO before page faults
> are enabled again, including after an access fault. Existing empty-work
> checks ensure that every new region performs at least one access.
> 
> The number of dynamic MSR TCO executions therefore changes as follows:
> 
>     Work                         Before    After
>     N nofault accesses          2N        2
>     4 KiB nofault copy          1,024     2
>     N-byte strncpy              2N        2
> 
> The 4 KiB case assumes 512 64-bit accesses. These figures come from the
> control flow rather than a runtime measurement, so the time saved depends
> on the CPU and workload. Generic fallbacks leave other architectures
> unchanged.
> 
> Signed-off-by: Muhammad Usama Anjum <usama.anjum at arm.com>
> ---

[...]

>  Efault:
> @@ -96,11 +100,13 @@ long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count)
>  		return -ERANGE;
>  
>  	scoped_guard(pagefault) {
> -		do {
> -			__get_kernel_nofault(dst, src, u8, Efault);
> -			dst++;
> -			src++;
> -		} while (dst[-1] && src - unsafe_addr < count);
> +		scoped_guard(__kernel_nofault_bare) {
> +			do {
> +				__get_kernel_nofault_bare(dst, src, u8, Efault);
> +				dst++;
> +				src++;
> +			} while (dst[-1] && src - unsafe_addr < count);
> +		}

Reading the same thing multiple times, why can't we have a new guard that wraps
both these things?

-- 
Cheers,

David



More information about the linux-arm-kernel mailing list