* [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation
@ 2021-12-04 20:23 Jarkko Sakkinen
2021-12-05 0:32 ` Reinette Chatre
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Jarkko Sakkinen @ 2021-12-04 20:23 UTC (permalink / raw)
To: Shuah Khan
Cc: Dave Hansen, Reinette Chatre, linux-kselftest, linux-sgx,
Jarkko Sakkinen
Compilation results:
$ make -C tools/testing/selftests/sgx/
make: Entering directory '/home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx'
gcc -Wall -Werror -g -I../../../../tools/include -fPIC -z noexecstack -c main.c -o /home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx/main.o
main.c: In function ‘get_total_epc_mem’:
main.c:296:17: 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: /home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx/main.o] Error 1
make: Leaving directory '/home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx'
Include to cpuid.h is missing and the macro usage is incorrect.
Include cpuid.h and use __cpuid_count() macro in order to fix the
compilation issue.
Fixes: f0ff2447b861 ("selftests/sgx: Add a new kselftest: Unclobbered_vdso_oversubscribed")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
tools/testing/selftests/sgx/main.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index 7e912db4c6c5..370c4995f7c4 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2016-20 Intel Corporation. */
+#include <cpuid.h>
#include <elf.h>
#include <errno.h>
#include <fcntl.h>
@@ -291,9 +292,7 @@ static unsigned long get_total_epc_mem(void)
int section = 0;
while (true) {
- eax = SGX_CPUID;
- ecx = section + SGX_CPUID_EPC;
- __cpuid(&eax, &ebx, &ecx, &edx);
+ __cpuid_count(SGX_CPUID, section + SGX_CPUID_EPC, eax, ebx, ecx, edx);
type = eax & SGX_CPUID_EPC_MASK;
if (type == SGX_CPUID_EPC_INVALID)
--
2.32.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation
2021-12-04 20:23 [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation Jarkko Sakkinen
@ 2021-12-05 0:32 ` Reinette Chatre
2021-12-06 22:54 ` Dave Hansen
2021-12-15 0:19 ` Reinette Chatre
2021-12-17 16:58 ` [tip: x86/sgx] " tip-bot2 for Jarkko Sakkinen
2 siblings, 1 reply; 8+ messages in thread
From: Reinette Chatre @ 2021-12-05 0:32 UTC (permalink / raw)
To: Jarkko Sakkinen, Shuah Khan; +Cc: Dave Hansen, linux-kselftest, linux-sgx
Hi Jarkko,
(Dave: I am very sorry - selftests on x86/sgx on tip.git is currently
broken because of this)
On 12/4/2021 12:23 PM, Jarkko Sakkinen wrote:
> Compilation results:
>
> $ make -C tools/testing/selftests/sgx/
> make: Entering directory '/home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx'
> gcc -Wall -Werror -g -I../../../../tools/include -fPIC -z noexecstack -c main.c -o /home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx/main.o
> main.c: In function ‘get_total_epc_mem’:
> main.c:296:17: 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: /home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx/main.o] Error 1
> make: Leaving directory '/home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx'
>
> Include to cpuid.h is missing and the macro usage is incorrect.
>
> Include cpuid.h and use __cpuid_count() macro in order to fix the
> compilation issue.
>
> Fixes: f0ff2447b861 ("selftests/sgx: Add a new kselftest: Unclobbered_vdso_oversubscribed")
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
I am sorry - this was my mistake because of a last minute change to that
patch that I submitted with a dependency that only arrives in a later
patch that is not upstream yet.
Jarkko, thank you very much for catching this.
I am not sure what the right way is to fix it though - my original
intention, what the code uses, was to add a snippet as below as is the
custom for all tests needing to run cpuid. There are many usages of
cpuid among the selftests but none rely on the cpuid.h to bring in
__cpuid_count. I do not know the motivation for this but preferred to
stick with the custom for my implementation.
+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");
+}
Reinette
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation
2021-12-05 0:32 ` Reinette Chatre
@ 2021-12-06 22:54 ` Dave Hansen
2021-12-06 23:32 ` Reinette Chatre
0 siblings, 1 reply; 8+ messages in thread
From: Dave Hansen @ 2021-12-06 22:54 UTC (permalink / raw)
To: Reinette Chatre, Jarkko Sakkinen, Shuah Khan
Cc: Dave Hansen, linux-kselftest, linux-sgx
On 12/4/21 4:32 PM, Reinette Chatre wrote:
> I am not sure what the right way is to fix it though - my original
> intention, what the code uses, was to add a snippet as below as is the
> custom for all tests needing to run cpuid. There are many usages of
> cpuid among the selftests but none rely on the cpuid.h to bring in
> __cpuid_count. I do not know the motivation for this but preferred to
> stick with the custom for my implementation.
>
> +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");
> +}
Reinette, is there some reason using __cpuid_count() won't work for the
SGX test? Or is your concern that it _might_ break something because
you haven't tested it?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation
2021-12-06 22:54 ` Dave Hansen
@ 2021-12-06 23:32 ` Reinette Chatre
2021-12-06 23:36 ` Dave Hansen
0 siblings, 1 reply; 8+ messages in thread
From: Reinette Chatre @ 2021-12-06 23:32 UTC (permalink / raw)
To: Dave Hansen, Jarkko Sakkinen, Shuah Khan
Cc: Dave Hansen, linux-kselftest, linux-sgx
Hi Dave,
On 12/6/2021 2:54 PM, Dave Hansen wrote:
> On 12/4/21 4:32 PM, Reinette Chatre wrote:
>> I am not sure what the right way is to fix it though - my original
>> intention, what the code uses, was to add a snippet as below as is the
>> custom for all tests needing to run cpuid. There are many usages of
>> cpuid among the selftests but none rely on the cpuid.h to bring in
>> __cpuid_count. I do not know the motivation for this but preferred to
>> stick with the custom for my implementation.
>>
>> +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");
>> +}
>
> Reinette, is there some reason using __cpuid_count() won't work for the
> SGX test? Or is your concern that it _might_ break something because
> you haven't tested it?
As a sanity check I tested with __cpuid_count() and it works.
My concern is actually about the kselftest framework where I could not
answer the following question with certainty: why are there so many
usages of cpuid but everybody writes their own instead of including
cpuid.h? I am concerned that there are some environment constraints that
I am not familiar with and thus decided to follow the custom.
One speculation is that since cpuid.h arrives with libgcc's dev package
instead of the regular libc dev package there may now be a new
dependency on what users need to have on their systems to run these tests.
Reinette
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation
2021-12-06 23:32 ` Reinette Chatre
@ 2021-12-06 23:36 ` Dave Hansen
0 siblings, 0 replies; 8+ messages in thread
From: Dave Hansen @ 2021-12-06 23:36 UTC (permalink / raw)
To: Reinette Chatre, Jarkko Sakkinen, Shuah Khan
Cc: Dave Hansen, linux-kselftest, linux-sgx
On 12/6/21 3:32 PM, Reinette Chatre wrote:
> My concern is actually about the kselftest framework where I could not
> answer the following question with certainty: why are there so many
> usages of cpuid but everybody writes their own instead of including
> cpuid.h? I am concerned that there are some environment constraints that
> I am not familiar with and thus decided to follow the custom.
I'm probably guilty of a case or two. There was no logic behind it,
just that I took and out-of-tree test and plopped it into the kernel
tree without looking for any selftest infrastructure.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation
2021-12-04 20:23 [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation Jarkko Sakkinen
2021-12-05 0:32 ` Reinette Chatre
@ 2021-12-15 0:19 ` Reinette Chatre
2021-12-22 0:40 ` Jarkko Sakkinen
2021-12-17 16:58 ` [tip: x86/sgx] " tip-bot2 for Jarkko Sakkinen
2 siblings, 1 reply; 8+ messages in thread
From: Reinette Chatre @ 2021-12-15 0:19 UTC (permalink / raw)
To: Jarkko Sakkinen, Shuah Khan; +Cc: Dave Hansen, linux-kselftest, linux-sgx
Hi Dave and Jarkko,
On 12/4/2021 12:23 PM, Jarkko Sakkinen wrote:
> Compilation results:
>
> $ make -C tools/testing/selftests/sgx/
> make: Entering directory '/home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx'
> gcc -Wall -Werror -g -I../../../../tools/include -fPIC -z noexecstack -c main.c -o /home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx/main.o
> main.c: In function ‘get_total_epc_mem’:
> main.c:296:17: 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: /home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx/main.o] Error 1
> make: Leaving directory '/home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx'
>
> Include to cpuid.h is missing and the macro usage is incorrect.
>
> Include cpuid.h and use __cpuid_count() macro in order to fix the
> compilation issue.
>
> Fixes: f0ff2447b861 ("selftests/sgx: Add a new kselftest: Unclobbered_vdso_oversubscribed")
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> ---
> tools/testing/selftests/sgx/main.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
> index 7e912db4c6c5..370c4995f7c4 100644
> --- a/tools/testing/selftests/sgx/main.c
> +++ b/tools/testing/selftests/sgx/main.c
> @@ -1,6 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0
> /* Copyright(c) 2016-20 Intel Corporation. */
>
> +#include <cpuid.h>
> #include <elf.h>
> #include <errno.h>
> #include <fcntl.h>
> @@ -291,9 +292,7 @@ static unsigned long get_total_epc_mem(void)
> int section = 0;
>
> while (true) {
> - eax = SGX_CPUID;
> - ecx = section + SGX_CPUID_EPC;
> - __cpuid(&eax, &ebx, &ecx, &edx);
> + __cpuid_count(SGX_CPUID, section + SGX_CPUID_EPC, eax, ebx, ecx, edx);
>
> type = eax & SGX_CPUID_EPC_MASK;
> if (type == SGX_CPUID_EPC_INVALID)
Shuah confirmed ([1]) that there is no problem including cpuid.h and
that this is the preferred fix.
Thank you very much Jarkko.
Acked-by: Reinette Chatre <reinette.chatre@intel.com>
Reinette
[1]
https://lore.kernel.org/linux-kselftest/63293c72-55ca-9446-35eb-74aff4c8ba5d@linuxfoundation.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [tip: x86/sgx] selftests/sgx: Fix corrupted cpuid macro invocation
2021-12-04 20:23 [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation Jarkko Sakkinen
2021-12-05 0:32 ` Reinette Chatre
2021-12-15 0:19 ` Reinette Chatre
@ 2021-12-17 16:58 ` tip-bot2 for Jarkko Sakkinen
2 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for Jarkko Sakkinen @ 2021-12-17 16:58 UTC (permalink / raw)
To: linux-tip-commits
Cc: Jarkko Sakkinen, Dave Hansen, Reinette Chatre, Shuah Khan, x86,
linux-kernel
The following commit has been merged into the x86/sgx branch of tip:
Commit-ID: 572a0a647b9b491729d24c083c8410c55bf16326
Gitweb: https://git.kernel.org/tip/572a0a647b9b491729d24c083c8410c55bf16326
Author: Jarkko Sakkinen <jarkko@kernel.org>
AuthorDate: Sat, 04 Dec 2021 22:23:55 +02:00
Committer: Dave Hansen <dave.hansen@linux.intel.com>
CommitterDate: Fri, 17 Dec 2021 08:52:33 -08:00
selftests/sgx: Fix corrupted cpuid macro invocation
The SGX selftest fails to build on tip/x86/sgx:
main.c: In function ‘get_total_epc_mem’:
main.c:296:17: error: implicit declaration of function ‘__cpuid’ [-Werror=implicit-function-declaration]
296 | __cpuid(&eax, &ebx, &ecx, &edx);
| ^~~~~~~
Include cpuid.h and use __cpuid_count() macro in order to fix the
compilation issue.
[ dhansen: tweak commit message ]
Fixes: f0ff2447b861 ("selftests/sgx: Add a new kselftest: Unclobbered_vdso_oversubscribed")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lkml.kernel.org/r/20211204202355.23005-1-jarkko@kernel.org
Cc: Shuah Khan <shuah@kernel.org>
---
tools/testing/selftests/sgx/main.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index 7e912db..370c499 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2016-20 Intel Corporation. */
+#include <cpuid.h>
#include <elf.h>
#include <errno.h>
#include <fcntl.h>
@@ -291,9 +292,7 @@ static unsigned long get_total_epc_mem(void)
int section = 0;
while (true) {
- eax = SGX_CPUID;
- ecx = section + SGX_CPUID_EPC;
- __cpuid(&eax, &ebx, &ecx, &edx);
+ __cpuid_count(SGX_CPUID, section + SGX_CPUID_EPC, eax, ebx, ecx, edx);
type = eax & SGX_CPUID_EPC_MASK;
if (type == SGX_CPUID_EPC_INVALID)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation
2021-12-15 0:19 ` Reinette Chatre
@ 2021-12-22 0:40 ` Jarkko Sakkinen
0 siblings, 0 replies; 8+ messages in thread
From: Jarkko Sakkinen @ 2021-12-22 0:40 UTC (permalink / raw)
To: Reinette Chatre; +Cc: Shuah Khan, Dave Hansen, linux-kselftest, linux-sgx
On Tue, Dec 14, 2021 at 04:19:24PM -0800, Reinette Chatre wrote:
> Hi Dave and Jarkko,
>
> On 12/4/2021 12:23 PM, Jarkko Sakkinen wrote:
> > Compilation results:
> >
> > $ make -C tools/testing/selftests/sgx/
> > make: Entering directory '/home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx'
> > gcc -Wall -Werror -g -I../../../../tools/include -fPIC -z noexecstack -c main.c -o /home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx/main.o
> > main.c: In function ‘get_total_epc_mem’:
> > main.c:296:17: 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: /home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx/main.o] Error 1
> > make: Leaving directory '/home/jarkko/Projects/linux-sgx/tools/testing/selftests/sgx'
> >
> > Include to cpuid.h is missing and the macro usage is incorrect.
> >
> > Include cpuid.h and use __cpuid_count() macro in order to fix the
> > compilation issue.
> >
> > Fixes: f0ff2447b861 ("selftests/sgx: Add a new kselftest: Unclobbered_vdso_oversubscribed")
> > Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> > ---
> > tools/testing/selftests/sgx/main.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
> > index 7e912db4c6c5..370c4995f7c4 100644
> > --- a/tools/testing/selftests/sgx/main.c
> > +++ b/tools/testing/selftests/sgx/main.c
> > @@ -1,6 +1,7 @@
> > // SPDX-License-Identifier: GPL-2.0
> > /* Copyright(c) 2016-20 Intel Corporation. */
> > +#include <cpuid.h>
> > #include <elf.h>
> > #include <errno.h>
> > #include <fcntl.h>
> > @@ -291,9 +292,7 @@ static unsigned long get_total_epc_mem(void)
> > int section = 0;
> > while (true) {
> > - eax = SGX_CPUID;
> > - ecx = section + SGX_CPUID_EPC;
> > - __cpuid(&eax, &ebx, &ecx, &edx);
> > + __cpuid_count(SGX_CPUID, section + SGX_CPUID_EPC, eax, ebx, ecx, edx);
> > type = eax & SGX_CPUID_EPC_MASK;
> > if (type == SGX_CPUID_EPC_INVALID)
>
>
> Shuah confirmed ([1]) that there is no problem including cpuid.h and that
> this is the preferred fix.
>
> Thank you very much Jarkko.
>
> Acked-by: Reinette Chatre <reinette.chatre@intel.com>
>
> Reinette
>
> [1] https://lore.kernel.org/linux-kselftest/63293c72-55ca-9446-35eb-74aff4c8ba5d@linuxfoundation.org/
OK, cool, thanks!
/Jarkko
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-12-22 0:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-04 20:23 [PATCH] selftests/sgx: Fix corrupted cpuid macro invocation Jarkko Sakkinen
2021-12-05 0:32 ` Reinette Chatre
2021-12-06 22:54 ` Dave Hansen
2021-12-06 23:32 ` Reinette Chatre
2021-12-06 23:36 ` Dave Hansen
2021-12-15 0:19 ` Reinette Chatre
2021-12-22 0:40 ` Jarkko Sakkinen
2021-12-17 16:58 ` [tip: x86/sgx] " tip-bot2 for Jarkko Sakkinen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.