From: Oliver Upton <oupton@google.com>
To: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
David Dunn <daviddunn@google.com>,
Peter Shier <pshier@google.com>, Oliver Upton <oupton@google.com>
Subject: [PATCH 0/2] KVM: x86: Allow opt out of guest hypercall patching
Date: Wed, 16 Mar 2022 00:55:36 +0000 [thread overview]
Message-ID: <20220316005538.2282772-1-oupton@google.com> (raw)
Another interesting behavior of KVM is that it rewrites guest hypercall
instructions when emulated on #UD. So, if a guest uses the wrong
instruction for the vendor its running on, KVM rewrites the guest
instruction to use the correct one (i.e. VMCALL on VMX, VMMCALL on SVM).
While it may not be the end of the world for a non-nested guest that
knows its running on KVM, this is dead wrong in the context of nested
virtualization.
The nested situation could probably be seen as a bug, but I decided to
leave it as is for now in the series since there hasn't been any
complaints about it so far.
This series adds a quirk which allows userspace to opt out of hypercall
rewrites. With the quirk disabled, misbehaved guests will see a #UD
instead.
Applies to kvm/queue at the following commit:
2ca1ba339ed8 ("KVM: x86: Test case for TSC scaling and offset sync")
Note, the series depends on KVM_CAP_DISABLE_QUIRKS2 which was introduced
in the following commit on kvm/queue:
3a825326df69 ("KVM: x86: Introduce KVM_CAP_DISABLE_QUIRKS2")
Tested with the included selftest on an Intel Skylake and AMD Rome
machine.
Oliver Upton (2):
KVM: x86: Allow userspace to opt out of hypercall patching
selftests: KVM: Test KVM_X86_QUIRK_FIX_HYPERCALL_INSN
Documentation/virt/kvm/api.rst | 9 +
arch/x86/include/asm/kvm_host.h | 3 +-
arch/x86/include/uapi/asm/kvm.h | 11 +-
arch/x86/kvm/x86.c | 11 ++
tools/testing/selftests/kvm/.gitignore | 1 +
tools/testing/selftests/kvm/Makefile | 1 +
.../selftests/kvm/x86_64/fix_hypercall_test.c | 170 ++++++++++++++++++
7 files changed, 200 insertions(+), 6 deletions(-)
create mode 100644 tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c
--
2.35.1.723.g4982287a31-goog
next reply other threads:[~2022-03-16 0:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-16 0:55 Oliver Upton [this message]
2022-03-16 0:55 ` [PATCH 1/2] KVM: x86: Allow userspace to opt out of hypercall patching Oliver Upton
2022-03-24 17:44 ` Sean Christopherson
2022-03-24 17:57 ` Paolo Bonzini
2022-03-24 19:05 ` Oliver Upton
2022-03-25 23:53 ` Sean Christopherson
2022-03-28 17:28 ` Oliver Upton
2022-03-28 18:28 ` Sean Christopherson
2022-08-24 9:34 ` Maxim Levitsky
2022-08-24 14:43 ` Sean Christopherson
2022-08-24 15:06 ` Maxim Levitsky
2022-08-24 17:15 ` Paolo Bonzini
2022-08-24 18:40 ` Sean Christopherson
2022-03-16 0:55 ` [PATCH 2/2] selftests: KVM: Test KVM_X86_QUIRK_FIX_HYPERCALL_INSN Oliver Upton
2022-03-24 19:09 ` Oliver Upton
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=20220316005538.2282772-1-oupton@google.com \
--to=oupton@google.com \
--cc=daviddunn@google.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=pshier@google.com \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/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