linux-stable/arch/arm64/kvm
Dave Martin 93390c0a1b arm64: KVM: Hide unsupported AArch64 CPU features from guests
Currently, a guest kernel sees the true CPU feature registers
(ID_*_EL1) when it reads them using MRS instructions.  This means
that the guest may observe features that are present in the
hardware but the host doesn't understand or doesn't provide support
for.  A guest may legimitately try to use such a feature as per the
architecture, but use of the feature may trap instead of working
normally, triggering undef injection into the guest.

This is not a problem for the host, but the guest may go wrong when
running on newer hardware than the host knows about.

This patch hides from guest VMs any AArch64-specific CPU features
that the host doesn't support, by exposing to the guest the
sanitised versions of the registers computed by the cpufeatures
framework, instead of the true hardware registers.  To achieve
this, HCR_EL2.TID3 is now set for AArch64 guests, and emulation
code is added to KVM to report the sanitised versions of the
affected registers in response to MRS and register reads from
userspace.

The affected registers are removed from invariant_sys_regs[] (since
the invariant_sys_regs handling is no longer quite correct for
them) and added to sys_reg_desgs[], with appropriate access(),
get_user() and set_user() methods.  No runtime vcpu storage is
allocated for the registers: instead, they are read on demand from
the cpufeatures framework.  This may need modification in the
future if there is a need for userspace to customise the features
visible to the guest.

Attempts by userspace to write the registers are handled similarly
to the current invariant_sys_regs handling: writes are permitted,
but only if they don't attempt to change the value.  This is
sufficient to support VM snapshot/restore from userspace.

Because of the additional registers, restoring a VM on an older
kernel may not work unless userspace knows how to handle the extra
VM registers exposed to the KVM user ABI by this patch.

Under the principle of least damage, this patch makes no attempt to
handle any of the other registers currently in
invariant_sys_regs[], or to emulate registers for AArch32: however,
these could be handled in a similar way in future, as necessary.

Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-11-03 15:24:12 +00:00
..
hyp arm64: KVM: Hide unsupported AArch64 CPU features from guests 2017-11-03 15:24:12 +00:00
debug.c arm64: KVM: Save/restore the host SPE state when entering/leaving a VM 2017-02-02 18:33:01 +00:00
guest.c KVM: arm/arm64: Allow setting the timer IRQ numbers from userspace 2017-06-08 16:59:57 +02:00
handle_exit.c KVM: arm: implements the kvm_arch_vcpu_in_kernel() 2017-08-08 10:57:43 +02:00
hyp-init.S arm64: KVM: Allow unaligned accesses at EL2 2017-06-06 22:20:02 +02:00
hyp.S arm64: hyp-stub/KVM: Kill __hyp_get_vectors 2017-04-09 07:49:34 -07:00
inject_fault.c arm64: KVM: Add Virtual Abort injection helper 2016-09-08 12:53:00 +02:00
irq.h KVM: arm/arm64: Enable irqchip routing 2016-07-22 18:52:01 +01:00
Kconfig ARM: KVM: Support vGICv3 ITS 2016-11-14 10:32:54 +00:00
Makefile KVM: arm/arm64: Move shared files to virt/kvm/arm 2017-05-04 13:57:26 +02:00
regmap.c arm64: KVM: 32bit GP register access 2013-06-12 16:42:14 +01:00
reset.c KVM: arm/arm64: Move timer IRQ default init to arch_timer.c 2017-06-08 16:59:56 +02:00
sys_regs.c arm64: KVM: Hide unsupported AArch64 CPU features from guests 2017-11-03 15:24:12 +00:00
sys_regs.h Merge remote-tracking branch 'rutland/kvm/common-sysreg' into next-fix 2017-04-09 07:50:34 -07:00
sys_regs_generic_v8.c KVM: arm64: Use common sysreg definitions 2017-03-22 18:38:26 +00:00
trace.h tracing: Add TRACE_DEFINE_SIZEOF() macros 2017-06-13 17:11:08 -04:00
vgic-sys-reg-v3.c KVM: arm/arm64: Extract GICv3 max APRn index calculation 2017-09-05 17:33:39 +02:00