[RFC PATCH 24/27] KVM: arm64: Make memcache anonymous in pgtable allocator

2020-11-17 Thread Quentin Perret
The current stage2 page-table allocator uses a memcache to get pre-allocated pages when it needs any. To allow re-using this code at EL2 which uses a concept of memory pools, make the memcache argument to kvm_pgtable_stage2_map() anonymous. and let the mm_ops zalloc_page() callbacks use it the way

[RFC PATCH 22/27] KVM: arm64: Refactor __load_guest_stage2()

2020-11-17 Thread Quentin Perret
Refactor __load_guest_stage2() to introduce __load_stage2() which will be re-used when loading the host stage 2. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_mmu.h | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_mmu.h

[RFC PATCH 25/27] KVM: arm64: Reserve memory for host stage 2

2020-11-17 Thread Quentin Perret
Extend the memory pool allocated for the hypervisor to include enough pages to map all of memory at page granularity for the host stage 2. While at it, also reserve some memory for device mappings. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/mm.h | 36

[RFC PATCH 19/27] KVM: arm64: Use kvm_arch in kvm_s2_mmu

2020-11-17 Thread Quentin Perret
In order to make use of the stage 2 pgtable code for the host stage 2, change kvm_s2_mmu to use a kvm_arch pointer in lieu of the kvm pointer, as the host will have the former but not the latter. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_host.h | 2 +-

[RFC PATCH 21/27] KVM: arm64: Refactor kvm_arm_setup_stage2()

2020-11-17 Thread Quentin Perret
In order to re-use some of the stage 2 setup at EL2, factor parts of kvm_arm_setup_stage2() out into static inline functions. No functional change intended. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_mmu.h | 48 arch/arm64/kvm/reset.c

[RFC PATCH 23/27] KVM: arm64: Refactor __populate_fault_info()

2020-11-17 Thread Quentin Perret
Refactor __populate_fault_info() to introduce __get_fault_info() which will be used once the host is wrapped in a stage 2. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/hyp/switch.h | 36 +++-- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git

[RFC PATCH 26/27] KVM: arm64: Sort the memblock regions list

2020-11-17 Thread Quentin Perret
The hypervisor will need the list of memblock regions sorted by increasing start address to make look-ups more efficient. Make the host do the hard work early while it is still trusted to avoid the need for a sorting library at EL2. Signed-off-by: Quentin Perret ---

[RFC PATCH 27/27] KVM: arm64: Wrap the host with a stage 2

2020-11-17 Thread Quentin Perret
When KVM runs in protected nVHE mode, make use of a stage 2 page-table to give the hypervisor some control over the host memory accesses. At the moment all memory aborts from the host will be instantly idmapped RWX at stage 2 in a lazy fashion. Later patches will make use of that infrastructure to

[RFC PATCH 15/27] of/fdt: Introduce early_init_dt_add_memory_hyp()

2020-11-17 Thread Quentin Perret
Introduce early_init_dt_add_memory_hyp() to allow KVM to conserve a copy of the memory regions parsed from DT. This will be needed in the context of the protected nVHE feature of KVM/arm64 where the code running at EL2 will be cleanly separated from the host kernel during boot, and will need its

[RFC PATCH 18/27] KVM: arm64: Use kvm_arch for stage 2 pgtable

2020-11-17 Thread Quentin Perret
In order to make use of the stage 2 pgtable code for the host stage 2, use struct kvm_arch in lieu of struct kvm as the host will have the former but not the latter. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_pgtable.h | 5 +++-- arch/arm64/kvm/hyp/pgtable.c | 6 +++---

[RFC PATCH 20/27] KVM: arm64: Set host stage 2 using kvm_nvhe_init_params

2020-11-17 Thread Quentin Perret
Move the registers relevant to host stage 2 enablement to kvm_nvhe_init_params to prepare the ground for enabling it in later patches. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_asm.h | 3 +++ arch/arm64/kernel/asm-offsets.c| 3 +++ arch/arm64/kvm/arm.c | 5

[RFC PATCH 16/27] KVM: arm64: Prepare Hyp memory protection

2020-11-17 Thread Quentin Perret
When memory protection is enabled, the Hyp code needs the ability to create and manage its own page-table. To do so, introduce a new set of hypercalls to initialize Hyp memory protection. During the init hcall, the hypervisor runs with the host-provided page-table and uses the trivial early page

[RFC PATCH 12/27] KVM: arm64: Introduce a Hyp buddy page allocator

2020-11-17 Thread Quentin Perret
When memory protection is enabled, the hyp code will require a basic form of memory management in order to allocate and free memory pages at EL2. This is needed for various use-cases, including the creation of hyp mappings or the allocation of stage 2 page tables. To address these use-case,

[RFC PATCH 13/27] KVM: arm64: Enable access to sanitized CPU features at EL2

2020-11-17 Thread Quentin Perret
Introduce the infrastructure in KVM enabling to copy CPU feature registers into EL2-owned data-structures, to allow reading sanitised values directly at EL2 in nVHE. Given that only a subset of these features are being read by the hypervisor, the ones that need to be copied are to be listed under

[RFC PATCH 00/27] KVM/arm64: A stage 2 for the host

2020-11-17 Thread Quentin Perret
Hi all, This RFC series provides the infrastructure enabling to wrap the host kernel with a stage 2 when running KVM in nVHE. This can be useful for several use-cases, but the primary motivation is to (eventually) be able to protect guest memory from the host kernel. More details about the

[RFC PATCH 08/27] KVM: arm64: Make kvm_call_hyp() a function call at Hyp

2020-11-17 Thread Quentin Perret
kvm_call_hyp() has some logic to issue a function call or a hypercall depending the EL at which the kernel is running. However, all the code compiled under __KVM_NVHE_HYPERVISOR__ is guaranteed to run only at EL2, and in this case a simple function call is needed. Add ifdefery to kvm_host.h to

[RFC PATCH 02/27] KVM: arm64: Link position-independent string routines into .hyp.text

2020-11-17 Thread Quentin Perret
From: Will Deacon Pull clear_page(), copy_page(), memcpy() and memset() into the nVHE hyp code and ensure that we always execute the '__pi_' entry point on the offchance that it changes in future. [ qperret: Commit title nits ] Signed-off-by: Will Deacon Signed-off-by: Quentin Perret ---

[RFC PATCH 10/27] KVM: arm64: Introduce an early Hyp page allocator

2020-11-17 Thread Quentin Perret
With nVHE, the host currently creates all s1 hypervisor mappings at EL1 during boot, installs them at EL2, and extends them as required (e.g. when creating a new VM). But in a world where the host is no longer trusted, it cannot have full control over the code mapped in the hypervisor. In

[RFC PATCH 17/27] KVM: arm64: Elevate Hyp mappings creation at EL2

2020-11-17 Thread Quentin Perret
Previous commits have introduced infrastructure at EL2 to enable the Hyp code to manage its own memory, and more specifically its stage 1 page tables. However, this was preliminary work, and none of it is currently in use. Put all of this together by elevating the hyp mappings creation at EL2

[RFC PATCH 14/27] KVM: arm64: Factor out vector address calculation

2020-11-17 Thread Quentin Perret
In order to re-map the guest vectors at EL2 when pKVM is enabled, refactor __kvm_vector_slot2idx() and kvm_init_vector_slot() to move all the address calculation logic in a static inline function. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_mmu.h | 8

[RFC PATCH 07/27] KVM: arm64: Introduce a BSS section for use at Hyp

2020-11-17 Thread Quentin Perret
Currently, the hyp code cannot make full use of a bss, as the kernel section is mapped read-only. While this mapping could simply be changed to read-write, it would intermingle even more the hyp and kernel state than they currently are. Instead, introduce a __hyp_bss section, that uses reserved

[RFC PATCH 11/27] KVM: arm64: Stub CONFIG_DEBUG_LIST at Hyp

2020-11-17 Thread Quentin Perret
In order to use the kernel list library at EL2, introduce stubs for the CONFIG_DEBUG_LIST out-of-lines calls. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/stub.c | 22 ++ 2 files changed, 23 insertions(+), 1

[RFC PATCH 09/27] KVM: arm64: Allow using kvm_nvhe_sym() in hyp code

2020-11-17 Thread Quentin Perret
In order to allow the usage of code shared by the host and the hyp in static inline library function, allow the usage of kvm_nvhe_sym() at el2 by defaulting to the raw symbol name. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/hyp_image.h | 4 arch/arm64/include/asm/kvm_asm.h

[RFC PATCH 06/27] KVM: arm64: Factor memory allocation out of pgtable.c

2020-11-17 Thread Quentin Perret
In preparation for enabling the creation of page-tables at EL2, factor all memory allocation out of the page-table code, hence making it re-usable with any compatible memory allocator. No functional changes intended. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_pgtable.h | 32

[RFC PATCH 03/27] KVM: arm64: Add standalone ticket spinlock implementation for use at hyp

2020-11-17 Thread Quentin Perret
From: Will Deacon We will soon need to synchronise multiple CPUs in the hyp text at EL2. The qspinlock-based locking used by the host is overkill for this purpose and requires a working "percpu" implementation for the MCS nodes. Implement a simple ticket locking scheme based heavily on the code

[RFC PATCH 05/27] KVM: arm64: Avoid free_page() in page-table allocator

2020-11-17 Thread Quentin Perret
Currently, the KVM page-table allocator uses a mix of put_page() and free_page() calls depending on the context even though page-allocation is always achieved using variants of __get_free_page(). Make the code consitent by using put_page() throughout, and reduce the memory management API surface

[RFC PATCH 04/27] KVM: arm64: Initialize kvm_nvhe_init_params early

2020-11-17 Thread Quentin Perret
Move the initialization of kvm_nvhe_init_params in a dedicated function that is run early, and only once during KVM init, rather than every time the KVM vectors are set and reset. This also opens the opportunity for the hypervisor to change the init structs during boot, hence simplifying the

[RFC PATCH 01/27] arm64: lib: Annotate {clear, copy}_page() as position-independent

2020-11-17 Thread Quentin Perret
From: Will Deacon clear_page() and copy_page() are suitable for use outside of the kernel address space, so annotate them as position-independent code. Signed-off-by: Will Deacon --- arch/arm64/lib/clear_page.S | 4 ++-- arch/arm64/lib/copy_page.S | 4 ++-- 2 files changed, 4 insertions(+),

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

2020-11-17 Thread Linus Walleij
On Fri, Nov 13, 2020 at 7:24 PM Andre Przywara wrote: > 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

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

2020-11-17 Thread Linus Walleij
On Fri, Nov 13, 2020 at 7:24 PM Andre Przywara wrote: > 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

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

2020-11-17 Thread Linus Walleij
On Fri, Nov 13, 2020 at 7:24 PM Andre Przywara wrote: > 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

Re: [PATCH v4 2/2] arm64: kvm: Introduce MTE VCPU feature

2020-11-17 Thread Marc Zyngier
Hi Steven, On 2020-10-26 15:57, Steven Price wrote: Add a new VM feature 'KVM_ARM_CAP_MTE' which enables memory tagging for a VM. This exposes the feature to the guest and automatically tags memory pages touched by the VM as PG_mte_tagged (and clears the tags storage) to ensure that the guest

Re: [PATCH v4 1/2] arm64: kvm: Save/restore MTE registers

2020-11-17 Thread Marc Zyngier
Hi Steven, These patches unfortunately don't apply to -rc4 anymore, as we repainted quite a bit while working on fixes. I'd be grateful if you could rebase them. A few other things though: On 2020-10-26 15:57, Steven Price wrote: Define the new system registers that MTE introduces and

Re: [PATCH] KVM: arm64: vgic-v3: Drop the reporting of GICR_TYPER.Last for userspace

2020-11-17 Thread Marc Zyngier
On Tue, 17 Nov 2020 23:16:29 +0800, Zenghui Yu wrote: > It was recently reported that if GICR_TYPER is accessed before the RD base > address is set, we'll suffer from the unset @rdreg dereferencing. Oops... > > gpa_t last_rdist_typer = rdreg->base + GICR_TYPER + >

Re: [PATCH] KVM: arm64: vgic-v3: Drop the reporting of GICR_TYPER.Last for userspace

2020-11-17 Thread Auger Eric
Hi Zenghui, On 11/17/20 4:16 PM, Zenghui Yu wrote: > It was recently reported that if GICR_TYPER is accessed before the RD base > address is set, we'll suffer from the unset @rdreg dereferencing. Oops... > > gpa_t last_rdist_typer = rdreg->base + GICR_TYPER + >

Re: [PATCH v4 2/2] arm64: kvm: Introduce MTE VCPU feature

2020-11-17 Thread Catalin Marinas
Hi Steven, On Mon, Oct 26, 2020 at 03:57:27PM +, Steven Price wrote: > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 19aacc7d64de..38fe25310ca1 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -862,6 +862,26 @@ static int user_mem_abort(struct kvm_vcpu

[PATCH] KVM: arm64: vgic-v3: Drop the reporting of GICR_TYPER.Last for userspace

2020-11-17 Thread Zenghui Yu
It was recently reported that if GICR_TYPER is accessed before the RD base address is set, we'll suffer from the unset @rdreg dereferencing. Oops... gpa_t last_rdist_typer = rdreg->base + GICR_TYPER + (rdreg->free_index - 1) * KVM_VGIC_V3_REDIST_SIZE; It's

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

2020-11-17 Thread Zenghui Yu
On 2020/11/17 16:49, Marc Zyngier wrote: Hi Zenghui, On 2020-11-16 14:57, Zenghui Yu wrote: Hi Marc, On 2020/11/16 22:10, Marc Zyngier wrote: My take is that only if the "[Re]Distributor base address" is specified in the system memory map, will the user-provided kvm_device_attr.offset make

Re: [PATCH v12 04/15] iommu/smmuv3: Dynamically allocate s1_cfg and s2_cfg

2020-11-17 Thread Auger Eric
Hi Shameer, On 11/17/20 12:39 PM, Shameerali Kolothum Thodi wrote: > Hi Eric, > >> -Original Message- >> From: Eric Auger [mailto:eric.au...@redhat.com] >> Sent: 16 November 2020 10:43 >> To: eric.auger@gmail.com; eric.au...@redhat.com; >> io...@lists.linux-foundation.org;

RE: [PATCH v12 04/15] iommu/smmuv3: Dynamically allocate s1_cfg and s2_cfg

2020-11-17 Thread Shameerali Kolothum Thodi
Hi Eric, > -Original Message- > From: Eric Auger [mailto:eric.au...@redhat.com] > Sent: 16 November 2020 10:43 > To: eric.auger@gmail.com; eric.au...@redhat.com; > io...@lists.linux-foundation.org; linux-ker...@vger.kernel.org; > k...@vger.kernel.org; kvmarm@lists.cs.columbia.edu;

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

2020-11-17 Thread Marc Zyngier
On 2020-11-17 09:59, Auger Eric wrote: Hi Marc, On 11/17/20 9:49 AM, Marc Zyngier wrote: Hi Zenghui, On 2020-11-16 14:57, Zenghui Yu wrote: Hi Marc, On 2020/11/16 22:10, Marc Zyngier wrote: My take is that only if the "[Re]Distributor base address" is specified in the system memory map,

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

2020-11-17 Thread Auger Eric
Hi Marc, On 11/17/20 9:49 AM, Marc Zyngier wrote: > Hi Zenghui, > > On 2020-11-16 14:57, Zenghui Yu wrote: >> Hi Marc, >> >> On 2020/11/16 22:10, Marc Zyngier wrote: My take is that only if the "[Re]Distributor base address" is specified in the system memory map, will the user-provided

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

2020-11-17 Thread Auger Eric
Hi Zenghui, On 11/17/20 9:49 AM, Marc Zyngier wrote: > Hi Zenghui, > > On 2020-11-16 14:57, Zenghui Yu wrote: >> Hi Marc, >> >> On 2020/11/16 22:10, Marc Zyngier wrote: My take is that only if the "[Re]Distributor base address" is specified in the system memory map, will the

RE: [PATCH v11 00/13] SMMUv3 Nested Stage Setup (IOMMU part)

2020-11-17 Thread Shameerali Kolothum Thodi
Hi Eric, First, many thanks for the respin. I will go through all of these(iommu/vfio/Qemu) and will do a thorough verification/tests on our hardware. > -Original Message- > From: Auger Eric [mailto:eric.au...@redhat.com] > Sent: 17 November 2020 08:40 > To: Shameerali Kolothum Thodi ;

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

2020-11-17 Thread Marc Zyngier
Hi Zenghui, On 2020-11-16 14:57, Zenghui Yu wrote: Hi Marc, On 2020/11/16 22:10, Marc Zyngier wrote: My take is that only if the "[Re]Distributor base address" is specified in the system memory map, will the user-provided kvm_device_attr.offset make sense. And we can then handle the access

Re: [PATCH v11 00/13] SMMUv3 Nested Stage Setup (IOMMU part)

2020-11-17 Thread Auger Eric
Hi Shameer, On 5/13/20 5:57 PM, Shameerali Kolothum Thodi wrote: > Hi Eric, > >> -Original Message- >> From: Auger Eric [mailto:eric.au...@redhat.com] >> Sent: 13 May 2020 14:29 >> To: Shameerali Kolothum Thodi ; >> Zhangfei Gao ; eric.auger@gmail.com; >>