Skip to contentSkip to conversation

x86: Fix ARCH_REQ_XCOMP_PERM and update the test

PATCH Applied Chang S. Bae 5 participants 16 messages Jan 29, 2022 – Mar 23, 2022

Subsystems (5)
Stable branch x86 KVM Kselftest +1 more subsystems
lore
Share & tools
lore
#0 lore raw

v4 cover x86: Fix ARCH_REQ_XCOMP_PERM and update the test

Changes from V3:
* Rebased onto 5.17-rc1.

V3: https://lore.kernel.org/lkml/[email protected]/

---

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.

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: e783362eb54cd99b2cac8b3a9aeac942e6f6ac07

Signature · 1 line
2.17.1
#1 lore raw

PATCH v4 1/2 x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation

From: Yang Zhong <[email protected]>

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")
Cc Thomas Gleixner <[email protected]>

---
Changes from v3:
* Adjust the change to the mainline (v5.17-rc).

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(-)
arch/x86/kernel/fpu/xstate.c +1 -1
index 02b3ddaf4f75..2d4363e32517 100644
@@ -1636,7 +1636,7 @@ static int __xstate_request_perm(u64 permitted, u64 requested, bool guest)
 
 	perm = guest ? &fpu->guest_perm : &fpu->perm;
 	/* Pairs with the READ_ONCE() in xstate_get_group_perm() */
-	WRITE_ONCE(perm->__state_perm, requested);
+	WRITE_ONCE(perm->__state_perm, mask);
 	/* Protected by sighand lock */
 	perm->__state_size = ksize;
 	perm->__user_state_size = usize;
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v4 1/2] x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation

x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation

If WRITE_ONCE(perm->__state_perm, requested) is modified to
WRITE_ONCE(perm->__state_perm, mask), When the qemu process does not request the XFEATURE_MASK_XTILE_DATA xsave state permission, there may be a gp error (kvm: kvm_set_xcr line 1091 inject gp fault with cpl 0) because __kvm_set_xcr return 1.

static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr){
    ...
    // xcr0 includes XFEATURE_MASK_XTILE_CFG by default.
    if ((xcr0 & XFEATURE_MASK_XTILE) &&
        ((xcr0 & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE))
        return 1;
    ...
}
arch/x86/kernel/fpu/xstate.c +1 -1
index 02b3dda..2d4363e 100644
@@ -1636,7 +1636,7 @@ static int __xstate_request_perm(u64 permitted, u64 requested, bool guest)
 
        perm = guest ? &fpu->guest_perm : &fpu->perm;
        /* Pairs with the READ_ONCE() in xstate_get_group_perm() */
-       WRITE_ONCE(perm->__state_perm, requested);
+       WRITE_ONCE(perm->__state_perm, mask);
        /* Protected by sighand lock */
        perm->__state_size = ksize;
        perm->__user_state_size = usize;
arch/x86/kvm/cpuid.c +0 -0
index 494d4d3..e8704568 100644
@@ -908,6 +908,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
                break;
        case 0xd: {
                u64 permitted_xcr0 = supported_xcr0 & 

xstate_get_guest_group_perm();
+ permitted_xcr0 = ((permitted_xcr0 & XFEATURES_MASK_XTILE) != XFEATURES_MASK_XTILE)
+ ? permitted_xcr0

+                               : permitted_xcr0 & ~XFEATURES_MASK_XTILE;
                u64 permitted_xss = supported_xss;

                entry->eax &= permitted_xcr0;
#3 lore raw

Re: [PATCH v4 1/2] x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation

Quoted 4 lines · Hao Xiang

x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation

If WRITE_ONCE(perm->__state_perm, requested) is modified to
WRITE_ONCE(perm->__state_perm, mask), When the qemu process does not request the XFEATURE_MASK_XTILE_DATA xsave state permission, there may be a gp error (kvm: kvm_set_xcr line 1091 inject gp fault with cpl 0) because __kvm_set_xcr return 1.

What you said here does not make sense to me. When the Qemu process does not request XTILEDATA, then the __xstate_request_perm() function is never called in this, no?

Quoted 29 lines

static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr){
    ...
    // xcr0 includes XFEATURE_MASK_XTILE_CFG by default. if ((xcr0 & XFEATURE_MASK_XTILE) &&
        ((xcr0 & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE)) return 1;
    ...
}

arch/x86/kernel/fpu/xstate.c +1 -1
index 02b3dda..2d4363e 100644
@@ -1636,7 +1636,7 @@ static int __xstate_request_perm(u64 permitted, 
 u64 requested, bool guest)
 
         perm = guest ? &fpu->guest_perm : &fpu->perm;
         /* Pairs with the READ_ONCE() in xstate_get_group_perm() */
-       WRITE_ONCE(perm->__state_perm, requested);
+       WRITE_ONCE(perm->__state_perm, mask);
         /* Protected by sighand lock */
         perm->__state_size = ksize;

        perm->__user_state_size = usize;

arch/x86/kvm/cpuid.c +0 -0
index 494d4d3..e8704568 100644

arch/x86/kvm/cpuid.c static inline int __do_cpuid_func(struct · line 912

Quoted 5 lines
arch/x86/kvm/cpuid.c +0 -0
@@ -908,6 +908,9 @@ static inline int __do_cpuid_func(struct 
 kvm_cpuid_array *array, u32 function)
                 break;
         case 0xd: {
                 u64 permitted_xcr0 = supported_xcr0 & 
 xstate_get_guest_group_perm();

Yang, I think you should have included your fix [1] in your series [2] in the first place, before using it widely like [3].

Quoted 8 lines
arch/x86/kvm/cpuid.c +3 -0
+               permitted_xcr0 = ((permitted_xcr0 & 
 XFEATURES_MASK_XTILE) != XFEATURES_MASK_XTILE)
+                               ? permitted_xcr0
+                               : permitted_xcr0 & ~XFEATURES_MASK_XTILE;

                u64 permitted_xss = supported_xss;

                entry->eax &= permitted_xcr0;

Well, first of all, one patch should fix one issue, not two or more, no?

But this hunk looks duplicate with this [4].

Thanks,
Chang

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
[4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kvm/x86.c#n1033

#4 lore raw

Re: [PATCH v4 1/2] x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation

Using the linux upsteam code with your patches,the problem is not reproduced. Maybe my patches are incomplete.

Thanks,
Hao

Quoted 66 lines · Chang S. Bae
Quoted 4 lines · Hao Xiang

x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation

If WRITE_ONCE(perm->__state_perm, requested) is modified to
WRITE_ONCE(perm->__state_perm, mask), When the qemu process does not request the XFEATURE_MASK_XTILE_DATA xsave state permission, there may be a gp error (kvm: kvm_set_xcr line 1091 inject gp fault with cpl 0) because __kvm_set_xcr return 1.

What you said here does not make sense to me. When the Qemu process does not request XTILEDATA, then the __xstate_request_perm() function is never called in this, no?

Quoted 29 lines

static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr){
     ...
     // xcr0 includes XFEATURE_MASK_XTILE_CFG by default. if ((xcr0 & XFEATURE_MASK_XTILE) &&
         ((xcr0 & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE)) return 1;
     ...
}

arch/x86/kernel/fpu/xstate.c +1 -1
index 02b3dda..2d4363e 100644
@@ -1636,7 +1636,7 @@ static int __xstate_request_perm(u64 permitted, 
 u64 requested, bool guest)
 
          perm = guest ? &fpu->guest_perm : &fpu->perm;
          /* Pairs with the READ_ONCE() in xstate_get_group_perm() */
-       WRITE_ONCE(perm->__state_perm, requested);
+       WRITE_ONCE(perm->__state_perm, mask);
          /* Protected by sighand lock */
          perm->__state_size = ksize;

         perm->__user_state_size = usize;

arch/x86/kvm/cpuid.c +0 -0
index 494d4d3..e8704568 100644

arch/x86/kvm/cpuid.c static inline int __do_cpuid_func(struct · line 911

Quoted 4 lines
arch/x86/kvm/cpuid.c +0 -0
@@ -908,6 +908,9 @@ static inline int __do_cpuid_func(struct 
 kvm_cpuid_array *array, u32 function)
                  break;
          case 0xd: {
                  u64 permitted_xcr0 = supported_xcr0 & xstate_get_guest_group_perm();

Yang, I think you should have included your fix [1] in your series [2] in the first place, before using it widely like [3].

Quoted 8 lines
arch/x86/kvm/cpuid.c +3 -0
+               permitted_xcr0 = ((permitted_xcr0 & 
 XFEATURES_MASK_XTILE) != XFEATURES_MASK_XTILE)
+                               ? permitted_xcr0
+                               : permitted_xcr0 & ~XFEATURES_MASK_XTILE;
                  u64 permitted_xss = supported_xss;

                 entry->eax &= permitted_xcr0;

Well, first of all, one patch should fix one issue, not two or more, no?

But this hunk looks duplicate with this [4].

Thanks,
Chang

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
[4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kvm/x86.c#n1033

merge bot Applied
#5 lore raw

[tip: x86/urgent] x86/fpu/xstate: Fix the ARCH_REQ_XCOMP_PERM implementation

In reply to Chang S. Bae
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     063452fd94d153d4eb38ad58f210f3d37a09cca4
Gitweb:        https://git.kernel.org/tip/063452fd94d153d4eb38ad58f210f3d37a09cca4
Author:        Yang Zhong <[email protected]>
AuthorDate:    Sat, 29 Jan 2022 09:36:46 -08:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Wed, 23 Mar 2022 21:28:34 +01:00

x86/fpu/xstate: Fix the ARCH_REQ_XCOMP_PERM implementation

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 requested feature bit to the master bitmask.

Fixes db8268df0983 ("x86/arch_prctl: Add controls for dynamic XSTATE components")
Cc Paolo Bonzini <[email protected]>
---
 arch/x86/kernel/fpu/xstate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/fpu/xstate.c +1 -1
index 7c7824a..dc6d5e9 100644
@@ -1639,7 +1639,7 @@ static int __xstate_request_perm(u64 permitted, u64 requested, bool guest)
 
 	perm = guest ? &fpu->guest_perm : &fpu->perm;
 	/* Pairs with the READ_ONCE() in xstate_get_group_perm() */
-	WRITE_ONCE(perm->__state_perm, requested);
+	WRITE_ONCE(perm->__state_perm, mask);
 	/* Protected by sighand lock */
 	perm->__state_size = ksize;
 	perm->__user_state_size = usize;
#6 lore raw

PATCH v4 2/2 selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test

In reply to Chang S. Bae

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.

---
 tools/testing/selftests/x86/amx.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
tools/testing/selftests/x86/amx.c +14 -2
index 3615ef4a48bb..e1e2c8f3356f 100644
@@ -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");
 	}
 }
Signature · 1 line
2.17.1
#7 lore raw

Re: [PATCH v4 2/2] selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test

Quoted 6 lines · Chang S. Bae

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.

Running it on a machine which does not have AMX results in:

amx_64: [FAIL] xstate cpuid: invalid tile data size/offset: 0/0: Success

It's not a failure, really. Selftests are supposed to run on all machines and the proper thing to do if a hardware feature is not available is to SKIP the test and return 0.

Thanks,

tglx

#8 lore raw

Re: [PATCH v4 2/2] selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test

Quoted 8 lines · Thomas Gleixner

Running it on a machine which does not have AMX results in:

amx_64: [FAIL] xstate cpuid: invalid tile data size/offset: 0/0: Success

It's not a failure, really. Selftests are supposed to run on all machines and the proper thing to do if a hardware feature is not available is to SKIP the test and return 0.

Ah, right. The test should be just *skipped* on non-AMX or even non-XSAVE systems.

Will follow up with a separate patch.

Thanks,
Chang

merge bot Applied
#9 lore raw

[tip: x86/urgent] selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test

In reply to Chang S. Bae
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     20df737561484cb2d42e537663c03a7311d2b3c1
Gitweb:        https://git.kernel.org/tip/20df737561484cb2d42e537663c03a7311d2b3c1
Author:        Chang S. Bae <[email protected]>
AuthorDate:    Sat, 29 Jan 2022 09:36:47 -08:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Wed, 23 Mar 2022 21:28:34 +01:00

selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test

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.

---
 tools/testing/selftests/x86/amx.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
tools/testing/selftests/x86/amx.c +14 -2
index 3615ef4..2189f03 100644
@@ -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 set a wrong bitmask: %lx, expected: %lx.\n",
+			    bitmask, expected_bitmask);
+	} else {
 		printf("\tARCH_REQ_XCOMP_PERM is successful.\n");
 	}
 }
#10 lore raw

ping Re: [PATCH v4 0/2] x86: Fix ARCH_REQ_XCOMP_PERM and update the test

In reply to Chang S. Bae

Thomas, Dave,

can this series be included in 5.18 and CCed to stable?

The bug makes the __state_perm field completely wrong. As a result, arch_prctl(ARCH_GET_XCOMP_PERM) only returns the features that were requested last, forgetting what was already in __state_perm (the "permitted" argument to __xstate_request_perm).

In KVM, it is a bit worse. It affects arch_prctl(ARCH_GET_XCOMP_GUEST_PERM) in the same way and also ioctl(KVM_GET_SUPPORTED_CPUID), but the bug can also make KVM return the wrong xsave state size to userspace. It's likely to go unnoticed by userspace until Intel adds non-dynamic states above a dynamic one, but potentially userspace could allocate a buffer that is too small.

Paolo

Quoted 37 lines · Chang S. Bae

Changes from V3:
* Rebased onto 5.17-rc1.

V3: https://lore.kernel.org/lkml/[email protected]/

---

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.

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: e783362eb54cd99b2cac8b3a9aeac942e6f6ac07

#11 lore raw

Re: ping Re: [PATCH v4 0/2] x86: Fix ARCH_REQ_XCOMP_PERM and update the test

Paolo,

Quoted 1 line · Paolo Bonzini

can this series be included in 5.18 and CCed to stable?

working on it. There is another issue with that which I'm currently looking into.

Thanks,

tglx

#12 lore raw

Re: ping Re: [PATCH v4 0/2] x86: Fix ARCH_REQ_XCOMP_PERM and update the test

Quoted 5 lines · Thomas Gleixner
Quoted 1 line · Paolo Bonzini

can this series be included in 5.18 and CCed to stable?

working on it. There is another issue with that which I'm currently looking into.

The size calculation for the kernel state fails to take supervisor states into account. Up to 5.18 that did not matter because ENQCMD/PASID was disabled. But now it matters...

Thanks,

tglx
---

arch/x86/kernel/fpu/xstate.c +2 -0
@@ -1625,6 +1625,8 @@ static int __xstate_request_perm(u64 per
 
 	/* Calculate the resulting kernel state size */
 	mask = permitted | requested;
+	/* Take supervisor states into account */
+	mask |= xfeatures_mask_supervisor();
 	ksize = xstate_calculate_size(mask, compacted);
 
 	/* Calculate the resulting user state size */
#13 lore raw

Re: ping Re: [PATCH v4 0/2] x86: Fix ARCH_REQ_XCOMP_PERM and update the test

arch/x86/kernel/fpu/xstate.c static int __xstate_request_perm(u64 per · line 1631

Quoted 10 lines · Thomas Gleixner
arch/x86/kernel/fpu/xstate.c +2 -0
@@ -1625,6 +1625,8 @@ static int __xstate_request_perm(u64 per
 
  	/* Calculate the resulting kernel state size */
  	mask = permitted | requested;
+	/* Take supervisor states into account */
+	mask |= xfeatures_mask_supervisor();
  	ksize = xstate_calculate_size(mask, compacted);
 

This should be only added in for the !guest case.

Paolo

#14 lore raw

Re: ping Re: [PATCH v4 0/2] x86: Fix ARCH_REQ_XCOMP_PERM and update the test

Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Thomas Gleixner
arch/x86/kernel/fpu/xstate.c +0 -0
@@ -1625,6 +1625,8 @@ static int __xstate_request_perm(u64 per
 
Quoted 8 lines

arch/x86/kernel/fpu/xstate.c static int __xstate_request_perm(u64 per · line 1631

Quoted 6 lines
arch/x86/kernel/fpu/xstate.c +2 -0
  	/* Calculate the resulting kernel state size */
  	mask = permitted | requested;
+	/* Take supervisor states into account */
+	mask |= xfeatures_mask_supervisor();
  	ksize = xstate_calculate_size(mask, compacted);
 

This should be only added in for the !guest case.

Yes, I figured that out already :)

#15 lore raw

Re: ping Re: [PATCH v4 0/2] x86: Fix ARCH_REQ_XCOMP_PERM and update the test

Quoted 15 lines · Thomas Gleixner
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Thomas Gleixner
arch/x86/kernel/fpu/xstate.c +0 -0
@@ -1625,6 +1625,8 @@ static int __xstate_request_perm(u64 per
 
Quoted 8 lines

arch/x86/kernel/fpu/xstate.c static int __xstate_request_perm(u64 per · line 1631

Quoted 6 lines
arch/x86/kernel/fpu/xstate.c +2 -0
  	/* Calculate the resulting kernel state size */
  	mask = permitted | requested;
+	/* Take supervisor states into account */
+	mask |= xfeatures_mask_supervisor();
  	ksize = xstate_calculate_size(mask, compacted);
 

This should be only added in for the !guest case.

Quoted 1 line

Yes, I figured that out already :)

Hrm, that has more consequences vs. the buffer conversion functions. Let me stare some more.

Thanks,

tglx