arm/syscalls: Move address limit check in loop
Subsystems (2)
PATCH 1/3 arm/syscalls: Move address limit check in loop
The work pending loop can call set_fs after addr_limit_user_check removed the _TIF_FSCHECK flag. To prevent the infinite loop, move the addr_limit_user_check call at the beginning of the loop.
--- arch/arm/kernel/signal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm/kernel/signal.c +3 -3
@@ -573,10 +573,10 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)*/ trace_hardirqs_off (); -/* Check valid user FS if needed */ -addr_limit_user_check (); - do { + /* Check valid user FS if needed */ + addr_limit_user_check(); + if (likely(thread_flags & _TIF_NEED_RESCHED)) { schedule(); } else {
Signature · 1 line
2.14.0.rc0.284.gd933b75aa4-goog
PATCH 2/3 arm/syscalls: Optimize work flags assembly check
Remove the double branch and use tsteq instead.
--- arch/arm/kernel/entry-common.S | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/arm/kernel/entry-common.S +2 -5
@@ -42,8 +42,7 @@ ret_fast_syscall: disable_irq_notrace @ disable interrupts ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK - bne fast_work_pending - tst r1, #_TIF_WORK_MASK + tsteq r1, #_TIF_WORK_MASK bne fast_work_pending /* perform architecture specific actions before user return */
@@ -70,14 +69,12 @@ ret_fast_syscall: disable_irq_notrace @ disable interrupts ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK - bne fast_work_pending - tst r1, #_TIF_WORK_MASK + tsteq r1, #_TIF_WORK_MASK beq no_work_pending UNWIND(.fnend ) ENDPROC(ret_fast_syscall) /* Slower path - fall through to work_pending */ -fast_work_pending: #endif tst r1, #_TIF_SYSCALL_WORK
Signature · 1 line
2.14.0.rc0.284.gd933b75aa4-goog
PATCH 3/3 arm64/syscalls: Move address limit check in loop
In reply to Thomas GarnierThe original bug was reported on arm but I am fixing arm64 too because it has a similar code pattern.
The work pending loop can call set_fs after addr_limit_user_check removed the _TIF_FSCHECK flag. To prevent the infinite loop, move the addr_limit_user_check call at the beginning of the loop.
--- arch/arm64/kernel/signal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kernel/signal.c +3 -3
@@ -751,10 +751,10 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,*/ trace_hardirqs_off (); -/* Check valid user FS if needed */ -addr_limit_user_check (); - do { + /* Check valid user FS if needed */ + addr_limit_user_check(); + if (thread_flags & _TIF_NEED_RESCHED) { schedule(); } else {
Signature · 1 line
2.14.0.rc0.284.gd933b75aa4-goog
Quoted 7 lines · Thomas Garnier
The work pending loop can call
set_fsafteraddr_limit_user_checkremoved the_TIF_FSCHECKflag. To prevent the infinite loop, move theaddr_limit_user_checkcall at the beginning of the loop.Fixes 73ac5d6a2b6a ("arm/syscalls: Check address limit on user-mode return")Reported-by Leonard Crestez <[email protected]>Signed-off-by Thomas Garnier <[email protected]>
Any comments on this patch set?
Quoted 25 lines
--- arch/arm/kernel/signal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/arm/kernel/signal.c +3
-4@@ -573,10 +573,10 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)*/ trace_hardirqs_off (); -/* Check valid user FS if needed */ -addr_limit_user_check (); - do { + /* Check valid user FS if needed */ + addr_limit_user_check(); + if (likely(thread_flags & _TIF_NEED_RESCHED)) { schedule(); } else { --2.14.0.rc0.284.gd933b75aa4-goog
Signature · 1 line
Thomas
Leonard Crestez
Tested-byQuoted 7 lines · Thomas Garnier
On Wed, Jul 19, 2017 at 10:58 AM, Thomas Garnier <[email protected]
Quoted 6 lines
wrote:
The work pending loop can call
set_fsafteraddr_limit_user_checkremoved the_TIF_FSCHECKflag. To prevent the infinite loop, move theaddr_limit_user_checkcall at the beginning of the loop.
Quoted 6 lines
Quoted 4 lines
Fixes 73ac5d6a2b6a ("arm/syscalls: Check address limit on user-mode return")
Reported-by Leonard Crestez <[email protected]>Signed-off-by Thomas Garnier <[email protected]>Any comments on this patch set?
This appears to fix the original issue of failing to boot from NFS when there are lots of alignment faults. But this is a very basic test relative to the reach of this change.
However the original patch has been in linux-next for a while and apparently nobody else noticed system calls randomly hanging on arm.
I assume maintainers need to give their opinion.
Russell King - ARM Linux
maintainerQuoted 17 lines · Leonard Crestez
Quoted 7 lines · Thomas Garnier
On Wed, Jul 19, 2017 at 10:58 AM, Thomas Garnier <[email protected]
Quoted 6 lines
wrote:
The work pending loop can call
set_fsafteraddr_limit_user_checkremoved the_TIF_FSCHECKflag. To prevent the infinite loop, move theaddr_limit_user_checkcall at the beginning of the loop.Quoted 6 lines
Quoted 4 lines
Fixes 73ac5d6a2b6a ("arm/syscalls: Check address limit on user-mode return")
Reported-by Leonard Crestez <[email protected]>Signed-off-by Thomas Garnier <[email protected]>Any comments on this patch set?
Tested-by Leonard Crestez <[email protected]>
Quoted 8 lines
This appears to fix the original issue of failing to boot from NFS when there are lots of alignment faults. But this is a very basic test relative to the reach of this change.
However the original patch has been in linux-next for a while and apparently nobody else noticed system calls randomly hanging on arm.
I assume maintainers need to give their opinion.
I've already stated my opinion, which is different from what Linus has requested of Thomas. IMHO, the current approach is going to keep on causing problems along the lines that I've already pointed out.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
Quoted 22 lines · Russell King - ARM Linux
Quoted 21 lines · Leonard Crestez
Quoted 7 lines · Thomas Garnier
On Wed, Jul 19, 2017 at 10:58 AM, Thomas Garnier <[email protected]
Quoted 6 lines
wrote:
The work pending loop can call
set_fsafteraddr_limit_user_checkremoved the_TIF_FSCHECKflag. To prevent the infinite loop, move theaddr_limit_user_checkcall at the beginning of the loop.Quoted 6 lines
Quoted 4 lines
Fixes 73ac5d6a2b6a ("arm/syscalls: Check address limit on user-mode return")
Reported-by Leonard Crestez <[email protected]>Signed-off-by Thomas Garnier <[email protected]>Any comments on this patch set?
Tested-by Leonard Crestez <[email protected]>This appears to fix the original issue of failing to boot from NFS when there are lots of alignment faults. But this is a very basic test relative to the reach of this change.
Quoted 8 lines
Quoted 4 lines
However the original patch has been in linux-next for a while and apparently nobody else noticed system calls randomly hanging on arm.
I assume maintainers need to give their opinion.
I've already stated my opinion, which is different from what Linus has requested of Thomas. IMHO, the current approach is going to keep on causing problems along the lines that I've already pointed out.
I understand. Do you think this problem apply to arm64 as well?
Quoted 5 lines
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
Signature · 1 line
Thomas
Quoted 27 lines · Thomas Garnier
Quoted 25 lines · Russell King - ARM Linux
Quoted 24 lines · Leonard Crestez
Quoted 7 lines · Thomas Garnier
On Wed, Jul 19, 2017 at 10:58 AM, Thomas Garnier <[email protected]
Quoted 6 lines
wrote:
The work pending loop can call
set_fsafteraddr_limit_user_checkremoved the_TIF_FSCHECKflag. To prevent the infinite loop, move theaddr_limit_user_checkcall at the beginning of the loop.Quoted 6 lines
Quoted 4 lines
Fixes 73ac5d6a2b6a ("arm/syscalls: Check address limit on user-mode return")
Reported-by Leonard Crestez <[email protected]>Signed-off-by Thomas Garnier <[email protected]>Any comments on this patch set?
Tested-by Leonard Crestez <[email protected]>This appears to fix the original issue of failing to boot from NFS when there are lots of alignment faults. But this is a very basic test relative to the reach of this change.
However the original patch has been in linux-next for a while and apparently nobody else noticed system calls randomly hanging on arm.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I assume maintainers need to give their opinion.
I've already stated my opinion, which is different from what Linus has requested of Thomas. IMHO, the current approach is going to keep on causing problems along the lines that I've already pointed out.
I understand. Do you think this problem apply to arm64 as well?
It's probably less of an issue for arm64 because we don't take alignment faults from the kernel and I think the perf case would resolve itself by throttling the event. However, I also don't see the advantage of doing this in the work loop as opposed to leaving it until we're actually doing the return to userspace.
I looked to see what you've done for x86, but it looks like you check/clear the flag before the work pending loop (exit_to_usermode_loop), which subsequently re-enables interrupts and exits when EXIT_TO_USERMODE_LOOP_FLAGS are all clear. Since TIF_FSCHECK isn't included in those flags, what stops it being set again by an irq and remaining set for the return to userspace?
Will
Quoted 34 lines · Will Deacon
Quoted 33 lines · Thomas Garnier
Quoted 30 lines · Russell King - ARM Linux
Quoted 17 lines · Leonard Crestez
Quoted 7 lines · Thomas Garnier
On Wed, Jul 19, 2017 at 10:58 AM, Thomas Garnier <[email protected]
Quoted 6 lines
wrote:
The work pending loop can call
set_fsafteraddr_limit_user_checkremoved the_TIF_FSCHECKflag. To prevent the infinite loop, move theaddr_limit_user_checkcall at the beginning of the loop.Quoted 6 lines
Quoted 4 lines
Fixes 73ac5d6a2b6a ("arm/syscalls: Check address limit on user-mode return")
Reported-by Leonard Crestez <[email protected]>Signed-off-by Thomas Garnier <[email protected]>Any comments on this patch set?
Tested-by Leonard Crestez <[email protected]>Quoted 8 lines
This appears to fix the original issue of failing to boot from NFS when there are lots of alignment faults. But this is a very basic test relative to the reach of this change.
However the original patch has been in linux-next for a while and apparently nobody else noticed system calls randomly hanging on arm.
I assume maintainers need to give their opinion.
I've already stated my opinion, which is different from what Linus has requested of Thomas. IMHO, the current approach is going to keep on causing problems along the lines that I've already pointed out.
Quoted 7 lines
Quoted 1 line
I understand. Do you think this problem apply to arm64 as well?
It's probably less of an issue for arm64 because we don't take alignment faults from the kernel and I think the perf case would resolve itself by throttling the event. However, I also don't see the advantage of doing this in the work loop as opposed to leaving it until we're actually doing the return to userspace.
I think the idea is doing the check as early as possible to catch any error before any additional logic.
Quoted 7 lines
I looked to see what you've done for x86, but it looks like you check/clear the flag before the work pending loop (
exit_to_usermode_loop), which subsequently re-enables interrupts and exits whenEXIT_TO_USERMODE_LOOP_FLAGSare all clear. SinceTIF_FSCHECKisn't included in those flags, what stops it being set again by an irq and remaining set for the return to userspace?
Nothing, I plan to improve the x86 logic later. I focused on ARM/ARM64 right now based on Leonard report.
For the next iteration, I plan on having an updated version of the previous implementation for ARM. I will send it soon.
Quoted 2 lines
Will
Signature · 1 line
Thomas
Russell King - ARM Linux
maintainerQuoted 10 lines · Thomas Garnier
Quoted 6 lines · Will Deacon
I looked to see what you've done for x86, but it looks like you check/clear the flag before the work pending loop (
exit_to_usermode_loop), which subsequently re-enables interrupts and exits whenEXIT_TO_USERMODE_LOOP_FLAGSare all clear. SinceTIF_FSCHECKisn't included in those flags, what stops it being set again by an irq and remaining set for the return to userspace?Nothing, I plan to improve the x86 logic later. I focused on ARM/ARM64 right now based on Leonard report.
Hmm. In this case, I'd suggest concentrating on x86 and getting the implementation correct there before porting it to other architectures.
If x86 were to check TIF_FSCHECK in the loop, and repeat until clear, would x86 also end up in these infinite loops that have been reported on ARM as well?
I strongly suggest testing the behaviour with kprobes/tracing enabled for a function called from the work pending loop, and checking how that behaves.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
Quoted 9 lines · Russell King - ARM Linux
Quoted 8 lines · Thomas Garnier
Quoted 6 lines · Will Deacon
I looked to see what you've done for x86, but it looks like you check/clear the flag before the work pending loop (
exit_to_usermode_loop), which subsequently re-enables interrupts and exits whenEXIT_TO_USERMODE_LOOP_FLAGSare all clear. SinceTIF_FSCHECKisn't included in those flags, what stops it being set again by an irq and remaining set for the return to userspace?
Quoted 5 lines
Quoted 2 lines
Nothing, I plan to improve the x86 logic later. I focused on ARM/ARM64 right now based on Leonard report.
Hmm. In this case, I'd suggest concentrating on x86 and getting the implementation correct there before porting it to other architectures.
I think the ARM architecture is different.
Quoted 4 lines
If x86 were to check
TIF_FSCHECKin the loop, and repeat until clear, would x86 also end up in these infinite loops that have been reported on ARM as well?
If for every loop set_fs was called. I think the idea is that at some point only the TIF_FSCHECK remain. I don't think x86 suffers from the same issue than ARM.
Quoted 9 lines
I strongly suggest testing the behaviour with kprobes/tracing enabled for a function called from the work pending loop, and checking how that behaves.
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
Signature · 1 line
Thomas