Skip to content

Commit 3154bdd

Browse files
committed
Merge tag 'kvmarm-fixes-6.13-2' of https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into HEAD
KVM/arm64 fixes for 6.13, part #2 - Fix confusion with implicitly-shifted MDCR_EL2 masks breaking SPE/TRBE initialization - Align nested page table walker with the intended memory attribute combining rules of the architecture - Prevent userspace from constraining the advertised ASID width, avoiding horrors of guest TLBIs not matching the intended context in hardware - Don't leak references on LPIs when insertion into the translation cache fails
2 parents fac04ef + be7e611 commit 3154bdd

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

arch/arm64/include/asm/el2_setup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
1 << PMSCR_EL2_PA_SHIFT)
8888
msr_s SYS_PMSCR_EL2, x0 // addresses and physical counter
8989
.Lskip_spe_el2_\@:
90-
mov x0, #(MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT)
90+
mov x0, #MDCR_EL2_E2PB_MASK
9191
orr x2, x2, x0 // If we don't have VHE, then
9292
// use EL1&0 translation.
9393

@@ -100,7 +100,7 @@
100100
and x0, x0, TRBIDR_EL1_P
101101
cbnz x0, .Lskip_trace_\@ // If TRBE is available at EL2
102102

103-
mov x0, #(MDCR_EL2_E2TB_MASK << MDCR_EL2_E2TB_SHIFT)
103+
mov x0, #MDCR_EL2_E2TB_MASK
104104
orr x2, x2, x0 // allow the EL1&0 translation
105105
// to own it.
106106

arch/arm64/kernel/hyp-stub.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ SYM_CODE_START_LOCAL(__finalise_el2)
114114

115115
// Use EL2 translations for SPE & TRBE and disable access from EL1
116116
mrs x0, mdcr_el2
117-
bic x0, x0, #(MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT)
118-
bic x0, x0, #(MDCR_EL2_E2TB_MASK << MDCR_EL2_E2TB_SHIFT)
117+
bic x0, x0, #MDCR_EL2_E2PB_MASK
118+
bic x0, x0, #MDCR_EL2_E2TB_MASK
119119
msr mdcr_el2, x0
120120

121121
// Transfer the MM state from EL1 to EL2

arch/arm64/kvm/at.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,15 @@ static u64 compute_par_s12(struct kvm_vcpu *vcpu, u64 s1_par,
739739
final_attr = s1_parattr;
740740
break;
741741
default:
742-
/* MemAttr[2]=0, Device from S2 */
743-
final_attr = s2_memattr & GENMASK(1,0) << 2;
742+
/*
743+
* MemAttr[2]=0, Device from S2.
744+
*
745+
* FWB does not influence the way that stage 1
746+
* memory types and attributes are combined
747+
* with stage 2 Device type and attributes.
748+
*/
749+
final_attr = min(s2_memattr_to_attr(s2_memattr),
750+
s1_parattr);
744751
}
745752
} else {
746753
/* Combination of R_HMNDG, R_TNHFM and R_GQFSF */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)
126126
/* Trap SPE */
127127
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMSVer), feature_ids)) {
128128
mdcr_set |= MDCR_EL2_TPMS;
129-
mdcr_clear |= MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT;
129+
mdcr_clear |= MDCR_EL2_E2PB_MASK;
130130
}
131131

132132
/* Trap Trace Filter */
@@ -143,7 +143,7 @@ static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)
143143

144144
/* Trap External Trace */
145145
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_ExtTrcBuff), feature_ids))
146-
mdcr_clear |= MDCR_EL2_E2TB_MASK << MDCR_EL2_E2TB_SHIFT;
146+
mdcr_clear |= MDCR_EL2_E2TB_MASK;
147147

148148
vcpu->arch.mdcr_el2 |= mdcr_set;
149149
vcpu->arch.mdcr_el2 &= ~mdcr_clear;

arch/arm64/kvm/sys_regs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
26182618
ID_WRITABLE(ID_AA64MMFR0_EL1, ~(ID_AA64MMFR0_EL1_RES0 |
26192619
ID_AA64MMFR0_EL1_TGRAN4_2 |
26202620
ID_AA64MMFR0_EL1_TGRAN64_2 |
2621-
ID_AA64MMFR0_EL1_TGRAN16_2)),
2621+
ID_AA64MMFR0_EL1_TGRAN16_2 |
2622+
ID_AA64MMFR0_EL1_ASIDBITS)),
26222623
ID_WRITABLE(ID_AA64MMFR1_EL1, ~(ID_AA64MMFR1_EL1_RES0 |
26232624
ID_AA64MMFR1_EL1_HCX |
26242625
ID_AA64MMFR1_EL1_TWED |

arch/arm64/kvm/vgic/vgic-its.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,22 @@ static void vgic_its_cache_translation(struct kvm *kvm, struct vgic_its *its,
608608
lockdep_assert_held(&its->its_lock);
609609
vgic_get_irq_kref(irq);
610610

611+
old = xa_store(&its->translation_cache, cache_key, irq, GFP_KERNEL_ACCOUNT);
612+
613+
/*
614+
* Put the reference taken on @irq if the store fails. Intentionally do
615+
* not return the error as the translation cache is best effort.
616+
*/
617+
if (xa_is_err(old)) {
618+
vgic_put_irq(kvm, irq);
619+
return;
620+
}
621+
611622
/*
612623
* We could have raced with another CPU caching the same
613624
* translation behind our back, ensure we don't leak a
614625
* reference if that is the case.
615626
*/
616-
old = xa_store(&its->translation_cache, cache_key, irq, GFP_KERNEL_ACCOUNT);
617627
if (old)
618628
vgic_put_irq(kvm, old);
619629
}

0 commit comments

Comments
 (0)