From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Peter Xu <peterx@redhat.com>,
Michael Tsirkin <mst@redhat.com>,
Julia Suvorova <jsuvorov@redhat.com>,
Andy Lutomirski <luto@kernel.org>,
Andrew Jones <drjones@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 0/3] KVM: x86: KVM_MEM_PCI_HOLE memory
Date: Fri, 7 Aug 2020 16:12:29 +0200 [thread overview]
Message-ID: <20200807141232.402895-1-vkuznets@redhat.com> (raw)
Changes since v1:
- Better KVM_SET_USER_MEMORY_REGION flags description, minor tweaks to
the code [Drew Jones]
- BUG_ON() condition in __gfn_to_hva_memslot() adjusted.
This is a continuation of "[PATCH RFC 0/5] KVM: x86: KVM_MEM_ALLONES
memory" work:
https://lore.kernel.org/kvm/20200514180540.52407-1-vkuznets@redhat.com/
and pairs with Julia's "x86/PCI: Use MMCONFIG by default for KVM guests":
https://lore.kernel.org/linux-pci/20200722001513.298315-1-jusual@redhat.com/
PCIe config space can (depending on the configuration) be quite big but
usually is sparsely populated. Guest may scan it by accessing individual
device's page which, when device is missing, is supposed to have 'pci
hole' semantics: reads return '0xff' and writes get discarded.
When testing Linux kernel boot with QEMU q35 VM and direct kernel boot
I observed 8193 accesses to PCI hole memory. When such exit is handled
in KVM without exiting to userspace, it takes roughly 0.000001 sec.
Handling the same exit in userspace is six times slower (0.000006 sec) so
the overal; difference is 0.04 sec. This may be significant for 'microvm'
ideas.
Note, the same speed can already be achieved by using KVM_MEM_READONLY
but doing this would require allocating real memory for all missing
devices and e.g. 8192 pages gives us 32mb. This will have to be allocated
for each guest separately and for 'microvm' use-cases this is likely
a no-go.
Introduce special KVM_MEM_PCI_HOLE memory: userspace doesn't need to
back it with real memory, all reads from it are handled inside KVM and
return '0xff'. Writes still go to userspace but these should be extremely
rare.
The original 'KVM_MEM_ALLONES' idea had additional optimizations: KVM
was mapping all 'PCI hole' pages to a single read-only page stuffed with
0xff. This is omitted in this submission as the benefits are unclear:
KVM will have to allocate SPTEs (either on demand or aggressively) and
this also consumes time/memory. We can always take a look at possible
optimizations later.
Vitaly Kuznetsov (3):
KVM: x86: move kvm_vcpu_gfn_to_memslot() out of try_async_pf()
KVM: x86: introduce KVM_MEM_PCI_HOLE memory
KVM: selftests: add KVM_MEM_PCI_HOLE test
Documentation/virt/kvm/api.rst | 18 ++-
arch/x86/include/uapi/asm/kvm.h | 1 +
arch/x86/kvm/mmu/mmu.c | 19 +--
arch/x86/kvm/mmu/paging_tmpl.h | 10 +-
arch/x86/kvm/x86.c | 10 +-
include/linux/kvm_host.h | 3 +
include/uapi/linux/kvm.h | 2 +
tools/testing/selftests/kvm/Makefile | 1 +
.../testing/selftests/kvm/include/kvm_util.h | 1 +
tools/testing/selftests/kvm/lib/kvm_util.c | 81 +++++++------
.../kvm/x86_64/memory_slot_pci_hole.c | 112 ++++++++++++++++++
virt/kvm/kvm_main.c | 39 ++++--
12 files changed, 239 insertions(+), 58 deletions(-)
create mode 100644 tools/testing/selftests/kvm/x86_64/memory_slot_pci_hole.c
--
2.25.4
next reply other threads:[~2020-08-07 14:12 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-07 14:12 Vitaly Kuznetsov [this message]
2020-08-07 14:12 ` [PATCH v2 1/3] KVM: x86: move kvm_vcpu_gfn_to_memslot() out of try_async_pf() Vitaly Kuznetsov
2020-08-14 1:40 ` Sean Christopherson
2020-09-01 14:15 ` Vitaly Kuznetsov
2020-09-04 3:47 ` Sean Christopherson
2020-08-07 14:12 ` [PATCH v2 2/3] KVM: x86: introduce KVM_MEM_PCI_HOLE memory Vitaly Kuznetsov
2020-08-14 2:31 ` Sean Christopherson
2020-08-14 14:30 ` Michael S. Tsirkin
2020-08-17 16:32 ` Sean Christopherson
2020-08-21 1:46 ` Michael S. Tsirkin
2020-08-22 3:19 ` Sean Christopherson
2020-09-01 14:39 ` Vitaly Kuznetsov
2020-09-03 9:35 ` Michael S. Tsirkin
2020-08-07 14:12 ` [PATCH v2 3/3] KVM: selftests: add KVM_MEM_PCI_HOLE test Vitaly Kuznetsov
2020-08-25 21:25 ` [PATCH v2 0/3] KVM: x86: KVM_MEM_PCI_HOLE memory Peter Xu
2020-09-01 14:43 ` Vitaly Kuznetsov
2020-09-01 20:00 ` Peter Xu
2020-09-02 8:59 ` Vitaly Kuznetsov
2020-09-04 6:12 ` Sean Christopherson
2020-09-04 7:29 ` Gerd Hoffmann
2020-09-04 16:00 ` Sean Christopherson
2020-09-07 8:37 ` Vitaly Kuznetsov
2020-09-07 11:32 ` Michael S. Tsirkin
2020-09-11 17:00 ` Sean Christopherson
2020-09-18 12:34 ` Michael S. Tsirkin
2020-09-21 17:21 ` Sean Christopherson
2020-09-07 10:52 ` Michael S. Tsirkin
2020-09-18 9:33 ` Gerd Hoffmann
2020-09-07 10:54 ` Michael S. Tsirkin
2020-09-18 8:49 ` Gerd Hoffmann
2020-09-04 7:20 ` Gerd Hoffmann
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=20200807141232.402895-1-vkuznets@redhat.com \
--to=vkuznets@redhat.com \
--cc=drjones@redhat.com \
--cc=jmattson@google.com \
--cc=jsuvorov@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=sean.j.christopherson@intel.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
all inboxes | Powered by JetHome®