Skip to contentSkip to conversation

Hugetlb for 32-bit FSL PowerPC BookE

PATCH Applied Becky Bruce 5 participants 13 messages Jun 28, 2011 – Jul 24, 2011

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

cover Hugetlb for 32-bit FSL PowerPC BookE

Implement HugeTLB for 32-bit BookE PowerPC. There is also some infrastructure in place for 64-bit BookE as well from David Gibson; I'm not sure if we want to include this at this time or not. I have only been able to build test the 64-bit configurations. Ben, let me know how you want to proceed here.

The bulk of this patch series is powerpc-specific, but there are a couple of minor fixes to the generic fs and mm code included, hence the cross-post.

Note that to use this fully some modifications to libhugetlbfs are required; I expect to publish those shortly.

Diffstat below.

Cheers,
Becky

arch/powerpc/Kconfig                   |    3 +-
arch/powerpc/include/asm/hugetlb.h     |   63 +++++-
arch/powerpc/include/asm/mmu-book3e.h  |    7 +
arch/powerpc/include/asm/mmu-hash64.h  |    3 +-
arch/powerpc/include/asm/mmu.h         |   23 ++-
arch/powerpc/include/asm/page.h        |   31 +++-
arch/powerpc/include/asm/page_64.h     |   11 -
arch/powerpc/include/asm/pte-book3e.h  |    3 +
arch/powerpc/kernel/head_fsl_booke.S   |  133 ++++++++++--
arch/powerpc/kernel/smp.c              |    4 +
arch/powerpc/mm/Makefile               |    1 +
arch/powerpc/mm/hash_utils_64.c        |    3 -
arch/powerpc/mm/hugetlbpage-book3e.c   |  121 ++++++++++
arch/powerpc/mm/hugetlbpage.c          |  379 ++++++++++++++++++++++++++++----
arch/powerpc/mm/init_32.c              |    9 +
arch/powerpc/mm/mem.c                  |   17 ++-
arch/powerpc/mm/mmu_context_nohash.c   |    5 +
arch/powerpc/mm/pgtable.c              |    3 +-
arch/powerpc/mm/tlb_low_64e.S          |   24 +-
arch/powerpc/mm/tlb_nohash.c           |   52 +++++-
arch/powerpc/platforms/Kconfig.cputype |    4 +-
fs/hugetlbfs/inode.c                   |    2 +-
include/linux/hugetlb.h                |    3 +
mm/hugetlb.c                           |    8 +-
24 files changed, 803 insertions(+), 109 deletions(-)
#1 lore raw

PATCH 1/5 fs/hugetlbfs/inode.c: Fix pgoff alignment checking on 32-bit

From: Becky Bruce <[email protected]>

This:

vma->vm_pgoff & ~(huge_page_mask(h) >> PAGE_SHIFT)

is incorrect on 32-bit. It causes us to & the pgoff with something that looks like this (for a 4m hugepage): 0xfff003ff. The mask should be flipped and *then* shifted, to give you 0x0000_03fff.

---
 fs/hugetlbfs/inode.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/hugetlbfs/inode.c +1 -1
index 7aafeb8..537a209 100644
@@ -94,7 +94,7 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
 	vma->vm_flags |= VM_HUGETLB | VM_RESERVED;
 	vma->vm_ops = &hugetlb_vm_ops;
 
-	if (vma->vm_pgoff & ~(huge_page_mask(h) >> PAGE_SHIFT))
+	if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT))
 		return -EINVAL;
 
 	vma_len = (loff_t)(vma->vm_end - vma->vm_start);
Signature · 1 line
1.5.6.5
#2 lore raw

PATCH 2/5 hugetlb: add phys addr to struct huge_bootmem_page

From: Becky Bruce <[email protected]>

This is needed on HIGHMEM systems - we don't always have a virtual address so store the physical address and map it in as needed.

---
 include/linux/hugetlb.h |    3 +++
 mm/hugetlb.c            |    8 +++++++-
 2 files changed, 10 insertions(+), 1 deletions(-)
include/linux/hugetlb.h +3 -0
index 59225ef..19644e0 100644
@@ -231,6 +231,9 @@ struct hstate {
 struct huge_bootmem_page {
 	struct list_head list;
 	struct hstate *hstate;
+#ifdef CONFIG_HIGHMEM
+	phys_addr_t phys;
+#endif
 };
 
 struct page *alloc_huge_page_node(struct hstate *h, int nid);
mm/hugetlb.c +7 -1
index 6402458..2db81ea 100644
@@ -1105,8 +1105,14 @@ static void __init gather_bootmem_prealloc(void)
 	struct huge_bootmem_page *m;
 
 	list_for_each_entry(m, &huge_boot_pages, list) {
-		struct page *page = virt_to_page(m);
 		struct hstate *h = m->hstate;
+#ifdef CONFIG_HIGHMEM
+		struct page *page = pfn_to_page(m->phys >> PAGE_SHIFT);
+		free_bootmem_late((unsigned long)m,
+				  sizeof(struct huge_bootmem_page));
+#else
+		struct page *page = virt_to_page(m);
+#endif
 		__ClearPageReserved(page);
 		WARN_ON(page_count(page) != 1);
 		prep_compound_huge_page(page, h->order);
Signature · 1 line
1.5.6.5
#3 lore raw

PATCH 3/5 powerpc: mem_init should call memblock_is_reserved with phys_addr_t

From: Becky Bruce <[email protected]>

This has been broken for a while but hasn't been an issue until now because nobody was reserving regions at high addresses.

---
 arch/powerpc/mm/mem.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/powerpc/mm/mem.c +2 -1
index 57e545b..097b288 100644
@@ -337,8 +337,9 @@ void __init mem_init(void)
 
 		highmem_mapnr = lowmem_end_addr >> PAGE_SHIFT;
 		for (pfn = highmem_mapnr; pfn < max_mapnr; ++pfn) {
+			phys_addr_t paddr = (phys_addr_t)pfn << PAGE_SHIFT;
 			struct page *page = pfn_to_page(pfn);
-			if (memblock_is_reserved(pfn << PAGE_SHIFT))
+			if (memblock_is_reserved(paddr))
 				continue;
 			ClearPageReserved(page);
 			init_page_count(page);
Signature · 1 line
1.5.6.5
#4 lore raw

PATCH 4/5 powerpc: Create next_tlbcam_idx percpu variable for FSL_BOOKE

From: Becky Bruce <[email protected]>

This is used to round-robin TLBCAM entries.

---
 arch/powerpc/include/asm/mmu.h |    5 +++++
 arch/powerpc/kernel/smp.c      |    4 ++++
 arch/powerpc/mm/mem.c          |    9 +++++++++
 arch/powerpc/mm/tlb_nohash.c   |    6 ++++++
 4 files changed, 24 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/mmu.h +5 -0
index 4138b21..b427a55 100644
@@ -115,6 +115,11 @@
 #ifndef __ASSEMBLY__
 #include <asm/cputable.h>
 
+#ifdef CONFIG_PPC_FSL_BOOK3E
+#include <asm/percpu.h>
+DECLARE_PER_CPU(int, next_tlbcam_idx);
+#endif
+
 static inline int mmu_has_feature(unsigned long feature)
 {
 	return (cur_cpu_spec->mmu_features & feature);
arch/powerpc/kernel/smp.c +4 -0
index 2975f64..3c9681a 100644
@@ -313,6 +313,10 @@ struct thread_info *current_set[NR_CPUS];
 static void __devinit smp_store_cpu_info(int id)
 {
 	per_cpu(cpu_pvr, id) = mfspr(SPRN_PVR);
+#ifdef CONFIG_PPC_FSL_BOOK3E
+	per_cpu(next_tlbcam_idx, id)
+		= (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) - 1;
+#endif
 }
 
 void __init smp_prepare_cpus(unsigned int max_cpus)
arch/powerpc/mm/mem.c +9 -0
index 097b288..7209901 100644
@@ -353,6 +353,15 @@ void __init mem_init(void)
 	}
 #endif /* CONFIG_HIGHMEM */
 
+#if defined(CONFIG_PPC_FSL_BOOK3E) && !defined(CONFIG_SMP)
+	/*
+	 * If smp is enabled, next_tlbcam_idx is initialized in the cpu up
+	 * functions.... do it here for the non-smp case.
+	 */
+	per_cpu(next_tlbcam_idx, smp_processor_id()) =
+		(mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) - 1;
+#endif
+
 	printk(KERN_INFO "Memory: %luk/%luk available (%luk kernel code, "
 	       "%luk reserved, %luk data, %luk bss, %luk init)\n",
 		nr_free_pages() << (PAGE_SHIFT-10),
arch/powerpc/mm/tlb_nohash.c +6 -0
index 5693499..ea037ba 100644
@@ -102,6 +102,12 @@ unsigned long linear_map_top;	/* Top of linear mapping */
 
 #endif /* CONFIG_PPC64 */
 
+#ifdef CONFIG_PPC_FSL_BOOK3E
+/* next_tlbcam_idx is used to round-robin tlbcam entry assignment */
+DEFINE_PER_CPU(int, next_tlbcam_idx);
+EXPORT_PER_CPU_SYMBOL(next_tlbcam_idx);
+#endif
+
 /*
  * Base TLB flushing operations:
  *
Signature · 1 line
1.5.6.5
#5 lore raw

PATCH 5/5 powerpc: Hugetlb for BookE

From: Becky Bruce <[email protected]>

Enable hugepages on Freescale BookE processors. This allows the kernel to use huge TLB entries to map pages, which can greatly reduce the number of TLB misses and the amount of TLB thrashing experienced by applications with large memory footprints. Care should be taken when using this on FSL processors, as the number of large TLB entries supported by the core is low (16-64) on current processors.

The supported set of hugepage sizes include 4m, 16m, 64m, 256m, and 1g. Page sizes larger than the max zone size are called "gigantic" pages and must be allocated on the command line (and cannot be deallocated).

This is currently only fully implemented for Freescale 32-bit BookE processors, but there is some infrastructure in the code for 64-bit BooKE.

---
 arch/powerpc/Kconfig                   |    3 +-
 arch/powerpc/include/asm/hugetlb.h     |   63 +++++-
 arch/powerpc/include/asm/mmu-book3e.h  |    7 +
 arch/powerpc/include/asm/mmu-hash64.h  |    3 +-
 arch/powerpc/include/asm/mmu.h         |   18 +-
 arch/powerpc/include/asm/page.h        |   31 +++-
 arch/powerpc/include/asm/page_64.h     |   11 -
 arch/powerpc/include/asm/pte-book3e.h  |    3 +
 arch/powerpc/kernel/head_fsl_booke.S   |  133 ++++++++++--
 arch/powerpc/mm/Makefile               |    1 +
 arch/powerpc/mm/hash_utils_64.c        |    3 -
 arch/powerpc/mm/hugetlbpage-book3e.c   |  121 ++++++++++
 arch/powerpc/mm/hugetlbpage.c          |  379 ++++++++++++++++++++++++++++----
 arch/powerpc/mm/init_32.c              |    9 +
 arch/powerpc/mm/mem.c                  |    5 +
 arch/powerpc/mm/mmu_context_nohash.c   |    5 +
 arch/powerpc/mm/pgtable.c              |    3 +-
 arch/powerpc/mm/tlb_low_64e.S          |   24 +-
 arch/powerpc/mm/tlb_nohash.c           |   46 ++++-
 arch/powerpc/platforms/Kconfig.cputype |    4 +-
 20 files changed, 766 insertions(+), 106 deletions(-)
 create mode 100644 arch/powerpc/mm/hugetlbpage-book3e.c
arch/powerpc/Kconfig +1 -2
index 2729c66..b7af257 100644
@@ -426,8 +426,7 @@ config ARCH_POPULATES_NODE_MAP
 	def_bool y
 
 config SYS_SUPPORTS_HUGETLBFS
-       def_bool y
-       depends on PPC_BOOK3S_64
+	bool
 
 source "mm/Kconfig"
 
arch/powerpc/include/asm/hugetlb.h +61 -2

88 lines not on this page · raw message

arch/powerpc/include/asm/mmu-book3e.h +7 -0
index 3ea0f9a..0260ea5 100644
@@ -66,6 +66,7 @@
 #define MAS2_M			0x00000004
 #define MAS2_G			0x00000002
 #define MAS2_E			0x00000001
+#define MAS2_WIMGE_MASK		0x0000001f
 #define MAS2_EPN_MASK(size)		(~0 << (size + 10))
 #define MAS2_VAL(addr, size, flags)	((addr) & MAS2_EPN_MASK(size) | (flags))
 
@@ -80,6 +81,7 @@
 #define MAS3_SW			0x00000004
 #define MAS3_UR			0x00000002
 #define MAS3_SR			0x00000001
+#define MAS3_BAP_MASK		0x0000003f
 #define MAS3_SPSIZE		0x0000003e
 #define MAS3_SPSIZE_SHIFT	1
 
@@ -212,6 +214,11 @@ typedef struct {
 	unsigned int	id;
 	unsigned int	active;
 	unsigned long	vdso_base;
+#ifdef CONFIG_PPC_MM_SLICES
+	u64 low_slices_psize;   /* SLB page size encodings */
+	u64 high_slices_psize;  /* 4 bits per slice for now */
+	u16 user_psize;         /* page size index */
+#endif
 } mm_context_t;
 
 /* Page size definitions, common between 32 and 64-bit
arch/powerpc/include/asm/mmu-hash64.h +1 -2
index d865bd9..9169032 100644
@@ -256,8 +256,7 @@ extern void hash_failure_debug(unsigned long ea, unsigned long access,
 extern int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
 			     unsigned long pstart, unsigned long prot,
 			     int psize, int ssize);
-extern void add_gpage(unsigned long addr, unsigned long page_size,
-			  unsigned long number_of_pages);
+extern void add_gpage(u64 addr, u64 page_size, unsigned long number_of_pages);
 extern void demote_segment_4k(struct mm_struct *mm, unsigned long addr);
 
 extern void hpte_init_native(void);
arch/powerpc/include/asm/mmu.h +10 -8
index b427a55..07f7b28 100644
@@ -170,14 +170,16 @@ extern u64 ppc64_rma_size;
 #define MMU_PAGE_64K_AP	3	/* "Admixed pages" (hash64 only) */
 #define MMU_PAGE_256K	4
 #define MMU_PAGE_1M	5
-#define MMU_PAGE_8M	6
-#define MMU_PAGE_16M	7
-#define MMU_PAGE_256M	8
-#define MMU_PAGE_1G	9
-#define MMU_PAGE_16G	10
-#define MMU_PAGE_64G	11
-#define MMU_PAGE_COUNT	12
-
+#define MMU_PAGE_4M	6
+#define MMU_PAGE_8M	7
+#define MMU_PAGE_16M	8
+#define MMU_PAGE_64M	9
+#define MMU_PAGE_256M	10
+#define MMU_PAGE_1G	11
+#define MMU_PAGE_16G	12
+#define MMU_PAGE_64G	13
+
+#define MMU_PAGE_COUNT	14
 
 #if defined(CONFIG_PPC_STD_MMU_64)
 /* 64-bit classic hash table MMU */
arch/powerpc/include/asm/page.h +30 -1
index 2cd664e..dd9c4fd 100644
@@ -36,6 +36,18 @@
 
 #define PAGE_SIZE		(ASM_CONST(1) << PAGE_SHIFT)
 
+#ifndef __ASSEMBLY__
+#ifdef CONFIG_HUGETLB_PAGE
+extern unsigned int HPAGE_SHIFT;
+#else
+#define HPAGE_SHIFT PAGE_SHIFT
+#endif
+#define HPAGE_SIZE		((1UL) << HPAGE_SHIFT)
+#define HPAGE_MASK		(~(HPAGE_SIZE - 1))
+#define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
+#define HUGE_MAX_HSTATE		(MMU_PAGE_COUNT-1)
+#endif
+
 /* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */
 #define __HAVE_ARCH_GATE_AREA		1
 
@@ -158,6 +170,24 @@ extern phys_addr_t kernstart_addr;
 #define is_kernel_addr(x)	((x) >= PAGE_OFFSET)
 #endif
 
+/*
+ * Use the top bit of the higher-level page table entries to indicate whether
+ * the entries we point to contain hugepages.  This works because we know that
+ * the page tables live in kernel space.  If we ever decide to support having
+ * page tables at arbitrary addresses, this breaks and will have to change.
+ */
+#ifdef CONFIG_PPC64
+#define PD_HUGE 0x8000000000000000
+#else
+#define PD_HUGE 0x80000000
+#endif
+
+/*
+ * Some number of bits at the level of the page table that points to
+ * a hugepte are used to encode the size.  This masks those bits.
+ */
+#define HUGEPD_SHIFT_MASK     0x3f
+
 #ifndef __ASSEMBLY__
 
 #undef STRICT_MM_TYPECHECKS
@@ -243,7 +273,6 @@ typedef unsigned long pgprot_t;
 #endif
 
 typedef struct { signed long pd; } hugepd_t;
-#define HUGEPD_SHIFT_MASK     0x3f
 
 #ifdef CONFIG_HUGETLB_PAGE
 static inline int hugepd_ok(hugepd_t hpd)
arch/powerpc/include/asm/page_64.h +0 -11
index 9356262..fb40ede 100644
@@ -64,17 +64,6 @@ extern void copy_page(void *to, void *from);
 /* Log 2 of page table size */
 extern u64 ppc64_pft_size;
 
-/* Large pages size */
-#ifdef CONFIG_HUGETLB_PAGE
-extern unsigned int HPAGE_SHIFT;
-#else
-#define HPAGE_SHIFT PAGE_SHIFT
-#endif
-#define HPAGE_SIZE		((1UL) << HPAGE_SHIFT)
-#define HPAGE_MASK		(~(HPAGE_SIZE - 1))
-#define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
-#define HUGE_MAX_HSTATE		(MMU_PAGE_COUNT-1)
-
 #endif /* __ASSEMBLY__ */
 
 #ifdef CONFIG_PPC_MM_SLICES
arch/powerpc/include/asm/pte-book3e.h +3 -0
index 082d515..0156702 100644
@@ -72,6 +72,9 @@
 #define	PTE_RPN_SHIFT	(24)
 #endif
 
+#define PTE_WIMGE_SHIFT (19)
+#define PTE_BAP_SHIFT	(2)
+
 /* On 32-bit, we never clear the top part of the PTE */
 #ifdef CONFIG_PPC32
 #define _PTE_NONE_MASK	0xffffffff00000000ULL
arch/powerpc/kernel/head_fsl_booke.S +114 -19

206 lines not on this page · raw message

arch/powerpc/mm/Makefile +1 -0
index bdca46e..991ee81 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_PPC_MM_SLICES)	+= slice.o
 ifeq ($(CONFIG_HUGETLB_PAGE),y)
 obj-y				+= hugetlbpage.o
 obj-$(CONFIG_PPC_STD_MMU_64)	+= hugetlbpage-hash64.o
+obj-$(CONFIG_PPC_BOOK3E_MMU)	+= hugetlbpage-book3e.o
 endif
 obj-$(CONFIG_PPC_SUBPAGE_PROT)	+= subpage-prot.o
 obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
arch/powerpc/mm/hash_utils_64.c +0 -3
index 26b2872..1f8b2a0 100644
@@ -105,9 +105,6 @@ int mmu_kernel_ssize = MMU_SEGSIZE_256M;
 int mmu_highuser_ssize = MMU_SEGSIZE_256M;
 u16 mmu_slb_size = 64;
 EXPORT_SYMBOL_GPL(mmu_slb_size);
-#ifdef CONFIG_HUGETLB_PAGE
-unsigned int HPAGE_SHIFT;
-#endif
 #ifdef CONFIG_PPC_64K_PAGES
 int mmu_ci_restrictions;
 #endif
arch/powerpc/mm/hugetlbpage-book3e.c new file +121 -0

121 lines not on this page · raw message

arch/powerpc/mm/hugetlbpage.c +337 -42

522 lines not on this page · raw message

arch/powerpc/mm/init_32.c +9 -0
index d65b591..3e1ba4c 100644
@@ -32,6 +32,8 @@
 #include <linux/pagemap.h>
 #include <linux/memblock.h>
 #include <linux/gfp.h>
+#include <linux/slab.h>
+#include <linux/hugetlb.h>
 
 #include <asm/pgalloc.h>
 #include <asm/prom.h>
@@ -44,6 +46,7 @@
 #include <asm/tlb.h>
 #include <asm/sections.h>
 #include <asm/system.h>
+#include <asm/hugetlb.h>
 
 #include "mmu_decl.h"
 
@@ -123,6 +126,12 @@ void __init MMU_init(void)
 	/* parse args from command line */
 	MMU_setup();
 
+	/*
+	 * Reserve gigantic pages for hugetlb.  This MUST occur before
+	 * lowmem_end_addr is initialized below.
+	 */
+	reserve_hugetlb_gpages();
+
 	if (memblock.memory.cnt > 1) {
 #ifndef CONFIG_WII
 		memblock.memory.cnt = 1;
arch/powerpc/mm/mem.c +5 -0
index 7209901..9e6f3a6 100644
@@ -510,4 +510,9 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
 		return;
 	hash_preload(vma->vm_mm, address, access, trap);
 #endif /* CONFIG_PPC_STD_MMU */
+#if (defined(CONFIG_PPC_BOOK3E_64) || defined(CONFIG_PPC_FSL_BOOK3E)) \
+	&& defined(CONFIG_HUGETLB_PAGE)
+	if (is_vm_hugetlb_page(vma))
+		book3e_hugetlb_preload(vma->vm_mm, address, *ptep);
+#endif
 }
arch/powerpc/mm/mmu_context_nohash.c +5 -0
index 336807d..5b63bd3 100644
@@ -292,6 +292,11 @@ int init_new_context(struct task_struct *t, struct mm_struct *mm)
 	mm->context.id = MMU_NO_CONTEXT;
 	mm->context.active = 0;
 
+#ifdef CONFIG_PPC_MM_SLICES
+	if (slice_mm_new_context(mm))
+		slice_set_user_psize(mm, mmu_virtual_psize);
+#endif
+
 	return 0;
 }
 
arch/powerpc/mm/pgtable.c +2 -1
index af40c87..214130a 100644
@@ -27,6 +27,7 @@
 #include <linux/init.h>
 #include <linux/percpu.h>
 #include <linux/hardirq.h>
+#include <linux/hugetlb.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
 #include <asm/tlb.h>
@@ -212,7 +213,7 @@ int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
 	entry = set_access_flags_filter(entry, vma, dirty);
 	changed = !pte_same(*(ptep), entry);
 	if (changed) {
-		if (!(vma->vm_flags & VM_HUGETLB))
+		if (!is_vm_hugetlb_page(vma))
 			assert_pte_locked(vma->vm_mm, address);
 		__ptep_set_access_flags(ptep, entry);
 		flush_tlb_page_nohash(vma, address);
arch/powerpc/mm/tlb_low_64e.S +12 -12
index af08922..12ae424 100644
@@ -347,24 +347,24 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_TLBRSRV)
 	rldicl	r11,r16,64-VPTE_PGD_SHIFT,64-PGD_INDEX_SIZE-3
 	clrrdi	r10,r11,3
 	ldx	r15,r10,r15
-	cmpldi	cr0,r15,0
-	beq	virt_page_table_tlb_miss_fault
+	cmpdi	cr0,r15,0
+	bge	virt_page_table_tlb_miss_fault
 
 #ifndef CONFIG_PPC_64K_PAGES
 	/* Get to PUD entry */
 	rldicl	r11,r16,64-VPTE_PUD_SHIFT,64-PUD_INDEX_SIZE-3
 	clrrdi	r10,r11,3
 	ldx	r15,r10,r15
-	cmpldi	cr0,r15,0
-	beq	virt_page_table_tlb_miss_fault
+	cmpdi	cr0,r15,0
+	bge	virt_page_table_tlb_miss_fault
 #endif /* CONFIG_PPC_64K_PAGES */
 
 	/* Get to PMD entry */
 	rldicl	r11,r16,64-VPTE_PMD_SHIFT,64-PMD_INDEX_SIZE-3
 	clrrdi	r10,r11,3
 	ldx	r15,r10,r15
-	cmpldi	cr0,r15,0
-	beq	virt_page_table_tlb_miss_fault
+	cmpdi	cr0,r15,0
+	bge	virt_page_table_tlb_miss_fault
 
 	/* Ok, we're all right, we can now create a kernel translation for
 	 * a 4K or 64K page from r16 -> r15.
@@ -596,24 +596,24 @@ htw_tlb_miss:
 	rldicl	r11,r16,64-(PGDIR_SHIFT-3),64-PGD_INDEX_SIZE-3
 	clrrdi	r10,r11,3
 	ldx	r15,r10,r15
-	cmpldi	cr0,r15,0
-	beq	htw_tlb_miss_fault
+	cmpdi	cr0,r15,0
+	bge	htw_tlb_miss_fault
 
 #ifndef CONFIG_PPC_64K_PAGES
 	/* Get to PUD entry */
 	rldicl	r11,r16,64-(PUD_SHIFT-3),64-PUD_INDEX_SIZE-3
 	clrrdi	r10,r11,3
 	ldx	r15,r10,r15
-	cmpldi	cr0,r15,0
-	beq	htw_tlb_miss_fault
+	cmpdi	cr0,r15,0
+	bge	htw_tlb_miss_fault
 #endif /* CONFIG_PPC_64K_PAGES */
 
 	/* Get to PMD entry */
 	rldicl	r11,r16,64-(PMD_SHIFT-3),64-PMD_INDEX_SIZE-3
 	clrrdi	r10,r11,3
 	ldx	r15,r10,r15
-	cmpldi	cr0,r15,0
-	beq	htw_tlb_miss_fault
+	cmpdi	cr0,r15,0
+	bge	htw_tlb_miss_fault
 
 	/* Ok, we're all right, we can now create an indirect entry for
 	 * a 1M or 256M page.
arch/powerpc/mm/tlb_nohash.c +44 -2

77 lines not on this page · raw message

arch/powerpc/platforms/Kconfig.cputype +3 -1
index 2165b65..9abc655 100644
@@ -69,6 +69,7 @@ choice
 config PPC_BOOK3S_64
 	bool "Server processors"
 	select PPC_FPU
+	select SYS_SUPPORTS_HUGETLBFS
 
 config PPC_BOOK3E_64
 	bool "Embedded processors"
@@ -173,6 +174,7 @@ config BOOKE
 config FSL_BOOKE
 	bool
 	depends on (E200 || E500) && PPC32
+	select SYS_SUPPORTS_HUGETLBFS if PHYS_64BIT
 	default y
 
 # this is for common code between PPC32 & PPC64 FSL BOOKE
@@ -296,7 +298,7 @@ config PPC_BOOK3E_MMU
 
 config PPC_MM_SLICES
 	bool
-	default y if HUGETLB_PAGE || (PPC_STD_MMU_64 && PPC_64K_PAGES)
+	default y if (PPC64 && HUGETLB_PAGE) || (PPC_STD_MMU_64 && PPC_64K_PAGES)
 	default n
 
 config VIRT_CPU_ACCOUNTING
Signature · 1 line
1.5.6.5
Applied
#6 lore raw

Re: [PATCH 4/5] powerpc: Create next_tlbcam_idx percpu variable for FSL_BOOKE

In reply to Becky Bruce
Quoted 11 lines · Becky Bruce

From: Becky Bruce <[email protected]>

This is used to round-robin TLBCAM entries.

---

arch/powerpc/include/asm/mmu.h |    5 +++++
arch/powerpc/kernel/smp.c      |    4 ++++
arch/powerpc/mm/mem.c          |    9 +++++++++
arch/powerpc/mm/tlb_nohash.c   |    6 ++++++
4 files changed, 24 insertions(+), 0 deletions(-)

applied to next

- k

#7 lore raw

Re: [PATCH 2/5] hugetlb: add phys addr to struct huge_bootmem_page

In reply to Becky Bruce
Quoted 11 lines · Becky Bruce

struct page *alloc_huge_page_node(struct hstate *h, int nid);

mm/hugetlb.c +0 -1
index 6402458..2db81ea 100644
@@ -1105,8 +1105,14 @@ static void __init
 gather_bootmem_prealloc(void)
        struct huge_bootmem_page *m;
 
        list_for_each_entry(m, &huge_boot_pages, list) {
-               struct page *page = virt_to_page(m);

mm/hugetlb.c static void __init · line 1118

Quoted 10 lines
mm/hugetlb.c +7 -0
                struct hstate *h = m->hstate;
+#ifdef CONFIG_HIGHMEM
+               struct page *page = pfn_to_page(m->phys >>
 PAGE_SHIFT);
+               free_bootmem_late((unsigned long)m,
+                                 sizeof(struct huge_bootmem_page));
+#else
+               struct page *page = virt_to_page(m);
+#endif
                __ClearPageReserved(page);

Why do you add free_bootmem_late() in the highmem case and not the normal case ?

Cheers,
Ben.

#8 lore raw

Re: [PATCH 2/5] hugetlb: add phys addr to struct huge_bootmem_page

Quoted 17 lines · Benjamin Herrenschmidt
Quoted 16 lines · Becky Bruce

struct page *alloc_huge_page_node(struct hstate *h, int nid);

mm/hugetlb.c +0 -0
index 6402458..2db81ea 100644
@@ -1105,8 +1105,14 @@ static void __init
 gather_bootmem_prealloc(void)
       struct huge_bootmem_page *m;

=20

       list_for_each_entry(m, &huge_boot_pages, list) {
mm/hugetlb.c +2 -1
-               struct page *page =3D virt_to_page(m);
               struct hstate *h =3D m->hstate;
+#ifdef CONFIG_HIGHMEM
+               struct page *page =3D pfn_to_page(m->phys >>

PAGE_SHIFT);
+ free_bootmem_late((unsigned long)m,

Quoted 8 lines

mm/hugetlb.c static void __init gather_bootmem_prealloc(void) · line 1116

Quoted 5 lines
mm/hugetlb.c +4 -0
+                                 sizeof(struct huge_bootmem_page));
+#else
+               struct page *page =3D virt_to_page(m);
+#endif
               __ClearPageReserved(page);

=20
Why do you add free_bootmem_late() in the highmem case and not the normal case ?

Because there was no bootmem allocation in the normal case - the = non-highmem version stores data structure in the huge page itself. This = is perfectly fine as long as you have a mapping. Since this isn't true = for HIGHMEM pages, I allocate bootmem to store the early data structure = that stores information about the hugepage (this happens in = arch-specific code in alloc_bootmem_huge_page).

-Becky

#9 lore raw

Re: [PATCH 2/5] hugetlb: add phys addr to struct huge_bootmem_page

On Thu, Jun 30, 2011 at 1:50 PM, Becky Bruce <[email protected]> w= rote:

Quoted 1 line

Because there was no bootmem allocation in the normal case - the non-high=

mem

Quoted 1 line

version stores data structure in the huge page itself. =A0This is perfect=

ly fine as long

Quoted 1 line

as you have a mapping. =A0Since this isn't true for HIGHMEM pages, I allo=

cate

Quoted 1 line

bootmem to store the early data structure that stores information about t=

he

Quoted 1 line

hugepage (this happens in arch-specific code in alloc_bootmem_huge_page).

I would put this text in a comment in the code.

--=20
Timur Tabi
Linux kernel developer at Freescale=

maintainer
#10 lore raw

Re: [PATCH 2/5] hugetlb: add phys addr to struct huge_bootmem_page

In reply to Becky Bruce
Quoted 35 lines · On Tue, 28 Jun 2011 14:54:45 -0500 Becky Bruce <[email protected]>…

From: Becky Bruce <[email protected]>

This is needed on HIGHMEM systems - we don't always have a virtual address so store the physical address and map it in as needed.

---
 include/linux/hugetlb.h |    3 +++
 mm/hugetlb.c            |    8 +++++++-
 2 files changed, 10 insertions(+), 1 deletions(-)
include/linux/hugetlb.h +3 -0
index 59225ef..19644e0 100644
@@ -231,6 +231,9 @@ struct hstate {
 struct huge_bootmem_page {
 	struct list_head list;
 	struct hstate *hstate;
+#ifdef CONFIG_HIGHMEM
+	phys_addr_t phys;
+#endif
 };
 
 struct page *alloc_huge_page_node(struct hstate *h, int nid);
mm/hugetlb.c +0 -1
index 6402458..2db81ea 100644
@@ -1105,8 +1105,14 @@ static void __init gather_bootmem_prealloc(void)
 	struct huge_bootmem_page *m;
 
 	list_for_each_entry(m, &huge_boot_pages, list) {
-		struct page *page = virt_to_page(m);
 		struct hstate *h = m->hstate;

mm/hugetlb.c static void __init gather_bootmem_prealloc(void) · line 1118

Quoted 10 lines
mm/hugetlb.c +7 -0
+#ifdef CONFIG_HIGHMEM
+		struct page *page = pfn_to_page(m->phys >> PAGE_SHIFT);
+		free_bootmem_late((unsigned long)m,
+				  sizeof(struct huge_bootmem_page));
+#else
+		struct page *page = virt_to_page(m);
+#endif
 		__ClearPageReserved(page);
 		WARN_ON(page_count(page) != 1);
 		prep_compound_huge_page(page, h->order);

nit: wrapping both definitions and statements in an ifdef like this is a bit nasty from a readability and maintainability point of view - it's inviting people to later make changes which fail to compile when the config option is flipped.

This is better:

mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-add-phys-addr-to-struct-huge_bootmem_page-fix +4 -2
@@ -1106,12 +1106,14 @@ static void __init gather_bootmem_preall
 
 	list_for_each_entry(m, &huge_boot_pages, list) {
 		struct hstate *h = m->hstate;
+		struct page *page;
+
 #ifdef CONFIG_HIGHMEM
-		struct page *page = pfn_to_page(m->phys >> PAGE_SHIFT);
+		page = pfn_to_page(m->phys >> PAGE_SHIFT);
 		free_bootmem_late((unsigned long)m,
 				  sizeof(struct huge_bootmem_page));
 #else
-		struct page *page = virt_to_page(m);
+		page = virt_to_page(m);
 #endif
 		__ClearPageReserved(page);
 		WARN_ON(page_count(page) != 1);

_

#11 lore raw

Re: [PATCH 2/5] hugetlb: add phys addr to struct huge_bootmem_page

Quoted 25 lines · Andrew Morton

On Tue, 28 Jun 2011 14:54:45 -0500
Becky Bruce <[email protected]> wrote:
=20

Quoted 22 lines

From: Becky Bruce <[email protected]>
=20
This is needed on HIGHMEM systems - we don't always have a virtual address so store the physical address and map it in as needed. =20

---

include/linux/hugetlb.h |    3 +++
mm/hugetlb.c            |    8 +++++++-
2 files changed, 10 insertions(+), 1 deletions(-)

=20

include/linux/hugetlb.h +3 -0
index 59225ef..19644e0 100644
@@ -231,6 +231,9 @@ struct hstate {
 struct huge_bootmem_page {
 	struct list_head list;
 	struct hstate *hstate;
+#ifdef CONFIG_HIGHMEM
+	phys_addr_t phys;
+#endif
Quoted 8 lines

mm/hugetlb.c static void __init =

Quoted 8 lines
include/linux/hugetlb.h +0 -0
 };

=20
struct page *alloc_huge_page_node(struct hstate *h, int nid);

mm/hugetlb.c +0 -0
index 6402458..2db81ea 100644
@@ -1105,8 +1105,14 @@ static void __init =

gather_bootmem_prealloc(void)

Quoted 7 lines

mm/hugetlb.c

Quoted 7 lines
mm/hugetlb.c +0 -0
 	struct huge_bootmem_page *m;

=20

	list_for_each_entry(m, &huge_boot_pages, list) {
mm/hugetlb.c +0 -1
-		struct page *page =3D virt_to_page(m);
		struct hstate *h =3D m->hstate;
mm/hugetlb.c +2 -0
+#ifdef CONFIG_HIGHMEM
+		struct page *page =3D pfn_to_page(m->phys >> =

PAGE_SHIFT);

Quoted 11 lines
Quoted 8 lines
mm/hugetlb.c +5 -0
+		free_bootmem_late((unsigned long)m,
+				  sizeof(struct huge_bootmem_page));
+#else
+		struct page *page =3D virt_to_page(m);
+#endif
		__ClearPageReserved(page);
		WARN_ON(page_count(page) !=3D 1);
		prep_compound_huge_page(page, h->order);

=20
nit: wrapping both definitions and statements in an ifdef like this is a bit nasty from a readability and maintainability point of view - =

it's

Quoted 6 lines

inviting people to later make changes which fail to compile when the config option is flipped.
=20
This is better:
=20
--- =

a/mm/hugetlb.c~hugetlb-add-phys-addr-to-struct-huge_bootmem_page-fix

Review

Quoted 9 lines

+++ a/mm/hugetlb.c

(quoted diff) +0 -0
@@ -1106,12 +1106,14 @@ static void __init gather_bootmem_preall

=20

	list_for_each_entry(m, &huge_boot_pages, list) {
		struct hstate *h =3D m->hstate;
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-add-phys-addr-to-struct-huge_bootmem_page-fix +2 -0
+		struct page *page;
+

#ifdef CONFIG_HIGHMEM

(quoted diff) +0 -1
-		struct page *page =3D pfn_to_page(m->phys >> =

PAGE_SHIFT);

Quoted 9 lines
(quoted diff) +1 -0
+		page =3D pfn_to_page(m->phys >> PAGE_SHIFT);
		free_bootmem_late((unsigned long)m,
				  sizeof(struct huge_bootmem_page));

#else

(quoted diff) +1 -1
-		struct page *page =3D virt_to_page(m);
+		page =3D virt_to_page(m);
#endif
		__ClearPageReserved(page);
		WARN_ON(page_count(page) !=3D 1);

Andrew,

I totally agree, this is better, thanks. I see you've put my original =
patch and your fix into -mm; I'd like it to percolate there for a bit = before it goes to Linus to be sure I haven't broken anything. It should = be safe, as I don't think this particular function was ever expected to = work on highmem platforms, but it's possible I'm overlooking something.

Cheers,
-Becky

#12 lore raw

Re: [PATCH 1/5] fs/hugetlbfs/inode.c: Fix pgoff alignment checking on 32-bit

In reply to Becky Bruce

Andrew, Anybody ? Can I have an -mm ack for this ?

Cheers,
Ben.

Quoted 21 lines · Becky Bruce

From: Becky Bruce <[email protected]>

This:

vma->vm_pgoff & ~(huge_page_mask(h) >> PAGE_SHIFT)

is incorrect on 32-bit. It causes us to & the pgoff with something that looks like this (for a 4m hugepage): 0xfff003ff. The mask should be flipped and *then* shifted, to give you 0x0000_03fff.

---
 fs/hugetlbfs/inode.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/hugetlbfs/inode.c +0 -0
index 7aafeb8..537a209 100644

fs/hugetlbfs/inode.c static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) · line 100

Quoted 8 lines
fs/hugetlbfs/inode.c +1 -1
@@ -94,7 +94,7 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
 	vma->vm_flags |= VM_HUGETLB | VM_RESERVED;
 	vma->vm_ops = &hugetlb_vm_ops;
 
-	if (vma->vm_pgoff & ~(huge_page_mask(h) >> PAGE_SHIFT))
+	if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT))
 		return -EINVAL;
 
 	vma_len = (loff_t)(vma->vm_end - vma->vm_start);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>