public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Mark Rutland <mark.rutland@arm.com>,
	linux-arm-kernel@lists.infradead.org
Cc: catalin.marinas@arm.com, james.morse@arm.com, hch@lst.de,
	will@kernel.org
Subject: Re: [PATCHv3 11/17] arm64: uaccess: refactor __{get,put}_user
Date: Tue, 27 Oct 2020 18:03:19 +0000	[thread overview]
Message-ID: <bf2bb221-f25c-fb8f-6c76-d63540f17fd5@arm.com> (raw)
In-Reply-To: <20201026133156.44186-12-mark.rutland@arm.com>

On 2020-10-26 13:31, Mark Rutland wrote:
> As a step towards implementing __{get,put}_kernel_nofault(), this patch
> splits most user-memory specific logic out of __{get,put}_user(), with
> the memory access and fault handling in new __{raw_get,put}_mem()
> helpers.
> 
> For now the LDR/LDTR patching is left within the *get_mem() helpers, and
> will be removed in a subsequent patch.
> 
> There should be no functional change as a result of this patch.
> 
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: James Morse <james.morse@arm.com>
> Cc: Will Deacon <will@kernel.org>
> ---
>   arch/arm64/include/asm/uaccess.h | 40 +++++++++++++++++++++++++---------------
>   1 file changed, 25 insertions(+), 15 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
> index d6a4e496ebc64..4ad2990241d78 100644
> --- a/arch/arm64/include/asm/uaccess.h
> +++ b/arch/arm64/include/asm/uaccess.h
> @@ -253,7 +253,7 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr)
>    * The "__xxx_error" versions set the third argument to -EFAULT if an error
>    * occurs, and leave it unchanged on success.
>    */
> -#define __get_user_asm(instr, alt_instr, reg, x, addr, err, feature)	\
> +#define __get_mem_asm(instr, alt_instr, reg, x, addr, err, feature)	\
>   	asm volatile(							\
>   	"1:"ALTERNATIVE(instr "     " reg "1, [%2]\n",			\
>   			alt_instr " " reg "1, [%2]\n", feature)		\
> @@ -268,35 +268,40 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr)
>   	: "+r" (err), "=&r" (x)						\
>   	: "r" (addr), "i" (-EFAULT))
>   
> -#define __raw_get_user(x, ptr, err)					\
> +#define __raw_get_mem(x, ptr, err)					\
>   do {									\
>   	unsigned long __gu_val;						\
>   	__chk_user_ptr(ptr);						\

Should this move out as well? It seems logical that wherever we figure 
out whether a pointer is "kernel" or "user" in order to call the 
appropriate low-level routine, the __user annotation could be dropped 
from the "kernel" path at that point - or have I misunderstood?

Robin.

> -	uaccess_enable_not_uao();					\
>   	switch (sizeof(*(ptr))) {					\
>   	case 1:								\
> -		__get_user_asm("ldrb", "ldtrb", "%w", __gu_val, (ptr),  \
> +		__get_mem_asm("ldrb", "ldtrb", "%w", __gu_val, (ptr),	\
>   			       (err), ARM64_HAS_UAO);			\
>   		break;							\
>   	case 2:								\
> -		__get_user_asm("ldrh", "ldtrh", "%w", __gu_val, (ptr),  \
> +		__get_mem_asm("ldrh", "ldtrh", "%w", __gu_val, (ptr),	\
>   			       (err), ARM64_HAS_UAO);			\
>   		break;							\
>   	case 4:								\
> -		__get_user_asm("ldr", "ldtr", "%w", __gu_val, (ptr),	\
> +		__get_mem_asm("ldr", "ldtr", "%w", __gu_val, (ptr),	\
>   			       (err), ARM64_HAS_UAO);			\
>   		break;							\
>   	case 8:								\
> -		__get_user_asm("ldr", "ldtr", "%x",  __gu_val, (ptr),	\
> +		__get_mem_asm("ldr", "ldtr", "%x",  __gu_val, (ptr),	\
>   			       (err), ARM64_HAS_UAO);			\
>   		break;							\
>   	default:							\
>   		BUILD_BUG();						\
>   	}								\
> -	uaccess_disable_not_uao();					\
>   	(x) = (__force __typeof__(*(ptr)))__gu_val;			\
>   } while (0)
>   
> +#define __raw_get_user(x, ptr, err)					\
> +do {									\
> +	uaccess_enable_not_uao();					\
> +	__raw_get_mem(x, ptr, err);					\
> +	uaccess_disable_not_uao();					\
> +} while (0)
> +
>   #define __get_user_error(x, ptr, err)					\
>   do {									\
>   	__typeof__(*(ptr)) __user *__p = (ptr);				\
> @@ -318,7 +323,7 @@ do {									\
>   
>   #define get_user	__get_user
>   
> -#define __put_user_asm(instr, alt_instr, reg, x, addr, err, feature)	\
> +#define __put_mem_asm(instr, alt_instr, reg, x, addr, err, feature)	\
>   	asm volatile(							\
>   	"1:"ALTERNATIVE(instr "     " reg "1, [%2]\n",			\
>   			alt_instr " " reg "1, [%2]\n", feature)		\
> @@ -332,31 +337,36 @@ do {									\
>   	: "+r" (err)							\
>   	: "r" (x), "r" (addr), "i" (-EFAULT))
>   
> -#define __raw_put_user(x, ptr, err)					\
> +#define __raw_put_mem(x, ptr, err)					\
>   do {									\
>   	__typeof__(*(ptr)) __pu_val = (x);				\
>   	__chk_user_ptr(ptr);						\
> -	uaccess_enable_not_uao();					\
>   	switch (sizeof(*(ptr))) {					\
>   	case 1:								\
> -		__put_user_asm("strb", "sttrb", "%w", __pu_val, (ptr),	\
> +		__put_mem_asm("strb", "sttrb", "%w", __pu_val, (ptr),	\
>   			       (err), ARM64_HAS_UAO);			\
>   		break;							\
>   	case 2:								\
> -		__put_user_asm("strh", "sttrh", "%w", __pu_val, (ptr),	\
> +		__put_mem_asm("strh", "sttrh", "%w", __pu_val, (ptr),	\
>   			       (err), ARM64_HAS_UAO);			\
>   		break;							\
>   	case 4:								\
> -		__put_user_asm("str", "sttr", "%w", __pu_val, (ptr),	\
> +		__put_mem_asm("str", "sttr", "%w", __pu_val, (ptr),	\
>   			       (err), ARM64_HAS_UAO);			\
>   		break;							\
>   	case 8:								\
> -		__put_user_asm("str", "sttr", "%x", __pu_val, (ptr),	\
> +		__put_mem_asm("str", "sttr", "%x", __pu_val, (ptr),	\
>   			       (err), ARM64_HAS_UAO);			\
>   		break;							\
>   	default:							\
>   		BUILD_BUG();						\
>   	}								\
> +} while (0)
> +
> +#define __raw_put_user(x, ptr, err)					\
> +do {									\
> +	uaccess_enable_not_uao();					\
> +	__raw_put_mem(x, ptr, err);					\
>   	uaccess_disable_not_uao();					\
>   } while (0)
>   
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-10-27 18:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 13:31 [PATCHv3 00/17] arm64: remove set_fs() and friends Mark Rutland
2020-10-26 13:31 ` [PATCHv3 01/17] arm64: ensure ERET from kthread is illegal Mark Rutland
2020-10-26 13:31 ` [PATCHv3 02/17] arm64: add C wrappers for SET_PSTATE_*() Mark Rutland
2020-10-26 13:31 ` [PATCHv3 03/17] arm64: head.S: rename el2_setup -> init_kernel_el Mark Rutland
2020-10-26 13:31 ` [PATCHv3 04/17] arm64: head.S: cleanup SCTLR_ELx initialization Mark Rutland
2020-10-26 13:31 ` [PATCHv3 05/17] arm64: head.S: always initialize PSTATE Mark Rutland
2020-10-26 13:31 ` [PATCHv3 06/17] arm64: sdei: move uaccess logic to arch/arm64/ Mark Rutland
2020-10-26 13:31 ` [PATCHv3 07/17] arm64: sdei: explicitly simulate PAN/UAO entry Mark Rutland
2020-10-26 13:31 ` [PATCHv3 08/17] arm64: uaccess: move uao_* alternatives to asm-uaccess.h Mark Rutland
2020-11-03 14:26   ` Will Deacon
2020-11-03 14:41     ` Mark Rutland
2020-10-26 13:31 ` [PATCHv3 09/17] arm64: uaccess: rename privileged uaccess routines Mark Rutland
2020-10-26 13:31 ` [PATCHv3 10/17] arm64: uaccess: simplify __copy_user_flushcache() Mark Rutland
2020-10-27 17:33   ` Robin Murphy
2020-11-02 10:14     ` Mark Rutland
2020-10-26 13:31 ` [PATCHv3 11/17] arm64: uaccess: refactor __{get,put}_user Mark Rutland
2020-10-27 18:03   ` Robin Murphy [this message]
2020-11-02 10:25     ` Mark Rutland
2020-10-26 13:31 ` [PATCHv3 12/17] arm64: uaccess: split user/kernel routines Mark Rutland
2020-11-02 10:48   ` Mark Rutland
2020-10-26 13:31 ` [PATCHv3 13/17] arm64: uaccess cleanup macro naming Mark Rutland
2020-10-27 18:45   ` Robin Murphy
2020-11-02 10:35     ` Mark Rutland
2020-10-26 13:31 ` [PATCHv3 14/17] arm64: uaccess: remove set_fs() Mark Rutland
2020-10-26 13:31 ` [PATCHv3 15/17] arm64: uaccess: remove addr_limit_user_check() Mark Rutland
2020-10-26 13:31 ` [PATCHv3 16/17] arm64: uaccess: remove redundant PAN toggling Mark Rutland
2020-10-26 13:31 ` [PATCHv3 17/17] arm64: uaccess: remove vestigal UAO support Mark Rutland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf2bb221-f25c-fb8f-6c76-d63540f17fd5@arm.com \
    --to=robin.murphy@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=hch@lst.de \
    --cc=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox