All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] arm64/traps: Avoid unnecessary kernel/user pointer conversion
@ 2021-09-17  5:58 ` Amit Daniel Kachhap
  0 siblings, 0 replies; 6+ messages in thread
From: Amit Daniel Kachhap @ 2021-09-17  5:58 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: linux-kernel, Mark Rutland, Vincenzo Frascino, Kevin Brodsky,
	Amit Daniel Kachhap, Catalin Marinas, Will Deacon

Annotating a pointer from kernel to __user and then back again requires
an extra __force annotation to silent sparse warning. In call_undef_hook()
this unnecessary complexity can be avoided by modifying the intermediate
user pointer to unsigned long.

This way there is no inter-changeable use of user and kernel pointers
and the code is consistent.

Note: This patch adds no functional changes to code.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Amit Daniel Kachhap <amit.kachhap@arm.com>
---
Changes from v1:
* Instead of directly using instruction_pointer() for kernel pointers,
  modified the pc type from void __user * to unsigned long as suggested
  by Mark Rutland.

 arch/arm64/kernel/traps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index b03e383d944a..09236751283e 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -400,11 +400,11 @@ static int call_undef_hook(struct pt_regs *regs)
 	unsigned long flags;
 	u32 instr;
 	int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
-	void __user *pc = (void __user *)instruction_pointer(regs);
+	unsigned long pc = instruction_pointer(regs);
 
 	if (!user_mode(regs)) {
 		__le32 instr_le;
-		if (get_kernel_nofault(instr_le, (__force __le32 *)pc))
+		if (get_kernel_nofault(instr_le, (__le32 *)pc))
 			goto exit;
 		instr = le32_to_cpu(instr_le);
 	} else if (compat_thumb_mode(regs)) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2] arm64/traps: Avoid unnecessary kernel/user pointer conversion
@ 2021-09-17  5:58 ` Amit Daniel Kachhap
  0 siblings, 0 replies; 6+ messages in thread
From: Amit Daniel Kachhap @ 2021-09-17  5:58 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: linux-kernel, Mark Rutland, Vincenzo Frascino, Kevin Brodsky,
	Amit Daniel Kachhap, Catalin Marinas, Will Deacon

Annotating a pointer from kernel to __user and then back again requires
an extra __force annotation to silent sparse warning. In call_undef_hook()
this unnecessary complexity can be avoided by modifying the intermediate
user pointer to unsigned long.

This way there is no inter-changeable use of user and kernel pointers
and the code is consistent.

Note: This patch adds no functional changes to code.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Amit Daniel Kachhap <amit.kachhap@arm.com>
---
Changes from v1:
* Instead of directly using instruction_pointer() for kernel pointers,
  modified the pc type from void __user * to unsigned long as suggested
  by Mark Rutland.

 arch/arm64/kernel/traps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index b03e383d944a..09236751283e 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -400,11 +400,11 @@ static int call_undef_hook(struct pt_regs *regs)
 	unsigned long flags;
 	u32 instr;
 	int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
-	void __user *pc = (void __user *)instruction_pointer(regs);
+	unsigned long pc = instruction_pointer(regs);
 
 	if (!user_mode(regs)) {
 		__le32 instr_le;
-		if (get_kernel_nofault(instr_le, (__force __le32 *)pc))
+		if (get_kernel_nofault(instr_le, (__le32 *)pc))
 			goto exit;
 		instr = le32_to_cpu(instr_le);
 	} else if (compat_thumb_mode(regs)) {
-- 
2.17.1


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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] arm64/traps: Avoid unnecessary kernel/user pointer conversion
  2021-09-17  5:58 ` Amit Daniel Kachhap
@ 2021-09-17  9:36   ` Mark Rutland
  -1 siblings, 0 replies; 6+ messages in thread
From: Mark Rutland @ 2021-09-17  9:36 UTC (permalink / raw)
  To: Amit Daniel Kachhap
  Cc: linux-arm-kernel, linux-kernel, Vincenzo Frascino, Kevin Brodsky,
	Catalin Marinas, Will Deacon

On Fri, Sep 17, 2021 at 11:28:11AM +0530, Amit Daniel Kachhap wrote:
> Annotating a pointer from kernel to __user and then back again requires
> an extra __force annotation to silent sparse warning. In call_undef_hook()
> this unnecessary complexity can be avoided by modifying the intermediate
> user pointer to unsigned long.
> 
> This way there is no inter-changeable use of user and kernel pointers
> and the code is consistent.
> 
> Note: This patch adds no functional changes to code.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Signed-off-by: Amit Daniel Kachhap <amit.kachhap@arm.com>

I like that this clarifies that `pc` is not necessarily a user pointer,
and this makes the relevant lines shorter and eaier to read, so FWIW:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Thanks,
Mark.

> ---
> Changes from v1:
> * Instead of directly using instruction_pointer() for kernel pointers,
>   modified the pc type from void __user * to unsigned long as suggested
>   by Mark Rutland.
> 
>  arch/arm64/kernel/traps.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
> index b03e383d944a..09236751283e 100644
> --- a/arch/arm64/kernel/traps.c
> +++ b/arch/arm64/kernel/traps.c
> @@ -400,11 +400,11 @@ static int call_undef_hook(struct pt_regs *regs)
>  	unsigned long flags;
>  	u32 instr;
>  	int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
> -	void __user *pc = (void __user *)instruction_pointer(regs);
> +	unsigned long pc = instruction_pointer(regs);
>  
>  	if (!user_mode(regs)) {
>  		__le32 instr_le;
> -		if (get_kernel_nofault(instr_le, (__force __le32 *)pc))
> +		if (get_kernel_nofault(instr_le, (__le32 *)pc))
>  			goto exit;
>  		instr = le32_to_cpu(instr_le);
>  	} else if (compat_thumb_mode(regs)) {
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] arm64/traps: Avoid unnecessary kernel/user pointer conversion
@ 2021-09-17  9:36   ` Mark Rutland
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Rutland @ 2021-09-17  9:36 UTC (permalink / raw)
  To: Amit Daniel Kachhap
  Cc: linux-arm-kernel, linux-kernel, Vincenzo Frascino, Kevin Brodsky,
	Catalin Marinas, Will Deacon

On Fri, Sep 17, 2021 at 11:28:11AM +0530, Amit Daniel Kachhap wrote:
> Annotating a pointer from kernel to __user and then back again requires
> an extra __force annotation to silent sparse warning. In call_undef_hook()
> this unnecessary complexity can be avoided by modifying the intermediate
> user pointer to unsigned long.
> 
> This way there is no inter-changeable use of user and kernel pointers
> and the code is consistent.
> 
> Note: This patch adds no functional changes to code.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Signed-off-by: Amit Daniel Kachhap <amit.kachhap@arm.com>

I like that this clarifies that `pc` is not necessarily a user pointer,
and this makes the relevant lines shorter and eaier to read, so FWIW:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Thanks,
Mark.

> ---
> Changes from v1:
> * Instead of directly using instruction_pointer() for kernel pointers,
>   modified the pc type from void __user * to unsigned long as suggested
>   by Mark Rutland.
> 
>  arch/arm64/kernel/traps.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
> index b03e383d944a..09236751283e 100644
> --- a/arch/arm64/kernel/traps.c
> +++ b/arch/arm64/kernel/traps.c
> @@ -400,11 +400,11 @@ static int call_undef_hook(struct pt_regs *regs)
>  	unsigned long flags;
>  	u32 instr;
>  	int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
> -	void __user *pc = (void __user *)instruction_pointer(regs);
> +	unsigned long pc = instruction_pointer(regs);
>  
>  	if (!user_mode(regs)) {
>  		__le32 instr_le;
> -		if (get_kernel_nofault(instr_le, (__force __le32 *)pc))
> +		if (get_kernel_nofault(instr_le, (__le32 *)pc))
>  			goto exit;
>  		instr = le32_to_cpu(instr_le);
>  	} else if (compat_thumb_mode(regs)) {
> -- 
> 2.17.1
> 

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] arm64/traps: Avoid unnecessary kernel/user pointer conversion
  2021-09-17  5:58 ` Amit Daniel Kachhap
@ 2021-09-29 17:48   ` Will Deacon
  -1 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2021-09-29 17:48 UTC (permalink / raw)
  To: Amit Daniel Kachhap, linux-arm-kernel
  Cc: catalin.marinas, kernel-team, Will Deacon, Mark Rutland,
	Vincenzo Frascino, Kevin Brodsky, linux-kernel

On Fri, 17 Sep 2021 11:28:11 +0530, Amit Daniel Kachhap wrote:
> Annotating a pointer from kernel to __user and then back again requires
> an extra __force annotation to silent sparse warning. In call_undef_hook()
> this unnecessary complexity can be avoided by modifying the intermediate
> user pointer to unsigned long.
> 
> This way there is no inter-changeable use of user and kernel pointers
> and the code is consistent.
> 
> [...]

Applied to arm64 (for-next/misc), thanks!

[1/1] arm64/traps: Avoid unnecessary kernel/user pointer conversion
      https://git.kernel.org/arm64/c/f5b650f887f3

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] arm64/traps: Avoid unnecessary kernel/user pointer conversion
@ 2021-09-29 17:48   ` Will Deacon
  0 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2021-09-29 17:48 UTC (permalink / raw)
  To: Amit Daniel Kachhap, linux-arm-kernel
  Cc: catalin.marinas, kernel-team, Will Deacon, Mark Rutland,
	Vincenzo Frascino, Kevin Brodsky, linux-kernel

On Fri, 17 Sep 2021 11:28:11 +0530, Amit Daniel Kachhap wrote:
> Annotating a pointer from kernel to __user and then back again requires
> an extra __force annotation to silent sparse warning. In call_undef_hook()
> this unnecessary complexity can be avoided by modifying the intermediate
> user pointer to unsigned long.
> 
> This way there is no inter-changeable use of user and kernel pointers
> and the code is consistent.
> 
> [...]

Applied to arm64 (for-next/misc), thanks!

[1/1] arm64/traps: Avoid unnecessary kernel/user pointer conversion
      https://git.kernel.org/arm64/c/f5b650f887f3

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-09-29 17:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-17  5:58 [PATCH v2] arm64/traps: Avoid unnecessary kernel/user pointer conversion Amit Daniel Kachhap
2021-09-17  5:58 ` Amit Daniel Kachhap
2021-09-17  9:36 ` Mark Rutland
2021-09-17  9:36   ` Mark Rutland
2021-09-29 17:48 ` Will Deacon
2021-09-29 17:48   ` Will Deacon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.