x86/fpu: Set the corret permission value for perm.__state_perm
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
@@ -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
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). setARCH_REQ_XCOMP_PERMwithXFEATURE_XTILEDATA(3).ARCH_GET_XCOMP_PERM, the bitmask=0x40000, the correct valueshould 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@@ -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
Quoted 3 lines · Chang Seok
I think this has to update the group leader’s like:
WRITE_ONCE(current->group_leader->thread.fpu.perm.__state_perm, mask);
Posted a new patch along with the test update here:
https://lore.kernel.org/lkml/[email protected]/
Thanks,
Chang
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). setARCH_REQ_XCOMP_PERMwithXFEATURE_XTILEDATA(3).ARCH_GET_XCOMP_PERM, the bitmask=0x40000, the correct valueshould be 0x602e7 here.Oh, bad.
Quoted 7 lines
arch/x86/kernel/fpu/xstate.c +0
-0@@ -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 = ¤t->group_leader->thread.fpu;
Please check Thomas's changes for KVM, the WRITE_ONCE(fpu->perm.__state_perm, mask) is more reasonable here.
I also verified this changes from host and guest side, all work well.
Regards,
Yang
Quoted 5 lines
Thanks,
Chang