2020-06-22 20:24:33

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH 0/6] KVM: x86/mmu: Files and sp helper cleanups

Move more files to the mmu/ directory, and an mmu_internal.h to share
stuff amongst the mmu/ files, and clean up the helpers for retrieving a
shadow page from a sptep and/or hpa.

Sean Christopherson (6):
KVM: x86/mmu: Move mmu_audit.c and mmutrace.h into the mmu/
sub-directory
KVM: x86/mmu: Move kvm_mmu_available_pages() into mmu.c
KVM: x86/mmu: Add MMU-internal header
KVM: x86/mmu: Make kvm_mmu_page definition and accessor internal-only
KVM: x86/mmu: Add sptep_to_sp() helper to wrap shadow page lookup
KVM: x86/mmu: Rename page_header() to to_shadow_page()

arch/x86/include/asm/kvm_host.h | 46 +---------------------
arch/x86/kvm/mmu.h | 13 ------
arch/x86/kvm/mmu/mmu.c | 58 +++++++++++++++------------
arch/x86/kvm/{ => mmu}/mmu_audit.c | 12 +++---
arch/x86/kvm/mmu/mmu_internal.h | 63 ++++++++++++++++++++++++++++++
arch/x86/kvm/{ => mmu}/mmutrace.h | 2 +-
arch/x86/kvm/mmu/page_track.c | 2 +-
arch/x86/kvm/mmu/paging_tmpl.h | 4 +-
8 files changed, 108 insertions(+), 92 deletions(-)
rename arch/x86/kvm/{ => mmu}/mmu_audit.c (96%)
create mode 100644 arch/x86/kvm/mmu/mmu_internal.h
rename arch/x86/kvm/{ => mmu}/mmutrace.h (99%)

--
2.26.0


2020-06-22 20:24:50

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH 3/6] KVM: x86/mmu: Add MMU-internal header

Add mmu/mmu_internal.h to hold declarations and definitions that need
to be shared between various mmu/ files, but should not be used by
anything outside of the MMU.

Begin populating mmu_internal.h with declarations of the helpers used by
page_track.c.

Signed-off-by: Sean Christopherson <[email protected]>
---
arch/x86/kvm/mmu.h | 4 ----
arch/x86/kvm/mmu/mmu.c | 1 +
arch/x86/kvm/mmu/mmu_internal.h | 10 ++++++++++
arch/x86/kvm/mmu/page_track.c | 2 +-
4 files changed, 12 insertions(+), 5 deletions(-)
create mode 100644 arch/x86/kvm/mmu/mmu_internal.h

diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index d46944488e72..434acfcbf710 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -209,10 +209,6 @@ static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,

void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end);

-void kvm_mmu_gfn_disallow_lpage(struct kvm_memory_slot *slot, gfn_t gfn);
-void kvm_mmu_gfn_allow_lpage(struct kvm_memory_slot *slot, gfn_t gfn);
-bool kvm_mmu_slot_gfn_write_protect(struct kvm *kvm,
- struct kvm_memory_slot *slot, u64 gfn);
int kvm_arch_write_log_dirty(struct kvm_vcpu *vcpu);

int kvm_mmu_post_init_vm(struct kvm *kvm);
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 1b4d45b8f462..c1bf30e24bfc 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -18,6 +18,7 @@
#include "irq.h"
#include "ioapic.h"
#include "mmu.h"
+#include "mmu_internal.h"
#include "x86.h"
#include "kvm_cache_regs.h"
#include "kvm_emulate.h"
diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
new file mode 100644
index 000000000000..d7938c37c7de
--- /dev/null
+++ b/arch/x86/kvm/mmu/mmu_internal.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __KVM_X86_MMU_INTERNAL_H
+#define __KVM_X86_MMU_INTERNAL_H
+
+void kvm_mmu_gfn_disallow_lpage(struct kvm_memory_slot *slot, gfn_t gfn);
+void kvm_mmu_gfn_allow_lpage(struct kvm_memory_slot *slot, gfn_t gfn);
+bool kvm_mmu_slot_gfn_write_protect(struct kvm *kvm,
+ struct kvm_memory_slot *slot, u64 gfn);
+
+#endif /* __KVM_X86_MMU_INTERNAL_H */
diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c
index a7bcde34d1f2..a84a141a2ad2 100644
--- a/arch/x86/kvm/mmu/page_track.c
+++ b/arch/x86/kvm/mmu/page_track.c
@@ -16,7 +16,7 @@

#include <asm/kvm_page_track.h>

-#include "mmu.h"
+#include "mmu_internal.h"

void kvm_page_track_free_memslot(struct kvm_memory_slot *slot)
{
--
2.26.0

2020-06-22 20:25:00

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH 1/6] KVM: x86/mmu: Move mmu_audit.c and mmutrace.h into the mmu/ sub-directory

Move mmu_audit.c and mmutrace.h under mmu/ where they belong.

Signed-off-by: Sean Christopherson <[email protected]>
---
arch/x86/kvm/{ => mmu}/mmu_audit.c | 0
arch/x86/kvm/{ => mmu}/mmutrace.h | 2 +-
2 files changed, 1 insertion(+), 1 deletion(-)
rename arch/x86/kvm/{ => mmu}/mmu_audit.c (100%)
rename arch/x86/kvm/{ => mmu}/mmutrace.h (99%)

diff --git a/arch/x86/kvm/mmu_audit.c b/arch/x86/kvm/mmu/mmu_audit.c
similarity index 100%
rename from arch/x86/kvm/mmu_audit.c
rename to arch/x86/kvm/mmu/mmu_audit.c
diff --git a/arch/x86/kvm/mmutrace.h b/arch/x86/kvm/mmu/mmutrace.h
similarity index 99%
rename from arch/x86/kvm/mmutrace.h
rename to arch/x86/kvm/mmu/mmutrace.h
index ffcd96fc02d0..9d15bc0c535b 100644
--- a/arch/x86/kvm/mmutrace.h
+++ b/arch/x86/kvm/mmu/mmutrace.h
@@ -387,7 +387,7 @@ TRACE_EVENT(
#endif /* _TRACE_KVMMMU_H */

#undef TRACE_INCLUDE_PATH
-#define TRACE_INCLUDE_PATH .
+#define TRACE_INCLUDE_PATH mmu
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE mmutrace

--
2.26.0

2020-06-22 20:41:56

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH 2/6] KVM: x86/mmu: Move kvm_mmu_available_pages() into mmu.c

Move kvm_mmu_available_pages() from mmu.h to mmu.c, it has a single
caller and has no business being exposed via mmu.h.

Signed-off-by: Sean Christopherson <[email protected]>
---
arch/x86/kvm/mmu.h | 9 ---------
arch/x86/kvm/mmu/mmu.c | 9 +++++++++
2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index 0ad06bfe2c2c..d46944488e72 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -64,15 +64,6 @@ bool kvm_can_do_async_pf(struct kvm_vcpu *vcpu);
int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
u64 fault_address, char *insn, int insn_len);

-static inline unsigned long kvm_mmu_available_pages(struct kvm *kvm)
-{
- if (kvm->arch.n_max_mmu_pages > kvm->arch.n_used_mmu_pages)
- return kvm->arch.n_max_mmu_pages -
- kvm->arch.n_used_mmu_pages;
-
- return 0;
-}
-
static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu)
{
if (likely(vcpu->arch.mmu->root_hpa != INVALID_PAGE))
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index fdd05c233308..1b4d45b8f462 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -2825,6 +2825,15 @@ static bool prepare_zap_oldest_mmu_page(struct kvm *kvm,
return kvm_mmu_prepare_zap_page(kvm, sp, invalid_list);
}

+static inline unsigned long kvm_mmu_available_pages(struct kvm *kvm)
+{
+ if (kvm->arch.n_max_mmu_pages > kvm->arch.n_used_mmu_pages)
+ return kvm->arch.n_max_mmu_pages -
+ kvm->arch.n_used_mmu_pages;
+
+ return 0;
+}
+
static int make_mmu_pages_available(struct kvm_vcpu *vcpu)
{
LIST_HEAD(invalid_list);
--
2.26.0

2020-07-03 17:21:36

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH 0/6] KVM: x86/mmu: Files and sp helper cleanups

On 22/06/20 22:20, Sean Christopherson wrote:
> Move more files to the mmu/ directory, and an mmu_internal.h to share
> stuff amongst the mmu/ files, and clean up the helpers for retrieving a
> shadow page from a sptep and/or hpa.
>
> Sean Christopherson (6):
> KVM: x86/mmu: Move mmu_audit.c and mmutrace.h into the mmu/
> sub-directory
> KVM: x86/mmu: Move kvm_mmu_available_pages() into mmu.c
> KVM: x86/mmu: Add MMU-internal header
> KVM: x86/mmu: Make kvm_mmu_page definition and accessor internal-only
> KVM: x86/mmu: Add sptep_to_sp() helper to wrap shadow page lookup
> KVM: x86/mmu: Rename page_header() to to_shadow_page()
>
> arch/x86/include/asm/kvm_host.h | 46 +---------------------
> arch/x86/kvm/mmu.h | 13 ------
> arch/x86/kvm/mmu/mmu.c | 58 +++++++++++++++------------
> arch/x86/kvm/{ => mmu}/mmu_audit.c | 12 +++---
> arch/x86/kvm/mmu/mmu_internal.h | 63 ++++++++++++++++++++++++++++++
> arch/x86/kvm/{ => mmu}/mmutrace.h | 2 +-
> arch/x86/kvm/mmu/page_track.c | 2 +-
> arch/x86/kvm/mmu/paging_tmpl.h | 4 +-
> 8 files changed, 108 insertions(+), 92 deletions(-)
> rename arch/x86/kvm/{ => mmu}/mmu_audit.c (96%)
> create mode 100644 arch/x86/kvm/mmu/mmu_internal.h
> rename arch/x86/kvm/{ => mmu}/mmutrace.h (99%)
>

Queued, thanks.

Paolo