提交 1192b93b 编写于 作者: M Mark Brown 提交者: Will Deacon

arm64/fp: Use a struct to pass data to fpsimd_bind_state_to_cpu()

For reasons that are unclear to this reader fpsimd_bind_state_to_cpu()
populates the struct fpsimd_last_state_struct that it uses to store the
active floating point state for KVM guests by passing an argument for
each member of the structure. As the richness of the architecture increases
this is resulting in a function with a rather large number of arguments
which isn't ideal.

Simplify the interface by using the struct directly as the single argument
for the function, renaming it as we lift the definition into the header.
This could be built on further to reduce the work we do adding storage for
new FP state in various places but for now it just simplifies this one
interface.
Signed-off-by: NMark Brown <broonie@kernel.org>
Reviewed-by: NCatalin Marinas <catalin.marinas@arm.com>
Reviewed-by: NMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20221115094640.112848-9-broonie@kernel.orgSigned-off-by: NWill Deacon <will@kernel.org>
上级 8c845e27
...@@ -58,11 +58,18 @@ extern void fpsimd_restore_current_state(void); ...@@ -58,11 +58,18 @@ extern void fpsimd_restore_current_state(void);
extern void fpsimd_update_current_state(struct user_fpsimd_state const *state); extern void fpsimd_update_current_state(struct user_fpsimd_state const *state);
extern void fpsimd_kvm_prepare(void); extern void fpsimd_kvm_prepare(void);
extern void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *state, struct cpu_fp_state {
void *sve_state, unsigned int sve_vl, struct user_fpsimd_state *st;
void *za_state, unsigned int sme_vl, void *sve_state;
u64 *svcr, enum fp_type *type, void *za_state;
enum fp_type to_save); u64 *svcr;
unsigned int sve_vl;
unsigned int sme_vl;
enum fp_type *fp_type;
enum fp_type to_save;
};
extern void fpsimd_bind_state_to_cpu(struct cpu_fp_state *fp_state);
extern void fpsimd_flush_task_state(struct task_struct *target); extern void fpsimd_flush_task_state(struct task_struct *target);
extern void fpsimd_save_and_flush_cpu_state(void); extern void fpsimd_save_and_flush_cpu_state(void);
......
...@@ -118,18 +118,8 @@ ...@@ -118,18 +118,8 @@
* returned from the 2nd syscall yet, TIF_FOREIGN_FPSTATE is still set so * returned from the 2nd syscall yet, TIF_FOREIGN_FPSTATE is still set so
* whatever is in the FPSIMD registers is not saved to memory, but discarded. * whatever is in the FPSIMD registers is not saved to memory, but discarded.
*/ */
struct fpsimd_last_state_struct {
struct user_fpsimd_state *st;
void *sve_state;
void *za_state;
u64 *svcr;
unsigned int sve_vl;
unsigned int sme_vl;
enum fp_type *fp_type;
enum fp_type to_save;
};
static DEFINE_PER_CPU(struct fpsimd_last_state_struct, fpsimd_last_state); static DEFINE_PER_CPU(struct cpu_fp_state, fpsimd_last_state);
__ro_after_init struct vl_info vl_info[ARM64_VEC_MAX] = { __ro_after_init struct vl_info vl_info[ARM64_VEC_MAX] = {
#ifdef CONFIG_ARM64_SVE #ifdef CONFIG_ARM64_SVE
...@@ -468,7 +458,7 @@ static void task_fpsimd_load(void) ...@@ -468,7 +458,7 @@ static void task_fpsimd_load(void)
*/ */
static void fpsimd_save(void) static void fpsimd_save(void)
{ {
struct fpsimd_last_state_struct const *last = struct cpu_fp_state const *last =
this_cpu_ptr(&fpsimd_last_state); this_cpu_ptr(&fpsimd_last_state);
/* set by fpsimd_bind_task_to_cpu() or fpsimd_bind_state_to_cpu() */ /* set by fpsimd_bind_task_to_cpu() or fpsimd_bind_state_to_cpu() */
bool save_sve_regs = false; bool save_sve_regs = false;
...@@ -1716,8 +1706,7 @@ void fpsimd_kvm_prepare(void) ...@@ -1716,8 +1706,7 @@ void fpsimd_kvm_prepare(void)
*/ */
static void fpsimd_bind_task_to_cpu(void) static void fpsimd_bind_task_to_cpu(void)
{ {
struct fpsimd_last_state_struct *last = struct cpu_fp_state *last = this_cpu_ptr(&fpsimd_last_state);
this_cpu_ptr(&fpsimd_last_state);
WARN_ON(!system_supports_fpsimd()); WARN_ON(!system_supports_fpsimd());
last->st = &current->thread.uw.fpsimd_state; last->st = &current->thread.uw.fpsimd_state;
...@@ -1749,25 +1738,14 @@ static void fpsimd_bind_task_to_cpu(void) ...@@ -1749,25 +1738,14 @@ static void fpsimd_bind_task_to_cpu(void)
} }
} }
void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *st, void *sve_state, void fpsimd_bind_state_to_cpu(struct cpu_fp_state *state)
unsigned int sve_vl, void *za_state,
unsigned int sme_vl, u64 *svcr,
enum fp_type *type, enum fp_type to_save)
{ {
struct fpsimd_last_state_struct *last = struct cpu_fp_state *last = this_cpu_ptr(&fpsimd_last_state);
this_cpu_ptr(&fpsimd_last_state);
WARN_ON(!system_supports_fpsimd()); WARN_ON(!system_supports_fpsimd());
WARN_ON(!in_softirq() && !irqs_disabled()); WARN_ON(!in_softirq() && !irqs_disabled());
last->st = st; *last = *state;
last->svcr = svcr;
last->sve_state = sve_state;
last->za_state = za_state;
last->sve_vl = sve_vl;
last->sme_vl = sme_vl;
last->fp_type = type;
last->to_save = to_save;
} }
/* /*
......
...@@ -130,25 +130,29 @@ void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu) ...@@ -130,25 +130,29 @@ void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu)
*/ */
void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu) void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu)
{ {
enum fp_type fp_type; struct cpu_fp_state fp_state;
WARN_ON_ONCE(!irqs_disabled()); WARN_ON_ONCE(!irqs_disabled());
if (vcpu->arch.fp_state == FP_STATE_GUEST_OWNED) { if (vcpu->arch.fp_state == FP_STATE_GUEST_OWNED) {
if (vcpu_has_sve(vcpu))
fp_type = FP_STATE_SVE;
else
fp_type = FP_STATE_FPSIMD;
/* /*
* Currently we do not support SME guests so SVCR is * Currently we do not support SME guests so SVCR is
* always 0 and we just need a variable to point to. * always 0 and we just need a variable to point to.
*/ */
fpsimd_bind_state_to_cpu(&vcpu->arch.ctxt.fp_regs, fp_state.st = &vcpu->arch.ctxt.fp_regs;
vcpu->arch.sve_state, fp_state.sve_state = vcpu->arch.sve_state;
vcpu->arch.sve_max_vl, fp_state.sve_vl = vcpu->arch.sve_max_vl;
NULL, 0, &vcpu->arch.svcr, fp_state.za_state = NULL;
&vcpu->arch.fp_type, fp_type); fp_state.svcr = &vcpu->arch.svcr;
fp_state.fp_type = &vcpu->arch.fp_type;
if (vcpu_has_sve(vcpu))
fp_state.to_save = FP_STATE_SVE;
else
fp_state.to_save = FP_STATE_FPSIMD;
fpsimd_bind_state_to_cpu(&fp_state);
clear_thread_flag(TIF_FOREIGN_FPSTATE); clear_thread_flag(TIF_FOREIGN_FPSTATE);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册