Skip to content

Commit 1c880ea

Browse files
author
Marc Zyngier
committed
Merge branch kvm-arm64/gicv3-tdir-fixes into kvmarm-master/next
* kvm-arm64/gicv3-tdir-fixes: : . : Address two trapping-related issues when running legacy (i.e. GICv3) : guests on GICv5 hosts, courtesy of Sascha Bischoff. : . KVM: arm64: Correct test for ICH_HCR_EL2_TDIR cap for GICv5 hosts KVM: arm64: gic: Enable GICv3 CPUIF trapping on GICv5 hosts if required Signed-off-by: Marc Zyngier <maz@kernel.org>
2 parents 26e013b + 28e505d commit 1c880ea

4 files changed

Lines changed: 22 additions & 14 deletions

File tree

arch/arm64/kernel/cpufeature.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,16 +2335,16 @@ static bool can_trap_icv_dir_el1(const struct arm64_cpu_capabilities *entry,
23352335

23362336
BUILD_BUG_ON(ARM64_HAS_ICH_HCR_EL2_TDIR <= ARM64_HAS_GICV3_CPUIF);
23372337
BUILD_BUG_ON(ARM64_HAS_ICH_HCR_EL2_TDIR <= ARM64_HAS_GICV5_LEGACY);
2338-
if (!this_cpu_has_cap(ARM64_HAS_GICV3_CPUIF) &&
2339-
!is_midr_in_range_list(has_vgic_v3))
2340-
return false;
2341-
23422338
if (!is_hyp_mode_available())
23432339
return false;
23442340

23452341
if (this_cpu_has_cap(ARM64_HAS_GICV5_LEGACY))
23462342
return true;
23472343

2344+
if (!this_cpu_has_cap(ARM64_HAS_GICV3_CPUIF) &&
2345+
!is_midr_in_range_list(has_vgic_v3))
2346+
return false;
2347+
23482348
if (is_kernel_in_hyp_mode())
23492349
res.a1 = read_sysreg_s(SYS_ICH_VTR_EL2);
23502350
else

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,20 @@ void noinstr kvm_compute_ich_hcr_trap_bits(struct alt_instr *alt,
880880
*updptr = cpu_to_le32(insn);
881881
}
882882

883+
void vgic_v3_enable_cpuif_traps(void)
884+
{
885+
u64 traps = vgic_ich_hcr_trap_bits();
886+
887+
if (traps) {
888+
kvm_info("GICv3 sysreg trapping enabled ([%s%s%s%s], reduced performance)\n",
889+
(traps & ICH_HCR_EL2_TALL0) ? "G0" : "",
890+
(traps & ICH_HCR_EL2_TALL1) ? "G1" : "",
891+
(traps & ICH_HCR_EL2_TC) ? "C" : "",
892+
(traps & ICH_HCR_EL2_TDIR) ? "D" : "");
893+
static_branch_enable(&vgic_v3_cpuif_trap);
894+
}
895+
}
896+
883897
/**
884898
* vgic_v3_probe - probe for a VGICv3 compatible interrupt controller
885899
* @info: pointer to the GIC description
@@ -891,7 +905,6 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
891905
{
892906
u64 ich_vtr_el2 = kvm_call_hyp_ret(__vgic_v3_get_gic_config);
893907
bool has_v2;
894-
u64 traps;
895908
int ret;
896909

897910
has_v2 = ich_vtr_el2 >> 63;
@@ -955,15 +968,7 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
955968
kvm_vgic_global_state.ich_vtr_el2 &= ~ICH_VTR_EL2_SEIS;
956969
}
957970

958-
traps = vgic_ich_hcr_trap_bits();
959-
if (traps) {
960-
kvm_info("GICv3 sysreg trapping enabled ([%s%s%s%s], reduced performance)\n",
961-
(traps & ICH_HCR_EL2_TALL0) ? "G0" : "",
962-
(traps & ICH_HCR_EL2_TALL1) ? "G1" : "",
963-
(traps & ICH_HCR_EL2_TC) ? "C" : "",
964-
(traps & ICH_HCR_EL2_TDIR) ? "D" : "");
965-
static_branch_enable(&vgic_v3_cpuif_trap);
966-
}
971+
vgic_v3_enable_cpuif_traps();
967972

968973
kvm_vgic_global_state.vctrl_base = NULL;
969974
kvm_vgic_global_state.type = VGIC_V3;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@ int vgic_v5_probe(const struct gic_kvm_info *info)
4848
static_branch_enable(&kvm_vgic_global_state.gicv3_cpuif);
4949
kvm_info("GCIE legacy system register CPU interface\n");
5050

51+
vgic_v3_enable_cpuif_traps();
52+
5153
return 0;
5254
}

arch/arm64/kvm/vgic/vgic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ void vgic_v3_configure_hcr(struct kvm_vcpu *vcpu, struct ap_list_summary *als);
324324
void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
325325
void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
326326
void vgic_v3_reset(struct kvm_vcpu *vcpu);
327+
void vgic_v3_enable_cpuif_traps(void);
327328
int vgic_v3_probe(const struct gic_kvm_info *info);
328329
int vgic_v3_map_resources(struct kvm *kvm);
329330
int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq);

0 commit comments

Comments
 (0)