Re: [PATCH v2 02/22] KVM: arm64: Remove kvm_mmu_free_memory_caches()

2020-08-18 Thread Gavin Shan
On 8/18/20 11:27 PM, Will Deacon wrote: kvm_mmu_free_memory_caches() is only called by kvm_arch_vcpu_destroy(), so inline the implementation and get rid of the extra function. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_mmu.h | 2 -- arch/a

Re: [PATCH v2 01/22] KVM: arm64: Don't free memcache pages in kvm_phys_addr_ioremap()

2020-08-18 Thread Gavin Shan
Hi Will, On 8/18/20 11:27 PM, Will Deacon wrote: kvm_phys_addr_ioremap() unconditionally empties out the memcache pages for the current vCPU on return. This causes subsequent topups to allocate fresh pages and is at odds with the behaviour when mapping memory in user_mem_abort(). Remove the cal

Re: [RFC PATCH 0/5] KVM: arm64: Add pvtime LPT support

2020-08-18 Thread Marc Zyngier
On 2020-08-17 09:41, Keqian Zhu wrote: Hi all, This patch series picks up the LPT pvtime feature originally developed by Steven Price: https://patchwork.kernel.org/cover/10726499/ Backgroud: There is demand for cross-platform migration, which means we have to solve different CPU features and a

Re: [PATCH v1 1/3] arm64: allow de-selection of ThunderX PCI controllers

2020-08-18 Thread Bjorn Helgaas
On Tue, Aug 04, 2020 at 01:44:15PM +0100, Alex Bennée wrote: > For a pure VirtIO guest bringing in all the PCI quirk handling adds a > significant amount of bloat to kernel we don't need. Solve this by > adding a CONFIG symbol for the ThunderX PCI devices and allowing it to > be turned off. Saving

[PATCH v2 19/22] KVM: arm64: Check the pgt instead of the pgd when modifying page-table

2020-08-18 Thread Will Deacon
In preparation for removing the 'pgd' field of 'struct kvm_s2_mmu', update the few remaining users to check the 'pgt' field instead. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a

[PATCH v2 13/22] KVM: arm64: Add support for stage-2 write-protect in generic page-table

2020-08-18 Thread Will Deacon
From: Quentin Perret Add a stage-2 wrprotect() operation to the generic page-table code. Cc: Marc Zyngier Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_pgtable.h | 15 +++ arch/arm64/kvm/hyp/pgtable.c | 6 ++ 2 files changed,

[PATCH v2 20/22] KVM: arm64: Remove unused page-table code

2020-08-18 Thread Will Deacon
Now that KVM is using the generic page-table code to manage the guest stage-2 page-tables, we can remove a bunch of unused macros, #defines and static inline functions from the old implementation. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_mmu

[PATCH v2 16/22] KVM: arm64: Convert memslot cache-flushing code to generic page-table API

2020-08-18 Thread Will Deacon
From: Quentin Perret Convert stage2_flush_memslot() to call the kvm_pgtable_stage2_flush() function of the generic page-table code instead of walking the page-table directly. Cc: Marc Zyngier Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmu.c | 13 +

[PATCH v2 10/22] KVM: arm64: Convert unmap_stage2_range() to generic page-table API

2020-08-18 Thread Will Deacon
Convert unmap_stage2_range() to use kvm_pgtable_stage2_unmap() instead of walking the page-table directly. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmu.c | 57 +--- 1 file changed, 32 insertions(+), 25 deletions(-

[PATCH v2 14/22] KVM: arm64: Convert write-protect operation to generic page-table API

2020-08-18 Thread Will Deacon
From: Quentin Perret Convert stage2_wp_range() to call the kvm_pgtable_stage2_wrprotect() function of the generic page-table code instead of walking the page-table directly. Cc: Marc Zyngier Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmu.c | 25 --

[PATCH v2 06/22] KVM: arm64: Add support for creating kernel-agnostic stage-2 page tables

2020-08-18 Thread Will Deacon
Introduce alloc() and free() functions to the generic page-table code for guest stage-2 page-tables and plumb these into the existing KVM page-table allocator. Subsequent patches will convert other operations within the KVM allocator over to the generic code. Cc: Marc Zyngier Cc: Quentin Perret

[PATCH v2 18/22] KVM: arm64: Convert user_mem_abort() to generic page-table API

2020-08-18 Thread Will Deacon
Convert user_mem_abort() to call kvm_pgtable_stage2_relax_perms() when handling a stage-2 permission fault and kvm_pgtable_stage2_map() when handling a stage-2 translation fault, rather than walking the page-table manually. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arc

[PATCH v2 11/22] KVM: arm64: Add support for stage-2 page-aging in generic page-table

2020-08-18 Thread Will Deacon
Add stage-2 mkyoung(), mkold() and is_young() operations to the generic page-table code. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_pgtable.h | 38 arch/arm64/kvm/hyp/pgtable.c | 86 2 files ch

[PATCH v2 15/22] KVM: arm64: Add support for stage-2 cache flushing in generic page-table

2020-08-18 Thread Will Deacon
From: Quentin Perret Add support for cache flushing a range of the stage-2 address space to the generic page-table code. Cc: Marc Zyngier Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_pgtable.h | 12 arch/arm64/kvm/hyp/pgtable.c

[PATCH v2 02/22] KVM: arm64: Remove kvm_mmu_free_memory_caches()

2020-08-18 Thread Will Deacon
kvm_mmu_free_memory_caches() is only called by kvm_arch_vcpu_destroy(), so inline the implementation and get rid of the extra function. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_mmu.h | 2 -- arch/arm64/kvm/arm.c | 2 +- arch/arm6

[PATCH v2 17/22] KVM: arm64: Add support for relaxing stage-2 perms in generic page-table code

2020-08-18 Thread Will Deacon
Add support for relaxing the permissions of a stage-2 mapping (i.e. adding additional permissions) to the generic page-table code. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_pgtable.h | 17 + arch/arm64/kvm/hyp/pgtable.c

[PATCH v2 05/22] KVM: arm64: Use generic allocator for hyp stage-1 page-tables

2020-08-18 Thread Will Deacon
Now that we have a shiny new page-table allocator, replace the hyp page-table code with calls into the new API. This also allows us to remove the extended idmap code, as we can now simply ensure that the VA size is large enough to map everything we need. Cc: Marc Zyngier Cc: Quentin Perret Signe

[PATCH v2 09/22] KVM: arm64: Convert kvm_set_spte_hva() to generic page-table API

2020-08-18 Thread Will Deacon
Convert kvm_set_spte_hva() to use kvm_pgtable_stage2_map() instead of stage2_set_pte(). Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmu.c | 23 ++- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/a

[PATCH v2 04/22] KVM: arm64: Add support for creating kernel-agnostic stage-1 page tables

2020-08-18 Thread Will Deacon
The generic page-table walker is pretty useless as it stands, because it doesn't understand enough to allocate anything. Teach it about stage-1 page-tables, and hook up an API for allocating these for the hypervisor at EL2. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arc

[PATCH v2 22/22] KVM: arm64: Don't constrain maximum IPA size based on host configuration

2020-08-18 Thread Will Deacon
Now that the guest stage-2 page-tables are managed independently from the host stage-1 page-tables, we can avoid constraining the IPA size based on the host and instead limit it only based on the PARange field of the ID_AA64MMFR0 register. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will

[PATCH v2 12/22] KVM: arm64: Convert page-aging and access faults to generic page-table API

2020-08-18 Thread Will Deacon
Convert the page-aging functions and access fault handler to use the generic page-table code instead of walking the page-table directly. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmu.c | 74 ++-- 1 file changed, 16

[PATCH v2 21/22] KVM: arm64: Remove unused 'pgd' field from 'struct kvm_s2_mmu'

2020-08-18 Thread Will Deacon
The stage-2 page-tables are entirely encapsulated by the 'pgt' field of 'struct kvm_s2_mmu', so remove the unused 'pgd' field. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_host.h | 1 - arch/arm64/kvm/mmu.c | 2 -- 2 files changed,

[PATCH v2 00/22] KVM: arm64: Rewrite page-table code and fault handling

2020-08-18 Thread Will Deacon
Hi everyone, This is version two of the patches rewriting KVM's page-table code on arm64 that I previously posted here: https://lore.kernel.org/r/20200730153406.25136-1-w...@kernel.org Changes since v1 include: * Removed opaque cookie in favour of exposing 'struct kvm_pgtable' * Moved cod

[PATCH v2 03/22] KVM: arm64: Add stand-alone page-table walker infrastructure

2020-08-18 Thread Will Deacon
The KVM page-table code is intricately tied into the kernel page-table code and re-uses the pte/pmd/pud/p4d/pgd macros directly in an attempt to reduce code duplication. Unfortunately, the reality is that there is an awful lot of code required to make this work, and at the end of the day you're lim

[PATCH v2 01/22] KVM: arm64: Don't free memcache pages in kvm_phys_addr_ioremap()

2020-08-18 Thread Will Deacon
kvm_phys_addr_ioremap() unconditionally empties out the memcache pages for the current vCPU on return. This causes subsequent topups to allocate fresh pages and is at odds with the behaviour when mapping memory in user_mem_abort(). Remove the call to kvm_mmu_free_memory_cache() from kvm_phys_addr_

[PATCH v2 07/22] KVM: arm64: Add support for stage-2 map()/unmap() in generic page-table

2020-08-18 Thread Will Deacon
Add stage-2 map() and unmap() operations to the generic page-table code. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_pgtable.h | 39 arch/arm64/kvm/hyp/pgtable.c | 262 +++ 2 files changed, 301 insertions(+

[PATCH v2 08/22] KVM: arm64: Convert kvm_phys_addr_ioremap() to generic page-table API

2020-08-18 Thread Will Deacon
Convert kvm_phys_addr_ioremap() to use kvm_pgtable_stage2_map() instead of stage2_set_pte(). Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/pgtable.c | 14 +- arch/arm64/kvm/mmu.c | 24 ++-- 2 files changed, 11 inse

Re: [PATCH 0/2] KVM: arm64: Fix sleeping while atomic BUG() on OOM

2020-08-18 Thread Marc Zyngier
On Tue, 11 Aug 2020 11:27:23 +0100, Will Deacon wrote: > While stress-testing my arm64 stage-2 page-table rewrite [1], I ran into > a sleeping while atomic BUG() during OOM that I can reproduce with > mainline. > > The problem is that the arm64 page-table code periodically calls > cond_resched_loc

Re: [PATCH 0/2] KVM: arm64: Fix sleeping while atomic BUG() on OOM

2020-08-18 Thread Marc Zyngier
On 2020-08-18 11:16, Will Deacon wrote: On Tue, Aug 18, 2020 at 08:31:08AM +0200, Paolo Bonzini wrote: On 11/08/20 12:27, Will Deacon wrote: > Will Deacon (2): > KVM: Pass MMU notifier range flags to kvm_unmap_hva_range() > KVM: arm64: Only reschedule if MMU_NOTIFIER_RANGE_BLOCKABLE is not s

Re: [PATCH 0/2] KVM: arm64: Fix sleeping while atomic BUG() on OOM

2020-08-18 Thread Will Deacon
On Tue, Aug 18, 2020 at 08:31:08AM +0200, Paolo Bonzini wrote: > On 11/08/20 12:27, Will Deacon wrote: > > Will Deacon (2): > > KVM: Pass MMU notifier range flags to kvm_unmap_hva_range() > > KVM: arm64: Only reschedule if MMU_NOTIFIER_RANGE_BLOCKABLE is not set > > > > arch/arm64/include/asm