Skip to contentSkip to conversation

x86/fpu: Set the corret permission value for perm.__state_perm

PATCH In review Yang Zhong 2 participants 4 messages Nov 8, 2021 – Nov 9, 2021 x86

lore
Share & tools
lore

Yang Zhong

author
#0 lore raw

PATCH 1/1 x86/fpu: Set the corret permission value for perm.__state_perm

The perm.__state_perm is default xsave set features, when we request AMX permission from application, the requested value(bit18) should be replaced with mask value(requested | permitted), which can keep default features there.

Without this change, the below prctl syscall:
(1). ARCH_GET_XCOMP_PERM, the bitmask=0x202e7
(2). set ARCH_REQ_XCOMP_PERM with XFEATURE_XTILEDATA (3). ARCH_GET_XCOMP_PERM, the bitmask=0x40000, the correct value

     should be 0x602e7 here.
---
 arch/x86/kernel/fpu/xstate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/fpu/xstate.c +1 -1
index d28829403ed0..fc1ab0116f4e 100644
@@ -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;
Signature · 1 line
2.30.2
#1 lore raw
Quoted 11 lines · Yang

The perm.__state_perm is default xsave set features, when we request AMX permission from application, the requested value(bit18) should be replaced with mask value(requested | permitted), which can keep default features there.

Without this change, the below prctl syscall:
(1). ARCH_GET_XCOMP_PERM, the bitmask=0x202e7
(2). set ARCH_REQ_XCOMP_PERM with XFEATURE_XTILEDATA (3). ARCH_GET_XCOMP_PERM, the bitmask=0x40000, the correct value

    should be 0x602e7 here.

Oh, bad.

arch/x86/kernel/fpu/xstate.c static int __xstate_request_perm(u64 permitted, u64 requested) · line 1629

Quoted 10 lines
arch/x86/kernel/fpu/xstate.c +1 -1
index d28829403ed0..fc1ab0116f4e 100644
@@ -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);

I think this has to update the group leader’s like:

    WRITE_ONCE(current->group_leader->thread.fpu.perm.__state_perm, mask);

Thanks,
Chang

author
#3 lore raw
In reply to Bae, Chang Seok
Quoted 22 lines · Chang Seok
Quoted 11 lines · Yang

The perm.__state_perm is default xsave set features, when we request AMX permission from application, the requested value(bit18) should be replaced with mask value(requested | permitted), which can keep default features there.

Without this change, the below prctl syscall:
(1). ARCH_GET_XCOMP_PERM, the bitmask=0x202e7
(2). set ARCH_REQ_XCOMP_PERM with XFEATURE_XTILEDATA (3). ARCH_GET_XCOMP_PERM, the bitmask=0x40000, the correct value

    should be 0x602e7 here.

Oh, bad.

Quoted 7 lines
arch/x86/kernel/fpu/xstate.c +0 -0
index d28829403ed0..fc1ab0116f4e 100644
@@ -1626,7 +1626,7 @@ static int __xstate_request_perm(u64 permitted, u64 requested)
              return ret;
 
Quoted 7 lines

arch/x86/kernel/fpu/xstate.c static int __xstate_request_perm(u64 permitted, u64 requested) · line 1629

Quoted 3 lines
arch/x86/kernel/fpu/xstate.c +1 -1
      /* Pairs with the READ_ONCE() in xstate_get_group_perm() */
-     WRITE_ONCE(fpu->perm.__state_perm, requested);
+     WRITE_ONCE(fpu->perm.__state_perm, mask);

I think this has to update the group leader’s like:

    WRITE_ONCE(current->group_leader->thread.fpu.perm.__state_perm, mask);

I think this is no need to change with group leader here, the fpu pointer has defined as below:

  struct fpu *fpu = &current->group_leader->thread.fpu;

Please check Thomas's changes for KVM, the WRITE_ONCE(fpu->perm.__state_perm, mask) is more reasonable here.

https://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git/commit/?h=x86/fpu-kvm&id=62016e4cc41716b33da890ad43145b646f9db51d

I also verified this changes from host and guest side, all work well.

Regards,

Yang

Quoted 5 lines

Thanks,
Chang