kvmarm.lists.cs.columbia.edu archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: arm64: Hide SPE from guests
@ 2021-04-09 15:21 Alexandru Elisei
  2021-04-09 15:21 ` [PATCH 1/2] KVM: arm64: Don't print warning when trapping SPE registers Alexandru Elisei
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alexandru Elisei @ 2021-04-09 15:21 UTC (permalink / raw)
  To: maz, linux-arm-kernel, kvmarm

This was part of the KVM SPE series that I posted some time ago [1]. The
series didn't get too much attention, so I've decided to send this
fix/cleanup/improvement separately, to make it easier to review.

I've split the original patch into two because it makes more sense to me
this way, but I'm not opposed to squashing the series back into a single
patch if that is preferred.

Based on v5.12-rc6.

[1] https://www.spinics.net/lists/kvm-arm/msg42962.html

Alexandru Elisei (2):
  KVM: arm64: Don't print warning when trapping SPE registers
  KVM: arm64: Don't advertise FEAT_SPE to guests

 arch/arm64/include/asm/sysreg.h |  2 ++
 arch/arm64/kvm/sys_regs.c       | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

-- 
2.31.1

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] KVM: arm64: Don't print warning when trapping SPE registers
  2021-04-09 15:21 [PATCH 0/2] KVM: arm64: Hide SPE from guests Alexandru Elisei
@ 2021-04-09 15:21 ` Alexandru Elisei
  2021-04-09 15:21 ` [PATCH 2/2] KVM: arm64: Don't advertise FEAT_SPE to guests Alexandru Elisei
  2021-04-11  8:47 ` [PATCH 0/2] KVM: arm64: Hide SPE from guests Marc Zyngier
  2 siblings, 0 replies; 4+ messages in thread
From: Alexandru Elisei @ 2021-04-09 15:21 UTC (permalink / raw)
  To: maz, linux-arm-kernel, kvmarm

KVM sets up MDCR_EL2 to trap accesses to the SPE buffer and sampling
control registers and it relies on the fact that KVM injects an undefined
exception for unknown registers. This mechanism of injecting undefined
exceptions also prints a warning message for the host kernel; for example,
when a guest tries to access PMSIDR_EL1:

[    2.691830] kvm [142]: Unsupported guest sys_reg access at: 80009e78 [800003c5]
[    2.691830]  { Op0( 3), Op1( 0), CRn( 9), CRm( 9), Op2( 7), func_read },

This is unnecessary, because KVM has explicitly configured trapping of
those registers and is well aware of their existence. Prevent the warning
by adding the SPE registers to the list of registers that KVM emulates.
The access function will inject the undefined exception.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arch/arm64/include/asm/sysreg.h |  2 ++
 arch/arm64/kvm/sys_regs.c       | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index d4a5fca984c3..43bca834c477 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -283,6 +283,8 @@
 #define SYS_PMSIRR_EL1_INTERVAL_MASK	0xffffffUL
 
 /* Filtering controls */
+#define SYS_PMSNEVFR_EL1		sys_reg(3, 0, 9, 9, 1)
+
 #define SYS_PMSFCR_EL1			sys_reg(3, 0, 9, 9, 4)
 #define SYS_PMSFCR_EL1_FE_SHIFT		0
 #define SYS_PMSFCR_EL1_FT_SHIFT		1
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 4f2f1e3145de..402cd11aa4fc 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1501,6 +1501,19 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 	{ SYS_DESC(SYS_FAR_EL1), access_vm_reg, reset_unknown, FAR_EL1 },
 	{ SYS_DESC(SYS_PAR_EL1), NULL, reset_unknown, PAR_EL1 },
 
+	{ SYS_DESC(SYS_PMSCR_EL1), undef_access },
+	{ SYS_DESC(SYS_PMSNEVFR_EL1), undef_access },
+	{ SYS_DESC(SYS_PMSICR_EL1), undef_access },
+	{ SYS_DESC(SYS_PMSIRR_EL1), undef_access },
+	{ SYS_DESC(SYS_PMSFCR_EL1), undef_access },
+	{ SYS_DESC(SYS_PMSEVFR_EL1), undef_access },
+	{ SYS_DESC(SYS_PMSLATFR_EL1), undef_access },
+	{ SYS_DESC(SYS_PMSIDR_EL1), undef_access },
+	{ SYS_DESC(SYS_PMBLIMITR_EL1), undef_access },
+	{ SYS_DESC(SYS_PMBPTR_EL1), undef_access },
+	{ SYS_DESC(SYS_PMBSR_EL1), undef_access },
+	/* PMBIDR_EL1 is not trapped */
+
 	{ PMU_SYS_REG(SYS_PMINTENSET_EL1),
 	  .access = access_pminten, .reg = PMINTENSET_EL1 },
 	{ PMU_SYS_REG(SYS_PMINTENCLR_EL1),
-- 
2.31.1

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] KVM: arm64: Don't advertise FEAT_SPE to guests
  2021-04-09 15:21 [PATCH 0/2] KVM: arm64: Hide SPE from guests Alexandru Elisei
  2021-04-09 15:21 ` [PATCH 1/2] KVM: arm64: Don't print warning when trapping SPE registers Alexandru Elisei
@ 2021-04-09 15:21 ` Alexandru Elisei
  2021-04-11  8:47 ` [PATCH 0/2] KVM: arm64: Hide SPE from guests Marc Zyngier
  2 siblings, 0 replies; 4+ messages in thread
From: Alexandru Elisei @ 2021-04-09 15:21 UTC (permalink / raw)
  To: maz, linux-arm-kernel, kvmarm

Even though KVM sets up MDCR_EL2 to trap accesses to the SPE buffer and
sampling control registers and to inject an undefined exception, the
presence of FEAT_SPE is still advertised in the ID_AA64DFR0_EL1 register,
if the hardware supports it. Getting an undefined exception when accessing
a register usually happens for a hardware feature which is not implemented,
and indeed this is how PMU emulation is handled when the virtual machine
has been created without the KVM_ARM_VCPU_PMU_V3 feature. Let's be
consistent and never advertise FEAT_SPE, because KVM doesn't have support
for emulating it yet.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arch/arm64/kvm/sys_regs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 402cd11aa4fc..61ee9bfb8826 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1063,6 +1063,8 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
 		val = cpuid_feature_cap_perfmon_field(val,
 						      ID_AA64DFR0_PMUVER_SHIFT,
 						      kvm_vcpu_has_pmu(vcpu) ? ID_AA64DFR0_PMUVER_8_4 : 0);
+		/* Hide SPE from guests */
+		val &= ~FEATURE(ID_AA64DFR0_PMSVER);
 		break;
 	case SYS_ID_DFR0_EL1:
 		/* Limit guests to PMUv3 for ARMv8.4 */
-- 
2.31.1

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] KVM: arm64: Hide SPE from guests
  2021-04-09 15:21 [PATCH 0/2] KVM: arm64: Hide SPE from guests Alexandru Elisei
  2021-04-09 15:21 ` [PATCH 1/2] KVM: arm64: Don't print warning when trapping SPE registers Alexandru Elisei
  2021-04-09 15:21 ` [PATCH 2/2] KVM: arm64: Don't advertise FEAT_SPE to guests Alexandru Elisei
@ 2021-04-11  8:47 ` Marc Zyngier
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2021-04-11  8:47 UTC (permalink / raw)
  To: kvmarm, Alexandru Elisei, linux-arm-kernel

On Fri, 9 Apr 2021 16:21:52 +0100, Alexandru Elisei wrote:
> This was part of the KVM SPE series that I posted some time ago [1]. The
> series didn't get too much attention, so I've decided to send this
> fix/cleanup/improvement separately, to make it easier to review.
> 
> I've split the original patch into two because it makes more sense to me
> this way, but I'm not opposed to squashing the series back into a single
> patch if that is preferred.
> 
> [...]

Applied to kvm-arm64/debug-5.13, thanks!

[1/2] KVM: arm64: Don't print warning when trapping SPE registers
      commit: 13611bc80d3da162aaf32b01ceffc804e027d406
[2/2] KVM: arm64: Don't advertise FEAT_SPE to guests
      commit: 96f4f6809beec1bb2338e1aeac408e6a733f8135

Cheers,

	M.
-- 
Without deviation from the norm, progress is not possible.


_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-11  8:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-09 15:21 [PATCH 0/2] KVM: arm64: Hide SPE from guests Alexandru Elisei
2021-04-09 15:21 ` [PATCH 1/2] KVM: arm64: Don't print warning when trapping SPE registers Alexandru Elisei
2021-04-09 15:21 ` [PATCH 2/2] KVM: arm64: Don't advertise FEAT_SPE to guests Alexandru Elisei
2021-04-11  8:47 ` [PATCH 0/2] KVM: arm64: Hide SPE from guests Marc Zyngier

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).