From: Sean Christopherson <sean.j.christopherson@intel.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Peter Xu <peterx@redhat.com>,
Julia Suvorova <jsuvorov@redhat.com>,
Andy Lutomirski <luto@kernel.org>,
Andrew Jones <drjones@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] KVM: x86: introduce KVM_MEM_PCI_HOLE memory
Date: Mon, 17 Aug 2020 09:32:07 -0700 [thread overview]
Message-ID: <20200817163207.GC22407@linux.intel.com> (raw)
In-Reply-To: <20200814102850-mutt-send-email-mst@kernel.org>
On Fri, Aug 14, 2020 at 10:30:14AM -0400, Michael S. Tsirkin wrote:
> On Thu, Aug 13, 2020 at 07:31:39PM -0700, Sean Christopherson wrote:
> > > @@ -2318,6 +2338,11 @@ static int __kvm_read_guest_page(struct kvm_memory_slot *slot, gfn_t gfn,
> > > int r;
> > > unsigned long addr;
> > >
> > > + if (unlikely(slot && (slot->flags & KVM_MEM_PCI_HOLE))) {
> > > + memset(data, 0xff, len);
> > > + return 0;
> > > + }
> >
> > This feels wrong, shouldn't we be treating PCI_HOLE as MMIO? Given that
> > this is performance oriented, I would think we'd want to leverage the
> > GPA from the VMCS instead of doing a full translation.
> >
> > That brings up a potential alternative to adding a memslot flag. What if
> > we instead add a KVM_MMIO_BUS device similar to coalesced MMIO? I think
> > it'd be about the same amount of KVM code, and it would provide userspace
> > with more flexibility, e.g. I assume it would allow handling even writes
> > wholly within the kernel for certain ranges and/or use cases, and it'd
> > allow stuffing a value other than 0xff (though I have no idea if there is
> > a use case for this).
>
> I still think down the road the way to go is to map
> valid RO page full of 0xff to avoid exit on read.
> I don't think a KVM_MMIO_BUS device will allow this, will it?
No, it would not, but adding KVM_MEM_PCI_HOLE doesn't get us any closer to
solving that problem either.
What if we add a flag to allow routing all GFNs in a memslot to a single
HVA? At a glance, it doesn't seem to heinous. It would have several of the
same touchpoints as this series, e.g. __kvm_set_memory_region() and
kvm_alloc_memslot_metadata().
The functional changes (for x86) would be a few lines in
__gfn_to_hva_memslot() and some new logic in kvm_handle_hva_range(). The
biggest concern is probably the fragility of such an implementation, as KVM
has a habit of open coding operations on memslots.
The new flags could then be paired with KVM_MEM_READONLY to yield the desired
behavior of reading out 0xff for an arbitrary range without requiring copious
memslots and/or host pages.
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 852fc8274bdd..875243a0ab36 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1103,6 +1103,9 @@ __gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn)
static inline unsigned long
__gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn)
{
+ if (unlikely(slot->flags & KVM_MEM_SINGLE_HVA))
+ return slot->userspace_addr;
+
return slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE;
}
next prev parent reply other threads:[~2020-08-17 17:22 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-07 14:12 [PATCH v2 0/3] KVM: x86: KVM_MEM_PCI_HOLE memory Vitaly Kuznetsov
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 [this message]
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=20200817163207.GC22407@linux.intel.com \
--to=sean.j.christopherson@intel.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=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