* [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2
@ 2017-06-09 11:49 Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 01/27] arm64: Add a facility to turn an ESR syndrome into a sysreg encoding Marc Zyngier
` (26 more replies)
0 siblings, 27 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Some systems have less than perfect GICv3 implementations, leading to
all kind of ugly issues (guest hanging, host dying). In order to allow
some level of diagnostic, and in some cases implement workarounds,
this series enables the trapping of both Group-0, Group-1 and Common
sysregs. Mediating the access at EL2 allows some form of sanity
checking that the HW is sometimes sorely lacking.
Instead of fully emulating a GICv3 CPU interface, we still use the
existing HW (list registers, AP registers, VMCR...), which allows the
code to be independent from the rest of the KVM code, and to cope with
partial trapping.
Of course, trapping has a cost, which is why this must be either
enabled on the command line, or selected by another cpu capability
(see Cavium erratum 30115). A quick test on an A57-based platform
shows a 25% hit when repeatedly banging on the trapped registers,
while normal workloads do not seem to suffer noticeably from such
trapping (hackbench variance is in the usual noise, despite being very
IPI happy).
This has been tested on a dual socket Thundex-X and a Freescale
LS-2085a, as well as separately by David Daney and Alex Graf.
I've taken the liberty to rebase David Daney's initial Cavium erratum
30115 workaround on top of this series, and included it here as a
typical use case.
- From v2:
* Added patches that check for illeggal accesses, just in case...
* Fixed a number of bugs in handling BPR1, IAR0
* Tried to clarify the use of the preemption bits
* Renamed the command-line options to refer to kvm-arm
* Added documentation for these options
* Added TBs, ABs, RBs
* Rebased on 4.12-rc4 + d68356cc51e3 (from kvmarm/master)
- From v1:
* Fix bug in DIR handling which would have performed a deactivation even
when EOImode==0
* Some minor cleanups and clarifications.
* All the initial fixes have already been merged.
* Rebased on 4.12-rc3.
David Daney (2):
arm64: Add MIDR values for Cavium cn83XX SoCs
arm64: Add workaround for Cavium Thunder erratum 30115
Marc Zyngier (25):
arm64: Add a facility to turn an ESR syndrome into a sysreg encoding
KVM: arm/arm64: vgic-v3: Add accessors for the ICH_APxRn_EL2 registers
KVM: arm64: Make kvm_condition_valid32() accessible from EL2
KVM: arm64: vgic-v3: Add hook to handle guest GICv3 sysreg accesses at
EL2
KVM: arm64: vgic-v3: Add ICV_BPR1_EL1 handler
KVM: arm64: vgic-v3: Add ICV_IGRPEN1_EL1 handler
KVM: arm64: vgic-v3: Add ICV_IAR1_EL1 handler
KVM: arm64: vgic-v3: Add ICV_EOIR1_EL1 handler
KVM: arm64: vgic-v3: Add ICV_AP1Rn_EL1 handler
KVM: arm64: vgic-v3: Add ICV_HPPIR1_EL1 handler
KVM: arm64: vgic-v3: Enable trapping of Group-1 system registers
KVM: arm64: Enable GICv3 Group-1 sysreg trapping via command-line
KVM: arm64: vgic-v3: Add ICV_BPR0_EL1 handler
KVM: arm64: vgic-v3: Add ICV_IGNREN0_EL1 handler
KVM: arm64: vgic-v3: Add misc Group-0 handlers
KVM: arm64: vgic-v3: Enable trapping of Group-0 system registers
KVM: arm64: Enable GICv3 Group-0 sysreg trapping via command-line
KVM: arm64: vgic-v3: Add ICV_DIR_EL1 handler
KVM: arm64: vgic-v3: Add ICV_RPR_EL1 handler
KVM: arm64: vgic-v3: Add ICV_CTLR_EL1 handler
KVM: arm64: vgic-v3: Add ICV_PMR_EL1 handler
KVM: arm64: Enable GICv3 common sysreg trapping via command-line
KVM: arm64: vgic-v3: Log which GICv3 system registers are trapped
KVM: arm64: Log an error if trapping a read-from-write-only GICv3
access
KVM: arm64: Log an error if trapping a write-to-read-only GICv3 access
Documentation/admin-guide/kernel-parameters.txt | 12 +
Documentation/arm64/silicon-errata.txt | 1 +
arch/arm64/Kconfig | 11 +
arch/arm64/include/asm/cpucaps.h | 3 +-
arch/arm64/include/asm/cputype.h | 2 +
arch/arm64/include/asm/esr.h | 24 +
arch/arm64/include/asm/kvm_hyp.h | 1 +
arch/arm64/include/asm/sysreg.h | 9 +
arch/arm64/kernel/cpu_errata.c | 21 +
arch/arm64/kvm/hyp/switch.c | 14 +
arch/arm64/kvm/sys_regs.c | 27 +-
include/kvm/arm_vgic.h | 1 +
include/linux/irqchip/arm-gic-v3.h | 6 +
virt/kvm/arm/aarch32.c | 2 +-
virt/kvm/arm/hyp/vgic-v3-sr.c | 823 +++++++++++++++++++++++-
virt/kvm/arm/vgic/vgic-v3.c | 45 ++
16 files changed, 980 insertions(+), 22 deletions(-)
--
2.11.0
^ permalink raw reply [flat|nested] 37+ messages in thread
* [PATCH v3 01/27] arm64: Add a facility to turn an ESR syndrome into a sysreg encoding
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 02/27] KVM: arm/arm64: vgic-v3: Add accessors for the ICH_APxRn_EL2 registers Marc Zyngier
` (25 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
It is often useful to compare an ESR syndrome reporting the trapping
of a system register with a value matching that system register.
Since encoding both the sysreg and the ESR version seem to be a bit
overkill, let's add a set of macros that convert an ESR value into
the corresponding sysreg encoding.
We handle both AArch32 and AArch64, taking advantage of identical
encodings between system registers and CP15 accessors.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/include/asm/esr.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h
index 85997c0e5443..e7d8e281ff62 100644
--- a/arch/arm64/include/asm/esr.h
+++ b/arch/arm64/include/asm/esr.h
@@ -19,6 +19,7 @@
#define __ASM_ESR_H
#include <asm/memory.h>
+#include <asm/sysreg.h>
#define ESR_ELx_EC_UNKNOWN (0x00)
#define ESR_ELx_EC_WFx (0x01)
@@ -181,6 +182,29 @@
#define ESR_ELx_SYS64_ISS_SYS_CNTFRQ (ESR_ELx_SYS64_ISS_SYS_VAL(3, 3, 0, 14, 0) | \
ESR_ELx_SYS64_ISS_DIR_READ)
+#define esr_sys64_to_sysreg(e) \
+ sys_reg((((e) & ESR_ELx_SYS64_ISS_OP0_MASK) >> \
+ ESR_ELx_SYS64_ISS_OP0_SHIFT), \
+ (((e) & ESR_ELx_SYS64_ISS_OP1_MASK) >> \
+ ESR_ELx_SYS64_ISS_OP1_SHIFT), \
+ (((e) & ESR_ELx_SYS64_ISS_CRN_MASK) >> \
+ ESR_ELx_SYS64_ISS_CRN_SHIFT), \
+ (((e) & ESR_ELx_SYS64_ISS_CRM_MASK) >> \
+ ESR_ELx_SYS64_ISS_CRM_SHIFT), \
+ (((e) & ESR_ELx_SYS64_ISS_OP2_MASK) >> \
+ ESR_ELx_SYS64_ISS_OP2_SHIFT))
+
+#define esr_cp15_to_sysreg(e) \
+ sys_reg(3, \
+ (((e) & ESR_ELx_SYS64_ISS_OP1_MASK) >> \
+ ESR_ELx_SYS64_ISS_OP1_SHIFT), \
+ (((e) & ESR_ELx_SYS64_ISS_CRN_MASK) >> \
+ ESR_ELx_SYS64_ISS_CRN_SHIFT), \
+ (((e) & ESR_ELx_SYS64_ISS_CRM_MASK) >> \
+ ESR_ELx_SYS64_ISS_CRM_SHIFT), \
+ (((e) & ESR_ELx_SYS64_ISS_OP2_MASK) >> \
+ ESR_ELx_SYS64_ISS_OP2_SHIFT))
+
#ifndef __ASSEMBLY__
#include <asm/types.h>
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 02/27] KVM: arm/arm64: vgic-v3: Add accessors for the ICH_APxRn_EL2 registers
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 01/27] arm64: Add a facility to turn an ESR syndrome into a sysreg encoding Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 03/27] KVM: arm64: Make kvm_condition_valid32() accessible from EL2 Marc Zyngier
` (24 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
As we're about to access the Active Priority registers a lot more,
let's define accessors that take the register number as a parameter.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
virt/kvm/arm/hyp/vgic-v3-sr.c | 116 ++++++++++++++++++++++++++++++++++++------
1 file changed, 100 insertions(+), 16 deletions(-)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 87940364570b..3dd8f0c4419e 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -118,6 +118,90 @@ static void __hyp_text __gic_v3_set_lr(u64 val, int lr)
}
}
+static void __hyp_text __vgic_v3_write_ap0rn(u32 val, int n)
+{
+ switch (n) {
+ case 0:
+ write_gicreg(val, ICH_AP0R0_EL2);
+ break;
+ case 1:
+ write_gicreg(val, ICH_AP0R1_EL2);
+ break;
+ case 2:
+ write_gicreg(val, ICH_AP0R2_EL2);
+ break;
+ case 3:
+ write_gicreg(val, ICH_AP0R3_EL2);
+ break;
+ }
+}
+
+static void __hyp_text __vgic_v3_write_ap1rn(u32 val, int n)
+{
+ switch (n) {
+ case 0:
+ write_gicreg(val, ICH_AP1R0_EL2);
+ break;
+ case 1:
+ write_gicreg(val, ICH_AP1R1_EL2);
+ break;
+ case 2:
+ write_gicreg(val, ICH_AP1R2_EL2);
+ break;
+ case 3:
+ write_gicreg(val, ICH_AP1R3_EL2);
+ break;
+ }
+}
+
+static u32 __hyp_text __vgic_v3_read_ap0rn(int n)
+{
+ u32 val;
+
+ switch (n) {
+ case 0:
+ val = read_gicreg(ICH_AP0R0_EL2);
+ break;
+ case 1:
+ val = read_gicreg(ICH_AP0R1_EL2);
+ break;
+ case 2:
+ val = read_gicreg(ICH_AP0R2_EL2);
+ break;
+ case 3:
+ val = read_gicreg(ICH_AP0R3_EL2);
+ break;
+ default:
+ unreachable();
+ }
+
+ return val;
+}
+
+static u32 __hyp_text __vgic_v3_read_ap1rn(int n)
+{
+ u32 val;
+
+ switch (n) {
+ case 0:
+ val = read_gicreg(ICH_AP1R0_EL2);
+ break;
+ case 1:
+ val = read_gicreg(ICH_AP1R1_EL2);
+ break;
+ case 2:
+ val = read_gicreg(ICH_AP1R2_EL2);
+ break;
+ case 3:
+ val = read_gicreg(ICH_AP1R3_EL2);
+ break;
+ default:
+ unreachable();
+ }
+
+ return val;
+}
+
void __hyp_text __vgic_v3_save_state(struct kvm_vcpu *vcpu)
{
struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3;
@@ -154,22 +238,22 @@ void __hyp_text __vgic_v3_save_state(struct kvm_vcpu *vcpu)
switch (nr_pre_bits) {
case 7:
- cpu_if->vgic_ap0r[3] = read_gicreg(ICH_AP0R3_EL2);
- cpu_if->vgic_ap0r[2] = read_gicreg(ICH_AP0R2_EL2);
+ cpu_if->vgic_ap0r[3] = __vgic_v3_read_ap0rn(3);
+ cpu_if->vgic_ap0r[2] = __vgic_v3_read_ap0rn(2);
case 6:
- cpu_if->vgic_ap0r[1] = read_gicreg(ICH_AP0R1_EL2);
+ cpu_if->vgic_ap0r[1] = __vgic_v3_read_ap0rn(1);
default:
- cpu_if->vgic_ap0r[0] = read_gicreg(ICH_AP0R0_EL2);
+ cpu_if->vgic_ap0r[0] = __vgic_v3_read_ap0rn(0);
}
switch (nr_pre_bits) {
case 7:
- cpu_if->vgic_ap1r[3] = read_gicreg(ICH_AP1R3_EL2);
- cpu_if->vgic_ap1r[2] = read_gicreg(ICH_AP1R2_EL2);
+ cpu_if->vgic_ap1r[3] = __vgic_v3_read_ap1rn(3);
+ cpu_if->vgic_ap1r[2] = __vgic_v3_read_ap1rn(2);
case 6:
- cpu_if->vgic_ap1r[1] = read_gicreg(ICH_AP1R1_EL2);
+ cpu_if->vgic_ap1r[1] = __vgic_v3_read_ap1rn(1);
default:
- cpu_if->vgic_ap1r[0] = read_gicreg(ICH_AP1R0_EL2);
+ cpu_if->vgic_ap1r[0] = __vgic_v3_read_ap1rn(0);
}
} else {
cpu_if->vgic_elrsr = 0xffff;
@@ -224,22 +308,22 @@ void __hyp_text __vgic_v3_restore_state(struct kvm_vcpu *vcpu)
switch (nr_pre_bits) {
case 7:
- write_gicreg(cpu_if->vgic_ap0r[3], ICH_AP0R3_EL2);
- write_gicreg(cpu_if->vgic_ap0r[2], ICH_AP0R2_EL2);
+ __vgic_v3_write_ap0rn(cpu_if->vgic_ap0r[3], 3);
+ __vgic_v3_write_ap0rn(cpu_if->vgic_ap0r[2], 2);
case 6:
- write_gicreg(cpu_if->vgic_ap0r[1], ICH_AP0R1_EL2);
+ __vgic_v3_write_ap0rn(cpu_if->vgic_ap0r[1], 1);
default:
- write_gicreg(cpu_if->vgic_ap0r[0], ICH_AP0R0_EL2);
+ __vgic_v3_write_ap0rn(cpu_if->vgic_ap0r[0], 0);
}
switch (nr_pre_bits) {
case 7:
- write_gicreg(cpu_if->vgic_ap1r[3], ICH_AP1R3_EL2);
- write_gicreg(cpu_if->vgic_ap1r[2], ICH_AP1R2_EL2);
+ __vgic_v3_write_ap1rn(cpu_if->vgic_ap1r[3], 3);
+ __vgic_v3_write_ap1rn(cpu_if->vgic_ap1r[2], 2);
case 6:
- write_gicreg(cpu_if->vgic_ap1r[1], ICH_AP1R1_EL2);
+ __vgic_v3_write_ap1rn(cpu_if->vgic_ap1r[1], 1);
default:
- write_gicreg(cpu_if->vgic_ap1r[0], ICH_AP1R0_EL2);
+ __vgic_v3_write_ap1rn(cpu_if->vgic_ap1r[0], 0);
}
for (i = 0; i < used_lrs; i++)
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 03/27] KVM: arm64: Make kvm_condition_valid32() accessible from EL2
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 01/27] arm64: Add a facility to turn an ESR syndrome into a sysreg encoding Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 02/27] KVM: arm/arm64: vgic-v3: Add accessors for the ICH_APxRn_EL2 registers Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 04/27] KVM: arm64: vgic-v3: Add hook to handle guest GICv3 sysreg accesses at EL2 Marc Zyngier
` (23 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
As we're about to trap CP15 accesses and handle them at EL2, we
need to evaluate whether or not the condition flags are valid,
as an implementation is allowed to trap despite the condition
not being met.
Tagging the function as __hyp_text allows this. We still rely on
the cc_map array to be mapped at EL2 by virtue of being "const",
and the linker to only emit relative references.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
virt/kvm/arm/aarch32.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/virt/kvm/arm/aarch32.c b/virt/kvm/arm/aarch32.c
index 528af4b2d09e..79c7c357804b 100644
--- a/virt/kvm/arm/aarch32.c
+++ b/virt/kvm/arm/aarch32.c
@@ -60,7 +60,7 @@ static const unsigned short cc_map[16] = {
/*
* Check if a trapped instruction should have been executed or not.
*/
-bool kvm_condition_valid32(const struct kvm_vcpu *vcpu)
+bool __hyp_text kvm_condition_valid32(const struct kvm_vcpu *vcpu)
{
unsigned long cpsr;
u32 cpsr_cond;
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 04/27] KVM: arm64: vgic-v3: Add hook to handle guest GICv3 sysreg accesses at EL2
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (2 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 03/27] KVM: arm64: Make kvm_condition_valid32() accessible from EL2 Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 05/27] KVM: arm64: vgic-v3: Add ICV_BPR1_EL1 handler Marc Zyngier
` (22 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
In order to start handling guest access to GICv3 system registers,
let's add a hook that will get called when we trap a system register
access. This is gated by a new static key (vgic_v3_cpuif_trap).
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/include/asm/kvm_hyp.h | 1 +
arch/arm64/kvm/hyp/switch.c | 14 ++++++++++++++
include/kvm/arm_vgic.h | 1 +
virt/kvm/arm/hyp/vgic-v3-sr.c | 38 ++++++++++++++++++++++++++++++++++++++
virt/kvm/arm/vgic/vgic-v3.c | 2 ++
5 files changed, 56 insertions(+)
diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h
index b18e852d27e8..4572a9b560fa 100644
--- a/arch/arm64/include/asm/kvm_hyp.h
+++ b/arch/arm64/include/asm/kvm_hyp.h
@@ -127,6 +127,7 @@ int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu);
void __vgic_v3_save_state(struct kvm_vcpu *vcpu);
void __vgic_v3_restore_state(struct kvm_vcpu *vcpu);
+int __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu);
void __timer_save_state(struct kvm_vcpu *vcpu);
void __timer_restore_state(struct kvm_vcpu *vcpu);
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
index aede1658aeda..dfd8ca16601b 100644
--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -350,6 +350,20 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
}
}
+ if (static_branch_unlikely(&vgic_v3_cpuif_trap) &&
+ exit_code == ARM_EXCEPTION_TRAP &&
+ (kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_SYS64 ||
+ kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_CP15_32)) {
+ int ret = __vgic_v3_perform_cpuif_access(vcpu);
+
+ if (ret == 1) {
+ __skip_instr(vcpu);
+ goto again;
+ }
+
+ /* 0 falls through to be handled out of EL2 */
+ }
+
fp_enabled = __fpsimd_enabled();
__sysreg_save_guest_state(guest_ctxt);
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
index ef718586321c..39b9fc4dc65d 100644
--- a/include/kvm/arm_vgic.h
+++ b/include/kvm/arm_vgic.h
@@ -285,6 +285,7 @@ struct vgic_cpu {
};
extern struct static_key_false vgic_v2_cpuif_trap;
+extern struct static_key_false vgic_v3_cpuif_trap;
int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write);
void kvm_vgic_early_init(struct kvm *kvm);
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 3dd8f0c4419e..e6c05b95a1b1 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -19,6 +19,7 @@
#include <linux/irqchip/arm-gic-v3.h>
#include <linux/kvm_host.h>
+#include <asm/kvm_emulate.h>
#include <asm/kvm_hyp.h>
#define vtr_to_max_lr_idx(v) ((v) & 0xf)
@@ -371,3 +372,40 @@ void __hyp_text __vgic_v3_write_vmcr(u32 vmcr)
{
write_gicreg(vmcr, ICH_VMCR_EL2);
}
+
+#ifdef CONFIG_ARM64
+
+int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
+{
+ int rt;
+ u32 esr;
+ u32 vmcr;
+ void (*fn)(struct kvm_vcpu *, u32, int);
+ bool is_read;
+ u32 sysreg;
+
+ esr = kvm_vcpu_get_hsr(vcpu);
+ if (vcpu_mode_is_32bit(vcpu)) {
+ if (!kvm_condition_valid(vcpu))
+ return 1;
+
+ sysreg = esr_cp15_to_sysreg(esr);
+ } else {
+ sysreg = esr_sys64_to_sysreg(esr);
+ }
+
+ is_read = (esr & ESR_ELx_SYS64_ISS_DIR_MASK) == ESR_ELx_SYS64_ISS_DIR_READ;
+
+ switch (sysreg) {
+ default:
+ return 0;
+ }
+
+ vmcr = __vgic_v3_read_vmcr();
+ rt = kvm_vcpu_sys_get_rt(vcpu);
+ fn(vcpu, vmcr, rt);
+
+ return 1;
+}
+
+#endif
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index 6fe3f003636a..88d9bd9bf468 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -410,6 +410,8 @@ int vgic_v3_map_resources(struct kvm *kvm)
return ret;
}
+DEFINE_STATIC_KEY_FALSE(vgic_v3_cpuif_trap);
+
/**
* vgic_v3_probe - probe for a GICv3 compatible interrupt controller in DT
* @node: pointer to the DT node
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 05/27] KVM: arm64: vgic-v3: Add ICV_BPR1_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (3 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 04/27] KVM: arm64: vgic-v3: Add hook to handle guest GICv3 sysreg accesses at EL2 Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 15:23 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 06/27] KVM: arm64: vgic-v3: Add ICV_IGRPEN1_EL1 handler Marc Zyngier
` (21 subsequent siblings)
26 siblings, 1 reply; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for reading/writing the guest's view of the ICC_BPR1_EL1
register, which is located in the ICH_VMCR_EL2.BPR1 field.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
virt/kvm/arm/hyp/vgic-v3-sr.c | 57 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index e6c05b95a1b1..fe021abc8b51 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -375,6 +375,57 @@ void __hyp_text __vgic_v3_write_vmcr(u32 vmcr)
#ifdef CONFIG_ARM64
+static int __hyp_text __vgic_v3_bpr_min(void)
+{
+ /* See Pseudocode for VPriorityGroup */
+ return 8 - vtr_to_nr_pre_bits(read_gicreg(ICH_VTR_EL2));
+}
+
+static unsigned int __hyp_text __vgic_v3_get_bpr0(u32 vmcr)
+{
+ return (vmcr & ICH_VMCR_BPR0_MASK) >> ICH_VMCR_BPR0_SHIFT;
+}
+
+static unsigned int __hyp_text __vgic_v3_get_bpr1(u32 vmcr)
+{
+ unsigned int bpr;
+
+ if (vmcr & ICH_VMCR_CBPR_MASK) {
+ bpr = __vgic_v3_get_bpr0(vmcr);
+ if (bpr < 7)
+ bpr++;
+ } else {
+ bpr = (vmcr & ICH_VMCR_BPR1_MASK) >> ICH_VMCR_BPR1_SHIFT;
+ }
+
+ return bpr;
+}
+
+static void __hyp_text __vgic_v3_read_bpr1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
+{
+ vcpu_set_reg(vcpu, rt, __vgic_v3_get_bpr1(vmcr));
+}
+
+static void __hyp_text __vgic_v3_write_bpr1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
+{
+ u64 val = vcpu_get_reg(vcpu, rt);
+ u8 bpr_min = __vgic_v3_bpr_min();
+
+ if (vmcr & ICH_VMCR_CBPR_MASK)
+ return;
+
+ /* Enforce BPR limiting */
+ if (val < bpr_min)
+ val = bpr_min;
+
+ val <<= ICH_VMCR_BPR1_SHIFT;
+ val &= ICH_VMCR_BPR1_MASK;
+ vmcr &= ~ICH_VMCR_BPR1_MASK;
+ vmcr |= val;
+
+ __vgic_v3_write_vmcr(vmcr);
+}
+
int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
{
int rt;
@@ -397,6 +448,12 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
is_read = (esr & ESR_ELx_SYS64_ISS_DIR_MASK) == ESR_ELx_SYS64_ISS_DIR_READ;
switch (sysreg) {
+ case SYS_ICC_BPR1_EL1:
+ if (is_read)
+ fn = __vgic_v3_read_bpr1;
+ else
+ fn = __vgic_v3_write_bpr1;
+ break;
default:
return 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 06/27] KVM: arm64: vgic-v3: Add ICV_IGRPEN1_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (4 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 05/27] KVM: arm64: vgic-v3: Add ICV_BPR1_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 07/27] KVM: arm64: vgic-v3: Add ICV_IAR1_EL1 handler Marc Zyngier
` (20 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for reading/writing the guest's view of the ICC_IGRPEN1_EL1
register, which is located in the ICH_VMCR_EL2.VENG1 field.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
virt/kvm/arm/hyp/vgic-v3-sr.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index fe021abc8b51..25f09721241f 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -401,6 +401,23 @@ static unsigned int __hyp_text __vgic_v3_get_bpr1(u32 vmcr)
return bpr;
}
+static void __hyp_text __vgic_v3_read_igrpen1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
+{
+ vcpu_set_reg(vcpu, rt, !!(vmcr & ICH_VMCR_ENG1_MASK));
+}
+
+static void __hyp_text __vgic_v3_write_igrpen1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
+{
+ u64 val = vcpu_get_reg(vcpu, rt);
+
+ if (val & 1)
+ vmcr |= ICH_VMCR_ENG1_MASK;
+ else
+ vmcr &= ~ICH_VMCR_ENG1_MASK;
+
+ __vgic_v3_write_vmcr(vmcr);
+}
+
static void __hyp_text __vgic_v3_read_bpr1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
{
vcpu_set_reg(vcpu, rt, __vgic_v3_get_bpr1(vmcr));
@@ -448,6 +465,12 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
is_read = (esr & ESR_ELx_SYS64_ISS_DIR_MASK) == ESR_ELx_SYS64_ISS_DIR_READ;
switch (sysreg) {
+ case SYS_ICC_GRPEN1_EL1:
+ if (is_read)
+ fn = __vgic_v3_read_igrpen1;
+ else
+ fn = __vgic_v3_write_igrpen1;
+ break;
case SYS_ICC_BPR1_EL1:
if (is_read)
fn = __vgic_v3_read_bpr1;
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 07/27] KVM: arm64: vgic-v3: Add ICV_IAR1_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (5 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 06/27] KVM: arm64: vgic-v3: Add ICV_IGRPEN1_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 15:26 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 08/27] KVM: arm64: vgic-v3: Add ICV_EOIR1_EL1 handler Marc Zyngier
` (19 subsequent siblings)
26 siblings, 1 reply; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for reading the guest's view of the ICC_IAR1_EL1
register. This involves finding the highest priority Group-1
interrupt, checking against both PMR and the active group
priority, activating the interrupt and setting the group
priority as active.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
include/linux/irqchip/arm-gic-v3.h | 1 +
virt/kvm/arm/hyp/vgic-v3-sr.c | 163 +++++++++++++++++++++++++++++++++++++
2 files changed, 164 insertions(+)
diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
index fffb91202bc9..401db585a534 100644
--- a/include/linux/irqchip/arm-gic-v3.h
+++ b/include/linux/irqchip/arm-gic-v3.h
@@ -405,6 +405,7 @@
#define ICH_LR_PHYS_ID_SHIFT 32
#define ICH_LR_PHYS_ID_MASK (0x3ffULL << ICH_LR_PHYS_ID_SHIFT)
#define ICH_LR_PRIORITY_SHIFT 48
+#define ICH_LR_PRIORITY_MASK (0xffULL << ICH_LR_PRIORITY_SHIFT)
/* These are for GICv2 emulation only */
#define GICH_LR_VIRTUALID (0x3ffUL << 0)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 25f09721241f..5a20f8d5bada 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -24,6 +24,7 @@
#define vtr_to_max_lr_idx(v) ((v) & 0xf)
#define vtr_to_nr_pre_bits(v) ((((u32)(v) >> 26) & 7) + 1)
+#define vtr_to_nr_apr_regs(v) (1 << (vtr_to_nr_pre_bits(v) - 5))
static u64 __hyp_text __gic_v3_get_lr(unsigned int lr)
{
@@ -381,6 +382,88 @@ static int __hyp_text __vgic_v3_bpr_min(void)
return 8 - vtr_to_nr_pre_bits(read_gicreg(ICH_VTR_EL2));
}
+static int __hyp_text __vgic_v3_get_group(struct kvm_vcpu *vcpu)
+{
+ u32 esr = kvm_vcpu_get_hsr(vcpu);
+ u8 crm = (esr & ESR_ELx_SYS64_ISS_CRM_MASK) >> ESR_ELx_SYS64_ISS_CRM_SHIFT;
+
+ return crm != 8;
+}
+
+#define GICv3_IDLE_PRIORITY 0xff
+
+static int __hyp_text __vgic_v3_highest_priority_lr(struct kvm_vcpu *vcpu,
+ u32 vmcr,
+ u64 *lr_val)
+{
+ unsigned int used_lrs = vcpu->arch.vgic_cpu.used_lrs;
+ u8 priority = GICv3_IDLE_PRIORITY;
+ int i, lr = -1;
+
+ for (i = 0; i < used_lrs; i++) {
+ u64 val = __gic_v3_get_lr(i);
+ u8 lr_prio = (val & ICH_LR_PRIORITY_MASK) >> ICH_LR_PRIORITY_SHIFT;
+
+ /* Not pending in the state? */
+ if ((val & ICH_LR_STATE) != ICH_LR_PENDING_BIT)
+ continue;
+
+ /* Group-0 interrupt, but Group-0 disabled? */
+ if (!(val & ICH_LR_GROUP) && !(vmcr & ICH_VMCR_ENG0_MASK))
+ continue;
+
+ /* Group-1 interrupt, but Group-1 disabled? */
+ if ((val & ICH_LR_GROUP) && !(vmcr & ICH_VMCR_ENG1_MASK))
+ continue;
+
+ /* Not the highest priority? */
+ if (lr_prio >= priority)
+ continue;
+
+ /* This is a candidate */
+ priority = lr_prio;
+ *lr_val = val;
+ lr = i;
+ }
+
+ if (lr == -1)
+ *lr_val = ICC_IAR1_EL1_SPURIOUS;
+
+ return lr;
+}
+
+static int __hyp_text __vgic_v3_get_highest_active_priority(void)
+{
+ u8 nr_apr_regs = vtr_to_nr_apr_regs(read_gicreg(ICH_VTR_EL2));
+ u32 hap = 0;
+ int i;
+
+ for (i = 0; i < nr_apr_regs; i++) {
+ u32 val;
+
+ /*
+ * The ICH_AP0Rn_EL2 and ICH_AP1Rn_EL2 registers
+ * contain the active priority levels for this VCPU
+ * for the maximum number of supported priority
+ * levels, and we return the full priority level only
+ * if the BPR is programmed to its minimum, otherwise
+ * we return a combination of the priority level and
+ * subpriority, as determined by the setting of the
+ * BPR, but without the full subpriority.
+ */
+ val = __vgic_v3_read_ap0rn(i);
+ val |= __vgic_v3_read_ap1rn(i);
+ if (!val) {
+ hap += 32;
+ continue;
+ }
+
+ return (hap + __ffs(val)) << __vgic_v3_bpr_min();
+ }
+
+ return GICv3_IDLE_PRIORITY;
+}
+
static unsigned int __hyp_text __vgic_v3_get_bpr0(u32 vmcr)
{
return (vmcr & ICH_VMCR_BPR0_MASK) >> ICH_VMCR_BPR0_SHIFT;
@@ -401,6 +484,83 @@ static unsigned int __hyp_text __vgic_v3_get_bpr1(u32 vmcr)
return bpr;
}
+/*
+ * Convert a priority to a preemption level, taking the relevant BPR
+ * into account by zeroing the sub-priority bits.
+ */
+static u8 __hyp_text __vgic_v3_pri_to_pre(u8 pri, u32 vmcr, int grp)
+{
+ unsigned int bpr;
+
+ if (!grp)
+ bpr = __vgic_v3_get_bpr0(vmcr) + 1;
+ else
+ bpr = __vgic_v3_get_bpr1(vmcr);
+
+ return pri & (GENMASK(7, 0) << bpr);
+}
+
+/*
+ * The priority value is independent of any of the BPR values, so we
+ * normalize it using the minumal BPR value. This guarantees that no
+ * matter what the guest does with its BPR, we can always set/get the
+ * same value of a priority.
+ */
+static void __hyp_text __vgic_v3_set_active_priority(u8 pri, u32 vmcr, int grp)
+{
+ u8 pre, ap;
+ u32 val;
+ int apr;
+
+ pre = __vgic_v3_pri_to_pre(pri, vmcr, grp);
+ ap = pre >> __vgic_v3_bpr_min();
+ apr = ap / 32;
+
+ if (!grp) {
+ val = __vgic_v3_read_ap0rn(apr);
+ __vgic_v3_write_ap0rn(val | BIT(ap % 32), apr);
+ } else {
+ val = __vgic_v3_read_ap1rn(apr);
+ __vgic_v3_write_ap1rn(val | BIT(ap % 32), apr);
+ }
+}
+
+static void __hyp_text __vgic_v3_read_iar(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
+{
+ u64 lr_val;
+ u8 lr_prio, pmr;
+ int lr, grp;
+
+ grp = __vgic_v3_get_group(vcpu);
+
+ lr = __vgic_v3_highest_priority_lr(vcpu, vmcr, &lr_val);
+ if (lr < 0)
+ goto spurious;
+
+ if (grp != !!(lr_val & ICH_LR_GROUP))
+ goto spurious;
+
+ pmr = (vmcr & ICH_VMCR_PMR_MASK) >> ICH_VMCR_PMR_SHIFT;
+ lr_prio = (lr_val & ICH_LR_PRIORITY_MASK) >> ICH_LR_PRIORITY_SHIFT;
+ if (pmr <= lr_prio)
+ goto spurious;
+
+ if (__vgic_v3_get_highest_active_priority() <= __vgic_v3_pri_to_pre(lr_prio, vmcr, grp))
+ goto spurious;
+
+ lr_val &= ~ICH_LR_STATE;
+ /* No active state for LPIs */
+ if ((lr_val & ICH_LR_VIRTUAL_ID_MASK) <= VGIC_MAX_SPI)
+ lr_val |= ICH_LR_ACTIVE_BIT;
+ __gic_v3_set_lr(lr_val, lr);
+ __vgic_v3_set_active_priority(lr_prio, vmcr, grp);
+ vcpu_set_reg(vcpu, rt, lr_val & ICH_LR_VIRTUAL_ID_MASK);
+ return;
+
+spurious:
+ vcpu_set_reg(vcpu, rt, ICC_IAR1_EL1_SPURIOUS);
+}
+
static void __hyp_text __vgic_v3_read_igrpen1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
{
vcpu_set_reg(vcpu, rt, !!(vmcr & ICH_VMCR_ENG1_MASK));
@@ -465,6 +625,9 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
is_read = (esr & ESR_ELx_SYS64_ISS_DIR_MASK) == ESR_ELx_SYS64_ISS_DIR_READ;
switch (sysreg) {
+ case SYS_ICC_IAR1_EL1:
+ fn = __vgic_v3_read_iar;
+ break;
case SYS_ICC_GRPEN1_EL1:
if (is_read)
fn = __vgic_v3_read_igrpen1;
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 08/27] KVM: arm64: vgic-v3: Add ICV_EOIR1_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (6 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 07/27] KVM: arm64: vgic-v3: Add ICV_IAR1_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 15:27 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 09/27] KVM: arm64: vgic-v3: Add ICV_AP1Rn_EL1 handler Marc Zyngier
` (18 subsequent siblings)
26 siblings, 1 reply; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for writing the guest's view of the ICC_EOIR1_EL1
register. This involves dropping the priority of the interrupt,
and deactivating it if required (EOImode == 0).
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
include/linux/irqchip/arm-gic-v3.h | 2 +
virt/kvm/arm/hyp/vgic-v3-sr.c | 120 +++++++++++++++++++++++++++++++++++++
2 files changed, 122 insertions(+)
diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
index 401db585a534..e50ce5d416a3 100644
--- a/include/linux/irqchip/arm-gic-v3.h
+++ b/include/linux/irqchip/arm-gic-v3.h
@@ -417,6 +417,8 @@
#define ICH_HCR_EN (1 << 0)
#define ICH_HCR_UIE (1 << 1)
+#define ICH_HCR_EOIcount_SHIFT 27
+#define ICH_HCR_EOIcount_MASK (0x1f << ICH_HCR_EOIcount_SHIFT)
#define ICH_VMCR_CBPR_SHIFT 4
#define ICH_VMCR_CBPR_MASK (1 << ICH_VMCR_CBPR_SHIFT)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 5a20f8d5bada..e9ff99112c4d 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -432,6 +432,26 @@ static int __hyp_text __vgic_v3_highest_priority_lr(struct kvm_vcpu *vcpu,
return lr;
}
+static int __hyp_text __vgic_v3_find_active_lr(struct kvm_vcpu *vcpu,
+ int intid, u64 *lr_val)
+{
+ unsigned int used_lrs = vcpu->arch.vgic_cpu.used_lrs;
+ int i;
+
+ for (i = 0; i < used_lrs; i++) {
+ u64 val = __gic_v3_get_lr(i);
+
+ if ((val & ICH_LR_VIRTUAL_ID_MASK) == intid &&
+ (val & ICH_LR_ACTIVE_BIT)) {
+ *lr_val = val;
+ return i;
+ }
+ }
+
+ *lr_val = ICC_IAR1_EL1_SPURIOUS;
+ return -1;
+}
+
static int __hyp_text __vgic_v3_get_highest_active_priority(void)
{
u8 nr_apr_regs = vtr_to_nr_apr_regs(read_gicreg(ICH_VTR_EL2));
@@ -525,6 +545,44 @@ static void __hyp_text __vgic_v3_set_active_priority(u8 pri, u32 vmcr, int grp)
}
}
+static int __hyp_text __vgic_v3_clear_highest_active_priority(void)
+{
+ u8 nr_apr_regs = vtr_to_nr_apr_regs(read_gicreg(ICH_VTR_EL2));
+ u32 hap = 0;
+ int i;
+
+ for (i = 0; i < nr_apr_regs; i++) {
+ u32 ap0, ap1;
+ int c0, c1;
+
+ ap0 = __vgic_v3_read_ap0rn(i);
+ ap1 = __vgic_v3_read_ap1rn(i);
+ if (!ap0 && !ap1) {
+ hap += 32;
+ continue;
+ }
+
+ c0 = ap0 ? __ffs(ap0) : 32;
+ c1 = ap1 ? __ffs(ap1) : 32;
+
+ /* Always clear the LSB, which is the highest priority */
+ if (c0 < c1) {
+ ap0 &= ~BIT(c0);
+ __vgic_v3_write_ap0rn(ap0, i);
+ hap += c0;
+ } else {
+ ap1 &= ~BIT(c1);
+ __vgic_v3_write_ap1rn(ap1, i);
+ hap += c1;
+ }
+
+ /* Rescale to 8 bits of priority */
+ return hap << __vgic_v3_bpr_min();
+ }
+
+ return GICv3_IDLE_PRIORITY;
+}
+
static void __hyp_text __vgic_v3_read_iar(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
{
u64 lr_val;
@@ -561,6 +619,65 @@ static void __hyp_text __vgic_v3_read_iar(struct kvm_vcpu *vcpu, u32 vmcr, int r
vcpu_set_reg(vcpu, rt, ICC_IAR1_EL1_SPURIOUS);
}
+static void __hyp_text __vgic_v3_clear_active_lr(int lr, u64 lr_val)
+{
+ lr_val &= ~ICH_LR_ACTIVE_BIT;
+ if (lr_val & ICH_LR_HW) {
+ u32 pid;
+
+ pid = (lr_val & ICH_LR_PHYS_ID_MASK) >> ICH_LR_PHYS_ID_SHIFT;
+ gic_write_dir(pid);
+ }
+
+ __gic_v3_set_lr(lr_val, lr);
+}
+
+static void __hyp_text __vgic_v3_bump_eoicount(void)
+{
+ u32 hcr;
+
+ hcr = read_gicreg(ICH_HCR_EL2);
+ hcr += 1 << ICH_HCR_EOIcount_SHIFT;
+ write_gicreg(hcr, ICH_HCR_EL2);
+}
+
+static void __hyp_text __vgic_v3_write_eoir(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
+{
+ u32 vid = vcpu_get_reg(vcpu, rt);
+ u64 lr_val;
+ u8 lr_prio, act_prio;
+ int lr, grp;
+
+ grp = __vgic_v3_get_group(vcpu);
+
+ /* Drop priority in any case */
+ act_prio = __vgic_v3_clear_highest_active_priority();
+
+ /* If EOIing an LPI, no deactivate to be performed */
+ if (vid >= VGIC_MIN_LPI)
+ return;
+
+ /* EOImode == 1, nothing to be done here */
+ if (vmcr & ICH_VMCR_EOIM_MASK)
+ return;
+
+ lr = __vgic_v3_find_active_lr(vcpu, vid, &lr_val);
+ if (lr == -1) {
+ __vgic_v3_bump_eoicount();
+ return;
+ }
+
+ lr_prio = (lr_val & ICH_LR_PRIORITY_MASK) >> ICH_LR_PRIORITY_SHIFT;
+
+ /* If priorities or group do not match, the guest has fscked-up. */
+ if (grp != !!(lr_val & ICH_LR_GROUP) ||
+ __vgic_v3_pri_to_pre(lr_prio, vmcr, grp) != act_prio)
+ return;
+
+ /* Let's now perform the deactivation */
+ __vgic_v3_clear_active_lr(lr, lr_val);
+}
+
static void __hyp_text __vgic_v3_read_igrpen1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
{
vcpu_set_reg(vcpu, rt, !!(vmcr & ICH_VMCR_ENG1_MASK));
@@ -628,6 +745,9 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
case SYS_ICC_IAR1_EL1:
fn = __vgic_v3_read_iar;
break;
+ case SYS_ICC_EOIR1_EL1:
+ fn = __vgic_v3_write_eoir;
+ break;
case SYS_ICC_GRPEN1_EL1:
if (is_read)
fn = __vgic_v3_read_igrpen1;
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 09/27] KVM: arm64: vgic-v3: Add ICV_AP1Rn_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (7 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 08/27] KVM: arm64: vgic-v3: Add ICV_EOIR1_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 10/27] KVM: arm64: vgic-v3: Add ICV_HPPIR1_EL1 handler Marc Zyngier
` (17 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for reading/writing the guest's view of the ICV_AP1Rn_EL1
registers. We just map them to the corresponding ICH_AP1Rn_EL2 registers.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/include/asm/sysreg.h | 1 +
virt/kvm/arm/hyp/vgic-v3-sr.c | 94 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+)
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 15c142ce991c..aad46b8eea5e 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -180,6 +180,7 @@
#define SYS_VBAR_EL1 sys_reg(3, 0, 12, 0, 0)
+#define SYS_ICC_AP1Rn_EL1(n) sys_reg(3, 0, 12, 9, n)
#define SYS_ICC_DIR_EL1 sys_reg(3, 0, 12, 11, 1)
#define SYS_ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5)
#define SYS_ICC_IAR1_EL1 sys_reg(3, 0, 12, 12, 0)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index e9ff99112c4d..1c85a6df22d9 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -720,6 +720,76 @@ static void __hyp_text __vgic_v3_write_bpr1(struct kvm_vcpu *vcpu, u32 vmcr, int
__vgic_v3_write_vmcr(vmcr);
}
+static void __hyp_text __vgic_v3_read_apxrn(struct kvm_vcpu *vcpu, int rt, int n)
+{
+ u32 val;
+
+ if (!__vgic_v3_get_group(vcpu))
+ val = __vgic_v3_read_ap0rn(n);
+ else
+ val = __vgic_v3_read_ap1rn(n);
+
+ vcpu_set_reg(vcpu, rt, val);
+}
+
+static void __hyp_text __vgic_v3_write_apxrn(struct kvm_vcpu *vcpu, int rt, int n)
+{
+ u32 val = vcpu_get_reg(vcpu, rt);
+
+ if (!__vgic_v3_get_group(vcpu))
+ __vgic_v3_write_ap0rn(val, n);
+ else
+ __vgic_v3_write_ap1rn(val, n);
+}
+
+static void __hyp_text __vgic_v3_read_apxr0(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ __vgic_v3_read_apxrn(vcpu, rt, 0);
+}
+
+static void __hyp_text __vgic_v3_read_apxr1(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ __vgic_v3_read_apxrn(vcpu, rt, 1);
+}
+
+static void __hyp_text __vgic_v3_read_apxr2(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ __vgic_v3_read_apxrn(vcpu, rt, 2);
+}
+
+static void __hyp_text __vgic_v3_read_apxr3(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ __vgic_v3_read_apxrn(vcpu, rt, 3);
+}
+
+static void __hyp_text __vgic_v3_write_apxr0(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ __vgic_v3_write_apxrn(vcpu, rt, 0);
+}
+
+static void __hyp_text __vgic_v3_write_apxr1(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ __vgic_v3_write_apxrn(vcpu, rt, 1);
+}
+
+static void __hyp_text __vgic_v3_write_apxr2(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ __vgic_v3_write_apxrn(vcpu, rt, 2);
+}
+
+static void __hyp_text __vgic_v3_write_apxr3(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ __vgic_v3_write_apxrn(vcpu, rt, 3);
+}
+
int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
{
int rt;
@@ -760,6 +830,30 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
else
fn = __vgic_v3_write_bpr1;
break;
+ case SYS_ICC_AP1Rn_EL1(0):
+ if (is_read)
+ fn = __vgic_v3_read_apxr0;
+ else
+ fn = __vgic_v3_write_apxr0;
+ break;
+ case SYS_ICC_AP1Rn_EL1(1):
+ if (is_read)
+ fn = __vgic_v3_read_apxr1;
+ else
+ fn = __vgic_v3_write_apxr1;
+ break;
+ case SYS_ICC_AP1Rn_EL1(2):
+ if (is_read)
+ fn = __vgic_v3_read_apxr2;
+ else
+ fn = __vgic_v3_write_apxr2;
+ break;
+ case SYS_ICC_AP1Rn_EL1(3):
+ if (is_read)
+ fn = __vgic_v3_read_apxr3;
+ else
+ fn = __vgic_v3_write_apxr3;
+ break;
default:
return 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 10/27] KVM: arm64: vgic-v3: Add ICV_HPPIR1_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (8 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 09/27] KVM: arm64: vgic-v3: Add ICV_AP1Rn_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 15:28 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 11/27] KVM: arm64: vgic-v3: Enable trapping of Group-1 system registers Marc Zyngier
` (16 subsequent siblings)
26 siblings, 1 reply; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for reading the guest's view of the ICV_HPPIR1_EL1
register. This is a simple parsing of the available LRs, extracting the
highest available interrupt.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/include/asm/sysreg.h | 1 +
virt/kvm/arm/hyp/vgic-v3-sr.c | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index aad46b8eea5e..bd000686194a 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -185,6 +185,7 @@
#define SYS_ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5)
#define SYS_ICC_IAR1_EL1 sys_reg(3, 0, 12, 12, 0)
#define SYS_ICC_EOIR1_EL1 sys_reg(3, 0, 12, 12, 1)
+#define SYS_ICC_HPPIR1_EL1 sys_reg(3, 0, 12, 12, 2)
#define SYS_ICC_BPR1_EL1 sys_reg(3, 0, 12, 12, 3)
#define SYS_ICC_CTLR_EL1 sys_reg(3, 0, 12, 12, 4)
#define SYS_ICC_SRE_EL1 sys_reg(3, 0, 12, 12, 5)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 1c85a6df22d9..f031e8f088ae 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -790,6 +790,26 @@ static void __hyp_text __vgic_v3_write_apxr3(struct kvm_vcpu *vcpu,
__vgic_v3_write_apxrn(vcpu, rt, 3);
}
+static void __hyp_text __vgic_v3_read_hppir(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ u64 lr_val;
+ int lr, lr_grp, grp;
+
+ grp = __vgic_v3_get_group(vcpu);
+
+ lr = __vgic_v3_highest_priority_lr(vcpu, vmcr, &lr_val);
+ if (lr == -1)
+ goto spurious;
+
+ lr_grp = !!(lr_val & ICH_LR_GROUP);
+ if (lr_grp != grp)
+ lr_val = ICC_IAR1_EL1_SPURIOUS;
+
+spurious:
+ vcpu_set_reg(vcpu, rt, lr_val & ICH_LR_VIRTUAL_ID_MASK);
+}
+
int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
{
int rt;
@@ -854,6 +874,9 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
else
fn = __vgic_v3_write_apxr3;
break;
+ case SYS_ICC_HPPIR1_EL1:
+ fn = __vgic_v3_read_hppir;
+ break;
default:
return 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 11/27] KVM: arm64: vgic-v3: Enable trapping of Group-1 system registers
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (9 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 10/27] KVM: arm64: vgic-v3: Add ICV_HPPIR1_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 12/27] KVM: arm64: Enable GICv3 Group-1 sysreg trapping via command-line Marc Zyngier
` (15 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
In order to be able to trap Group-1 GICv3 system registers, we need to
set ICH_HCR_EL2.TALL1 before entering the guest. This is conditionally
done after having restored the guest's state, and cleared on exit.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Acked-by: Christoffer Dall <cdall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
include/linux/irqchip/arm-gic-v3.h | 1 +
virt/kvm/arm/hyp/vgic-v3-sr.c | 11 +++++++++++
virt/kvm/arm/vgic/vgic-v3.c | 4 ++++
3 files changed, 16 insertions(+)
diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
index e50ce5d416a3..03b5a28bb2d0 100644
--- a/include/linux/irqchip/arm-gic-v3.h
+++ b/include/linux/irqchip/arm-gic-v3.h
@@ -417,6 +417,7 @@
#define ICH_HCR_EN (1 << 0)
#define ICH_HCR_UIE (1 << 1)
+#define ICH_HCR_TALL1 (1 << 12)
#define ICH_HCR_EOIcount_SHIFT 27
#define ICH_HCR_EOIcount_MASK (0x1f << ICH_HCR_EOIcount_SHIFT)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index f031e8f088ae..a2a62f030341 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -258,6 +258,9 @@ void __hyp_text __vgic_v3_save_state(struct kvm_vcpu *vcpu)
cpu_if->vgic_ap1r[0] = __vgic_v3_read_ap1rn(0);
}
} else {
+ if (static_branch_unlikely(&vgic_v3_cpuif_trap))
+ write_gicreg(0, ICH_HCR_EL2);
+
cpu_if->vgic_elrsr = 0xffff;
cpu_if->vgic_ap0r[0] = 0;
cpu_if->vgic_ap0r[1] = 0;
@@ -330,6 +333,14 @@ void __hyp_text __vgic_v3_restore_state(struct kvm_vcpu *vcpu)
for (i = 0; i < used_lrs; i++)
__gic_v3_set_lr(cpu_if->vgic_lr[i], i);
+ } else {
+ /*
+ * If we need to trap system registers, we must write
+ * ICH_HCR_EL2 anyway, even if no interrupts are being
+ * injected,
+ */
+ if (static_branch_unlikely(&vgic_v3_cpuif_trap))
+ write_gicreg(cpu_if->vgic_hcr, ICH_HCR_EL2);
}
/*
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index 88d9bd9bf468..fbd678bc046d 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -21,6 +21,8 @@
#include "vgic.h"
+static bool group1_trap;
+
void vgic_v3_set_underflow(struct kvm_vcpu *vcpu)
{
struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3;
@@ -239,6 +241,8 @@ void vgic_v3_enable(struct kvm_vcpu *vcpu)
/* Get the show on the road... */
vgic_v3->vgic_hcr = ICH_HCR_EN;
+ if (group1_trap)
+ vgic_v3->vgic_hcr |= ICH_HCR_TALL1;
}
int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq)
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 12/27] KVM: arm64: Enable GICv3 Group-1 sysreg trapping via command-line
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (10 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 11/27] KVM: arm64: vgic-v3: Enable trapping of Group-1 system registers Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 15:29 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 13/27] KVM: arm64: vgic-v3: Add ICV_BPR0_EL1 handler Marc Zyngier
` (14 subsequent siblings)
26 siblings, 1 reply; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Now that we're able to safely handle Group-1 sysreg access, let's
give the user the opportunity to enable it by passing a specific
command-line option (vgic_v3.group1_trap).
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
Documentation/admin-guide/kernel-parameters.txt | 4 ++++
virt/kvm/arm/vgic/vgic-v3.c | 11 +++++++++++
2 files changed, 15 insertions(+)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 15f79c27748d..42fe395be6c8 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1829,6 +1829,10 @@
for all guests.
Default is 1 (enabled) if in 64-bit or 32-bit PAE mode.
+ kvm-arm.vgic_v3_group1_trap=
+ [KVM,ARM] Trap guest accesses to GICv3 group-1
+ system registers
+
kvm-intel.ept= [KVM,Intel] Disable extended page tables
(virtualized MMU) support on capable Intel chips.
Default is 1 (enabled)
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index fbd678bc046d..df55818f095c 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -416,6 +416,12 @@ int vgic_v3_map_resources(struct kvm *kvm)
DEFINE_STATIC_KEY_FALSE(vgic_v3_cpuif_trap);
+static int __init early_group1_trap_cfg(char *buf)
+{
+ return strtobool(buf, &group1_trap);
+}
+early_param("kvm-arm.vgic_v3_group1_trap", early_group1_trap_cfg);
+
/**
* vgic_v3_probe - probe for a GICv3 compatible interrupt controller in DT
* @node: pointer to the DT node
@@ -467,6 +473,11 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
if (kvm_vgic_global_state.vcpu_base == 0)
kvm_info("disabling GICv2 emulation\n");
+ if (group1_trap) {
+ kvm_info("GICv3 sysreg trapping enabled (reduced performance)\n");
+ static_branch_enable(&vgic_v3_cpuif_trap);
+ }
+
kvm_vgic_global_state.vctrl_base = NULL;
kvm_vgic_global_state.type = VGIC_V3;
kvm_vgic_global_state.max_gic_vcpus = VGIC_V3_MAX_CPUS;
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 13/27] KVM: arm64: vgic-v3: Add ICV_BPR0_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (11 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 12/27] KVM: arm64: Enable GICv3 Group-1 sysreg trapping via command-line Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 15:29 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 14/27] KVM: arm64: vgic-v3: Add ICV_IGNREN0_EL1 handler Marc Zyngier
` (13 subsequent siblings)
26 siblings, 1 reply; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for reading/writing the guest's view of the ICC_BPR0_EL1
register, which is located in the ICH_VMCR_EL2.BPR0 field.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/include/asm/sysreg.h | 1 +
virt/kvm/arm/hyp/vgic-v3-sr.c | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index bd000686194a..d20be0b28ca4 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -180,6 +180,7 @@
#define SYS_VBAR_EL1 sys_reg(3, 0, 12, 0, 0)
+#define SYS_ICC_BPR0_EL1 sys_reg(3, 0, 12, 8, 3)
#define SYS_ICC_AP1Rn_EL1(n) sys_reg(3, 0, 12, 9, n)
#define SYS_ICC_DIR_EL1 sys_reg(3, 0, 12, 11, 1)
#define SYS_ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index a2a62f030341..f53908cc981c 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -706,11 +706,33 @@ static void __hyp_text __vgic_v3_write_igrpen1(struct kvm_vcpu *vcpu, u32 vmcr,
__vgic_v3_write_vmcr(vmcr);
}
+static void __hyp_text __vgic_v3_read_bpr0(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
+{
+ vcpu_set_reg(vcpu, rt, __vgic_v3_get_bpr0(vmcr));
+}
+
static void __hyp_text __vgic_v3_read_bpr1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
{
vcpu_set_reg(vcpu, rt, __vgic_v3_get_bpr1(vmcr));
}
+static void __hyp_text __vgic_v3_write_bpr0(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
+{
+ u64 val = vcpu_get_reg(vcpu, rt);
+ u8 bpr_min = __vgic_v3_bpr_min() - 1;
+
+ /* Enforce BPR limiting */
+ if (val < bpr_min)
+ val = bpr_min;
+
+ val <<= ICH_VMCR_BPR0_SHIFT;
+ val &= ICH_VMCR_BPR0_MASK;
+ vmcr &= ~ICH_VMCR_BPR0_MASK;
+ vmcr |= val;
+
+ __vgic_v3_write_vmcr(vmcr);
+}
+
static void __hyp_text __vgic_v3_write_bpr1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
{
u64 val = vcpu_get_reg(vcpu, rt);
@@ -888,6 +910,12 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
case SYS_ICC_HPPIR1_EL1:
fn = __vgic_v3_read_hppir;
break;
+ case SYS_ICC_BPR0_EL1:
+ if (is_read)
+ fn = __vgic_v3_read_bpr0;
+ else
+ fn = __vgic_v3_write_bpr0;
+ break;
default:
return 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 14/27] KVM: arm64: vgic-v3: Add ICV_IGNREN0_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (12 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 13/27] KVM: arm64: vgic-v3: Add ICV_BPR0_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 15/27] KVM: arm64: vgic-v3: Add misc Group-0 handlers Marc Zyngier
` (12 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for reading/writing the guest's view of the ICC_IGRPEN0_EL1
register, which is located in the ICH_VMCR_EL2.VENG0 field.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/include/asm/sysreg.h | 1 +
virt/kvm/arm/hyp/vgic-v3-sr.c | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index d20be0b28ca4..ba93bc7ac8e4 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -190,6 +190,7 @@
#define SYS_ICC_BPR1_EL1 sys_reg(3, 0, 12, 12, 3)
#define SYS_ICC_CTLR_EL1 sys_reg(3, 0, 12, 12, 4)
#define SYS_ICC_SRE_EL1 sys_reg(3, 0, 12, 12, 5)
+#define SYS_ICC_GRPEN0_EL1 sys_reg(3, 0, 12, 12, 6)
#define SYS_ICC_GRPEN1_EL1 sys_reg(3, 0, 12, 12, 7)
#define SYS_CONTEXTIDR_EL1 sys_reg(3, 0, 13, 0, 1)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index f53908cc981c..45927762bf14 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -689,11 +689,28 @@ static void __hyp_text __vgic_v3_write_eoir(struct kvm_vcpu *vcpu, u32 vmcr, int
__vgic_v3_clear_active_lr(lr, lr_val);
}
+static void __hyp_text __vgic_v3_read_igrpen0(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
+{
+ vcpu_set_reg(vcpu, rt, !!(vmcr & ICH_VMCR_ENG0_MASK));
+}
+
static void __hyp_text __vgic_v3_read_igrpen1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
{
vcpu_set_reg(vcpu, rt, !!(vmcr & ICH_VMCR_ENG1_MASK));
}
+static void __hyp_text __vgic_v3_write_igrpen0(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
+{
+ u64 val = vcpu_get_reg(vcpu, rt);
+
+ if (val & 1)
+ vmcr |= ICH_VMCR_ENG0_MASK;
+ else
+ vmcr &= ~ICH_VMCR_ENG0_MASK;
+
+ __vgic_v3_write_vmcr(vmcr);
+}
+
static void __hyp_text __vgic_v3_write_igrpen1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
{
u64 val = vcpu_get_reg(vcpu, rt);
@@ -910,6 +927,12 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
case SYS_ICC_HPPIR1_EL1:
fn = __vgic_v3_read_hppir;
break;
+ case SYS_ICC_GRPEN0_EL1:
+ if (is_read)
+ fn = __vgic_v3_read_igrpen0;
+ else
+ fn = __vgic_v3_write_igrpen0;
+ break;
case SYS_ICC_BPR0_EL1:
if (is_read)
fn = __vgic_v3_read_bpr0;
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 15/27] KVM: arm64: vgic-v3: Add misc Group-0 handlers
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (13 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 14/27] KVM: arm64: vgic-v3: Add ICV_IGNREN0_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 16/27] KVM: arm64: vgic-v3: Enable trapping of Group-0 system registers Marc Zyngier
` (11 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
A number of Group-0 registers can be handled by the same accessors
as that of Group-1, so let's add the required system register encodings
and catch them in the dispatching function.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Acked-by: Christoffer Dall <cdall@linaro.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/include/asm/sysreg.h | 4 ++++
virt/kvm/arm/hyp/vgic-v3-sr.c | 7 +++++++
2 files changed, 11 insertions(+)
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index ba93bc7ac8e4..9971c5c435a7 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -180,7 +180,11 @@
#define SYS_VBAR_EL1 sys_reg(3, 0, 12, 0, 0)
+#define SYS_ICC_IAR0_EL1 sys_reg(3, 0, 12, 8, 0)
+#define SYS_ICC_EOIR0_EL1 sys_reg(3, 0, 12, 8, 1)
+#define SYS_ICC_HPPIR0_EL1 sys_reg(3, 0, 12, 8, 2)
#define SYS_ICC_BPR0_EL1 sys_reg(3, 0, 12, 8, 3)
+#define SYS_ICC_AP0Rn_EL1(n) sys_reg(3, 0, 12, 8, 4 | n)
#define SYS_ICC_AP1Rn_EL1(n) sys_reg(3, 0, 12, 9, n)
#define SYS_ICC_DIR_EL1 sys_reg(3, 0, 12, 11, 1)
#define SYS_ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 45927762bf14..08a5d76c82c7 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -882,9 +882,11 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
is_read = (esr & ESR_ELx_SYS64_ISS_DIR_MASK) == ESR_ELx_SYS64_ISS_DIR_READ;
switch (sysreg) {
+ case SYS_ICC_IAR0_EL1:
case SYS_ICC_IAR1_EL1:
fn = __vgic_v3_read_iar;
break;
+ case SYS_ICC_EOIR0_EL1:
case SYS_ICC_EOIR1_EL1:
fn = __vgic_v3_write_eoir;
break;
@@ -900,30 +902,35 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
else
fn = __vgic_v3_write_bpr1;
break;
+ case SYS_ICC_AP0Rn_EL1(0):
case SYS_ICC_AP1Rn_EL1(0):
if (is_read)
fn = __vgic_v3_read_apxr0;
else
fn = __vgic_v3_write_apxr0;
break;
+ case SYS_ICC_AP0Rn_EL1(1):
case SYS_ICC_AP1Rn_EL1(1):
if (is_read)
fn = __vgic_v3_read_apxr1;
else
fn = __vgic_v3_write_apxr1;
break;
+ case SYS_ICC_AP0Rn_EL1(2):
case SYS_ICC_AP1Rn_EL1(2):
if (is_read)
fn = __vgic_v3_read_apxr2;
else
fn = __vgic_v3_write_apxr2;
break;
+ case SYS_ICC_AP0Rn_EL1(3):
case SYS_ICC_AP1Rn_EL1(3):
if (is_read)
fn = __vgic_v3_read_apxr3;
else
fn = __vgic_v3_write_apxr3;
break;
+ case SYS_ICC_HPPIR0_EL1:
case SYS_ICC_HPPIR1_EL1:
fn = __vgic_v3_read_hppir;
break;
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 16/27] KVM: arm64: vgic-v3: Enable trapping of Group-0 system registers
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (14 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 15/27] KVM: arm64: vgic-v3: Add misc Group-0 handlers Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 17/27] KVM: arm64: Enable GICv3 Group-0 sysreg trapping via command-line Marc Zyngier
` (10 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
In order to be able to trap Group-0 GICv3 system registers, we need to
set ICH_HCR_EL2.TALL0 begore entering the guest. This is conditionnaly
done after having restored the guest's state, and cleared on exit.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Acked-by: Christoffer Dall <cdall@linaro.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
include/linux/irqchip/arm-gic-v3.h | 1 +
virt/kvm/arm/vgic/vgic-v3.c | 5 ++++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
index 03b5a28bb2d0..46a1e0943cf8 100644
--- a/include/linux/irqchip/arm-gic-v3.h
+++ b/include/linux/irqchip/arm-gic-v3.h
@@ -417,6 +417,7 @@
#define ICH_HCR_EN (1 << 0)
#define ICH_HCR_UIE (1 << 1)
+#define ICH_HCR_TALL0 (1 << 11)
#define ICH_HCR_TALL1 (1 << 12)
#define ICH_HCR_EOIcount_SHIFT 27
#define ICH_HCR_EOIcount_MASK (0x1f << ICH_HCR_EOIcount_SHIFT)
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index df55818f095c..06773b985b4e 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -21,6 +21,7 @@
#include "vgic.h"
+static bool group0_trap;
static bool group1_trap;
void vgic_v3_set_underflow(struct kvm_vcpu *vcpu)
@@ -241,6 +242,8 @@ void vgic_v3_enable(struct kvm_vcpu *vcpu)
/* Get the show on the road... */
vgic_v3->vgic_hcr = ICH_HCR_EN;
+ if (group0_trap)
+ vgic_v3->vgic_hcr |= ICH_HCR_TALL0;
if (group1_trap)
vgic_v3->vgic_hcr |= ICH_HCR_TALL1;
}
@@ -473,7 +476,7 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
if (kvm_vgic_global_state.vcpu_base == 0)
kvm_info("disabling GICv2 emulation\n");
- if (group1_trap) {
+ if (group0_trap || group1_trap) {
kvm_info("GICv3 sysreg trapping enabled (reduced performance)\n");
static_branch_enable(&vgic_v3_cpuif_trap);
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 17/27] KVM: arm64: Enable GICv3 Group-0 sysreg trapping via command-line
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (15 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 16/27] KVM: arm64: vgic-v3: Enable trapping of Group-0 system registers Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 18/27] arm64: Add MIDR values for Cavium cn83XX SoCs Marc Zyngier
` (9 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Now that we're able to safely handle Group-0 sysreg access, let's
give the user the opportunity to enable it by passing a specific
command-line option (vgic_v3.group0_trap).
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
Documentation/admin-guide/kernel-parameters.txt | 4 ++++
virt/kvm/arm/vgic/vgic-v3.c | 6 ++++++
2 files changed, 10 insertions(+)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 42fe395be6c8..88bdc421351f 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1829,6 +1829,10 @@
for all guests.
Default is 1 (enabled) if in 64-bit or 32-bit PAE mode.
+ kvm-arm.vgic_v3_group0_trap=
+ [KVM,ARM] Trap guest accesses to GICv3 group-0
+ system registers
+
kvm-arm.vgic_v3_group1_trap=
[KVM,ARM] Trap guest accesses to GICv3 group-1
system registers
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index 06773b985b4e..e0e50ca547de 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -419,6 +419,12 @@ int vgic_v3_map_resources(struct kvm *kvm)
DEFINE_STATIC_KEY_FALSE(vgic_v3_cpuif_trap);
+static int __init early_group0_trap_cfg(char *buf)
+{
+ return strtobool(buf, &group0_trap);
+}
+early_param("kvm-arm.vgic_v3_group0_trap", early_group0_trap_cfg);
+
static int __init early_group1_trap_cfg(char *buf)
{
return strtobool(buf, &group1_trap);
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 18/27] arm64: Add MIDR values for Cavium cn83XX SoCs
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (16 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 17/27] KVM: arm64: Enable GICv3 Group-0 sysreg trapping via command-line Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 19/27] arm64: Add workaround for Cavium Thunder erratum 30115 Marc Zyngier
` (8 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
From: David Daney <david.daney@cavium.com>
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: David Daney <david.daney@cavium.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/include/asm/cputype.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h
index 0984d1b3a8f2..235e77d98261 100644
--- a/arch/arm64/include/asm/cputype.h
+++ b/arch/arm64/include/asm/cputype.h
@@ -86,6 +86,7 @@
#define CAVIUM_CPU_PART_THUNDERX 0x0A1
#define CAVIUM_CPU_PART_THUNDERX_81XX 0x0A2
+#define CAVIUM_CPU_PART_THUNDERX_83XX 0x0A3
#define BRCM_CPU_PART_VULCAN 0x516
@@ -96,6 +97,7 @@
#define MIDR_CORTEX_A73 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73)
#define MIDR_THUNDERX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX)
#define MIDR_THUNDERX_81XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_81XX)
+#define MIDR_THUNDERX_83XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_83XX)
#define MIDR_QCOM_FALKOR_V1 MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR_V1)
#ifndef __ASSEMBLY__
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 19/27] arm64: Add workaround for Cavium Thunder erratum 30115
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (17 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 18/27] arm64: Add MIDR values for Cavium cn83XX SoCs Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 20/27] KVM: arm64: vgic-v3: Add ICV_DIR_EL1 handler Marc Zyngier
` (7 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
From: David Daney <david.daney@cavium.com>
Some Cavium Thunder CPUs suffer a problem where a KVM guest may
inadvertently cause the host kernel to quit receiving interrupts.
Use the Group-0/1 trapping in order to deal with it.
[maz]: Adapted patch to the Group-0/1 trapping, reworked commit log
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: David Daney <david.daney@cavium.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
Documentation/arm64/silicon-errata.txt | 1 +
arch/arm64/Kconfig | 11 +++++++++++
arch/arm64/include/asm/cpucaps.h | 3 ++-
arch/arm64/kernel/cpu_errata.c | 21 +++++++++++++++++++++
virt/kvm/arm/vgic/vgic-v3.c | 7 +++++++
5 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/Documentation/arm64/silicon-errata.txt b/Documentation/arm64/silicon-errata.txt
index 10f2dddbf449..f5f93dca54b7 100644
--- a/Documentation/arm64/silicon-errata.txt
+++ b/Documentation/arm64/silicon-errata.txt
@@ -62,6 +62,7 @@ stable kernels.
| Cavium | ThunderX GICv3 | #23154 | CAVIUM_ERRATUM_23154 |
| Cavium | ThunderX Core | #27456 | CAVIUM_ERRATUM_27456 |
| Cavium | ThunderX SMMUv2 | #27704 | N/A |
+| Cavium | ThunderX Core | #30115 | CAVIUM_ERRATUM_30115 |
| | | | |
| Freescale/NXP | LS2080A/LS1043A | A-008585 | FSL_ERRATUM_A008585 |
| | | | |
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 3dcd7ec69bca..6252365b0c96 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -480,6 +480,17 @@ config CAVIUM_ERRATUM_27456
If unsure, say Y.
+config CAVIUM_ERRATUM_30115
+ bool "Cavium erratum 30115: Guest may disable interrupts in host"
+ default y
+ help
+ On ThunderX T88 pass 1.x through 2.2, T81 pass 1.0 through
+ 1.2, and T83 Pass 1.0, KVM guest execution may disable
+ interrupts in host. Trapping both GICv3 group-0 and group-1
+ accesses sidesteps the issue.
+
+ If unsure, say Y.
+
config QCOM_FALKOR_ERRATUM_1003
bool "Falkor E1003: Incorrect translation due to ASID change"
default y
diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h
index b3aab8a17868..8d2272c6822c 100644
--- a/arch/arm64/include/asm/cpucaps.h
+++ b/arch/arm64/include/asm/cpucaps.h
@@ -38,7 +38,8 @@
#define ARM64_WORKAROUND_REPEAT_TLBI 17
#define ARM64_WORKAROUND_QCOM_FALKOR_E1003 18
#define ARM64_WORKAROUND_858921 19
+#define ARM64_WORKAROUND_CAVIUM_30115 20
-#define ARM64_NCAPS 20
+#define ARM64_NCAPS 21
#endif /* __ASM_CPUCAPS_H */
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
index 2ed2a7657711..0e27f86ee709 100644
--- a/arch/arm64/kernel/cpu_errata.c
+++ b/arch/arm64/kernel/cpu_errata.c
@@ -133,6 +133,27 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
MIDR_RANGE(MIDR_THUNDERX_81XX, 0x00, 0x00),
},
#endif
+#ifdef CONFIG_CAVIUM_ERRATUM_30115
+ {
+ /* Cavium ThunderX, T88 pass 1.x - 2.2 */
+ .desc = "Cavium erratum 30115",
+ .capability = ARM64_WORKAROUND_CAVIUM_30115,
+ MIDR_RANGE(MIDR_THUNDERX, 0x00,
+ (1 << MIDR_VARIANT_SHIFT) | 2),
+ },
+ {
+ /* Cavium ThunderX, T81 pass 1.0 - 1.2 */
+ .desc = "Cavium erratum 30115",
+ .capability = ARM64_WORKAROUND_CAVIUM_30115,
+ MIDR_RANGE(MIDR_THUNDERX_81XX, 0x00, 0x02),
+ },
+ {
+ /* Cavium ThunderX, T83 pass 1.0 */
+ .desc = "Cavium erratum 30115",
+ .capability = ARM64_WORKAROUND_CAVIUM_30115,
+ MIDR_RANGE(MIDR_THUNDERX_83XX, 0x00, 0x00),
+ },
+#endif
{
.desc = "Mismatched cache line size",
.capability = ARM64_MISMATCHED_CACHE_LINE_SIZE,
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index e0e50ca547de..ffc581b70c4e 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -482,6 +482,13 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
if (kvm_vgic_global_state.vcpu_base == 0)
kvm_info("disabling GICv2 emulation\n");
+#ifdef CONFIG_ARM64
+ if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_30115)) {
+ group0_trap = true;
+ group1_trap = true;
+ }
+#endif
+
if (group0_trap || group1_trap) {
kvm_info("GICv3 sysreg trapping enabled (reduced performance)\n");
static_branch_enable(&vgic_v3_cpuif_trap);
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 20/27] KVM: arm64: vgic-v3: Add ICV_DIR_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (18 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 19/27] arm64: Add workaround for Cavium Thunder erratum 30115 Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 21/27] KVM: arm64: vgic-v3: Add ICV_RPR_EL1 handler Marc Zyngier
` (6 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for writing the guest's view of the ICC_DIR_EL1
register, performing the deactivation of an interrupt if EOImode
is set ot 1.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
virt/kvm/arm/hyp/vgic-v3-sr.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 08a5d76c82c7..2f2af03e8932 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -652,6 +652,30 @@ static void __hyp_text __vgic_v3_bump_eoicount(void)
write_gicreg(hcr, ICH_HCR_EL2);
}
+static void __hyp_text __vgic_v3_write_dir(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ u32 vid = vcpu_get_reg(vcpu, rt);
+ u64 lr_val;
+ int lr;
+
+ /* EOImode == 0, nothing to be done here */
+ if (!(vmcr & ICH_VMCR_EOIM_MASK))
+ return;
+
+ /* No deactivate to be performed on an LPI */
+ if (vid >= VGIC_MIN_LPI)
+ return;
+
+ lr = __vgic_v3_find_active_lr(vcpu, vid, &lr_val);
+ if (lr == -1) {
+ __vgic_v3_bump_eoicount();
+ return;
+ }
+
+ __vgic_v3_clear_active_lr(lr, lr_val);
+}
+
static void __hyp_text __vgic_v3_write_eoir(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
{
u32 vid = vcpu_get_reg(vcpu, rt);
@@ -946,6 +970,9 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
else
fn = __vgic_v3_write_bpr0;
break;
+ case SYS_ICC_DIR_EL1:
+ fn = __vgic_v3_write_dir;
+ break;
default:
return 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 21/27] KVM: arm64: vgic-v3: Add ICV_RPR_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (19 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 20/27] KVM: arm64: vgic-v3: Add ICV_DIR_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 22/27] KVM: arm64: vgic-v3: Add ICV_CTLR_EL1 handler Marc Zyngier
` (5 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for reading the guest's view of the ICV_RPR_EL1
register, returning the highest active priority.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Acked-by: Christoffer Dall <cdall@linaro.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/include/asm/sysreg.h | 1 +
virt/kvm/arm/hyp/vgic-v3-sr.c | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 9971c5c435a7..c4d48e403629 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -187,6 +187,7 @@
#define SYS_ICC_AP0Rn_EL1(n) sys_reg(3, 0, 12, 8, 4 | n)
#define SYS_ICC_AP1Rn_EL1(n) sys_reg(3, 0, 12, 9, n)
#define SYS_ICC_DIR_EL1 sys_reg(3, 0, 12, 11, 1)
+#define SYS_ICC_RPR_EL1 sys_reg(3, 0, 12, 11, 3)
#define SYS_ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5)
#define SYS_ICC_IAR1_EL1 sys_reg(3, 0, 12, 12, 0)
#define SYS_ICC_EOIR1_EL1 sys_reg(3, 0, 12, 12, 1)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 2f2af03e8932..406da9c667ff 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -884,6 +884,13 @@ static void __hyp_text __vgic_v3_read_hppir(struct kvm_vcpu *vcpu,
vcpu_set_reg(vcpu, rt, lr_val & ICH_LR_VIRTUAL_ID_MASK);
}
+static void __hyp_text __vgic_v3_read_rpr(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ u32 val = __vgic_v3_get_highest_active_priority();
+ vcpu_set_reg(vcpu, rt, val);
+}
+
int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
{
int rt;
@@ -973,6 +980,9 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
case SYS_ICC_DIR_EL1:
fn = __vgic_v3_write_dir;
break;
+ case SYS_ICC_RPR_EL1:
+ fn = __vgic_v3_read_rpr;
+ break;
default:
return 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 22/27] KVM: arm64: vgic-v3: Add ICV_CTLR_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (20 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 21/27] KVM: arm64: vgic-v3: Add ICV_RPR_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 23/27] KVM: arm64: vgic-v3: Add ICV_PMR_EL1 handler Marc Zyngier
` (4 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for reading/writing the guest's view of the ICV_CTLR_EL1
register. only EOIMode and CBPR are of interest here, as all the other
bits directly come from ICH_VTR_EL2 and are Read-Only.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Acked-by: Christoffer Dall <cdall@linaro.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
virt/kvm/arm/hyp/vgic-v3-sr.c | 46 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 406da9c667ff..a8a58dedc38e 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -891,6 +891,46 @@ static void __hyp_text __vgic_v3_read_rpr(struct kvm_vcpu *vcpu,
vcpu_set_reg(vcpu, rt, val);
}
+static void __hyp_text __vgic_v3_read_ctlr(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ u32 vtr, val;
+
+ vtr = read_gicreg(ICH_VTR_EL2);
+ /* PRIbits */
+ val = ((vtr >> 29) & 7) << ICC_CTLR_EL1_PRI_BITS_SHIFT;
+ /* IDbits */
+ val |= ((vtr >> 23) & 7) << ICC_CTLR_EL1_ID_BITS_SHIFT;
+ /* SEIS */
+ val |= ((vtr >> 22) & 1) << ICC_CTLR_EL1_SEIS_SHIFT;
+ /* A3V */
+ val |= ((vtr >> 21) & 1) << ICC_CTLR_EL1_A3V_SHIFT;
+ /* EOImode */
+ val |= ((vmcr & ICH_VMCR_EOIM_MASK) >> ICH_VMCR_EOIM_SHIFT) << ICC_CTLR_EL1_EOImode_SHIFT;
+ /* CBPR */
+ val |= (vmcr & ICH_VMCR_CBPR_MASK) >> ICH_VMCR_CBPR_SHIFT;
+
+ vcpu_set_reg(vcpu, rt, val);
+}
+
+static void __hyp_text __vgic_v3_write_ctlr(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ u32 val = vcpu_get_reg(vcpu, rt);
+
+ if (val & ICC_CTLR_EL1_CBPR_MASK)
+ vmcr |= ICH_VMCR_CBPR_MASK;
+ else
+ vmcr &= ~ICH_VMCR_CBPR_MASK;
+
+ if (val & ICC_CTLR_EL1_EOImode_MASK)
+ vmcr |= ICH_VMCR_EOIM_MASK;
+ else
+ vmcr &= ~ICH_VMCR_EOIM_MASK;
+
+ write_gicreg(vmcr, ICH_VMCR_EL2);
+}
+
int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
{
int rt;
@@ -983,6 +1023,12 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
case SYS_ICC_RPR_EL1:
fn = __vgic_v3_read_rpr;
break;
+ case SYS_ICC_CTLR_EL1:
+ if (is_read)
+ fn = __vgic_v3_read_ctlr;
+ else
+ fn = __vgic_v3_write_ctlr;
+ break;
default:
return 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 23/27] KVM: arm64: vgic-v3: Add ICV_PMR_EL1 handler
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (21 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 22/27] KVM: arm64: vgic-v3: Add ICV_CTLR_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 24/27] KVM: arm64: Enable GICv3 common sysreg trapping via command-line Marc Zyngier
` (3 subsequent siblings)
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Add a handler for reading/writing the guest's view of the ICC_PMR_EL1
register, which is located in the ICH_VMCR_EL2.VPMR field.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Acked-by: Christoffer Dall <cdall@linaro.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
virt/kvm/arm/hyp/vgic-v3-sr.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index a8a58dedc38e..15b557697086 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -884,6 +884,27 @@ static void __hyp_text __vgic_v3_read_hppir(struct kvm_vcpu *vcpu,
vcpu_set_reg(vcpu, rt, lr_val & ICH_LR_VIRTUAL_ID_MASK);
}
+static void __hyp_text __vgic_v3_read_pmr(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ vmcr &= ICH_VMCR_PMR_MASK;
+ vmcr >>= ICH_VMCR_PMR_SHIFT;
+ vcpu_set_reg(vcpu, rt, vmcr);
+}
+
+static void __hyp_text __vgic_v3_write_pmr(struct kvm_vcpu *vcpu,
+ u32 vmcr, int rt)
+{
+ u32 val = vcpu_get_reg(vcpu, rt);
+
+ val <<= ICH_VMCR_PMR_SHIFT;
+ val &= ICH_VMCR_PMR_MASK;
+ vmcr &= ~ICH_VMCR_PMR_MASK;
+ vmcr |= val;
+
+ write_gicreg(vmcr, ICH_VMCR_EL2);
+}
+
static void __hyp_text __vgic_v3_read_rpr(struct kvm_vcpu *vcpu,
u32 vmcr, int rt)
{
@@ -1029,6 +1050,12 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
else
fn = __vgic_v3_write_ctlr;
break;
+ case SYS_ICC_PMR_EL1:
+ if (is_read)
+ fn = __vgic_v3_read_pmr;
+ else
+ fn = __vgic_v3_write_pmr;
+ break;
default:
return 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 24/27] KVM: arm64: Enable GICv3 common sysreg trapping via command-line
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (22 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 23/27] KVM: arm64: vgic-v3: Add ICV_PMR_EL1 handler Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 15:31 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 25/27] KVM: arm64: vgic-v3: Log which GICv3 system registers are trapped Marc Zyngier
` (2 subsequent siblings)
26 siblings, 1 reply; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
Now that we're able to safely handle common sysreg access, let's
give the user the opportunity to enable it by passing a specific
command-line option (vgic_v3.common_trap).
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
Documentation/admin-guide/kernel-parameters.txt | 4 ++++
include/linux/irqchip/arm-gic-v3.h | 1 +
virt/kvm/arm/vgic/vgic-v3.c | 11 ++++++++++-
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 88bdc421351f..aa8341e73b35 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1837,6 +1837,10 @@
[KVM,ARM] Trap guest accesses to GICv3 group-1
system registers
+ kvm-arm.vgic_v3_common_trap=
+ [KVM,ARM] Trap guest accesses to GICv3 common
+ system registers
+
kvm-intel.ept= [KVM,Intel] Disable extended page tables
(virtualized MMU) support on capable Intel chips.
Default is 1 (enabled)
diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
index 46a1e0943cf8..f0cebb6e57d0 100644
--- a/include/linux/irqchip/arm-gic-v3.h
+++ b/include/linux/irqchip/arm-gic-v3.h
@@ -417,6 +417,7 @@
#define ICH_HCR_EN (1 << 0)
#define ICH_HCR_UIE (1 << 1)
+#define ICH_HCR_TC (1 << 10)
#define ICH_HCR_TALL0 (1 << 11)
#define ICH_HCR_TALL1 (1 << 12)
#define ICH_HCR_EOIcount_SHIFT 27
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index ffc581b70c4e..3960e89c05ad 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -23,6 +23,7 @@
static bool group0_trap;
static bool group1_trap;
+static bool common_trap;
void vgic_v3_set_underflow(struct kvm_vcpu *vcpu)
{
@@ -246,6 +247,8 @@ void vgic_v3_enable(struct kvm_vcpu *vcpu)
vgic_v3->vgic_hcr |= ICH_HCR_TALL0;
if (group1_trap)
vgic_v3->vgic_hcr |= ICH_HCR_TALL1;
+ if (common_trap)
+ vgic_v3->vgic_hcr |= ICH_HCR_TC;
}
int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq)
@@ -431,6 +434,12 @@ static int __init early_group1_trap_cfg(char *buf)
}
early_param("kvm-arm.vgic_v3_group1_trap", early_group1_trap_cfg);
+static int __init early_common_trap_cfg(char *buf)
+{
+ return strtobool(buf, &common_trap);
+}
+early_param("kvm-arm.vgic_v3_common_trap", early_common_trap_cfg);
+
/**
* vgic_v3_probe - probe for a GICv3 compatible interrupt controller in DT
* @node: pointer to the DT node
@@ -489,7 +498,7 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
}
#endif
- if (group0_trap || group1_trap) {
+ if (group0_trap || group1_trap || common_trap) {
kvm_info("GICv3 sysreg trapping enabled (reduced performance)\n");
static_branch_enable(&vgic_v3_cpuif_trap);
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 25/27] KVM: arm64: vgic-v3: Log which GICv3 system registers are trapped
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (23 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 24/27] KVM: arm64: Enable GICv3 common sysreg trapping via command-line Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 26/27] KVM: arm64: Log an error if trapping a read-from-write-only GICv3 access Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 27/27] KVM: arm64: Log an error if trapping a write-to-read-only " Marc Zyngier
26 siblings, 0 replies; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
In order to facilitate debug, let's log which class of GICv3 system
registers are trapped.
Tested-by: Alexander Graf <agraf@suse.de>
Acked-by: David Daney <david.daney@cavium.com>
Acked-by: Christoffer Dall <cdall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
virt/kvm/arm/vgic/vgic-v3.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index 3960e89c05ad..f934a5bb144f 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -499,7 +499,10 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
#endif
if (group0_trap || group1_trap || common_trap) {
- kvm_info("GICv3 sysreg trapping enabled (reduced performance)\n");
+ kvm_info("GICv3 sysreg trapping enabled ([%s%s%s], reduced performance)\n",
+ group0_trap ? "G0" : "",
+ group1_trap ? "G1" : "",
+ common_trap ? "C" : "");
static_branch_enable(&vgic_v3_cpuif_trap);
}
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 26/27] KVM: arm64: Log an error if trapping a read-from-write-only GICv3 access
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (24 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 25/27] KVM: arm64: vgic-v3: Log which GICv3 system registers are trapped Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 15:33 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 27/27] KVM: arm64: Log an error if trapping a write-to-read-only " Marc Zyngier
26 siblings, 1 reply; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
A read-from-write-only GICv3 access should UNDEF at EL1. But since
we're in complete paranoia-land with broken CPUs, let's assume the
worse and gracefully handle the case.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/kvm/sys_regs.c | 12 ++++++++----
virt/kvm/arm/hyp/vgic-v3-sr.c | 4 ++++
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 0fe27024a2e1..8d51c075966d 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -56,7 +56,8 @@
*/
static bool read_from_write_only(struct kvm_vcpu *vcpu,
- const struct sys_reg_params *params)
+ struct sys_reg_params *params,
+ const struct sys_reg_desc *r)
{
WARN_ONCE(1, "Unexpected sys_reg read to write-only register\n");
print_sys_reg_instr(params);
@@ -93,7 +94,7 @@ static bool access_dcsw(struct kvm_vcpu *vcpu,
const struct sys_reg_desc *r)
{
if (!p->is_write)
- return read_from_write_only(vcpu, p);
+ return read_from_write_only(vcpu, p, r);
kvm_set_way_flush(vcpu);
return true;
@@ -135,7 +136,7 @@ static bool access_gic_sgi(struct kvm_vcpu *vcpu,
const struct sys_reg_desc *r)
{
if (!p->is_write)
- return read_from_write_only(vcpu, p);
+ return read_from_write_only(vcpu, p, r);
vgic_v3_dispatch_sgi(vcpu, p->regval);
@@ -773,7 +774,7 @@ static bool access_pmswinc(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
return trap_raz_wi(vcpu, p, r);
if (!p->is_write)
- return read_from_write_only(vcpu, p);
+ return read_from_write_only(vcpu, p, r);
if (pmu_write_swinc_el0_disabled(vcpu))
return false;
@@ -953,7 +954,10 @@ static const struct sys_reg_desc sys_reg_descs[] = {
{ SYS_DESC(SYS_VBAR_EL1), NULL, reset_val, VBAR_EL1, 0 },
+ { SYS_DESC(SYS_ICC_EOIR0_EL1), read_from_write_only },
+ { SYS_DESC(SYS_ICC_DIR_EL1), read_from_write_only },
{ SYS_DESC(SYS_ICC_SGI1R_EL1), access_gic_sgi },
+ { SYS_DESC(SYS_ICC_EOIR1_EL1), read_from_write_only },
{ SYS_DESC(SYS_ICC_SRE_EL1), access_gic_sre },
{ SYS_DESC(SYS_CONTEXTIDR_EL1), access_vm_reg, reset_val, CONTEXTIDR_EL1, 0 },
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 15b557697086..b26ce58b012a 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -980,6 +980,8 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
break;
case SYS_ICC_EOIR0_EL1:
case SYS_ICC_EOIR1_EL1:
+ if (unlikely(is_read))
+ return 0;
fn = __vgic_v3_write_eoir;
break;
case SYS_ICC_GRPEN1_EL1:
@@ -1039,6 +1041,8 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
fn = __vgic_v3_write_bpr0;
break;
case SYS_ICC_DIR_EL1:
+ if (unlikely(is_read))
+ return 0;
fn = __vgic_v3_write_dir;
break;
case SYS_ICC_RPR_EL1:
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 27/27] KVM: arm64: Log an error if trapping a write-to-read-only GICv3 access
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
` (25 preceding siblings ...)
2017-06-09 11:49 ` [PATCH v3 26/27] KVM: arm64: Log an error if trapping a read-from-write-only GICv3 access Marc Zyngier
@ 2017-06-09 11:49 ` Marc Zyngier
2017-06-09 15:34 ` Christoffer Dall
26 siblings, 1 reply; 37+ messages in thread
From: Marc Zyngier @ 2017-06-09 11:49 UTC (permalink / raw)
To: linux-arm-kernel
A write-to-read-only GICv3 access should UNDEF at EL1. But since
we're in complete paranoia-land with broken CPUs, let's assume the
worse and gracefully handle the case.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/kvm/sys_regs.c | 15 +++++++++++++++
virt/kvm/arm/hyp/vgic-v3-sr.c | 6 ++++++
2 files changed, 21 insertions(+)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 8d51c075966d..77862881ae86 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -65,6 +65,16 @@ static bool read_from_write_only(struct kvm_vcpu *vcpu,
return false;
}
+static bool write_to_read_only(struct kvm_vcpu *vcpu,
+ struct sys_reg_params *params,
+ const struct sys_reg_desc *r)
+{
+ WARN_ONCE(1, "Unexpected sys_reg write to read-only register\n");
+ print_sys_reg_instr(params);
+ kvm_inject_undefined(vcpu);
+ return false;
+}
+
/* 3 bits per cache level, as per CLIDR, but non-existent caches always 0 */
static u32 cache_levels;
@@ -954,10 +964,15 @@ static const struct sys_reg_desc sys_reg_descs[] = {
{ SYS_DESC(SYS_VBAR_EL1), NULL, reset_val, VBAR_EL1, 0 },
+ { SYS_DESC(SYS_ICC_IAR0_EL1), write_to_read_only },
{ SYS_DESC(SYS_ICC_EOIR0_EL1), read_from_write_only },
+ { SYS_DESC(SYS_ICC_HPPIR0_EL1), write_to_read_only },
{ SYS_DESC(SYS_ICC_DIR_EL1), read_from_write_only },
+ { SYS_DESC(SYS_ICC_RPR_EL1), write_to_read_only },
{ SYS_DESC(SYS_ICC_SGI1R_EL1), access_gic_sgi },
+ { SYS_DESC(SYS_ICC_IAR1_EL1), write_to_read_only },
{ SYS_DESC(SYS_ICC_EOIR1_EL1), read_from_write_only },
+ { SYS_DESC(SYS_ICC_HPPIR1_EL1), write_to_read_only },
{ SYS_DESC(SYS_ICC_SRE_EL1), access_gic_sre },
{ SYS_DESC(SYS_CONTEXTIDR_EL1), access_vm_reg, reset_val, CONTEXTIDR_EL1, 0 },
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index b26ce58b012a..79e3c2d3b754 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -976,6 +976,8 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
switch (sysreg) {
case SYS_ICC_IAR0_EL1:
case SYS_ICC_IAR1_EL1:
+ if (unlikely(!is_read))
+ return 0;
fn = __vgic_v3_read_iar;
break;
case SYS_ICC_EOIR0_EL1:
@@ -1026,6 +1028,8 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
break;
case SYS_ICC_HPPIR0_EL1:
case SYS_ICC_HPPIR1_EL1:
+ if (unlikely(!is_read))
+ return 0;
fn = __vgic_v3_read_hppir;
break;
case SYS_ICC_GRPEN0_EL1:
@@ -1046,6 +1050,8 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
fn = __vgic_v3_write_dir;
break;
case SYS_ICC_RPR_EL1:
+ if (unlikely(!is_read))
+ return 0;
fn = __vgic_v3_read_rpr;
break;
case SYS_ICC_CTLR_EL1:
--
2.11.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH v3 05/27] KVM: arm64: vgic-v3: Add ICV_BPR1_EL1 handler
2017-06-09 11:49 ` [PATCH v3 05/27] KVM: arm64: vgic-v3: Add ICV_BPR1_EL1 handler Marc Zyngier
@ 2017-06-09 15:23 ` Christoffer Dall
0 siblings, 0 replies; 37+ messages in thread
From: Christoffer Dall @ 2017-06-09 15:23 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jun 09, 2017 at 12:49:34PM +0100, Marc Zyngier wrote:
> Add a handler for reading/writing the guest's view of the ICC_BPR1_EL1
> register, which is located in the ICH_VMCR_EL2.BPR1 field.
>
> Tested-by: Alexander Graf <agraf@suse.de>
> Acked-by: David Daney <david.daney@cavium.com>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
> ---
> virt/kvm/arm/hyp/vgic-v3-sr.c | 57 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 57 insertions(+)
>
> diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
> index e6c05b95a1b1..fe021abc8b51 100644
> --- a/virt/kvm/arm/hyp/vgic-v3-sr.c
> +++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
> @@ -375,6 +375,57 @@ void __hyp_text __vgic_v3_write_vmcr(u32 vmcr)
>
> #ifdef CONFIG_ARM64
>
> +static int __hyp_text __vgic_v3_bpr_min(void)
> +{
> + /* See Pseudocode for VPriorityGroup */
> + return 8 - vtr_to_nr_pre_bits(read_gicreg(ICH_VTR_EL2));
> +}
> +
> +static unsigned int __hyp_text __vgic_v3_get_bpr0(u32 vmcr)
> +{
> + return (vmcr & ICH_VMCR_BPR0_MASK) >> ICH_VMCR_BPR0_SHIFT;
> +}
> +
> +static unsigned int __hyp_text __vgic_v3_get_bpr1(u32 vmcr)
> +{
> + unsigned int bpr;
> +
> + if (vmcr & ICH_VMCR_CBPR_MASK) {
> + bpr = __vgic_v3_get_bpr0(vmcr);
> + if (bpr < 7)
> + bpr++;
> + } else {
> + bpr = (vmcr & ICH_VMCR_BPR1_MASK) >> ICH_VMCR_BPR1_SHIFT;
> + }
> +
> + return bpr;
> +}
> +
> +static void __hyp_text __vgic_v3_read_bpr1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> +{
> + vcpu_set_reg(vcpu, rt, __vgic_v3_get_bpr1(vmcr));
> +}
> +
> +static void __hyp_text __vgic_v3_write_bpr1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> +{
> + u64 val = vcpu_get_reg(vcpu, rt);
> + u8 bpr_min = __vgic_v3_bpr_min();
> +
> + if (vmcr & ICH_VMCR_CBPR_MASK)
> + return;
> +
> + /* Enforce BPR limiting */
> + if (val < bpr_min)
> + val = bpr_min;
> +
> + val <<= ICH_VMCR_BPR1_SHIFT;
> + val &= ICH_VMCR_BPR1_MASK;
> + vmcr &= ~ICH_VMCR_BPR1_MASK;
> + vmcr |= val;
> +
> + __vgic_v3_write_vmcr(vmcr);
> +}
> +
> int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> {
> int rt;
> @@ -397,6 +448,12 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> is_read = (esr & ESR_ELx_SYS64_ISS_DIR_MASK) == ESR_ELx_SYS64_ISS_DIR_READ;
>
> switch (sysreg) {
> + case SYS_ICC_BPR1_EL1:
> + if (is_read)
> + fn = __vgic_v3_read_bpr1;
> + else
> + fn = __vgic_v3_write_bpr1;
> + break;
> default:
> return 0;
> }
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 37+ messages in thread
* [PATCH v3 07/27] KVM: arm64: vgic-v3: Add ICV_IAR1_EL1 handler
2017-06-09 11:49 ` [PATCH v3 07/27] KVM: arm64: vgic-v3: Add ICV_IAR1_EL1 handler Marc Zyngier
@ 2017-06-09 15:26 ` Christoffer Dall
0 siblings, 0 replies; 37+ messages in thread
From: Christoffer Dall @ 2017-06-09 15:26 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jun 09, 2017 at 12:49:36PM +0100, Marc Zyngier wrote:
> Add a handler for reading the guest's view of the ICC_IAR1_EL1
> register. This involves finding the highest priority Group-1
> interrupt, checking against both PMR and the active group
> priority, activating the interrupt and setting the group
> priority as active.
>
> Tested-by: Alexander Graf <agraf@suse.de>
> Acked-by: David Daney <david.daney@cavium.com>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
> ---
> include/linux/irqchip/arm-gic-v3.h | 1 +
> virt/kvm/arm/hyp/vgic-v3-sr.c | 163 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 164 insertions(+)
>
> diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
> index fffb91202bc9..401db585a534 100644
> --- a/include/linux/irqchip/arm-gic-v3.h
> +++ b/include/linux/irqchip/arm-gic-v3.h
> @@ -405,6 +405,7 @@
> #define ICH_LR_PHYS_ID_SHIFT 32
> #define ICH_LR_PHYS_ID_MASK (0x3ffULL << ICH_LR_PHYS_ID_SHIFT)
> #define ICH_LR_PRIORITY_SHIFT 48
> +#define ICH_LR_PRIORITY_MASK (0xffULL << ICH_LR_PRIORITY_SHIFT)
>
> /* These are for GICv2 emulation only */
> #define GICH_LR_VIRTUALID (0x3ffUL << 0)
> diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
> index 25f09721241f..5a20f8d5bada 100644
> --- a/virt/kvm/arm/hyp/vgic-v3-sr.c
> +++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
> @@ -24,6 +24,7 @@
>
> #define vtr_to_max_lr_idx(v) ((v) & 0xf)
> #define vtr_to_nr_pre_bits(v) ((((u32)(v) >> 26) & 7) + 1)
> +#define vtr_to_nr_apr_regs(v) (1 << (vtr_to_nr_pre_bits(v) - 5))
>
> static u64 __hyp_text __gic_v3_get_lr(unsigned int lr)
> {
> @@ -381,6 +382,88 @@ static int __hyp_text __vgic_v3_bpr_min(void)
> return 8 - vtr_to_nr_pre_bits(read_gicreg(ICH_VTR_EL2));
> }
>
> +static int __hyp_text __vgic_v3_get_group(struct kvm_vcpu *vcpu)
> +{
> + u32 esr = kvm_vcpu_get_hsr(vcpu);
> + u8 crm = (esr & ESR_ELx_SYS64_ISS_CRM_MASK) >> ESR_ELx_SYS64_ISS_CRM_SHIFT;
> +
> + return crm != 8;
> +}
> +
> +#define GICv3_IDLE_PRIORITY 0xff
> +
> +static int __hyp_text __vgic_v3_highest_priority_lr(struct kvm_vcpu *vcpu,
> + u32 vmcr,
> + u64 *lr_val)
> +{
> + unsigned int used_lrs = vcpu->arch.vgic_cpu.used_lrs;
> + u8 priority = GICv3_IDLE_PRIORITY;
> + int i, lr = -1;
> +
> + for (i = 0; i < used_lrs; i++) {
> + u64 val = __gic_v3_get_lr(i);
> + u8 lr_prio = (val & ICH_LR_PRIORITY_MASK) >> ICH_LR_PRIORITY_SHIFT;
> +
> + /* Not pending in the state? */
> + if ((val & ICH_LR_STATE) != ICH_LR_PENDING_BIT)
> + continue;
> +
> + /* Group-0 interrupt, but Group-0 disabled? */
> + if (!(val & ICH_LR_GROUP) && !(vmcr & ICH_VMCR_ENG0_MASK))
> + continue;
> +
> + /* Group-1 interrupt, but Group-1 disabled? */
> + if ((val & ICH_LR_GROUP) && !(vmcr & ICH_VMCR_ENG1_MASK))
> + continue;
> +
> + /* Not the highest priority? */
> + if (lr_prio >= priority)
> + continue;
> +
> + /* This is a candidate */
> + priority = lr_prio;
> + *lr_val = val;
> + lr = i;
> + }
> +
> + if (lr == -1)
> + *lr_val = ICC_IAR1_EL1_SPURIOUS;
> +
> + return lr;
> +}
> +
> +static int __hyp_text __vgic_v3_get_highest_active_priority(void)
> +{
> + u8 nr_apr_regs = vtr_to_nr_apr_regs(read_gicreg(ICH_VTR_EL2));
> + u32 hap = 0;
> + int i;
> +
> + for (i = 0; i < nr_apr_regs; i++) {
> + u32 val;
> +
> + /*
> + * The ICH_AP0Rn_EL2 and ICH_AP1Rn_EL2 registers
> + * contain the active priority levels for this VCPU
> + * for the maximum number of supported priority
> + * levels, and we return the full priority level only
> + * if the BPR is programmed to its minimum, otherwise
> + * we return a combination of the priority level and
> + * subpriority, as determined by the setting of the
> + * BPR, but without the full subpriority.
> + */
> + val = __vgic_v3_read_ap0rn(i);
> + val |= __vgic_v3_read_ap1rn(i);
> + if (!val) {
> + hap += 32;
> + continue;
> + }
> +
> + return (hap + __ffs(val)) << __vgic_v3_bpr_min();
> + }
> +
> + return GICv3_IDLE_PRIORITY;
> +}
> +
> static unsigned int __hyp_text __vgic_v3_get_bpr0(u32 vmcr)
> {
> return (vmcr & ICH_VMCR_BPR0_MASK) >> ICH_VMCR_BPR0_SHIFT;
> @@ -401,6 +484,83 @@ static unsigned int __hyp_text __vgic_v3_get_bpr1(u32 vmcr)
> return bpr;
> }
>
> +/*
> + * Convert a priority to a preemption level, taking the relevant BPR
> + * into account by zeroing the sub-priority bits.
> + */
> +static u8 __hyp_text __vgic_v3_pri_to_pre(u8 pri, u32 vmcr, int grp)
> +{
> + unsigned int bpr;
> +
> + if (!grp)
> + bpr = __vgic_v3_get_bpr0(vmcr) + 1;
> + else
> + bpr = __vgic_v3_get_bpr1(vmcr);
> +
> + return pri & (GENMASK(7, 0) << bpr);
> +}
> +
> +/*
> + * The priority value is independent of any of the BPR values, so we
> + * normalize it using the minumal BPR value. This guarantees that no
> + * matter what the guest does with its BPR, we can always set/get the
> + * same value of a priority.
> + */
> +static void __hyp_text __vgic_v3_set_active_priority(u8 pri, u32 vmcr, int grp)
> +{
> + u8 pre, ap;
> + u32 val;
> + int apr;
> +
> + pre = __vgic_v3_pri_to_pre(pri, vmcr, grp);
> + ap = pre >> __vgic_v3_bpr_min();
> + apr = ap / 32;
> +
> + if (!grp) {
> + val = __vgic_v3_read_ap0rn(apr);
> + __vgic_v3_write_ap0rn(val | BIT(ap % 32), apr);
> + } else {
> + val = __vgic_v3_read_ap1rn(apr);
> + __vgic_v3_write_ap1rn(val | BIT(ap % 32), apr);
> + }
> +}
> +
> +static void __hyp_text __vgic_v3_read_iar(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> +{
> + u64 lr_val;
> + u8 lr_prio, pmr;
> + int lr, grp;
> +
> + grp = __vgic_v3_get_group(vcpu);
> +
> + lr = __vgic_v3_highest_priority_lr(vcpu, vmcr, &lr_val);
> + if (lr < 0)
> + goto spurious;
> +
> + if (grp != !!(lr_val & ICH_LR_GROUP))
> + goto spurious;
> +
> + pmr = (vmcr & ICH_VMCR_PMR_MASK) >> ICH_VMCR_PMR_SHIFT;
> + lr_prio = (lr_val & ICH_LR_PRIORITY_MASK) >> ICH_LR_PRIORITY_SHIFT;
> + if (pmr <= lr_prio)
> + goto spurious;
> +
> + if (__vgic_v3_get_highest_active_priority() <= __vgic_v3_pri_to_pre(lr_prio, vmcr, grp))
> + goto spurious;
> +
> + lr_val &= ~ICH_LR_STATE;
> + /* No active state for LPIs */
> + if ((lr_val & ICH_LR_VIRTUAL_ID_MASK) <= VGIC_MAX_SPI)
> + lr_val |= ICH_LR_ACTIVE_BIT;
> + __gic_v3_set_lr(lr_val, lr);
> + __vgic_v3_set_active_priority(lr_prio, vmcr, grp);
> + vcpu_set_reg(vcpu, rt, lr_val & ICH_LR_VIRTUAL_ID_MASK);
> + return;
> +
> +spurious:
> + vcpu_set_reg(vcpu, rt, ICC_IAR1_EL1_SPURIOUS);
> +}
> +
> static void __hyp_text __vgic_v3_read_igrpen1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> {
> vcpu_set_reg(vcpu, rt, !!(vmcr & ICH_VMCR_ENG1_MASK));
> @@ -465,6 +625,9 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> is_read = (esr & ESR_ELx_SYS64_ISS_DIR_MASK) == ESR_ELx_SYS64_ISS_DIR_READ;
>
> switch (sysreg) {
> + case SYS_ICC_IAR1_EL1:
> + fn = __vgic_v3_read_iar;
> + break;
> case SYS_ICC_GRPEN1_EL1:
> if (is_read)
> fn = __vgic_v3_read_igrpen1;
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 37+ messages in thread
* [PATCH v3 08/27] KVM: arm64: vgic-v3: Add ICV_EOIR1_EL1 handler
2017-06-09 11:49 ` [PATCH v3 08/27] KVM: arm64: vgic-v3: Add ICV_EOIR1_EL1 handler Marc Zyngier
@ 2017-06-09 15:27 ` Christoffer Dall
0 siblings, 0 replies; 37+ messages in thread
From: Christoffer Dall @ 2017-06-09 15:27 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jun 09, 2017 at 12:49:37PM +0100, Marc Zyngier wrote:
> Add a handler for writing the guest's view of the ICC_EOIR1_EL1
> register. This involves dropping the priority of the interrupt,
> and deactivating it if required (EOImode == 0).
>
> Tested-by: Alexander Graf <agraf@suse.de>
> Acked-by: David Daney <david.daney@cavium.com>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
> ---
> include/linux/irqchip/arm-gic-v3.h | 2 +
> virt/kvm/arm/hyp/vgic-v3-sr.c | 120 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 122 insertions(+)
>
> diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
> index 401db585a534..e50ce5d416a3 100644
> --- a/include/linux/irqchip/arm-gic-v3.h
> +++ b/include/linux/irqchip/arm-gic-v3.h
> @@ -417,6 +417,8 @@
>
> #define ICH_HCR_EN (1 << 0)
> #define ICH_HCR_UIE (1 << 1)
> +#define ICH_HCR_EOIcount_SHIFT 27
> +#define ICH_HCR_EOIcount_MASK (0x1f << ICH_HCR_EOIcount_SHIFT)
>
> #define ICH_VMCR_CBPR_SHIFT 4
> #define ICH_VMCR_CBPR_MASK (1 << ICH_VMCR_CBPR_SHIFT)
> diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
> index 5a20f8d5bada..e9ff99112c4d 100644
> --- a/virt/kvm/arm/hyp/vgic-v3-sr.c
> +++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
> @@ -432,6 +432,26 @@ static int __hyp_text __vgic_v3_highest_priority_lr(struct kvm_vcpu *vcpu,
> return lr;
> }
>
> +static int __hyp_text __vgic_v3_find_active_lr(struct kvm_vcpu *vcpu,
> + int intid, u64 *lr_val)
> +{
> + unsigned int used_lrs = vcpu->arch.vgic_cpu.used_lrs;
> + int i;
> +
> + for (i = 0; i < used_lrs; i++) {
> + u64 val = __gic_v3_get_lr(i);
> +
> + if ((val & ICH_LR_VIRTUAL_ID_MASK) == intid &&
> + (val & ICH_LR_ACTIVE_BIT)) {
> + *lr_val = val;
> + return i;
> + }
> + }
> +
> + *lr_val = ICC_IAR1_EL1_SPURIOUS;
> + return -1;
> +}
> +
> static int __hyp_text __vgic_v3_get_highest_active_priority(void)
> {
> u8 nr_apr_regs = vtr_to_nr_apr_regs(read_gicreg(ICH_VTR_EL2));
> @@ -525,6 +545,44 @@ static void __hyp_text __vgic_v3_set_active_priority(u8 pri, u32 vmcr, int grp)
> }
> }
>
> +static int __hyp_text __vgic_v3_clear_highest_active_priority(void)
> +{
> + u8 nr_apr_regs = vtr_to_nr_apr_regs(read_gicreg(ICH_VTR_EL2));
> + u32 hap = 0;
> + int i;
> +
> + for (i = 0; i < nr_apr_regs; i++) {
> + u32 ap0, ap1;
> + int c0, c1;
> +
> + ap0 = __vgic_v3_read_ap0rn(i);
> + ap1 = __vgic_v3_read_ap1rn(i);
> + if (!ap0 && !ap1) {
> + hap += 32;
> + continue;
> + }
> +
> + c0 = ap0 ? __ffs(ap0) : 32;
> + c1 = ap1 ? __ffs(ap1) : 32;
> +
> + /* Always clear the LSB, which is the highest priority */
> + if (c0 < c1) {
> + ap0 &= ~BIT(c0);
> + __vgic_v3_write_ap0rn(ap0, i);
> + hap += c0;
> + } else {
> + ap1 &= ~BIT(c1);
> + __vgic_v3_write_ap1rn(ap1, i);
> + hap += c1;
> + }
> +
> + /* Rescale to 8 bits of priority */
> + return hap << __vgic_v3_bpr_min();
> + }
> +
> + return GICv3_IDLE_PRIORITY;
> +}
> +
> static void __hyp_text __vgic_v3_read_iar(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> {
> u64 lr_val;
> @@ -561,6 +619,65 @@ static void __hyp_text __vgic_v3_read_iar(struct kvm_vcpu *vcpu, u32 vmcr, int r
> vcpu_set_reg(vcpu, rt, ICC_IAR1_EL1_SPURIOUS);
> }
>
> +static void __hyp_text __vgic_v3_clear_active_lr(int lr, u64 lr_val)
> +{
> + lr_val &= ~ICH_LR_ACTIVE_BIT;
> + if (lr_val & ICH_LR_HW) {
> + u32 pid;
> +
> + pid = (lr_val & ICH_LR_PHYS_ID_MASK) >> ICH_LR_PHYS_ID_SHIFT;
> + gic_write_dir(pid);
> + }
> +
> + __gic_v3_set_lr(lr_val, lr);
> +}
> +
> +static void __hyp_text __vgic_v3_bump_eoicount(void)
> +{
> + u32 hcr;
> +
> + hcr = read_gicreg(ICH_HCR_EL2);
> + hcr += 1 << ICH_HCR_EOIcount_SHIFT;
> + write_gicreg(hcr, ICH_HCR_EL2);
> +}
> +
> +static void __hyp_text __vgic_v3_write_eoir(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> +{
> + u32 vid = vcpu_get_reg(vcpu, rt);
> + u64 lr_val;
> + u8 lr_prio, act_prio;
> + int lr, grp;
> +
> + grp = __vgic_v3_get_group(vcpu);
> +
> + /* Drop priority in any case */
> + act_prio = __vgic_v3_clear_highest_active_priority();
> +
> + /* If EOIing an LPI, no deactivate to be performed */
> + if (vid >= VGIC_MIN_LPI)
> + return;
> +
> + /* EOImode == 1, nothing to be done here */
> + if (vmcr & ICH_VMCR_EOIM_MASK)
> + return;
> +
> + lr = __vgic_v3_find_active_lr(vcpu, vid, &lr_val);
> + if (lr == -1) {
> + __vgic_v3_bump_eoicount();
> + return;
> + }
> +
> + lr_prio = (lr_val & ICH_LR_PRIORITY_MASK) >> ICH_LR_PRIORITY_SHIFT;
> +
> + /* If priorities or group do not match, the guest has fscked-up. */
> + if (grp != !!(lr_val & ICH_LR_GROUP) ||
> + __vgic_v3_pri_to_pre(lr_prio, vmcr, grp) != act_prio)
> + return;
> +
> + /* Let's now perform the deactivation */
> + __vgic_v3_clear_active_lr(lr, lr_val);
> +}
> +
> static void __hyp_text __vgic_v3_read_igrpen1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> {
> vcpu_set_reg(vcpu, rt, !!(vmcr & ICH_VMCR_ENG1_MASK));
> @@ -628,6 +745,9 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> case SYS_ICC_IAR1_EL1:
> fn = __vgic_v3_read_iar;
> break;
> + case SYS_ICC_EOIR1_EL1:
> + fn = __vgic_v3_write_eoir;
> + break;
> case SYS_ICC_GRPEN1_EL1:
> if (is_read)
> fn = __vgic_v3_read_igrpen1;
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 37+ messages in thread
* [PATCH v3 10/27] KVM: arm64: vgic-v3: Add ICV_HPPIR1_EL1 handler
2017-06-09 11:49 ` [PATCH v3 10/27] KVM: arm64: vgic-v3: Add ICV_HPPIR1_EL1 handler Marc Zyngier
@ 2017-06-09 15:28 ` Christoffer Dall
0 siblings, 0 replies; 37+ messages in thread
From: Christoffer Dall @ 2017-06-09 15:28 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jun 09, 2017 at 12:49:39PM +0100, Marc Zyngier wrote:
> Add a handler for reading the guest's view of the ICV_HPPIR1_EL1
> register. This is a simple parsing of the available LRs, extracting the
> highest available interrupt.
>
> Tested-by: Alexander Graf <agraf@suse.de>
> Acked-by: David Daney <david.daney@cavium.com>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
> ---
> arch/arm64/include/asm/sysreg.h | 1 +
> virt/kvm/arm/hyp/vgic-v3-sr.c | 23 +++++++++++++++++++++++
> 2 files changed, 24 insertions(+)
>
> diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
> index aad46b8eea5e..bd000686194a 100644
> --- a/arch/arm64/include/asm/sysreg.h
> +++ b/arch/arm64/include/asm/sysreg.h
> @@ -185,6 +185,7 @@
> #define SYS_ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5)
> #define SYS_ICC_IAR1_EL1 sys_reg(3, 0, 12, 12, 0)
> #define SYS_ICC_EOIR1_EL1 sys_reg(3, 0, 12, 12, 1)
> +#define SYS_ICC_HPPIR1_EL1 sys_reg(3, 0, 12, 12, 2)
> #define SYS_ICC_BPR1_EL1 sys_reg(3, 0, 12, 12, 3)
> #define SYS_ICC_CTLR_EL1 sys_reg(3, 0, 12, 12, 4)
> #define SYS_ICC_SRE_EL1 sys_reg(3, 0, 12, 12, 5)
> diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
> index 1c85a6df22d9..f031e8f088ae 100644
> --- a/virt/kvm/arm/hyp/vgic-v3-sr.c
> +++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
> @@ -790,6 +790,26 @@ static void __hyp_text __vgic_v3_write_apxr3(struct kvm_vcpu *vcpu,
> __vgic_v3_write_apxrn(vcpu, rt, 3);
> }
>
> +static void __hyp_text __vgic_v3_read_hppir(struct kvm_vcpu *vcpu,
> + u32 vmcr, int rt)
> +{
> + u64 lr_val;
> + int lr, lr_grp, grp;
> +
> + grp = __vgic_v3_get_group(vcpu);
> +
> + lr = __vgic_v3_highest_priority_lr(vcpu, vmcr, &lr_val);
> + if (lr == -1)
> + goto spurious;
> +
> + lr_grp = !!(lr_val & ICH_LR_GROUP);
> + if (lr_grp != grp)
> + lr_val = ICC_IAR1_EL1_SPURIOUS;
> +
> +spurious:
> + vcpu_set_reg(vcpu, rt, lr_val & ICH_LR_VIRTUAL_ID_MASK);
> +}
> +
> int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> {
> int rt;
> @@ -854,6 +874,9 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> else
> fn = __vgic_v3_write_apxr3;
> break;
> + case SYS_ICC_HPPIR1_EL1:
> + fn = __vgic_v3_read_hppir;
> + break;
> default:
> return 0;
> }
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 37+ messages in thread
* [PATCH v3 12/27] KVM: arm64: Enable GICv3 Group-1 sysreg trapping via command-line
2017-06-09 11:49 ` [PATCH v3 12/27] KVM: arm64: Enable GICv3 Group-1 sysreg trapping via command-line Marc Zyngier
@ 2017-06-09 15:29 ` Christoffer Dall
0 siblings, 0 replies; 37+ messages in thread
From: Christoffer Dall @ 2017-06-09 15:29 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jun 09, 2017 at 12:49:41PM +0100, Marc Zyngier wrote:
> Now that we're able to safely handle Group-1 sysreg access, let's
> give the user the opportunity to enable it by passing a specific
> command-line option (vgic_v3.group1_trap).
>
> Tested-by: Alexander Graf <agraf@suse.de>
> Acked-by: David Daney <david.daney@cavium.com>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Christoffer Dall <cdall@linaro.org>
> ---
> Documentation/admin-guide/kernel-parameters.txt | 4 ++++
> virt/kvm/arm/vgic/vgic-v3.c | 11 +++++++++++
> 2 files changed, 15 insertions(+)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 15f79c27748d..42fe395be6c8 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -1829,6 +1829,10 @@
> for all guests.
> Default is 1 (enabled) if in 64-bit or 32-bit PAE mode.
>
> + kvm-arm.vgic_v3_group1_trap=
> + [KVM,ARM] Trap guest accesses to GICv3 group-1
> + system registers
> +
> kvm-intel.ept= [KVM,Intel] Disable extended page tables
> (virtualized MMU) support on capable Intel chips.
> Default is 1 (enabled)
> diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
> index fbd678bc046d..df55818f095c 100644
> --- a/virt/kvm/arm/vgic/vgic-v3.c
> +++ b/virt/kvm/arm/vgic/vgic-v3.c
> @@ -416,6 +416,12 @@ int vgic_v3_map_resources(struct kvm *kvm)
>
> DEFINE_STATIC_KEY_FALSE(vgic_v3_cpuif_trap);
>
> +static int __init early_group1_trap_cfg(char *buf)
> +{
> + return strtobool(buf, &group1_trap);
> +}
> +early_param("kvm-arm.vgic_v3_group1_trap", early_group1_trap_cfg);
> +
> /**
> * vgic_v3_probe - probe for a GICv3 compatible interrupt controller in DT
> * @node: pointer to the DT node
> @@ -467,6 +473,11 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
> if (kvm_vgic_global_state.vcpu_base == 0)
> kvm_info("disabling GICv2 emulation\n");
>
> + if (group1_trap) {
> + kvm_info("GICv3 sysreg trapping enabled (reduced performance)\n");
> + static_branch_enable(&vgic_v3_cpuif_trap);
> + }
> +
> kvm_vgic_global_state.vctrl_base = NULL;
> kvm_vgic_global_state.type = VGIC_V3;
> kvm_vgic_global_state.max_gic_vcpus = VGIC_V3_MAX_CPUS;
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 37+ messages in thread
* [PATCH v3 13/27] KVM: arm64: vgic-v3: Add ICV_BPR0_EL1 handler
2017-06-09 11:49 ` [PATCH v3 13/27] KVM: arm64: vgic-v3: Add ICV_BPR0_EL1 handler Marc Zyngier
@ 2017-06-09 15:29 ` Christoffer Dall
0 siblings, 0 replies; 37+ messages in thread
From: Christoffer Dall @ 2017-06-09 15:29 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jun 09, 2017 at 12:49:42PM +0100, Marc Zyngier wrote:
> Add a handler for reading/writing the guest's view of the ICC_BPR0_EL1
> register, which is located in the ICH_VMCR_EL2.BPR0 field.
>
> Tested-by: Alexander Graf <agraf@suse.de>
> Acked-by: David Daney <david.daney@cavium.com>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
> ---
> arch/arm64/include/asm/sysreg.h | 1 +
> virt/kvm/arm/hyp/vgic-v3-sr.c | 28 ++++++++++++++++++++++++++++
> 2 files changed, 29 insertions(+)
>
> diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
> index bd000686194a..d20be0b28ca4 100644
> --- a/arch/arm64/include/asm/sysreg.h
> +++ b/arch/arm64/include/asm/sysreg.h
> @@ -180,6 +180,7 @@
>
> #define SYS_VBAR_EL1 sys_reg(3, 0, 12, 0, 0)
>
> +#define SYS_ICC_BPR0_EL1 sys_reg(3, 0, 12, 8, 3)
> #define SYS_ICC_AP1Rn_EL1(n) sys_reg(3, 0, 12, 9, n)
> #define SYS_ICC_DIR_EL1 sys_reg(3, 0, 12, 11, 1)
> #define SYS_ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5)
> diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
> index a2a62f030341..f53908cc981c 100644
> --- a/virt/kvm/arm/hyp/vgic-v3-sr.c
> +++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
> @@ -706,11 +706,33 @@ static void __hyp_text __vgic_v3_write_igrpen1(struct kvm_vcpu *vcpu, u32 vmcr,
> __vgic_v3_write_vmcr(vmcr);
> }
>
> +static void __hyp_text __vgic_v3_read_bpr0(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> +{
> + vcpu_set_reg(vcpu, rt, __vgic_v3_get_bpr0(vmcr));
> +}
> +
> static void __hyp_text __vgic_v3_read_bpr1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> {
> vcpu_set_reg(vcpu, rt, __vgic_v3_get_bpr1(vmcr));
> }
>
> +static void __hyp_text __vgic_v3_write_bpr0(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> +{
> + u64 val = vcpu_get_reg(vcpu, rt);
> + u8 bpr_min = __vgic_v3_bpr_min() - 1;
> +
> + /* Enforce BPR limiting */
> + if (val < bpr_min)
> + val = bpr_min;
> +
> + val <<= ICH_VMCR_BPR0_SHIFT;
> + val &= ICH_VMCR_BPR0_MASK;
> + vmcr &= ~ICH_VMCR_BPR0_MASK;
> + vmcr |= val;
> +
> + __vgic_v3_write_vmcr(vmcr);
> +}
> +
> static void __hyp_text __vgic_v3_write_bpr1(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
> {
> u64 val = vcpu_get_reg(vcpu, rt);
> @@ -888,6 +910,12 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> case SYS_ICC_HPPIR1_EL1:
> fn = __vgic_v3_read_hppir;
> break;
> + case SYS_ICC_BPR0_EL1:
> + if (is_read)
> + fn = __vgic_v3_read_bpr0;
> + else
> + fn = __vgic_v3_write_bpr0;
> + break;
> default:
> return 0;
> }
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 37+ messages in thread
* [PATCH v3 24/27] KVM: arm64: Enable GICv3 common sysreg trapping via command-line
2017-06-09 11:49 ` [PATCH v3 24/27] KVM: arm64: Enable GICv3 common sysreg trapping via command-line Marc Zyngier
@ 2017-06-09 15:31 ` Christoffer Dall
0 siblings, 0 replies; 37+ messages in thread
From: Christoffer Dall @ 2017-06-09 15:31 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jun 09, 2017 at 12:49:53PM +0100, Marc Zyngier wrote:
> Now that we're able to safely handle common sysreg access, let's
> give the user the opportunity to enable it by passing a specific
> command-line option (vgic_v3.common_trap).
>
> Tested-by: Alexander Graf <agraf@suse.de>
> Acked-by: David Daney <david.daney@cavium.com>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Christoffer Dall <cdall@linaro.org>
> ---
> Documentation/admin-guide/kernel-parameters.txt | 4 ++++
> include/linux/irqchip/arm-gic-v3.h | 1 +
> virt/kvm/arm/vgic/vgic-v3.c | 11 ++++++++++-
> 3 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 88bdc421351f..aa8341e73b35 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -1837,6 +1837,10 @@
> [KVM,ARM] Trap guest accesses to GICv3 group-1
> system registers
>
> + kvm-arm.vgic_v3_common_trap=
> + [KVM,ARM] Trap guest accesses to GICv3 common
> + system registers
> +
> kvm-intel.ept= [KVM,Intel] Disable extended page tables
> (virtualized MMU) support on capable Intel chips.
> Default is 1 (enabled)
> diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
> index 46a1e0943cf8..f0cebb6e57d0 100644
> --- a/include/linux/irqchip/arm-gic-v3.h
> +++ b/include/linux/irqchip/arm-gic-v3.h
> @@ -417,6 +417,7 @@
>
> #define ICH_HCR_EN (1 << 0)
> #define ICH_HCR_UIE (1 << 1)
> +#define ICH_HCR_TC (1 << 10)
> #define ICH_HCR_TALL0 (1 << 11)
> #define ICH_HCR_TALL1 (1 << 12)
> #define ICH_HCR_EOIcount_SHIFT 27
> diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
> index ffc581b70c4e..3960e89c05ad 100644
> --- a/virt/kvm/arm/vgic/vgic-v3.c
> +++ b/virt/kvm/arm/vgic/vgic-v3.c
> @@ -23,6 +23,7 @@
>
> static bool group0_trap;
> static bool group1_trap;
> +static bool common_trap;
>
> void vgic_v3_set_underflow(struct kvm_vcpu *vcpu)
> {
> @@ -246,6 +247,8 @@ void vgic_v3_enable(struct kvm_vcpu *vcpu)
> vgic_v3->vgic_hcr |= ICH_HCR_TALL0;
> if (group1_trap)
> vgic_v3->vgic_hcr |= ICH_HCR_TALL1;
> + if (common_trap)
> + vgic_v3->vgic_hcr |= ICH_HCR_TC;
> }
>
> int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq)
> @@ -431,6 +434,12 @@ static int __init early_group1_trap_cfg(char *buf)
> }
> early_param("kvm-arm.vgic_v3_group1_trap", early_group1_trap_cfg);
>
> +static int __init early_common_trap_cfg(char *buf)
> +{
> + return strtobool(buf, &common_trap);
> +}
> +early_param("kvm-arm.vgic_v3_common_trap", early_common_trap_cfg);
> +
> /**
> * vgic_v3_probe - probe for a GICv3 compatible interrupt controller in DT
> * @node: pointer to the DT node
> @@ -489,7 +498,7 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
> }
> #endif
>
> - if (group0_trap || group1_trap) {
> + if (group0_trap || group1_trap || common_trap) {
> kvm_info("GICv3 sysreg trapping enabled (reduced performance)\n");
> static_branch_enable(&vgic_v3_cpuif_trap);
> }
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 37+ messages in thread
* [PATCH v3 26/27] KVM: arm64: Log an error if trapping a read-from-write-only GICv3 access
2017-06-09 11:49 ` [PATCH v3 26/27] KVM: arm64: Log an error if trapping a read-from-write-only GICv3 access Marc Zyngier
@ 2017-06-09 15:33 ` Christoffer Dall
0 siblings, 0 replies; 37+ messages in thread
From: Christoffer Dall @ 2017-06-09 15:33 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jun 09, 2017 at 12:49:55PM +0100, Marc Zyngier wrote:
> A read-from-write-only GICv3 access should UNDEF at EL1. But since
> we're in complete paranoia-land with broken CPUs, let's assume the
> worse and gracefully handle the case.
>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
> ---
> arch/arm64/kvm/sys_regs.c | 12 ++++++++----
> virt/kvm/arm/hyp/vgic-v3-sr.c | 4 ++++
> 2 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 0fe27024a2e1..8d51c075966d 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -56,7 +56,8 @@
> */
>
> static bool read_from_write_only(struct kvm_vcpu *vcpu,
> - const struct sys_reg_params *params)
> + struct sys_reg_params *params,
> + const struct sys_reg_desc *r)
> {
> WARN_ONCE(1, "Unexpected sys_reg read to write-only register\n");
> print_sys_reg_instr(params);
> @@ -93,7 +94,7 @@ static bool access_dcsw(struct kvm_vcpu *vcpu,
> const struct sys_reg_desc *r)
> {
> if (!p->is_write)
> - return read_from_write_only(vcpu, p);
> + return read_from_write_only(vcpu, p, r);
>
> kvm_set_way_flush(vcpu);
> return true;
> @@ -135,7 +136,7 @@ static bool access_gic_sgi(struct kvm_vcpu *vcpu,
> const struct sys_reg_desc *r)
> {
> if (!p->is_write)
> - return read_from_write_only(vcpu, p);
> + return read_from_write_only(vcpu, p, r);
>
> vgic_v3_dispatch_sgi(vcpu, p->regval);
>
> @@ -773,7 +774,7 @@ static bool access_pmswinc(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
> return trap_raz_wi(vcpu, p, r);
>
> if (!p->is_write)
> - return read_from_write_only(vcpu, p);
> + return read_from_write_only(vcpu, p, r);
>
> if (pmu_write_swinc_el0_disabled(vcpu))
> return false;
> @@ -953,7 +954,10 @@ static const struct sys_reg_desc sys_reg_descs[] = {
>
> { SYS_DESC(SYS_VBAR_EL1), NULL, reset_val, VBAR_EL1, 0 },
>
> + { SYS_DESC(SYS_ICC_EOIR0_EL1), read_from_write_only },
> + { SYS_DESC(SYS_ICC_DIR_EL1), read_from_write_only },
> { SYS_DESC(SYS_ICC_SGI1R_EL1), access_gic_sgi },
> + { SYS_DESC(SYS_ICC_EOIR1_EL1), read_from_write_only },
> { SYS_DESC(SYS_ICC_SRE_EL1), access_gic_sre },
>
> { SYS_DESC(SYS_CONTEXTIDR_EL1), access_vm_reg, reset_val, CONTEXTIDR_EL1, 0 },
> diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
> index 15b557697086..b26ce58b012a 100644
> --- a/virt/kvm/arm/hyp/vgic-v3-sr.c
> +++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
> @@ -980,6 +980,8 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> break;
> case SYS_ICC_EOIR0_EL1:
> case SYS_ICC_EOIR1_EL1:
> + if (unlikely(is_read))
> + return 0;
> fn = __vgic_v3_write_eoir;
> break;
> case SYS_ICC_GRPEN1_EL1:
> @@ -1039,6 +1041,8 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> fn = __vgic_v3_write_bpr0;
> break;
> case SYS_ICC_DIR_EL1:
> + if (unlikely(is_read))
> + return 0;
> fn = __vgic_v3_write_dir;
> break;
> case SYS_ICC_RPR_EL1:
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 37+ messages in thread
* [PATCH v3 27/27] KVM: arm64: Log an error if trapping a write-to-read-only GICv3 access
2017-06-09 11:49 ` [PATCH v3 27/27] KVM: arm64: Log an error if trapping a write-to-read-only " Marc Zyngier
@ 2017-06-09 15:34 ` Christoffer Dall
0 siblings, 0 replies; 37+ messages in thread
From: Christoffer Dall @ 2017-06-09 15:34 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jun 09, 2017 at 12:49:56PM +0100, Marc Zyngier wrote:
> A write-to-read-only GICv3 access should UNDEF at EL1. But since
> we're in complete paranoia-land with broken CPUs, let's assume the
> worse and gracefully handle the case.
>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
> ---
> arch/arm64/kvm/sys_regs.c | 15 +++++++++++++++
> virt/kvm/arm/hyp/vgic-v3-sr.c | 6 ++++++
> 2 files changed, 21 insertions(+)
>
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 8d51c075966d..77862881ae86 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -65,6 +65,16 @@ static bool read_from_write_only(struct kvm_vcpu *vcpu,
> return false;
> }
>
> +static bool write_to_read_only(struct kvm_vcpu *vcpu,
> + struct sys_reg_params *params,
> + const struct sys_reg_desc *r)
> +{
> + WARN_ONCE(1, "Unexpected sys_reg write to read-only register\n");
> + print_sys_reg_instr(params);
> + kvm_inject_undefined(vcpu);
> + return false;
> +}
> +
> /* 3 bits per cache level, as per CLIDR, but non-existent caches always 0 */
> static u32 cache_levels;
>
> @@ -954,10 +964,15 @@ static const struct sys_reg_desc sys_reg_descs[] = {
>
> { SYS_DESC(SYS_VBAR_EL1), NULL, reset_val, VBAR_EL1, 0 },
>
> + { SYS_DESC(SYS_ICC_IAR0_EL1), write_to_read_only },
> { SYS_DESC(SYS_ICC_EOIR0_EL1), read_from_write_only },
> + { SYS_DESC(SYS_ICC_HPPIR0_EL1), write_to_read_only },
> { SYS_DESC(SYS_ICC_DIR_EL1), read_from_write_only },
> + { SYS_DESC(SYS_ICC_RPR_EL1), write_to_read_only },
> { SYS_DESC(SYS_ICC_SGI1R_EL1), access_gic_sgi },
> + { SYS_DESC(SYS_ICC_IAR1_EL1), write_to_read_only },
> { SYS_DESC(SYS_ICC_EOIR1_EL1), read_from_write_only },
> + { SYS_DESC(SYS_ICC_HPPIR1_EL1), write_to_read_only },
> { SYS_DESC(SYS_ICC_SRE_EL1), access_gic_sre },
>
> { SYS_DESC(SYS_CONTEXTIDR_EL1), access_vm_reg, reset_val, CONTEXTIDR_EL1, 0 },
> diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
> index b26ce58b012a..79e3c2d3b754 100644
> --- a/virt/kvm/arm/hyp/vgic-v3-sr.c
> +++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
> @@ -976,6 +976,8 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> switch (sysreg) {
> case SYS_ICC_IAR0_EL1:
> case SYS_ICC_IAR1_EL1:
> + if (unlikely(!is_read))
> + return 0;
> fn = __vgic_v3_read_iar;
> break;
> case SYS_ICC_EOIR0_EL1:
> @@ -1026,6 +1028,8 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> break;
> case SYS_ICC_HPPIR0_EL1:
> case SYS_ICC_HPPIR1_EL1:
> + if (unlikely(!is_read))
> + return 0;
> fn = __vgic_v3_read_hppir;
> break;
> case SYS_ICC_GRPEN0_EL1:
> @@ -1046,6 +1050,8 @@ int __hyp_text __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
> fn = __vgic_v3_write_dir;
> break;
> case SYS_ICC_RPR_EL1:
> + if (unlikely(!is_read))
> + return 0;
> fn = __vgic_v3_read_rpr;
> break;
> case SYS_ICC_CTLR_EL1:
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 37+ messages in thread
end of thread, other threads:[~2017-06-09 15:34 UTC | newest]
Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-09 11:49 [PATCH v3 00/27] arm64: KVM: Mediate access to GICv3 sysregs at EL2 Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 01/27] arm64: Add a facility to turn an ESR syndrome into a sysreg encoding Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 02/27] KVM: arm/arm64: vgic-v3: Add accessors for the ICH_APxRn_EL2 registers Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 03/27] KVM: arm64: Make kvm_condition_valid32() accessible from EL2 Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 04/27] KVM: arm64: vgic-v3: Add hook to handle guest GICv3 sysreg accesses at EL2 Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 05/27] KVM: arm64: vgic-v3: Add ICV_BPR1_EL1 handler Marc Zyngier
2017-06-09 15:23 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 06/27] KVM: arm64: vgic-v3: Add ICV_IGRPEN1_EL1 handler Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 07/27] KVM: arm64: vgic-v3: Add ICV_IAR1_EL1 handler Marc Zyngier
2017-06-09 15:26 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 08/27] KVM: arm64: vgic-v3: Add ICV_EOIR1_EL1 handler Marc Zyngier
2017-06-09 15:27 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 09/27] KVM: arm64: vgic-v3: Add ICV_AP1Rn_EL1 handler Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 10/27] KVM: arm64: vgic-v3: Add ICV_HPPIR1_EL1 handler Marc Zyngier
2017-06-09 15:28 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 11/27] KVM: arm64: vgic-v3: Enable trapping of Group-1 system registers Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 12/27] KVM: arm64: Enable GICv3 Group-1 sysreg trapping via command-line Marc Zyngier
2017-06-09 15:29 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 13/27] KVM: arm64: vgic-v3: Add ICV_BPR0_EL1 handler Marc Zyngier
2017-06-09 15:29 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 14/27] KVM: arm64: vgic-v3: Add ICV_IGNREN0_EL1 handler Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 15/27] KVM: arm64: vgic-v3: Add misc Group-0 handlers Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 16/27] KVM: arm64: vgic-v3: Enable trapping of Group-0 system registers Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 17/27] KVM: arm64: Enable GICv3 Group-0 sysreg trapping via command-line Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 18/27] arm64: Add MIDR values for Cavium cn83XX SoCs Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 19/27] arm64: Add workaround for Cavium Thunder erratum 30115 Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 20/27] KVM: arm64: vgic-v3: Add ICV_DIR_EL1 handler Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 21/27] KVM: arm64: vgic-v3: Add ICV_RPR_EL1 handler Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 22/27] KVM: arm64: vgic-v3: Add ICV_CTLR_EL1 handler Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 23/27] KVM: arm64: vgic-v3: Add ICV_PMR_EL1 handler Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 24/27] KVM: arm64: Enable GICv3 common sysreg trapping via command-line Marc Zyngier
2017-06-09 15:31 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 25/27] KVM: arm64: vgic-v3: Log which GICv3 system registers are trapped Marc Zyngier
2017-06-09 11:49 ` [PATCH v3 26/27] KVM: arm64: Log an error if trapping a read-from-write-only GICv3 access Marc Zyngier
2017-06-09 15:33 ` Christoffer Dall
2017-06-09 11:49 ` [PATCH v3 27/27] KVM: arm64: Log an error if trapping a write-to-read-only " Marc Zyngier
2017-06-09 15:34 ` Christoffer Dall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).