All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm64: fix inline asm in load_unaligned_zeropad()
@ 2021-04-01 16:51 ` Peter Collingbourne
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Collingbourne @ 2021-04-01 16:51 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: Peter Collingbourne, linux-arm-kernel, stable

The inline asm's addr operand is marked as input-only, however in
the case where an exception is taken it may be modified by the BIC
instruction on the exception path. Fix the problem by using a temporary
register as the destination register for the BIC instruction.

Signed-off-by: Peter Collingbourne <pcc@google.com>
Cc: stable@vger.kernel.org
Link: https://linux-review.googlesource.com/id/I84538c8a2307d567b4f45bb20b715451005f9617
---
 arch/arm64/include/asm/word-at-a-time.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/include/asm/word-at-a-time.h b/arch/arm64/include/asm/word-at-a-time.h
index 3333950b5909..ea487218db79 100644
--- a/arch/arm64/include/asm/word-at-a-time.h
+++ b/arch/arm64/include/asm/word-at-a-time.h
@@ -53,7 +53,7 @@ static inline unsigned long find_zero(unsigned long mask)
  */
 static inline unsigned long load_unaligned_zeropad(const void *addr)
 {
-	unsigned long ret, offset;
+	unsigned long ret, tmp;
 
 	/* Load word from unaligned pointer addr */
 	asm(
@@ -61,9 +61,9 @@ static inline unsigned long load_unaligned_zeropad(const void *addr)
 	"2:\n"
 	"	.pushsection .fixup,\"ax\"\n"
 	"	.align 2\n"
-	"3:	and	%1, %2, #0x7\n"
-	"	bic	%2, %2, #0x7\n"
-	"	ldr	%0, [%2]\n"
+	"3:	bic	%1, %2, #0x7\n"
+	"	ldr	%0, [%1]\n"
+	"	and	%1, %2, #0x7\n"
 	"	lsl	%1, %1, #0x3\n"
 #ifndef __AARCH64EB__
 	"	lsr	%0, %0, %1\n"
@@ -73,7 +73,7 @@ static inline unsigned long load_unaligned_zeropad(const void *addr)
 	"	b	2b\n"
 	"	.popsection\n"
 	_ASM_EXTABLE(1b, 3b)
-	: "=&r" (ret), "=&r" (offset)
+	: "=&r" (ret), "=&r" (tmp)
 	: "r" (addr), "Q" (*(unsigned long *)addr));
 
 	return ret;
-- 
2.31.0.291.g576ba9dcdaf-goog


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

* [PATCH] arm64: fix inline asm in load_unaligned_zeropad()
@ 2021-04-01 16:51 ` Peter Collingbourne
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Collingbourne @ 2021-04-01 16:51 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: Peter Collingbourne, linux-arm-kernel, stable

The inline asm's addr operand is marked as input-only, however in
the case where an exception is taken it may be modified by the BIC
instruction on the exception path. Fix the problem by using a temporary
register as the destination register for the BIC instruction.

Signed-off-by: Peter Collingbourne <pcc@google.com>
Cc: stable@vger.kernel.org
Link: https://linux-review.googlesource.com/id/I84538c8a2307d567b4f45bb20b715451005f9617
---
 arch/arm64/include/asm/word-at-a-time.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/include/asm/word-at-a-time.h b/arch/arm64/include/asm/word-at-a-time.h
index 3333950b5909..ea487218db79 100644
--- a/arch/arm64/include/asm/word-at-a-time.h
+++ b/arch/arm64/include/asm/word-at-a-time.h
@@ -53,7 +53,7 @@ static inline unsigned long find_zero(unsigned long mask)
  */
 static inline unsigned long load_unaligned_zeropad(const void *addr)
 {
-	unsigned long ret, offset;
+	unsigned long ret, tmp;
 
 	/* Load word from unaligned pointer addr */
 	asm(
@@ -61,9 +61,9 @@ static inline unsigned long load_unaligned_zeropad(const void *addr)
 	"2:\n"
 	"	.pushsection .fixup,\"ax\"\n"
 	"	.align 2\n"
-	"3:	and	%1, %2, #0x7\n"
-	"	bic	%2, %2, #0x7\n"
-	"	ldr	%0, [%2]\n"
+	"3:	bic	%1, %2, #0x7\n"
+	"	ldr	%0, [%1]\n"
+	"	and	%1, %2, #0x7\n"
 	"	lsl	%1, %1, #0x3\n"
 #ifndef __AARCH64EB__
 	"	lsr	%0, %0, %1\n"
@@ -73,7 +73,7 @@ static inline unsigned long load_unaligned_zeropad(const void *addr)
 	"	b	2b\n"
 	"	.popsection\n"
 	_ASM_EXTABLE(1b, 3b)
-	: "=&r" (ret), "=&r" (offset)
+	: "=&r" (ret), "=&r" (tmp)
 	: "r" (addr), "Q" (*(unsigned long *)addr));
 
 	return ret;
-- 
2.31.0.291.g576ba9dcdaf-goog


_______________________________________________
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] 4+ messages in thread

* Re: [PATCH] arm64: fix inline asm in load_unaligned_zeropad()
  2021-04-01 16:51 ` Peter Collingbourne
@ 2021-04-01 17:33   ` Will Deacon
  -1 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2021-04-01 17:33 UTC (permalink / raw)
  To: Peter Collingbourne, Catalin Marinas
  Cc: kernel-team, Will Deacon, stable, linux-arm-kernel

On Thu, 1 Apr 2021 09:51:10 -0700, Peter Collingbourne wrote:
> The inline asm's addr operand is marked as input-only, however in
> the case where an exception is taken it may be modified by the BIC
> instruction on the exception path. Fix the problem by using a temporary
> register as the destination register for the BIC instruction.

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

[1/1] arm64: fix inline asm in load_unaligned_zeropad()
      https://git.kernel.org/arm64/c/185f2e5f51c2

Cheers,
-- 
Will

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

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

* Re: [PATCH] arm64: fix inline asm in load_unaligned_zeropad()
@ 2021-04-01 17:33   ` Will Deacon
  0 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2021-04-01 17:33 UTC (permalink / raw)
  To: Peter Collingbourne, Catalin Marinas
  Cc: kernel-team, Will Deacon, stable, linux-arm-kernel

On Thu, 1 Apr 2021 09:51:10 -0700, Peter Collingbourne wrote:
> The inline asm's addr operand is marked as input-only, however in
> the case where an exception is taken it may be modified by the BIC
> instruction on the exception path. Fix the problem by using a temporary
> register as the destination register for the BIC instruction.

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

[1/1] arm64: fix inline asm in load_unaligned_zeropad()
      https://git.kernel.org/arm64/c/185f2e5f51c2

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] 4+ messages in thread

end of thread, other threads:[~2021-04-01 17:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 16:51 [PATCH] arm64: fix inline asm in load_unaligned_zeropad() Peter Collingbourne
2021-04-01 16:51 ` Peter Collingbourne
2021-04-01 17:33 ` Will Deacon
2021-04-01 17:33   ` 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.