[PATCH v7 2/4] KVM: arm64: Introduce mm_ops member for structure stage2_attr_data

2021-06-17 Thread Yanan Wang
Also add a mm_ops member for structure stage2_attr_data, since we will move I-cache maintenance for guest stage-2 to the permission path and as a result will need mm_ops for some callbacks. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 10 ++ 1 file changed, 6 insertions

[PATCH v7 3/4] KVM: arm64: Tweak parameters of guest cache maintenance functions

2021-06-17 Thread Yanan Wang
Adjust the parameter "kvm_pfn_t pfn" of __clean_dcache_guest_page and __invalidate_icache_guest_page to "void *va", which paves the way for converting these two guest CMO functions into callbacks in structure kvm_pgtable_mm_ops. No functional change. Signed-off-by: Yanan W

[PATCH v7 4/4] KVM: arm64: Move guest CMOs to the fault handlers

2021-06-17 Thread Yanan Wang
migration, the heavy workload will be resumed on the destination VM, however all the stage-2 page tables need to be rebuilt at the moment. So this solution will ease the performance drop during resuming stage. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 38

[PATCH v7 1/4] KVM: arm64: Introduce two cache maintenance callbacks

2021-06-17 Thread Yanan Wang
To prepare for performing CMOs for guest stage-2 in the fault handlers in pgtable.c, here introduce two cache maintenance callbacks in struct kvm_pgtable_mm_ops. We also adjust the comment alignment for the existing part but make no real content change at all. Signed-off-by: Yanan Wang --- arch

[PATCH v7 0/4] KVM: arm64: Improve efficiency of stage2 page table

2021-06-17 Thread Yanan Wang
35760-1-wangyana...@huawei.com/ v4->v5: - rebased on the latest kvmarm/tree to adapt to the new stage-2 page-table code - v4: https://lore.kernel.org/lkml/20210409033652.28316-1-wangyana...@huawei.com --- Yanan Wang (4): KVM: arm64: Introduce two cache maintenance callbacks KVM: arm64: Intr

[PATCH v6 4/4] KVM: arm64: Move guest CMOs to the fault handlers

2021-06-16 Thread Yanan Wang
migration, the heavy workload will be resumed on the destination VM, however all the stage-2 page tables need to be rebuilt at the moment. So this solution will ease the performance drop during resuming stage. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 37

[PATCH v6 0/4] KVM: arm64: Improve efficiency of stage2 page table

2021-06-16 Thread Yanan Wang
uentin) - rebased on latest kvmarm/tree - v5: https://lore.kernel.org/lkml/20210415115032.35760-1-wangyana...@huawei.com/ v4->v5: - rebased on the latest kvmarm/tree to adapt to the new stage-2 page-table code - v4: https://lore.kernel.org/lkml/20210409033652.28316-1-wangyana...@huawei.com ---

[PATCH v6 1/4] KVM: arm64: Introduce cache maintenance callbacks for guest stage-2

2021-06-16 Thread Yanan Wang
To prepare for performing guest CMOs in the fault handlers in pgtable.c, introduce two cache maintenance callbacks in struct kvm_pgtable_mm_ops. The new callbacks are specific for guest stage-2, so they will only be initialized in 'struct kvm_pgtable_mm_ops kvm_s2_mm_ops'. Signed-off-by: Yanan

[PATCH v6 3/4] KVM: arm64: Tweak parameters of guest cache maintenance functions

2021-06-16 Thread Yanan Wang
Adjust the parameter "kvm_pfn_t pfn" of __clean_dcache_guest_page and __invalidate_icache_guest_page to "void *va", which paves the way for converting these two guest CMO functions into callbacks in structure kvm_pgtable_mm_ops. No functional change. Signed-off-by: Yanan W

[PATCH v6 2/4] KVM: arm64: Introduce mm_ops member for structure stage2_attr_data

2021-06-16 Thread Yanan Wang
Also add a mm_ops member for structure stage2_attr_data, since we will move I-cache maintenance for guest stage-2 to the permission path and as a result will need mm_ops for some callbacks. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 10 ++ 1 file changed, 6 insertions

[PATCH v2] KVM: arm64: Fix inconsistency from function comment of __unmap_stage2_range

2021-06-15 Thread Yanan Wang
tewak some comment identation by using tabs instead of spaces to be consistent with the other functions. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index

[PATCH] KVM: arm64: Fix inconsistency from function comment of __unmap_stage2_range

2021-06-15 Thread Yanan Wang
tewak some comment identation by using tabs instead of spaces to be consistent with the other functions. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index

[PATCH] KVM: arm64: Trival coding style fixes for all vgic-related files

2021-06-14 Thread Yanan Wang
lines. Signed-off-by: Yanan Wang --- arch/arm64/kvm/vgic/vgic-debug.c | 6 +++--- arch/arm64/kvm/vgic/vgic-init.c | 1 - arch/arm64/kvm/vgic/vgic-irqfd.c | 4 ++-- arch/arm64/kvm/vgic/vgic-its.c| 20 +--- arch/arm64/kvm/vgic/vgic-kvm-device.c | 2 +- arch

[PATCH v5 6/6] KVM: arm64: Distinguish cases of memcache allocations completely

2021-04-15 Thread Yanan Wang
the existing leaf entry instead of collapsing a block entry into a table. By comparing fault_granule and vma_pagesize, cases that require allocations from memcache and cases that don't can be distinguished completely. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 25 - 1

[PATCH v5 5/6] KVM: arm64: Move I-cache flush to the fault handlers

2021-04-15 Thread Yanan Wang
an executable permission to the existing guest stage-2 mapping. Signed-off-by: Yanan Wang --- arch/arm64/include/asm/kvm_mmu.h | 15 -- arch/arm64/kvm/hyp/pgtable.c | 35 +++- arch/arm64/kvm/mmu.c | 9 +--- 3 files changed, 35 insertions

[PATCH v5 3/6] KVM: arm64: Add mm_ops member for structure stage2_attr_data

2021-04-15 Thread Yanan Wang
Also add a mm_ops member for structure stage2_attr_data, since we will move I-cache maintenance for guest stage-2 to the permission path and as a result will need mm_ops for address transformation. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 10 ++ 1 file changed, 6

[PATCH v5 4/6] KVM: arm64: Provide invalidate_icache_range at non-VHE EL2

2021-04-15 Thread Yanan Wang
EL2 code for pKVM mode. In this patch, we only introduce symbol of invalidate_icache_range with no real functionality in nvhe/cache.S, because there haven't been situations found currently where I-cache maintenance is also needed in non-VHE EL2 for pKVM mode. Signed-off-by: Yanan Wang --- arch

[PATCH v5 1/6] KVM: arm64: Introduce KVM_PGTABLE_S2_GUEST stage-2 flag

2021-04-15 Thread Yanan Wang
the KVM_PGTABLE_S2_GUEST flag to determine if we are doing something about guest stage-2. This flag will be used in a coming patch, in which we will move CMOs for guest to pgtable.c. Signed-off-by: Yanan Wang --- arch/arm64/include/asm/kvm_pgtable.h | 38 ++-- arch/arm64/kvm/mmu.c

[PATCH v5 2/6] KVM: arm64: Move D-cache flush to the fault handlers

2021-04-15 Thread Yanan Wang
and improve efficiency of the page table code. This patch only moves clean of D-cache to the map path, and drop the original APIs in mmu.c/mmu.h for D-cache maintenance by using what we already have in pgtable.c. Change about the I-side will come from a later patch. Signed-off-by: Yanan Wang --- arch

[PATCH v5 0/6] KVM: arm64: Improve efficiency of stage2 page table

2021-04-15 Thread Yanan Wang
t v2 based on v5.12-rc2 - v1: https://lore.kernel.org/lkml/20210208112250.163568-1-wangyana...@huawei.com/ --- Yanan Wang (6): KVM: arm64: Introduce KVM_PGTABLE_S2_GUEST stage-2 flag KVM: arm64: Move D-cache flush to the fault handlers KVM: arm64: Add mm_ops member for structure stage2_attr_data KVM: ar

[PATCH v4 0/2] KVM: arm64: Improve efficiency of stage2 page table

2021-04-08 Thread Yanan Wang
t_granule and vma_pagesize, cases that require allocations from memcache and cases that don't can be distinguished completely. Yanan Wang (2): KVM: arm64: Move CMOs from user_mem_abort to the fault handlers KVM: arm64: Distinguish cases of memcache allocations completely arch

[PATCH v4 2/2] KVM: arm64: Distinguish cases of memcache allocations completely

2021-04-08 Thread Yanan Wang
the existing leaf entry instead of collapsing a block entry into a table. By comparing fault_granule and vma_pagesize, cases that require allocations from memcache and cases that don't can be distinguished completely. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 25 - 1

[PATCH v4 1/2] KVM: arm64: Move CMOs from user_mem_abort to the fault handlers

2021-04-08 Thread Yanan Wang
to pgtable.c. Signed-off-by: Yanan Wang --- arch/arm64/include/asm/kvm_mmu.h | 31 --- arch/arm64/kvm/hyp/pgtable.c | 68 +--- arch/arm64/kvm/mmu.c | 23 ++- 3 files changed, 57 insertions(+), 65 deletions(-) diff --git a/arch/arm64/include

[RFC PATCH v3 1/2] KVM: arm64: Move CMOs from user_mem_abort to the fault handlers

2021-03-25 Thread Yanan Wang
to pgtable.c. Signed-off-by: Yanan Wang --- arch/arm64/include/asm/kvm_mmu.h | 31 --- arch/arm64/kvm/hyp/pgtable.c | 68 +--- arch/arm64/kvm/mmu.c | 23 ++- 3 files changed, 57 insertions(+), 65 deletions(-) diff --git a/arch/arm64/include

[RFC PATCH v3 0/2] KVM: arm64: Improve efficiency of stage2 page table

2021-03-25 Thread Yanan Wang
-> after 115.94s +33.44% KVM_REBUILD_BLOCKS: before 103.95s -> after 2.96s +97.15% Patch #2: A new method to distinguish cases of memcache allocations is introduced. By comparing fault_granule and vma_pagesize, cases that require allocations from memcache and cases that don't can be di

[RFC PATCH v3 2/2] KVM: arm64: Distinguish cases of memcache allocations completely

2021-03-25 Thread Yanan Wang
the existing leaf entry instead of collapsing a block entry into a table. By comparing fault_granule and vma_pagesize, cases that require allocations from memcache and cases that don't can be distinguished completely. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 25 - 1

[RFC PATCH v2 3/3] KVM: arm64: Distinguish cases of memcache allocations completely

2021-03-10 Thread Yanan Wang
the existing leaf entry instead of collapsing a block entry into a table. By comparing fault_granule and vma_pagesize, cases that require allocations from memcache and cases that don't can be distinguished completely. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 25 - 1

[RFC PATCH v2 1/3] KVM: arm64: Move CMOs from user_mem_abort to the fault handlers

2021-03-10 Thread Yanan Wang
clean of D-cache and invalidation of I-cache to the map path and move only invalidation of I-cache to the permission path. Since the original APIs for CMOs in mmu.c are only called in function user_mem_abort, we now also move them to pgtable.c. Signed-off-by: Yanan Wang --- arch/arm64/include/asm

[RFC PATCH v2 2/3] KVM: arm64: Install the block entry before unmapping the page mappings

2021-03-10 Thread Yanan Wang
translation faults. After this patch the steps can be like: 1) invalidate the table entry in the PMD/PUD table 2) flush TLB by VMID 3) install the new block entry to the PMD/PUD table 4) unmap the old sub-level tables Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 44

[RFC PATCH v2 0/3] KVM: arm64: Improve efficiency of stage2 page table

2021-03-10 Thread Yanan Wang
ew method to distinguish cases of memcache allocations is introduced. By comparing fault_granule and vma_pagesize, cases that require allocations from memcache and cases that don't can be distinguished completely. --- Yanan Wang (3): KVM: arm64: Move CMOs from user_mem_abort to the fault hand

[RFC PATCH 4/4] KVM: arm64: Distinguish cases of memcache allocations completely

2021-02-08 Thread Yanan Wang
the existing leaf entry instead of collapsing a block entry into a table. By comparing fault_granule and vma_pagesize, cases that require allocations from memcache and cases that don't can be distinguished completely. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 25 - 1

[RFC PATCH 2/4] KVM: arm64: Add an independent API for coalescing tables

2021-02-08 Thread Yanan Wang
Process of coalescing page mappings back to a block mapping is different from normal map path, such as TLB invalidation and CMOs, so here add an independent API for this case. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 18 ++ 1 file changed, 18 insertions

[RFC PATCH 3/4] KVM: arm64: Install the block entry before unmapping the page mappings

2021-02-08 Thread Yanan Wang
of the unnecessary translation faults. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 26 -- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 78a560446f80..308c36b9cd21 100644 --- a/arch

[RFC PATCH 0/4] KVM: arm64: Improve efficiency of stage2 page table

2021-02-08 Thread Yanan Wang
appings(granule 1G)) Before patch: KVM_ADJUST_MAPPINGS: 2.9621s 2.9648s 2.9474s 2.9587s 2.9603s After patch: KVM_ADJUST_MAPPINGS: 0.3541s 0.3694s 0.3656s 0.3693s 0.3687s --- Yanan Wang (4): KVM: arm64: Move the clean of dcache to the map handler KVM: arm64: Add an independent API for coalescing t

[RFC PATCH 1/4] KVM: arm64: Move the clean of dcache to the map handler

2021-02-08 Thread Yanan Wang
the efficiency of creating mappings. Signed-off-by: Yanan Wang --- arch/arm64/include/asm/kvm_mmu.h | 16 -- arch/arm64/kvm/hyp/pgtable.c | 38 arch/arm64/kvm/mmu.c | 14 +++- 3 files changed, 27 insertions(+), 41 deletions(-) diff --git

[RFC PATCH v1 0/5] Enable CPU TTRem feature for stage-2

2021-01-26 Thread Yanan Wang
with the second kind of implementation, the above described spurious translations can be prevented. Yanan Wang (5): KVM: arm64: Detect the ARMv8.4 TTRem feature KVM: arm64: Add an API to get level of TTRem supported by hardware KVM: arm64: Support usage of TTRem in guest stage-2 translation KVM

[RFC PATCH v1 2/5] arm64: cpufeature: Add an API to get level of TTRem supported by hardware

2021-01-26 Thread Yanan Wang
. Signed-off-by: Yanan Wang --- arch/arm64/include/asm/cpufeature.h | 13 + 1 file changed, 13 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 9a555809b89c..f8ee7d30829b 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch

[RFC PATCH v1 4/5] KVM: arm64: Add handling of coalescing tables into a block mapping

2021-01-26 Thread Yanan Wang
conflict which is bothering, so we use nT both at level-1 and level-2 case to avoid handling TLB conflict aborts. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 35 +++ 1 file changed, 35 insertions(+) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch

[RFC PATCH v1 3/5] KVM: arm64: Support usage of TTRem in guest stage-2 translation

2021-01-26 Thread Yanan Wang
As TTrem can be used when coalesce existing table mappings into a block in guest stage-2 translation, so just support usage of it. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp

[RFC PATCH v1 1/5] arm64: cpufeature: Detect the ARMv8.4 TTRem feature

2021-01-26 Thread Yanan Wang
the performance in guest stage-2 translation. So detact the TTRem feature here. Signed-off-by: Yanan Wang --- arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/kernel/cpufeature.c | 10 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/cpucaps.h b/arch

[RFC PATCH v1 5/5] KVM: arm64: Adapt page-table code to new handling of coalescing tables

2021-01-26 Thread Yanan Wang
With new handling of coalescing tables, we can install the block entry before unmap of the old table mappings. So make the installation in stage2_map_walk_table_pre(), and elide the installation from function stage2_map_walk_table_post(). Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp

[PATCH 0/2] Performance improvement about cache flush

2021-01-25 Thread Yanan Wang
be skipped. Yanan Wang (2): KVM: arm64: Distinguish cases of allocating memcache more precisely KVM: arm64: Skip the cache flush when coalescing tables into a block arch/arm64/kvm/mmu.c | 37 + 1 file changed, 21 insertions(+), 16 deletions(-) -- 2.19.1

[PATCH 1/2] KVM: arm64: Distinguish cases of allocating memcache more precisely

2021-01-25 Thread Yanan Wang
if VMs are not configured with huge mappings. The cases where allocations from memcache are required can be much more precisely distinguished by comparing fault_granule and vma_pagesize. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 25 - 1 file changed, 12 insertions

[PATCH 2/2] KVM: arm64: Skip the cache flush when coalescing tables into a block

2021-01-25 Thread Yanan Wang
-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 12 +--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 8e8549ea1d70..37b427dcbc4f 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -744,7 +744,7 @@ static int

[RFC PATCH v4 0/2] Some optimization for stage-2 translation

2021-01-22 Thread Yanan Wang
Add a new patch (patch-3) --- Yanan Wang (2): KVM: arm64: Adjust partial code of hyp stage-1 map and guest stage-2 map KVM: arm64: Filter out the case of only changing permissions from stage-2 map path arch/arm64/include/asm/kvm_pgtable.h | 4 ++ arch/arm64/kvm/hyp/pgtable.c

[RFC PATCH v4 2/2] KVM: arm64: Filter out the case of only changing permissions from stage-2 map path

2021-01-22 Thread Yanan Wang
change access permissions that don't require break-before-make. If there have already been the permissions we want, don't bother to update. If still more permissions need to be added, then update the PTE directly without break-before-make. Signed-off-by: Yanan Wang --- arch/arm64/include/asm

[RFC PATCH v4 1/2] KVM: arm64: Adjust partial code of hyp stage-1 map and guest stage-2 map

2021-01-22 Thread Yanan Wang
Procedures of hyp stage-1 map and guest stage-2 map are quite different, but they are tied closely by function kvm_set_valid_leaf_pte(). So adjust the relative code for ease of code maintenance in the future. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 54

[PATCH v3 1/3] KVM: arm64: Adjust partial code of hyp stage-1 map and guest stage-2 map

2021-01-14 Thread Yanan Wang
Procedures of hyp stage-1 map and guest stage-2 map are quite different, but they are tied closely by function kvm_set_valid_leaf_pte(). So adjust the relative code for ease of code maintenance in the future. Signed-off-by: Will Deacon Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c

[PATCH v3 2/3] KVM: arm64: Filter out the case of only changing permissions from stage-2 map path

2021-01-14 Thread Yanan Wang
permissions, and don't update the valid leaf PTE here in this case. Instead, let the vCPU enter back the guest and it will exit next time to go through the relax_perms path without break-before-make if it still wants more permissions. Signed-off-by: Yanan Wang --- arch/arm64/include/asm/kvm_pgtable.h

[PATCH v3 0/3] Some optimization for stage-2 translation

2021-01-14 Thread Yanan Wang
anging permissions case in map path - Add a new patch (patch-3) - v1: https://lore.kernel.org/lkml/20201211080115.21460-1-wangyana...@huawei.com/ --- Yanan Wang (3): KVM: arm64: Adjust partial code of hyp stage-1 map and guest stage-2 map KVM: arm64: Filter out the case of only changing permission

[PATCH v3 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully

2021-01-14 Thread Yanan Wang
been handled successfully. When an -EAGAIN errno is returned from the map handler, we hope to the vcpu to enter guest directly instead of exiting back to userspace, so adjust the return value at the end of function. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 13 - 1 file