Re: [PATCH v5 3/3] KVM/arm/arm64: enable enhanced armv8 fp/simd lazy switch
On 12/22/2015 12:06 AM, Christoffer Dall wrote: > On Mon, Dec 21, 2015 at 11:34:25AM -0800, Mario Smarduch wrote: >> >> >> On 12/18/2015 11:45 PM, Christoffer Dall wrote: >>> On Fri, Dec 18, 2015 at 05:17:00PM -0800, Mario Smarduch wrote: On 12/18/2015 5:54 AM, Christoffer Dall wrote: > On Sun, Dec 06, 2015 at 05:07:14PM -0800, Mario Smarduch wrote: [...] >> + * we set FPEXC.EN to prevent traps to EL1, when setting the TFP >> bit. >> + */ >> +ENTRY(__kvm_vcpu_enable_fpexc32) >> +mov x3, #(1 << 30) >> +msr fpexc32_el2, x3 >> +isb > > this is only called via a hypercall so do you really need the ISB? Same comment as in 2nd patch for the isb. >>> >>> Unless you can argue that something needs to take effect before >>> something else, where there's no other implicit barrier, you don't need >>> the ISB. >> >> Make sense an exception level change should be a barrier. It was not there >> before I put it in due to lack of info on meaning of 'implicit'. The manual >> has >> more info on implicit barriers for operations like DMB. > > if the effect from the register write just has to be visible after > taking an exception, then you don't need the ISB. Good definition, should be in the manual :) Thanks. > >> >> Speaking of ISB it doesn't appear like this one is needed, it's between >> couple >> register reads in 'save_time_state' macro. >> >> mrc p15, 0, r2, c14, c3, 1 @ CNTV_CTL >> str r2, [vcpu, #VCPU_TIMER_CNTV_CTL] >> >> isb >> >> mrrcp15, 3, rr_lo_hi(r2, r3), c14 @ CNTV_CVAL >> > > I think there was a reason for that one, so let's not worry about that > for now. > > -Christoffer > -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v5 3/3] KVM/arm/arm64: enable enhanced armv8 fp/simd lazy switch
On Mon, Dec 21, 2015 at 11:34:25AM -0800, Mario Smarduch wrote:
>
>
> On 12/18/2015 11:45 PM, Christoffer Dall wrote:
> > On Fri, Dec 18, 2015 at 05:17:00PM -0800, Mario Smarduch wrote:
> >> On 12/18/2015 5:54 AM, Christoffer Dall wrote:
> >>> On Sun, Dec 06, 2015 at 05:07:14PM -0800, Mario Smarduch wrote:
> This patch tracks armv7 and armv8 fp/simd hardware state with cptr_el2
> register.
> On vcpu_load for 32 bit guests enable FP access, and enable fp/simd
> trapping for 32 and 64 bit guests. On first fp/simd access trap to
> handler
> to save host and restore guest context, and clear trapping bits to
> enable vcpu
> lazy mode. On vcpu_put if trap bits are clear save guest and restore
> host
> context and also save 32 bit guest fpexc register.
>
> Signed-off-by: Mario Smarduch
> ---
> arch/arm/include/asm/kvm_emulate.h | 5 ++
> arch/arm/include/asm/kvm_host.h | 2 +
> arch/arm/kvm/arm.c | 20 +--
> arch/arm64/include/asm/kvm_asm.h | 2 +
> arch/arm64/include/asm/kvm_emulate.h | 15 +++--
> arch/arm64/include/asm/kvm_host.h| 16 +-
> arch/arm64/kernel/asm-offsets.c | 1 +
> arch/arm64/kvm/Makefile | 3 +-
> arch/arm64/kvm/fpsimd_switch.S | 38
> arch/arm64/kvm/hyp.S | 108
> +--
> arch/arm64/kvm/hyp_head.S| 48
> 11 files changed, 181 insertions(+), 77 deletions(-)
> create mode 100644 arch/arm64/kvm/fpsimd_switch.S
> create mode 100644 arch/arm64/kvm/hyp_head.S
>
> diff --git a/arch/arm/include/asm/kvm_emulate.h
> b/arch/arm/include/asm/kvm_emulate.h
> index 3de11a2..13feed5 100644
> --- a/arch/arm/include/asm/kvm_emulate.h
> +++ b/arch/arm/include/asm/kvm_emulate.h
> @@ -243,6 +243,11 @@ static inline unsigned long
> vcpu_data_host_to_guest(struct kvm_vcpu *vcpu,
> }
> }
>
> +static inline bool kvm_guest_vcpu_is_32bit(struct kvm_vcpu *vcpu)
> +{
> +return true;
> +}
> +
> #ifdef CONFIG_VFPv3
> /* Called from vcpu_load - save fpexc and enable guest access to
> fp/simd unit */
> static inline void kvm_enable_vcpu_fpexc(struct kvm_vcpu *vcpu)
> diff --git a/arch/arm/include/asm/kvm_host.h
> b/arch/arm/include/asm/kvm_host.h
> index ecc883a..720ae51 100644
> --- a/arch/arm/include/asm/kvm_host.h
> +++ b/arch/arm/include/asm/kvm_host.h
> @@ -227,6 +227,8 @@ int kvm_perf_teardown(void);
> void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
>
> struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long
> mpidr);
> +
> +static inline void kvm_save_guest_vcpu_fpexc(struct kvm_vcpu *vcpu) {}
> void kvm_restore_host_vfp_state(struct kvm_vcpu *);
>
> static inline void kvm_arch_hardware_disable(void) {}
> diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
> index 1de07ab..dd59f8a 100644
> --- a/arch/arm/kvm/arm.c
> +++ b/arch/arm/kvm/arm.c
> @@ -292,8 +292,12 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int
> cpu)
>
> kvm_arm_set_running_vcpu(vcpu);
>
> -/* Save and enable FPEXC before we load guest context */
> -kvm_enable_vcpu_fpexc(vcpu);
> +/*
> + * For 32bit guest executing on arm64, enable fp/simd access in
> + * EL2. On arm32 save host fpexc and then enable fp/simd access.
> + */
> +if (kvm_guest_vcpu_is_32bit(vcpu))
> +kvm_enable_vcpu_fpexc(vcpu);
>
> /* reset hyp cptr register to trap on tracing and vfp/simd
> access*/
> vcpu_reset_cptr(vcpu);
> @@ -302,10 +306,18 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int
> cpu)
> void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
> {
> /* If the fp/simd registers are dirty save guest, restore host.
> */
> -if (kvm_vcpu_vfp_isdirty(vcpu))
> +if (kvm_vcpu_vfp_isdirty(vcpu)) {
> kvm_restore_host_vfp_state(vcpu);
>
> -/* Restore host FPEXC trashed in vcpu_load */
> +/*
> + * For 32bit guest on arm64 save the guest fpexc
> register
> + * in EL2 mode.
> + */
> +if (kvm_guest_vcpu_is_32bit(vcpu))
> +kvm_save_guest_vcpu_fpexc(vcpu);
> +}
> +
> +/* For arm32 restore host FPEXC trashed in vcpu_load. */
> kvm_restore_host_fpexc(vcpu);
>
> /*
> diff --git a/arch/arm64/include/asm/kvm_asm.h
>
Re: [PATCH v5 3/3] KVM/arm/arm64: enable enhanced armv8 fp/simd lazy switch
On 12/18/2015 11:45 PM, Christoffer Dall wrote:
> On Fri, Dec 18, 2015 at 05:17:00PM -0800, Mario Smarduch wrote:
>> On 12/18/2015 5:54 AM, Christoffer Dall wrote:
>>> On Sun, Dec 06, 2015 at 05:07:14PM -0800, Mario Smarduch wrote:
This patch tracks armv7 and armv8 fp/simd hardware state with cptr_el2
register.
On vcpu_load for 32 bit guests enable FP access, and enable fp/simd
trapping for 32 and 64 bit guests. On first fp/simd access trap to handler
to save host and restore guest context, and clear trapping bits to enable
vcpu
lazy mode. On vcpu_put if trap bits are clear save guest and restore host
context and also save 32 bit guest fpexc register.
Signed-off-by: Mario Smarduch
---
arch/arm/include/asm/kvm_emulate.h | 5 ++
arch/arm/include/asm/kvm_host.h | 2 +
arch/arm/kvm/arm.c | 20 +--
arch/arm64/include/asm/kvm_asm.h | 2 +
arch/arm64/include/asm/kvm_emulate.h | 15 +++--
arch/arm64/include/asm/kvm_host.h| 16 +-
arch/arm64/kernel/asm-offsets.c | 1 +
arch/arm64/kvm/Makefile | 3 +-
arch/arm64/kvm/fpsimd_switch.S | 38
arch/arm64/kvm/hyp.S | 108
+--
arch/arm64/kvm/hyp_head.S| 48
11 files changed, 181 insertions(+), 77 deletions(-)
create mode 100644 arch/arm64/kvm/fpsimd_switch.S
create mode 100644 arch/arm64/kvm/hyp_head.S
diff --git a/arch/arm/include/asm/kvm_emulate.h
b/arch/arm/include/asm/kvm_emulate.h
index 3de11a2..13feed5 100644
--- a/arch/arm/include/asm/kvm_emulate.h
+++ b/arch/arm/include/asm/kvm_emulate.h
@@ -243,6 +243,11 @@ static inline unsigned long
vcpu_data_host_to_guest(struct kvm_vcpu *vcpu,
}
}
+static inline bool kvm_guest_vcpu_is_32bit(struct kvm_vcpu *vcpu)
+{
+ return true;
+}
+
#ifdef CONFIG_VFPv3
/* Called from vcpu_load - save fpexc and enable guest access to fp/simd
unit */
static inline void kvm_enable_vcpu_fpexc(struct kvm_vcpu *vcpu)
diff --git a/arch/arm/include/asm/kvm_host.h
b/arch/arm/include/asm/kvm_host.h
index ecc883a..720ae51 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -227,6 +227,8 @@ int kvm_perf_teardown(void);
void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
+
+static inline void kvm_save_guest_vcpu_fpexc(struct kvm_vcpu *vcpu) {}
void kvm_restore_host_vfp_state(struct kvm_vcpu *);
static inline void kvm_arch_hardware_disable(void) {}
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 1de07ab..dd59f8a 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -292,8 +292,12 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int
cpu)
kvm_arm_set_running_vcpu(vcpu);
- /* Save and enable FPEXC before we load guest context */
- kvm_enable_vcpu_fpexc(vcpu);
+ /*
+ * For 32bit guest executing on arm64, enable fp/simd access in
+ * EL2. On arm32 save host fpexc and then enable fp/simd access.
+ */
+ if (kvm_guest_vcpu_is_32bit(vcpu))
+ kvm_enable_vcpu_fpexc(vcpu);
/* reset hyp cptr register to trap on tracing and vfp/simd access*/
vcpu_reset_cptr(vcpu);
@@ -302,10 +306,18 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int
cpu)
void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
{
/* If the fp/simd registers are dirty save guest, restore host. */
- if (kvm_vcpu_vfp_isdirty(vcpu))
+ if (kvm_vcpu_vfp_isdirty(vcpu)) {
kvm_restore_host_vfp_state(vcpu);
- /* Restore host FPEXC trashed in vcpu_load */
+ /*
+ * For 32bit guest on arm64 save the guest fpexc register
+ * in EL2 mode.
+ */
+ if (kvm_guest_vcpu_is_32bit(vcpu))
+ kvm_save_guest_vcpu_fpexc(vcpu);
+ }
+
+ /* For arm32 restore host FPEXC trashed in vcpu_load. */
kvm_restore_host_fpexc(vcpu);
/*
diff --git a/arch/arm64/include/asm/kvm_asm.h
b/arch/arm64/include/asm/kvm_asm.h
index 5e37710..d53d069 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -117,6 +117,8 @@ extern char __kvm_hyp_vector[];
extern void __kvm_flush_vm_context(void);
extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa);
extern void __kvm_tlb_flush_vmid(struct kvm *kvm);
+extern void __kvm_vcpu_enable_fpexc32(void);
+extern void __kvm_vcpu_save_fpexc32(struct kvm_vcpu
Re: [PATCH v5 3/3] KVM/arm/arm64: enable enhanced armv8 fp/simd lazy switch
On Fri, Dec 18, 2015 at 05:17:00PM -0800, Mario Smarduch wrote:
> On 12/18/2015 5:54 AM, Christoffer Dall wrote:
> > On Sun, Dec 06, 2015 at 05:07:14PM -0800, Mario Smarduch wrote:
> >> This patch tracks armv7 and armv8 fp/simd hardware state with cptr_el2
> >> register.
> >> On vcpu_load for 32 bit guests enable FP access, and enable fp/simd
> >> trapping for 32 and 64 bit guests. On first fp/simd access trap to handler
> >> to save host and restore guest context, and clear trapping bits to enable
> >> vcpu
> >> lazy mode. On vcpu_put if trap bits are clear save guest and restore host
> >> context and also save 32 bit guest fpexc register.
> >>
> >> Signed-off-by: Mario Smarduch
> >> ---
> >> arch/arm/include/asm/kvm_emulate.h | 5 ++
> >> arch/arm/include/asm/kvm_host.h | 2 +
> >> arch/arm/kvm/arm.c | 20 +--
> >> arch/arm64/include/asm/kvm_asm.h | 2 +
> >> arch/arm64/include/asm/kvm_emulate.h | 15 +++--
> >> arch/arm64/include/asm/kvm_host.h| 16 +-
> >> arch/arm64/kernel/asm-offsets.c | 1 +
> >> arch/arm64/kvm/Makefile | 3 +-
> >> arch/arm64/kvm/fpsimd_switch.S | 38
> >> arch/arm64/kvm/hyp.S | 108
> >> +--
> >> arch/arm64/kvm/hyp_head.S| 48
> >> 11 files changed, 181 insertions(+), 77 deletions(-)
> >> create mode 100644 arch/arm64/kvm/fpsimd_switch.S
> >> create mode 100644 arch/arm64/kvm/hyp_head.S
> >>
> >> diff --git a/arch/arm/include/asm/kvm_emulate.h
> >> b/arch/arm/include/asm/kvm_emulate.h
> >> index 3de11a2..13feed5 100644
> >> --- a/arch/arm/include/asm/kvm_emulate.h
> >> +++ b/arch/arm/include/asm/kvm_emulate.h
> >> @@ -243,6 +243,11 @@ static inline unsigned long
> >> vcpu_data_host_to_guest(struct kvm_vcpu *vcpu,
> >>}
> >> }
> >>
> >> +static inline bool kvm_guest_vcpu_is_32bit(struct kvm_vcpu *vcpu)
> >> +{
> >> + return true;
> >> +}
> >> +
> >> #ifdef CONFIG_VFPv3
> >> /* Called from vcpu_load - save fpexc and enable guest access to fp/simd
> >> unit */
> >> static inline void kvm_enable_vcpu_fpexc(struct kvm_vcpu *vcpu)
> >> diff --git a/arch/arm/include/asm/kvm_host.h
> >> b/arch/arm/include/asm/kvm_host.h
> >> index ecc883a..720ae51 100644
> >> --- a/arch/arm/include/asm/kvm_host.h
> >> +++ b/arch/arm/include/asm/kvm_host.h
> >> @@ -227,6 +227,8 @@ int kvm_perf_teardown(void);
> >> void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
> >>
> >> struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
> >> +
> >> +static inline void kvm_save_guest_vcpu_fpexc(struct kvm_vcpu *vcpu) {}
> >> void kvm_restore_host_vfp_state(struct kvm_vcpu *);
> >>
> >> static inline void kvm_arch_hardware_disable(void) {}
> >> diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
> >> index 1de07ab..dd59f8a 100644
> >> --- a/arch/arm/kvm/arm.c
> >> +++ b/arch/arm/kvm/arm.c
> >> @@ -292,8 +292,12 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int
> >> cpu)
> >>
> >>kvm_arm_set_running_vcpu(vcpu);
> >>
> >> - /* Save and enable FPEXC before we load guest context */
> >> - kvm_enable_vcpu_fpexc(vcpu);
> >> + /*
> >> + * For 32bit guest executing on arm64, enable fp/simd access in
> >> + * EL2. On arm32 save host fpexc and then enable fp/simd access.
> >> + */
> >> + if (kvm_guest_vcpu_is_32bit(vcpu))
> >> + kvm_enable_vcpu_fpexc(vcpu);
> >>
> >>/* reset hyp cptr register to trap on tracing and vfp/simd access*/
> >>vcpu_reset_cptr(vcpu);
> >> @@ -302,10 +306,18 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int
> >> cpu)
> >> void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
> >> {
> >>/* If the fp/simd registers are dirty save guest, restore host. */
> >> - if (kvm_vcpu_vfp_isdirty(vcpu))
> >> + if (kvm_vcpu_vfp_isdirty(vcpu)) {
> >>kvm_restore_host_vfp_state(vcpu);
> >>
> >> - /* Restore host FPEXC trashed in vcpu_load */
> >> + /*
> >> + * For 32bit guest on arm64 save the guest fpexc register
> >> + * in EL2 mode.
> >> + */
> >> + if (kvm_guest_vcpu_is_32bit(vcpu))
> >> + kvm_save_guest_vcpu_fpexc(vcpu);
> >> + }
> >> +
> >> + /* For arm32 restore host FPEXC trashed in vcpu_load. */
> >>kvm_restore_host_fpexc(vcpu);
> >>
> >>/*
> >> diff --git a/arch/arm64/include/asm/kvm_asm.h
> >> b/arch/arm64/include/asm/kvm_asm.h
> >> index 5e37710..d53d069 100644
> >> --- a/arch/arm64/include/asm/kvm_asm.h
> >> +++ b/arch/arm64/include/asm/kvm_asm.h
> >> @@ -117,6 +117,8 @@ extern char __kvm_hyp_vector[];
> >> extern void __kvm_flush_vm_context(void);
> >> extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa);
> >> extern void __kvm_tlb_flush_vmid(struct kvm *kvm);
> >> +extern void __kvm_vcpu_enable_fpexc32(void);
> >> +extern void __kvm_vcpu_save_fpexc32(struct kvm_vcpu *vcpu);
> >>
> >> extern int __kvm_vcpu_run(struct
Re: [PATCH v5 3/3] KVM/arm/arm64: enable enhanced armv8 fp/simd lazy switch
On 12/18/2015 5:54 AM, Christoffer Dall wrote:
> On Sun, Dec 06, 2015 at 05:07:14PM -0800, Mario Smarduch wrote:
>> This patch tracks armv7 and armv8 fp/simd hardware state with cptr_el2
>> register.
>> On vcpu_load for 32 bit guests enable FP access, and enable fp/simd
>> trapping for 32 and 64 bit guests. On first fp/simd access trap to handler
>> to save host and restore guest context, and clear trapping bits to enable
>> vcpu
>> lazy mode. On vcpu_put if trap bits are clear save guest and restore host
>> context and also save 32 bit guest fpexc register.
>>
>> Signed-off-by: Mario Smarduch
>> ---
>> arch/arm/include/asm/kvm_emulate.h | 5 ++
>> arch/arm/include/asm/kvm_host.h | 2 +
>> arch/arm/kvm/arm.c | 20 +--
>> arch/arm64/include/asm/kvm_asm.h | 2 +
>> arch/arm64/include/asm/kvm_emulate.h | 15 +++--
>> arch/arm64/include/asm/kvm_host.h| 16 +-
>> arch/arm64/kernel/asm-offsets.c | 1 +
>> arch/arm64/kvm/Makefile | 3 +-
>> arch/arm64/kvm/fpsimd_switch.S | 38
>> arch/arm64/kvm/hyp.S | 108
>> +--
>> arch/arm64/kvm/hyp_head.S| 48
>> 11 files changed, 181 insertions(+), 77 deletions(-)
>> create mode 100644 arch/arm64/kvm/fpsimd_switch.S
>> create mode 100644 arch/arm64/kvm/hyp_head.S
>>
>> diff --git a/arch/arm/include/asm/kvm_emulate.h
>> b/arch/arm/include/asm/kvm_emulate.h
>> index 3de11a2..13feed5 100644
>> --- a/arch/arm/include/asm/kvm_emulate.h
>> +++ b/arch/arm/include/asm/kvm_emulate.h
>> @@ -243,6 +243,11 @@ static inline unsigned long
>> vcpu_data_host_to_guest(struct kvm_vcpu *vcpu,
>> }
>> }
>>
>> +static inline bool kvm_guest_vcpu_is_32bit(struct kvm_vcpu *vcpu)
>> +{
>> +return true;
>> +}
>> +
>> #ifdef CONFIG_VFPv3
>> /* Called from vcpu_load - save fpexc and enable guest access to fp/simd
>> unit */
>> static inline void kvm_enable_vcpu_fpexc(struct kvm_vcpu *vcpu)
>> diff --git a/arch/arm/include/asm/kvm_host.h
>> b/arch/arm/include/asm/kvm_host.h
>> index ecc883a..720ae51 100644
>> --- a/arch/arm/include/asm/kvm_host.h
>> +++ b/arch/arm/include/asm/kvm_host.h
>> @@ -227,6 +227,8 @@ int kvm_perf_teardown(void);
>> void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
>>
>> struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
>> +
>> +static inline void kvm_save_guest_vcpu_fpexc(struct kvm_vcpu *vcpu) {}
>> void kvm_restore_host_vfp_state(struct kvm_vcpu *);
>>
>> static inline void kvm_arch_hardware_disable(void) {}
>> diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
>> index 1de07ab..dd59f8a 100644
>> --- a/arch/arm/kvm/arm.c
>> +++ b/arch/arm/kvm/arm.c
>> @@ -292,8 +292,12 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
>>
>> kvm_arm_set_running_vcpu(vcpu);
>>
>> -/* Save and enable FPEXC before we load guest context */
>> -kvm_enable_vcpu_fpexc(vcpu);
>> +/*
>> + * For 32bit guest executing on arm64, enable fp/simd access in
>> + * EL2. On arm32 save host fpexc and then enable fp/simd access.
>> + */
>> +if (kvm_guest_vcpu_is_32bit(vcpu))
>> +kvm_enable_vcpu_fpexc(vcpu);
>>
>> /* reset hyp cptr register to trap on tracing and vfp/simd access*/
>> vcpu_reset_cptr(vcpu);
>> @@ -302,10 +306,18 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
>> void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
>> {
>> /* If the fp/simd registers are dirty save guest, restore host. */
>> -if (kvm_vcpu_vfp_isdirty(vcpu))
>> +if (kvm_vcpu_vfp_isdirty(vcpu)) {
>> kvm_restore_host_vfp_state(vcpu);
>>
>> -/* Restore host FPEXC trashed in vcpu_load */
>> +/*
>> + * For 32bit guest on arm64 save the guest fpexc register
>> + * in EL2 mode.
>> + */
>> +if (kvm_guest_vcpu_is_32bit(vcpu))
>> +kvm_save_guest_vcpu_fpexc(vcpu);
>> +}
>> +
>> +/* For arm32 restore host FPEXC trashed in vcpu_load. */
>> kvm_restore_host_fpexc(vcpu);
>>
>> /*
>> diff --git a/arch/arm64/include/asm/kvm_asm.h
>> b/arch/arm64/include/asm/kvm_asm.h
>> index 5e37710..d53d069 100644
>> --- a/arch/arm64/include/asm/kvm_asm.h
>> +++ b/arch/arm64/include/asm/kvm_asm.h
>> @@ -117,6 +117,8 @@ extern char __kvm_hyp_vector[];
>> extern void __kvm_flush_vm_context(void);
>> extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa);
>> extern void __kvm_tlb_flush_vmid(struct kvm *kvm);
>> +extern void __kvm_vcpu_enable_fpexc32(void);
>> +extern void __kvm_vcpu_save_fpexc32(struct kvm_vcpu *vcpu);
>>
>> extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu);
>>
>> diff --git a/arch/arm64/include/asm/kvm_emulate.h
>> b/arch/arm64/include/asm/kvm_emulate.h
>> index 8dccbd7..bbbee9d 100644
>> --- a/arch/arm64/include/asm/kvm_emulate.h
>> +++ b/arch/arm64/include/asm/kvm_emulate.h
>> @@
Re: [PATCH v5 3/3] KVM/arm/arm64: enable enhanced armv8 fp/simd lazy switch
On Sun, Dec 06, 2015 at 05:07:14PM -0800, Mario Smarduch wrote:
> This patch tracks armv7 and armv8 fp/simd hardware state with cptr_el2
> register.
> On vcpu_load for 32 bit guests enable FP access, and enable fp/simd
> trapping for 32 and 64 bit guests. On first fp/simd access trap to handler
> to save host and restore guest context, and clear trapping bits to enable
> vcpu
> lazy mode. On vcpu_put if trap bits are clear save guest and restore host
> context and also save 32 bit guest fpexc register.
>
> Signed-off-by: Mario Smarduch
> ---
> arch/arm/include/asm/kvm_emulate.h | 5 ++
> arch/arm/include/asm/kvm_host.h | 2 +
> arch/arm/kvm/arm.c | 20 +--
> arch/arm64/include/asm/kvm_asm.h | 2 +
> arch/arm64/include/asm/kvm_emulate.h | 15 +++--
> arch/arm64/include/asm/kvm_host.h| 16 +-
> arch/arm64/kernel/asm-offsets.c | 1 +
> arch/arm64/kvm/Makefile | 3 +-
> arch/arm64/kvm/fpsimd_switch.S | 38
> arch/arm64/kvm/hyp.S | 108
> +--
> arch/arm64/kvm/hyp_head.S| 48
> 11 files changed, 181 insertions(+), 77 deletions(-)
> create mode 100644 arch/arm64/kvm/fpsimd_switch.S
> create mode 100644 arch/arm64/kvm/hyp_head.S
>
> diff --git a/arch/arm/include/asm/kvm_emulate.h
> b/arch/arm/include/asm/kvm_emulate.h
> index 3de11a2..13feed5 100644
> --- a/arch/arm/include/asm/kvm_emulate.h
> +++ b/arch/arm/include/asm/kvm_emulate.h
> @@ -243,6 +243,11 @@ static inline unsigned long
> vcpu_data_host_to_guest(struct kvm_vcpu *vcpu,
> }
> }
>
> +static inline bool kvm_guest_vcpu_is_32bit(struct kvm_vcpu *vcpu)
> +{
> + return true;
> +}
> +
> #ifdef CONFIG_VFPv3
> /* Called from vcpu_load - save fpexc and enable guest access to fp/simd
> unit */
> static inline void kvm_enable_vcpu_fpexc(struct kvm_vcpu *vcpu)
> diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
> index ecc883a..720ae51 100644
> --- a/arch/arm/include/asm/kvm_host.h
> +++ b/arch/arm/include/asm/kvm_host.h
> @@ -227,6 +227,8 @@ int kvm_perf_teardown(void);
> void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
>
> struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
> +
> +static inline void kvm_save_guest_vcpu_fpexc(struct kvm_vcpu *vcpu) {}
> void kvm_restore_host_vfp_state(struct kvm_vcpu *);
>
> static inline void kvm_arch_hardware_disable(void) {}
> diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
> index 1de07ab..dd59f8a 100644
> --- a/arch/arm/kvm/arm.c
> +++ b/arch/arm/kvm/arm.c
> @@ -292,8 +292,12 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
>
> kvm_arm_set_running_vcpu(vcpu);
>
> - /* Save and enable FPEXC before we load guest context */
> - kvm_enable_vcpu_fpexc(vcpu);
> + /*
> + * For 32bit guest executing on arm64, enable fp/simd access in
> + * EL2. On arm32 save host fpexc and then enable fp/simd access.
> + */
> + if (kvm_guest_vcpu_is_32bit(vcpu))
> + kvm_enable_vcpu_fpexc(vcpu);
>
> /* reset hyp cptr register to trap on tracing and vfp/simd access*/
> vcpu_reset_cptr(vcpu);
> @@ -302,10 +306,18 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
> void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
> {
> /* If the fp/simd registers are dirty save guest, restore host. */
> - if (kvm_vcpu_vfp_isdirty(vcpu))
> + if (kvm_vcpu_vfp_isdirty(vcpu)) {
> kvm_restore_host_vfp_state(vcpu);
>
> - /* Restore host FPEXC trashed in vcpu_load */
> + /*
> + * For 32bit guest on arm64 save the guest fpexc register
> + * in EL2 mode.
> + */
> + if (kvm_guest_vcpu_is_32bit(vcpu))
> + kvm_save_guest_vcpu_fpexc(vcpu);
> + }
> +
> + /* For arm32 restore host FPEXC trashed in vcpu_load. */
> kvm_restore_host_fpexc(vcpu);
>
> /*
> diff --git a/arch/arm64/include/asm/kvm_asm.h
> b/arch/arm64/include/asm/kvm_asm.h
> index 5e37710..d53d069 100644
> --- a/arch/arm64/include/asm/kvm_asm.h
> +++ b/arch/arm64/include/asm/kvm_asm.h
> @@ -117,6 +117,8 @@ extern char __kvm_hyp_vector[];
> extern void __kvm_flush_vm_context(void);
> extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa);
> extern void __kvm_tlb_flush_vmid(struct kvm *kvm);
> +extern void __kvm_vcpu_enable_fpexc32(void);
> +extern void __kvm_vcpu_save_fpexc32(struct kvm_vcpu *vcpu);
>
> extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu);
>
> diff --git a/arch/arm64/include/asm/kvm_emulate.h
> b/arch/arm64/include/asm/kvm_emulate.h
> index 8dccbd7..bbbee9d 100644
> --- a/arch/arm64/include/asm/kvm_emulate.h
> +++ b/arch/arm64/include/asm/kvm_emulate.h
> @@ -290,13 +290,20 @@ static inline unsigned long
> vcpu_data_host_to_guest(struct kvm_vcpu *vcpu,
> return data;/* Leave LE
