Skip to content

Commit b158888

Browse files
ChangSeokBaehansendc
authored andcommitted
x86/fpu/xstate: Prevent false-positive warning in __copy_xstate_uabi_buf()
__copy_xstate_to_uabi_buf() copies either from the tasks XSAVE buffer or from init_fpstate into the ptrace buffer. Dynamic features, like XTILEDATA, have an all zeroes init state and are not saved in init_fpstate, which means the corresponding bit is not set in the xfeatures bitmap of the init_fpstate header. But __copy_xstate_to_uabi_buf() retrieves addresses for both the tasks xstate and init_fpstate unconditionally via __raw_xsave_addr(). So if the tasks XSAVE buffer has a dynamic feature set, then the address retrieval for init_fpstate triggers the warning in __raw_xsave_addr() which checks the feature bit in the init_fpstate header. Remove the address retrieval from init_fpstate for extended features. They have an all zeroes init state so init_fpstate has zeros for them. Then zeroing the user buffer for the init state is the same as copying them from init_fpstate. Fixes: 2308ee5 ("x86/fpu/amx: Enable the AMX feature in 64-bit mode") Reported-by: Mingwei Zhang <mizhang@google.com> Link: https://lore.kernel.org/kvm/20230221163655.920289-2-mizhang@google.com/ Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Tested-by: Mingwei Zhang <mizhang@google.com> Link: https://lore.kernel.org/all/20230227210504.18520-2-chang.seok.bae%40intel.com Cc: stable@vger.kernel.org
1 parent a3f547a commit b158888

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

arch/x86/kernel/fpu/xstate.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,21 +1118,20 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate,
11181118
zerofrom = offsetof(struct xregs_state, extended_state_area);
11191119

11201120
/*
1121-
* The ptrace buffer is in non-compacted XSAVE format. In
1122-
* non-compacted format disabled features still occupy state space,
1123-
* but there is no state to copy from in the compacted
1124-
* init_fpstate. The gap tracking will zero these states.
1125-
*/
1126-
mask = fpstate->user_xfeatures;
1127-
1128-
/*
1129-
* Dynamic features are not present in init_fpstate. When they are
1130-
* in an all zeros init state, remove those from 'mask' to zero
1131-
* those features in the user buffer instead of retrieving them
1132-
* from init_fpstate.
1121+
* This 'mask' indicates which states to copy from fpstate.
1122+
* Those extended states that are not present in fpstate are
1123+
* either disabled or initialized:
1124+
*
1125+
* In non-compacted format, disabled features still occupy
1126+
* state space but there is no state to copy from in the
1127+
* compacted init_fpstate. The gap tracking will zero these
1128+
* states.
1129+
*
1130+
* The extended features have an all zeroes init state. Thus,
1131+
* remove them from 'mask' to zero those features in the user
1132+
* buffer instead of retrieving them from init_fpstate.
11331133
*/
1134-
if (fpu_state_size_dynamic())
1135-
mask &= (header.xfeatures | xinit->header.xcomp_bv);
1134+
mask = header.xfeatures;
11361135

11371136
for_each_extended_xfeature(i, mask) {
11381137
/*
@@ -1151,9 +1150,8 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate,
11511150
pkru.pkru = pkru_val;
11521151
membuf_write(&to, &pkru, sizeof(pkru));
11531152
} else {
1154-
copy_feature(header.xfeatures & BIT_ULL(i), &to,
1153+
membuf_write(&to,
11551154
__raw_xsave_addr(xsave, i),
1156-
__raw_xsave_addr(xinit, i),
11571155
xstate_sizes[i]);
11581156
}
11591157
/*

0 commit comments

Comments
 (0)