Skip to content

Commit f4298ca

Browse files
committed
Merge tag 'kvmarm-fixes-6.1-3' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into HEAD
* Fix the pKVM stage-1 walker erronously using the stage-2 accessor * Correctly convert vcpu->kvm to a hyp pointer when generating an exception in a nVHE+MTE configuration * Check that KVM_CAP_DIRTY_LOG_* are valid before enabling them * Fix SMPRI_EL1/TPIDR2_EL0 trapping on VHE * Document the boot requirements for FGT when entering the kernel at EL1
2 parents 1462014 + be0ddf5 commit f4298ca

File tree

7 files changed

+34
-36
lines changed

7 files changed

+34
-36
lines changed

Documentation/arm64/booting.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ Before jumping into the kernel, the following conditions must be met:
340340
- SMCR_EL2.LEN must be initialised to the same value for all CPUs the
341341
kernel will execute on.
342342

343+
- HWFGRTR_EL2.nTPIDR2_EL0 (bit 55) must be initialised to 0b01.
344+
345+
- HWFGWTR_EL2.nTPIDR2_EL0 (bit 55) must be initialised to 0b01.
346+
347+
- HWFGRTR_EL2.nSMPRI_EL1 (bit 54) must be initialised to 0b01.
348+
349+
- HWFGWTR_EL2.nSMPRI_EL1 (bit 54) must be initialised to 0b01.
350+
343351
For CPUs with the Scalable Matrix Extension FA64 feature (FEAT_SME_FA64)
344352

345353
- If EL3 is present:

arch/arm64/kvm/hyp/exception.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <hyp/adjust_pc.h>
1414
#include <linux/kvm_host.h>
1515
#include <asm/kvm_emulate.h>
16+
#include <asm/kvm_mmu.h>
1617

1718
#if !defined (__KVM_NVHE_HYPERVISOR__) && !defined (__KVM_VHE_HYPERVISOR__)
1819
#error Hypervisor code only!
@@ -115,7 +116,7 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode,
115116
new |= (old & PSR_C_BIT);
116117
new |= (old & PSR_V_BIT);
117118

118-
if (kvm_has_mte(vcpu->kvm))
119+
if (kvm_has_mte(kern_hyp_va(vcpu->kvm)))
119120
new |= PSR_TCO_BIT;
120121

121122
new |= (old & PSR_DIT_BIT);

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
8787

8888
vcpu->arch.mdcr_el2_host = read_sysreg(mdcr_el2);
8989
write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
90+
91+
if (cpus_have_final_cap(ARM64_SME)) {
92+
sysreg_clear_set_s(SYS_HFGRTR_EL2,
93+
HFGxTR_EL2_nSMPRI_EL1_MASK |
94+
HFGxTR_EL2_nTPIDR2_EL0_MASK,
95+
0);
96+
sysreg_clear_set_s(SYS_HFGWTR_EL2,
97+
HFGxTR_EL2_nSMPRI_EL1_MASK |
98+
HFGxTR_EL2_nTPIDR2_EL0_MASK,
99+
0);
100+
}
90101
}
91102

92103
static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu)
@@ -96,6 +107,15 @@ static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu)
96107
write_sysreg(0, hstr_el2);
97108
if (kvm_arm_support_pmu_v3())
98109
write_sysreg(0, pmuserenr_el0);
110+
111+
if (cpus_have_final_cap(ARM64_SME)) {
112+
sysreg_clear_set_s(SYS_HFGRTR_EL2, 0,
113+
HFGxTR_EL2_nSMPRI_EL1_MASK |
114+
HFGxTR_EL2_nTPIDR2_EL0_MASK);
115+
sysreg_clear_set_s(SYS_HFGWTR_EL2, 0,
116+
HFGxTR_EL2_nSMPRI_EL1_MASK |
117+
HFGxTR_EL2_nTPIDR2_EL0_MASK);
118+
}
99119
}
100120

101121
static inline void ___activate_traps(struct kvm_vcpu *vcpu)

arch/arm64/kvm/hyp/nvhe/mem_protect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ static enum pkvm_page_state hyp_get_page_state(kvm_pte_t pte)
516516
if (!kvm_pte_valid(pte))
517517
return PKVM_NOPAGE;
518518

519-
return pkvm_getstate(kvm_pgtable_stage2_pte_prot(pte));
519+
return pkvm_getstate(kvm_pgtable_hyp_pte_prot(pte));
520520
}
521521

522522
static int __hyp_check_page_state_range(u64 addr, u64 size,

arch/arm64/kvm/hyp/nvhe/switch.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
5555
write_sysreg(val, cptr_el2);
5656
write_sysreg(__this_cpu_read(kvm_hyp_vector), vbar_el2);
5757

58-
if (cpus_have_final_cap(ARM64_SME)) {
59-
val = read_sysreg_s(SYS_HFGRTR_EL2);
60-
val &= ~(HFGxTR_EL2_nTPIDR2_EL0_MASK |
61-
HFGxTR_EL2_nSMPRI_EL1_MASK);
62-
write_sysreg_s(val, SYS_HFGRTR_EL2);
63-
64-
val = read_sysreg_s(SYS_HFGWTR_EL2);
65-
val &= ~(HFGxTR_EL2_nTPIDR2_EL0_MASK |
66-
HFGxTR_EL2_nSMPRI_EL1_MASK);
67-
write_sysreg_s(val, SYS_HFGWTR_EL2);
68-
}
69-
7058
if (cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT)) {
7159
struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt;
7260

@@ -110,20 +98,6 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)
11098

11199
write_sysreg(this_cpu_ptr(&kvm_init_params)->hcr_el2, hcr_el2);
112100

113-
if (cpus_have_final_cap(ARM64_SME)) {
114-
u64 val;
115-
116-
val = read_sysreg_s(SYS_HFGRTR_EL2);
117-
val |= HFGxTR_EL2_nTPIDR2_EL0_MASK |
118-
HFGxTR_EL2_nSMPRI_EL1_MASK;
119-
write_sysreg_s(val, SYS_HFGRTR_EL2);
120-
121-
val = read_sysreg_s(SYS_HFGWTR_EL2);
122-
val |= HFGxTR_EL2_nTPIDR2_EL0_MASK |
123-
HFGxTR_EL2_nSMPRI_EL1_MASK;
124-
write_sysreg_s(val, SYS_HFGWTR_EL2);
125-
}
126-
127101
cptr = CPTR_EL2_DEFAULT;
128102
if (vcpu_has_sve(vcpu) && (vcpu->arch.fp_state == FP_STATE_GUEST_OWNED))
129103
cptr |= CPTR_EL2_TZ;

arch/arm64/kvm/hyp/vhe/switch.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
6363
__activate_traps_fpsimd32(vcpu);
6464
}
6565

66-
if (cpus_have_final_cap(ARM64_SME))
67-
write_sysreg(read_sysreg(sctlr_el2) & ~SCTLR_ELx_ENTP2,
68-
sctlr_el2);
69-
7066
write_sysreg(val, cpacr_el1);
7167

7268
write_sysreg(__this_cpu_read(kvm_hyp_vector), vbar_el1);
@@ -88,10 +84,6 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)
8884
*/
8985
asm(ALTERNATIVE("nop", "isb", ARM64_WORKAROUND_SPECULATIVE_AT));
9086

91-
if (cpus_have_final_cap(ARM64_SME))
92-
write_sysreg(read_sysreg(sctlr_el2) | SCTLR_ELx_ENTP2,
93-
sctlr_el2);
94-
9587
write_sysreg(CPACR_EL1_DEFAULT, cpacr_el1);
9688

9789
if (!arm64_kernel_unmapped_at_el0())

virt/kvm/kvm_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,6 +4585,9 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm,
45854585
}
45864586
case KVM_CAP_DIRTY_LOG_RING:
45874587
case KVM_CAP_DIRTY_LOG_RING_ACQ_REL:
4588+
if (!kvm_vm_ioctl_check_extension_generic(kvm, cap->cap))
4589+
return -EINVAL;
4590+
45884591
return kvm_vm_ioctl_enable_dirty_log_ring(kvm, cap->args[0]);
45894592
default:
45904593
return kvm_vm_ioctl_enable_cap(kvm, cap);

0 commit comments

Comments
 (0)