Skip to content

Commit 381d2f9

Browse files
jmberg-intelrichardweinberger
authored andcommitted
um: fix time-travel syscall scheduling hack
The schedule() call there really never did anything at least since the introduction of the EEVDF scheduler, but now I found a case where we permanently hang in a loop of -ERESTARTNOINTR (due to locking.) Work around it by making any syscalls with error return take time (and then schedule after) so we cannot hang in such a loop forever. Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent ae0dc67 commit 381d2f9

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

arch/um/kernel/skas/syscall.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,13 @@
1212
#include <sysdep/syscalls.h>
1313
#include <linux/time-internal.h>
1414
#include <asm/unistd.h>
15+
#include <asm/delay.h>
1516

1617
void handle_syscall(struct uml_pt_regs *r)
1718
{
1819
struct pt_regs *regs = container_of(r, struct pt_regs, regs);
1920
int syscall;
2021

21-
/*
22-
* If we have infinite CPU resources, then make every syscall also a
23-
* preemption point, since we don't have any other preemption in this
24-
* case, and kernel threads would basically never run until userspace
25-
* went to sleep, even if said userspace interacts with the kernel in
26-
* various ways.
27-
*/
28-
if (time_travel_mode == TT_MODE_INFCPU ||
29-
time_travel_mode == TT_MODE_EXTERNAL)
30-
schedule();
31-
3222
/* Initialize the syscall number and default return value. */
3323
UPT_SYSCALL_NR(r) = PT_SYSCALL_NR(r->gp);
3424
PT_REGS_SET_SYSCALL_RETURN(regs, -ENOSYS);
@@ -41,9 +31,25 @@ void handle_syscall(struct uml_pt_regs *r)
4131
goto out;
4232

4333
syscall = UPT_SYSCALL_NR(r);
44-
if (syscall >= 0 && syscall < __NR_syscalls)
45-
PT_REGS_SET_SYSCALL_RETURN(regs,
46-
EXECUTE_SYSCALL(syscall, regs));
34+
if (syscall >= 0 && syscall < __NR_syscalls) {
35+
unsigned long ret = EXECUTE_SYSCALL(syscall, regs);
36+
37+
PT_REGS_SET_SYSCALL_RETURN(regs, ret);
38+
39+
/*
40+
* An error value here can be some form of -ERESTARTSYS
41+
* and then we'd just loop. Make any error syscalls take
42+
* some time, so that it won't just loop if something is
43+
* not ready, and hopefully other things will make some
44+
* progress.
45+
*/
46+
if (IS_ERR_VALUE(ret) &&
47+
(time_travel_mode == TT_MODE_INFCPU ||
48+
time_travel_mode == TT_MODE_EXTERNAL)) {
49+
um_udelay(1);
50+
schedule();
51+
}
52+
}
4753

4854
out:
4955
syscall_trace_leave(regs);

0 commit comments

Comments
 (0)