[PW_SID:1098129] KVM: riscv: Fix hugetlb G-stage block mapping eligibility#1984
[PW_SID:1098129] KVM: riscv: Fix hugetlb G-stage block mapping eligibility#1984linux-riscv-bot wants to merge 4 commits into
Conversation
fault_supports_gstage_huge_mapping() already contains the two checks needed before installing a G-stage block mapping: the userspace address and GPA must have matching offsets within the block, and the whole block must be contained within the memslot. The helper currently hard-codes PMD_SIZE because its only caller is the transparent hugepage path. The hugetlb path needs the same checks, but the target block size can be either PMD_SIZE or PUD_SIZE depending on the hugetlb VMA. So pass the target mapping size into the helper and use it for the alignment and bounds checks. This keeps the existing THP PMD behavior unchanged and prepares the helper to be reused for the following hugetlb fix. Signed-off-by: Jinyu Tang <tjytimi@163.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
RISC-V KVM has used the hugetlb VMA size directly as the G-stage mapping size since stage-2 page table support was added. That is safe only if the block covered by the fault is fully contained in the memslot and the userspace address has the same offset as the GPA within that block. The THP path already checks those constraints before installing a PMD block mapping. The hugetlb path did not, so an unaligned memslot could make KVM install a PMD or PUD sized G-stage block that covers memory outside the slot or maps the wrong host pages. Select hugetlb mapping sizes through the same memslot-boundary check, falling back from PUD to PMD to PAGE_SIZE. When a smaller hugetlb mapping size is selected, fault the GFN aligned to that selected size instead of the original VMA size. Also keep hugetlb mappings out of transparent_hugepage_adjust(). Once the hugetlb path has chosen PAGE_SIZE, promoting it again through the THP helper would miss the hugetlb fallback decision. Fixes: 9d05c1f ("RISC-V: KVM: Implement stage2 page table programming") Signed-off-by: Jinyu Tang <tjytimi@163.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
kvm_page_table_test can already exercise hugetlb-backed guest memory, but it always creates the test memslot with GPA alignment matching the hugetlb backing size. That misses the case where a valid hugetlb memslot is later moved so that the memslot GPA and HVA no longer have the same offset within the backing huge page. Add a -u option that moves the test memslot GPA by one guest page after creating the hugetlb memslot. The memslot is created through the normal helper first, so the backing allocation remains valid and hugetlb aligned. Moving the memslot then creates a deliberate HVA/GPA offset mismatch before the guest mapping is installed. This mode is useful for checking that architecture MMUs do not install a block mapping when the block would map the wrong host pages or cover memory outside the memslot. The option is restricted to hugetlb-backed test memory because it's specifically about hugetlb block mapping eligibility. Signed-off-by: Jinyu Tang <tjytimi@163.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 1: "[1/3] KVM: riscv: Pass the target size to huge G-stage checks" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 2: "[2/3] KVM: riscv: Check hugetlb block mappings against memslot bounds" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
|
Patch 3: "[3/3] KVM: selftests: Add a hugetlb memslot alignment test mode" |
248facd to
1b98b85
Compare
PR for series 1098129 applied to workflow
Name: KVM: riscv: Fix hugetlb G-stage block mapping eligibility
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1098129
Version: 1