Re: [PATCH] x86/uaccess: Implement get_kernel()

Peter Zijlstra
2015-04-10T11:34:27Z

On Fri, Apr 10, 2015 at 01:14:27PM +0200, Ingo Molnar wrote:
> +/*
> + * Simple copy-from-possibly-faulting-kernel-addresses method that
> + * avoids the STAC/CLAC SMAP overhead.
> + *
> + * NOTE: this does not propagate the error code of faulting kernel
> + * addresses properly. You can recover it via uaccess_catch()
> + * if you really need to.
> + */
> +#define get_kernel(dst, src) \
> +do { \
> + typeof(*(src)) __val; \

Should we make that:

typeof(*(src)) __val = (dst);

> + \
> + switch (sizeof(__val)) { \
> + case 1: __get_kernel_asm_ex(__val, src, "b", "b", "=q"); break; \
> + case 2: __get_kernel_asm_ex(__val, src, "w", "w", "=r"); break; \
> + case 4: __get_kernel_asm_ex(__val, src, "l", "k", "=r"); break; \
> + case 8: __get_kernel_asm_ex(__val, src, "q", " ", "=r"); break; \
> + default: __get_kernel_BUILD_ERROR(); \
> + } \
> + (dst) = __val; \
> +} while (0)

Such that when we fault, the value is unmodified? The way it is we'll
assign whatever was on stack for __val, which seems undesirable, no?