From: Julia Suvorova <jusual@redhat.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Bjorn Helgaas <helgaas@kernel.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
Sean Christopherson <sean.j.christopherson@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Julia Suvorova <jusual@redhat.com>
Subject: [PATCH] KVM: x86: Use MMCONFIG for all PCI config space accesses
Date: Thu, 30 Jul 2020 21:35:10 +0200 [thread overview]
Message-ID: <20200730193510.578309-1-jusual@redhat.com> (raw)
Using MMCONFIG instead of I/O ports cuts the number of config space
accesses in half, which is faster on KVM and opens the door for
additional optimizations such as Vitaly's "[PATCH 0/3] KVM: x86: KVM
MEM_PCI_HOLE memory":
https://lore.kernel.org/kvm/20200728143741.2718593-1-vkuznets@redhat.com
However, this change will not bring significant performance improvement
unless it is running on x86 within a hypervisor. Moreover, allowing
MMCONFIG access for addresses < 256 can be dangerous for some devices:
see commit a0ca99096094 ("PCI x86: always use conf1 to access config
space below 256 bytes"). That is why a special feature flag is needed.
Introduce KVM_FEATURE_PCI_GO_MMCONFIG, which can be enabled when the
configuration is known to be safe (e.g. in QEMU).
Signed-off-by: Julia Suvorova <jusual@redhat.com>
---
Documentation/virt/kvm/cpuid.rst | 4 ++++
arch/x86/include/uapi/asm/kvm_para.h | 1 +
arch/x86/kernel/kvm.c | 14 ++++++++++++++
3 files changed, 19 insertions(+)
diff --git a/Documentation/virt/kvm/cpuid.rst b/Documentation/virt/kvm/cpuid.rst
index a7dff9186bed..711f2074877b 100644
--- a/Documentation/virt/kvm/cpuid.rst
+++ b/Documentation/virt/kvm/cpuid.rst
@@ -92,6 +92,10 @@ KVM_FEATURE_ASYNC_PF_INT 14 guest checks this feature bit
async pf acknowledgment msr
0x4b564d07.
+KVM_FEATURE_PCI_GO_MMCONFIG 15 guest checks this feature bit
+ before using MMCONFIG for all
+ PCI config accesses
+
KVM_FEATURE_CLOCSOURCE_STABLE_BIT 24 host will warn if no guest-side
per-cpu warps are expeced in
kvmclock
diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h
index 812e9b4c1114..5793f372cae0 100644
--- a/arch/x86/include/uapi/asm/kvm_para.h
+++ b/arch/x86/include/uapi/asm/kvm_para.h
@@ -32,6 +32,7 @@
#define KVM_FEATURE_POLL_CONTROL 12
#define KVM_FEATURE_PV_SCHED_YIELD 13
#define KVM_FEATURE_ASYNC_PF_INT 14
+#define KVM_FEATURE_PCI_GO_MMCONFIG 15
#define KVM_HINTS_REALTIME 0
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index df63786e7bfa..1ec73e6f25ce 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -33,6 +33,7 @@
#include <asm/hypervisor.h>
#include <asm/tlb.h>
#include <asm/cpuidle_haltpoll.h>
+#include <asm/pci_x86.h>
DEFINE_STATIC_KEY_FALSE(kvm_async_pf_enabled);
@@ -715,6 +716,18 @@ static uint32_t __init kvm_detect(void)
return kvm_cpuid_base();
}
+static int __init kvm_pci_arch_init(void)
+{
+ if (raw_pci_ext_ops &&
+ kvm_para_has_feature(KVM_FEATURE_PCI_GO_MMCONFIG)) {
+ pr_info("PCI: Using MMCONFIG for base access\n");
+ raw_pci_ops = raw_pci_ext_ops;
+ return 0;
+ }
+
+ return 1;
+}
+
static void __init kvm_apic_init(void)
{
#if defined(CONFIG_SMP)
@@ -726,6 +739,7 @@ static void __init kvm_apic_init(void)
static void __init kvm_init_platform(void)
{
kvmclock_init();
+ x86_init.pci.arch_init = kvm_pci_arch_init;
x86_platform.apic_post_init = kvm_apic_init;
}
--
2.25.4
next reply other threads:[~2020-07-30 19:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-30 19:35 Julia Suvorova [this message]
2020-07-30 19:50 ` [PATCH] KVM: x86: Use MMCONFIG for all PCI config space accesses Andy Shevchenko
2020-07-31 9:22 ` Vitaly Kuznetsov
2020-07-31 9:41 ` Andy Shevchenko
2020-07-31 18:23 ` Julia Suvorova
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=20200730193510.578309-1-jusual@redhat.com \
--to=jusual@redhat.com \
--cc=andy.shevchenko@gmail.com \
--cc=helgaas@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=willy@infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.