Re: [PATCH 2/2] KVM: arm64: Workaround firmware wrongly advertising GICv2-on-v3 compatibility

2021-01-08 Thread Ard Biesheuvel
On Fri, 8 Jan 2021 at 19:13, Marc Zyngier wrote: > > On 2021-01-08 17:59, Ard Biesheuvel wrote: > > On Fri, 8 Jan 2021 at 18:12, Marc Zyngier wrote: > >> > >> It looks like we have broken firmware out there that wrongly > >> advertises > >> a GICv2 compatibility interface, despite the CPUs not

Re: [PATCH 2/2] KVM: arm64: Workaround firmware wrongly advertising GICv2-on-v3 compatibility

2021-01-08 Thread Marc Zyngier
On 2021-01-08 17:59, Ard Biesheuvel wrote: On Fri, 8 Jan 2021 at 18:12, Marc Zyngier wrote: It looks like we have broken firmware out there that wrongly advertises a GICv2 compatibility interface, despite the CPUs not being able to deal with it. To work around this, check that the CPU

Re: [PATCH 2/2] KVM: arm64: Workaround firmware wrongly advertising GICv2-on-v3 compatibility

2021-01-08 Thread Ard Biesheuvel
On Fri, 8 Jan 2021 at 18:12, Marc Zyngier wrote: > > It looks like we have broken firmware out there that wrongly advertises > a GICv2 compatibility interface, despite the CPUs not being able to deal > with it. > > To work around this, check that the CPU initialising KVM is actually able > to

[PATCH 0/2] KVM: arm64: Work around firmware wongly advertising GICv2 compatibility

2021-01-08 Thread Marc Zyngier
It appears that there is firmware out there that advertise GICv2 compatibility on GICv3, despite the CPUs not being able to actually do it. That's a bummer, and at best creates unexpected behaviours for the users. At worse, it will crash the machine. Awesome! In order to mitigate this issue, try

[PATCH 2/2] KVM: arm64: Workaround firmware wrongly advertising GICv2-on-v3 compatibility

2021-01-08 Thread Marc Zyngier
It looks like we have broken firmware out there that wrongly advertises a GICv2 compatibility interface, despite the CPUs not being able to deal with it. To work around this, check that the CPU initialising KVM is actually able to switch to MMIO instead of system registers, and use that as a

[PATCH 1/2] KVM: arm64: Rename __vgic_v3_get_ich_vtr_el2() to __vgic_v3_get_gic_config()

2021-01-08 Thread Marc Zyngier
As we are about to report a bit more information to the rest of the kernel, rename __vgic_v3_get_ich_vtr_el2() to the more explicit __vgic_v3_get_gic_config(). No functional change. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_asm.h | 4 ++-- arch/arm64/kvm/hyp/nvhe/hyp-main.c

RE: [PATCH v13 00/15] SMMUv3 Nested Stage Setup (IOMMU part)

2021-01-08 Thread Shameerali Kolothum Thodi
Hi Eric, > -Original Message- > From: Eric Auger [mailto:eric.au...@redhat.com] > Sent: 18 November 2020 11:22 > 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] KVM: arm64: Compute TPIDR_EL2 ignoring MTE tag

2021-01-08 Thread Steven Price
On 08/01/2021 16:51, Marc Zyngier wrote: Hi Steven, On 2021-01-08 16:12, Steven Price wrote: KASAN in HW_TAGS mode will store MTE tags in the top byte of the pointer. When computing the offset for TPIDR_EL2 we don't want anything in the top byte, so remove the tag to ensure the computation is

Re: [PATCH] KVM: arm64: Compute TPIDR_EL2 ignoring MTE tag

2021-01-08 Thread Marc Zyngier
Hi Steven, On 2021-01-08 16:12, Steven Price wrote: KASAN in HW_TAGS mode will store MTE tags in the top byte of the pointer. When computing the offset for TPIDR_EL2 we don't want anything in the top byte, so remove the tag to ensure the computation is correct no matter what the tag. Fixes:

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

2021-01-08 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 v2 26/26] KVM: arm64: Wrap the host with a stage 2

2021-01-08 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 v2 22/26] KVM: arm64: Refactor __load_guest_stage2()

2021-01-08 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 v2 23/26] KVM: arm64: Refactor __populate_fault_info()

2021-01-08 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 v2 21/26] KVM: arm64: Refactor kvm_arm_setup_stage2()

2021-01-08 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 v2 24/26] KVM: arm64: Make memcache anonymous in pgtable allocator

2021-01-08 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 v2 18/26] KVM: arm64: Use kvm_arch for stage 2 pgtable

2021-01-08 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 v2 10/26] KVM: arm64: Introduce an early Hyp page allocator

2021-01-08 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 v2 03/26] arm64: kvm: Add standalone ticket spinlock implementation for use at hyp

2021-01-08 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 relies on the kernel's "percpu" implementation for the MCS nodes. Implement a simple ticket locking scheme based heavily on the

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

2021-01-08 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 v2 01/26] arm64: lib: Annotate {clear, copy}_page() as position-independent

2021-01-08 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 Signed-off-by: Quentin Perret --- arch/arm64/lib/clear_page.S | 4 ++-- arch/arm64/lib/copy_page.S | 4 ++-- 2

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

2021-01-08 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 v2 14/26] KVM: arm64: Factor out vector address calculation

2021-01-08 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 v2 13/26] KVM: arm64: Enable access to sanitized CPU features at EL2

2021-01-08 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 v2 17/26] KVM: arm64: Elevate Hyp mappings creation at EL2

2021-01-08 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 v2 12/26] KVM: arm64: Introduce a Hyp buddy page allocator

2021-01-08 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 v2 16/26] KVM: arm64: Prepare Hyp memory protection

2021-01-08 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 v2 08/26] KVM: arm64: Make kvm_call_hyp() a function call at Hyp

2021-01-08 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 v2 07/26] KVM: arm64: Introduce a BSS section for use at Hyp

2021-01-08 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 v2 09/26] KVM: arm64: Allow using kvm_nvhe_sym() in hyp code

2021-01-08 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 1 file changed, 4 insertions(+)

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

2021-01-08 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 v2 15/26] of/fdt: Introduce early_init_dt_add_memory_hyp()

2021-01-08 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 v2 06/26] KVM: arm64: Factor memory allocation out of pgtable.c

2021-01-08 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 v2 05/26] KVM: arm64: Avoid free_page() in page-table allocator

2021-01-08 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 v2 20/26] KVM: arm64: Set host stage 2 using kvm_nvhe_init_params

2021-01-08 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 v2 00/26] KVM/arm64: A stage 2 for the host

2021-01-08 Thread Quentin Perret
Hi all, This is the v2 of the series previously posted here: https://lore.kernel.org/kvmarm/20201117181607.1761516-1-qper...@google.com/ This basically allows us to wrap the host with a stage 2 when running in nVHE, hence paving the way for protecting guest memory from the host in the future

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

2021-01-08 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 +-

[PATCH] KVM: arm64: Compute TPIDR_EL2 ignoring MTE tag

2021-01-08 Thread Steven Price
KASAN in HW_TAGS mode will store MTE tags in the top byte of the pointer. When computing the offset for TPIDR_EL2 we don't want anything in the top byte, so remove the tag to ensure the computation is correct no matter what the tag. Fixes: 94ab5b61ee16 ("kasan, arm64: enable

RE: [PATCH v11 12/13] vfio/pci: Register a DMA fault response region

2021-01-08 Thread Shameerali Kolothum Thodi
Hi Eric, > -Original Message- > From: Eric Auger [mailto:eric.au...@redhat.com] > Sent: 16 November 2020 11:00 > 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: [GIT PULL] KVM/arm64 fixes for 5.11, take #1

2021-01-08 Thread Paolo Bonzini
On 08/01/21 09:22, Marc Zyngier wrote:    git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-fixes-5.11-1 Looks like there are issues with the upstream changes brought in by this pull request.  Unless my bisection is quick tomorrow it may not make it into 5.11-rc3. 

Re: [GIT PULL] KVM/arm64 fixes for 5.11, take #1

2021-01-08 Thread Marc Zyngier
Hi Paolo, On 2021-01-07 23:09, Paolo Bonzini wrote: On 07/01/21 12:20, Marc Zyngier wrote: git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-fixes-5.11-1 Looks like there are issues with the upstream changes brought in by this pull request. Unless my bisection