x86/fpu: Make XFD initialization in __fpstate_reset() a function argument
authorJing Liu <jing2.liu@intel.com>
Wed, 5 Jan 2022 12:35:16 +0000 (04:35 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 14 Jan 2022 18:40:57 +0000 (13:40 -0500)
vCPU threads are different from native tasks regarding to the initial XFD
value. While all native tasks follow a fixed value (init_fpstate::xfd)
established by the FPU core at boot, vCPU threads need to obey the reset
value (i.e. ZERO) defined by the specification, to meet the expectation of
the guest.

Let the caller supply an argument and adjust the host and guest related
invocations accordingly.

Signed-off-by: Jing Liu <jing2.liu@intel.com>
Signed-off-by: Yang Zhong <yang.zhong@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jing Liu <jing2.liu@intel.com>
Signed-off-by: Yang Zhong <yang.zhong@intel.com>
Message-Id: <20220105123532.12586-6-yang.zhong@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kernel/fpu/core.c

index eddeeb4ed2f52cc0ec98598dced5d481c1fdc9dc..a78bc547fc03f19fb03d9f80a219d7cc34974c94 100644 (file)
@@ -199,7 +199,7 @@ void fpu_reset_from_exception_fixup(void)
 }
 
 #if IS_ENABLED(CONFIG_KVM)
-static void __fpstate_reset(struct fpstate *fpstate);
+static void __fpstate_reset(struct fpstate *fpstate, u64 xfd);
 
 static void fpu_init_guest_permissions(struct fpu_guest *gfpu)
 {
@@ -231,7 +231,8 @@ bool fpu_alloc_guest_fpstate(struct fpu_guest *gfpu)
        if (!fpstate)
                return false;
 
-       __fpstate_reset(fpstate);
+       /* Leave xfd to 0 (the reset value defined by spec) */
+       __fpstate_reset(fpstate, 0);
        fpstate_init_user(fpstate);
        fpstate->is_valloc      = true;
        fpstate->is_guest       = true;
@@ -454,21 +455,21 @@ void fpstate_init_user(struct fpstate *fpstate)
                fpstate_init_fstate(fpstate);
 }
 
-static void __fpstate_reset(struct fpstate *fpstate)
+static void __fpstate_reset(struct fpstate *fpstate, u64 xfd)
 {
        /* Initialize sizes and feature masks */
        fpstate->size           = fpu_kernel_cfg.default_size;
        fpstate->user_size      = fpu_user_cfg.default_size;
        fpstate->xfeatures      = fpu_kernel_cfg.default_features;
        fpstate->user_xfeatures = fpu_user_cfg.default_features;
-       fpstate->xfd            = init_fpstate.xfd;
+       fpstate->xfd            = xfd;
 }
 
 void fpstate_reset(struct fpu *fpu)
 {
        /* Set the fpstate pointer to the default fpstate */
        fpu->fpstate = &fpu->__fpstate;
-       __fpstate_reset(fpu->fpstate);
+       __fpstate_reset(fpu->fpstate, init_fpstate.xfd);
 
        /* Initialize the permission related info in fpu */
        fpu->perm.__state_perm          = fpu_kernel_cfg.default_features;