Skip to contentSkip to conversation

KVM: PPC: E500: Support hugetlbfs

PATCH In review Alexander Graf 2 participants 4 messages Oct 5, 2011

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

PATCH 1/1 KVM: PPC: E500: Support hugetlbfs

With hugetlbfs support emerging on e500, we should also support KVM backing its guest memory by it.

This patch adds support for hugetlbfs into the e500 shadow mmu code.

---

v1 -> v2:

- address scott's comments

---
 arch/powerpc/kvm/e500_tlb.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
arch/powerpc/kvm/e500_tlb.c +24 -0
index ec17148..1dd96a9 100644
@@ -24,6 +24,7 @@
 #include <linux/sched.h>
 #include <linux/rwsem.h>
 #include <linux/vmalloc.h>
+#include <linux/hugetlb.h>
 #include <asm/kvm_ppc.h>
 #include <asm/kvm_e500.h>
 
@@ -673,12 +674,31 @@ static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 				pfn &= ~(tsize_pages - 1);
 				break;
 			}
+		} else if (vma && hva >= vma->vm_start &&
+                           (vma->vm_flags & VM_HUGETLB)) {
+			unsigned long psize = vma_kernel_pagesize(vma);
+
+			tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >>
+				MAS1_TSIZE_SHIFT;
+
+			/*
+			 * Take the largest page size that satisfies both host
+			 * and guest mapping
+			 */
+			tsize = min(__ilog2(psize) - 10, tsize);
+
+			/*
+			 * e500 doesn't implement the lowest tsize bit,
+			 * or 1K pages.
+			 */
+			tsize = max(BOOK3E_PAGESZ_4K, tsize & ~1);
 		}
 
 		up_read(&current->mm->mmap_sem);
 	}
 
 	if (likely(!pfnmap)) {
+		unsigned long tsize_pages = 1 << (tsize + 10 - PAGE_SHIFT);
 		pfn = gfn_to_pfn_memslot(vcpu_e500->vcpu.kvm, slot, gfn);
 		if (is_error_pfn(pfn)) {
 			printk(KERN_ERR "Couldn't get real page for gfn %lx!\n",
@@ -686,6 +706,10 @@ static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 			kvm_release_pfn_clean(pfn);
 			return;
 		}
+
+		/* Align guest and physical address to page map boundaries */
+		pfn &= ~(tsize_pages - 1);
+		gvaddr &= ~((tsize_pages << PAGE_SHIFT) - 1);
 	}
 
 	/* Drop old ref and setup new one. */
Signature · 1 line
1.6.0.2
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Alexander Graf
arch/powerpc/kvm/e500_tlb.c +3 -0
index ec17148..1dd96a9 100644
@@ -24,6 +24,7 @@
 #include <linux/sched.h>
 #include <linux/rwsem.h>
 #include <linux/vmalloc.h>
+#include <linux/hugetlb.h>
 #include <asm/kvm_ppc.h>
 #include <asm/kvm_e500.h>
 
@@ -673,12 +674,31 @@ static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 				pfn &= ~(tsize_pages - 1);
 				break;
 			}
+		} else if (vma && hva >= vma->vm_start &&
+                           (vma->vm_flags & VM_HUGETLB)) {

arch/powerpc/kvm/e500_tlb.c static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, · line 688

Quoted 10 lines
arch/powerpc/kvm/e500_tlb.c +10 -0
+			unsigned long psize = vma_kernel_pagesize(vma);
+
+			tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >>
+				MAS1_TSIZE_SHIFT;
+
+			/*
+			 * Take the largest page size that satisfies both host
+			 * and guest mapping
+			 */
+			tsize = min(__ilog2(psize) - 10, tsize);

Any reason for __ilog2() rather than ilog2()? Shouldn't make a difference, just curious about avoiding the public interface.

Either way,

-Scott

#2 lore raw
Quoted 24 lines · Scott Wood
Quoted 23 lines · Alexander Graf
arch/powerpc/kvm/e500_tlb.c +8 -0
index ec17148..1dd96a9 100644
@@ -24,6 +24,7 @@
 #include <linux/sched.h>
 #include <linux/rwsem.h>
 #include <linux/vmalloc.h>
+#include <linux/hugetlb.h>
 #include <asm/kvm_ppc.h>
 #include <asm/kvm_e500.h>
 
@@ -673,12 +674,31 @@ static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 				pfn &= ~(tsize_pages - 1);
 				break;
 			}
+		} else if (vma && hva >= vma->vm_start &&
+                           (vma->vm_flags & VM_HUGETLB)) {
+			unsigned long psize = vma_kernel_pagesize(vma);
+
+			tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >>
+				MAS1_TSIZE_SHIFT;
+
Quoted 8 lines

arch/powerpc/kvm/e500_tlb.c static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, · line 688

Quoted 5 lines
arch/powerpc/kvm/e500_tlb.c +5 -0
+			/*
+			 * Take the largest page size that satisfies both host
+			 * and guest mapping
+			 */
+			tsize = min(__ilog2(psize) - 10, tsize);

Any reason for __ilog2() rather than ilog2()? Shouldn't make a difference, just curious about avoiding the public interface.

I grep'ed through the kernel tree and only found __ilog2 defined as well as mostly users for __ilog2, so I figured there's got to be a reason ;)

Alex

#3 lore raw
Quoted 7 lines · Alexander Graf
Quoted 2 lines · Scott Wood

Any reason for __ilog2() rather than ilog2()? Shouldn't make a difference, just curious about avoiding the public interface.

I grep'ed through the kernel tree and only found __ilog2 defined as well as mostly users for __ilog2, so I figured there's got to be a reason ;)

ilog2() is defined in include/linux/ilog2.h. It produces constant output if the input is constant, and appears to be the "front door" to __ilog2_u32/__ilog2_u64. Plain __ilog2 is older and powerpc-specific, which is probably why there are more users of that in arch/powerpc.

-Scott