From: Tina Zhang <zhang_wei@open-hieco.net>
To: Sean Christopherson <seanjc@google.com>,
Jim Mattson <jmattson@google.com>,
kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Shuah Khan <shuah@kernel.org>,
zhouyanjing@hygon.cn, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v8 0/8] KVM: nSVM: Enable DecodeAssists for nested guests
Date: Wed, 23 Sep 2026 22:02:25 +0800 [thread overview]
Message-ID: <cover.1790171702.git.zhang_wei@open-hieco.net> (raw)
The SVM DecodeAssists feature provides decode state for selected
VM-Exits. KVM currently does not expose this feature to L1. Some L1
hypervisors may therefore treat the platform's SVM support as
incomplete.
In practice, this was observed with Hyper-V running on top of KVM.
Hyper-V appears to require DecodeAssists before enabling nested SVM for
its guests. Virtualizing the feature lets users enable Hyper-V
virtualization features inside a Windows VM when needed, e.g. to run
QEMU/KVM in WSL.
Virtualize both parts of DecodeAssists for nested SVM. For emulated
MOV CR/DR, INTn, INVLPG, and related intercepts, populate EXITINFO1 as
specified by the architecture. Preserve MOV-to-CR0 decode information
for selective CR0 write intercepts. INVLPGA's address remains in saved
guest rAX. Leave EXITINFO1 unchanged when DecodeAssists is not exposed.
For data #NPF and intercepted data #PF exits, propagate current hardware
instruction bytes when available. For an emulator-generated #NPF, keep
the bytes used to decode the instruction and fetch any missing tail.
Queued #PF exits, including userspace-injected exceptions, use an
on-demand fetch from the current L2 CS:RIP. Instruction-fetch faults
report zero bytes, and SEV guests do not use the memory-fetch fallback.
The selftest checks hardware and forced-emulation instruction intercepts
against the same expected values, including selective CR0 writes. It
also covers hardware and synthesized instruction bytes, truncated
fetches, cache preservation after instruction memory changes during
MMIO, and userspace-injected #PF after MMIO completion.
The complete selftest passed with kvm.force_emulation_prefix both
disabled and enabled in an isolated VM running a kernel built from
this series on the base commit below. SEV and live migration have
not been tested.
Changes since v7:
- Rebase onto kvm-x86/next at the base commit listed below.
- Revise the INVLPG comment as suggested by Jim.
Previous versions (including earlier changelogs):
v7:
https://lore.kernel.org/r/cover.1789721173.git.zhang_wei@open-hieco.net
v6:
https://lore.kernel.org/r/cover.1789281096.git.zhang_wei@open-hieco.net
v5:
https://lore.kernel.org/r/20260824123954.315112-1-zhang_wei@open-hieco.net
v4:
https://lore.kernel.org/r/cover.1787116250.git.zhang_wei@open-hieco.net
v3:
https://lore.kernel.org/r/cover.1785411877.git.zhang_wei@open-hieco.net
v2:
https://lore.kernel.org/r/cover.1783999988.git.zhang_wei@open-hieco.net
v1:
https://lore.kernel.org/r/20260629125205.52394-1-zhang_wei@open-hieco.net
Tina Zhang (8):
KVM: x86: Provide INVLPG linear address to intercept handlers
KVM: nSVM: Synthesize DecodeAssists EXITINFO for emulated intercepts
KVM: nSVM: Track valid hardware DecodeAssist bytes
KVM: nSVM: Propagate hardware DecodeAssist bytes to VMCB12
KVM: nSVM: Fetch DecodeAssist bytes for synthesized faults
KVM: nSVM: Use emulator bytes for synthesized nested #NPF
KVM: nSVM: Advertise DecodeAssists to L1
KVM: selftests: Add nested SVM DecodeAssists test
arch/x86/kvm/cpuid.c | 1 +
arch/x86/kvm/emulate.c | 45 ++
arch/x86/kvm/kvm_emulate.h | 4 +
arch/x86/kvm/svm/nested.c | 142 ++++-
arch/x86/kvm/svm/svm.c | 29 +
arch/x86/kvm/svm/svm.h | 3 +
arch/x86/kvm/x86.c | 56 +-
arch/x86/kvm/x86.h | 2 +
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../selftests/kvm/include/x86/processor.h | 1 +
.../kvm/x86/svm_nested_decode_assists_test.c | 590 ++++++++++++++++++
11 files changed, 862 insertions(+), 12 deletions(-)
create mode 100644 tools/testing/selftests/kvm/x86/svm_nested_decode_assists_test.c
base-commit: 30b5175943e709911702d8a9364145e911f57e3f
--
2.43.7
next reply other threads:[~2026-09-23 14:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 14:02 Tina Zhang [this message]
2026-09-23 14:02 ` [PATCH v8 1/8] KVM: x86: Provide INVLPG linear address to intercept handlers Tina Zhang
2026-09-23 19:49 ` Jim Mattson
2026-09-23 14:02 ` [PATCH v8 2/8] KVM: nSVM: Synthesize DecodeAssists EXITINFO for emulated intercepts Tina Zhang
2026-09-23 14:02 ` [PATCH v8 3/8] KVM: nSVM: Track valid hardware DecodeAssist bytes Tina Zhang
2026-09-23 14:02 ` [PATCH v8 4/8] KVM: nSVM: Propagate hardware DecodeAssist bytes to VMCB12 Tina Zhang
2026-09-23 14:02 ` [PATCH v8 5/8] KVM: nSVM: Fetch DecodeAssist bytes for synthesized faults Tina Zhang
2026-09-23 22:20 ` Jim Mattson
2026-09-23 14:02 ` [PATCH v8 6/8] KVM: nSVM: Use emulator bytes for synthesized nested #NPF Tina Zhang
2026-09-23 14:02 ` [PATCH v8 7/8] KVM: nSVM: Advertise DecodeAssists to L1 Tina Zhang
2026-09-23 14:02 ` [PATCH v8 8/8] KVM: selftests: Add nested SVM DecodeAssists test Tina Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cover.1790171702.git.zhang_wei@open-hieco.net \
--to=zhang_wei@open-hieco.net \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=zhouyanjing@hygon.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®