@@ -557,6 +557,68 @@ static __always_inline void kvm_incr_pc(struct kvm_vcpu *vcpu)
557557 vcpu_set_flag((v), e); \
558558 } while (0)
559559
560+ #define __build_check_all_or_none (r , bits ) \
561+ BUILD_BUG_ON(((r) & (bits)) && ((r) & (bits)) != (bits))
562+
563+ #define __cpacr_to_cptr_clr (clr , set ) \
564+ ({ \
565+ u64 cptr = 0; \
566+ \
567+ if ((set) & CPACR_ELx_FPEN) \
568+ cptr |= CPTR_EL2_TFP; \
569+ if ((set) & CPACR_ELx_ZEN) \
570+ cptr |= CPTR_EL2_TZ; \
571+ if ((set) & CPACR_ELx_SMEN) \
572+ cptr |= CPTR_EL2_TSM; \
573+ if ((clr) & CPACR_ELx_TTA) \
574+ cptr |= CPTR_EL2_TTA; \
575+ if ((clr) & CPTR_EL2_TAM) \
576+ cptr |= CPTR_EL2_TAM; \
577+ if ((clr) & CPTR_EL2_TCPAC) \
578+ cptr |= CPTR_EL2_TCPAC; \
579+ \
580+ cptr; \
581+ })
582+
583+ #define __cpacr_to_cptr_set (clr , set ) \
584+ ({ \
585+ u64 cptr = 0; \
586+ \
587+ if ((clr) & CPACR_ELx_FPEN) \
588+ cptr |= CPTR_EL2_TFP; \
589+ if ((clr) & CPACR_ELx_ZEN) \
590+ cptr |= CPTR_EL2_TZ; \
591+ if ((clr) & CPACR_ELx_SMEN) \
592+ cptr |= CPTR_EL2_TSM; \
593+ if ((set) & CPACR_ELx_TTA) \
594+ cptr |= CPTR_EL2_TTA; \
595+ if ((set) & CPTR_EL2_TAM) \
596+ cptr |= CPTR_EL2_TAM; \
597+ if ((set) & CPTR_EL2_TCPAC) \
598+ cptr |= CPTR_EL2_TCPAC; \
599+ \
600+ cptr; \
601+ })
602+
603+ #define cpacr_clear_set (clr , set ) \
604+ do { \
605+ BUILD_BUG_ON((set) & CPTR_VHE_EL2_RES0); \
606+ BUILD_BUG_ON((clr) & CPACR_ELx_E0POE); \
607+ __build_check_all_or_none((clr), CPACR_ELx_FPEN); \
608+ __build_check_all_or_none((set), CPACR_ELx_FPEN); \
609+ __build_check_all_or_none((clr), CPACR_ELx_ZEN); \
610+ __build_check_all_or_none((set), CPACR_ELx_ZEN); \
611+ __build_check_all_or_none((clr), CPACR_ELx_SMEN); \
612+ __build_check_all_or_none((set), CPACR_ELx_SMEN); \
613+ \
614+ if (has_vhe() || has_hvhe()) \
615+ sysreg_clear_set(cpacr_el1, clr, set); \
616+ else \
617+ sysreg_clear_set(cptr_el2, \
618+ __cpacr_to_cptr_clr(clr, set), \
619+ __cpacr_to_cptr_set(clr, set));\
620+ } while (0)
621+
560622static __always_inline void kvm_write_cptr_el2 (u64 val )
561623{
562624 if (has_vhe () || has_hvhe ())
@@ -570,17 +632,16 @@ static __always_inline u64 kvm_get_reset_cptr_el2(struct kvm_vcpu *vcpu)
570632 u64 val ;
571633
572634 if (has_vhe ()) {
573- val = (CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN |
574- CPACR_EL1_ZEN_EL1EN );
635+ val = (CPACR_ELx_FPEN | CPACR_EL1_ZEN_EL1EN );
575636 if (cpus_have_final_cap (ARM64_SME ))
576637 val |= CPACR_EL1_SMEN_EL1EN ;
577638 } else if (has_hvhe ()) {
578- val = ( CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN ) ;
639+ val = CPACR_ELx_FPEN ;
579640
580641 if (!vcpu_has_sve (vcpu ) || !guest_owns_fp_regs ())
581- val |= CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN ;
642+ val |= CPACR_ELx_ZEN ;
582643 if (cpus_have_final_cap (ARM64_SME ))
583- val |= CPACR_EL1_SMEN_EL1EN | CPACR_EL1_SMEN_EL0EN ;
644+ val |= CPACR_ELx_SMEN ;
584645 } else {
585646 val = CPTR_NVHE_EL2_RES1 ;
586647
0 commit comments