[RFC,01/14] KVM: x86/MMU: Add shadow_mmu.(c|h)

Message ID 20221221222418.3307832-2-bgardon@google.com
State New
Headers
Series KVM: x86/MMU: Formalize the Shadow MMU |

Commit Message

Ben Gardon Dec. 21, 2022, 10:24 p.m. UTC
  As a first step to splitting the Shadow MMU out of KVM MMU common code,
add separate files for it with some of the boilerplate and includes the
Shadow MMU will need.

No functional change intended.

Signed-off-by: Ben Gardon <bgardon@google.com>
---
 arch/x86/kvm/Makefile         |  2 +-
 arch/x86/kvm/mmu/mmu.c        |  1 +
 arch/x86/kvm/mmu/shadow_mmu.c | 21 +++++++++++++++++++++
 arch/x86/kvm/mmu/shadow_mmu.h |  8 ++++++++
 4 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/kvm/mmu/shadow_mmu.c
 create mode 100644 arch/x86/kvm/mmu/shadow_mmu.h
  

Comments

Sean Christopherson Feb. 1, 2023, 7:45 p.m. UTC | #1
On Wed, Dec 21, 2022, Ben Gardon wrote:
> diff --git a/arch/x86/kvm/mmu/shadow_mmu.c b/arch/x86/kvm/mmu/shadow_mmu.c
> new file mode 100644
> index 000000000000..7bce5ec52b2e
> --- /dev/null
> +++ b/arch/x86/kvm/mmu/shadow_mmu.c
> @@ -0,0 +1,21 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * KVM Shadow MMU
> + *
> + * This file implements the Shadow MMU: the KVM MMU implementation which has
> + * developed organically from hardware which did not have second level paging,
> + * and so used "shadow paging" to virtualize guest memory. The Shadow MMU is
> + * an alternative to the TDP MMU which only supports hardware with Two
> + * Dimentional Paging. (e.g. EPT on Intel or NPT on AMD CPUs.) Note that the
> + * Shadow MMU also supports TDP, it's just less scalable. The Shadow and TDP
> + * MMUs can cooperate to support nested virtualization on hardware with TDP.
> + */

Eh, I vote to omit the comment.  For newbies, Documentation is likely a better
landing spot for describing the MMUs, and people that are familiar with KVM x86
MMU already know what the shadow MMU is and does.  That way we avoid bikeshedding
this comment, at least in the conext of this series.  E.g. I'm pretty sure much
of the shadow MMU behavior wasn't developed organically, it was stolen from Xen.
And the line about the Shadow and TDP MMUs cooperating support nested virt is
loaded with assumptions and qualifiers, and makes it sound like nested virt only
works with _the_ TDP MMU as oposed to _a_ TDP MMU`.
  
Ben Gardon Feb. 1, 2023, 7:48 p.m. UTC | #2
On Wed, Feb 1, 2023 at 11:45 AM Sean Christopherson <seanjc@google.com> wrote:
>
> On Wed, Dec 21, 2022, Ben Gardon wrote:
> > diff --git a/arch/x86/kvm/mmu/shadow_mmu.c b/arch/x86/kvm/mmu/shadow_mmu.c
> > new file mode 100644
> > index 000000000000..7bce5ec52b2e
> > --- /dev/null
> > +++ b/arch/x86/kvm/mmu/shadow_mmu.c
> > @@ -0,0 +1,21 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * KVM Shadow MMU
> > + *
> > + * This file implements the Shadow MMU: the KVM MMU implementation which has
> > + * developed organically from hardware which did not have second level paging,
> > + * and so used "shadow paging" to virtualize guest memory. The Shadow MMU is
> > + * an alternative to the TDP MMU which only supports hardware with Two
> > + * Dimentional Paging. (e.g. EPT on Intel or NPT on AMD CPUs.) Note that the
> > + * Shadow MMU also supports TDP, it's just less scalable. The Shadow and TDP
> > + * MMUs can cooperate to support nested virtualization on hardware with TDP.
> > + */
>
> Eh, I vote to omit the comment.  For newbies, Documentation is likely a better
> landing spot for describing the MMUs, and people that are familiar with KVM x86
> MMU already know what the shadow MMU is and does.  That way we avoid bikeshedding
> this comment, at least in the conext of this series.  E.g. I'm pretty sure much
> of the shadow MMU behavior wasn't developed organically, it was stolen from Xen.
> And the line about the Shadow and TDP MMUs cooperating support nested virt is
> loaded with assumptions and qualifiers, and makes it sound like nested virt only
> works with _the_ TDP MMU as oposed to _a_ TDP MMU`.

Sounds good, I can dump the comment. I plan to send out a rebased
version of this series tomorrow, incorporating all the feedback this
series has gotten. Thanks for taking another look at it.
  

Patch

diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index 80e3fe184d17..d6e94660b006 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -12,7 +12,7 @@  include $(srctree)/virt/kvm/Makefile.kvm
 kvm-y			+= x86.o emulate.o i8259.o irq.o lapic.o \
 			   i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \
 			   hyperv.o debugfs.o mmu/mmu.o mmu/page_track.o \
-			   mmu/spte.o
+			   mmu/spte.o mmu/shadow_mmu.o
 
 ifdef CONFIG_HYPERV
 kvm-y			+= kvm_onhyperv.o
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 4736d7849c60..07b99a7ce830 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -20,6 +20,7 @@ 
 #include "mmu.h"
 #include "mmu_internal.h"
 #include "tdp_mmu.h"
+#include "shadow_mmu.h"
 #include "x86.h"
 #include "kvm_cache_regs.h"
 #include "smm.h"
diff --git a/arch/x86/kvm/mmu/shadow_mmu.c b/arch/x86/kvm/mmu/shadow_mmu.c
new file mode 100644
index 000000000000..7bce5ec52b2e
--- /dev/null
+++ b/arch/x86/kvm/mmu/shadow_mmu.c
@@ -0,0 +1,21 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KVM Shadow MMU
+ *
+ * This file implements the Shadow MMU: the KVM MMU implementation which has
+ * developed organically from hardware which did not have second level paging,
+ * and so used "shadow paging" to virtualize guest memory. The Shadow MMU is
+ * an alternative to the TDP MMU which only supports hardware with Two
+ * Dimentional Paging. (e.g. EPT on Intel or NPT on AMD CPUs.) Note that the
+ * Shadow MMU also supports TDP, it's just less scalable. The Shadow and TDP
+ * MMUs can cooperate to support nested virtualization on hardware with TDP.
+ */
+#include "mmu.h"
+#include "mmu_internal.h"
+#include "mmutrace.h"
+#include "shadow_mmu.h"
+#include "spte.h"
+
+#include <asm/vmx.h>
+#include <asm/cmpxchg.h>
+#include <trace/events/kvm.h>
diff --git a/arch/x86/kvm/mmu/shadow_mmu.h b/arch/x86/kvm/mmu/shadow_mmu.h
new file mode 100644
index 000000000000..719b10f6c403
--- /dev/null
+++ b/arch/x86/kvm/mmu/shadow_mmu.h
@@ -0,0 +1,8 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __KVM_X86_MMU_SHADOW_MMU_H
+#define __KVM_X86_MMU_SHADOW_MMU_H
+
+#include <linux/kvm_host.h>
+
+#endif /* __KVM_X86_MMU_SHADOW_MMU_H */