2024-05-01 12:30:57

by Muhammad Usama Anjum

[permalink] [raw]
Subject: [PATCH 0/8] selftests: x86: build suite with clang

This series fixes build errors found by clang to allow the x86 suite to
get built with the clang.

Unfortunately, there is one bug [1] in the clang becuase of which
extended asm isn't handled correctly by it and build fails for
sysret_rip.c. Hence even after this series the build of this test would
fail with clang. Should we disable this test for now when clang is used
until the bug is fixed in clang? Not sure. Any opinions?

[1] https://github.com/llvm/llvm-project/issues/53728

Muhammad Usama Anjum (8):
selftests: x86: Remove dependence of headers file
selftests: x86: check_initial_reg_state: remove -no-pie while using
-static
selftests: x86: test_vsyscall: remove unused function
selftests: x86: fsgsbase_restore: fix asm directive from =rm to =r
selftests: x86: syscall_arg_fault_32: remove unused variable
selftests: x86: test_FISTTP: use fisttps instead of ambigous fisttp
selftests: x86: fsgsbase: Remove unused function and variable
selftests: x86: amx: Remove unused functions

tools/testing/selftests/x86/Makefile | 9 +++++----
tools/testing/selftests/x86/amx.c | 16 ----------------
tools/testing/selftests/x86/fsgsbase.c | 6 ------
tools/testing/selftests/x86/fsgsbase_restore.c | 2 +-
tools/testing/selftests/x86/syscall_arg_fault.c | 1 -
tools/testing/selftests/x86/test_FISTTP.c | 8 ++++----
tools/testing/selftests/x86/test_vsyscall.c | 5 -----
7 files changed, 10 insertions(+), 37 deletions(-)

--
2.39.2



2024-05-01 12:31:07

by Muhammad Usama Anjum

[permalink] [raw]
Subject: [PATCH 7/8] selftests: x86: fsgsbase: Remove unused function and variable

Remove unused code.

fsgsbase.c:112:20: warning: unused function 'wrfsbase' [-Wunused-function]
112 | static inline void wrfsbase(unsigned long fsbase)
| ^~~~~~~~
fsgsbase.c:215:22: warning: unused variable 'remote_hard_zero' [-Wunused-variable]
215 | static volatile bool remote_hard_zero;
| ^~~~~~~~~~~~~~~~

Signed-off-by: Muhammad Usama Anjum <[email protected]>
---
tools/testing/selftests/x86/fsgsbase.c | 6 ------
1 file changed, 6 deletions(-)

diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c
index 8c780cce941da..50cf32de63139 100644
--- a/tools/testing/selftests/x86/fsgsbase.c
+++ b/tools/testing/selftests/x86/fsgsbase.c
@@ -109,11 +109,6 @@ static inline void wrgsbase(unsigned long gsbase)
asm volatile("wrgsbase %0" :: "r" (gsbase) : "memory");
}

-static inline void wrfsbase(unsigned long fsbase)
-{
- asm volatile("wrfsbase %0" :: "r" (fsbase) : "memory");
-}
-
enum which_base { FS, GS };

static unsigned long read_base(enum which_base which)
@@ -212,7 +207,6 @@ static void mov_0_gs(unsigned long initial_base, bool schedule)
}

static volatile unsigned long remote_base;
-static volatile bool remote_hard_zero;
static volatile unsigned int ftx;

/*
--
2.39.2


2024-05-01 12:31:22

by Muhammad Usama Anjum

[permalink] [raw]
Subject: [PATCH 8/8] selftests: x86: amx: Remove unused functions

Remove unused code.

amx.c:42:24: warning: unused function 'xgetbv' [-Wunused-function]
42 | static inline uint64_t xgetbv(uint32_t index)
| ^~~~~~
amx.c:167:24: warning: unused function 'get_xstatebv' [-Wunused-function]
167 | static inline uint64_t get_xstatebv(struct xsave_buffer *buffer)
| ^~~~~~~~~~~~

Signed-off-by: Muhammad Usama Anjum <[email protected]>
---
tools/testing/selftests/x86/amx.c | 16 ----------------
1 file changed, 16 deletions(-)

diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x86/amx.c
index 95aad6d8849be..1fdf35a4d7f63 100644
--- a/tools/testing/selftests/x86/amx.c
+++ b/tools/testing/selftests/x86/amx.c
@@ -39,16 +39,6 @@ struct xsave_buffer {
};
};

-static inline uint64_t xgetbv(uint32_t index)
-{
- uint32_t eax, edx;
-
- asm volatile("xgetbv;"
- : "=a" (eax), "=d" (edx)
- : "c" (index));
- return eax + ((uint64_t)edx << 32);
-}
-
static inline void xsave(struct xsave_buffer *xbuf, uint64_t rfbm)
{
uint32_t rfbm_lo = rfbm;
@@ -164,12 +154,6 @@ static inline void clear_xstate_header(struct xsave_buffer *buffer)
memset(&buffer->header, 0, sizeof(buffer->header));
}

-static inline uint64_t get_xstatebv(struct xsave_buffer *buffer)
-{
- /* XSTATE_BV is at the beginning of the header: */
- return *(uint64_t *)&buffer->header;
-}
-
static inline void set_xstatebv(struct xsave_buffer *buffer, uint64_t bv)
{
/* XSTATE_BV is at the beginning of the header: */
--
2.39.2


2024-05-01 12:31:44

by Muhammad Usama Anjum

[permalink] [raw]
Subject: [PATCH 2/8] selftests: x86: check_initial_reg_state: remove -no-pie while using -static

The -static clang flag ignores -no-pie flag. Hence following warning is
generated. Fix the warning by removing the -no-pie flag before
specifying -static flag.

clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]

Signed-off-by: Muhammad Usama Anjum <[email protected]>
---
tools/testing/selftests/x86/Makefile | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/x86/Makefile b/tools/testing/selftests/x86/Makefile
index 671b1819694ff..b0f5b5ff79b8d 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -108,8 +108,9 @@ $(OUTPUT)/test_syscall_vdso_32: thunks_32.S
# check_initial_reg_state is special: it needs a custom entry, and it
# needs to be static so that its interpreter doesn't destroy its initial
# state.
-$(OUTPUT)/check_initial_reg_state_32: CFLAGS += -Wl,-ereal_start -static
-$(OUTPUT)/check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static
+CFLAGS2:=$(filter-out -no-pie,$(CFLAGS))
+$(OUTPUT)/check_initial_reg_state_32: CFLAGS2 += -Wl,-ereal_start -static
+$(OUTPUT)/check_initial_reg_state_64: CFLAGS2 += -Wl,-ereal_start -static

$(OUTPUT)/nx_stack_32: CFLAGS += -Wl,-z,noexecstack
$(OUTPUT)/nx_stack_64: CFLAGS += -Wl,-z,noexecstack
--
2.39.2


2024-05-01 12:32:06

by Muhammad Usama Anjum

[permalink] [raw]
Subject: [PATCH 3/8] selftests: x86: test_vsyscall: remove unused function

Remove unused function to fix the following warning:

test_vsyscall.c:100:19: warning: unused function 'sys_clock_gettime' [-Wunused-function]
100 | static inline int sys_clock_gettime(clockid_t id, struct timespec *ts)

Signed-off-by: Muhammad Usama Anjum <[email protected]>
---
tools/testing/selftests/x86/test_vsyscall.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/tools/testing/selftests/x86/test_vsyscall.c b/tools/testing/selftests/x86/test_vsyscall.c
index d4c8e8d79d389..1c9895cfc660b 100644
--- a/tools/testing/selftests/x86/test_vsyscall.c
+++ b/tools/testing/selftests/x86/test_vsyscall.c
@@ -97,11 +97,6 @@ static inline long sys_gtod(struct timeval *tv, struct timezone *tz)
return syscall(SYS_gettimeofday, tv, tz);
}

-static inline int sys_clock_gettime(clockid_t id, struct timespec *ts)
-{
- return syscall(SYS_clock_gettime, id, ts);
-}
-
static inline long sys_time(time_t *t)
{
return syscall(SYS_time, t);
--
2.39.2


2024-05-06 23:26:49

by Fangrui Song

[permalink] [raw]
Subject: Re: [PATCH 0/8] selftests: x86: build suite with clang

On Wed, May 1, 2024 at 5:29 AM Muhammad Usama Anjum
<[email protected]> wrote:
>
> This series fixes build errors found by clang to allow the x86 suite to
> get built with the clang.
>
> Unfortunately, there is one bug [1] in the clang becuase of which
> extended asm isn't handled correctly by it and build fails for
> sysret_rip.c. Hence even after this series the build of this test would
> fail with clang. Should we disable this test for now when clang is used
> until the bug is fixed in clang? Not sure. Any opinions?
>
> [1] https://github.com/llvm/llvm-project/issues/53728

I've closed https://github.com/llvm/llvm-project/issues/53728
(constant expression folding for relocatable file output
(MCObjectStreamer)).

I've sent a patch to address https://github.com/llvm/llvm-project/issues/62520
(constant expression folding for relocatable file output when inline
assembly is used).

(I am subscribed to [email protected] but rarely read it. I noticed
this message accidentally :) )

> Muhammad Usama Anjum (8):
> selftests: x86: Remove dependence of headers file
> selftests: x86: check_initial_reg_state: remove -no-pie while using
> -static
> selftests: x86: test_vsyscall: remove unused function
> selftests: x86: fsgsbase_restore: fix asm directive from =rm to =r
> selftests: x86: syscall_arg_fault_32: remove unused variable
> selftests: x86: test_FISTTP: use fisttps instead of ambigous fisttp
> selftests: x86: fsgsbase: Remove unused function and variable
> selftests: x86: amx: Remove unused functions
>
> tools/testing/selftests/x86/Makefile | 9 +++++----
> tools/testing/selftests/x86/amx.c | 16 ----------------
> tools/testing/selftests/x86/fsgsbase.c | 6 ------
> tools/testing/selftests/x86/fsgsbase_restore.c | 2 +-
> tools/testing/selftests/x86/syscall_arg_fault.c | 1 -
> tools/testing/selftests/x86/test_FISTTP.c | 8 ++++----
> tools/testing/selftests/x86/test_vsyscall.c | 5 -----
> 7 files changed, 10 insertions(+), 37 deletions(-)
>
> --
> 2.39.2
>
>


--
宋方睿

2024-05-16 14:07:43

by Muhammad Usama Anjum

[permalink] [raw]
Subject: Re: [PATCH 0/8] selftests: x86: build suite with clang

On 5/1/24 6:29 AM, Muhammad Usama Anjum wrote:
> This series fixes build errors found by clang to allow the x86 suite to
> get built with the clang.
>
> Unfortunately, there is one bug [1] in the clang becuase of which
> extended asm isn't handled correctly by it and build fails for
> sysret_rip.c. Hence even after this series the build of this test would
> fail with clang. Should we disable this test for now when clang is used
> until the bug is fixed in clang? Not sure. Any opinions?
Its seems like the bug has been fixed in clang. I'll verify it in next
release and draft a patch separately to fix that error.

I think this series is good to accept then.

>
> [1] https://github.com/llvm/llvm-project/issues/53728
>
> Muhammad Usama Anjum (8):
> selftests: x86: Remove dependence of headers file
> selftests: x86: check_initial_reg_state: remove -no-pie while using
> -static
> selftests: x86: test_vsyscall: remove unused function
> selftests: x86: fsgsbase_restore: fix asm directive from =rm to =r
> selftests: x86: syscall_arg_fault_32: remove unused variable
> selftests: x86: test_FISTTP: use fisttps instead of ambigous fisttp
> selftests: x86: fsgsbase: Remove unused function and variable
> selftests: x86: amx: Remove unused functions
>
> tools/testing/selftests/x86/Makefile | 9 +++++----
> tools/testing/selftests/x86/amx.c | 16 ----------------
> tools/testing/selftests/x86/fsgsbase.c | 6 ------
> tools/testing/selftests/x86/fsgsbase_restore.c | 2 +-
> tools/testing/selftests/x86/syscall_arg_fault.c | 1 -
> tools/testing/selftests/x86/test_FISTTP.c | 8 ++++----
> tools/testing/selftests/x86/test_vsyscall.c | 5 -----
> 7 files changed, 10 insertions(+), 37 deletions(-)
>

--
BR,
Muhammad Usama Anjum

2024-05-28 05:05:06

by Muhammad Usama Anjum

[permalink] [raw]
Subject: Re: [PATCH 0/8] selftests: x86: build suite with clang

Soft reminder

On 5/1/24 5:29 PM, Muhammad Usama Anjum wrote:
> This series fixes build errors found by clang to allow the x86 suite to
> get built with the clang.
>
> Unfortunately, there is one bug [1] in the clang becuase of which
> extended asm isn't handled correctly by it and build fails for
> sysret_rip.c. Hence even after this series the build of this test would
> fail with clang. Should we disable this test for now when clang is used
> until the bug is fixed in clang? Not sure. Any opinions?
>
> [1] https://github.com/llvm/llvm-project/issues/53728
>
> Muhammad Usama Anjum (8):
> selftests: x86: Remove dependence of headers file
> selftests: x86: check_initial_reg_state: remove -no-pie while using
> -static
> selftests: x86: test_vsyscall: remove unused function
> selftests: x86: fsgsbase_restore: fix asm directive from =rm to =r
> selftests: x86: syscall_arg_fault_32: remove unused variable
> selftests: x86: test_FISTTP: use fisttps instead of ambigous fisttp
> selftests: x86: fsgsbase: Remove unused function and variable
> selftests: x86: amx: Remove unused functions
>
> tools/testing/selftests/x86/Makefile | 9 +++++----
> tools/testing/selftests/x86/amx.c | 16 ----------------
> tools/testing/selftests/x86/fsgsbase.c | 6 ------
> tools/testing/selftests/x86/fsgsbase_restore.c | 2 +-
> tools/testing/selftests/x86/syscall_arg_fault.c | 1 -
> tools/testing/selftests/x86/test_FISTTP.c | 8 ++++----
> tools/testing/selftests/x86/test_vsyscall.c | 5 -----
> 7 files changed, 10 insertions(+), 37 deletions(-)
>

--
BR,
Muhammad Usama Anjum

2024-06-07 20:50:27

by Shuah Khan

[permalink] [raw]
Subject: Re: [PATCH 0/8] selftests: x86: build suite with clang

On 5/27/24 23:04, Muhammad Usama Anjum wrote:
> Soft reminder
>
> On 5/1/24 5:29 PM, Muhammad Usama Anjum wrote:
>> This series fixes build errors found by clang to allow the x86 suite to
>> get built with the clang.
>>
>> Unfortunately, there is one bug [1] in the clang becuase of which
>> extended asm isn't handled correctly by it and build fails for
>> sysret_rip.c. Hence even after this series the build of this test would
>> fail with clang. Should we disable this test for now when clang is used
>> until the bug is fixed in clang? Not sure. Any opinions?
>>
>> [1] https://github.com/llvm/llvm-project/issues/53728
>>
>> Muhammad Usama Anjum (8):
>> selftests: x86: Remove dependence of headers file
>> selftests: x86: check_initial_reg_state: remove -no-pie while using
>> -static
>> selftests: x86: test_vsyscall: remove unused function
>> selftests: x86: fsgsbase_restore: fix asm directive from =rm to =r
>> selftests: x86: syscall_arg_fault_32: remove unused variable
>> selftests: x86: test_FISTTP: use fisttps instead of ambigous fisttp
>> selftests: x86: fsgsbase: Remove unused function and variable
>> selftests: x86: amx: Remove unused functions
>>
>> tools/testing/selftests/x86/Makefile | 9 +++++----
>> tools/testing/selftests/x86/amx.c | 16 ----------------
>> tools/testing/selftests/x86/fsgsbase.c | 6 ------
>> tools/testing/selftests/x86/fsgsbase_restore.c | 2 +-
>> tools/testing/selftests/x86/syscall_arg_fault.c | 1 -
>> tools/testing/selftests/x86/test_FISTTP.c | 8 ++++----
>> tools/testing/selftests/x86/test_vsyscall.c | 5 -----
>> 7 files changed, 10 insertions(+), 37 deletions(-)
>>
>

These patches usually go through x86 repo.

I need ack from x86 maintainers to take these. I don't see x86 list
cc'ed.

Please make sure to include everybody on these threads to get quicker
response.

thanks,
-- Shuah

2024-06-07 21:18:05

by Dave Hansen

[permalink] [raw]
Subject: Re: [PATCH 0/8] selftests: x86: build suite with clang

On 6/7/24 13:50, Shuah Khan wrote:
> These patches usually go through x86 repo.
>
> I need ack from x86 maintainers to take these. I don't see x86 list
> cc'ed.
>
> Please make sure to include everybody on these threads to get quicker
> response.

John Hubbard (cc'd) had a partially overlapping set with these. He and
Muhammad were going to work together to get a set they could both get
behind. I _think_ John picked up one of Muhammad's, but we haven't
heard back from Muhammad last I checked.



2024-06-07 21:25:37

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH 0/8] selftests: x86: build suite with clang

On 6/7/24 2:17 PM, Dave Hansen wrote:
> On 6/7/24 13:50, Shuah Khan wrote:
>> These patches usually go through x86 repo.
>>
>> I need ack from x86 maintainers to take these. I don't see x86 list
>> cc'ed.
>>
>> Please make sure to include everybody on these threads to get quicker
>> response.
>
> John Hubbard (cc'd) had a partially overlapping set with these. He and
> Muhammad were going to work together to get a set they could both get
> behind. I _think_ John picked up one of Muhammad's, but we haven't
> heard back from Muhammad last I checked.

Yes I did that. My latest series has 1 fix from Muhammad and 6 more
from me. Muhammad hasn't formally ack'd nor responded to the latest
series [1] yet, although he was OK doing it this way [2].

[1] https://lore.kernel.org/[email protected]

[2] https://lore.kernel.org/[email protected]


thanks,
--
John Hubbard
NVIDIA