Re: [PATCH 00/12] KVM: arm64: FF-A proxy for pKVM

2022-12-02 Thread Will Deacon
On Wed, 16 Nov 2022 17:03:23 +, Quentin Perret wrote: > pKVM's primary goal is to protect guest pages from a compromised host by > enforcing access control restrictions using stage-2 page-tables. Sadly, > this cannot prevent TrustZone from accessing non-secure memory, and a > compromised host

Re: [PATCH 02/12] firmware: arm_ffa: Move comment before the field it is documenting

2022-12-01 Thread Will Deacon
On Thu, Dec 01, 2022 at 11:53:08AM +, Sudeep Holla wrote: > On Wed, Nov 16, 2022 at 05:03:25PM +, Quentin Perret wrote: > > From: Will Deacon > > > > This is consistent with the other comments in the struct. > > > Not sure how that happened :). Anyways,

Re: [PATCH v4 0/3] KVM: arm64: Fixes for parallel faults series

2022-11-21 Thread Will Deacon
; v4: > - Return an error instead of WARN() in hyp for shared walks (Will) For the series: Acked-by: Will Deacon Thanks! Will ___ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

Re: [PATCH v3 0/8] perf: Arm SPEv1.2 support

2022-11-18 Thread Will Deacon
On Thu, Nov 17, 2022 at 08:43:17AM -0600, Rob Herring wrote: > On Fri, Nov 4, 2022 at 10:55 AM Rob Herring wrote: > > > > This series adds support for Arm SPEv1.2 which is part of the > > Armv8.7/Armv9.2 architecture. There's 2 new features that affect the > > kernel: a new event filter bit,

Re: [PATCH v3 7/8] perf: Add perf_event_attr::config3

2022-11-18 Thread Will Deacon
On Fri, Nov 04, 2022 at 10:55:07AM -0500, Rob Herring wrote: > Arm SPEv1.2 adds another 64-bits of event filtering control. As the > existing perf_event_attr::configN fields are all used up for SPE PMU, an > additional field is needed. Add a new 'config3' field. > > Tested-by: James Clark >

Re: [RFC PATCH 2/3] KVM: arm64: Allow userspace to trap SMCCC sub-ranges

2022-11-18 Thread Will Deacon
Hey Oliver, On Thu, Nov 10, 2022 at 01:53:26AM +, Oliver Upton wrote: > As the SMCCC (and related specifications) march towards an > 'everything and the kitchen sink' interface for interacting with a > system, it is less likely that KVM will implement every supported > feature. > > Add a

Re: [PATCH v3 2/2] KVM: arm64: Don't acquire RCU read lock for exclusive table walks

2022-11-18 Thread Will Deacon
On Thu, Nov 17, 2022 at 06:23:23PM +, Oliver Upton wrote: > On Thu, Nov 17, 2022 at 05:49:52PM +, Will Deacon wrote: > > On Wed, Nov 16, 2022 at 04:56:55PM +, Oliver Upton wrote: > > [...] > > > > -static inline void kvm_pgtable_walk_begin(void) {

Re: [PATCH v3 2/2] KVM: arm64: Don't acquire RCU read lock for exclusive table walks

2022-11-17 Thread Will Deacon
On Wed, Nov 16, 2022 at 04:56:55PM +, Oliver Upton wrote: > Marek reported a BUG resulting from the recent parallel faults changes, > as the hyp stage-1 map walker attempted to allocate table memory while > holding the RCU read lock: > > BUG: sleeping function called from invalid context at

Re: [PATCH 1/1] KVM: arm64: Use a separate function for hyp stage-1 walks

2022-11-15 Thread Will Deacon
On Mon, Nov 14, 2022 at 08:11:27PM +, Oliver Upton wrote: > A subsequent change to the page table walkers adds RCU protection for > walking stage-2 page tables. KVM uses a global lock to serialize hyp > stage-1 walks, meaning RCU protection is quite meaningless for > protecting hyp stage-1

Re: [PATCH 2/2] KVM: arm64: Redefine pKVM memory transitions in terms of source/target

2022-11-10 Thread Will Deacon
On Fri, Oct 28, 2022 at 10:23:36AM +, Oliver Upton wrote: > On Fri, Oct 28, 2022 at 09:57:04AM +, Quentin Perret wrote: > > On Friday 28 Oct 2022 at 08:34:48 (+), Oliver Upton wrote: > > > Perhaps it is just me, but the 'initiator' and 'completer' terms are > > > slightly confusing

Re: [PATCH 1/2] KVM: arm64: Clean out the odd handling of completer_addr

2022-11-10 Thread Will Deacon
Hi Oliver, On Fri, Oct 28, 2022 at 08:34:47AM +, Oliver Upton wrote: > The layout of struct pkvm_mem_transition is a bit weird; the destination > address for the transition is actually stashed in the initiator address > context. Even weirder so, that address is thrown inside a union and >

Re: [PATCH] arm64: paravirt: remove conduit check in has_pv_steal_clock

2022-11-09 Thread Will Deacon
On Fri, 4 Nov 2022 06:16:59 +, Usama Arif wrote: > arm_smccc_1_1_invoke() which is called later on in the function > will return failure if there's no conduit (or pre-SMCCC 1.1), > hence the check is unnecessary. > > Applied to arm64 (for-next/trivial), thanks! [1/1] arm64: paravirt:

[RFC PATCH v3 25/25] KVM: arm64: Use the pKVM hyp vCPU structure in handle___kvm_vcpu_run()

2022-09-14 Thread Will Deacon
is initialised in protected mode. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 4 ++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 79 +- arch/arm64/kvm/hyp/nvhe/pkvm.c | 28 + 3 files changed, 109 insertions(+), 2 deletions(-) diff --git

[PATCH v3 24/25] KVM: arm64: Don't unnecessarily map host kernel sections at EL2

2022-09-14 Thread Will Deacon
-off-by: Will Deacon --- arch/arm64/kernel/image-vars.h | 6 -- arch/arm64/kvm/hyp/nvhe/setup.c | 14 +++--- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h index d20dc9d555af..b585bbd36d81 100644 --- a/arch

[PATCH v3 23/25] KVM: arm64: Explicitly map 'kvm_vgic_global_state' at EL2

2022-09-14 Thread Will Deacon
on mapping all of the host '.rodata' section. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/setup.c | 5 + 1 file changed, 5 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 0f69c1393416..5a371ab236db

[PATCH v3 22/25] KVM: arm64: Maintain a copy of 'kvm_arm_vmid_bits' at EL2

2022-09-14 Thread Will Deacon
of 'kvm_arm_vmid_bits' in the pKVM hypervisor and initialise it from the host value while it is still trusted. Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_hyp.h | 2 ++ arch/arm64/kernel/image-vars.h | 3 --- arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/hyp/nvhe/pkvm.c

[PATCH v3 21/25] KVM: arm64: Unmap 'kvm_arm_hyp_percpu_base' from the host

2022-09-14 Thread Will Deacon
this this into the nVHE code where it cannot be modified by the untrusted host at EL1. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_asm.h | 4 ++-- arch/arm64/kernel/image-vars.h| 3 --- arch/arm64/kvm/arm.c | 9 - arch/arm64/kvm/hyp

[PATCH v3 20/25] KVM: arm64: Return guest memory from EL2 via dedicated teardown memcache

2022-09-14 Thread Will Deacon
by the pKVM hypervisor at EL2. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_host.h | 7 + arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 +- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 17 ++ arch/arm64/kvm/hyp/nvhe/pkvm.c

[PATCH v3 19/25] KVM: arm64: Instantiate guest stage-2 page-tables at EL2

2022-09-14 Thread Will Deacon
Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 6 ++ arch/arm64/kvm/hyp/nvhe/mem_protect.c | 125 - arch/arm64/kvm/mmu.c | 4 +- 3 files changed, 132 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe

[PATCH v3 18/25] KVM: arm64: Consolidate stage-2 initialisation into a single function

2022-09-14 Thread Will Deacon
this code path by merging both functions into one, taking care to map the 'struct kvm' into the hypervisor stage-1 early on in order to simplify the failure path. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_arm.h | 2 +- arch/arm64/include/asm

[PATCH v3 17/25] KVM: arm64: Add generic hyp_memcache helpers

2022-09-14 Thread Will Deacon
Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_host.h | 57 +++ arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 + arch/arm64/kvm/hyp/nvhe/mm.c | 33 +++ arch/arm64/kvm/mmu.c | 26 + 4 files

[PATCH v3 16/25] KVM: arm64: Provide I-cache invalidation by virtual address at EL2

2022-09-14 Thread Will Deacon
into the guest stage-2 page-table is visible to the instruction fetcher. Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_hyp.h | 1 + arch/arm64/kernel/image-vars.h | 3 --- arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/hyp/nvhe/cache.S | 11 +++ arch/arm64/kvm/hyp

[PATCH v3 12/25] KVM: arm64: Add infrastructure to create and track pKVM instances at EL2

2022-09-14 Thread Will Deacon
is directly associated with an untrusted host KVM instance, and is referenced by the host using an opaque handle. Future patches will provide hypercalls to allow the host to initialize/set/get pKVM VM/vCPU state using the opaque handle. Signed-off-by: Fuad Tabba Signed-off-by: Will Deacon --- arch

[PATCH v3 15/25] KVM: arm64: Initialise hypervisor copies of host symbols unconditionally

2022-09-14 Thread Will Deacon
symbols from the host copies regardless of pKVM, ensuring that any reference to this data at EL2 with normal nVHE will return a sensibly initialised value. Signed-off-by: Will Deacon --- arch/arm64/kvm/arm.c | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/arm64

[PATCH v3 14/25] KVM: arm64: Add per-cpu fixmap infrastructure at EL2

2022-09-14 Thread Will Deacon
. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_pgtable.h | 12 +++ arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 + arch/arm64/kvm/hyp/include/nvhe/mm.h | 4 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 1 - arch/arm64/kvm/hyp

[PATCH v3 13/25] KVM: arm64: Instantiate pKVM hypervisor VM and vCPU structures from EL1

2022-09-14 Thread Will Deacon
structures are allocated separately so as to avoid the need for a large physically-contiguous allocation in the host at run-time. Signed-off-by: Fuad Tabba Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_host.h | 15 +++- arch/arm64/include/asm/kvm_pkvm.h | 4 + arch/arm64/kvm/arm.c

[PATCH v3 11/25] KVM: arm64: Rename 'host_kvm' to 'host_mmu'

2022-09-14 Thread Will Deacon
. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 6 +-- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 46 +-- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include

[PATCH v3 10/25] KVM: arm64: Add hyp_spinlock_t static initializer

2022-09-14 Thread Will Deacon
From: Fuad Tabba Introduce a static initializer macro for 'hyp_spinlock_t' so that it is straightforward to instantiate global locks at EL2. This will be later utilised for locking the VM table in the hypervisor. Signed-off-by: Fuad Tabba Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp

[PATCH v3 09/25] KVM: arm64: Include asm/kvm_mmu.h in nvhe/mem_protect.h

2022-09-14 Thread Will Deacon
nvhe/mem_protect.h refers to __load_stage2() in the definition of __load_host_stage2() but doesn't include the relevant header. Include asm/kvm_mmu.h in nvhe/mem_protect.h so that users of the latter don't have to do this themselves. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include

[PATCH v3 08/25] KVM: arm64: Add helpers to pin memory shared with the hypervisor at EL2

2022-09-14 Thread Will Deacon
-structures (e.g. 'struct kvm') with the guarantee that these pages will remain in a stable state until the hypervisor decides to release them, for example during guest teardown. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 3 ++ arch

[PATCH v3 07/25] KVM: arm64: Prevent the donation of no-map pages

2022-09-14 Thread Will Deacon
eck for the presence of the MEMBLOCK_NOMAP flag on a region containing pages being donated from the host. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 22 -- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git

[PATCH v3 06/25] KVM: arm64: Implement do_donate() helper for donating memory

2022-09-14 Thread Will Deacon
performed by the hypervisor to ensure that the component initiating the transition really is the owner of the page and also that the completer does not currently have a page mapped at the target address. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mem

[PATCH v3 05/25] KVM: arm64: Unify identifiers used to distinguish host and hypervisor

2022-09-14 Thread Will Deacon
of the memory protection code, for example when initialising the owner for hypervisor-owned pages. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 6 +- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 8 arch/arm64/kvm/hyp/nvhe/setup.c

[PATCH v3 04/25] KVM: arm64: Fix-up hyp stage-1 refcounts for all pages mapped at EL2

2022-09-14 Thread Will Deacon
. This is achieved by traversing the entire hypervisor stage-1 page-table during initialisation of EL2 and updating the corresponding 'struct hyp_page' for each valid mapping. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/setup.c | 62

[PATCH v3 03/25] KVM: arm64: Back the hypervisor 'struct hyp_page' array for all memory

2022-09-14 Thread Will Deacon
in the host stage-2 page-table entries. This will be used in subsequent patches when pinning host memory pages for use by the hypervisor at EL2. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_pkvm.h| 26 +++ arch/arm64/kvm/hyp/include

[PATCH v3 02/25] KVM: arm64: Allow attaching of non-coalescable pages to a hyp pool

2022-09-14 Thread Will Deacon
the host to the hypervisor when allocating guest stage-2 page-table pages at EL2. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/page_alloc.c | 5 + 1 file changed, 5 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe

[PATCH v3 01/25] KVM: arm64: Move hyp refcount manipulation helpers to common header file

2022-09-14 Thread Will Deacon
From: Quentin Perret We will soon need to manipulate 'struct hyp_page' refcounts from outside page_alloc.c, so move the helpers to a common header file to allow them to be reused easily. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/memory.h

[PATCH v3 00/25] KVM: arm64: Introduce pKVM hyp VM and vCPU state at EL2

2022-09-14 Thread Will Deacon
considerably closer to isolating guests from the host. Cheers, Will, Quentin, Fuad and Marc Cc: Sean Christopherson Cc: Will Deacon Cc: Vincent Donnefort Cc: Alexandru Elisei Cc: Catalin Marinas Cc: James Morse Cc: Chao Peng Cc: Quentin Perret Cc: Suzuki K Poulose Cc: Mark Rutland Cc: Fuad

Re: [PATCH v2] KVM: arm64: Only set KVM_MODE_PROTECTED if is_hyp_mode_available()

2022-09-10 Thread Will Deacon
On Sat, Sep 10, 2022 at 10:09:31AM +0100, Marc Zyngier wrote: > On Fri, 09 Sep 2022 18:55:18 +0100, > Elliot Berman wrote: > > > > > > > > On 9/9/2022 10:28 AM, Catalin Marinas wrote: > > > On Fri, Sep 09, 2022 at 07:45:52AM -0700, Elliot Berman wrote: > > >> Do not switch kvm_mode to

Re: [PATCH kvmtool 0/1] Introduce LIBFDT_DIR

2022-08-04 Thread Will Deacon
On Fri, 22 Jul 2022 15:14:47 +0100, Alexandru Elisei wrote: > This is based on the series that added the libfdt source files to the > kvmtool tree [1]. I've reconsidered the feedback I got from Andre and Will, > and so I came up with a different approach: the user can opt to compile > libdt

Re: KVM/arm64: SPE: Translate VA to IPA on a stage 2 fault instead of pinning VM memory

2022-08-01 Thread Will Deacon
Hi Alex, On Mon, Jul 25, 2022 at 11:06:24AM +0100, Alexandru Elisei wrote: > On Tue, Apr 19, 2022 at 03:10:13PM +0100, Will Deacon wrote: > > On Tue, Apr 19, 2022 at 02:51:05PM +0100, Alexandru Elisei wrote: > > > The approach I've taken so far in adding support for SPE

Re: [PATCH v2 00/24] KVM: arm64: Introduce pKVM shadow state at EL2

2022-07-20 Thread Will Deacon
Hi Sean, On Tue, Jul 19, 2022 at 04:11:32PM +, Sean Christopherson wrote: > Apologies for the slow reply. No problem; you've provided a tonne of insightful feedback here, so it was worth the wait. Thanks! > On Fri, Jul 08, 2022, Will Deacon wrote: > > but I wanted to inherit th

Re: [PATCH v2 18/24] KVM: arm64: Instantiate guest stage-2 page-tables at EL2

2022-07-20 Thread Will Deacon
On Tue, Jul 19, 2022 at 02:32:18PM +0100, Vincent Donnefort wrote: > [...] > > > } > > > > void reclaim_guest_pages(struct kvm_shadow_vm *vm) > > { > > - unsigned long nr_pages; > > + unsigned long nr_pages, pfn; > > > > nr_pages = kvm_pgtable_stage2_pgd_size(vm->kvm.arch.vtcr) >>

Re: [PATCH v2 12/24] KVM: arm64: Introduce shadow VM state at EL2

2022-07-20 Thread Will Deacon
Hi Vincent, Thanks for going through this. On Mon, Jul 18, 2022 at 07:40:05PM +0100, Vincent Donnefort wrote: > [...] > > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h > > b/arch/arm64/include/asm/kvm_pgtable.h > > index 9f339dffbc1a..2d6b5058f7d3 100644 > > ---

Re: [PATCH v2 06/24] KVM: arm64: Unify identifiers used to distinguish host and hypervisor

2022-07-20 Thread Will Deacon
Hi Oliver, Thanks for having a look. On Wed, Jul 20, 2022 at 03:11:04PM +, Oliver Upton wrote: > On Thu, Jun 30, 2022 at 02:57:29PM +0100, Will Deacon wrote: > > The 'pkvm_component_id' enum type provides constants to refer to the > > host and the hypervisor, yet t

Re: [PATCH v2 7/7] arm64/sve: Don't zero non-FPSIMD register state on syscall by default

2022-07-20 Thread Will Deacon
On Tue, Jul 19, 2022 at 08:35:46PM +0100, Mark Brown wrote: > On Tue, Jul 19, 2022 at 06:35:37PM +0100, Catalin Marinas wrote: > > On Mon, Jun 20, 2022 at 01:41:58PM +0100, Mark Brown wrote: > > > > The documented syscall ABI specifies that the SVE state not shared with > > > FPSIMD is undefined

Re: [PATCH v2 00/24] KVM: arm64: Introduce pKVM shadow state at EL2

2022-07-08 Thread Will Deacon
Hi Sean, Thanks for having a look. On Wed, Jul 06, 2022 at 07:17:29PM +, Sean Christopherson wrote: > On Thu, Jun 30, 2022, Will Deacon wrote: > > This series has been extracted from the pKVM base support series (aka > > "pKVM mega-patch") previously post

Re: [PATCH kvmtool] arm: gic: fdt: fix PPI CPU mask calculation

2022-07-01 Thread Will Deacon
On Thu, 16 Jun 2022 15:55:26 +0100, Andre Przywara wrote: > The GICv2 DT binding describes the third cell in each interrupt > descriptor as holding the trigger type, but also the CPU mask that this > IRQ applies to, in bits [15:8]. However this is not the case for GICv3, > where we don't use a CPU

Re: [PATCH v4 kvmtool 00/12] arm64: Allow the user to set RAM base address

2022-07-01 Thread Will Deacon
On Thu, 16 Jun 2022 14:48:16 +0100, Alexandru Elisei wrote: > The series can be found at [1]. It is loosely based on the patches that > allow the user to define the VM memory layout (RAM + MMIO) [2]. I've > cherry-picked a handful of patches from that series, the rest I wrote from > scratch since

Re: [PATCH kvmtool] arm64: pvtime: Use correct region size

2022-07-01 Thread Will Deacon
On Wed, 29 Jun 2022 11:39:05 +0100, Alexandru Elisei wrote: > pvtime uses ARM_PVTIME_BASE instead of ARM_PVTIME_SIZE for the size of the > memory region given to the guest, which causes to the following error when > creating a flash device (via the -F/--flash command line argument): > > Error:

[RFC PATCH v2 24/24] KVM: arm64: Use the shadow vCPU structure in handle___kvm_vcpu_run()

2022-06-30 Thread Will Deacon
is initialised in protected mode. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 4 ++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 84 +- arch/arm64/kvm/hyp/nvhe/pkvm.c | 28 + 3 files changed, 114 insertions(+), 2 deletions(-) diff --git

[PATCH v2 23/24] KVM: arm64: Don't map host sections in pkvm

2022-06-30 Thread Will Deacon
From: Quentin Perret We no longer need to map the host's .rodata and .bss sections in the pkvm hypervisor, so let's remove those mappings. This will avoid creating dependencies at EL2 on host-controlled data-structures. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64

[PATCH v2 22/24] KVM: arm64: Explicitly map kvm_vgic_global_state at EL2

2022-06-30 Thread Will Deacon
From: Quentin Perret The pkvm hypervisor may need to read the kvm_vgic_global_state variable at EL2. Make sure to explicitly map it in its stage-1 page-table rather than relying on mapping all of the host .rodata section. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch

[PATCH v2 21/24] KVM: arm64: Maintain a copy of 'kvm_arm_vmid_bits' at EL2

2022-06-30 Thread Will Deacon
of 'kvm_arm_vmid_bits' and initialise it from the host value while it is still trusted. Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_hyp.h | 2 ++ arch/arm64/kernel/image-vars.h | 3 --- arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/hyp/nvhe/pkvm.c | 3 +++ 4 files

[PATCH v2 20/24] KVM: arm64: Unmap kvm_arm_hyp_percpu_base from the host

2022-06-30 Thread Will Deacon
From: Quentin Perret In pKVM mode, we can't trust the host not to mess with the hypervisor per-cpu offsets, so let's move the array containing them to the nVHE code. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_asm.h | 4 ++-- arch/arm64/kernel

[PATCH v2 19/24] KVM: arm64: Return guest memory from EL2 via dedicated teardown memcache

2022-06-30 Thread Will Deacon
Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_host.h | 6 +- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 +- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 17 +++-- arch/arm64/kvm/hyp/nvhe/pkvm.c| 8 +++- arch/arm64/kvm

[PATCH v2 18/24] KVM: arm64: Instantiate guest stage-2 page-tables at EL2

2022-06-30 Thread Will Deacon
as there is no way for the host to map anything into it. Yet. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 6 ++ arch/arm64/kvm/hyp/nvhe/mem_protect.c | 127 - 2 files changed, 130 insertions(+), 3 deletions(-) diff --git a/arch

[PATCH v2 17/24] KVM: arm64: Add generic hyp_memcache helpers

2022-06-30 Thread Will Deacon
hyp_memcache which is essentially a linked list of available pages, indexed by physical addresses. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_host.h | 57 +++ arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 + arch/arm64/kvm/hyp

[PATCH v2 16/24] KVM: arm64: Provide I-cache invalidation by VA at EL2

2022-06-30 Thread Will Deacon
In preparation for handling cache maintenance of guest pages at EL2, introduce an EL2 copy of icache_inval_pou() which will later be plumbed into the stage-2 page-table cache maintenance callbacks. Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_hyp.h | 1 + arch/arm64/kernel/image

[PATCH v2 15/24] KVM: arm64: Initialise hyp symbols regardless of pKVM

2022-06-30 Thread Will Deacon
symbols from the host copies regardless of pKVM, ensuring that any reference to this data at EL2 with normal nVHE will return an sensibly initialised value. Signed-off-by: Will Deacon --- arch/arm64/kvm/arm.c | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/arch

[PATCH v2 14/24] KVM: arm64: Add pcpu fixmap infrastructure at EL2

2022-06-30 Thread Will Deacon
Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 + arch/arm64/kvm/hyp/include/nvhe/mm.h | 4 ++ arch/arm64/kvm/hyp/nvhe/mem_protect.c | 1 - arch/arm64/kvm/hyp/nvhe/mm.c | 72 +++ arch/arm64/kvm/hyp/nvhe/setup.c

[PATCH v2 13/24] KVM: arm64: Instantiate VM shadow data from EL1

2022-06-30 Thread Will Deacon
From: Fuad Tabba Now that EL2 provides calls to create and destroy shadow VM structures, plumb these into the KVM code at EL1 so that a shadow VM is created on first vCPU run and destroyed later along with the 'struct kvm' at teardown time. Signed-off-by: Fuad Tabba Signed-off-by: Will Deacon

[PATCH v2 12/24] KVM: arm64: Introduce shadow VM state at EL2

2022-06-30 Thread Will Deacon
From: Fuad Tabba Introduce a table of shadow VM structures at EL2 and provide hypercalls to the host for creating and destroying shadow VMs. Signed-off-by: Fuad Tabba Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_asm.h | 2 + arch/arm64/include/asm/kvm_host.h

[PATCH v2 11/24] KVM: arm64: Add hyp_spinlock_t static initializer

2022-06-30 Thread Will Deacon
From: Fuad Tabba Having a static initializer for hyp_spinlock_t simplifies its use when there isn't an initializing function. No functional change intended. Signed-off-by: Fuad Tabba Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/spinlock.h | 10 +- 1 file changed, 9

[PATCH v2 10/24] KVM: arm64: Include asm/kvm_mmu.h in nvhe/mem_protect.h

2022-06-30 Thread Will Deacon
nvhe/mem_protect.h refers to __load_stage2() in the definition of __load_host_stage2() but doesn't include the relevant header. Include asm/kvm_mmu.h in nvhe/mem_protect.h so that users of the latter don't have to do this themselves. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include

[PATCH v2 09/24] KVM: arm64: Add helpers to pin memory shared with hyp

2022-06-30 Thread Will Deacon
-structures (struct kvm and such) and be guaranteed these pages will remain in a stable state until it decides to release them, e.g. during guest teardown. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 3 ++ arch/arm64/kvm/hyp/include/nvhe

[PATCH v2 08/24] KVM: arm64: Prevent the donation of no-map pages

2022-06-30 Thread Will Deacon
region at EL2 easily. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 22 -- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c

[PATCH v2 07/24] KVM: arm64: Implement do_donate() helper for donating memory

2022-06-30 Thread Will Deacon
as do_{un,}share, and provide this functionality for the host-{to,from}-hyp cases as this will later be used to donate/reclaim memory pages to store VM metadata at EL2. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 + arch/arm

[PATCH v2 06/24] KVM: arm64: Unify identifiers used to distinguish host and hypervisor

2022-06-30 Thread Will Deacon
of the memory protection code. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 6 +- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 8 arch/arm64/kvm/hyp/nvhe/setup.c | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git

[PATCH v2 05/24] KVM: arm64: Make hyp stage-1 refcnt correct on the whole range

2022-06-30 Thread Will Deacon
-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/setup.c | 62 +++-- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 579eb4f73476..8f2726d7e201 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch

[PATCH v2 04/24] KVM: arm64: Back hyp_vmemmap for all of memory

2022-06-30 Thread Will Deacon
of memory. This will simplify a lot memory tracking as the hypervisor will have a place to store metadata (e.g. refcounts) that wouldn't otherwise fit in the 4 SW bits we have in the host stage-2 page-table for instance. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64

[PATCH v2 03/24] KVM: arm64: Add flags to struct hyp_page

2022-06-30 Thread Will Deacon
From: Quentin Perret Add a 'flags' field to struct hyp_page, and reduce the size of the order field to u8 to avoid growing the struct size. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/gfp.h| 6 +++--- arch/arm64/kvm/hyp/include/nvhe

[PATCH v2 02/24] KVM: arm64: Allow non-coalescable pages in a hyp_pool

2022-06-30 Thread Will Deacon
to the hypervisor when allocating guest stage-2 page-table pages at EL2. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/page_alloc.c | 5 + 1 file changed, 5 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe

[PATCH v2 00/24] KVM: arm64: Introduce pKVM shadow state at EL2

2022-06-30 Thread Will Deacon
ntin, Fuad and Marc Cc: Ard Biesheuvel Cc: Sean Christopherson Cc: Will Deacon Cc: Alexandru Elisei Cc: Andy Lutomirski Cc: Catalin Marinas Cc: James Morse Cc: Chao Peng Cc: Quentin Perret Cc: Suzuki K Poulose Cc: Michael Roth Cc: Mark Rutland Cc: Fuad Tabba Cc: Oliver Upton Cc: Ma

[PATCH v2 01/24] KVM: arm64: Move hyp refcount manipulation helpers

2022-06-30 Thread Will Deacon
From: Quentin Perret We will soon need to manipulate struct hyp_page refcounts from outside page_alloc.c, so move the helpers to a header file. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/memory.h | 18 ++ arch/arm64/kvm/hyp

[PATCH 6/6] KVM: arm64: Drop stale comment

2022-06-09 Thread Will Deacon
From: Marc Zyngier The layout of 'struct kvm_vcpu_arch' has evolved significantly since the initial port of KVM/arm64, so remove the stale comment suggesting that a prefix of the structure is used exclusively from assembly code. Signed-off-by: Marc Zyngier ---

[PATCH 4/6] KVM: arm64: Extend comment in has_vhe()

2022-06-09 Thread Will Deacon
to be dropped from the nVHE object. Expand the comment in has_vhe() to make this clearer, hopefully discouraging anybody from simplifying the code. Cc: David Brazdil Acked-by: Mark Rutland Signed-off-by: Will Deacon --- arch/arm64/include/asm/virt.h | 3 +++ 1 file changed, 3 insertions

[PATCH 5/6] KVM: arm64: Remove redundant hyp_assert_lock_held() assertions

2022-06-09 Thread Will Deacon
host_stage2_try() asserts that the KVM host lock is held, so there's no need to duplicate the assertion in its wrappers. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 4 1 file changed, 4 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch

[PATCH 3/6] KVM: arm64: Ignore 'kvm-arm.mode=protected' when using VHE

2022-06-09 Thread Will Deacon
Ignore 'kvm-arm.mode=protected' when using VHE so that kvm_get_mode() only returns KVM_MODE_PROTECTED on systems where the feature is available. Cc: David Brazdil Acked-by: Mark Rutland Signed-off-by: Will Deacon --- Documentation/admin-guide/kernel-parameters.txt | 1 - arch/arm64/kernel

[PATCH 2/6] KVM: arm64: Handle all ID registers trapped for a protected VM

2022-06-09 Thread Will Deacon
ones), and have them to return 0. Reported-by: Will Deacon Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 42 -- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/sys_regs.c b/arch/arm64/kvm/hyp/nvhe

[PATCH 1/6] KVM: arm64: Return error from kvm_arch_init_vm() on allocation failure

2022-06-09 Thread Will Deacon
If we fail to allocate the 'supported_cpus' cpumask in kvm_arch_init_vm() then be sure to return -ENOMEM instead of success (0) on the failure path. Reviewed-by: Alexandru Elisei Signed-off-by: Will Deacon --- arch/arm64/kvm/arm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff

[PATCH 0/6] KVM/arm64: Minor/trivial fixes from pKVM mega-patch

2022-06-09 Thread Will Deacon
sters trapped for a protected VM KVM: arm64: Drop stale comment Will Deacon (4): KVM: arm64: Return error from kvm_arch_init_vm() on allocation failure KVM: arm64: Ignore 'kvm-arm.mode=protected' when using VHE KVM: arm64: Extend comment in has_vhe() KVM: arm64: Remove redundant hyp_ass

Re: [PATCH] KVM: arm64: Fix memory leaks from stage2 pagetable

2022-05-31 Thread Will Deacon
On Tue, May 31, 2022 at 05:57:11PM +0100, Will Deacon wrote: > On Thu, May 26, 2022 at 04:39:56PM -0400, Qian Cai wrote: > > Running some SR-IOV workloads could trigger some leak reports from > > kmemleak. > > > > unreferenced object 0x080243cef500 (size 128):

Re: [PATCH] KVM: arm64: Fix memory leaks from stage2 pagetable

2022-05-31 Thread Will Deacon
On Thu, May 26, 2022 at 04:39:56PM -0400, Qian Cai wrote: > Running some SR-IOV workloads could trigger some leak reports from > kmemleak. > > unreferenced object 0x080243cef500 (size 128): > comm "qemu-system-aar", pid 179935, jiffies 4298359506 (age 1629.732s) > hex dump (first 32

Re: [PATCH 33/89] KVM: arm64: Handle guest stage-2 page-tables entirely at EL2

2022-05-31 Thread Will Deacon
On Fri, May 20, 2022 at 05:03:29PM +0100, Alexandru Elisei wrote: > On Thu, May 19, 2022 at 02:41:08PM +0100, Will Deacon wrote: > > Now that EL2 is able to manage guest stage-2 page-tables, avoid > > allocating a separate MMU structure in the host and instead introduce a > &

Re: [PATCH 03/89] KVM: arm64: Return error from kvm_arch_init_vm() on allocation failure

2022-05-31 Thread Will Deacon
On Fri, May 20, 2022 at 04:55:51PM +0100, Alexandru Elisei wrote: > Hi, > > On Thu, May 19, 2022 at 02:40:38PM +0100, Will Deacon wrote: > > If we fail to allocate the 'supported_cpus' cpumask in kvm_arch_init_vm() > > then be sure to return -ENOMEM instead of success (0) on

Re: [PATCH kvmtool 0/2] Fixes for arm64 and MIPS

2022-05-26 Thread Will Deacon
On Wed, 25 May 2022 17:57:02 +0100, Alexandru Elisei wrote: > The first fix is for arm64, where the VCPUs weren't pinned correctly with > --vcpu-affinity when creating an aarch32 guest. Hopefully the patch is > straightforward. > > The last patch is a fix for MIPS not compiling for a year now,

Re: [PATCH kvmtool 0/4] Update virtio headers (to fix build)

2022-05-26 Thread Will Deacon
On Tue, 24 May 2022 16:06:07 +0100, Andre Przywara wrote: > Since we implement some virtio devices in kvmtool, we were including > older copies of some virtio UAPI header files in our tree, but were > relying on some other headers to be provided by the distribution. > This leads to problems when

Re: [PATCH kvmtool] aarch64: Give up with MTE for AArch32 guest

2022-05-20 Thread Will Deacon
On Fri, 20 May 2022 13:38:44 +0100, Vladimir Murzin wrote: > KVM doesn't support combination of MTE and AArch32 guest, so do not > even try. > > Applied to kvmtool (master), thanks! [1/1] aarch64: Give up with MTE for AArch32 guest https://git.kernel.org/will/kvmtool/c/324cc0969b7c

[PATCH 89/89] Documentation: KVM: Add some documentation for Protected KVM on arm64

2022-05-19 Thread Will Deacon
Add some initial documentation for the Protected KVM (pKVM) feature on arm64, describing the user ABI for creating protected VMs as well as their limitations. Signed-off-by: Will Deacon --- .../admin-guide/kernel-parameters.txt | 4 +- Documentation/virt/kvm/arm/index.rst | 1

[PATCH 88/89] KVM: arm64: Introduce KVM_VM_TYPE_ARM_PROTECTED machine type for PVMs

2022-05-19 Thread Will Deacon
Introduce a new virtual machine type, KVM_VM_TYPE_ARM_PROTECTED, which specifies that the guest memory pages are to be unmapped from the host stage-2 by the hypervisor. Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_pkvm.h | 2 +- arch/arm64/kvm/arm.c | 5 - arch

[PATCH 87/89] KVM: arm64: Expose memory sharing hypercalls to protected guests

2022-05-19 Thread Will Deacon
MEM_SHARE:Share a page RWX with the host, faulting the page in if necessary. MEM_UNSHARE: Unshare a page with the host. Subsequent host accesses to the page will result in a fault being injected by the hypervisor. Signed-off-by: W

[PATCH 85/89] KVM: arm64: Document the KVM/arm64-specific calls in hypercalls.rst

2022-05-19 Thread Will Deacon
KVM/arm64 makes use of the SMCCC "Vendor Specific Hypervisor Service Call Range" to expose KVM-specific hypercalls to guests in a discoverable and extensible fashion. Document the existence of this interface and the discovery hypercall. Signed-off-by: Will Deacon --- Documentation/vi

[PATCH 86/89] KVM: arm64: Reformat/beautify PTP hypercall documentation

2022-05-19 Thread Will Deacon
The PTP hypercall documentation doesn't produce the best-looking table when formatting in HTML as all of the return value definitions end up on the same line. Reformat the PTP hypercall documentation to follow the formatting used by hypercalls.rst. Signed-off-by: Will Deacon --- Documentation

[PATCH 84/89] KVM: arm64: Extend memory sharing to allow guest-to-host transitions

2022-05-19 Thread Will Deacon
but will later be exposed to the guest via hypercalls. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 232 ++ 2 files changed, 234 insertions(+) diff --git a/arch/arm64/kvm/hyp/include/nvhe

[PATCH 83/89] KVM: arm64: Avoid BBM when changing only s/w bits in Stage-2 PTE

2022-05-19 Thread Will Deacon
tware bits of a PTE, avoid the sequence in this case and just update the PTE directly. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/pgtable.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 20

[PATCH 82/89] KVM: arm64: Support TLB invalidation in guest context

2022-05-19 Thread Will Deacon
supports being invoked from guest context and acts as a no-op if the target context matches the running context. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/tlb.c | 96 --- 1 file changed, 78 insertions(+), 18 deletions(-) diff --git a/arch/arm64/kvm/hyp

[PATCH 81/89] KVM: arm64: Inject SIGSEGV on illegal accesses

2022-05-19 Thread Will Deacon
From: Quentin Perret The pKVM hypervisor will currently panic if the host tries to access memory that it doesn't own (e.g. protected guest memory). Sadly, as guest memory can still be mapped into the VMM's address space, userspace can trivially crash the kernel/hypervisor by poking into guest

[PATCH 80/89] KVM: arm64: Refactor enter_exception64()

2022-05-19 Thread Will Deacon
From: Quentin Perret In order to simplify the injection of exceptions in the host in pkvm context, let's factor out of enter_exception64() the code calculating the exception offset from VBAR_EL1 and the cpsr. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_emulate.h | 5 ++

[PATCH 79/89] KVM: arm64: Add is_pkvm_initialized() helper

2022-05-19 Thread Will Deacon
From: Quentin Perret Add a helper allowing to check when the pkvm static key is enabled to ease the introduction of pkvm hooks in other parts of the code. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/virt.h | 12 1 file changed, 8 insertions(+), 4 deletions(-) diff

  1   2   3   4   5   6   7   8   9   10   >