Skip to contentSkip to conversation

Add support for 4PB virtual address space on hash

PATCH Superseded Aneesh Kumar K.V 2 participants 6 messages Mar 7, 2018 – Mar 18, 2018 PowerPC

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add support for 4PB virtual address space on hash

This patch series extended the max virtual address space value from 512TB to 4PB with 64K page size. We do that by allocating one vsid context for each 512TB range. More details of that is explained in patch 3.

Changes from V3:
* move extended_id to be a union with mm_context_t id. This reduce some array index complexity.
* Add addr_limit check when handling slb miss for extended context

Changes from V2:
* Rebased on top of slice_mask series from Nick Piggin
* Fixed segfault when mmap with 512TB hint address

Aneesh Kumar K.V (3):
powerpc/mm: Add support for handling > 512TB address in SLB miss powerpc/mm/hash64: Increase the VA range powerpc/mm/hash: Don't memset pgd table if not needed

 arch/powerpc/include/asm/book3s/64/hash-4k.h  |   6 +
 arch/powerpc/include/asm/book3s/64/hash-64k.h |   7 +-
 arch/powerpc/include/asm/book3s/64/mmu-hash.h |   6 +-
 arch/powerpc/include/asm/book3s/64/mmu.h      |  26 ++++-
 arch/powerpc/include/asm/book3s/64/pgalloc.h  |  13 ++-
 arch/powerpc/include/asm/processor.h          |  16 ++-
 arch/powerpc/kernel/exceptions-64s.S          |  12 +-
 arch/powerpc/mm/copro_fault.c                 |   2 +-
 arch/powerpc/mm/hash_utils_64.c               |   4 +-
 arch/powerpc/mm/init_64.c                     |   6 -
 arch/powerpc/mm/mmu_context_book3s64.c        |  15 ++-
 arch/powerpc/mm/pgtable-hash64.c              |   2 +-
 arch/powerpc/mm/pgtable_64.c                  |   5 -
 arch/powerpc/mm/slb.c                         | 154 ++++++++++++++++++++++++++
 arch/powerpc/mm/slb_low.S                     |   6 +-
 arch/powerpc/mm/tlb_hash64.c                  |   2 +-
 16 files changed, 252 insertions(+), 30 deletions(-)
Signature · 1 line
2.14.3
#1 lore raw

PATCH v4 1/3 powerpc/mm: Add support for handling > 512TB address in SLB miss

For address above 512TB we allocate additional mmu context. To make it all easy address above 512TB is handled with IR/DR=1 and with stack frame setup.

We do the additional context allocation in SLB miss handler. If the context is not allocated, we enable interrupts and allocate the context and retry the access which will again result in a SLB miss.

---
 arch/powerpc/include/asm/book3s/64/hash-4k.h  |   6 +
 arch/powerpc/include/asm/book3s/64/hash-64k.h |   5 +
 arch/powerpc/include/asm/book3s/64/mmu-hash.h |   6 +-
 arch/powerpc/include/asm/book3s/64/mmu.h      |  26 ++++-
 arch/powerpc/include/asm/processor.h          |   7 ++
 arch/powerpc/kernel/exceptions-64s.S          |  12 +-
 arch/powerpc/mm/copro_fault.c                 |   2 +-
 arch/powerpc/mm/hash_utils_64.c               |   4 +-
 arch/powerpc/mm/mmu_context_book3s64.c        |  15 ++-
 arch/powerpc/mm/pgtable-hash64.c              |   2 +-
 arch/powerpc/mm/slb.c                         | 154 ++++++++++++++++++++++++++
 arch/powerpc/mm/slb_low.S                     |   6 +-
 arch/powerpc/mm/tlb_hash64.c                  |   2 +-
 13 files changed, 231 insertions(+), 16 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-4k.h +6 -0
index 67c5475311ee..af2ba9875f18 100644
@@ -11,6 +11,12 @@
 #define H_PUD_INDEX_SIZE  9
 #define H_PGD_INDEX_SIZE  9
 
+/*
+ * No of address bits below which we use the default context
+ * for slb allocation. For 4k this is 64TB.
+ */
+#define H_BITS_FIRST_CONTEXT	46
+
 #ifndef __ASSEMBLY__
 #define H_PTE_TABLE_SIZE	(sizeof(pte_t) << H_PTE_INDEX_SIZE)
 #define H_PMD_TABLE_SIZE	(sizeof(pmd_t) << H_PMD_INDEX_SIZE)
arch/powerpc/include/asm/book3s/64/hash-64k.h +5 -0
index 3bcf269f8f55..0ee0fc1ad675 100644
@@ -6,6 +6,11 @@
 #define H_PMD_INDEX_SIZE  10
 #define H_PUD_INDEX_SIZE  7
 #define H_PGD_INDEX_SIZE  8
+/*
+ * No of address bits below which we use the default context
+ * for slb allocation. For 64k this is 512TB.
+ */
+#define H_BITS_FIRST_CONTEXT	49
 
 /*
  * 64k aligned address free up few of the lower bits of RPN for us
arch/powerpc/include/asm/book3s/64/mmu-hash.h +3 -3
index 50ed64fba4ae..8ee83f6e9c84 100644
@@ -691,8 +691,8 @@ static inline int user_segment_size(unsigned long addr)
 	return MMU_SEGSIZE_256M;
 }
 
-static inline unsigned long get_vsid(unsigned long context, unsigned long ea,
-				     int ssize)
+static inline unsigned long __get_vsid(unsigned long context, unsigned long ea,
+				       int ssize)
 {
 	unsigned long va_bits = VA_BITS;
 	unsigned long vsid_bits;
@@ -744,7 +744,7 @@ static inline unsigned long get_kernel_vsid(unsigned long ea, int ssize)
 	 */
 	context = (ea >> 60) - KERNEL_REGION_CONTEXT_OFFSET;
 
-	return get_vsid(context, ea, ssize);
+	return __get_vsid(context, ea, ssize);
 }
 
 unsigned htab_shift_for_mem_size(unsigned long mem_size);
arch/powerpc/include/asm/book3s/64/mmu.h +25 -1
index 777778579305..a70adbb7ec56 100644
@@ -91,7 +91,15 @@ struct slice_mask {
 };
 
 typedef struct {
-	mm_context_id_t id;
+	union {
+		/*
+		 * One context for each 512TB.
+		 * First 512TB context is saved in id and is also used
+		 * as PIDR.
+		 */
+		mm_context_id_t id;
+		mm_context_id_t extended_id[TASK_SIZE_USER64/TASK_CONTEXT_SIZE];
+	};
 	u16 user_psize;		/* page size index */
 
 	/* Number of bits in the mm_cpumask */
@@ -193,5 +201,21 @@ extern void radix_init_pseries(void);
 static inline void radix_init_pseries(void) { };
 #endif
 
+static inline int get_esid_context(mm_context_t *ctx, unsigned long ea)
+{
+	int index = ea >> H_BITS_FIRST_CONTEXT;
+
+	return ctx->extended_id[index];
+}
+
+static inline unsigned long get_user_vsid(mm_context_t *ctx,
+					  unsigned long ea, int ssize)
+{
+	unsigned long context = get_esid_context(ctx, ea);
+
+	return __get_vsid(context, ea, ssize);
+}
+
+
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_POWERPC_BOOK3S_64_MMU_H_ */
arch/powerpc/include/asm/processor.h +7 -0
index 01299cdc9806..70d65b482504 100644
@@ -119,9 +119,16 @@ void release_thread(struct task_struct *);
  */
 #define TASK_SIZE_USER64		TASK_SIZE_512TB
 #define DEFAULT_MAP_WINDOW_USER64	TASK_SIZE_128TB
+#define TASK_CONTEXT_SIZE		TASK_SIZE_512TB
 #else
 #define TASK_SIZE_USER64		TASK_SIZE_64TB
 #define DEFAULT_MAP_WINDOW_USER64	TASK_SIZE_64TB
+/*
+ * We don't need allocate extended context id for 4K
+ * page size. We limit max address on this config to
+ * 64TB.
+ */
+#define TASK_CONTEXT_SIZE		TASK_SIZE_64TB
 #endif
 
 /*
arch/powerpc/kernel/exceptions-64s.S +8 -4
index 3ac87e53b3da..166b8c0f1830 100644
@@ -620,8 +620,12 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
 	ld	r10,PACA_EXSLB+EX_LR(r13)
 	lwz	r9,PACA_EXSLB+EX_CCR(r13)	/* get saved CR */
 	mtlr	r10
+	/*
+	 * Large address, check whether we have to allocate new
+	 * contexts.
+	 */
+	beq-	8f
 
-	beq-	8f		/* if bad address, make full stack frame */
 
 	bne-	cr5,2f		/* if unrecoverable exception, oops */
 
@@ -685,7 +689,7 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
 	mr	r3,r12
 	mfspr	r11,SPRN_SRR0
 	mfspr	r12,SPRN_SRR1
-	LOAD_HANDLER(r10,bad_addr_slb)
+	LOAD_HANDLER(r10, multi_context_slb)
 	mtspr	SPRN_SRR0,r10
 	ld	r10,PACAKMSR(r13)
 	mtspr	SPRN_SRR1,r10
@@ -700,7 +704,7 @@ EXC_COMMON_BEGIN(unrecov_slb)
 	bl	unrecoverable_exception
 	b	1b
 
-EXC_COMMON_BEGIN(bad_addr_slb)
+EXC_COMMON_BEGIN(multi_context_slb)
 	EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
 	RECONCILE_IRQ_STATE(r10, r11)
 	ld	r3, PACA_EXSLB+EX_DAR(r13)
@@ -710,7 +714,7 @@ EXC_COMMON_BEGIN(bad_addr_slb)
 	std	r10, _TRAP(r1)
 2:	bl	save_nvgprs
 	addi	r3, r1, STACK_FRAME_OVERHEAD
-	bl	slb_miss_bad_addr
+	bl	handle_multi_context_slb_miss
 	b	ret_from_except
 
 EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
arch/powerpc/mm/copro_fault.c +1 -1
index 697b70ad1195..7d0945bd3a61 100644
@@ -112,7 +112,7 @@ int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)
 			return 1;
 		psize = get_slice_psize(mm, ea);
 		ssize = user_segment_size(ea);
-		vsid = get_vsid(mm->context.id, ea, ssize);
+		vsid = get_user_vsid(&mm->context, ea, ssize);
 		vsidkey = SLB_VSID_USER;
 		break;
 	case VMALLOC_REGION_ID:
arch/powerpc/mm/hash_utils_64.c +2 -2
index b578148d89e6..f62325d4f5f5 100644
@@ -1261,7 +1261,7 @@ int hash_page_mm(struct mm_struct *mm, unsigned long ea,
 		}
 		psize = get_slice_psize(mm, ea);
 		ssize = user_segment_size(ea);
-		vsid = get_vsid(mm->context.id, ea, ssize);
+		vsid = get_user_vsid(&mm->context, ea, ssize);
 		break;
 	case VMALLOC_REGION_ID:
 		vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
@@ -1526,7 +1526,7 @@ void hash_preload(struct mm_struct *mm, unsigned long ea,
 
 	/* Get VSID */
 	ssize = user_segment_size(ea);
-	vsid = get_vsid(mm->context.id, ea, ssize);
+	vsid = get_user_vsid(&mm->context, ea, ssize);
 	if (!vsid)
 		return;
 	/*
arch/powerpc/mm/mmu_context_book3s64.c +14 -1
index 80acad52b006..ccc88fa7c35c 100644
@@ -178,6 +178,19 @@ void __destroy_context(int context_id)
 }
 EXPORT_SYMBOL_GPL(__destroy_context);
 
+static void destroy_contexts(mm_context_t *ctx)
+{
+	int index, context_id;
+
+	spin_lock(&mmu_context_lock);
+	for (index = 0; index < (TASK_SIZE_USER64/TASK_CONTEXT_SIZE); index++) {
+		context_id = ctx->extended_id[index];
+		if (context_id)
+			ida_remove(&mmu_context_ida, context_id);
+	}
+	spin_unlock(&mmu_context_lock);
+}
+
 #ifdef CONFIG_PPC_64K_PAGES
 static void destroy_pagetable_page(struct mm_struct *mm)
 {
@@ -216,7 +229,7 @@ void destroy_context(struct mm_struct *mm)
 	else
 		subpage_prot_free(mm);
 	destroy_pagetable_page(mm);
-	__destroy_context(mm->context.id);
+	destroy_contexts(&mm->context);
 	mm->context.id = MMU_NO_CONTEXT;
 }
 
arch/powerpc/mm/pgtable-hash64.c +1 -1
index 469808e77e58..a87b18cf6749 100644
@@ -320,7 +320,7 @@ void hpte_do_hugepage_flush(struct mm_struct *mm, unsigned long addr,
 
 	if (!is_kernel_addr(addr)) {
 		ssize = user_segment_size(addr);
-		vsid = get_vsid(mm->context.id, addr, ssize);
+		vsid = get_user_vsid(&mm->context, addr, ssize);
 		WARN_ON(vsid == 0);
 	} else {
 		vsid = get_kernel_vsid(addr, mmu_kernel_ssize);
arch/powerpc/mm/slb.c +154 -0

163 lines not on this page · raw message

arch/powerpc/mm/slb_low.S +4 -2
index 2c7c717fd2ea..c66cb06e73a1 100644
@@ -75,10 +75,12 @@ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA)
  */
 _GLOBAL(slb_allocate)
 	/*
-	 * check for bad kernel/user address
+	 * Check for address range for which we need to handle multi context. For
+         * the default context we allocate the slb via the fast path. For large
+         * address we branch out to C-code and look at additional context allocated.
 	 * (ea & ~REGION_MASK) >= PGTABLE_RANGE
 	 */
-	rldicr. r9,r3,4,(63 - H_PGTABLE_EADDR_SIZE - 4)
+	rldicr. r9,r3,4,(63 - H_BITS_FIRST_CONTEXT - 4)
 	bne-	8f
 
 	srdi	r9,r3,60		/* get region */
arch/powerpc/mm/tlb_hash64.c +1 -1
index 9b23f12e863c..87d71dd25441 100644
@@ -89,7 +89,7 @@ void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
 	/* Build full vaddr */
 	if (!is_kernel_addr(addr)) {
 		ssize = user_segment_size(addr);
-		vsid = get_vsid(mm->context.id, addr, ssize);
+		vsid = get_user_vsid(&mm->context, addr, ssize);
 	} else {
 		vsid = get_kernel_vsid(addr, mmu_kernel_ssize);
 		ssize = mmu_kernel_ssize;
Signature · 1 line
2.14.3
#2 lore raw

Re: [PATCH V4 1/3] powerpc/mm: Add support for handling > 512TB address in SLB miss

Hi Aneesh,

Some comments ...

Quoted 2 lines · Aneesh Kumar K.V

For address above 512TB we allocate additional mmu context. To make it all easy address above 512TB is handled with IR/DR=3D1 and with stack frame s=

etup.

Quoted 2 lines

We do the additional context allocation in SLB miss handler. If the conte=

xt is

Quoted 4 lines

not allocated, we enable interrupts and allocate the context and retry the access which will again result in a SLB miss.

This doesn't build for g5_defconfig:

In file included from ../arch/powerpc/include/asm/mmu.h:314:0,

                   from ../arch/powerpc/include/asm/lppaca.h:36,
                   from ../arch/powerpc/include/asm/paca.h:21,
                   from ../arch/powerpc/include/asm/hw_irq.h:63,
                   from ../arch/powerpc/include/asm/irqflags.h:12,
                   from ../include/linux/irqflags.h:16,
                   from ../include/linux/spinlock.h:54,
                   from ../include/linux/mmzone.h:8,
                   from ../arch/powerpc/include/asm/pgtable.h:7,
                   from ../arch/powerpc/mm/slb.c:17:

../arch/powerpc/mm/slb.c: In function =E2=80=98handle_multi_context_slb_m=
iss=E2=80=99:
../arch/powerpc/include/asm/book3s/64/mmu.h:208:25: error: array subscrip=
t is above array bounds [-Werror=3Darray-bounds]

    return ctx->extended_id[index];
           ~~~~~~~~~~~~~~~~^~~~~~~
  ../arch/powerpc/mm/slb.c:417:30: error: array subscript is above array bo=
unds [-Werror=3Darray-bounds]
    if (!mm->context.extended_id[index])
         ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
  ../arch/powerpc/mm/slb.c:418:26: error: array subscript is above array bo=
unds [-Werror=3Darray-bounds]
     mm->context.extended_id[index] =3D context_id;
     ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~

arch/powerpc/=

Quoted 1 line
arch/powerpc/= renamed from arch/powerpc/include/asm/book3s/64/hash-4k.h +0 -0

include/asm/book3s/64/hash-4k.h

Quoted 9 lines

index 67c5475311ee..af2ba9875f18 100644

arch/powerpc/include/asm/book3s/64/hash-4k.h +0 -0
@@ -11,6 +11,12 @@
 #define H_PUD_INDEX_SIZE  9
 #define H_PGD_INDEX_SIZE  9

=20=20
+/*
+ * No of address bits below which we use the default context

Can we use "Number", "No" means no, to mean number you need "No." but that's ugly.

Quoted 3 lines

+ * for slb allocation. For 4k this is 64TB.
+ */
+#define H_BITS_FIRST_CONTEXT 46

It's actually the number of address bits *per* context right?

"Context" is also a bit of a overloaded term, eg. context !=3D mm_context_t, maybe "context id" would be clearer?

So maybe H_BITS_PER_CONTEXT_ID?

This values is essentially VA_BITS - CONTEXT_BITS right?

Except VA_BITS is actually 65 in this case, but that's not clear at all from the code :/

It'd be really nice if this was calculated, or if the other values (VA_BITS/CONTEXT_BITS) were calculated based on it.

arch/powerpc=

Quoted 1 line
arch/powerpc= renamed from arch/powerpc/include/asm/book3s/64/hash-64k.h +0 -0

/include/asm/book3s/64/hash-64k.h

arch/powerpc/include/asm/book3s/64/hash-64k.h line 8

Quoted 7 lines

index 3bcf269f8f55..0ee0fc1ad675 100644

arch/powerpc/include/asm/book3s/64/hash-64k.h +0 -0
@@ -6,6 +6,11 @@
 #define H_PMD_INDEX_SIZE  10
 #define H_PUD_INDEX_SIZE  7
 #define H_PGD_INDEX_SIZE  8

Can we get some newlines between code?

arch/powerpc/include/asm/book3s/64/hash-64k.h line 13

Quoted 5 lines
arch/powerpc/include/asm/book3s/64/hash-64k.h +5 -0
+/*
+ * No of address bits below which we use the default context
+ * for slb allocation. For 64k this is 512TB.
+ */
+#define H_BITS_FIRST_CONTEXT	49

This really is =3D=3D VA_BITS - CONTEXT_BITS.

arch/powerpc=

Quoted 1 line
arch/powerpc= renamed from arch/powerpc/include/asm/book3s/64/mmu-hash.h +0 -0

/include/asm/book3s/64/mmu-hash.h

arch/powerpc/include/asm/book3s/64/mmu-hash.h static inline int user_segment_size(unsigned long add=

Quoted 4 lines

index 50ed64fba4ae..8ee83f6e9c84 100644

arch/powerpc/include/asm/book3s/64/mmu-hash.h +0 -0
@@ -691,8 +691,8 @@ static inline int user_segment_size(unsigned long add=

r)

Quoted 4 lines
arch/powerpc/include/asm/book3s/64/mmu-hash.h +0 -0
 	return MMU_SEGSIZE_256M;
 }

=20=20
-static inline unsigned long get_vsid(unsigned long context, unsigned lon=

g ea,

arch/powerpc/include/asm/book3s/64/mmu-hash.h

Quoted 2 lines
arch/powerpc/include/asm/book3s/64/mmu-hash.h +1 -1
-				     int ssize)
+static inline unsigned long __get_vsid(unsigned long context, unsigned l=

ong ea,

arch/powerpc/include/asm/book3s/64/mmu-hash.h static inline int user_segment_size(unsigned long addr) · line 695

Quoted 1 line
arch/powerpc/include/asm/book3s/64/mmu-hash.h +1 -0
+				       int ssize)

If you're going to realign it the 'i' in int should line up with the 'u' in unsigned.

Why did this become __get_vsid()? We don't have a get_vsid() that I can see?

arch/powerpc/incl=

Quoted 1 line
arch/powerpc/incl= renamed from arch/powerpc/include/asm/book3s/64/mmu.h +0 -0

ude/asm/book3s/64/mmu.h

Quoted 7 lines

index 777778579305..a70adbb7ec56 100644

arch/powerpc/include/asm/book3s/64/mmu.h +0 -0
@@ -91,7 +91,15 @@ struct slice_mask {
 };

=20=20
typedef struct {

arch/powerpc/include/asm/book3s/64/mmu.h struct slice_mask { · line 99

Quoted 7 lines
arch/powerpc/include/asm/book3s/64/mmu.h +6 -1
-	mm_context_id_t id;
+	union {
+		/*
+		 * One context for each 512TB.
+		 * First 512TB context is saved in id and is also used
+		 * as PIDR.
+		 */

Can you make it clearer how this is used on hash vs radix.

arch/powerpc/include/asm/book3s/64/mmu.h struct slice_mask { · line 101

Quoted 2 lines
arch/powerpc/include/asm/book3s/64/mmu.h +2 -0
+		mm_context_id_t id;
+		mm_context_id_t extended_id[TASK_SIZE_USER64/TASK_CONTEXT_SIZE];

If my math is right this is typically 4PB / 512T =3D=3D 8 =3D=3D 64 bytes.

Which is small enough to not worry about, but would be good to mention in the change log at least.

arch/powerpc/include/asm/book3s/64/mmu.h extern void radix_init_pseries(void);

Quoted 11 lines
arch/powerpc/include/asm/book3s/64/mmu.h +1 -0
+	};
 	u16 user_psize;		/* page size index */

=20=20

arch/powerpc/include/asm/book3s/64/mmu.h +0 -0
 	/* Number of bits in the mm_cpumask */
@@ -193,5 +201,21 @@ extern void radix_init_pseries(void);
 static inline void radix_init_pseries(void) { };
 #endif

=20=20

arch/powerpc/include/asm/book3s/64/mmu.h +3 -0
+static inline int get_esid_context(mm_context_t *ctx, unsigned long ea)
+{
+	int index =3D ea >> H_BITS_FIRST_CONTEXT;

Using "esid" in the name is a bit confusing, because the value is an EA, not an ESID. So change the name or what's passed?

I think change the name, the callers both have an EA so it makes sense to pass that.

Quoted 1 line

+

I know we check ea elsewhere, but a:

VM_BUG_ON(index >=3D ARRAY_SIZE(extened_id))

Would make me feel better I think, and index being unsigned.

arch/powerpc/include/=

Quoted 1 line
arch/powerpc/include/= renamed from arch/powerpc/include/asm/processor.h +0 -0

asm/processor.h

Quoted 6 lines

index 01299cdc9806..70d65b482504 100644

arch/powerpc/include/asm/processor.h +0 -0
@@ -119,9 +119,16 @@ void release_thread(struct task_struct *);
  */
 #define TASK_SIZE_USER64		TASK_SIZE_512TB

arch/powerpc/include/asm/processor.h void release_thread(struct task_struct *); · line 130

Quoted 10 lines
arch/powerpc/include/asm/processor.h +6 -0
 #define DEFAULT_MAP_WINDOW_USER64	TASK_SIZE_128TB
+#define TASK_CONTEXT_SIZE		TASK_SIZE_512TB
 #else
 #define TASK_SIZE_USER64		TASK_SIZE_64TB
 #define DEFAULT_MAP_WINDOW_USER64	TASK_SIZE_64TB
+/*
+ * We don't need allocate extended context id for 4K
+ * page size. We limit max address on this config to
+ * 64TB.
+ */

/*
* We don't need to allocate extended context ids for 4K page size, because
* we limit the max effective address on this config to 64TB. */

???

arch/powerpc/kernel/e=

Quoted 1 line
arch/powerpc/kernel/e= renamed from arch/powerpc/kernel/exceptions-64s.S +0 -0

xceptions-64s.S

arch/powerpc/kernel/exceptions-64s.S END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) · line 622

Quoted 7 lines

index 3ac87e53b3da..166b8c0f1830 100644

arch/powerpc/kernel/exceptions-64s.S +0 -0
@@ -620,8 +620,12 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
 	ld	r10,PACA_EXSLB+EX_LR(r13)
 	lwz	r9,PACA_EXSLB+EX_CCR(r13)	/* get saved CR */
 	mtlr	r10

Blank line would be nice.

arch/powerpc/kernel/exceptions-64s.S END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) · line 626

Quoted 4 lines
arch/powerpc/kernel/exceptions-64s.S +4 -0
+	/*
+	 * Large address, check whether we have to allocate new
+	 * contexts.
+	 */

That doesn't need to wrap.

	/* Large address, check whether we need to allocate new contexts. */

arch/powerpc/kernel/exceptions-64s.S END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) · line 624

Quoted 3 lines
arch/powerpc/kernel/exceptions-64s.S +1 -0
+	beq-	8f

=20=20

arch/powerpc/kernel/exceptions-64s.S +0 -1
-	beq-	8f		/* if bad address, make full stack frame */

And we ended up with two blank lines here which is probably overkill. =20

arch/powerpc/kernel/exceptions-64s.S EXC_COMMON_BEGIN(bad_addr_slb) · line 713

Quoted 5 lines
arch/powerpc/kernel/exceptions-64s.S +0 -1
@@ -710,7 +714,7 @@ EXC_COMMON_BEGIN(bad_addr_slb)
 	std	r10, _TRAP(r1)
 2:	bl	save_nvgprs
 	addi	r3, r1, STACK_FRAME_OVERHEAD
-	bl	slb_miss_bad_addr

You removed the only call to this but didn't remove the function or its prototype AFAICS.

arch/powerpc/mm/mmu=

Quoted 1 line
arch/powerpc/mm/mmu= renamed from arch/powerpc/mm/mmu_context_book3s64.c +0 -0

_context_book3s64.c

arch/powerpc/mm/mmu_context_book3s64.c void __destroy_context(int context_id)

Quoted 13 lines

index 80acad52b006..ccc88fa7c35c 100644

arch/powerpc/mm/mmu_context_book3s64.c +0 -0
@@ -178,6 +178,19 @@ void __destroy_context(int context_id)
 }
 EXPORT_SYMBOL_GPL(__destroy_context);

=20=20

arch/powerpc/mm/mmu_context_book3s64.c +6 -0
+static void destroy_contexts(mm_context_t *ctx)
+{
+	int index, context_id;
+
+	spin_lock(&mmu_context_lock);
+	for (index =3D 0; index < (TASK_SIZE_USER64/TASK_CONTEXT_SIZE); index++=

) {

ARRAY_SIZE(ctx->extended_id) ?

arch/powerpc/mm/slb.c line 26

Quoted 9 lines
arch/powerpc/mm/slb.c +1 -0
index 13cfe413b40d..a93887ee9b22 100644
@@ -23,6 +23,7 @@
 #include <asm/smp.h>
 #include <linux/compiler.h>
 #include <linux/mm_types.h>
+#include <linux/context_tracking.h>

Our includes are generally not well sorted, but can you try to keep them alphabetical. So after compiler.h.

arch/powerpc/mm/slb.c void slb_initialize(void) · line 346

Quoted 7 lines
arch/powerpc/mm/slb.c +0 -0
@@ -340,3 +341,156 @@ void slb_initialize(void)

=20=20

arch/powerpc/mm/slb.c +3 -0
 	asm volatile("isync":::"memory");
 }
+
+/*
+ * Only handle insert of 1TB slb entries.

What if we don't have them (enabled) ?

arch/powerpc/mm/slb.c void slb_initialize(void) · line 349

Quoted 3 lines

+ */

arch/powerpc/mm/slb.c +2 -0
+static void insert_slb_entry(unsigned long vsid, unsigned long ea,
+			     int bpsize, int ssize)

Parameter alignment again.

arch/powerpc/mm/slb.c void slb_initialize(void) · line 354

Quoted 5 lines
arch/powerpc/mm/slb.c +5 -0
+{
+	int slb_cache_index;
+	unsigned long flags;
+	enum slb_index index;
+	unsigned long vsid_data, esid_data;

Can you clean those up:

	unsigned long vsid_data, esid_data, flags;
	enum slb_index index;
	int slb_cache_index;

arch/powerpc/mm/slb.c void slb_initialize(void) · line 358

Quoted 4 lines
arch/powerpc/mm/slb.c +4 -0
+
+	/*
+	 * We are irq disabled, hence should be safe
+	 * to access PACA.

Doesn't need to wrap.

arch/powerpc/mm/slb.c

Quoted 2 lines
arch/powerpc/mm/slb.c +2 -0
+	 */
+	index =3D  get_paca()->stab_rr;
                ^

Unneeded extra space there

Blank line please.

arch/powerpc/mm/slb.c

Quoted 2 lines
arch/powerpc/mm/slb.c +2 -0
+	/*
+	 * simple round roubin replacement of slb.

"Simple round-robin"

Although it's not really, it's round-robin but not starting at zero, starting at SLB_NUM_BOLTED.

arch/powerpc/mm/slb.c void slb_initialize(void)

Quoted 5 lines
arch/powerpc/mm/slb.c +5 -0
+	 */
+	if (index < mmu_slb_size)
+		index++;
+	else
+		index =3D SLB_NUM_BOLTED;

Blank line.

arch/powerpc/mm/slb.c

Quoted 5 lines
arch/powerpc/mm/slb.c +5 -0
+	get_paca()->stab_rr =3D index;
+
+	flags =3D SLB_VSID_USER | mmu_psize_defs[bpsize].sllp;
+	vsid_data =3D  (vsid << SLB_VSID_SHIFT_1T) | flags |
+		((unsigned long) ssize << SLB_VSID_SSIZE_SHIFT);
	vsid_data =3D (vsid << SLB_VSID_SHIFT_1T) | flags |
        	    ((unsigned long) ssize << SLB_VSID_SSIZE_SHIFT);

arch/powerpc/mm/slb.c void slb_initialize(void) · line 376

Quoted 4 lines
arch/powerpc/mm/slb.c +4 -0
+	esid_data =3D mk_esid_data(ea, mmu_highuser_ssize, index);
+
+	asm volatile("slbmte %0, %1" : : "r" (vsid_data), "r" (esid_data)
+		     : "memory");

Blank line.

arch/powerpc/mm/slb.c void slb_initialize(void) · line 387

Quoted 11 lines
arch/powerpc/mm/slb.c +11 -0
+	/*
+	 * Now update slb cache entries
+	 */
+	slb_cache_index =3D get_paca()->slb_cache_ptr;
+	if (slb_cache_index < SLB_CACHE_ENTRIES) {
+		/*
+		 * We have space in slb cache for optimized switch_slb().
+		 * Top 36 bits from esid_data as per ISA
+		 */
+		get_paca()->slb_cache[slb_cache_index++] =3D esid_data >> 28;
+	}

Blank line.

arch/powerpc/mm/slb.c void slb_initialize(void)

Quoted 7 lines
arch/powerpc/mm/slb.c +7 -0
+	/*
+	 * if we are full, just increment and return.
+	 */
+	get_paca()->slb_cache_ptr++;
+}
+
+static void alloc_extended_context(struct mm_struct *mm, unsigned long e=

a)

Quoted 41 lines
arch/powerpc/mm/slb.c +38 -0
+{
+	int context_id;
+
+	int index =3D ea >> H_BITS_FIRST_CONTEXT;
+
+	/*
+	 * we need to do locking only here. If this value was not set before
+	 * we will have taken an SLB miss and will reach here. The value will
+	 * be either 0 or a valid extended context. We need to make sure two
+	 * parallel SLB miss don't end up allocating extended_context for the
+	 * same range. The locking below ensures that. For now we take the
+	 * heavy mmap_sem. But can be changed to per mm_context_t custom lock
+	 * if needed.
+	 */
+	down_read(&mm->mmap_sem);
 
+	context_id =3D hash__alloc_context_id();
+	if (context_id < 0) {
+		up_read(&mm->mmap_sem);
+		pagefault_out_of_memory();
+		return;
+	}
 
+	/* Check for parallel allocation after holding lock */
+	if (!mm->context.extended_id[index])
+		mm->context.extended_id[index] =3D context_id;
+	else
+		__destroy_context(context_id);
 
+	up_read(&mm->mmap_sem);
+}
+
+static void __handle_multi_context_slb_miss(struct pt_regs *regs,
+					    unsigned long ea)
+{
+	int context, bpsize;
+	unsigned long vsid;
+	struct mm_struct *mm =3D current->mm;
+
+	context =3D get_esid_context(&mm->context, ea);
+	if (!context) {

arch/powerpc/mm/slb.c void slb_initialize(void) · line 442

Quoted 10 lines
arch/powerpc/mm/slb.c +10 -0
+		/*
+		 * haven't allocated context yet for this range.
+		 * Enable irq and allo context and return. We will
+		 * take an slb miss on this again and come here with
+		 * allocated context.
+		 */
+		/* We restore the interrupt state now */
+		if (!arch_irq_disabled_regs(regs))
+			local_irq_enable();
+		return alloc_extended_context(mm, ea);

I guess I thought we'd do this somewhere in the slice code, when an address above the limit is first used?

Doing it this way means a stray access to >=3D 512TB will get a lot further, ie. we'll come in here allocate a context etc, install an SLB entry and only then realise there's nothing mapped when we look in the hash. I'd prefer we caught it earlier if possible.

arch/powerpc/mm/slb.c void slb_initialize(void) · line 454

Quoted 12 lines
arch/powerpc/mm/slb.c +12 -0
+	}
+	/*
+	 * We are always above 1TB, hence use high user segment size.
+	 */
+	vsid =3D __get_vsid(context, ea, mmu_highuser_ssize);
+	bpsize =3D get_slice_psize(mm, ea);
+
+	insert_slb_entry(vsid, ea, bpsize, mmu_highuser_ssize);
+}
+
+/*
+ * exception_enter() handling? FIXME!!

???

Quoted 2 lines

+ */
+void handle_multi_context_slb_miss(struct pt_regs *regs)

I don't love this name, maybe slb_miss_large_addr()?

That would also free-up the non-underscore name for the actual core of the handler above.

arch/powerpc/mm/slb.c void slb_initialize(void) · line 467

Quoted 11 lines
arch/powerpc/mm/slb.c +11 -0
+{
+	enum ctx_state prev_state =3D exception_enter();
+	unsigned long ea =3D regs->dar;
+
+	/*
+	 * Kernel always runs with single context. Hence
+	 * anything that request for multi context is
+	 * considered bad slb request.
+	 */
+	if (!user_mode(regs))
+		return bad_page_fault(regs, ea, SIGSEGV);

Can't copy/to_from_user() hit this case?

arch/powerpc/mm/slb.c

Quoted 2 lines
arch/powerpc/mm/slb.c +2 -0
+	if (REGION_ID(ea) !=3D USER_REGION_ID)
+		goto slb_bad_addr;

Blank line please :)

arch/powerpc/mm/slb.c

Quoted 2 lines
arch/powerpc/mm/slb.c +2 -0
+	/*
+	 * Are we beyound what the page table layout support ?

"supports" ?

arch/powerpc/mm/slb.c void slb_initialize(void) · line 477

Quoted 5 lines
arch/powerpc/mm/slb.c +5 -0
+	 */
+	if ((ea & ~REGION_MASK) >=3D H_PGTABLE_RANGE)
+		goto slb_bad_addr;
+
+#ifdef CONFIG_PPC_MM_SLICES

That can only ever be true in this file, right?

arch/powerpc/mm/slb.c void slb_initialize(void) · line 480

Quoted 3 lines
arch/powerpc/mm/slb.c +3 -0
+	/*
+	 * consider this as bad slb if we take an slb miss
+	 * on an address above addr limit.

It's a bad "access" not a "bad slb".

We should probably spell slb SLB in the comments too.

arch/powerpc/mm/slb.c void slb_initialize(void) · line 484

Quoted 4 lines
arch/powerpc/mm/slb.c +4 -0
+	 */
+	if (ea >=3D current->mm->context.slb_addr_limit)
+		goto slb_bad_addr;
+#endif

Blank ..

arch/powerpc/mm/slb.c void slb_initialize(void) · line 485

Quoted 1 line
arch/powerpc/mm/slb.c +1 -0
+	/* Lower address should be handled by asm code */

"should have been handled"

arch/powerpc/mm/slb.c void slb_initialize(void) · line 496

Quoted 11 lines
arch/powerpc/mm/slb.c +11 -0
+	if (ea < (1UL << H_BITS_FIRST_CONTEXT))
+		goto slb_bad_addr;
+
+	__handle_multi_context_slb_miss(regs, ea);
+	exception_exit(prev_state);
+	return;
+
+slb_bad_addr:
+	_exception(SIGSEGV, regs, SEGV_BNDERR, ea);
+	exception_exit(prev_state);
+}

I think this would work better if we had:

void slb_bad_addr(regs, ea)

{
	_exception(SIGSEGV, regs, SEGV_BNDERR, ea);
}

...
void handle_multi_context_slb_miss(struct pt_regs *regs) {
...

	if (ea < (1UL << H_BITS_FIRST_CONTEXT)) {
		slb_bad_addr(regs, ea);
                goto out;
        }
...
	__handle_multi_context_slb_miss(regs, ea);
out:
	exception_exit(prev_state);
}

arch/powerpc/mm/slb_low.S ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA) · line 78

Quoted 10 lines
arch/powerpc/mm/slb_low.S +1 -1
index 2c7c717fd2ea..c66cb06e73a1 100644
@@ -75,10 +75,12 @@ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA)
  */
 _GLOBAL(slb_allocate)
 	/*
-	 * check for bad kernel/user address
+	 * Check for address range for which we need to handle multi context. F=

or

arch/powerpc/mm/slb_low.S ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA) · line 79

Quoted 1 line
arch/powerpc/mm/slb_low.S +1 -0
+         * the default context we allocate the slb via the fast path. Fo=

r large

arch/powerpc/mm/slb_low.S ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA) · line 80

Quoted 1 line
arch/powerpc/mm/slb_low.S +1 -0
+         * address we branch out to C-code and look at additional contex=

t allocated.

Leading white space is fubar.

cheers

#3 lore raw

Re: [PATCH V4 1/3] powerpc/mm: Add support for handling > 512TB address in SLB miss

Quoted 6 lines · Michael Ellerman

Hi Aneesh,

Some comments ...

Quoted 1 line · Aneesh Kumar K.V

For address above 512TB we allocate additional mmu context. To make it a=

ll

Quoted 1 line
Quoted 1 line

easy address above 512TB is handled with IR/DR=3D1 and with stack frame =

setup.

Quoted 2 lines
Quoted 2 lines

We do the additional context allocation in SLB miss handler. If the cont=

ext is

Quoted 1 line
Quoted 1 line

not allocated, we enable interrupts and allocate the context and retry t=

he

Quoted 16 lines
Quoted 3 lines

access which will again result in a SLB miss.

This doesn't build for g5_defconfig:

In file included from ../arch/powerpc/include/asm/mmu.h:314:0,

                   from ../arch/powerpc/include/asm/lppaca.h:36,
                   from ../arch/powerpc/include/asm/paca.h:21,
                   from ../arch/powerpc/include/asm/hw_irq.h:63,
                   from ../arch/powerpc/include/asm/irqflags.h:12,
                   from ../include/linux/irqflags.h:16,
                   from ../include/linux/spinlock.h:54,
                   from ../include/linux/mmzone.h:8,
                   from ../arch/powerpc/include/asm/pgtable.h:7,
                   from ../arch/powerpc/mm/slb.c:17:
Quoted 1 line

../arch/powerpc/mm/slb.c: In function =E2=80=98handle_multi_context_slb=

_miss=E2=80=99:

Quoted 1 line

../arch/powerpc/include/asm/book3s/64/mmu.h:208:25: error: array subscr=

ipt is above array bounds [-Werror=3Darray-bounds]

Quoted 3 lines
    return ctx->extended_id[index];
           ~~~~~~~~~~~~~~~~^~~~~~~

../arch/powerpc/mm/slb.c:417:30: error: array subscript is above array =

bounds [-Werror=3Darray-bounds]

Quoted 3 lines
    if (!mm->context.extended_id[index])
         ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~

../arch/powerpc/mm/slb.c:418:26: error: array subscript is above array =

bounds [-Werror=3Darray-bounds]

Quoted 2 lines
     mm->context.extended_id[index] =3D context_id;
     ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~

I guess gcc is getting it wrong with ARRAY_SIZE is 1. I added the below:

static inline int get_ea_context(mm_context_t *ctx, unsigned long ea)

{
	int index =3D ea >> MAX_EA_BITS_PER_CONTEXT;

	if (likely(index < ARRAY_SIZE(ctx>extended_id)))
		return ctx->extended_id[index];
	/* should never happen */
	BUG();
}
Quoted 3 lines

arch/powerpc=

Quoted 3 lines
arch/powerpc= renamed from arch/powerpc/include/asm/book3s/64/hash-4k.h +0 -0

/include/asm/book3s/64/hash-4k.h

Quoted 25 lines
Quoted 9 lines

index 67c5475311ee..af2ba9875f18 100644

arch/powerpc/include/asm/book3s/64/hash-4k.h +0 -0
@@ -11,6 +11,12 @@
 #define H_PUD_INDEX_SIZE  9
 #define H_PGD_INDEX_SIZE  9

=20=20
+/*
+ * No of address bits below which we use the default context

Can we use "Number", "No" means no, to mean number you need "No." but that's ugly.

Quoted 3 lines

+ * for slb allocation. For 4k this is 64TB.
+ */
+#define H_BITS_FIRST_CONTEXT 46

It's actually the number of address bits *per* context right?

"Context" is also a bit of a overloaded term, eg. context !=3D mm_context_t, maybe "context id" would be clearer?

So maybe H_BITS_PER_CONTEXT_ID?

Quoted 7 lines

This values is essentially VA_BITS - CONTEXT_BITS right?

Except VA_BITS is actually 65 in this case, but that's not clear at all from the code :/

It'd be really nice if this was calculated, or if the other values (VA_BITS/CONTEXT_BITS) were calculated based on it.

How about=20
/*
* Each context is 512TB. But on 4k we restrict our max TASK size to 64TB
* Hence also limit max EA bits to 64TB.
*/
#define MAX_EA_BITS_PER_CONTEXT 46

The VA bits is a bit complex with different platforms having different restrictions. With 4k page size we still use VA bits as 68. We limit the task size to 64TB there because of performance issue w.r.t to supporting largere task size with 4K linux page size.

Now on p4 and p5 we do have hardware restrictions on VA bits. We default there to 65.

IMHO we should keep the above #define independent of VA bits. It is an indication of size of the address space context, which can possibily smaller than what the EA and context bits combination can support as in 4K.

Quoted 2 lines

arch/powerp=

Quoted 2 lines
arch/powerp= renamed from arch/powerpc/include/asm/book3s/64/hash-64k.h +0 -0

c/include/asm/book3s/64/hash-64k.h

Quoted 10 lines

arch/powerpc/include/asm/book3s/64/hash-64k.h line 8

Quoted 7 lines

index 3bcf269f8f55..0ee0fc1ad675 100644

arch/powerpc/include/asm/book3s/64/hash-64k.h +0 -0
@@ -6,6 +6,11 @@
 #define H_PMD_INDEX_SIZE  10
 #define H_PUD_INDEX_SIZE  7
 #define H_PGD_INDEX_SIZE  8

Can we get some newlines between code?

Quoted 5 lines

arch/powerpc/include/asm/book3s/64/hash-64k.h line 13

Quoted 5 lines
arch/powerpc/include/asm/book3s/64/hash-64k.h +5 -0
+/*
+ * No of address bits below which we use the default context
+ * for slb allocation. For 64k this is 512TB.
+ */
+#define H_BITS_FIRST_CONTEXT	49

The coding style I was following here and other parts of code was for multi block comments.
a =3D 10;
/*
* Comment here
*/

and for single line comment
a =3D 10;

/* Comment here */

The idea was the first line of the multiblock comment introduced the blank line needed. I have switched to what you suggested. Let me know if you have any preferences w.r.t the above two styles.

Quoted 4 lines

This really is =3D=3D VA_BITS - CONTEXT_BITS.

arch/powerp=

Quoted 1 line
arch/powerp= renamed from arch/powerpc/include/asm/book3s/64/mmu-hash.h +0 -0

c/include/asm/book3s/64/mmu-hash.h

Quoted 4 lines

arch/powerpc/include/asm/book3s/64/mmu-hash.h static inline int user_segment_size(unsigned long ad=

Quoted 4 lines

index 50ed64fba4ae..8ee83f6e9c84 100644

arch/powerpc/include/asm/book3s/64/mmu-hash.h +0 -0
@@ -691,8 +691,8 @@ static inline int user_segment_size(unsigned long ad=

dr)

Quoted 4 lines
Quoted 4 lines
arch/powerpc/include/asm/book3s/64/mmu-hash.h +0 -0
 	return MMU_SEGSIZE_256M;
 }

=20=20
-static inline unsigned long get_vsid(unsigned long context, unsigned lo=

ng ea,

Quoted 2 lines

arch/powerpc/include/asm/book3s/64/mmu-hash.h

Quoted 2 lines
arch/powerpc/include/asm/book3s/64/mmu-hash.h +1 -1
-				     int ssize)
+static inline unsigned long __get_vsid(unsigned long context, unsigned =

long ea,

Quoted 6 lines

arch/powerpc/include/asm/book3s/64/mmu-hash.h static inline int user_segment_size(unsigned long addr) · line 695

Quoted 1 line
arch/powerpc/include/asm/book3s/64/mmu-hash.h +1 -0
+				       int ssize)

If you're going to realign it the 'i' in int should line up with the 'u' in unsigned.

Why did this become __get_vsid()? We don't have a get_vsid() that I can s=

ee?

switched to get_vsid()

Quoted 2 lines

arch/powerpc/inc=

Quoted 2 lines
arch/powerpc/inc= renamed from arch/powerpc/include/asm/book3s/64/mmu.h +0 -0

lude/asm/book3s/64/mmu.h

Quoted 6 lines
Quoted 6 lines

index 777778579305..a70adbb7ec56 100644

arch/powerpc/include/asm/book3s/64/mmu.h +0 -0
@@ -91,7 +91,15 @@ struct slice_mask {
 };

=20=20

Quoted 8 lines

arch/powerpc/include/asm/book3s/64/mmu.h struct slice_mask { · line 99

Quoted 8 lines

typedef struct {

arch/powerpc/include/asm/book3s/64/mmu.h +6 -1
-	mm_context_id_t id;
+	union {
+		/*
+		 * One context for each 512TB.
+		 * First 512TB context is saved in id and is also used
+		 * as PIDR.
+		 */
	union {
		/*
		 * We use id as the PIDR content for radix. On hash we can use
		 * more than one id. The extended ids are used when we start
		 * having address above 512TB. We allocate one extended id
		 * for each 512TB. The new id is then used with the 49 bit
		 * EA to build a new VA. We always use ESID_BITS_1T_MASK bits
		 * from EA and new context ids to build the new VAs.
		 */
		mm_context_id_t id;
		mm_context_id_t extended_id[TASK_SIZE_USER64/TASK_CONTEXT_SIZE];
	};
Quoted 26 lines

Can you make it clearer how this is used on hash vs radix.

arch/powerpc/include/asm/book3s/64/mmu.h struct slice_mask { · line 101

Quoted 2 lines
arch/powerpc/include/asm/book3s/64/mmu.h +2 -0
+		mm_context_id_t id;
+		mm_context_id_t extended_id[TASK_SIZE_USER64/TASK_CONTEXT_SIZE];

If my math is right this is typically 4PB / 512T =3D=3D 8 =3D=3D 64 bytes.

Which is small enough to not worry about, but would be good to mention in the change log at least.

arch/powerpc/include/asm/book3s/64/mmu.h extern void radix_init_pseries(void);

Quoted 11 lines
arch/powerpc/include/asm/book3s/64/mmu.h +1 -0
+	};
 	u16 user_psize;		/* page size index */

=20=20

arch/powerpc/include/asm/book3s/64/mmu.h +0 -0
 	/* Number of bits in the mm_cpumask */
@@ -193,5 +201,21 @@ extern void radix_init_pseries(void);
 static inline void radix_init_pseries(void) { };
 #endif

=20=20

arch/powerpc/include/asm/book3s/64/mmu.h +3 -0
+static inline int get_esid_context(mm_context_t *ctx, unsigned long ea)
+{
+	int index =3D ea >> H_BITS_FIRST_CONTEXT;

Using "esid" in the name is a bit confusing, because the value is an EA, not an ESID. So change the name or what's passed?

Quoted 2 lines

I think change the name, the callers both have an EA so it makes sense to pass that.

changed to get_ea_context()

Quoted 10 lines
Quoted 2 lines

+

I know we check ea elsewhere, but a:

VM_BUG_ON(index >=3D ARRAY_SIZE(extened_id))

Would make me feel better I think, and index being unsigned.

arch/powerpc/include=

Quoted 1 line
arch/powerpc/include= renamed from arch/powerpc/include/asm/processor.h +0 -0

/asm/processor.h

Quoted 11 lines
Quoted 11 lines

index 01299cdc9806..70d65b482504 100644

arch/powerpc/include/asm/processor.h +1 -0
@@ -119,9 +119,16 @@ void release_thread(struct task_struct *);
  */
 #define TASK_SIZE_USER64		TASK_SIZE_512TB
 #define DEFAULT_MAP_WINDOW_USER64	TASK_SIZE_128TB
+#define TASK_CONTEXT_SIZE		TASK_SIZE_512TB
 #else
 #define TASK_SIZE_USER64		TASK_SIZE_64TB
 #define DEFAULT_MAP_WINDOW_USER64	TASK_SIZE_64TB
Quoted 8 lines

arch/powerpc/include/asm/processor.h void release_thread(struct task_struct *); · line 130

Quoted 5 lines
arch/powerpc/include/asm/processor.h +5 -0
+/*
+ * We don't need allocate extended context id for 4K
+ * page size. We limit max address on this config to
+ * 64TB.
+ */

/*
* We don't need to allocate extended context ids for 4K page size, becau=

se

Quoted 6 lines

* we limit the max effective address on this config to 64TB. */

???

arch/powerpc/kernel/=

Quoted 1 line
arch/powerpc/kernel/= renamed from arch/powerpc/kernel/exceptions-64s.S +0 -0

exceptions-64s.S

Quoted 34 lines

arch/powerpc/kernel/exceptions-64s.S END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) · line 622

Quoted 7 lines

index 3ac87e53b3da..166b8c0f1830 100644

arch/powerpc/kernel/exceptions-64s.S +0 -0
@@ -620,8 +620,12 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
 	ld	r10,PACA_EXSLB+EX_LR(r13)
 	lwz	r9,PACA_EXSLB+EX_CCR(r13)	/* get saved CR */
 	mtlr	r10

Blank line would be nice.

arch/powerpc/kernel/exceptions-64s.S END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) · line 626

Quoted 4 lines
arch/powerpc/kernel/exceptions-64s.S +4 -0
+	/*
+	 * Large address, check whether we have to allocate new
+	 * contexts.
+	 */

That doesn't need to wrap.

	/* Large address, check whether we need to allocate new contexts. */

arch/powerpc/kernel/exceptions-64s.S END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) · line 624

Quoted 3 lines
arch/powerpc/kernel/exceptions-64s.S +1 -0
+	beq-	8f

=20=20

arch/powerpc/kernel/exceptions-64s.S +0 -1
-	beq-	8f		/* if bad address, make full stack frame */

And we ended up with two blank lines here which is probably overkill. =20=20

arch/powerpc/kernel/exceptions-64s.S EXC_COMMON_BEGIN(bad_addr_slb) · line 713

Quoted 5 lines
arch/powerpc/kernel/exceptions-64s.S +0 -1
@@ -710,7 +714,7 @@ EXC_COMMON_BEGIN(bad_addr_slb)
 	std	r10, _TRAP(r1)
 2:	bl	save_nvgprs
 	addi	r3, r1, STACK_FRAME_OVERHEAD
-	bl	slb_miss_bad_addr

You removed the only call to this but didn't remove the function or its prototype AFAICS.

Quoted 1 line

arch/powerpc/mm/mm=

Quoted 1 line
arch/powerpc/mm/mm= renamed from arch/powerpc/mm/mmu_context_book3s64.c +0 -0

u_context_book3s64.c

Quoted 5 lines
Quoted 5 lines

index 80acad52b006..ccc88fa7c35c 100644

arch/powerpc/mm/mmu_context_book3s64.c +0 -0
@@ -178,6 +178,19 @@ void __destroy_context(int context_id)
 }
Quoted 8 lines

arch/powerpc/mm/mmu_context_book3s64.c void __destroy_context(int context_id)

Quoted 8 lines
arch/powerpc/mm/mmu_context_book3s64.c +0 -0
 EXPORT_SYMBOL_GPL(__destroy_context);

=20=20

arch/powerpc/mm/mmu_context_book3s64.c +6 -0
+static void destroy_contexts(mm_context_t *ctx)
+{
+	int index, context_id;
+
+	spin_lock(&mmu_context_lock);
+	for (index =3D 0; index < (TASK_SIZE_USER64/TASK_CONTEXT_SIZE); index+=

+) {

Quoted 40 lines

ARRAY_SIZE(ctx->extended_id) ?

arch/powerpc/mm/slb.c line 26

Quoted 9 lines
arch/powerpc/mm/slb.c +1 -0
index 13cfe413b40d..a93887ee9b22 100644
@@ -23,6 +23,7 @@
 #include <asm/smp.h>
 #include <linux/compiler.h>
 #include <linux/mm_types.h>
+#include <linux/context_tracking.h>

Our includes are generally not well sorted, but can you try to keep them alphabetical. So after compiler.h.

arch/powerpc/mm/slb.c void slb_initialize(void) · line 346

Quoted 7 lines
arch/powerpc/mm/slb.c +0 -0
@@ -340,3 +341,156 @@ void slb_initialize(void)

=20=20

arch/powerpc/mm/slb.c +3 -0
 	asm volatile("isync":::"memory");
 }
+
+/*
+ * Only handle insert of 1TB slb entries.

What if we don't have them (enabled) ?

arch/powerpc/mm/slb.c void slb_initialize(void) · line 349

Quoted 3 lines

+ */

arch/powerpc/mm/slb.c +2 -0
+static void insert_slb_entry(unsigned long vsid, unsigned long ea,
+			     int bpsize, int ssize)

Parameter alignment again.

arch/powerpc/mm/slb.c void slb_initialize(void) · line 354

Quoted 5 lines
arch/powerpc/mm/slb.c +5 -0
+{
+	int slb_cache_index;
+	unsigned long flags;
+	enum slb_index index;
+	unsigned long vsid_data, esid_data;

Can you clean those up:

Quoted 3 lines
	unsigned long vsid_data, esid_data, flags;
	enum slb_index index;
	int slb_cache_index;

The style I was following here and other parts of the code was

int a;
int ab;
int abc;

instead of
int abc;
int ab;
int a;

I like the former. If you have strong preference I will switch to the later

Quoted 57 lines

arch/powerpc/mm/slb.c void slb_initialize(void) · line 358

Quoted 5 lines
arch/powerpc/mm/slb.c +4 -0
+
+	/*
+	 * We are irq disabled, hence should be safe
+	 * to access PACA.

Doesn't need to wrap.

arch/powerpc/mm/slb.c

Quoted 2 lines
arch/powerpc/mm/slb.c +2 -0
+	 */
+	index =3D  get_paca()->stab_rr;
                ^

Unneeded extra space there

Blank line please.

arch/powerpc/mm/slb.c

Quoted 2 lines
arch/powerpc/mm/slb.c +2 -0
+	/*
+	 * simple round roubin replacement of slb.

"Simple round-robin"

Although it's not really, it's round-robin but not starting at zero, starting at SLB_NUM_BOLTED.

arch/powerpc/mm/slb.c void slb_initialize(void)

Quoted 5 lines
arch/powerpc/mm/slb.c +5 -0
+	 */
+	if (index < mmu_slb_size)
+		index++;
+	else
+		index =3D SLB_NUM_BOLTED;

Blank line.

arch/powerpc/mm/slb.c

Quoted 5 lines
arch/powerpc/mm/slb.c +5 -0
+	get_paca()->stab_rr =3D index;
+
+	flags =3D SLB_VSID_USER | mmu_psize_defs[bpsize].sllp;
+	vsid_data =3D  (vsid << SLB_VSID_SHIFT_1T) | flags |
+		((unsigned long) ssize << SLB_VSID_SSIZE_SHIFT);
	vsid_data =3D (vsid << SLB_VSID_SHIFT_1T) | flags |
        	    ((unsigned long) ssize << SLB_VSID_SSIZE_SHIFT);

arch/powerpc/mm/slb.c void slb_initialize(void) · line 376

Quoted 4 lines
arch/powerpc/mm/slb.c +4 -0
+	esid_data =3D mk_esid_data(ea, mmu_highuser_ssize, index);
+
+	asm volatile("slbmte %0, %1" : : "r" (vsid_data), "r" (esid_data)
+		     : "memory");

Blank line.

arch/powerpc/mm/slb.c void slb_initialize(void) · line 387

Quoted 11 lines
arch/powerpc/mm/slb.c +11 -0
+	/*
+	 * Now update slb cache entries
+	 */
+	slb_cache_index =3D get_paca()->slb_cache_ptr;
+	if (slb_cache_index < SLB_CACHE_ENTRIES) {
+		/*
+		 * We have space in slb cache for optimized switch_slb().
+		 * Top 36 bits from esid_data as per ISA
+		 */
+		get_paca()->slb_cache[slb_cache_index++] =3D esid_data >> 28;
+	}

Blank line.

Quoted 7 lines

arch/powerpc/mm/slb.c void slb_initialize(void)

Quoted 7 lines
arch/powerpc/mm/slb.c +7 -0
+	/*
+	 * if we are full, just increment and return.
+	 */
+	get_paca()->slb_cache_ptr++;
+}
+
+static void alloc_extended_context(struct mm_struct *mm, unsigned long =

ea)

Quoted 55 lines
Quoted 41 lines
arch/powerpc/mm/slb.c +38 -0
+{
+	int context_id;
+
+	int index =3D ea >> H_BITS_FIRST_CONTEXT;
+
+	/*
+	 * we need to do locking only here. If this value was not set before
+	 * we will have taken an SLB miss and will reach here. The value will
+	 * be either 0 or a valid extended context. We need to make sure two
+	 * parallel SLB miss don't end up allocating extended_context for the
+	 * same range. The locking below ensures that. For now we take the
+	 * heavy mmap_sem. But can be changed to per mm_context_t custom lock
+	 * if needed.
+	 */
+	down_read(&mm->mmap_sem);
 
+	context_id =3D hash__alloc_context_id();
+	if (context_id < 0) {
+		up_read(&mm->mmap_sem);
+		pagefault_out_of_memory();
+		return;
+	}
 
+	/* Check for parallel allocation after holding lock */
+	if (!mm->context.extended_id[index])
+		mm->context.extended_id[index] =3D context_id;
+	else
+		__destroy_context(context_id);
 
+	up_read(&mm->mmap_sem);
+}
+
+static void __handle_multi_context_slb_miss(struct pt_regs *regs,
+					    unsigned long ea)
+{
+	int context, bpsize;
+	unsigned long vsid;
+	struct mm_struct *mm =3D current->mm;
+
+	context =3D get_esid_context(&mm->context, ea);
+	if (!context) {

arch/powerpc/mm/slb.c void slb_initialize(void) · line 442

Quoted 10 lines
arch/powerpc/mm/slb.c +10 -0
+		/*
+		 * haven't allocated context yet for this range.
+		 * Enable irq and allo context and return. We will
+		 * take an slb miss on this again and come here with
+		 * allocated context.
+		 */
+		/* We restore the interrupt state now */
+		if (!arch_irq_disabled_regs(regs))
+			local_irq_enable();
+		return alloc_extended_context(mm, ea);

I guess I thought we'd do this somewhere in the slice code, when an address above the limit is first used?

Quoted 4 lines

Doing it this way means a stray access to >=3D 512TB will get a lot further, ie. we'll come in here allocate a context etc, install an SLB entry and only then realise there's nothing mapped when we look in the hash. I'd prefer we caught it earlier if possible.

Good. I moved this to slice_get_unmapped_area. So in the final part of slice code we now do

return_addr:

	if (need_extra_context(mm, newaddr)) {
		if (alloc_extended_context(mm, newaddr) < 0)
			return -ENOMEM;
	}
	return newaddr;
Quoted 15 lines

arch/powerpc/mm/slb.c void slb_initialize(void) · line 454

Quoted 13 lines
arch/powerpc/mm/slb.c +12 -0
+	}
+	/*
+	 * We are always above 1TB, hence use high user segment size.
+	 */
+	vsid =3D __get_vsid(context, ea, mmu_highuser_ssize);
+	bpsize =3D get_slice_psize(mm, ea);
+
+	insert_slb_entry(vsid, ea, bpsize, mmu_highuser_ssize);
+}
+
+/*
+ * exception_enter() handling? FIXME!!

???

stale comment removed

Quoted 8 lines
Quoted 3 lines

+ */
+void handle_multi_context_slb_miss(struct pt_regs *regs)

I don't love this name, maybe slb_miss_large_addr()?

That would also free-up the non-underscore name for the actual core of the handler above.

Done, byt we still have asm code as multi_context_slb. I think you would want that also changed? Any suggestion?

Quoted 14 lines

arch/powerpc/mm/slb.c void slb_initialize(void) · line 467

Quoted 12 lines
arch/powerpc/mm/slb.c +11 -0
+{
+	enum ctx_state prev_state =3D exception_enter();
+	unsigned long ea =3D regs->dar;
+
+	/*
+	 * Kernel always runs with single context. Hence
+	 * anything that request for multi context is
+	 * considered bad slb request.
+	 */
+	if (!user_mode(regs))
+		return bad_page_fault(regs, ea, SIGSEGV);

Can't copy/to_from_user() hit this case?

Thanks for catching this. What i really wanted there was to differentiate between how we handle access from kernel and user. It should essentially in the slb_bad_addr: hunk.

slb_bad_addr:

	if (user_mode(regs))
		_exception(SIGSEGV, regs, SEGV_BNDERR, ea);
	else
		bad_page_fault(regs, ea, SIGSEGV);
	exception_exit(prev_state);
Quoted 11 lines

arch/powerpc/mm/slb.c

Quoted 3 lines
arch/powerpc/mm/slb.c +2 -0
+	if (REGION_ID(ea) !=3D USER_REGION_ID)
+		goto slb_bad_addr;

Blank line please :)

arch/powerpc/mm/slb.c

Quoted 2 lines
arch/powerpc/mm/slb.c +2 -0
+	/*
+	 * Are we beyound what the page table layout support ?

"supports" ?

Quoted 7 lines

arch/powerpc/mm/slb.c void slb_initialize(void) · line 477

Quoted 5 lines
arch/powerpc/mm/slb.c +5 -0
+	 */
+	if ((ea & ~REGION_MASK) >=3D H_PGTABLE_RANGE)
+		goto slb_bad_addr;
+
+#ifdef CONFIG_PPC_MM_SLICES

That can only ever be true in this file, right?

yes.=20

Quoted 39 lines

arch/powerpc/mm/slb.c void slb_initialize(void) · line 480

Quoted 4 lines
arch/powerpc/mm/slb.c +3 -0
+	/*
+	 * consider this as bad slb if we take an slb miss
+	 * on an address above addr limit.

It's a bad "access" not a "bad slb".

We should probably spell slb SLB in the comments too.

arch/powerpc/mm/slb.c void slb_initialize(void) · line 484

Quoted 4 lines
arch/powerpc/mm/slb.c +4 -0
+	 */
+	if (ea >=3D current->mm->context.slb_addr_limit)
+		goto slb_bad_addr;
+#endif

Blank ..

arch/powerpc/mm/slb.c void slb_initialize(void) · line 485

Quoted 1 line
arch/powerpc/mm/slb.c +1 -0
+	/* Lower address should be handled by asm code */

"should have been handled"

arch/powerpc/mm/slb.c void slb_initialize(void) · line 496

Quoted 11 lines
arch/powerpc/mm/slb.c +11 -0
+	if (ea < (1UL << H_BITS_FIRST_CONTEXT))
+		goto slb_bad_addr;
+
+	__handle_multi_context_slb_miss(regs, ea);
+	exception_exit(prev_state);
+	return;
+
+slb_bad_addr:
+	_exception(SIGSEGV, regs, SEGV_BNDERR, ea);
+	exception_exit(prev_state);
+}

I think this would work better if we had:

void slb_bad_addr(regs, ea)

{
	_exception(SIGSEGV, regs, SEGV_BNDERR, ea);
}
Quoted 8 lines

...
void handle_multi_context_slb_miss(struct pt_regs *regs) {
...

	if (ea < (1UL << H_BITS_FIRST_CONTEXT)) {
		slb_bad_addr(regs, ea);
                goto out;
        }

that would mean i will have a multi line if() in that code. All the error path essentially does goto slb_bad_addr(). Any specific reason you wanted that as a function? To avoid the two return paths ?

Quoted 6 lines

...

	__handle_multi_context_slb_miss(regs, ea);
out:
	exception_exit(prev_state);
}
Quoted 10 lines

arch/powerpc/mm/slb_low.S ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA) · line 78

Quoted 10 lines
arch/powerpc/mm/slb_low.S +1 -1
index 2c7c717fd2ea..c66cb06e73a1 100644
@@ -75,10 +75,12 @@ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA)
  */
 _GLOBAL(slb_allocate)
 	/*
-	 * check for bad kernel/user address
+	 * Check for address range for which we need to handle multi context. =

For

Quoted 1 line

arch/powerpc/mm/slb_low.S ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA) · line 79

Quoted 1 line
arch/powerpc/mm/slb_low.S +1 -0
+         * the default context we allocate the slb via the fast path. F=

or large

Quoted 1 line

arch/powerpc/mm/slb_low.S ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA) · line 80

Quoted 1 line
arch/powerpc/mm/slb_low.S +1 -0
+         * address we branch out to C-code and look at additional conte=

xt allocated.

Quoted 5 lines

Leading white space is fubar.

cheers

#4 lore raw

PATCH v4 2/3 powerpc/mm/hash64: Increase the VA range

In reply to Aneesh Kumar K.V

This patch increase the max virtual address value to 4PB. With 4K page size config we continue to limit ourself to 64TB.

---
 arch/powerpc/include/asm/book3s/64/hash-64k.h | 2 +-
 arch/powerpc/include/asm/processor.h          | 9 ++++++++-
 arch/powerpc/mm/init_64.c                     | 6 ------
 arch/powerpc/mm/pgtable_64.c                  | 5 -----
 4 files changed, 9 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-64k.h +1 -1
index 0ee0fc1ad675..02098d7fe177 100644
@@ -4,7 +4,7 @@
 
 #define H_PTE_INDEX_SIZE  8
 #define H_PMD_INDEX_SIZE  10
-#define H_PUD_INDEX_SIZE  7
+#define H_PUD_INDEX_SIZE  10
 #define H_PGD_INDEX_SIZE  8
 /*
  * No of address bits below which we use the default context
arch/powerpc/include/asm/processor.h +8 -1
index 70d65b482504..a621a068880a 100644
@@ -109,6 +109,13 @@ void release_thread(struct task_struct *);
 #define TASK_SIZE_64TB  (0x0000400000000000UL)
 #define TASK_SIZE_128TB (0x0000800000000000UL)
 #define TASK_SIZE_512TB (0x0002000000000000UL)
+#define TASK_SIZE_1PB   (0x0004000000000000UL)
+#define TASK_SIZE_2PB   (0x0008000000000000UL)
+/*
+ * With 52 bits in the address we can support
+ * upto 4PB of range.
+ */
+#define TASK_SIZE_4PB   (0x0010000000000000UL)
 
 /*
  * For now 512TB is only supported with book3s and 64K linux page size.
@@ -117,7 +124,7 @@ void release_thread(struct task_struct *);
 /*
  * Max value currently used:
  */
-#define TASK_SIZE_USER64		TASK_SIZE_512TB
+#define TASK_SIZE_USER64		TASK_SIZE_4PB
 #define DEFAULT_MAP_WINDOW_USER64	TASK_SIZE_128TB
 #define TASK_CONTEXT_SIZE		TASK_SIZE_512TB
 #else
arch/powerpc/mm/init_64.c +0 -6
index fdb424a29f03..63470b06c502 100644
@@ -68,12 +68,6 @@
 
 #include "mmu_decl.h"
 
-#ifdef CONFIG_PPC_BOOK3S_64
-#if H_PGTABLE_RANGE > USER_VSID_RANGE
-#warning Limited user VSID range means pagetable space is wasted
-#endif
-#endif /* CONFIG_PPC_BOOK3S_64 */
-
 phys_addr_t memstart_addr = ~0;
 EXPORT_SYMBOL_GPL(memstart_addr);
 phys_addr_t kernstart_addr;
arch/powerpc/mm/pgtable_64.c +0 -5
index 28c980eb4422..16636bdf3331 100644
@@ -57,11 +57,6 @@
 
 #include "mmu_decl.h"
 
-#ifdef CONFIG_PPC_BOOK3S_64
-#if TASK_SIZE_USER64 > (1UL << (ESID_BITS + SID_SHIFT))
-#error TASK_SIZE_USER64 exceeds user VSID range
-#endif
-#endif
 
 #ifdef CONFIG_PPC_BOOK3S_64
 /*
Signature · 1 line
2.14.3
#5 lore raw

PATCH v4 3/3 powerpc/mm/hash: Don't memset pgd table if not needed

In reply to Aneesh Kumar K.V

We need to zero-out pgd table only if we share the slab cache with pud/pmd level caches. With the support of 4PB, we don't share the slab cache anymore. Instead of removing the code completely hide it within an #ifdef. We don't need to do this with any other page table level, because they all allocate table of double the size and we take of initializing the first half corrrectly during page table zap.

---
 arch/powerpc/include/asm/book3s/64/pgalloc.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgalloc.h +12 -1
index 4746bc68d446..07f0dbac479f 100644
@@ -80,8 +80,19 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
 
 	pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
 			       pgtable_gfp_flags(mm, GFP_KERNEL));
+	/*
+	 * With hugetlb, we don't clear the second half of the page table.
+	 * If we share the same slab cache with the pmd or pud level table,
+	 * we need to make sure we zero out the full table on alloc.
+	 * With 4K we don't store slot in the second half. Hence we don't
+	 * need to do this for 4k.
+	 */
+#if (H_PGD_INDEX_SIZE == H_PUD_CACHE_INDEX) || \
+		(H_PGD_INDEX_SIZE == H_PMD_CACHE_INDEX)
+#if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_PPC_64K_PAGES)
 	memset(pgd, 0, PGD_TABLE_SIZE);
-
+#endif
+#endif
 	return pgd;
 }
 
Signature · 1 line
2.14.3