Skip to contentSkip to conversation

x86/xen: simplify sysenter and syscall setup

PATCH Superseded Juergen Gross 3 participants 5 messages Oct 20, 2022 – Oct 21, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Juergen Gross

author maintainer
#0 lore raw

PATCH 1/1 x86/xen: simplify sysenter and syscall setup

xen_enable_sysenter() and xen_enable_syscall() can be simplified a lot.

---
 arch/x86/xen/setup.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
arch/x86/xen/setup.c +6 -17
index cfa99e8f054b..0f33ed6d3a7b 100644
@@ -910,17 +910,9 @@ static int register_callback(unsigned type, const void *func)
 
 void xen_enable_sysenter(void)
 {
-	int ret;
-	unsigned sysenter_feature;
-
-	sysenter_feature = X86_FEATURE_SYSENTER32;
-
-	if (!boot_cpu_has(sysenter_feature))
-		return;
-
-	ret = register_callback(CALLBACKTYPE_sysenter, xen_entry_SYSENTER_compat);
-	if(ret != 0)
-		setup_clear_cpu_cap(sysenter_feature);
+	if (boot_cpu_has(X86_FEATURE_SYSENTER32) &&
+	    register_callback(CALLBACKTYPE_sysenter, xen_entry_SYSENTER_compat))
+		setup_clear_cpu_cap(X86_FEATURE_SYSENTER32);
 }
 
 void xen_enable_syscall(void)
@@ -934,12 +926,9 @@ void xen_enable_syscall(void)
 		   mechanism for syscalls. */
 	}
 
-	if (boot_cpu_has(X86_FEATURE_SYSCALL32)) {
-		ret = register_callback(CALLBACKTYPE_syscall32,
-					xen_entry_SYSCALL_compat);
-		if (ret != 0)
-			setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
-	}
+	if (boot_cpu_has(X86_FEATURE_SYSCALL32) &&
+	    register_callback(CALLBACKTYPE_syscall32, xen_entry_SYSCALL_compat))
+		setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
 }
 
 static void __init xen_pvmmu_arch_setup(void)
Signature · 1 line
2.35.3
maintainer
#1 lore raw
Quoted 17 lines · Juergen Gross

xen_enable_sysenter() and xen_enable_syscall() can be simplified a lot.

---
 arch/x86/xen/setup.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
arch/x86/xen/setup.c +0 -2
index cfa99e8f054b..0f33ed6d3a7b 100644
@@ -910,17 +910,9 @@ static int register_callback(unsigned type, const void *func)
 
 void xen_enable_sysenter(void)
 {
-	int ret;
-	unsigned sysenter_feature;

arch/x86/xen/setup.c static int register_callback(unsigned type, const void *func) · line 913

Quoted 10 lines
arch/x86/xen/setup.c +1 -9
-
-	sysenter_feature = X86_FEATURE_SYSENTER32;
-
-	if (!boot_cpu_has(sysenter_feature))
-		return;
-
-	ret = register_callback(CALLBACKTYPE_sysenter, xen_entry_SYSENTER_compat);
-	if(ret != 0)
-		setup_clear_cpu_cap(sysenter_feature);
+	if (boot_cpu_has(X86_FEATURE_SYSENTER32) &&

Can you switch that and below to cpu_feature_enabled() while at it, pls?

arch/x86/xen/setup.c void xen_enable_syscall(void) · line 929

Quoted 1 line
arch/x86/xen/setup.c +1 -0
+	if (boot_cpu_has(X86_FEATURE_SYSCALL32) &&
	^^^^^^^^^^^^^^^^^^

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#2 lore raw
Quoted 31 lines · Borislav Petkov
Quoted 17 lines · Juergen Gross

xen_enable_sysenter() and xen_enable_syscall() can be simplified a lot.

---
  arch/x86/xen/setup.c | 23 ++++++-----------------
  1 file changed, 6 insertions(+), 17 deletions(-)
arch/x86/xen/setup.c +0 -2
index cfa99e8f054b..0f33ed6d3a7b 100644
@@ -910,17 +910,9 @@ static int register_callback(unsigned type, const void *func)
 
  void xen_enable_sysenter(void)
  {
-	int ret;
-	unsigned sysenter_feature;

arch/x86/xen/setup.c static int register_callback(unsigned type, const void *func) · line 913

Quoted 10 lines
arch/x86/xen/setup.c +1 -9
-
-	sysenter_feature = X86_FEATURE_SYSENTER32;
-
-	if (!boot_cpu_has(sysenter_feature))
-		return;
-
-	ret = register_callback(CALLBACKTYPE_sysenter, xen_entry_SYSENTER_compat);
-	if(ret != 0)
-		setup_clear_cpu_cap(sysenter_feature);
+	if (boot_cpu_has(X86_FEATURE_SYSENTER32) &&

Can you switch that and below to cpu_feature_enabled() while at it, pls?

Quoted 2 lines

arch/x86/xen/setup.c void xen_enable_syscall(void) · line 929

Quoted 1 line
arch/x86/xen/setup.c +1 -0
+	if (boot_cpu_has(X86_FEATURE_SYSCALL32) &&
	^^^^^^^^^^^^^^^^^^

Yes, of course.

Juergen

#3 lore raw
In reply to Borislav Petkov
Quoted 14 lines · Borislav Petkov
Quoted 13 lines · Juergen Gross

xen_enable_sysenter() and xen_enable_syscall() can be simplified a lot.

---
 arch/x86/xen/setup.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
arch/x86/xen/setup.c +0 -0
index cfa99e8f054b..0f33ed6d3a7b 100644
@@ -910,17 +910,9 @@ static int register_callback(unsigned type, const void *func)
 
Quoted 15 lines
Quoted 4 lines
arch/x86/xen/setup.c +0 -2
 void xen_enable_sysenter(void)
 {
-	int ret;
-	unsigned sysenter_feature;

arch/x86/xen/setup.c static int register_callback(unsigned type, const void *func) · line 913

Quoted 10 lines
arch/x86/xen/setup.c +1 -9
-
-	sysenter_feature = X86_FEATURE_SYSENTER32;
-
-	if (!boot_cpu_has(sysenter_feature))
-		return;
-
-	ret = register_callback(CALLBACKTYPE_sysenter, xen_entry_SYSENTER_compat);
-	if(ret != 0)
-		setup_clear_cpu_cap(sysenter_feature);
+	if (boot_cpu_has(X86_FEATURE_SYSENTER32) &&

Can you switch that and below to cpu_feature_enabled() while at it, pls?

Why?

This function (should) be called on the BSP only (because Xen's API lets this be specified when starting APs).

Whether it's once, or one per cpu, it doesn't matter.

cpu_feature_enabled() puts in an out-of-line thunk (which is what actually gets used), and a patchable code section.

Text patching will happen at least once to orphan the out-of-line thunk, probably after the last time it gets used, then then maybe again later to clear the feature.  Even if you had several million CPUs, there's no way the overhead of cpu_feature_enabled() is worth it here.

~Andrew

author maintainer
#4 lore raw
Quoted 31 lines · Andrew Cooper
Quoted 14 lines · Borislav Petkov
Quoted 13 lines · Juergen Gross

xen_enable_sysenter() and xen_enable_syscall() can be simplified a lot.

---
  arch/x86/xen/setup.c | 23 ++++++-----------------
  1 file changed, 6 insertions(+), 17 deletions(-)
arch/x86/xen/setup.c +0 -0
index cfa99e8f054b..0f33ed6d3a7b 100644
@@ -910,17 +910,9 @@ static int register_callback(unsigned type, const void *func)
 
Quoted 15 lines
Quoted 4 lines
arch/x86/xen/setup.c +0 -2
  void xen_enable_sysenter(void)
  {
-	int ret;
-	unsigned sysenter_feature;

arch/x86/xen/setup.c static int register_callback(unsigned type, const void *func) · line 913

Quoted 10 lines
arch/x86/xen/setup.c +1 -9
-
-	sysenter_feature = X86_FEATURE_SYSENTER32;
-
-	if (!boot_cpu_has(sysenter_feature))
-		return;
-
-	ret = register_callback(CALLBACKTYPE_sysenter, xen_entry_SYSENTER_compat);
-	if(ret != 0)
-		setup_clear_cpu_cap(sysenter_feature);
+	if (boot_cpu_has(X86_FEATURE_SYSENTER32) &&

Can you switch that and below to cpu_feature_enabled() while at it, pls?

Quoted 4 lines

Why?

This function (should) be called on the BSP only (because Xen's API lets this be specified when starting APs).

No, this is true for the syscall callback only. the sysenter and the syscall32 callbacks can only be set via Xen tools or on the local cpu by registering.

Quoted 2 lines

Whether it's once, or one per cpu, it doesn't matter.

It does.

Juergen