Skip to contentSkip to conversation

riscv: uaccess: Allow the last potential unrolled copy

PATCH Applied Xiao Wang 4 participants 7 messages Mar 13, 2024 – May 22, 2024 RISC-V

lore
Share & tools
lore

Xiao Wang

author
#0 lore raw

PATCH 1/1 riscv: uaccess: Allow the last potential unrolled copy

When the dst buffer pointer points to the last accessible aligned addr, we could still run another iteration of unrolled copy.

---
 arch/riscv/lib/uaccess.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/lib/uaccess.S +1 -1
index 2e665f8f8fcc..1399d797d81b 100644
@@ -103,7 +103,7 @@ SYM_FUNC_START(fallback_scalar_usercopy)
 	fixup REG_S   t4,  7*SZREG(a0), 10f
 	addi	a0, a0, 8*SZREG
 	addi	a1, a1, 8*SZREG
-	bltu	a0, t0, 2b
+	bleu	a0, t0, 2b
 
 	addi	t0, t0, 8*SZREG /* revert to original value */
 	j	.Lbyte_copy_tail
Signature · 1 line
2.25.1
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi Xiao,

Quoted 13 lines · Xiao Wang

When the dst buffer pointer points to the last accessible aligned addr, we could still run another iteration of unrolled copy.

---
  arch/riscv/lib/uaccess.S | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/lib/uaccess.S +0 -0
index 2e665f8f8fcc..1399d797d81b 100644

arch/riscv/lib/uaccess.S SYM_FUNC_START(fallback_scalar_usercopy) · line 109

Quoted 8 lines
arch/riscv/lib/uaccess.S +1 -1
@@ -103,7 +103,7 @@ SYM_FUNC_START(fallback_scalar_usercopy)
  	fixup REG_S   t4,  7*SZREG(a0), 10f
  	addi	a0, a0, 8*SZREG
  	addi	a1, a1, 8*SZREG
-	bltu	a0, t0, 2b
+	bleu	a0, t0, 2b
 
  	addi	t0, t0, 8*SZREG /* revert to original value */
  	j	.Lbyte_copy_tail

I agree it is still safe to continue for another word_copy here.

Thanks,

Alex

#2 lore raw
Quoted 27 lines · Alexandre Ghiti

Hi Xiao,

Quoted 13 lines · Xiao Wang

When the dst buffer pointer points to the last accessible aligned addr, we could still run another iteration of unrolled copy.

---
  arch/riscv/lib/uaccess.S | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/lib/uaccess.S +0 -0
index 2e665f8f8fcc..1399d797d81b 100644
@@ -103,7 +103,7 @@ SYM_FUNC_START(fallback_scalar_usercopy)
Quoted 7 lines

      fixup REG_S   t4,  7*SZREG(a0), 10f
      addi    a0, a0, 8*SZREG
      addi    a1, a1, 8*SZREG
-    bltu    a0, t0, 2b
+    bleu    a0, t0, 2b
      addi    t0, t0, 8*SZREG /* revert to original value */ j    .Lbyte_copy_tail

I agree it is still safe to continue for another word_copy here.

Quoted 1 line

Out of interest, has anyone checked if causing a schedule event during this code breaks like the last time we had issues with the upstream testing?

I did propose saving the state of the user-access flag in the task struct but we mostly solved it by making sleeping functions stay away from the address calculation. This of course may have been done already or need to be done if three's long areas where the user-access flags can be disabled (generally only a few drivers did this, so we may not have come across the problem)

Signature · 10 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw

Hi Ben,

Quoted 28 lines · Ben Dooks
Quoted 27 lines · Alexandre Ghiti

Hi Xiao,

Quoted 13 lines · Xiao Wang

When the dst buffer pointer points to the last accessible aligned addr, we could still run another iteration of unrolled copy.

---
  arch/riscv/lib/uaccess.S | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/lib/uaccess.S +0 -0
index 2e665f8f8fcc..1399d797d81b 100644
@@ -103,7 +103,7 @@ SYM_FUNC_START(fallback_scalar_usercopy)
Quoted 7 lines

      fixup REG_S   t4,  7*SZREG(a0), 10f
      addi    a0, a0, 8*SZREG
      addi    a1, a1, 8*SZREG
-    bltu    a0, t0, 2b
+    bleu    a0, t0, 2b
      addi    t0, t0, 8*SZREG /* revert to original value */ j    .Lbyte_copy_tail

I agree it is still safe to continue for another word_copy here.

Quoted 5 lines
Quoted 1 line

Out of interest, has anyone checked if causing a schedule event during this code breaks like the last time we had issues with the upstream testing?

I vaguely remember something, do you have a link to that discussion by chance?

Quoted 3 lines

I did propose saving the state of the user-access flag in the task struct

Makes sense, I just took a quick look and SR_SUM is cleared as soon as we enter handle_exception() and it does not seem to be restored. Weird it works, unless I missed something!

Quoted 6 lines

but we mostly solved it by making sleeping functions stay away from the address calculation. This of course may have been done already or need to be done if three's long areas where the user-access flags can be disabled (generally only a few drivers did this, so we may not have come across the problem)

I don't understand what you mean here, would you mind expanding a bit?

Thanks,

Alex

#4 lore raw
Quoted 49 lines · Alexandre Ghiti

Hi Ben,

Quoted 28 lines · Ben Dooks
Quoted 27 lines · Alexandre Ghiti

Hi Xiao,

Quoted 13 lines · Xiao Wang

When the dst buffer pointer points to the last accessible aligned addr, we could still run another iteration of unrolled copy.

---
  arch/riscv/lib/uaccess.S | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/lib/uaccess.S +0 -0
index 2e665f8f8fcc..1399d797d81b 100644
@@ -103,7 +103,7 @@ SYM_FUNC_START(fallback_scalar_usercopy)
Quoted 7 lines

      fixup REG_S   t4,  7*SZREG(a0), 10f
      addi    a0, a0, 8*SZREG
      addi    a1, a1, 8*SZREG
-    bltu    a0, t0, 2b
+    bleu    a0, t0, 2b
      addi    t0, t0, 8*SZREG /* revert to original value */ j    .Lbyte_copy_tail

I agree it is still safe to continue for another word_copy here.

Quoted 5 lines
Quoted 1 line

Out of interest, has anyone checked if causing a schedule event during this code breaks like the last time we had issues with the upstream testing?

I vaguely remember something, do you have a link to that discussion by chance?

Quoted 3 lines

I did propose saving the state of the user-access flag in the task struct

Makes sense, I just took a quick look and SR_SUM is cleared as soon as we enter handle_exception() and it does not seem to be restored. Weird it works, unless I missed something!

Quoted 8 lines
Quoted 6 lines

but we mostly solved it by making sleeping functions stay away from the address calculation. This of course may have been done already or need to be done if three's long areas where the user-access flags can be disabled (generally only a few drivers did this, so we may not have come across the problem)

I don't understand what you mean here, would you mind expanding a bit?

I think this was all gone through in the original post where we initially suggested saving SR_SUM and then moved as much out of the critical SR_SUM area by changing how the macros worked

https://lore.kernel.org/linux-riscv/[email protected]/

https://lore.kernel.org/linux-riscv/[email protected]/

Signature · 4 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html
#5 lore raw

Hi Alex,

Quoted 12 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Friday, May 3, 2024 10:30 PM
To: Alexandre Ghiti <[email protected]>; Wang, Xiao W <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Li, Haicheng <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH] riscv: uaccess: Allow the last potential unrolled copy

Quoted 52 lines
Quoted 51 lines · Alexandre Ghiti

Hi Ben,

Quoted 29 lines · Ben Dooks
Quoted 28 lines · Alexandre Ghiti

Hi Xiao,

Quoted 14 lines · Xiao Wang

When the dst buffer pointer points to the last accessible aligned addr, we
could still run another iteration of unrolled copy.

---
  arch/riscv/lib/uaccess.S | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/lib/uaccess.S +0 -0
index 2e665f8f8fcc..1399d797d81b 100644
@@ -103,7 +103,7 @@ SYM_FUNC_START(fallback_scalar_usercopy)
Quoted 7 lines

      fixup REG_S   t4,  7*SZREG(a0), 10f
      addi    a0, a0, 8*SZREG
      addi    a1, a1, 8*SZREG
-    bltu    a0, t0, 2b
+    bleu    a0, t0, 2b
      addi    t0, t0, 8*SZREG /* revert to original value */ j    .Lbyte_copy_tail

I agree it is still safe to continue for another word_copy here.

Quoted 5 lines
Quoted 1 line

Out of interest, has anyone checked if causing a schedule event during this code breaks like the last time we had issues with the upstream testing?

I vaguely remember something, do you have a link to that discussion by chance?

Quoted 3 lines

I did propose saving the state of the user-access flag in the task struct

Makes sense, I just took a quick look and SR_SUM is cleared as soon as we enter handle_exception() and it does not seem to be restored. Weird it works, unless I missed something!

I think it's already saved/restored via pt_regs.status, using the PT_STATUS() macro in entry.S.

BRs,
Xiao

Quoted 25 lines
Quoted 10 lines
Quoted 8 lines

but we mostly solved it by making sleeping functions stay away from the address calculation. This of course may have been done already or need to be done if three's long areas where the user-access flags can be disabled (generally only a few drivers did this, so we may not have come across the problem)

I don't understand what you mean here, would you mind expanding a bit?

I think this was all gone through in the original post where we initially suggested saving SR_SUM and then moved as much out of the critical SR_SUM area by changing how the macros worked

https://lore.kernel.org/linux-riscv/20210318151010.100966-1-
[email protected]/

https://lore.kernel.org/linux-riscv/20210329095749.998940-1-
[email protected]/
--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html

#6 lore raw
In reply to Xiao Wang
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Quoted 7 lines · On Wed, 13 Mar 2024 18:33:34 +0800 you wrote:

When the dst buffer pointer points to the last accessible aligned addr, we could still run another iteration of unrolled copy.

---
 arch/riscv/lib/uaccess.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Here is the summary with links:
- riscv: uaccess: Allow the last potential unrolled copy

    https://git.kernel.org/riscv/c/74362d66a416

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html