Skip to contentSkip to conversation

KVM: ARM: Transparent huge pages and hugetlbfs support

RFC PATCH New Christoffer Dall 2 participants 3 messages Jun 18, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 KVM: ARM: Transparent huge pages and hugetlbfs support

From: Christoffer Dall <[email protected]>

Support transparent huge pages in 32-bit KVM/ARM. The whole transparent_hugepage_adjust stuff is far from pretty, but this is how it's solved on x86 so we duplicate their logic. This should be shared across architectures if possible (like many other things), but can always be changed down the road.

The pud_huge checking on the unmap path may feel a bit silly as the pud_huge check is always defined to false, but the compiler should be smart about this.

---
 arch/arm/include/asm/kvm_host.h |   7 +-
 arch/arm/include/asm/kvm_mmu.h  |   6 +-
 arch/arm/kvm/mmu.c              | 158 +++++++++++++++++++++++++++++++++-------
 3 files changed, 137 insertions(+), 34 deletions(-)
arch/arm/include/asm/kvm_host.h +3 -4
index 1f3cee2..45a165e 100644
@@ -33,10 +33,9 @@
 
 #define KVM_VCPU_MAX_FEATURES 1
 
-/* We don't currently support large pages. */
-#define KVM_HPAGE_GFN_SHIFT(x)	0
-#define KVM_NR_PAGE_SIZES	1
-#define KVM_PAGES_PER_HPAGE(x)	(1UL<<31)
+#define KVM_HPAGE_GFN_SHIFT(_level)	(((_level) - 1) * 21)
+#define KVM_HPAGE_SIZE			(1UL << KVM_HPAGE_GFN_SHIFT(2))
+#define KVM_PAGES_PER_HPAGE		(KVM_HPAGE_SIZE / PAGE_SIZE)
 
 #include <kvm/arm_vgic.h>
 
arch/arm/include/asm/kvm_mmu.h +3 -3
index 472ac70..9ef71b1 100644
@@ -105,7 +105,8 @@ static inline void kvm_set_s2pte_writable(pte_t *pte)
 
 struct kvm;
 
-static inline void coherent_icache_guest_page(struct kvm *kvm, gfn_t gfn)
+static inline void coherent_icache_guest_page(struct kvm *kvm, hva_t hva,
+					      unsigned long size)
 {
 	/*
 	 * If we are going to insert an instruction page and the icache is
@@ -120,8 +121,7 @@ static inline void coherent_icache_guest_page(struct kvm *kvm, gfn_t gfn)
 	 * need any kind of flushing (DDI 0406C.b - Page B3-1392).
 	 */
 	if (icache_is_pipt()) {
-		unsigned long hva = gfn_to_hva(kvm, gfn);
-		__cpuc_coherent_user_range(hva, hva + PAGE_SIZE);
+		__cpuc_coherent_user_range(hva, hva + size);
 	} else if (!icache_is_vivt_asid_tagged()) {
 		/* any kind of VIPT cache */
 		__flush_icache_all();
arch/arm/kvm/mmu.c +131 -27

237 lines not on this page · raw message

Signature · 1 line
1.8.1.2
#1 lore raw

RFC PATCH 2/2 arm64: KVM: Fix build errors after 32-bit THP support

When KVM 32-bit adds THP support the build of KVM/arm64 will break because we rename some definition to be more sane and change the interface to coherent_icache_guest_page.

Huge pages are not supported on arm64 and the pgtable predicates will always return false, so this shouldn't change any functionality on the 64-bit side.

---
 arch/arm64/include/asm/kvm_host.h | 4 ++--
 arch/arm64/include/asm/kvm_mmu.h  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
arch/arm64/include/asm/kvm_host.h +2 -2
index 644d739..f5d73dc 100644
@@ -38,8 +38,8 @@
 
 /* We don't currently support large pages. */
 #define KVM_HPAGE_GFN_SHIFT(x)	0
-#define KVM_NR_PAGE_SIZES	1
-#define KVM_PAGES_PER_HPAGE(x)	(1UL<<31)
+#define KVM_HPAGE_SIZE		1
+#define KVM_PAGES_PER_HPAGE	(1UL<<31)
 
 struct kvm_vcpu;
 int kvm_target_cpu(void);
arch/arm64/include/asm/kvm_mmu.h +3 -3
index efe609c..c86749e 100644
@@ -118,11 +118,11 @@ static inline void kvm_set_s2pte_writable(pte_t *pte)
 
 struct kvm;
 
-static inline void coherent_icache_guest_page(struct kvm *kvm, gfn_t gfn)
+static inline void coherent_icache_guest_page(struct kvm *kvm, hva_t hva,
+					      size_t size)
 {
 	if (!icache_is_aliasing()) {		/* PIPT */
-		unsigned long hva = gfn_to_hva(kvm, gfn);
-		flush_icache_range(hva, hva + PAGE_SIZE);
+		flush_icache_range(hva, hva + size);
 	} else if (!icache_is_aivivt()) {	/* non ASID-tagged VIVT */
 		/* any kind of VIPT cache */
 		__flush_icache_all();
Signature · 1 line
1.8.1.2
maintainer
#2 lore raw

RFC PATCH 2/2 arm64: KVM: Fix build errors after 32-bit THP support

Quoted 7 lines · Christoffer Dall

When KVM 32-bit adds THP support the build of KVM/arm64 will break because we rename some definition to be more sane and change the interface to coherent_icache_guest_page.

Huge pages are not supported on arm64 and the pgtable predicates will always return false, so this shouldn't change any functionality on the 64-bit side.

FYI, huge pages will be supported on arm64 starting with 3.11-rc1. Given that it's -rc6 now, I would suggest you aim the kvm patches at 3.12.

Signature · 1 line
Catalin