Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH v1 0/2] selftests/x86: Skip int80 if not supported
@ 2025-12-17 13:59 Slawomir Rosek
  2025-12-17 13:59 ` [PATCH v1 1/2] selftests/x86/ldt_gdt: " Slawomir Rosek
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Slawomir Rosek @ 2025-12-17 13:59 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H . Peter Anvin, Shuah Khan
  Cc: Betty Zhou, Wake Liu, Kazuhiro Inaba, Jeff Xu, Alistair Delva,
	linux-kernel, linux-kselftest, Slawomir Rosek

The IA32 Emulation support can be either removed from the kernel,
disabled by default or disabled at runtime. Some of x86 selftests
are crashing for all of above thus is_32bit_syscall_supported()
helper is added to skip int80 syscalls if they are not supported.

Slawomir Rosek (2):
  selftests/x86/ldt_gdt: Skip int80 if not supported
  selftests/x86/ptrace_syscall: Skip int80 if not supported

 tools/testing/selftests/x86/ldt_gdt.c        | 21 +++++++++++++++++++-
 tools/testing/selftests/x86/ptrace_syscall.c | 20 +++++++++++++++++--
 2 files changed, 38 insertions(+), 3 deletions(-)

-- 
2.52.0.305.g3fc767764a-goog


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v1 1/2] selftests/x86/ldt_gdt: Skip int80 if not supported
  2025-12-17 13:59 [PATCH v1 0/2] selftests/x86: Skip int80 if not supported Slawomir Rosek
@ 2025-12-17 13:59 ` Slawomir Rosek
  2026-01-23 16:54   ` Borislav Petkov
  2025-12-17 13:59 ` [PATCH v1 2/2] selftests/x86/ptrace_syscall: " Slawomir Rosek
  2026-01-12 11:23 ` [PATCH v1 0/2] selftests/x86: " Sławomir Rosek
  2 siblings, 1 reply; 9+ messages in thread
From: Slawomir Rosek @ 2025-12-17 13:59 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H . Peter Anvin, Shuah Khan
  Cc: Betty Zhou, Wake Liu, Kazuhiro Inaba, Jeff Xu, Alistair Delva,
	linux-kernel, linux-kselftest, Slawomir Rosek

The IA32 Emulation support can be either removed from the kernel,
disabled by default or disabled at runtime. The x86/ldt_gdt selftest
crashes for all of above thus is_32bit_syscall_supported() helper
is added to skip int80 syscalls if they are not supported.

Signed-off-by: Slawomir Rosek <srosek@google.com>
---
 tools/testing/selftests/x86/ldt_gdt.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/x86/ldt_gdt.c b/tools/testing/selftests/x86/ldt_gdt.c
index bb99a71380a5..b178392e50c0 100644
--- a/tools/testing/selftests/x86/ldt_gdt.c
+++ b/tools/testing/selftests/x86/ldt_gdt.c
@@ -62,6 +62,18 @@ static struct user_desc *low_user_desc;
 static struct user_desc *low_user_desc_clear;  /* Use to delete GDT entry */
 static int gdt_entry_num;
 
+static bool is_32bit_syscall_supported(void)
+{
+#ifdef __x86_64__
+	return system("((zcat /proc/config.gz | grep CONFIG_IA32_EMULATION=y) &&"
+		"((test -z $(zcat /proc/config.gz | grep CONFIG_IA32_EMULATION_DEFAULT_DISABLED=y)) || (grep ia32_emulation=true /proc/cmdline)) &&"
+		"(test -z $(grep ia32_emulation=false /proc/cmdline))) >/dev/null 2>&1"
+	) == 0;
+#else
+	return true;
+#endif
+}
+
 static void check_invalid_segment(uint16_t index, int ldt)
 {
 	uint32_t has_limit = 0, has_ar = 0, limit, ar;
@@ -147,6 +159,7 @@ static bool install_valid_mode(const struct user_desc *d, uint32_t ar,
 	if (!ldt) {
 #ifndef __i386__
 		/* No point testing set_thread_area in a 64-bit build */
+		printf("[SKIP]\tNo point testing set_thread_area in a 64-bit build\n");
 		return false;
 #endif
 		if (!gdt_entry_num)
@@ -676,6 +689,10 @@ static void setup_counter_page(void)
 static int invoke_set_thread_area(void)
 {
 	int ret;
+	if (!is_32bit_syscall_supported()) {
+		printf("[SKIP]\tNo 32bit syscall support in a 64-bit build\n");
+		return -1;
+	}
 	asm volatile ("int $0x80"
 		      : "=a" (ret), "+m" (low_user_desc) :
 			"a" (243), "b" (low_user_desc)
@@ -716,8 +733,10 @@ static void setup_low_user_desc(void)
 
 static void test_gdt_invalidation(void)
 {
-	if (!gdt_entry_num)
+	if (!gdt_entry_num) {
+		printf("[SKIP]\tNo set_thread_area support in a 64-bit only system\n");
 		return;	/* 64-bit only system -- we can't use set_thread_area */
+	}
 
 	unsigned short prev_sel;
 	unsigned short sel;
-- 
2.52.0.305.g3fc767764a-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v1 2/2] selftests/x86/ptrace_syscall: Skip int80 if not supported
  2025-12-17 13:59 [PATCH v1 0/2] selftests/x86: Skip int80 if not supported Slawomir Rosek
  2025-12-17 13:59 ` [PATCH v1 1/2] selftests/x86/ldt_gdt: " Slawomir Rosek
@ 2025-12-17 13:59 ` Slawomir Rosek
  2026-01-12 11:23 ` [PATCH v1 0/2] selftests/x86: " Sławomir Rosek
  2 siblings, 0 replies; 9+ messages in thread
From: Slawomir Rosek @ 2025-12-17 13:59 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H . Peter Anvin, Shuah Khan
  Cc: Betty Zhou, Wake Liu, Kazuhiro Inaba, Jeff Xu, Alistair Delva,
	linux-kernel, linux-kselftest, Slawomir Rosek

The IA32 Emulation support can be either removed from the kernel,
disabled by default or disabled at runtime. The x86/ptrace_syscall
selftest crashes for all of above thus is_32bit_syscall_supported()
helper is added to skip int80 syscalls if they are not supported.

Signed-off-by: Slawomir Rosek <srosek@google.com>
---
 tools/testing/selftests/x86/ptrace_syscall.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/x86/ptrace_syscall.c b/tools/testing/selftests/x86/ptrace_syscall.c
index 360ec88d5432..6c19bea485c6 100644
--- a/tools/testing/selftests/x86/ptrace_syscall.c
+++ b/tools/testing/selftests/x86/ptrace_syscall.c
@@ -51,6 +51,18 @@ extern void sys32_helper(struct syscall_args32 *, void *);
 extern void int80_and_ret(void);
 #endif
 
+static bool is_32bit_syscall_supported(void)
+{
+#ifdef __x86_64__
+	return system("((zcat /proc/config.gz | grep CONFIG_IA32_EMULATION=y) &&"
+		"((test -z $(zcat /proc/config.gz | grep CONFIG_IA32_EMULATION_DEFAULT_DISABLED=y)) || (grep ia32_emulation=true /proc/cmdline)) &&"
+		"(test -z $(grep ia32_emulation=false /proc/cmdline))) >/dev/null 2>&1"
+	) == 0;
+#else
+	return true;
+#endif
+}
+
 /*
  * Helper to invoke int80 with controlled regs and capture the final regs.
  */
@@ -389,8 +401,12 @@ static void test_restart_under_ptrace(void)
 
 int main()
 {
-	printf("[RUN]\tCheck int80 return regs\n");
-	test_sys32_regs(do_full_int80);
+	if (is_32bit_syscall_supported()) {
+		printf("[RUN]\tCheck int80 return regs\n");
+		test_sys32_regs(do_full_int80);
+	} else {
+		printf("[SKIP]\t32bit syscall support is not available\n");
+	}
 
 #if defined(__i386__) && (!defined(__GLIBC__) || __GLIBC__ > 2 || __GLIBC_MINOR__ >= 16)
 	vsyscall32 = (void *)getauxval(AT_SYSINFO);
-- 
2.52.0.305.g3fc767764a-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 0/2] selftests/x86: Skip int80 if not supported
  2025-12-17 13:59 [PATCH v1 0/2] selftests/x86: Skip int80 if not supported Slawomir Rosek
  2025-12-17 13:59 ` [PATCH v1 1/2] selftests/x86/ldt_gdt: " Slawomir Rosek
  2025-12-17 13:59 ` [PATCH v1 2/2] selftests/x86/ptrace_syscall: " Slawomir Rosek
@ 2026-01-12 11:23 ` Sławomir Rosek
  2026-01-24  1:18   ` H. Peter Anvin
  2 siblings, 1 reply; 9+ messages in thread
From: Sławomir Rosek @ 2026-01-12 11:23 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H . Peter Anvin, Shuah Khan
  Cc: Betty Zhou, Wake Liu, Kazuhiro Inaba, Jeff Xu, Alistair Delva,
	linux-kernel, linux-kselftest

On Wed, Dec 17, 2025 at 2:59 PM Slawomir Rosek <srosek@google.com> wrote:
>
> The IA32 Emulation support can be either removed from the kernel,
> disabled by default or disabled at runtime. Some of x86 selftests
> are crashing for all of above thus is_32bit_syscall_supported()
> helper is added to skip int80 syscalls if they are not supported.
>
> Slawomir Rosek (2):
>   selftests/x86/ldt_gdt: Skip int80 if not supported
>   selftests/x86/ptrace_syscall: Skip int80 if not supported

Hi all,

Just a gentle reminder, it would be really great if someone could take
a look. Thanks in advance.

Best regards,
S. Rosek

>
>  tools/testing/selftests/x86/ldt_gdt.c        | 21 +++++++++++++++++++-
>  tools/testing/selftests/x86/ptrace_syscall.c | 20 +++++++++++++++++--
>  2 files changed, 38 insertions(+), 3 deletions(-)
>
> --
> 2.52.0.305.g3fc767764a-goog
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] selftests/x86/ldt_gdt: Skip int80 if not supported
  2025-12-17 13:59 ` [PATCH v1 1/2] selftests/x86/ldt_gdt: " Slawomir Rosek
@ 2026-01-23 16:54   ` Borislav Petkov
  2026-01-23 17:07     ` Dave Hansen
  2026-01-24  1:01     ` H. Peter Anvin
  0 siblings, 2 replies; 9+ messages in thread
From: Borislav Petkov @ 2026-01-23 16:54 UTC (permalink / raw)
  To: Slawomir Rosek
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H . Peter Anvin,
	Shuah Khan, Betty Zhou, Wake Liu, Kazuhiro Inaba, Jeff Xu,
	Alistair Delva, linux-kernel, linux-kselftest

On Wed, Dec 17, 2025 at 01:59:31PM +0000, Slawomir Rosek wrote:
> The IA32 Emulation support can be either removed from the kernel,
> disabled by default or disabled at runtime. The x86/ldt_gdt selftest
> crashes for all of above thus is_32bit_syscall_supported() helper
> is added to skip int80 syscalls if they are not supported.
> 
> Signed-off-by: Slawomir Rosek <srosek@google.com>
> ---
>  tools/testing/selftests/x86/ldt_gdt.c | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/x86/ldt_gdt.c b/tools/testing/selftests/x86/ldt_gdt.c
> index bb99a71380a5..b178392e50c0 100644
> --- a/tools/testing/selftests/x86/ldt_gdt.c
> +++ b/tools/testing/selftests/x86/ldt_gdt.c
> @@ -62,6 +62,18 @@ static struct user_desc *low_user_desc;
>  static struct user_desc *low_user_desc_clear;  /* Use to delete GDT entry */
>  static int gdt_entry_num;
>  
> +static bool is_32bit_syscall_supported(void)
> +{
> +#ifdef __x86_64__
> +	return system("((zcat /proc/config.gz | grep CONFIG_IA32_EMULATION=y) &&"
> +		"((test -z $(zcat /proc/config.gz | grep CONFIG_IA32_EMULATION_DEFAULT_DISABLED=y)) || (grep ia32_emulation=true /proc/cmdline)) &&"
> +		"(test -z $(grep ia32_emulation=false /proc/cmdline))) >/dev/null 2>&1"
> +	) == 0;
> +#else
> +	return true;
> +#endif
> +}

Hmmm, so, my gut feeling tells me that we need a proper ia32 emu support
detection in the running kernel. I can't find one after a short grep, maybe it
should be in /proc/cpuinfo, maybe it should be a syscall which fails when
IA32_EMULATION is off or maybe ptrace(2) says somewhere in the depths of its
countless ops that it does support IA32 emulation.

And then you could put that in that helper and then put that helper in
a header and not copy it in every test...

I'd say.

Thx.


-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] selftests/x86/ldt_gdt: Skip int80 if not supported
  2026-01-23 16:54   ` Borislav Petkov
@ 2026-01-23 17:07     ` Dave Hansen
  2026-01-24  1:01     ` H. Peter Anvin
  1 sibling, 0 replies; 9+ messages in thread
From: Dave Hansen @ 2026-01-23 17:07 UTC (permalink / raw)
  To: Borislav Petkov, Slawomir Rosek
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H . Peter Anvin,
	Shuah Khan, Betty Zhou, Wake Liu, Kazuhiro Inaba, Jeff Xu,
	Alistair Delva, linux-kernel, linux-kselftest

On 1/23/26 08:54, Borislav Petkov wrote:
> Hmmm, so, my gut feeling tells me that we need a proper ia32 emu support
> detection in the running kernel. I can't find one after a short grep, maybe it
> should be in /proc/cpuinfo, maybe it should be a syscall which fails when
> IA32_EMULATION is off or maybe ptrace(2) says somewhere in the depths of its
> countless ops that it does support IA32 emulation.

Yeah, a little arch_prctl() that returns supported or not would be nice.
I just hope we can manage to keep it used by the selftests and not get
abused by anyone else.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] selftests/x86/ldt_gdt: Skip int80 if not supported
  2026-01-23 16:54   ` Borislav Petkov
  2026-01-23 17:07     ` Dave Hansen
@ 2026-01-24  1:01     ` H. Peter Anvin
  2026-02-13 17:26       ` Sławomir Rosek
  1 sibling, 1 reply; 9+ messages in thread
From: H. Peter Anvin @ 2026-01-24  1:01 UTC (permalink / raw)
  To: Borislav Petkov, Slawomir Rosek
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, Shuah Khan,
	Betty Zhou, Wake Liu, Kazuhiro Inaba, Jeff Xu, Alistair Delva,
	linux-kernel, linux-kselftest

On 2026-01-23 08:54, Borislav Petkov wrote:
> 
> Hmmm, so, my gut feeling tells me that we need a proper ia32 emu support
> detection in the running kernel. I can't find one after a short grep, maybe it
> should be in /proc/cpuinfo, maybe it should be a syscall which fails when
> IA32_EMULATION is off or maybe ptrace(2) says somewhere in the depths of its
> countless ops that it does support IA32 emulation.
> 
> And then you could put that in that helper and then put that helper in
> a header and not copy it in every test...
> 

You can probe for it by trapping SIGSEGV and calling int $0x80. Not exactly
pretty, but...

Making it a sysfs entry would allow dynamically control it, too...

	-hpa


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 0/2] selftests/x86: Skip int80 if not supported
  2026-01-12 11:23 ` [PATCH v1 0/2] selftests/x86: " Sławomir Rosek
@ 2026-01-24  1:18   ` H. Peter Anvin
  0 siblings, 0 replies; 9+ messages in thread
From: H. Peter Anvin @ 2026-01-24  1:18 UTC (permalink / raw)
  To: Sławomir Rosek, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, Shuah Khan
  Cc: Betty Zhou, Wake Liu, Kazuhiro Inaba, Jeff Xu, Alistair Delva,
	linux-kernel, linux-kselftest

On 2026-01-12 03:23, Sławomir Rosek wrote:
> On Wed, Dec 17, 2025 at 2:59 PM Slawomir Rosek <srosek@google.com> wrote:
>>
>> The IA32 Emulation support can be either removed from the kernel,
>> disabled by default or disabled at runtime. Some of x86 selftests
>> are crashing for all of above thus is_32bit_syscall_supported()
>> helper is added to skip int80 syscalls if they are not supported.
>>
>> Slawomir Rosek (2):
>>   selftests/x86/ldt_gdt: Skip int80 if not supported
>>   selftests/x86/ptrace_syscall: Skip int80 if not supported
> 
> Hi all,
> 
> Just a gentle reminder, it would be really great if someone could take
> a look. Thanks in advance.

I think grepping the configuration and cmdline files is definitely not the way
to go.

For a solution that works on existing kernels, trapping SIGSEGV and calling
int $0x80 is probably the best way to probe.

	-hpa


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] selftests/x86/ldt_gdt: Skip int80 if not supported
  2026-01-24  1:01     ` H. Peter Anvin
@ 2026-02-13 17:26       ` Sławomir Rosek
  0 siblings, 0 replies; 9+ messages in thread
From: Sławomir Rosek @ 2026-02-13 17:26 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Borislav Petkov, Thomas Gleixner, Ingo Molnar, Dave Hansen, x86,
	Shuah Khan, Betty Zhou, Wake Liu, Kazuhiro Inaba, Jeff Xu,
	Alistair Delva, linux-kernel, linux-kselftest

On Sat, Jan 24, 2026 at 2:02 AM H. Peter Anvin <hpa@zytor.com> wrote:
>
> On 2026-01-23 08:54, Borislav Petkov wrote:
> >
> > Hmmm, so, my gut feeling tells me that we need a proper ia32 emu support
> > detection in the running kernel. I can't find one after a short grep, maybe it
> > should be in /proc/cpuinfo, maybe it should be a syscall which fails when
> > IA32_EMULATION is off or maybe ptrace(2) says somewhere in the depths of its
> > countless ops that it does support IA32 emulation.
> >
> > And then you could put that in that helper and then put that helper in
> > a header and not copy it in every test...
> >
>
> You can probe for it by trapping SIGSEGV and calling int $0x80. Not exactly
> pretty, but...
>
> Making it a sysfs entry would allow dynamically control it, too...
>
>         -hpa
>

Yeah, it was actually a really quick fix, and now that I think about it,
I agree that grepping like that doesn't look good. Sorry for the rushed
patches, and thanks for all the comments.

Regards,
Slawek

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-02-13 17:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-17 13:59 [PATCH v1 0/2] selftests/x86: Skip int80 if not supported Slawomir Rosek
2025-12-17 13:59 ` [PATCH v1 1/2] selftests/x86/ldt_gdt: " Slawomir Rosek
2026-01-23 16:54   ` Borislav Petkov
2026-01-23 17:07     ` Dave Hansen
2026-01-24  1:01     ` H. Peter Anvin
2026-02-13 17:26       ` Sławomir Rosek
2025-12-17 13:59 ` [PATCH v1 2/2] selftests/x86/ptrace_syscall: " Slawomir Rosek
2026-01-12 11:23 ` [PATCH v1 0/2] selftests/x86: " Sławomir Rosek
2026-01-24  1:18   ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox