Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] RISC-V: KVM: Preserve resident guest Vector state
@ 2026-10-27 13:13 slack up
  2026-10-27 13:13 ` [RFC PATCH 1/3] riscv: vector: Add a guest owner invalidation hook slack up
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: slack up @ 2026-10-27 13:13 UTC (permalink / raw)
  To: Anup Patel, Atish Patra, Palmer Dabbelt, kvm-riscv, linux-riscv
  Cc: Paul Walmsley, Albert Ou, Alexandre Ghiti, Paolo Bonzini,
	Sean Christopherson, Shuah Khan, kvm, linux-kernel,
	linux-kselftest, Xiaochun Yu

From: Xiaochun Yu <yxcnew@outlook.com>

kvm_arch_vcpu_put() saves the guest Vector state and restores the host
register file. A later vCPU load on the same hart saves the host again and
requests a full guest restore, even when no host user touched the Vector
data registers in between.

This RFC keeps the guest Vector register file resident across a vCPU
put/load pair when it is safe to do so. A matching load restores only the
control CSRs; all uncertain cases retain the existing full-restore path.

The series is intentionally conservative:

- every dirty vCPU put still saves the guest state, so guest memory remains
  authoritative for migration and userspace access;
- a per-hart owner records an opaque vCPU identity, an allocation cookie and a
  state generation, without retaining a dereferenceable vCPU pointer;
- task Vector save/restore/discard, kernel-mode Vector use, preemptible kernel
  Vector task resume and CPU state changes invalidate a resident guest before
  the registers can be reused;
- reset, dirty saves and KVM_SET_ONE_REG advance the generation;
- KVM_SET_ONE_REG advances the generation before copy_from_user(), because a
  partial copy can modify the destination and still return EFAULT;
- the optimization is guarded by a read-only module parameter and defaults to
  disabled. The generic invalidation sites are guarded by a static key.

Patch 1 establishes the generic invalidation boundary without changing KVM
behavior. Patch 2 adds the owner tracking, CSR-only restore and tracepoints.
Patch 3 adds focused lifetime, ONE_REG and partial-fault regression tests.

This series currently depends on the separately posted build fix:

  Message-ID: <OSQPR01MB6326DDE9C2F390EA3F0F444EC2662@OSQPR01MB6326.apcprd01.prod.exchangelabs.com>
  Link: https://lore.kernel.org/all/OSQPR01MB6326DDE9C2F390EA3F0F444EC2662@OSQPR01MB6326.apcprd01.prod.exchangelabs.com/

Ze Huang <ze.huang@oss.qualcomm.com> independently tested that prerequisite
with GCC 16.2.1 and Clang 23.1.3 and supplied a Tested-by tag in this reply:

  Link: https://lore.kernel.org/all/DMCBQSJ0B22A.2TDXAXPJNPZL2@oss.qualcomm.com/

Validation on Torvalds master 21a7f44fd076:

- CONFIG_RISCV_ISA_V=y, CONFIG_KVM=m: full Image + modules build;
- CONFIG_RISCV_ISA_V=n, CONFIG_KVM=m: full Image + modules build;
- lifetime, ONE_REG and partial-fault tests pass with the fast path disabled
  and enabled;
- nested KVM/RVV smoke passes 3/3 with the fast path enabled;
- the smoke trace recorded 785 owner hits, 784 CSR-only restores and eight
  conservative full fallbacks, with no trace-buffer overwrite;
- no emergency, alert, critical or error messages were present in dmesg.

Development note: OpenAI Codex was used in an extended interactive session to
assist with source analysis, implementation and selftest drafting, experiment
orchestration, patch review and changelog preparation. The prompts focused on
modeling per-hart ownership as a cache-validity problem, enumerating Vector
register invalidation boundaries, reproducing partial KVM_SET_ONE_REG writes
and reviewing the resulting patches. The build and runtime results above were
collected from the stated test environment rather than inferred by the model.

The nested QEMU result demonstrates functional behavior and event counts only;
it is not presented as a performance result. Hardware performance measurement
remains future work.

Feedback is especially welcome on whether the generic invalidation callback is
an acceptable RISC-V Vector/KVM boundary, whether the default-off module
parameter is useful for the first version, and whether the behavior patch
should be split further after the interface direction is agreed.

Xiaochun Yu (3):
  riscv: vector: Add a guest owner invalidation hook
  RISC-V: KVM: Preserve guest Vector state across vCPU put/load
  KVM: riscv: selftests: Add Vector owner regression tests

 arch/riscv/include/asm/kvm_host.h             |   4 +
 arch/riscv/include/asm/kvm_vcpu_vector.h      |  54 +++-
 arch/riscv/include/asm/processor.h            |   1 +
 arch/riscv/include/asm/vector.h               |  31 +++
 arch/riscv/kernel/kernel_mode_vector.c        |  38 +++
 arch/riscv/kvm/trace.h                        |  98 +++++++
 arch/riscv/kvm/vcpu.c                         |  54 +++-
 arch/riscv/kvm/vcpu_vector.c                  | 252 +++++++++++++++++-
 tools/testing/selftests/kvm/Makefile.kvm      |   3 +
 .../kvm/riscv/vector_owner_fault_test.c       | 147 ++++++++++
 .../kvm/riscv/vector_owner_lifetime_test.c    | 127 +++++++++
 .../kvm/riscv/vector_owner_onereg_test.c      | 191 +++++++++++++
 12 files changed, 976 insertions(+), 24 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/riscv/vector_owner_fault_test.c
 create mode 100644 tools/testing/selftests/kvm/riscv/vector_owner_lifetime_test.c
 create mode 100644 tools/testing/selftests/kvm/riscv/vector_owner_onereg_test.c


base-commit: 21a7f44fd0765fcc5194130b28767786eba1d1e7
prerequisite-patch-id: 370f0468ecd4354950ab075162058e4b7c31768b
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-10-27 14:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27 13:13 [RFC PATCH 0/3] RISC-V: KVM: Preserve resident guest Vector state slack up
2026-10-27 13:13 ` [RFC PATCH 1/3] riscv: vector: Add a guest owner invalidation hook slack up
2026-10-27 14:03   ` sashiko-bot
2026-10-27 13:13 ` [RFC PATCH 2/3] RISC-V: KVM: Preserve guest Vector state across vCPU put/load slack up
2026-10-27 14:11   ` sashiko-bot
2026-10-27 13:13 ` [RFC PATCH 3/3] KVM: riscv: selftests: Add Vector owner regression tests slack up
2026-10-27 14:03   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox