[PATCH] KVM: selftests: Tweak time measurement flag in kvm_page_table_test

2021-04-19 Thread Yanan Wang
Also use CLOCK_MONOTONIC flag to get time in kvm_page_table_test.c, since that's what all the kvm/selftests do currently. And this will be consistent with function timespec_elapsed() in test_util.c. Signed-off-by: Yanan Wang --- tools/testing/selftests/kvm/kvm_page_table_test.c | 8 --

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

2021-04-15 Thread Yanan Wang
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 ---

[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 ---

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

2021-04-15 Thread Yanan Wang
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 0/6] KVM: arm64: Improve efficiency of stage2 page table

2021-04-15 Thread Yanan Wang
retest 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 KV

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

2021-04-15 Thread Yanan Wang
m 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 ---

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

2021-04-15 Thread Yanan Wang
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 v4 1/2] KVM: arm64: Move CMOs from user_mem_abort to the fault handlers

2021-04-08 Thread Yanan Wang
ve them 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/arm

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

2021-04-08 Thread Yanan Wang
aring fault_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 co

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

2021-04-08 Thread Yanan Wang
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 ---

[PATCH v6 08/10] KVM: selftests: List all hugetlb src types specified with page sizes

2021-03-30 Thread Yanan Wang
that we want. And as all the known hugetlb page sizes are listed, it's appropriate for all architectures. Besides, the helper get_backing_src_pagesz() is added to get the granularity of different backing src types(anonumous, thp, hugetlb). Suggested-by: Ben Gardon Signed-off-by: Yanan

[PATCH v6 10/10] KVM: selftests: Add a test for kvm page table code

2021-03-30 Thread Yanan Wang
to dirty logging stopped of a VM with block mappings, so it can also reproduce this TLB conflict abort due to inadequate TLB invalidation when coalescing tables. Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/.gitignore| 1

[PATCH v6 05/10] KVM: selftests: Make a generic helper to get vm guest mode strings

2021-03-30 Thread Yanan Wang
For generality and conciseness, make an API which can be used in all kvm libs and selftests to get vm guest mode strings. And the index i is checked in the API in case of possiable faults. Suggested-by: Sean Christopherson Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon Reviewed-by: Andrew

[PATCH v6 07/10] KVM: selftests: Add a helper to get system default hugetlb page size

2021-03-30 Thread Yanan Wang
d and then get the default page size by reading /proc/meminfo. This helper can be useful when a program wants to use the default hugetlb pages of the system and doesn't know the default page size. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- .../testing/selftests/kvm/include/t

[PATCH v6 09/10] KVM: selftests: Adapt vm_userspace_mem_region_add to new helpers

2021-03-30 Thread Yanan Wang
architectures may have different THP page sizes configured, this can get the accurate THP page sizes on any platform. Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/lib/kvm_util.c | 28 +++--- 1 file changed, 9 insertions

[PATCH v6 06/10] KVM: selftests: Add a helper to get system configured THP page size

2021-03-30 Thread Yanan Wang
. Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon Reviewed-by: Andrew Jones --- .../testing/selftests/kvm/include/test_util.h | 2 ++ tools/testing/selftests/kvm/lib/test_util.c | 29 +++ 2 files changed, 31 insertions(+) diff --git a/tools/testing/selftests/kvm/include

[PATCH v6 04/10] KVM: selftests: Print the errno besides error-string in TEST_ASSERT

2021-03-30 Thread Yanan Wang
Print the errno besides error-string in TEST_ASSERT in the format of "errno=%d - %s" will explicitly indicate that the string is an error information. Besides, the errno is easier to be used for debugging than the error-string. Suggested-by: Andrew Jones Signed-off-by: Yanan Wang R

[PATCH v6 02/10] mm/hugetlb: Add a macro to get HUGETLB page sizes for mmap

2021-03-30 Thread Yanan Wang
corresponding hugetlb page size, using flag x. Cc: Ben Gardon Cc: Ingo Molnar Cc: Adrian Hunter Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: Arnd Bergmann Cc: Michael Kerrisk Cc: Thomas Gleixner Suggested-by: Ben Gardon Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- include/uapi

[PATCH v6 01/10] tools/headers: sync headers of asm-generic/hugetlb_encode.h

2021-03-30 Thread Yanan Wang
, but not tools/include/asm-generic/hugetlb_encode.h. Cc: Ingo Molnar Cc: Adrian Hunter Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- tools/include/asm-generic/hugetlb_encode.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/include

[PATCH v6 03/10] KVM: selftests: Use flag CLOCK_MONOTONIC_RAW for timing

2021-03-30 Thread Yanan Wang
In addition to function of CLOCK_MONOTONIC, flag CLOCK_MONOTONIC_RAW can also shield possiable impact of NTP, which can provide more robustness. Suggested-by: Vitaly Kuznetsov Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm

[PATCH v6 00/10] KVM: selftests: some improvement and a new test for kvm page table

2021-03-30 Thread Yanan Wang
patch to sync header files - Add helpers to get granularity of different backing src types - Some changes for suggestions about v1 series - v1: https://lore.kernel.org/lkml/20210208090841.333724-1-wangyana...@huawei.com/ --- Yanan Wang (10): tools headers: sync headers of asm-generic/hugetlb_e

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

2021-03-25 Thread Yanan Wang
before 174.20s -> 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

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

2021-03-25 Thread Yanan Wang
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 ---

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

2021-03-25 Thread Yanan Wang
ve them 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/arm

[RFC PATCH v5 07/10] KVM: selftests: Add a helper to get system default hugetlb page size

2021-03-23 Thread Yanan Wang
d and then get the default page size by reading /proc/meminfo. This helper can be useful when a program wants to use the default hugetlb pages of the system and doesn't know the default page size. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- .../testing/selftests/kvm/include/t

[RFC PATCH v5 09/10] KVM: selftests: Adapt vm_userspace_mem_region_add to new helpers

2021-03-23 Thread Yanan Wang
architectures may have different THP page sizes configured, this can get the accurate THP page sizes on any platform. Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/lib/kvm_util.c | 28 +++--- 1 file changed, 9 insertions

[RFC PATCH v5 10/10] KVM: selftests: Add a test for kvm page table code

2021-03-23 Thread Yanan Wang
to dirty logging stopped of a VM with block mappings, so it can also reproduce this TLB conflict abort due to inadequate TLB invalidation when coalescing tables. Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/.gitignore| 1 + tools/testing/selftests/kvm/

[RFC PATCH v5 08/10] KVM: selftests: List all hugetlb src types specified with page sizes

2021-03-23 Thread Yanan Wang
that we want. And as all the known hugetlb page sizes are listed, it's appropriate for all architectures. Besides, the helper get_backing_src_pagesz() is added to get the granularity of different backing src types(anonumous, thp, hugetlb). Suggested-by: Ben Gardon Signed-off-by: Yanan

[RFC PATCH v5 06/10] KVM: selftests: Add a helper to get system configured THP page size

2021-03-23 Thread Yanan Wang
. Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- .../testing/selftests/kvm/include/test_util.h | 2 ++ tools/testing/selftests/kvm/lib/test_util.c | 29 +++ 2 files changed, 31 insertions(+) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing

[RFC PATCH v5 04/10] KVM: selftests: Print the errno besides error-string in TEST_ASSERT

2021-03-23 Thread Yanan Wang
Print the errno besides error-string in TEST_ASSERT in the format of "errno=%d - %s" will explicitly indicate that the string is an error information. Besides, the errno is easier to be used for debugging than the error-string. Suggested-by: Andrew Jones Signed-off-by: Yanan Wang

[RFC PATCH v5 02/10] tools headers: Add a macro to get HUGETLB page sizes for mmap

2021-03-23 Thread Yanan Wang
corresponding hugetlb page size, using flag x. Cc: Ben Gardon Cc: Ingo Molnar Cc: Adrian Hunter Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: Arnd Bergmann Cc: Michael Kerrisk Cc: Thomas Gleixner Suggested-by: Ben Gardon Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- include/uapi/linux

[RFC PATCH v5 03/10] KVM: selftests: Use flag CLOCK_MONOTONIC_RAW for timing

2021-03-23 Thread Yanan Wang
In addition to function of CLOCK_MONOTONIC, flag CLOCK_MONOTONIC_RAW can also shield possiable impact of NTP, which can provide more robustness. Suggested-by: Vitaly Kuznetsov Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm

[RFC PATCH v5 05/10] KVM: selftests: Make a generic helper to get vm guest mode strings

2021-03-23 Thread Yanan Wang
For generality and conciseness, make an API which can be used in all kvm libs and selftests to get vm guest mode strings. And the index i is checked in the API in case of possiable faults. Suggested-by: Sean Christopherson Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones Reviewed-by: Ben

[RFC PATCH v5 01/10] tools headers: sync headers of asm-generic/hugetlb_encode.h

2021-03-23 Thread Yanan Wang
, but not tools/include/asm-generic/hugetlb_encode.h. Cc: Ingo Molnar Cc: Adrian Hunter Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- tools/include/asm-generic/hugetlb_encode.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/include

[RFC PATCH v5 00/10] KVM: selftests: some improvement and a new test for kvm page table

2021-03-23 Thread Yanan Wang
/20210225055940.18748-1-wangyana...@huawei.com/ v1->v2: - Add a patch to sync header files - Add helpers to get granularity of different backing src types - Some changes for suggestions about v1 series - v1: https://lore.kernel.org/lkml/20210208090841.333724-1-wangyana...@huawei.com/ --- Yan

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

2021-03-10 Thread Yanan Wang
ssary 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

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

2021-03-10 Thread Yanan Wang
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 ---

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

2021-03-10 Thread Yanan Wang
move both 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/i

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

2021-03-10 Thread Yanan Wang
ut patch 3: 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 distinguished completely. --- Yanan Wang (3): KVM: arm64: Move CMOs from user_mem_abo

[RFC PATCH v4 7/9] KVM: selftests: List all hugetlb src types specified with page sizes

2021-03-02 Thread Yanan Wang
that we want. And as all the known hugetlb page sizes are listed, it's appropriate for all architectures. Besides, the helper get_backing_src_pagesz() is added to get the granularity of different backing src types(anonumous, thp, hugetlb). Suggested-by: Ben Gardon Signed-off-by: Yanan

[RFC PATCH v4 4/9] KVM: selftests: Make a generic helper to get vm guest mode strings

2021-03-02 Thread Yanan Wang
For generality and conciseness, make an API which can be used in all kvm libs and selftests to get vm guest mode strings. And the index i is checked in the API in case of possiable faults. Suggested-by: Sean Christopherson Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones Reviewed-by: Ben

[RFC PATCH v4 3/9] KVM: selftests: Use flag CLOCK_MONOTONIC_RAW for timing

2021-03-02 Thread Yanan Wang
In addition to function of CLOCK_MONOTONIC, flag CLOCK_MONOTONIC_RAW can also shield possiable impact of NTP, which can provide more robustness. Suggested-by: Vitaly Kuznetsov Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/demand_paging_test.c | 8

[RFC PATCH v4 0/9] KVM: selftests: some improvement and a new test for kvm page table

2021-03-02 Thread Yanan Wang
t;v3: - Add tags of Suggested-by, Reviewed-by in the patches - Add a generic micro to get hugetlb page sizes - Some changes for suggestions about v2 series v1->v2: - Add a patch to sync header files - Add helpers to get granularity of different backing src types - Some changes for suggestions about

[RFC PATCH v4 6/9] KVM: selftests: Add a helper to get system default hugetlb page size

2021-03-02 Thread Yanan Wang
d and then get the default page size by reading /proc/meminfo. This helper can be useful when a program wants to use the default hugetlb pages of the system and doesn't know the default page size. Signed-off-by: Yanan Wang --- .../testing/selftests/kvm/include/test_util.h | 1 + too

[RFC PATCH v4 2/9] tools headers: Add a macro to get HUGETLB page sizes for mmap

2021-03-02 Thread Yanan Wang
corresponding hugetlb page size, using flag x. Cc: Ben Gardon Cc: Ingo Molnar Cc: Adrian Hunter Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: Arnd Bergmann Cc: Michael Kerrisk Cc: Thomas Gleixner Suggested-by: Ben Gardon Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- include/uapi/linux

[RFC PATCH v4 1/9] tools headers: sync headers of asm-generic/hugetlb_encode.h

2021-03-02 Thread Yanan Wang
, but not tools/include/asm-generic/hugetlb_encode.h. Cc: Ingo Molnar Cc: Adrian Hunter Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- tools/include/asm-generic/hugetlb_encode.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/include

[RFC PATCH v4 9/9] KVM: selftests: Add a test for kvm page table code

2021-03-02 Thread Yanan Wang
to dirty logging stopped of a VM with block mappings, so it can also reproduce this TLB conflict abort due to inadequate TLB invalidation when coalescing tables. Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/Makefile | 3 + .../selft

[RFC PATCH v4 8/9] KVM: selftests: Adapt vm_userspace_mem_region_add to new helpers

2021-03-02 Thread Yanan Wang
architectures may have different THP page sizes configured, this can get the accurate THP page sizes on any platform. Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/lib/kvm_util.c | 28 +++--- 1 file changed, 9 insertions(+), 19 deletions(-) diff

[RFC PATCH v4 5/9] KVM: selftests: Add a helper to get system configured THP page size

2021-03-02 Thread Yanan Wang
. Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- .../testing/selftests/kvm/include/test_util.h | 2 ++ tools/testing/selftests/kvm/lib/test_util.c | 36 +++ 2 files changed, 38 insertions(+) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing

[RFC PATCH v3 4/8] KVM: selftests: Make a generic helper to get vm guest mode strings

2021-02-28 Thread Yanan Wang
For generality and conciseness, make an API which can be used in all kvm libs and selftests to get vm guest mode strings. And the index i is checked in the API in case of possiable faults. Reviewed-by: Andrew Jones Suggested-by: Sean Christopherson Signed-off-by: Yanan Wang --- .../testing

[RFC PATCH v3 1/8] tools headers: sync headers of asm-generic/hugetlb_encode.h

2021-02-28 Thread Yanan Wang
, but not tools/include/asm-generic/hugetlb_encode.h. Cc: Ingo Molnar Cc: Adrian Hunter Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Signed-off-by: Yanan Wang --- tools/include/asm-generic/hugetlb_encode.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/include/asm-generic

[RFC PATCH v3 6/8] KVM: selftests: List all hugetlb src types specified with page sizes

2021-02-28 Thread Yanan Wang
that we want. And as all the known hugetlb page sizes are listed, it's appropriate for all architectures. Besides, the helper get_backing_src_pagesz() is added to get the granularity of different backing src types(anonumous, thp, hugetlb). Suggested-by: Ben Gardon Signed-off-by: Yanan

[RFC PATCH v3 8/8] KVM: selftests: Add a test for kvm page table code

2021-02-28 Thread Yanan Wang
to dirty logging stopped of a VM with block mappings, so it can also reproduce this TLB conflict abort due to inadequate TLB invalidation when coalescing tables. Signed-off-by: Yanan Wang --- tools/testing/selftests/kvm/Makefile | 3 + .../selftests/kvm/kvm_page_table_test.c

[RFC PATCH v3 0/7] KVM: selftests: some improvement and a new test for kvm page table

2021-02-28 Thread Yanan Wang
Add helpers to get granularity of different backing src types - Some changes for suggestions about v1 series --- Yanan Wang (7): tools headers: sync headers of asm-generic/hugetlb_encode.h tools headers: Add a macro to get HUGETLB page sizes for mmap KVM: selftests: Use flag CLOCK_MONOTONIC_R

[RFC PATCH v3 3/8] KVM: selftests: Use flag CLOCK_MONOTONIC_RAW for timing

2021-02-28 Thread Yanan Wang
In addition to function of CLOCK_MONOTONIC, flag CLOCK_MONOTONIC_RAW can also shield possiable impact of NTP, which can provide more robustness. Suggested-by: Vitaly Kuznetsov Signed-off-by: Yanan Wang --- tools/testing/selftests/kvm/demand_paging_test.c | 8 tools/testing/selftests

[RFC PATCH v3 7/8] KVM: selftests: Adapt vm_userspace_mem_region_add to new helpers

2021-02-28 Thread Yanan Wang
architectures may have different THP page sizes configured, this can get the accurate THP page sizes on any platform. Signed-off-by: Yanan Wang --- tools/testing/selftests/kvm/lib/kvm_util.c | 28 +++--- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/tools/testing

[RFC PATCH v3 5/8] KVM: selftests: Add a helper to get system configured THP page size

2021-02-28 Thread Yanan Wang
. Reviewed-by: Ben Gardon Signed-off-by: Yanan Wang --- .../testing/selftests/kvm/include/test_util.h | 2 ++ tools/testing/selftests/kvm/lib/test_util.c | 36 +++ 2 files changed, 38 insertions(+) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing

[RFC PATCH v3 2/8] tools headers: Add a macro to get HUGETLB page sizes for mmap

2021-02-28 Thread Yanan Wang
corresponding hugetlb page size, using flag x. Cc: Ben Gardon Cc: Ingo Molnar Cc: Adrian Hunter Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: Arnd Bergmann Cc: Michael Kerrisk Cc: Thomas Gleixner Suggested-by: Ben Gardon Signed-off-by: Yanan Wang --- include/uapi/linux/mman.h | 2 ++ tools

[RFC PATCH v2 7/7] KVM: selftests: Add a test for kvm page table code

2021-02-24 Thread Yanan Wang
to dirty logging stopped of a VM with block mappings, so it can also reproduce this TLB conflict abort due to inadequate TLB invalidation when coalescing tables. Signed-off-by: Yanan Wang --- tools/testing/selftests/kvm/Makefile | 3 + .../selftests/kvm/kvm_page_table_test.c

[RFC PATCH v2 6/7] KVM: selftests: Adapt vm_userspace_mem_region_add to new helpers

2021-02-24 Thread Yanan Wang
architectures may have different THP page sizes configured, this can get the accurate THP page sizes on any platform. Signed-off-by: Yanan Wang --- tools/testing/selftests/kvm/lib/kvm_util.c | 27 +++--- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/tools/testing

[RFC PATCH v2 5/7] KVM: selftests: List all hugetlb src types specified with page sizes

2021-02-24 Thread Yanan Wang
that we want. And as all the known hugetlb page sizes are listed, it's appropriate for all architectures. Besides, the helper get_backing_src_pagesz() is added to get the granularity of different backing src types(anonumous, thp, hugetlb). Signed-off-by: Yanan Wang --- .../testing/selftest

[RFC PATCH v2 2/7] KVM: selftests: Use flag CLOCK_MONOTONIC_RAW for timing

2021-02-24 Thread Yanan Wang
In addition to function of CLOCK_MONOTONIC, flag CLOCK_MONOTONIC_RAW can also shield possiable impact of NTP, which can provide more robustness. Signed-off-by: Yanan Wang --- tools/testing/selftests/kvm/demand_paging_test.c | 8 tools/testing/selftests/kvm/dirty_log_perf_test.c | 14

[RFC PATCH v2 3/7] KVM: selftests: Make a generic helper to get vm guest mode strings

2021-02-24 Thread Yanan Wang
For generality and conciseness, make an API which can be used in all kvm libs and selftests to get vm guest mode strings. And the index i is checked in the API in case of possiable faults. Signed-off-by: Yanan Wang --- .../testing/selftests/kvm/include/kvm_util.h | 4 +-- tools/testing

[RFC PATCH v2 1/7] tools include: sync head files of mmap flag encodings about hugetlb

2021-02-24 Thread Yanan Wang
, but not tools/include/asm-generic/hugetlb_encode.h. Signed-off-by: Yanan Wang --- tools/include/asm-generic/hugetlb_encode.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/include/asm-generic/hugetlb_encode.h b/tools/include/asm-generic/hugetlb_encode.h index e4732d3c2998

[RFC PATCH v2 4/7] KVM: selftests: Add a helper to get system configured THP page size

2021-02-24 Thread Yanan Wang
. Signed-off-by: Yanan Wang --- .../testing/selftests/kvm/include/test_util.h | 2 ++ tools/testing/selftests/kvm/lib/test_util.c | 36 +++ 2 files changed, 38 insertions(+) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include

[RFC PATCH v2 0/7] Some improvement and a new test for kvm page table

2021-02-24 Thread Yanan Wang
bled to dirty logging stopped of a VM with block mappings, so it can also reproduce this TLB conflict abort due to inadequate TLB invalidation when coalescing tables. Links about the TLB conflict abort: https://lore.kernel.org/lkml/20201201201034.116760-3-wangyana...@huawei.com/ Yanan Wang (7): tools

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

2021-02-08 Thread Yanan Wang
e 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 --

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

2021-02-08 Thread Yanan Wang
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 ---

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

2021-02-08 Thread Yanan Wang
f 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

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

2021-02-08 Thread Yanan Wang
memory, block mappings(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 f

[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 0/2] Add a test for kvm page table code

2021-02-08 Thread Yanan Wang
Before patch: KVM_ADJUST_MAPPINGS: 103.931s 103.936s 103.927s 103.942s 103.927s After patch: KVM_ADJUST_MAPPINGS: 0.3541s 0.3694s 0.3656s 0.3693s 0.3687s --- Yanan Wang (2): KVM: selftests: Add a macro to get string of vm_mem_backing_src_type KVM: selftests: Add a test for kvm page ta

[RFC PATCH 1/2] KVM: selftests: Add a macro to get string of vm_mem_backing_src_type

2021-02-08 Thread Yanan Wang
Add a macro to get string of the backing source memory type, so that application can add choices for source types in the help() function, and users can specify which type to use for testing. Signed-off-by: Yanan Wang --- tools/testing/selftests/kvm/include/kvm_util.h | 3 +++ tools/testing

[RFC PATCH 2/2] KVM: selftests: Add a test for kvm page table code

2021-02-08 Thread Yanan Wang
abled to dirty-logging stopped of a VM with block mappings, so it can also reproduce this TLB conflict abort due to inadequate TLB invalidation when coalescing tables. Signed-off-by: Yanan Wang --- tools/testing/selftests/kvm/Makefile | 3 + .../selftests/kvm/kvm_page_table_test.c

[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

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

2021-01-26 Thread Yanan Wang
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 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
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 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

[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

[PATCH 0/2] Performance improvement about cache flush

2021-01-25 Thread Yanan Wang
ons can 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
ng time 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

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

2021-01-22 Thread Yanan Wang
sions case in map path - 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/ar

[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

[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
pdate only 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 --- ar

[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
nge access 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/as

[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 0/3] Some optimization for stage-2 translation

2021-01-14 Thread Yanan Wang
meeting changing 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

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

2021-01-14 Thread Yanan Wang
t has 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

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

2020-12-16 Thread Yanan Wang
but not return to userspace if we were trying to recreate the same mapping or only change access permissions with BBM, which is not permitted in the mapping path. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 18 ++ 1 file changed, 14 insertions(+), 4 deletions(-) diff --git

[PATCH v2 0/3] RFC: Solve several problems in stage 2 translation

2020-12-16 Thread Yanan Wang
of the diff as an independent patch (PATCH1/3), and add Will's Signed-off-by. - Use *return -EPERM* way when changing permissions only in the mapping path. - Add a new patch (PATCH3/3). Yanan Wang (3): KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest stage 2 mapping

[PATCH v2 2/3] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler

2020-12-16 Thread Yanan Wang
, change of permissions will be handled through the relax_perms path next time if necessary. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 28 +++- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm

[PATCH v2 1/3] KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest stage 2 mapping

2020-12-16 Thread Yanan Wang
Procedures of hyp stage 1 mapping and guest stage 2 mapping are different, but they are tied closely by function kvm_set_valid_leaf_pte(). So separate them by rewriting kvm_set_valid_leaf_pte(). Signed-off-by: Will Deacon Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 54

[RFC PATCH 0/1] Add prejudgement for relaxing permissions only case

2020-12-11 Thread Yanan Wang
nly. Yanan Wang (1): KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault hand

[RFC PATCH] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler

2020-12-11 Thread Yanan Wang
eak-before-make if we are trying to add more permissions only. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 73 +--- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c in

[PATCH v2 2/3] KVM: arm64: Fix handling of merging tables into a block entry

2020-12-01 Thread Yanan Wang
mappings for the block. Without enough TLBI, multiple TLB entries for the memory in the block will be cached. Signed-off-by: Will Deacon Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b

[PATCH v2 0/3] Fix several bugs in KVM stage 2 translation

2020-12-01 Thread Yanan Wang
can strictly distinguish conditions is introduced in PATCH 3/3. Changes from v1: * In PATCH 1/3, introduce a more concise fix. * In PATCH 2/3, using full S2 TLB invalidation when merging tables into a block entry. Yanan Wang (3): KVM: arm64: Fix possible memory leak in kvm stage2 KVM: arm64

[PATCH v2 3/3] KVM: arm64: Add usage of stage 2 fault lookup level in user_mem_abort()

2020-12-01 Thread Yanan Wang
d-by: Keqian Zhu Signed-off-by: Yanan Wang --- arch/arm64/include/asm/esr.h | 1 + arch/arm64/include/asm/kvm_emulate.h | 5 + arch/arm64/kvm/mmu.c | 11 +-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/esr.h b/arch

  1   2   >