Skip to contentSkip to conversation

um: Enable preemption in UML

PATCH Superseded [email protected] 4 participants 8 messages Sep 21, 2023 User-mode Linux (UML)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH v2 1/1 um: Enable preemption in UML

From: Anton Ivanov <[email protected]>

Preemption requires saving/restoring FPU state. This patch adds support for it using GCC intrinsics.

---
 arch/um/Kconfig                         |  1 -
 arch/um/Makefile                        |  3 +-
 arch/um/include/asm/fpu/api.h           |  4 +-
 arch/um/include/asm/processor-generic.h |  3 +
 arch/um/kernel/Makefile                 |  2 +-
 arch/um/kernel/fpu.c                    | 83 +++++++++++++++++++++++++
 arch/um/kernel/irq.c                    |  2 +
 7 files changed, 93 insertions(+), 5 deletions(-)
 create mode 100644 arch/um/kernel/fpu.c
arch/um/Kconfig +0 -1
index b5e179360534..603f5fd82293 100644
@@ -11,7 +11,6 @@ config UML
 	select ARCH_HAS_KCOV
 	select ARCH_HAS_STRNCPY_FROM_USER
 	select ARCH_HAS_STRNLEN_USER
-	select ARCH_NO_PREEMPT
 	select HAVE_ARCH_AUDITSYSCALL
 	select HAVE_ARCH_KASAN if X86_64
 	select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN
arch/um/Makefile +2 -1
index 82f05f250634..6454f735cc9a 100644
@@ -61,7 +61,8 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
 	$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap	\
 	-Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
 	-Din6addr_loopback=kernel_in6addr_loopback \
-	-Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
+	-Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr \
+	-mxsave -mxsaveopt
 
 KBUILD_RUSTFLAGS += -Crelocation-model=pie
 
arch/um/include/asm/fpu/api.h +2 -2
index 71bfd9ef3938..0094624ae9b4 100644
@@ -8,8 +8,8 @@
  * of x86 optimized copy, xor, etc routines into the
  * UML code tree. */
 
-#define kernel_fpu_begin() (void)0
-#define kernel_fpu_end() (void)0
+void kernel_fpu_begin(void);
+void kernel_fpu_end(void);
 
 static inline bool irq_fpu_usable(void)
 {
arch/um/include/asm/processor-generic.h +3 -0
index 7414154b8e9a..d5924d0e16a7 100644
@@ -44,6 +44,9 @@ struct thread_struct {
 			} cb;
 		} u;
 	} request;
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+    u8 fpu[2048] __aligned(64); /* Intel docs require xsave/xrestore area to be aligned to 16 bytes */
+#endif
 };
 
 #define INIT_THREAD \
arch/um/kernel/Makefile +1 -1
index 811188be954c..5d9fbaa544be 100644
@@ -16,7 +16,7 @@ extra-y := vmlinux.lds
 
 obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \
 	physmem.o process.o ptrace.o reboot.o sigio.o \
-	signal.o sysrq.o time.o tlb.o trap.o \
+	signal.o sysrq.o time.o tlb.o trap.o fpu.o\
 	um_arch.o umid.o maccess.o kmsg_dump.o capflags.o skas/
 obj-y += load_file.o
 
arch/um/kernel/fpu.c new file +83 -0

83 lines not on this page · raw message

arch/um/kernel/irq.c +2 -0
index 635d44606bfe..c02525da45df 100644
@@ -195,7 +195,9 @@ static void _sigio_handler(struct uml_pt_regs *regs,
 
 void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
 {
+	preempt_disable();
 	_sigio_handler(regs, irqs_suspended);
+	preempt_enable();
 }
 
 static struct irq_entry *get_irq_entry_by_fd(int fd)
Signature · 7 lines
2.30.2


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#1 lore raw
Quoted 4 lines · On 21/09/2023 10:28, [email protected] wrote:

From: Anton Ivanov <[email protected]>

Preemption requires saving/restoring FPU state. This patch adds support for it using GCC intrinsics.

Marginally slower than before

3m 03s for find /usr -type f -exec cat {} > /dev/null \;

Still, better than the non-PREEMPT 20 minutes for the same job

Tested including the use of stress: stress --cpu 16 --io 16 --hdd 16 --timeout 60

This test was making non-PREEMPT unusable. You had to wait until it completes to get it to respond to anything. PREEMPT remains usable and responsive throughout.

All in all - we have to go back and finish the CPU flags translation work as we really need working alternatives and/or borrowing the CPU stuff from the x86 tree instead of reimplementing it.

Quoted 184 lines
---
  arch/um/Kconfig                         |  1 -
  arch/um/Makefile                        |  3 +-
  arch/um/include/asm/fpu/api.h           |  4 +-
  arch/um/include/asm/processor-generic.h |  3 +
  arch/um/kernel/Makefile                 |  2 +-
  arch/um/kernel/fpu.c                    | 83 +++++++++++++++++++++++++
  arch/um/kernel/irq.c                    |  2 +
  7 files changed, 93 insertions(+), 5 deletions(-)

create mode 100644 arch/um/kernel/fpu.c

arch/um/Kconfig +0 -1
index b5e179360534..603f5fd82293 100644
@@ -11,7 +11,6 @@ config UML
  	select ARCH_HAS_KCOV
  	select ARCH_HAS_STRNCPY_FROM_USER
  	select ARCH_HAS_STRNLEN_USER
-	select ARCH_NO_PREEMPT
  	select HAVE_ARCH_AUDITSYSCALL
  	select HAVE_ARCH_KASAN if X86_64
  	select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN
arch/um/Makefile +2 -1
index 82f05f250634..6454f735cc9a 100644
@@ -61,7 +61,8 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
  	$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap	\
  	-Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
  	-Din6addr_loopback=kernel_in6addr_loopback \
-	-Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
+	-Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr \
+	-mxsave -mxsaveopt
 
  KBUILD_RUSTFLAGS += -Crelocation-model=pie
 
arch/um/include/asm/fpu/api.h +2 -2
index 71bfd9ef3938..0094624ae9b4 100644
@@ -8,8 +8,8 @@
   * of x86 optimized copy, xor, etc routines into the
   * UML code tree. */
 
-#define kernel_fpu_begin() (void)0
-#define kernel_fpu_end() (void)0
+void kernel_fpu_begin(void);
+void kernel_fpu_end(void);
 
  static inline bool irq_fpu_usable(void)
  {
arch/um/include/asm/processor-generic.h +3 -0
index 7414154b8e9a..d5924d0e16a7 100644
@@ -44,6 +44,9 @@ struct thread_struct {
  			} cb;
  		} u;
  	} request;
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+    u8 fpu[2048] __aligned(64); /* Intel docs require xsave/xrestore area to be aligned to 16 bytes */
+#endif
  };
 
  #define INIT_THREAD \
arch/um/kernel/Makefile +1 -1
index 811188be954c..5d9fbaa544be 100644
@@ -16,7 +16,7 @@ extra-y := vmlinux.lds
 
  obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \
  	physmem.o process.o ptrace.o reboot.o sigio.o \
-	signal.o sysrq.o time.o tlb.o trap.o \
+	signal.o sysrq.o time.o tlb.o trap.o fpu.o\
  	um_arch.o umid.o maccess.o kmsg_dump.o capflags.o skas/
  obj-y += load_file.o
 
arch/um/kernel/fpu.c new file +83 -0
new file mode 100644
index 000000000000..fb90da5a0227
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 Cambridge Greys Ltd
+ * Copyright (C) 2023 Red Hat Inc
+ */
+
+#include <linux/cpu.h>
+#include <linux/init.h>
+#include <asm/fpu/api.h>
+#include <asm/cpufeature.h>
+
+/*
+ * The critical section between kernel_fpu_begin() and kernel_fpu_end()
+ * is non-reentrant. It is the caller's responsibility to avoid reentrance.
+ */
+
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+static DEFINE_PER_CPU(bool, in_kernel_fpu);
+#endif
+
+/* UML knows about 387 features up to and including AVX512, tile, etc are not yet
+ * supported.
+ */
+
+#define KNOWN_387_FEATURES 0xFF
+
+
+void kernel_fpu_begin(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+	preempt_disable();
+
+	WARN_ON(this_cpu_read(in_kernel_fpu));
+
+	this_cpu_write(in_kernel_fpu, true);
+
+#ifdef CONFIG_64BIT
+	if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+		__builtin_ia32_xsaveopt64(&current->thread.fpu, KNOWN_387_FEATURES);
+	else {
+		if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+			__builtin_ia32_xsave64(&current->thread.fpu, KNOWN_387_FEATURES);
+		else
+			__builtin_ia32_fxsave64(&current->thread.fpu);
+	}
+#else
+	if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+		__builtin_ia32_xsaveopt(&current->thread.fpu, KNOWN_387_FEATURES);
+	else {
+		if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+			__builtin_ia32_xsave(&current->thread.fpu, KNOWN_387_FEATURES);
+		else
+			__builtin_ia32_fxsave(&current->thread.fpu);
+	}
+#endif
+#endif
+}
+
+EXPORT_SYMBOL_GPL(kernel_fpu_begin);
+
+void kernel_fpu_end(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+	WARN_ON(!this_cpu_read(in_kernel_fpu));
+
+#ifdef CONFIG_64BIT
+	if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE)))
+		__builtin_ia32_xrstor64(&current->thread.fpu, KNOWN_387_FEATURES);
+	else
+		__builtin_ia32_fxrstor64(&current->thread.fpu);
+#else
+	if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE)))
+		__builtin_ia32_xrstor(&current->thread.fpu, KNOWN_387_FEATURES);
+	else
+		__builtin_ia32_fxrstor(&current->thread.fpu);
+#endif
+	this_cpu_write(in_kernel_fpu, false);
+
+	preempt_enable();
+#endif
+}
+EXPORT_SYMBOL_GPL(kernel_fpu_end);
+
arch/um/kernel/irq.c +2 -0
index 635d44606bfe..c02525da45df 100644
@@ -195,7 +195,9 @@ static void _sigio_handler(struct uml_pt_regs *regs,
 
  void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
  {
+	preempt_disable();
  	_sigio_handler(regs, irqs_suspended);
+	preempt_enable();
  }
 
  static struct irq_entry *get_irq_entry_by_fd(int fd)
Signature · 7 lines
Anton R. Ivanov
https://www.kot-begemot.co.uk/

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
maintainer
#2 lore raw
In reply to [email protected]

Hi,

Haven't chimed in here before, but thanks for looking at this! I actually really wanted at least the things you get for debug from this in the past, so much appreciated.

I think I actually tried a simpler approach and it kind of even worked, but my userspace likely has very little FPU usage.

Quoted 3 lines

+/* UML knows about 387 features up to and including AVX512, tile, etc are not yet
+ * supported.
+ */

Do you ensure that somehow? Warn if it's there at least? I may have missed that.

Or is it just for the saving? But what if you don't save enough and the host CPU has more?

arch/um/kernel/fpu.c line 30

Quoted 3 lines
arch/um/kernel/fpu.c new file +3 -0
+void kernel_fpu_begin(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)

maybe leave it as an inline in case it'd be empty, i.e. neither of these are defined?

Quoted 5 lines
arch/um/kernel/fpu.c new file +5 -0
+	preempt_disable();
+
+	WARN_ON(this_cpu_read(in_kernel_fpu));
+
+	this_cpu_write(in_kernel_fpu, true);

arch/um/kernel/fpu.c line 45

Quoted 10 lines
arch/um/kernel/fpu.c new file +10 -0
+
+#ifdef CONFIG_64BIT
+	if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+		__builtin_ia32_xsaveopt64(&current->thread.fpu, KNOWN_387_FEATURES);
+	else {
+		if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+			__builtin_ia32_xsave64(&current->thread.fpu, KNOWN_387_FEATURES);
+		else
+			__builtin_ia32_fxsave64(&current->thread.fpu);
+	}

nit: you could make all of these else if chains, and avoid the braces:

if (likely(...))

	...
else if (cpu_has(...))
	...
else
	...
Quoted 1 line

+void kernel_fpu_end(void)

same comments as above apply here.

arch/um/kernel/irq.c static void _sigio_handler(struct uml_pt_regs *regs, · line 200

Quoted 6 lines

void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) {

arch/um/kernel/irq.c +2 -0
+	preempt_disable();
 	_sigio_handler(regs, irqs_suspended);
+	preempt_enable();

I may have to look at those time-travel bits here :)

Thanks,
johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

author maintainer
#3 lore raw
Quoted 10 lines · Johannes Berg

Hi,

Haven't chimed in here before, but thanks for looking at this! I actually really wanted at least the things you get for debug from this in the past, so much appreciated.

I think I actually tried a simpler approach and it kind of even worked, but my userspace likely has very little FPU usage.

Quoted 6 lines
Quoted 3 lines

+/* UML knows about 387 features up to and including AVX512, tile, etc are not yet
+ * supported.
+ */

Do you ensure that somehow? Warn if it's there at least? I may have missed that.

We can if we want. We can just cut-off feature reflection into the kernel in the setup. Presently it reflects all features. That can be filtered if we want to. For example - x86 has boot flags to disable xrestore and xrestoreopt

Quoted 3 lines

Or is it just for the saving? But what if you don't save enough and the host CPU has more?

This is just for the saving. AFAIK no linux module touches _TILE and the other recent fancy stuff. The host kernel source looks that way.

Quoted 40 lines

arch/um/kernel/fpu.c line 30

Quoted 5 lines
arch/um/kernel/fpu.c new file +3 -0
+void kernel_fpu_begin(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)

maybe leave it as an inline in case it'd be empty, i.e. neither of these are defined?

Quoted 5 lines
arch/um/kernel/fpu.c new file +5 -0
+	preempt_disable();
+
+	WARN_ON(this_cpu_read(in_kernel_fpu));
+
+	this_cpu_write(in_kernel_fpu, true);

arch/um/kernel/fpu.c line 45

Quoted 10 lines
arch/um/kernel/fpu.c new file +10 -0
+
+#ifdef CONFIG_64BIT
+	if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+		__builtin_ia32_xsaveopt64(&current->thread.fpu, KNOWN_387_FEATURES);
+	else {
+		if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+			__builtin_ia32_xsave64(&current->thread.fpu, KNOWN_387_FEATURES);
+		else
+			__builtin_ia32_fxsave64(&current->thread.fpu);
+	}

nit: you could make all of these else if chains, and avoid the braces:

if (likely(...))

	...
else if (cpu_has(...))
	...
else
	...
Quoted 1 line

+void kernel_fpu_end(void)

same comments as above apply here.

Quoted 8 lines

arch/um/kernel/irq.c static void _sigio_handler(struct uml_pt_regs *regs, · line 200

Quoted 6 lines
  void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
  {
arch/um/kernel/irq.c +2 -0
+	preempt_disable();
  	_sigio_handler(regs, irqs_suspended);
+	preempt_enable();

I may have to look at those time-travel bits here :)

Yes. I was going to ask you to double check if they all work as intended.

Basic use seems without tt seems OK.

Quoted 9 lines

Thanks,
johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

Signature · 8 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
author maintainer
#4 lore raw
Quoted 25 lines · Anton Ivanov
Quoted 10 lines · Johannes Berg

Hi,

Haven't chimed in here before, but thanks for looking at this! I actually really wanted at least the things you get for debug from this in the past, so much appreciated.

I think I actually tried a simpler approach and it kind of even worked, but my userspace likely has very little FPU usage.

Quoted 6 lines
Quoted 3 lines

+/* UML knows about 387 features up to and including AVX512, tile, etc are not yet
+ * supported.
+ */

Do you ensure that somehow? Warn if it's there at least? I may have missed that.

We can if we want. We can just cut-off feature reflection into the kernel in the setup. Presently it reflects all features. That can be filtered if we want to. For example - x86 has boot flags to disable xrestore and xrestoreopt

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

Or is it just for the saving? But what if you don't save enough and the host CPU has more?

This is just for the saving. AFAIK no linux module touches _TILE and the other recent fancy stuff. The host kernel source looks that way.

This brings back the question of

1. Alternatives (this has become even more nightmarish since I last looked at it)
2. Static branch by key - this actually looks doable and is used by nearly all crypto, I may look at it when I have some free time.

Quoted 64 lines
Quoted 41 lines

arch/um/kernel/fpu.c line 30

Quoted 6 lines
arch/um/kernel/fpu.c new file +3 -0
+void kernel_fpu_begin(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)

maybe leave it as an inline in case it'd be empty, i.e. neither of these are defined?

Quoted 5 lines

+    preempt_disable();

arch/um/kernel/fpu.c new file +4 -0
+
+    WARN_ON(this_cpu_read(in_kernel_fpu));
+
+    this_cpu_write(in_kernel_fpu, true);

arch/um/kernel/fpu.c line 45

Quoted 10 lines
arch/um/kernel/fpu.c new file +10 -0
+
+#ifdef CONFIG_64BIT
+    if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+        __builtin_ia32_xsaveopt64(&current->thread.fpu, KNOWN_387_FEATURES);
+    else {
+        if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+            __builtin_ia32_xsave64(&current->thread.fpu, KNOWN_387_FEATURES);
+        else
+            __builtin_ia32_fxsave64(&current->thread.fpu);
+    }

nit: you could make all of these else if chains, and avoid the braces:

if (likely(...))
    ...
else if (cpu_has(...))
    ...
else
    ...

Quoted 1 line

+void kernel_fpu_end(void)

same comments as above apply here.

Quoted 8 lines
Quoted 6 lines

  void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) {
+    preempt_disable();
      _sigio_handler(regs, irqs_suspended);
+    preempt_enable();

I may have to look at those time-travel bits here :)

Yes. I was going to ask you to double check if they all work as intended.

Basic use seems without tt seems OK.

Quoted 9 lines

Thanks,
johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

Signature · 8 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#5 lore raw
In reply to [email protected]
Quoted 111 lines · On Thu, Sep 21, 2023 at 05:28, [email protected] wrote:

From: Anton Ivanov [email protected]

Preemption requires saving/restoring FPU state. This patch adds support for it using GCC intrinsics.

---
arch/um/Kconfig | 1 -
arch/um/Makefile | 3 +- arch/um/include/asm/fpu/api.h | 4 +- arch/um/include/asm/processor-generic.h | 3 + arch/um/kernel/Makefile | 2 +- arch/um/kernel/fpu.c | 83 +++++++++++++++++++++++++ arch/um/kernel/irq.c | 2 +

7 files changed, 93 insertions(+), 5 deletions(-)

create mode 100644 arch/um/kernel/fpu.c

arch/um/Kconfig +0 -0
index b5e179360534..603f5fd82293 100644
@@ -11,7 +11,6 @@ config UML

select ARCH_HAS_KCOV
select ARCH_HAS_STRNCPY_FROM_USER
select ARCH_HAS_STRNLEN_USER
- select ARCH_NO_PREEMPT
select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_KASAN if X86_64
select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN

arch/um/Makefile +2 -3
index 82f05f250634..6454f735cc9a 100644
@@ -61,7 +61,8 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
 $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
-Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
-Din6addr_loopback=kernel_in6addr_loopback \
- -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
+ -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr \
+ -mxsave -mxsaveopt
 

KBUILD_RUSTFLAGS += -Crelocation-model=pie

arch/um/include/asm/fpu/api.h +2 -2
index 71bfd9ef3938..0094624ae9b4 100644
@@ -8,8 +8,8 @@
 * of x86 optimized copy, xor, etc routines into the
 * UML code tree. /
 
-#define kernel_fpu_begin() (void)0
-#define kernel_fpu_end() (void)0
+void kernel_fpu_begin(void);
+void kernel_fpu_end(void);
 
 static inline bool irq_fpu_usable(void)
 {
arch/um/include/asm/processor-generic.h +3 -0
index 7414154b8e9a..d5924d0e16a7 100644
@@ -44,6 +44,9 @@ struct thread_struct {
 } cb;
 } u;
 } request;
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+ u8 fpu[2048] __aligned(64); / Intel docs require xsave/xrestore area to be aligned to 16 bytes /
+#endif
 };
 
 #define INIT_THREAD \
arch/um/kernel/Makefile +1 -1
index 811188be954c..5d9fbaa544be 100644
@@ -16,7 +16,7 @@ extra-y := vmlinux.lds
 
 obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \
 physmem.o process.o ptrace.o reboot.o sigio.o \
- signal.o sysrq.o time.o tlb.o trap.o \
+ signal.o sysrq.o time.o tlb.o trap.o fpu.o\

um_arch.o umid.o maccess.o kmsg_dump.o capflags.o skas/ obj-y += load_file.o

arch/um/kernel/fpu.c new file +13 -0
new file mode 100644
index 000000000000..fb90da5a0227
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/
+ * Copyright (C) 2023 Cambridge Greys Ltd
+ * Copyright (C) 2023 Red Hat Inc
+ */
+
+#include <linux/cpu.h>
 
+#include <linux/init.h>
 
+#include <asm/fpu/api.h>
 
+#include <asm/cpufeature.h>
 
+
+/*
+ * The critical section between kernel_fpu_begin() and kernel_fpu_end()

arch/um/kernel/fpu.c line 23

Quoted 10 lines
arch/um/kernel/fpu.c new file +10 -0
+ * is non-reentrant. It is the caller's responsibility to avoid reentrance.
+ /
+
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+static DEFINE_PER_CPU(bool, in_kernel_fpu);
+#endif
+
+/ UML knows about 387 features up to and including AVX512, tile, etc are not yet
+ * supported.
+ */

Features that are not supported probably shouldn't be reflected, including if the appropiate xsave instruction isn't available.

Quoted 30 lines
arch/um/kernel/fpu.c new file +26 -0
+
+#define KNOWN_387_FEATURES 0xFF
+
+
+void kernel_fpu_begin(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+ preempt_disable();
+
+ WARN_ON(this_cpu_read(in_kernel_fpu));
+
+ this_cpu_write(in_kernel_fpu, true);
+
+#ifdef CONFIG_64BIT
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+ __builtin_ia32_xsaveopt64(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else {
+ if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+ __builtin_ia32_xsave64(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else
+ __builtin_ia32_fxsave64(&current->thread.fpu);
 
+ }
+#else
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+ __builtin_ia32_xsaveopt(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else {

arch/um/kernel/fpu.c line 57

Quoted 10 lines
arch/um/kernel/fpu.c new file +8 -0
+ if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+ __builtin_ia32_xsave(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else
+ __builtin_ia32_fxsave(&current->thread.fpu);
 
+ }
+#endif
+#endif
+}

I would keep kernel_fpu_begin() as an empty macro if !defined(PREEMPT) && !defined(PREEMPT_VOLUNTARY) to avoid calling empty functions, then only compile fpu.c when you need PREEMPT behavior. This has the added bonus of removing a level of #if in this function.

I agree with Johannes about the if-else chains.

The if-else chains would be a good use for alternatives, but we know how that works with UML.

And what's the reasoning behind making xsaveopt support likely, but not xsave in the fallback path?

Quoted 20 lines
arch/um/kernel/fpu.c new file +17 -0
+
+EXPORT_SYMBOL_GPL(kernel_fpu_begin);
+
+void kernel_fpu_end(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+ WARN_ON(!this_cpu_read(in_kernel_fpu));
+
+#ifdef CONFIG_64BIT
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE)))
+ __builtin_ia32_xrstor64(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else
+ __builtin_ia32_fxrstor64(&current->thread.fpu);
 
+#else
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE)))
+ __builtin_ia32_xrstor(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else

arch/um/kernel/fpu.c line 83

Quoted 10 lines
arch/um/kernel/fpu.c new file +9 -0
+ __builtin_ia32_fxrstor(&current->thread.fpu);
 
+#endif
+ this_cpu_write(in_kernel_fpu, false);
+
+ preempt_enable();
+#endif
+}
+EXPORT_SYMBOL_GPL(kernel_fpu_end);
+

See above, minus the likely() part.

Quoted 15 lines
arch/um/kernel/irq.c +2 -1
index 635d44606bfe..c02525da45df 100644
@@ -195,7 +195,9 @@ static void _sigio_handler(struct uml_pt_regs *regs,
 
 void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
 {
+ preempt_disable();
 _sigio_handler(regs, irqs_suspended);
+ preempt_enable();
 }
 
 static struct irq_entry *get_irq_entry_by_fd(int fd)
--
Quoted 1 line

2.30.2

As a reminder, compilations with debug.config fail with the following error:

---
In file included from arch/um/kernel/irq.c:19:
./arch/um/include/shared/kern_util.h:53:12: error: conflicting types for ‘__cant_sleep’; have ‘int(void)’

   53 | extern int __cant_sleep(void);
      |            ^~~~~~~~~~~~
In file included from ./include/linux/cpumask.h:10,
                 from arch/um/kernel/irq.c:10:
./include/linux/kernel.h:129:13: note: previous declaration of ‘__cant_sleep’ with type ‘void(const char *, int,  int)’
  129 | extern void __cant_sleep(const char *file, int line, int preempt_offset);
      |             ^~~~~~~~~~~~

---

Cheers,
Peter

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

author maintainer
#6 lore raw
Quoted 108 lines · Peter Lafreniere
Quoted 107 lines · On Thu, Sep 21, 2023 at 05:28, [email protected] wrote:

From: Anton Ivanov [email protected]

Preemption requires saving/restoring FPU state. This patch adds support for it using GCC intrinsics.

---
arch/um/Kconfig | 1 -
arch/um/Makefile | 3 +- arch/um/include/asm/fpu/api.h | 4 +- arch/um/include/asm/processor-generic.h | 3 + arch/um/kernel/Makefile | 2 +- arch/um/kernel/fpu.c | 83 +++++++++++++++++++++++++ arch/um/kernel/irq.c | 2 +

7 files changed, 93 insertions(+), 5 deletions(-)

create mode 100644 arch/um/kernel/fpu.c

arch/um/Kconfig +0 -0
index b5e179360534..603f5fd82293 100644
@@ -11,7 +11,6 @@ config UML

select ARCH_HAS_KCOV
select ARCH_HAS_STRNCPY_FROM_USER
select ARCH_HAS_STRNLEN_USER
- select ARCH_NO_PREEMPT
select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_KASAN if X86_64
select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN

arch/um/Makefile +2 -3
index 82f05f250634..6454f735cc9a 100644
@@ -61,7 +61,8 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
 $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
-Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
-Din6addr_loopback=kernel_in6addr_loopback \
- -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
+ -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr \
+ -mxsave -mxsaveopt
 

KBUILD_RUSTFLAGS += -Crelocation-model=pie

arch/um/include/asm/fpu/api.h +2 -2
index 71bfd9ef3938..0094624ae9b4 100644
@@ -8,8 +8,8 @@
 * of x86 optimized copy, xor, etc routines into the
 * UML code tree. /
 
-#define kernel_fpu_begin() (void)0
-#define kernel_fpu_end() (void)0
+void kernel_fpu_begin(void);
+void kernel_fpu_end(void);
 
 static inline bool irq_fpu_usable(void)
 {
arch/um/include/asm/processor-generic.h +3 -0
index 7414154b8e9a..d5924d0e16a7 100644
@@ -44,6 +44,9 @@ struct thread_struct {
 } cb;
 } u;
 } request;
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+ u8 fpu[2048] __aligned(64); / Intel docs require xsave/xrestore area to be aligned to 16 bytes /
+#endif
 };
 
 #define INIT_THREAD \
arch/um/kernel/Makefile +1 -1
index 811188be954c..5d9fbaa544be 100644
@@ -16,7 +16,7 @@ extra-y := vmlinux.lds
 
 obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \
 physmem.o process.o ptrace.o reboot.o sigio.o \
- signal.o sysrq.o time.o tlb.o trap.o \
+ signal.o sysrq.o time.o tlb.o trap.o fpu.o\

um_arch.o umid.o maccess.o kmsg_dump.o capflags.o skas/ obj-y += load_file.o

arch/um/kernel/fpu.c new file +10 -0
new file mode 100644
index 000000000000..fb90da5a0227
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/
+ * Copyright (C) 2023 Cambridge Greys Ltd
+ * Copyright (C) 2023 Red Hat Inc
+ */
+
+#include <linux/cpu.h>
 
+#include <linux/init.h>
 
+#include <asm/fpu/api.h>
 
+#include <asm/cpufeature.h>
Quoted 15 lines

arch/um/kernel/fpu.c line 23

Quoted 13 lines
arch/um/kernel/fpu.c new file +13 -0
+
+/*
+ * The critical section between kernel_fpu_begin() and kernel_fpu_end()
+ * is non-reentrant. It is the caller's responsibility to avoid reentrance.
+ /
+
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+static DEFINE_PER_CPU(bool, in_kernel_fpu);
+#endif
+
+/ UML knows about 387 features up to and including AVX512, tile, etc are not yet
+ * supported.
+ */

Features that are not supported probably shouldn't be reflected, including if the appropiate xsave instruction isn't available.

They are OK to use by userspace and the same source is used for /proc/cpuinfo which can be used by userspace to see all available features.

Userspace task switching in UML uses a different mechanism for save/restore which will preserve them (ptrace REGs).

Quoted 37 lines
Quoted 37 lines
arch/um/kernel/fpu.c new file +30 -0
+
+#define KNOWN_387_FEATURES 0xFF
+
+
+void kernel_fpu_begin(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+ preempt_disable();
+
+ WARN_ON(this_cpu_read(in_kernel_fpu));
+
+ this_cpu_write(in_kernel_fpu, true);
+
+#ifdef CONFIG_64BIT
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+ __builtin_ia32_xsaveopt64(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else {
+ if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+ __builtin_ia32_xsave64(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else
+ __builtin_ia32_fxsave64(&current->thread.fpu);
 
+ }
+#else
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+ __builtin_ia32_xsaveopt(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else {
+ if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+ __builtin_ia32_xsave(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else
+ __builtin_ia32_fxsave(&current->thread.fpu);
Quoted 8 lines

arch/um/kernel/fpu.c line 57

Quoted 4 lines

+ }

arch/um/kernel/fpu.c new file +3 -0
+#endif
+#endif
+}

I would keep kernel_fpu_begin() as an empty macro if !defined(PREEMPT) && !defined(PREEMPT_VOLUNTARY) to avoid calling empty functions, then only compile fpu.c when you need PREEMPT behavior. This has the added bonus of removing a level of #if in this function.

Sure. We can. IMHO the compiler will inline it and optimize it out.

Quoted 8 lines

I agree with Johannes about the if-else chains.

The if-else chains would be a good use for alternatives, but we know how that works with UML.

And what's the reasoning behind making xsaveopt support likely, but not xsave in the fallback path?

xsaveopt has been around for what? 10+ years now? That is likely :) Very likely.

Sure we can put a likely on the following xsave. If you are hitting that, you are on a pre-2011 CPU.

Quoted 54 lines
Quoted 21 lines
arch/um/kernel/fpu.c new file +17 -0
+
+EXPORT_SYMBOL_GPL(kernel_fpu_begin);
+
+void kernel_fpu_end(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+ WARN_ON(!this_cpu_read(in_kernel_fpu));
+
+#ifdef CONFIG_64BIT
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE)))
+ __builtin_ia32_xrstor64(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else
+ __builtin_ia32_fxrstor64(&current->thread.fpu);
 
+#else
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE)))
+ __builtin_ia32_xrstor(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else

arch/um/kernel/fpu.c line 83

Quoted 10 lines
arch/um/kernel/fpu.c new file +9 -0
+ __builtin_ia32_fxrstor(&current->thread.fpu);
 
+#endif
+ this_cpu_write(in_kernel_fpu, false);
+
+ preempt_enable();
+#endif
+}
+EXPORT_SYMBOL_GPL(kernel_fpu_end);
+

See above, minus the likely() part.

Quoted 15 lines
arch/um/kernel/irq.c +2 -1
index 635d44606bfe..c02525da45df 100644
@@ -195,7 +195,9 @@ static void _sigio_handler(struct uml_pt_regs *regs,
 
 void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
 {
+ preempt_disable();
 _sigio_handler(regs, irqs_suspended);
+ preempt_enable();
 }
 
 static struct irq_entry *get_irq_entry_by_fd(int fd)
--
Quoted 1 line

2.30.2

As a reminder, compilations with debug.config fail with the following error:

---
In file included from arch/um/kernel/irq.c:19:
./arch/um/include/shared/kern_util.h:53:12: error: conflicting types for ‘__cant_sleep’; have ‘int(void)’

Quoted 6 lines
    53 | extern int __cant_sleep(void);
       |            ^~~~~~~~~~~~
In file included from ./include/linux/cpumask.h:10,
                  from arch/um/kernel/irq.c:10:

./include/linux/kernel.h:129:13: note: previous declaration of ‘__cant_sleep’ with type ‘void(const char *, int, int)’
129 | extern void __cant_sleep(const char *file, int line, int preempt_offset);

OK. Will look into this one. This looks like a bug in the first place.

Quoted 7 lines
       |             ^~~~~~~~~~~~

---

Cheers,
Peter

Signature · 9 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
author maintainer
#7 lore raw
In reply to Peter Lafreniere
Quoted 235 lines · Peter Lafreniere
Quoted 111 lines · On Thu, Sep 21, 2023 at 05:28, [email protected] wrote:

From: Anton Ivanov [email protected]

Preemption requires saving/restoring FPU state. This patch adds support for it using GCC intrinsics.

---
arch/um/Kconfig | 1 -
arch/um/Makefile | 3 +- arch/um/include/asm/fpu/api.h | 4 +- arch/um/include/asm/processor-generic.h | 3 + arch/um/kernel/Makefile | 2 +- arch/um/kernel/fpu.c | 83 +++++++++++++++++++++++++ arch/um/kernel/irq.c | 2 +

7 files changed, 93 insertions(+), 5 deletions(-)

create mode 100644 arch/um/kernel/fpu.c

arch/um/Kconfig +0 -0
index b5e179360534..603f5fd82293 100644
@@ -11,7 +11,6 @@ config UML

select ARCH_HAS_KCOV
select ARCH_HAS_STRNCPY_FROM_USER
select ARCH_HAS_STRNLEN_USER
- select ARCH_NO_PREEMPT
select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_KASAN if X86_64
select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN

arch/um/Makefile +2 -3
index 82f05f250634..6454f735cc9a 100644
@@ -61,7 +61,8 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
 $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
-Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
-Din6addr_loopback=kernel_in6addr_loopback \
- -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
+ -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr \
+ -mxsave -mxsaveopt
 

KBUILD_RUSTFLAGS += -Crelocation-model=pie

arch/um/include/asm/fpu/api.h +2 -2
index 71bfd9ef3938..0094624ae9b4 100644
@@ -8,8 +8,8 @@
 * of x86 optimized copy, xor, etc routines into the
 * UML code tree. /
 
-#define kernel_fpu_begin() (void)0
-#define kernel_fpu_end() (void)0
+void kernel_fpu_begin(void);
+void kernel_fpu_end(void);
 
 static inline bool irq_fpu_usable(void)
 {
arch/um/include/asm/processor-generic.h +3 -0
index 7414154b8e9a..d5924d0e16a7 100644
@@ -44,6 +44,9 @@ struct thread_struct {
 } cb;
 } u;
 } request;
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+ u8 fpu[2048] __aligned(64); / Intel docs require xsave/xrestore area to be aligned to 16 bytes /
+#endif
 };
 
 #define INIT_THREAD \
arch/um/kernel/Makefile +1 -1
index 811188be954c..5d9fbaa544be 100644
@@ -16,7 +16,7 @@ extra-y := vmlinux.lds
 
 obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \
 physmem.o process.o ptrace.o reboot.o sigio.o \
- signal.o sysrq.o time.o tlb.o trap.o \
+ signal.o sysrq.o time.o tlb.o trap.o fpu.o\

um_arch.o umid.o maccess.o kmsg_dump.o capflags.o skas/ obj-y += load_file.o

arch/um/kernel/fpu.c new file +13 -0
new file mode 100644
index 000000000000..fb90da5a0227
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/
+ * Copyright (C) 2023 Cambridge Greys Ltd
+ * Copyright (C) 2023 Red Hat Inc
+ */
+
+#include <linux/cpu.h>
 
+#include <linux/init.h>
 
+#include <asm/fpu/api.h>
 
+#include <asm/cpufeature.h>
 
+
+/*
+ * The critical section between kernel_fpu_begin() and kernel_fpu_end()

arch/um/kernel/fpu.c line 23

Quoted 10 lines
arch/um/kernel/fpu.c new file +10 -0
+ * is non-reentrant. It is the caller's responsibility to avoid reentrance.
+ /
+
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+static DEFINE_PER_CPU(bool, in_kernel_fpu);
+#endif
+
+/ UML knows about 387 features up to and including AVX512, tile, etc are not yet
+ * supported.
+ */

Features that are not supported probably shouldn't be reflected, including if the appropiate xsave instruction isn't available.

Quoted 30 lines
arch/um/kernel/fpu.c new file +26 -0
+
+#define KNOWN_387_FEATURES 0xFF
+
+
+void kernel_fpu_begin(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+ preempt_disable();
+
+ WARN_ON(this_cpu_read(in_kernel_fpu));
+
+ this_cpu_write(in_kernel_fpu, true);
+
+#ifdef CONFIG_64BIT
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+ __builtin_ia32_xsaveopt64(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else {
+ if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+ __builtin_ia32_xsave64(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else
+ __builtin_ia32_fxsave64(&current->thread.fpu);
 
+ }
+#else
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVEOPT)))
+ __builtin_ia32_xsaveopt(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else {

arch/um/kernel/fpu.c line 57

Quoted 10 lines
arch/um/kernel/fpu.c new file +8 -0
+ if (cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE))
+ __builtin_ia32_xsave(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else
+ __builtin_ia32_fxsave(&current->thread.fpu);
 
+ }
+#endif
+#endif
+}

I would keep kernel_fpu_begin() as an empty macro if !defined(PREEMPT) && !defined(PREEMPT_VOLUNTARY) to avoid calling empty functions, then only compile fpu.c when you need PREEMPT behavior. This has the added bonus of removing a level of #if in this function.

I agree with Johannes about the if-else chains.

The if-else chains would be a good use for alternatives, but we know how that works with UML.

And what's the reasoning behind making xsaveopt support likely, but not xsave in the fallback path?

Quoted 20 lines
arch/um/kernel/fpu.c new file +17 -0
+
+EXPORT_SYMBOL_GPL(kernel_fpu_begin);
+
+void kernel_fpu_end(void)
+{
+#if defined(PREEMPT) || defined(PREEMPT_VOLUNTRARY)
+ WARN_ON(!this_cpu_read(in_kernel_fpu));
+
+#ifdef CONFIG_64BIT
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE)))
+ __builtin_ia32_xrstor64(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else
+ __builtin_ia32_fxrstor64(&current->thread.fpu);
 
+#else
+ if (likely(cpu_has(&boot_cpu_data, X86_FEATURE_XSAVE)))
+ __builtin_ia32_xrstor(&current->thread.fpu, KNOWN_387_FEATURES);
 
+ else

arch/um/kernel/fpu.c line 83

Quoted 10 lines
arch/um/kernel/fpu.c new file +9 -0
+ __builtin_ia32_fxrstor(&current->thread.fpu);
 
+#endif
+ this_cpu_write(in_kernel_fpu, false);
+
+ preempt_enable();
+#endif
+}
+EXPORT_SYMBOL_GPL(kernel_fpu_end);
+

See above, minus the likely() part.

Quoted 15 lines
arch/um/kernel/irq.c +2 -1
index 635d44606bfe..c02525da45df 100644
@@ -195,7 +195,9 @@ static void _sigio_handler(struct uml_pt_regs *regs,
 
 void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
 {
+ preempt_disable();
 _sigio_handler(regs, irqs_suspended);
+ preempt_enable();
 }
 
 static struct irq_entry *get_irq_entry_by_fd(int fd)
--
Quoted 1 line

2.30.2

As a reminder, compilations with debug.config fail with the following error:

---
In file included from arch/um/kernel/irq.c:19:
./arch/um/include/shared/kern_util.h:53:12: error: conflicting types for ‘__cant_sleep’; have ‘int(void)’

Quoted 8 lines
    53 | extern int __cant_sleep(void);
       |            ^~~~~~~~~~~~
In file included from ./include/linux/cpumask.h:10,
                  from arch/um/kernel/irq.c:10:
./include/linux/kernel.h:129:13: note: previous declaration of ‘__cant_sleep’ with type ‘void(const char *, int,  int)’
   129 | extern void __cant_sleep(const char *file, int line, int preempt_offset);
       |             ^~~~~~~~~~~~

---

This is a bug - we ended up with a name clash. This will need to be fixed separately. Patch shortly.

Quoted 9 lines

Cheers,
Peter

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

Signature · 8 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um