]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
um: work around sched_yield not yielding in time-travel mode
authorBenjamin Berg <benjamin.berg@intel.com>
Fri, 14 Mar 2025 13:08:15 +0000 (14:08 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 18 Mar 2025 10:06:20 +0000 (11:06 +0100)
sched_yield by a userspace may not actually cause scheduling in
time-travel mode as no time has passed. In the case seen it appears to
be a badly implemented userspace spinlock in ASAN. Unfortunately, with
time-travel it causes an extreme slowdown or even deadlock depending on
the kernel configuration (CONFIG_UML_MAX_USERSPACE_ITERATIONS).

Work around it by accounting time to the process whenever it executes a
sched_yield syscall.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
Link: https://patch.msgid.link/20250314130815.226872-1-benjamin@sipsolutions.net
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
arch/um/include/linux/time-internal.h
arch/um/kernel/skas/syscall.c

index b22226634ff60905d013431b7c765b60c5c1868b..138908b999d76c147cbed78d82b48c134d8c32b4 100644 (file)
@@ -83,6 +83,8 @@ extern void time_travel_not_configured(void);
 #define time_travel_del_event(...) time_travel_not_configured()
 #endif /* CONFIG_UML_TIME_TRAVEL_SUPPORT */
 
+extern unsigned long tt_extra_sched_jiffies;
+
 /*
  * Without CONFIG_UML_TIME_TRAVEL_SUPPORT this is a linker error if used,
  * which is intentional since we really shouldn't link it in that case.
index b09e85279d2b8c84487a1d7ea35bfdbf16943024..a5beaea2967ec3f74cefc564f478a401f11fe9b5 100644 (file)
@@ -31,6 +31,17 @@ void handle_syscall(struct uml_pt_regs *r)
                goto out;
 
        syscall = UPT_SYSCALL_NR(r);
+
+       /*
+        * If no time passes, then sched_yield may not actually yield, causing
+        * broken spinlock implementations in userspace (ASAN) to hang for long
+        * periods of time.
+        */
+       if ((time_travel_mode == TT_MODE_INFCPU ||
+            time_travel_mode == TT_MODE_EXTERNAL) &&
+           syscall == __NR_sched_yield)
+               tt_extra_sched_jiffies += 1;
+
        if (syscall >= 0 && syscall < __NR_syscalls) {
                unsigned long ret = EXECUTE_SYSCALL(syscall, regs);