* [PATCH v3 0/2] x86: Fix ARCH_REQ_XCOMP_PERM and update the test
@ 2021-11-10 0:32 Chang S. Bae
2021-11-10 0:32 ` [PATCH v3 1/2] x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation Chang S. Bae
2021-11-10 0:32 ` [PATCH v3 2/2] selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test Chang S. Bae
0 siblings, 2 replies; 3+ messages in thread
From: Chang S. Bae @ 2021-11-10 0:32 UTC (permalink / raw)
To: linux-kernel
Cc: x86, tglx, dave.hansen, bp, mingo, yang.zhong, jing2.liu, chang.seok.bae
Fixed the authorship from V2:
https://lore.kernel.org/lkml/20211109012122.1142-1-chang.seok.bae@intel.com/
---
The recent x86 dynamic state support incorporates the arch_prctl option to
request permission before using a dynamic state.
It was designed to add the requested feature in the group leader's
permission bitmask so that every thread can reference this master bitmask.
The group leader is assumed to be unchanged here. The mainline is the case
as a group leader is identified at fork() or exec() time only.
This master bitmask should include non-dynamic features always, as they
are permitted by default. Users may check them via ARCH_GET_XCOMP_PERM.
But, in hindsight, the implementation does overwrite the bitmask with the
requested bit only, instead of adding the bit to the existing one. This
overwrite effectively revokes the permission that is granted already.
Fix the code and also update the selftest to disclose the issue if there
is.
Cc: Yang Zhong <yang.zhong@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Chang S. Bae (1):
selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test
Yang Zhong (1):
x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation
arch/x86/kernel/fpu/xstate.c | 2 +-
tools/testing/selftests/x86/amx.c | 16 ++++++++++++++--
2 files changed, 15 insertions(+), 3 deletions(-)
base-commit: 9a6cf455a952725422f4fb10848839989f833579
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 1/2] x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation
2021-11-10 0:32 [PATCH v3 0/2] x86: Fix ARCH_REQ_XCOMP_PERM and update the test Chang S. Bae
@ 2021-11-10 0:32 ` Chang S. Bae
2021-11-10 0:32 ` [PATCH v3 2/2] selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test Chang S. Bae
1 sibling, 0 replies; 3+ messages in thread
From: Chang S. Bae @ 2021-11-10 0:32 UTC (permalink / raw)
To: linux-kernel
Cc: x86, tglx, dave.hansen, bp, mingo, yang.zhong, jing2.liu, chang.seok.bae
From: Yang Zhong <yang.zhong@intel.com>
ARCH_REQ_XCOMP_PERM is supposed to add the requested feature to the
permission bitmap of thread_group_leader()->fpu. But the code overwrites
the bitmap with the requested feature bit only rather than adding it.
Fix the code to add the request feature bit to the master bitmask.
Fixes: db8268df0983 ("x86/arch_prctl: Add controls for dynamic XSTATE components")
Signed-off-by: Yang Zhong <yang.zhong@intel.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
---
Changes from v2:
* Fix the authorship.
Changes from v1:
* Change the mask value only and trim the changelog.
---
arch/x86/kernel/fpu/xstate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index d28829403ed0..fc1ab0116f4e 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -1626,7 +1626,7 @@ static int __xstate_request_perm(u64 permitted, u64 requested)
return ret;
/* Pairs with the READ_ONCE() in xstate_get_group_perm() */
- WRITE_ONCE(fpu->perm.__state_perm, requested);
+ WRITE_ONCE(fpu->perm.__state_perm, mask);
/* Protected by sighand lock */
fpu->perm.__state_size = ksize;
fpu->perm.__user_state_size = usize;
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3 2/2] selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test
2021-11-10 0:32 [PATCH v3 0/2] x86: Fix ARCH_REQ_XCOMP_PERM and update the test Chang S. Bae
2021-11-10 0:32 ` [PATCH v3 1/2] x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation Chang S. Bae
@ 2021-11-10 0:32 ` Chang S. Bae
1 sibling, 0 replies; 3+ messages in thread
From: Chang S. Bae @ 2021-11-10 0:32 UTC (permalink / raw)
To: linux-kernel
Cc: x86, tglx, dave.hansen, bp, mingo, yang.zhong, jing2.liu,
chang.seok.bae, linux-kselftest
Update the arch_prctl() test to check the permission bitmap whether the
requested feature is added as expected or not.
Every non-dynamic feature that is enabled is permitted already for use.
TILECFG is not dynamic feature. Ensure the bit is always on from
ARCH_GET_XCOMP_PERM.
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: linux-kselftest@vger.kernel.org
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
---
tools/testing/selftests/x86/amx.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x86/amx.c
index 3615ef4a48bb..e1e2c8f3356f 100644
--- a/tools/testing/selftests/x86/amx.c
+++ b/tools/testing/selftests/x86/amx.c
@@ -368,9 +368,16 @@ static void req_xtiledata_perm(void)
static void validate_req_xcomp_perm(enum expected_result exp)
{
- unsigned long bitmask;
+ unsigned long bitmask, expected_bitmask;
long rc;
+ rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_PERM, &bitmask);
+ if (rc) {
+ fatal_error("prctl(ARCH_GET_XCOMP_PERM) error: %ld", rc);
+ } else if (!(bitmask & XFEATURE_MASK_XTILECFG)) {
+ fatal_error("ARCH_GET_XCOMP_PERM returns XFEATURE_XTILECFG off.");
+ }
+
rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_PERM, XFEATURE_XTILEDATA);
if (exp == FAIL_EXPECTED) {
if (rc) {
@@ -383,10 +390,15 @@ static void validate_req_xcomp_perm(enum expected_result exp)
fatal_error("ARCH_REQ_XCOMP_PERM saw unexpected failure.\n");
}
+ expected_bitmask = bitmask | XFEATURE_MASK_XTILEDATA;
+
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_PERM, &bitmask);
if (rc) {
fatal_error("prctl(ARCH_GET_XCOMP_PERM) error: %ld", rc);
- } else if (bitmask & XFEATURE_MASK_XTILE) {
+ } else if (bitmask != expected_bitmask) {
+ fatal_error("ARCH_REQ_XCOMP_PERM saw a wrong bitmask: %lx, expected: %lx.\n",
+ bitmask, expected_bitmask);
+ } else {
printf("\tARCH_REQ_XCOMP_PERM is successful.\n");
}
}
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-10 0:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-10 0:32 [PATCH v3 0/2] x86: Fix ARCH_REQ_XCOMP_PERM and update the test Chang S. Bae
2021-11-10 0:32 ` [PATCH v3 1/2] x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation Chang S. Bae
2021-11-10 0:32 ` [PATCH v3 2/2] selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test Chang S. Bae
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).