* [PATCH V2] selftests/sgx: Fix build error caused by missing dependency
@ 2021-12-14 19:26 Reinette Chatre
2021-12-14 20:10 ` Shuah Khan
0 siblings, 1 reply; 6+ messages in thread
From: Reinette Chatre @ 2021-12-14 19:26 UTC (permalink / raw)
To: dave.hansen, jarkko, linux-sgx, shuah; +Cc: linux-kselftest
Commit f0ff2447b861 ("selftests/sgx: Add a new kselftest:
Unclobbered_vdso_oversubscribed") depends on __cpuid() without
providing the dependency and thus introduces a build error:
$ make
gcc -Wall -Werror -g -I../../../../tools/include -fPIC -z noexecstack -c main.c -o ../linux/tools/testing/selftests/sgx/main.o
main.c: In function ‘get_total_epc_mem’:
main.c:296:3: error: implicit declaration of function ‘__cpuid’ [-Werror=implicit-function-declaration]
296 | __cpuid(&eax, &ebx, &ecx, &edx);
| ^~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:33: ../linux/tools/testing/selftests/sgx/main.o] Error 1
$
Clone kernel's __cpuid() implementation to the self-test in order
to make it available to the EPC enumeration code.
Fixes: f0ff2447b861 ("selftests/sgx: Add a new kselftest: Unclobbered_vdso_oversubscribed")
Reported-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
The commit introducing the issue can be found on
the x86/sgx branch of tip.git.
Changes since V1:
- V1: https://lore.kernel.org/linux-sgx/797ff1331cfe540fc378fcc4a4a7b00ff5099fbe.1638905135.git.reinette.chatre@intel.com/
- Improve commit message. (Jarkko)
tools/testing/selftests/sgx/main.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index 7e912db4c6c5..6dead57a3121 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -73,6 +73,18 @@ static bool vdso_get_symtab(void *addr, struct vdso_symtab *symtab)
return true;
}
+static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
+ unsigned int *ecx, unsigned int *edx)
+{
+ asm volatile("cpuid"
+ : "=a" (*eax),
+ "=b" (*ebx),
+ "=c" (*ecx),
+ "=d" (*edx)
+ : "0" (*eax), "2" (*ecx)
+ : "memory");
+}
+
static unsigned long elf_sym_hash(const char *name)
{
unsigned long h = 0, high;
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH V2] selftests/sgx: Fix build error caused by missing dependency
2021-12-14 19:26 [PATCH V2] selftests/sgx: Fix build error caused by missing dependency Reinette Chatre
@ 2021-12-14 20:10 ` Shuah Khan
2021-12-14 21:28 ` Reinette Chatre
0 siblings, 1 reply; 6+ messages in thread
From: Shuah Khan @ 2021-12-14 20:10 UTC (permalink / raw)
To: Reinette Chatre, dave.hansen, jarkko, linux-sgx, shuah
Cc: linux-kselftest, Shuah Khan
On 12/14/21 12:26 PM, Reinette Chatre wrote:
> Commit f0ff2447b861 ("selftests/sgx: Add a new kselftest:
> Unclobbered_vdso_oversubscribed") depends on __cpuid() without
> providing the dependency and thus introduces a build error:
>
> $ make
> gcc -Wall -Werror -g -I../../../../tools/include -fPIC -z noexecstack -c main.c -o ../linux/tools/testing/selftests/sgx/main.o
> main.c: In function ‘get_total_epc_mem’:
> main.c:296:3: error: implicit declaration of function ‘__cpuid’ [-Werror=implicit-function-declaration]
> 296 | __cpuid(&eax, &ebx, &ecx, &edx);
> | ^~~~~~~
> cc1: all warnings being treated as errors
> make: *** [Makefile:33: ../linux/tools/testing/selftests/sgx/main.o] Error 1
> $
>
> Clone kernel's __cpuid() implementation to the self-test in order
> to make it available to the EPC enumeration code.
>
> Fixes: f0ff2447b861 ("selftests/sgx: Add a new kselftest: Unclobbered_vdso_oversubscribed")
> Reported-by: Jarkko Sakkinen <jarkko@kernel.org>
> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
> ---
>
> The commit introducing the issue can be found on
> the x86/sgx branch of tip.git.
>
> Changes since V1:
> - V1: https://lore.kernel.org/linux-sgx/797ff1331cfe540fc378fcc4a4a7b00ff5099fbe.1638905135.git.reinette.chatre@intel.com/
> - Improve commit message. (Jarkko)
>
> tools/testing/selftests/sgx/main.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
> index 7e912db4c6c5..6dead57a3121 100644
> --- a/tools/testing/selftests/sgx/main.c
> +++ b/tools/testing/selftests/sgx/main.c
> @@ -73,6 +73,18 @@ static bool vdso_get_symtab(void *addr, struct vdso_symtab *symtab)
> return true;
> }
>
> +static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
> + unsigned int *ecx, unsigned int *edx)
> +{
> + asm volatile("cpuid"
> + : "=a" (*eax),
> + "=b" (*ebx),
> + "=c" (*ecx),
> + "=d" (*edx)
> + : "0" (*eax), "2" (*ecx)
> + : "memory");
> +}
> +
> static unsigned long elf_sym_hash(const char *name)
> {
> unsigned long h = 0, high;
>
Let's not add one more __cpuid() define to the individual tests.
We so far have:
tools/testing/selftests/vm/pkey-x86.h
selftests/x86/corrupt_xstate_header.c
Let's move the defines to kselftest.h and remove all these duplicate
defines.
For now you could include vm/pkey-x86.h just to fix the build error
and do the proper cleanup.
There has been a proliferation of defines in tools and selftests.
I just fixed/remove 25+ ARRAY_SIZE duplicate define in selftests.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2] selftests/sgx: Fix build error caused by missing dependency
2021-12-14 20:10 ` Shuah Khan
@ 2021-12-14 21:28 ` Reinette Chatre
2021-12-14 21:55 ` Shuah Khan
0 siblings, 1 reply; 6+ messages in thread
From: Reinette Chatre @ 2021-12-14 21:28 UTC (permalink / raw)
To: Shuah Khan, dave.hansen, jarkko, linux-sgx, shuah; +Cc: linux-kselftest
Hi Shuah,
On 12/14/2021 12:10 PM, Shuah Khan wrote:
>
> Let's not add one more __cpuid() define to the individual tests.
> We so far have:
>
> tools/testing/selftests/vm/pkey-x86.h
> selftests/x86/corrupt_xstate_header.c
>
> Let's move the defines to kselftest.h and remove all these duplicate
> defines.
>
> For now you could include vm/pkey-x86.h just to fix the build error
> and do the proper cleanup.
Thank you so much for taking a look. We actually do have an alternative
fix that could be considered for the other users of __cpuid(). Instead
of another clone of the kernel's __cpuid() the fix includes cpuid.h and
uses the existing __cpuid_count() from it.
Please see:
https://lore.kernel.org/linux-sgx/20211204202355.23005-1-jarkko@kernel.org/
We decided against the above fix using __cpuid_count() because we could
not explain why all the existing users of __cpuid() implement their own
and decided to follow the custom instead ...
Do you see any problem with including cpuid.h into a selftest? If not,
then we can go back to our original fix of this issue and I could also
submit a change to remove all the __cpuid() clones and replace them with
the library's __cpuid_count().
Reinette
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2] selftests/sgx: Fix build error caused by missing dependency
2021-12-14 21:28 ` Reinette Chatre
@ 2021-12-14 21:55 ` Shuah Khan
2021-12-14 22:27 ` Reinette Chatre
0 siblings, 1 reply; 6+ messages in thread
From: Shuah Khan @ 2021-12-14 21:55 UTC (permalink / raw)
To: Reinette Chatre, dave.hansen, jarkko, linux-sgx, shuah
Cc: linux-kselftest, Shuah Khan
On 12/14/21 2:28 PM, Reinette Chatre wrote:
> Hi Shuah,
>
> On 12/14/2021 12:10 PM, Shuah Khan wrote:
>
>>
>> Let's not add one more __cpuid() define to the individual tests.
>> We so far have:
>>
>> tools/testing/selftests/vm/pkey-x86.h
>> selftests/x86/corrupt_xstate_header.c
>>
>> Let's move the defines to kselftest.h and remove all these duplicate
>> defines.
>>
>> For now you could include vm/pkey-x86.h just to fix the build error
>> and do the proper cleanup.
>
> Thank you so much for taking a look. We actually do have an alternative fix that could be considered for the other users of __cpuid(). Instead of another clone of the kernel's __cpuid() the fix includes cpuid.h and uses the existing __cpuid_count() from it.
>
> Please see:
> https://lore.kernel.org/linux-sgx/20211204202355.23005-1-jarkko@kernel.org/
>
This looks good to me.
> We decided against the above fix using __cpuid_count() because we could not explain why all the existing users of __cpuid() implement their own and decided to follow the custom instead ...
>
Most likely, copy and paste and taking the easy route. I looked at a couple of
defines and I dont't see a difference. If there are differences, that would be
a bigger concern. The whole idea of not having duplicates is that we don't have
bugs in these duplicates.
> Do you see any problem with including cpuid.h into a selftest? If not, then we can go back to our original fix of this issue and I could also submit a change to remove all the __cpuid() clones and replace them with the library's __cpuid_count().
>
There are no problems including cpuid.h - where is this though. I couldn't find
it in my cscope search?
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2] selftests/sgx: Fix build error caused by missing dependency
2021-12-14 21:55 ` Shuah Khan
@ 2021-12-14 22:27 ` Reinette Chatre
2021-12-14 22:59 ` Shuah Khan
0 siblings, 1 reply; 6+ messages in thread
From: Reinette Chatre @ 2021-12-14 22:27 UTC (permalink / raw)
To: Shuah Khan, dave.hansen, jarkko, linux-sgx, shuah; +Cc: linux-kselftest
Hi Shuah,
On 12/14/2021 1:55 PM, Shuah Khan wrote:
> On 12/14/21 2:28 PM, Reinette Chatre wrote:
>> Hi Shuah,
>>
>> On 12/14/2021 12:10 PM, Shuah Khan wrote:
>>
>>>
>>> Let's not add one more __cpuid() define to the individual tests.
>>> We so far have:
>>>
>>> tools/testing/selftests/vm/pkey-x86.h
>>> selftests/x86/corrupt_xstate_header.c
>>>
>>> Let's move the defines to kselftest.h and remove all these duplicate
>>> defines.
>>>
>>> For now you could include vm/pkey-x86.h just to fix the build error
>>> and do the proper cleanup.
>>
>> Thank you so much for taking a look. We actually do have an
>> alternative fix that could be considered for the other users of
>> __cpuid(). Instead of another clone of the kernel's __cpuid() the fix
>> includes cpuid.h and uses the existing __cpuid_count() from it.
>>
>> Please see:
>> https://lore.kernel.org/linux-sgx/20211204202355.23005-1-jarkko@kernel.org/
>>
>>
>
> This looks good to me.
Thank you very much for taking a look.
>
>> We decided against the above fix using __cpuid_count() because we
>> could not explain why all the existing users of __cpuid() implement
>> their own and decided to follow the custom instead ...
>>
>
> Most likely, copy and paste and taking the easy route. I looked at a
> couple of
> defines and I dont't see a difference. If there are differences, that
> would be
> a bigger concern. The whole idea of not having duplicates is that we
> don't have
> bugs in these duplicates.
>
>> Do you see any problem with including cpuid.h into a selftest? If not,
>> then we can go back to our original fix of this issue and I could also
>> submit a change to remove all the __cpuid() clones and replace them
>> with the library's __cpuid_count().
>>
>
> There are no problems including cpuid.h - where is this though. I
> couldn't find
> it in my cscope search?
On my system it arrived via user space's libgcc-dev package. This does
not seem to be the first time including files from this source - I did a
quick check and from what I can tell existing includes like stdarg.h,
stdbool.h, stdatomic.h, unwind.h, x86intrin.h ... arrive via libgcc-dev.
Do you still find that cpuid.h is ok to include?
Reinette
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2] selftests/sgx: Fix build error caused by missing dependency
2021-12-14 22:27 ` Reinette Chatre
@ 2021-12-14 22:59 ` Shuah Khan
0 siblings, 0 replies; 6+ messages in thread
From: Shuah Khan @ 2021-12-14 22:59 UTC (permalink / raw)
To: Reinette Chatre, dave.hansen, jarkko, linux-sgx, shuah
Cc: linux-kselftest, Shuah Khan
On 12/14/21 3:27 PM, Reinette Chatre wrote:
> Hi Shuah,
>
> On 12/14/2021 1:55 PM, Shuah Khan wrote:
>> On 12/14/21 2:28 PM, Reinette Chatre wrote:
>>> Hi Shuah,
>>>
>>> On 12/14/2021 12:10 PM, Shuah Khan wrote:
>>>
>>>>
>>>> Let's not add one more __cpuid() define to the individual tests.
>>>> We so far have:
>>>>
>>>> tools/testing/selftests/vm/pkey-x86.h
>>>> selftests/x86/corrupt_xstate_header.c
>>>>
>>>> Let's move the defines to kselftest.h and remove all these duplicate
>>>> defines.
>>>>
>>>> For now you could include vm/pkey-x86.h just to fix the build error
>>>> and do the proper cleanup.
>>>
>>> Thank you so much for taking a look. We actually do have an alternative fix that could be considered for the other users of __cpuid(). Instead of another clone of the kernel's __cpuid() the fix includes cpuid.h and uses the existing __cpuid_count() from it.
>>>
>>> Please see:
>>> https://lore.kernel.org/linux-sgx/20211204202355.23005-1-jarkko@kernel.org/
>>>
>>
>> This looks good to me.
>
> Thank you very much for taking a look.
>
>>
>>> We decided against the above fix using __cpuid_count() because we could not explain why all the existing users of __cpuid() implement their own and decided to follow the custom instead ...
>>>
>>
>> Most likely, copy and paste and taking the easy route. I looked at a couple of
>> defines and I dont't see a difference. If there are differences, that would be
>> a bigger concern. The whole idea of not having duplicates is that we don't have
>> bugs in these duplicates.
>>
>>> Do you see any problem with including cpuid.h into a selftest? If not, then we can go back to our original fix of this issue and I could also submit a change to remove all the __cpuid() clones and replace them with the library's __cpuid_count().
>>>
>>
>> There are no problems including cpuid.h - where is this though. I couldn't find
>> it in my cscope search?
>
> On my system it arrived via user space's libgcc-dev package. This does not seem to be the first time including files from this source - I did a quick check and from what I can tell existing includes like stdarg.h, stdbool.h, stdatomic.h, unwind.h, x86intrin.h ... arrive via libgcc-dev.
>
> Do you still find that cpuid.h is ok to include?
>
> Reinette
Yes. I found it on my system as well.
/usr/lib/llvm-13/lib/clang/13.0.0/include/cpuid.h
/usr/lib/llvm-12/lib/clang/12.0.1/include/cpuid.h
/usr/lib/gcc/x86_64-linux-gnu/11/include/cpuid.h
/usr/lib/gcc/x86_64-linux-gnu/10/include/cpuid.h
No problems using it.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-12-14 22:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 19:26 [PATCH V2] selftests/sgx: Fix build error caused by missing dependency Reinette Chatre
2021-12-14 20:10 ` Shuah Khan
2021-12-14 21:28 ` Reinette Chatre
2021-12-14 21:55 ` Shuah Khan
2021-12-14 22:27 ` Reinette Chatre
2021-12-14 22:59 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).