Re: [PATCH v3 0/5] ARM: arm64: Add SMCCC TRNG entropy service

2020-11-13 Thread André Przywara
On 13/11/2020 23:05, Ard Biesheuvel wrote: > On Fri, 13 Nov 2020 at 19:24, Andre Przywara wrote: >> >> Hi, >> >> an update to v2 with some fixes and a few tweaks. Ard's patch [1] should >> significantly reduce the frequency of arch_get_random_seed_long() calls, >> not sure if that is enough the

Re: [PATCH v3 0/5] ARM: arm64: Add SMCCC TRNG entropy service

2020-11-13 Thread Ard Biesheuvel
On Fri, 13 Nov 2020 at 19:24, Andre Przywara wrote: > > Hi, > > an update to v2 with some fixes and a few tweaks. Ard's patch [1] should > significantly reduce the frequency of arch_get_random_seed_long() calls, > not sure if that is enough the appease the concerns about the > potentially long

[PATCH 0/8] KVM: arm64: Disabled PMU handling

2020-11-13 Thread Marc Zyngier
It recently dawned on me that the way we handle PMU traps when the PMU is disabled is plain wrong. We consider that handling the registers as RAZ/WI is a fine thing to do, while the ARMv8 ARM is pretty clear that that's not OK and that such registers should UNDEF when FEAT_PMUv3 doesn't exist. I

[PATCH 4/8] KVM: arm64: Inject UNDEF on PMU access when no PMU configured

2020-11-13 Thread Marc Zyngier
The ARMv8 architecture says that in the absence of FEAT_PMUv3, all the PMU-related register generate an UNDEF. Let's make sure that all our PMU handers catch this case by hooking into check_pmu_access_disabled(), and add checks in a couple of other places. Note that we still cannot deliver an

[PATCH 8/8] KVM: arm64: Get rid of the PMU ready state

2020-11-13 Thread Marc Zyngier
The PMU ready state has no user left. Goodbye. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/pmu-emul.c | 1 - include/kvm/arm_pmu.h | 3 --- 2 files changed, 4 deletions(-) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 8806fdc85e8a..643cf819f3c0 100644 ---

[PATCH 5/8] KVM: arm64: Remove PMU RAZ/WI handling

2020-11-13 Thread Marc Zyngier
There is no RAZ/WI handling allowed for the PMU registers in the ARMv8 architecture. Nobody can remember how we cam to the conclusion that we could do this, but the ARMv8 ARM is pretty clear that we cannot. Remove the RAZ/WI handling of the PMU system registers when it is not configured.

[PATCH 3/8] KVM: arm64: Refuse illegal KVM_ARM_VCPU_PMU_V3 at reset time

2020-11-13 Thread Marc Zyngier
We accept to configure a PMU when a vcpu is created, even if the HW (or the host) doesn't support it. This results in failures when attributes get set, which is a bit odd as we should have failed the vcpu creation the first place. Move the check to the point where we check the vcpu feature set,

[PATCH 7/8] KVM: arm64: Gate kvm_pmu_update_state() on the PMU feature

2020-11-13 Thread Marc Zyngier
We currently gate the update of the PMU state on the PMU being "ready". The "ready" state is only set to true when the first vcpu run is successful, and if it isn't, we never reach the update code. So the "ready" state is never the right thing to check for, and it should instead be the presence

[PATCH 2/8] KVM: arm64: Set ID_AA64DFR0_EL1.PMUVer to 0 when no PMU support

2020-11-13 Thread Marc Zyngier
We always expose the HW view of PMU in ID_AA64FDR0_EL1.PMUver, even when the PMU feature is disabled, while the architecture says that FEAT_PMUv3 not being implemented should result in this field being zero. Let's follow the architecture's guidance. Signed-off-by: Marc Zyngier ---

[PATCH 6/8] KVM: arm64: Remove dead PMU sysreg decoding code

2020-11-13 Thread Marc Zyngier
The handling of traps in access_pmu_evcntr() has a couple of omminous "else return false;" statements that don't make any sense: the decoding tree coverse all the registers that trap to this handler, and returning false implies that we change PC, which we don't. Get rid of what is evidently dead

[PATCH 1/8] KVM: arm64: Add kvm_vcpu_has_pmu() helper

2020-11-13 Thread Marc Zyngier
There are a number of places where we check for the KVM_ARM_VCPU_PMU_V3 feature. Wrap this check into a new kvm_vcpu_has_pmu(), and use it at the existing locations. No functional change. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/kvm/pmu-emul.c

[PATCH v3 2/5] firmware: smccc: Introduce SMCCC TRNG framework

2020-11-13 Thread Andre Przywara
The ARM DEN0098 document describe an SMCCC based firmware service to deliver hardware generated random numbers. Its existence is advertised according to the SMCCC v1.1 specification. Add a (dummy) call to probe functions implemented in each architecture (ARM and arm64), to determine the existence

[PATCH v3 0/5] ARM: arm64: Add SMCCC TRNG entropy service

2020-11-13 Thread Andre Przywara
Hi, an update to v2 with some fixes and a few tweaks. Ard's patch [1] should significantly reduce the frequency of arch_get_random_seed_long() calls, not sure if that is enough the appease the concerns about the potentially long latency of SMC calls. I also dropped the direct arch_get_random()

[PATCH v3 5/5] KVM: arm64: implement the TRNG hypervisor call

2020-11-13 Thread Andre Przywara
From: Ard Biesheuvel Provide a hypervisor implementation of the ARM architected TRNG firmware interface described in ARM spec DEN0098. All function IDs are implemented, including both 32-bit and 64-bit versions of the TRNG_RND service, which is the centerpiece of the API. The API is backed by

[PATCH v3 3/5] ARM: implement support for SMCCC TRNG entropy source

2020-11-13 Thread Andre Przywara
From: Ard Biesheuvel Implement arch_get_random_seed_*() for ARM based on the firmware or hypervisor provided entropy source described in ARM DEN0098. This will make the kernel's random number generator consume entropy provided by this interface, at early boot, and periodically at runtime when

[PATCH v3 1/5] firmware: smccc: Add SMCCC TRNG function call IDs

2020-11-13 Thread Andre Przywara
From: Ard Biesheuvel The ARM architected TRNG firmware interface, described in ARM spec DEN0098, define an ARM SMCCC based interface to a true random number generator, provided by firmware. Add the definitions of the SMCCC functions as defined by the spec. Signed-off-by: Ard Biesheuvel

[PATCH v3 4/5] arm64: Add support for SMCCC TRNG entropy source

2020-11-13 Thread Andre Przywara
The ARM architected TRNG firmware interface, described in ARM spec DEN0098, defines an ARM SMCCC based interface to a true random number generator, provided by firmware. This can be discovered via the SMCCC >=v1.1 interface, and provides up to 192 bits of entropy per call. Hook this SMC call into

Re: [PATCH v10 04/11] vfio/pci: Add VFIO_REGION_TYPE_NESTED region type

2020-11-13 Thread Auger Eric
Hi Zenghui, On 9/24/20 10:23 AM, Zenghui Yu wrote: > Hi Eric, > > On 2020/3/21 0:19, Eric Auger wrote: >> Add a new specific DMA_FAULT region aiming to exposed nested mode >> translation faults. >> >> The region has a ring buffer that contains the actual fault >> records plus a header allowing to

Re: [PATCH v10 05/11] vfio/pci: Register an iommu fault handler

2020-11-13 Thread Auger Eric
Hi Zenghui, On 9/24/20 10:49 AM, Zenghui Yu wrote: > Hi Eric, > > On 2020/3/21 0:19, Eric Auger wrote: >> Register an IOMMU fault handler which records faults in >> the DMA FAULT region ring buffer. In a subsequent patch, we >> will add the signaling of a specific eventfd to allow the >>

[PATCH 0/2] KVM: arm64: vgic: Fix handling of userspace register accesses

2020-11-13 Thread Zenghui Yu
We had recently seen a kernel panic when accidently programming QEMU in an inappropriate way (in short, accessing RD registers before setting the RD base address. See patch #1 for details). And it looks like we're missing some basic checking when handling userspace register access. I've only

[PATCH 2/2] KVM: arm64: vgic: Forbid invalid userspace Distributor accesses

2020-11-13 Thread Zenghui Yu
Accessing registers in the Distributor before setting its base address should be treated as an invalid userspece behaviour. But KVM implicitly allows it as we handle the access anyway, regardless of whether the base address is set or not. Fix this issue by informing userspace what had gone wrong

[PATCH 1/2] KVM: arm64: vgic: Forbid invalid userspace Redistributor accesses

2020-11-13 Thread Zenghui Yu
It's expected that users will access registers in the redistributor *if* the RD has been initialized properly. Unfortunately userspace can be bogus enough to access registers before setting the RD base address, and KVM implicitly allows it (we handle the access anyway, regardless of whether the

Re: [PATCH v3 07/10] KVM: arm64: Allocate hyp vectors statically

2020-11-13 Thread Will Deacon
On Fri, Nov 13, 2020 at 12:02:10PM +, Marc Zyngier wrote: > On 2020-11-13 11:38, Will Deacon wrote: > > The EL2 vectors installed when a guest is running point at one of the > > following configurations for a given CPU: > > > > - Straight at __kvm_hyp_vector > > - A trampoline containing

Re: [PATCH v3 07/10] KVM: arm64: Allocate hyp vectors statically

2020-11-13 Thread Marc Zyngier
On 2020-11-13 11:38, Will Deacon wrote: The EL2 vectors installed when a guest is running point at one of the following configurations for a given CPU: - Straight at __kvm_hyp_vector - A trampoline containing an SMC sequence to mitigate Spectre-v2 and then a direct branch to

[PATCH v3 10/10] KVM: arm64: Remove redundant hyp vectors entry

2020-11-13 Thread Will Deacon
The hyp vectors entry corresponding to HYP_VECTOR_DIRECT (i.e. when neither Spectre-v2 nor Spectre-v3a are present) is unused, as we can simply dispatch straight to __kvm_hyp_vector in this case. Remove the redundant vector, and massage the logic for resolving a slot to a vectors entry.

[PATCH v3 08/10] arm64: spectre: Rename ARM64_HARDEN_EL2_VECTORS to ARM64_SPECTRE_V3A

2020-11-13 Thread Will Deacon
Since ARM64_HARDEN_EL2_VECTORS is really a mitigation for Spectre-v3a, rename it accordingly for consistency with the v2 and v4 mitigation. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- Documentation/arm64/memory.rst | 2 +- arch/arm64/include/asm/cpucaps.h | 2 +-

[PATCH v3 06/10] KVM: arm64: Re-jig logic when patching hardened hyp vectors

2020-11-13 Thread Will Deacon
The hardened hyp vectors are not used on systems running with VHE or CPUs without the ARM64_HARDEN_EL2_VECTORS capability. Re-jig the checking logic slightly in kvm_patch_vector_branch() so that it's a bit clearer what we're looking for. This is purely cosmetic. Cc: Marc Zyngier Cc: Quentin

[PATCH v3 07/10] KVM: arm64: Allocate hyp vectors statically

2020-11-13 Thread Will Deacon
The EL2 vectors installed when a guest is running point at one of the following configurations for a given CPU: - Straight at __kvm_hyp_vector - A trampoline containing an SMC sequence to mitigate Spectre-v2 and then a direct branch to __kvm_hyp_vector - A dynamically-allocated

[PATCH v3 00/10] Rework hyp vector handling

2020-11-13 Thread Will Deacon
Hi all, This is version three of the patches I previously posted here: v1: https://lore.kernel.org/r/20201026155833.24847-1-w...@kernel.org v2: https://lore.kernel.org/r/20201109214726.15276-1-w...@kernel.org Changes since v3 include: * Fix vector initialisation for VHE systems *

[PATCH v3 03/10] KVM: arm64: Move kvm_get_hyp_vector() out of header file

2020-11-13 Thread Will Deacon
kvm_get_hyp_vector() has only one caller, so move it out of kvm_mmu.h and inline it into a new function, cpu_set_hyp_vector(), for setting the vector. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_mmu.h | 43 -

[PATCH v3 09/10] arm64: spectre: Consolidate spectre-v3a detection

2020-11-13 Thread Will Deacon
The spectre-v3a mitigation is split between cpu_errata.c and spectre.c, with the former handling detection of the problem and the latter handling enabling of the workaround. Move the detection logic alongside the enabling logic, like we do for the other spectre mitigations. Cc: Marc Zyngier Cc:

[PATCH v3 01/10] KVM: arm64: Remove redundant Spectre-v2 code from kvm_map_vector()

2020-11-13 Thread Will Deacon
'__kvm_bp_vect_base' is only used when dealing with the hardened vectors so remove the redundant assignments in kvm_map_vectors(). Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/arm.c | 5 - 1 file changed, 5 deletions(-) diff --git

[PATCH v3 02/10] KVM: arm64: Tidy up kvm_map_vector()

2020-11-13 Thread Will Deacon
The bulk of the work in kvm_map_vector() is conditional on the ARM64_HARDEN_EL2_VECTORS capability, so return early if that is not set and make the code a bit easier to read. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/arm.c | 28

[PATCH v3 04/10] KVM: arm64: Make BP hardening globals static instead

2020-11-13 Thread Will Deacon
Branch predictor hardening of the hyp vectors is partially driven by a couple of global variables ('__kvm_bp_vect_base' and '__kvm_harden_el2_vector_slot'). However, these are only used within a single compilation unit, so internalise them there instead. Cc: Marc Zyngier Cc: Quentin Perret

[PATCH v3 05/10] KVM: arm64: Move BP hardening helpers into spectre.h

2020-11-13 Thread Will Deacon
The BP hardening helpers are an integral part of the Spectre-v2 mitigation, so move them into asm/spectre.h and inline the arm64_get_bp_hardening_data() function at the same time. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/mmu.h | 29

Re: [PATCH 0/3] KVM/arm64 fixes for 5.10, take #3

2020-11-13 Thread Paolo Bonzini
On 12/11/20 23:21, Marc Zyngier wrote: We now expose ID_AA64PFR0_EL1.CSV2=1 to guests running on hosts that are immune to Spectre-v2, but that don't have this field set, most likely because they predate the specification. However, this prevents the migration of guests that have started on a