Skip to content

[PW_SID:1067132] RISC-V: KVM: Fix hugepage mapping handling during dirty logging#1638

Open
linux-riscv-bot wants to merge 3 commits intoworkflow__riscv__fixesfrom
pw1067132
Open

[PW_SID:1067132] RISC-V: KVM: Fix hugepage mapping handling during dirty logging#1638
linux-riscv-bot wants to merge 3 commits intoworkflow__riscv__fixesfrom
pw1067132

Conversation

@linux-riscv-bot
Copy link

PR for series 1067132 applied to workflow__riscv__fixes

Name: RISC-V: KVM: Fix hugepage mapping handling during dirty logging
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1067132
Version: 3

…ging

When enabling dirty log in small chunks (e.g., QEMU default chunk
size of 256K), the chunk size is always smaller than the page size
of huge pages (1G or 2M) used in the gstage page tables. This caused
the write protection to be incorrectly skipped for huge PTEs because
the condition `(end - addr) >= page_size` was not satisfied.

Remove the size check in `kvm_riscv_gstage_wp_range()` to ensure huge
PTEs are always write-protected regardless of the chunk size. Additionally,
explicitly align the address down to the page size before invoking
`kvm_riscv_gstage_op_pte()` to guarantee that the address passed to the
operation function is page-aligned.

This fixes the issue where dirty pages might not be tracked correctly
when using huge pages.

Fixes: 9d05c1f ("RISC-V: KVM: Implement stage2 page table programming")
Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
This patch introduces the function kvm_riscv_gstage_split_huge().
It splits the huge page covering a given guest physical address down
to a specified target level (e.g., from 1G to 2M or 4K). The caller
provides a memory cache for allocating any intermediate page tables
and may request a TLB flush after the split.

This functionality will be used by subsequent patches to split huge
pages before handling the write-protection fault, or for other operations
that require page-level granularity.

Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
During dirty logging, all huge pages are write-protected. When the guest
writes to a write-protected huge page, a page fault is triggered. Before
recovering the write permission, the huge page must be split into smaller
pages (e.g., 4K). After splitting, the normal mapping process proceeds,
allowing write permission to be restored at the smaller page granularity.

If dirty logging is disabled because migration failed or was cancelled,
only recover the write permission at the 4K level, and skip recovering the
huge page mapping at this time to avoid the overhead of freeing page tables.
The huge page mapping can be recovered in the ioctl context, similar to x86,
in a later patch.

Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 137.98 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1029.80 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1421.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 26.34 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 28.11 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.76 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 84.29 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
kdoc
Desc: Detects for kdoc errors
Duration: 0.89 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.27 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v3,1/3] RISC-V: KVM: Fix lost write protection on huge pages during dirty logging"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.29 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 140.94 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1082.13 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1436.82 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 27.73 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 28.45 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.99 seconds
Result: ERROR
Output:

ERROR: code indent should use tabs where possible
#32: FILE: arch/riscv/include/asm/kvm_gstage.h:57:
+                                struct kvm_mmu_memory_cache *pcache,$

WARNING: please, no spaces at the start of a line
#32: FILE: arch/riscv/include/asm/kvm_gstage.h:57:
+                                struct kvm_mmu_memory_cache *pcache,$

ERROR: code indent should use tabs where possible
#33: FILE: arch/riscv/include/asm/kvm_gstage.h:58:
+                                gpa_t addr, u32 target_level, bool flush);$

WARNING: please, no spaces at the start of a line
#33: FILE: arch/riscv/include/asm/kvm_gstage.h:58:
+                                gpa_t addr, u32 target_level, bool flush);$

ERROR: space required before the open parenthesis '('
#74: FILE: arch/riscv/kvm/gstage.c:240:
+	while(current_level > target_level) {

CHECK: Alignment should match open parenthesis
#104: FILE: arch/riscv/kvm/gstage.c:270:
+		set_pte(ptep, pfn_pte(PFN_DOWN(__pa(next_ptep)),
+				__pgprot(_PAGE_TABLE)));

total: 3 errors, 2 warnings, 1 checks, 85 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

NOTE: Whitespace errors detected.
      You may wish to use scripts/cleanpatch or scripts/cleanfile

Commit c6bc3887a11b ("RISC-V: KVM: Allow splitting huge pages to arbitrary level") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
CHECK: Alignment should match open parenthesis
ERROR: code indent should use tabs where possible
ERROR: space required before the open parenthesis '('
WARNING: please, no spaces at the start of a line


@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 84.13 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
kdoc
Desc: Detects for kdoc errors
Duration: 0.89 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
module-param
Desc: Detect module_param changes
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v3,2/3] RISC-V: KVM: Allow splitting huge pages to arbitrary level"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.31 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 139.79 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1040.71 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1417.10 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 26.96 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.28 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.77 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 84.00 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
kdoc
Desc: Detects for kdoc errors
Duration: 0.87 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
module-param
Desc: Detect module_param changes
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.21 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v3,3/3] RISC-V: KVM: Split huge pages during fault handling for dirty logging"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.29 seconds
Result: PASS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants