Skip to content

Support runtime configuration for per-VM's HGATP mode

[email protected] kvm kvm-riscv linux-doc linux-riscv lkml 7 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v8 Latest3 patches 6 repliesIn review
  2. v74 patches 13 repliesSuperseded
  3. v64 patches 7 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v53 patches10 repliesSuperseded
v44 patches9 repliesSuperseded
v32 patches8 repliesSuperseded
v21 patch0 repliesSuperseded

Changes in v8 from the cover letter

- Reuse KVM_CAP_VM_GPA_BITS to advertise and select the effective GPA width for a VM (Anup's suggestion).
- Handle the kvm == NULL case and task kvm->lock and kvm->slots_lock to serialize against concurrent vCPU creation and memslot updates (Radim's suggestion).
- Link to v7:
https://lore.kernel.org/linux-riscv/[email protected]/
---

Patches in v8 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3RISC-V: KVM: Support runtime configuration for per-VM's HGATP modearch/riscv/include/asm/kvm_gstage.h arch/riscv/include/asm/kvm_host.h arch/riscv/kvm/gstage.c +4 more+86 -571 reply
2/3RISC-V: KVM: Cache gstage pgd_levels in struct kvm_gstagearch/riscv/include/asm/kvm_gstage.h arch/riscv/kvm/gstage.c arch/riscv/kvm/mmu.c+25 -451 reply
3/3RISC-V: KVM: Reuse KVM_CAP_VM_GPA_BITS to select HGATP.MODEarch/riscv/kvm/vm.c+42 -22 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchAndrew JonesAnup PatelGuo RenNutty Liu
1/3R-b R-b R-b R-b
2/3R-b R-b
3/3R-b R-b R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v8 thread

Cover letter [PATCH v8 0/3] Support runtime configuration for per-VM's HGATP mode

From: Fangyu Yu <[email protected]>

Currently, RISC-V KVM hardcodes the G-stage page table format (HGATP mode) to the maximum mode detected at boot time (e.g., SV57x4 if supported). but often such a wide GPA is unnecessary, just as a host sometimes doesn't need sv57.

This patch reuse KVM_CAP_VM_GPA_BITS to select HGATP.MODE. User-space can now explicitly request a specific HGATP mode (SV39x4, SV48x4, SV57x4 or SV32x4) during VM creation.

---
Changes in v8:
- Reuse KVM_CAP_VM_GPA_BITS to advertise and select the effective GPA width for a VM (Anup's suggestion).
- Handle the kvm == NULL case and task kvm->lock and kvm->slots_lock to serialize against concurrent vCPU creation and memslot updates (Radim's suggestion).
- Link to v7:
https://lore.kernel.org/linux-riscv/[email protected]/
---
Changes in v7 (Anup's suggestions):
- Keep the original HGATP mode probing logic.
- Link to v6:
https://lore.kernel.org/linux-riscv/[email protected]/
---
Changes in v6 (Anup's suggestions):
- Reworked kvm_riscv_gstage_gpa_bits() and kvm_riscv_gstage_gpa_size() to take "unsigned long pgd_levels" instead of "struct kvm_arch *".
- Moved kvm_riscv_gstage_mode() helper from kvm_host.h to kvm_gstage.h.
- Renamed kvm->arch.kvm_riscv_gstage_pgd_levels to kvm->arch.pgd_levels.
- Added pgd_levels to struct kvm_gstage to avoid repeated gstage->kvm->arch pointer chasing.
- Link to v5:
https://lore.kernel.org/linux-riscv/[email protected]/
---
Changes in v5:
- Use architectural HGATP.MODE encodings as the bit index for the supported-mode bitmap and for the VM-mode selection UAPI; no new UAPI mode/bit defines are introduced(per Radim).
- Allow KVM_CAP_RISCV_SET_HGATP_MODE on RV32 as well(per Drew).
- Link to v4:
https://lore.kernel.org/linux-riscv/[email protected]/
---
Changes in v4:
- Extend kvm_riscv_gstage_mode_detect() to probe all HGATP.MODE values supported by the host and record them in a bitmask.
- Treat unexpected pgd_levels in kvm_riscv_gstage_mode() as an internal error (e.g. WARN_ON_ONCE())(per Radim).
- Move kvm_riscv_gstage_gpa_bits() and kvm_riscv_gstage_gpa_size() to header as static inline helpers(per Radim).
- Drop gstage_mode_user_initialized and Remove the kvm_debug() message from KVM_CAP_RISCV_SET_HGATP_MODE(per Radim).
- Link to v3:
https://lore.kernel.org/linux-riscv/[email protected]/
---
Changes in v3:
- Reworked the patch formatting (per Drew).
- Dropped kvm->arch.kvm_riscv_gstage_mode and derive HGATP.MODE from kvm_riscv_gstage_pgd_levels via a helper, avoiding redundant per-VM state(per Drew).
- Removed kvm_riscv_gstage_max_mode and keep only kvm_riscv_gstage_max_pgd_levels for host capability detection(per Drew).
- Other initialization and return value issues(per Drew).
- Enforce that KVM_CAP_RISCV_SET_HGATP_MODE can only be enabled before any vCPUs are created by rejecting the ioctl once kvm->created_vcpus is non-zero(per Radim).
- Add a memslot safety check and reject the capability unless kvm_are_all_memslots_empty(kvm) is true, ensuring the G-stage format is not changed after any memslots have been installed(per Radim).
- Link to v2:
https://lore.kernel.org/linux-riscv/[email protected]/

Fangyu Yu (3):
RISC-V: KVM: Support runtime configuration for per-VM's HGATP mode
RISC-V: KVM: Cache gstage pgd_levels in struct kvm_gstage
RISC-V: KVM: Reuse KVM_CAP_VM_GPA_BITS to select HGATP.MODE

 arch/riscv/include/asm/kvm_gstage.h | 47 ++++++++++++++++---
 arch/riscv/include/asm/kvm_host.h   |  1 +
 arch/riscv/kvm/gstage.c             | 65 +++++++++++++--------------
 arch/riscv/kvm/main.c               | 12 ++---
 arch/riscv/kvm/mmu.c                | 70 +++++++++--------------------
 arch/riscv/kvm/vm.c                 | 49 ++++++++++++++++++--
 arch/riscv/kvm/vmid.c               |  3 +-
 7 files changed, 148 insertions(+), 99 deletions(-)
Signature · 1 line
2.50.1