[PATCH] arm64/perf: Replace '0xf' instances with ID_AA64DFR0_PMUVER_IMP_DEF

2021-08-09 Thread Anshuman Khandual
ID_AA64DFR0_PMUVER_IMP_DEF which indicate implementation defined PMU, never actually gets used although there are '0xf' instances scattered all around. Just do the macro replacement to improve readability. Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Peter Zijlstra Cc: Marc

[PATCH] arm64/mm: Define ID_AA64MMFR0_TGRAN_2_SHIFT

2021-08-09 Thread Anshuman Khandual
Streamline the Stage-2 TGRAN value extraction from ID_AA64MMFR0 register by adding a page size agnostic ID_AA64MMFR0_TGRAN_2_SHIFT. This is similar to the existing Stage-1 TGRAN shift i.e ID_AA64MMFR0_TGRAN_SHIFT. Cc: Catalin Marinas Cc: Will Deacon Cc: Marc Zyngier Cc:

Re: [PATCH v6 00/21] KVM: Add idempotent controls for migrating system counter state

2021-08-09 Thread Oliver Upton
On Wed, Aug 4, 2021 at 3:03 PM Oliver Upton wrote: > > On Wed, Aug 4, 2021 at 4:05 AM Oliver Upton wrote: > > > > On Wed, Aug 4, 2021 at 1:58 AM Oliver Upton wrote: > > > > > > KVM's current means of saving/restoring system counters is plagued with > > > temporal issues. At least on ARM64 and

[PATCH v4 17/21] KVM: arm64: Mark host bss and rodata section as shared

2021-08-09 Thread Quentin Perret
As the hypervisor maps the host's .bss and .rodata sections in its stage-1, make sure to tag them as shared in hyp and host page-tables. But since the hypervisor relies on the presence of these mappings, we cannot let the host in complete control of the memory regions -- it must not unshare or

[PATCH v4 20/21] KVM: arm64: Restrict EL2 stage-1 changes in protected mode

2021-08-09 Thread Quentin Perret
The host kernel is currently able to change EL2 stage-1 mappings without restrictions thanks to the __pkvm_create_mappings() hypercall. But in a world where the host is no longer part of the TCB, this clearly poses a problem. To fix this, introduce a new hypercall to allow the host to share a

[PATCH v4 18/21] KVM: arm64: Remove __pkvm_mark_hyp

2021-08-09 Thread Quentin Perret
Now that we mark memory owned by the hypervisor in the host stage-2 during __pkvm_init(), we no longer need to rely on the host to explicitly mark the hyp sections later on. Remove the __pkvm_mark_hyp() hypercall altogether. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_asm.h

[PATCH v4 13/21] KVM: arm64: Expose host stage-2 manipulation helpers

2021-08-09 Thread Quentin Perret
We will need to manipulate the host stage-2 page-table from outside mem_protect.c soon. Introduce two functions allowing this, and make them usable to users of mem_protect.h. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 ++

[PATCH v4 21/21] KVM: arm64: Make __pkvm_create_mappings static

2021-08-09 Thread Quentin Perret
The __pkvm_create_mappings() function is no longer used outside of nvhe/mm.c, make it static. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/mm.h | 2 -- arch/arm64/kvm/hyp/nvhe/mm.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git

[PATCH v4 19/21] KVM: arm64: Refactor protected nVHE stage-1 locking

2021-08-09 Thread Quentin Perret
Refactor the hypervisor stage-1 locking in nVHE protected mode to expose a new pkvm_create_mappings_locked() function. This will be used in later patches to allow walking and changing the hypervisor stage-1 without releasing the lock. Signed-off-by: Quentin Perret ---

[PATCH v4 09/21] KVM: arm64: Tolerate re-creating hyp mappings to set software bits

2021-08-09 Thread Quentin Perret
The current hypervisor stage-1 mapping code doesn't allow changing an existing valid mapping. Relax this condition by allowing changes that only target software bits, as that will soon be needed to annotate shared pages. Reviewed-by: Fuad Tabba Signed-off-by: Quentin Perret ---

[PATCH v4 10/21] KVM: arm64: Enable forcing page-level stage-2 mappings

2021-08-09 Thread Quentin Perret
Much of the stage-2 manipulation logic relies on being able to destroy block mappings if e.g. installing a smaller mapping in the range. The rationale for this behaviour is that stage-2 mappings can always be re-created lazily. However, this gets more complicated when the stage-2 page-table is

[PATCH v4 15/21] KVM: arm64: Introduce addr_is_memory()

2021-08-09 Thread Quentin Perret
Introduce a helper usable in nVHE protected mode to check whether a physical address is in a RAM region or not. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 1 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 7 +++ 2 files changed, 8 insertions(+)

[PATCH v4 08/21] KVM: arm64: Don't overwrite software bits with owner id

2021-08-09 Thread Quentin Perret
We will soon start annotating page-tables with new flags to track shared pages and such, and we will do so in valid mappings using software bits in the PTEs, as provided by the architecture. However, it is possible that we will need to use those flags to annotate invalid mappings as well in the

[PATCH v4 04/21] KVM: arm64: Introduce helper to retrieve a PTE and its level

2021-08-09 Thread Quentin Perret
From: Marc Zyngier It is becoming a common need to fetch the PTE for a given address together with its level. Add such a helper. Signed-off-by: Marc Zyngier Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_pgtable.h | 19 ++ arch/arm64/kvm/hyp/pgtable.c | 39

[PATCH v4 05/21] KVM: arm64: Expose page-table helpers

2021-08-09 Thread Quentin Perret
The KVM pgtable API exposes the kvm_pgtable_walk() function to allow the definition of walkers outside of pgtable.c. However, it is not easy to implement any of those walkers without some of the low-level helpers. Move some of them to the header file to allow re-use from other places.

[PATCH v4 16/21] KVM: arm64: Enable retrieving protections attributes of PTEs

2021-08-09 Thread Quentin Perret
Introduce helper functions in the KVM stage-2 and stage-1 page-table manipulation library allowing to retrieve the enum kvm_pgtable_prot of a PTE. This will be useful to implement custom walkers outside of pgtable.c. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_pgtable.h | 20

[PATCH v4 01/21] KVM: arm64: Add hyp_spin_is_locked() for basic locking assertions at EL2

2021-08-09 Thread Quentin Perret
From: Will Deacon Introduce hyp_spin_is_locked() so that functions can easily assert that a given lock is held (albeit possibly by another CPU!) without having to drag full lockdep support up to EL2. Signed-off-by: Will Deacon Signed-off-by: Quentin Perret ---

[PATCH v4 14/21] KVM: arm64: Expose pkvm_hyp_id

2021-08-09 Thread Quentin Perret
Allow references to the hypervisor's owner id from outside mem_protect.c. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 ++ arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git

[PATCH v4 03/21] KVM: arm64: Provide the host_stage2_try() helper macro

2021-08-09 Thread Quentin Perret
We currently unmap all MMIO mappings from the host stage-2 to recycle the pages whenever we run out. In order to make this pattern easy to re-use from other places, factor the logic out into a dedicated macro. While at it, apply the macro for the kvm_pgtable_stage2_set_owner() calls. They're

[PATCH v4 11/21] KVM: arm64: Allow populating software bits

2021-08-09 Thread Quentin Perret
Introduce infrastructure allowing to manipulate software bits in stage-1 and stage-2 page-tables using additional entries in the kvm_pgtable_prot enum. This is heavily inspired by Marc's implementation of a similar feature in the NV patch series, but adapted to allow stage-1 changes as well:

[PATCH v4 12/21] KVM: arm64: Add helpers to tag shared pages in SW bits

2021-08-09 Thread Quentin Perret
We will soon start annotating shared pages in page-tables in nVHE protected mode. Define all the states in which a page can be (owned, shared and owned, shared and borrowed), and provide helpers allowing to convert this into SW bits annotations using the matching prot attributes. Reviewed-by:

[PATCH v4 02/21] KVM: arm64: Introduce hyp_assert_lock_held()

2021-08-09 Thread Quentin Perret
Introduce a poor man's lockdep implementation at EL2 which allows to BUG() whenever a hyp spinlock is not held when it should. Hide this feature behind a new Kconfig option that targets the EL2 object specifically, instead of piggy backing on the existing CONFIG_LOCKDEP. EL2 cannot WARN() cleanly

[PATCH v4 00/21] Track shared pages at EL2 in protected mode

2021-08-09 Thread Quentin Perret
Hi all, This is v4 of the patch series previously posted here: https://lore.kernel.org/lkml/20210729132818.4091769-1-qper...@google.com/ This series aims to improve how the nVHE hypervisor tracks ownership of memory pages when running in protected mode ("kvm-arm.mode=protected" on the kernel

[PATCH v4 07/21] KVM: arm64: Rename KVM_PTE_LEAF_ATTR_S2_IGNORED

2021-08-09 Thread Quentin Perret
The ignored bits for both stage-1 and stage-2 page and block descriptors are in [55:58], so rename KVM_PTE_LEAF_ATTR_S2_IGNORED to make it applicable to both. And while at it, since these bits are more commonly known as 'software' bits, rename accordingly. Reviewed-by: Fuad Tabba Signed-off-by:

[PATCH v4 06/21] KVM: arm64: Optimize host memory aborts

2021-08-09 Thread Quentin Perret
The kvm_pgtable_stage2_find_range() function is used in the host memory abort path to try and look for the largest block mapping that can be used to map the faulting address. In order to do so, the function currently walks the stage-2 page-table and looks for existing incompatible mappings within

Re: [PATCH v3] memblock: make memblock_find_in_range method private

2021-08-09 Thread Guenter Roeck
256M of memory. It is also seen with almost all 32-bit efi boots. The problem is not seen when booting without efi. Guenter --- Bisect log: # bad: [da454ebf578f6c542ba9f5b3ddb98db3ede109c1] Add linux-next specific files for 20210809 # good: [36a21d51725af2ce0700c6ebcb6b9594aac658a6] Lin

RE: [PATCH v3 4/4] KVM: arm64: Clear active_vmids on vCPU schedule out

2021-08-09 Thread Shameerali Kolothum Thodi
> -Original Message- > From: Will Deacon [mailto:w...@kernel.org] > Sent: 09 August 2021 14:09 > To: Shameerali Kolothum Thodi > Cc: linux-arm-ker...@lists.infradead.org; kvmarm@lists.cs.columbia.edu; > linux-ker...@vger.kernel.org; m...@kernel.org; catalin.mari...@arm.com; >

Re: [PATCH v3 4/4] KVM: arm64: Clear active_vmids on vCPU schedule out

2021-08-09 Thread Will Deacon
On Fri, Aug 06, 2021 at 12:24:36PM +, Shameerali Kolothum Thodi wrote: > These are some test numbers with and without this patch, run on two > different test setups. > > > a)Test Setup -1 > --- > > Platform: HiSilicon D06 with 128 CPUs, VMID bits = 16 > Run 128 VMs