Skip to content

Commit bf9a95f

Browse files
Ram Paimpe
authored andcommitted
powerpc: Free up four 64K PTE bits in 64K backed HPTE pages
Rearrange 64K PTE bits to free up bits 3, 4, 5 and 6 in the 64K backed HPTE pages. This along with the earlier patch will entirely free up the four bits from 64K PTE. The bit numbers are big-endian as defined in the ISA3.0 This patch does the following change to 64K PTE backed by 64K HPTE. H_PAGE_F_SECOND (S) which occupied bit 4 moves to the second part of the pte to bit 60. H_PAGE_F_GIX (G,I,X) which occupied bit 5, 6 and 7 also moves to the second part of the pte to bit 61, 62, 63, 64 respectively since bit 7 is now freed up, we move H_PAGE_BUSY (B) from bit 9 to bit 7. The second part of the PTE will hold (H_PAGE_F_SECOND|H_PAGE_F_GIX) at bit 60,61,62,63. NOTE: None of the bits in the secondary PTE were not used by 64k-HPTE backed PTE. Before the patch, the 64K HPTE backed 64k PTE format was as follows 0 1 2 3 4 5 6 7 8 9 10...........................63 : : : : : : : : : : : : v v v v v v v v v v v v ,-,-,-,-,--,--,--,--,-,-,-,-,-,------------------,-,-,-, |x|x|x| |S |G |I |X |x|B| |x|x|................|x|x|x|x| <- primary pte '_'_'_'_'__'__'__'__'_'_'_'_'_'________________'_'_'_'_' | | | | | | | | | | | | |..................| | | | | <- secondary pte '_'_'_'_'__'__'__'__'_'_'_'_'__________________'_'_'_'_' After the patch, the 64k HPTE backed 64k PTE format is as follows 0 1 2 3 4 5 6 7 8 9 10...........................63 : : : : : : : : : : : : v v v v v v v v v v v v ,-,-,-,-,--,--,--,--,-,-,-,-,-,------------------,-,-,-, |x|x|x| | | | |B |x| | |x|x|................|.|.|.|.| <- primary pte '_'_'_'_'__'__'__'__'_'_'_'_'_'________________'_'_'_'_' | | | | | | | | | | | | |..................|S|G|I|X| <- secondary pte '_'_'_'_'__'__'__'__'_'_'_'_'__________________'_'_'_'_' The above PTE changes is applicable to hugetlbpages aswell. The patch does the following code changes: a) moves the H_PAGE_F_SECOND and H_PAGE_F_GIX to 4k PTE header since it is no more needed b the 64k PTEs. b) abstracts out __real_pte() and __rpte_to_hidx() so the caller need not know the bit location of the slot. c) moves the slot bits to the secondary pte. Reviewed-by: Aneesh Kumar K.V <[email protected]> Signed-off-by: Ram Pai <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 9d2edb1 commit bf9a95f

File tree

5 files changed

+33
-40
lines changed

5 files changed

+33
-40
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#define H_PUD_TABLE_SIZE (sizeof(pud_t) << H_PUD_INDEX_SIZE)
1818
#define H_PGD_TABLE_SIZE (sizeof(pgd_t) << H_PGD_INDEX_SIZE)
1919

20+
#define H_PAGE_F_GIX_SHIFT 56
21+
#define H_PAGE_F_SECOND _RPAGE_RSV2 /* HPTE is in 2ndary HPTEG */
22+
#define H_PAGE_F_GIX (_RPAGE_RSV3 | _RPAGE_RSV4 | _RPAGE_RPN44)
2023
#define H_PAGE_BUSY _RPAGE_RSV1 /* software: PTE & hash are busy */
2124

2225
/* PTE flags to conserve for HPTE identification */

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
#define H_PAGE_COMBO _RPAGE_RPN0 /* this is a combo 4k page */
1515
#define H_PAGE_4K_PFN _RPAGE_RPN1 /* PFN is for a single 4k page */
16-
#define H_PAGE_BUSY _RPAGE_RPN42 /* software: PTE & hash are busy */
16+
#define H_PAGE_BUSY _RPAGE_RPN44 /* software: PTE & hash are busy */
1717

1818
/*
1919
* We need to differentiate between explicit huge page and THP huge
@@ -22,8 +22,7 @@
2222
#define H_PAGE_THP_HUGE H_PAGE_4K_PFN
2323

2424
/* PTE flags to conserve for HPTE identification */
25-
#define _PAGE_HPTEFLAGS (H_PAGE_BUSY | H_PAGE_F_SECOND | \
26-
H_PAGE_F_GIX | H_PAGE_HASHPTE | H_PAGE_COMBO)
25+
#define _PAGE_HPTEFLAGS (H_PAGE_BUSY | H_PAGE_HASHPTE | H_PAGE_COMBO)
2726
/*
2827
* we support 16 fragments per PTE page of 64K size.
2928
*/
@@ -51,27 +50,26 @@ static inline real_pte_t __real_pte(pte_t pte, pte_t *ptep)
5150
unsigned long *hidxp;
5251

5352
rpte.pte = pte;
54-
rpte.hidx = 0;
55-
if (pte_val(pte) & H_PAGE_COMBO) {
56-
/*
57-
* Make sure we order the hidx load against the H_PAGE_COMBO
58-
* check. The store side ordering is done in __hash_page_4K
59-
*/
60-
smp_rmb();
61-
hidxp = (unsigned long *)(ptep + PTRS_PER_PTE);
62-
rpte.hidx = *hidxp;
63-
}
53+
54+
/*
55+
* Ensure that we do not read the hidx before we read the PTE. Because
56+
* the writer side is expected to finish writing the hidx first followed
57+
* by the PTE, by using smp_wmb(). pte_set_hash_slot() ensures that.
58+
*/
59+
smp_rmb();
60+
61+
hidxp = (unsigned long *)(ptep + PTRS_PER_PTE);
62+
rpte.hidx = *hidxp;
6463
return rpte;
6564
}
6665

6766
#define HIDX_BITS(x, index) (x << (index << 2))
67+
#define BITS_TO_HIDX(x, index) ((x >> (index << 2)) & 0xfUL)
6868
#define INVALID_RPTE_HIDX ~(0x0UL)
6969

7070
static inline unsigned long __rpte_to_hidx(real_pte_t rpte, unsigned long index)
7171
{
72-
if ((pte_val(rpte.pte) & H_PAGE_COMBO))
73-
return (rpte.hidx >> (index<<2)) & 0xf;
74-
return (pte_val(rpte.pte) >> H_PAGE_F_GIX_SHIFT) & 0xf;
72+
return BITS_TO_HIDX(rpte.hidx, index);
7573
}
7674

7775
/*

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
*
1010
*/
1111
#define H_PTE_NONE_MASK _PAGE_HPTEFLAGS
12-
#define H_PAGE_F_GIX_SHIFT 56
13-
#define H_PAGE_F_SECOND _RPAGE_RSV2 /* HPTE is in 2ndary HPTEG */
14-
#define H_PAGE_F_GIX (_RPAGE_RSV3 | _RPAGE_RSV4 | _RPAGE_RPN44)
1512
#define H_PAGE_HASHPTE _RPAGE_RPN43 /* PTE has associated HPTE */
1613

1714
#ifdef CONFIG_PPC_64K_PAGES

arch/powerpc/mm/hash64_64k.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
103103
* On hash insert failure we use old pte value and we don't
104104
* want slot information there if we have a insert failure.
105105
*/
106-
old_pte &= ~(H_PAGE_HASHPTE | H_PAGE_F_GIX | H_PAGE_F_SECOND);
107-
new_pte &= ~(H_PAGE_HASHPTE | H_PAGE_F_GIX | H_PAGE_F_SECOND);
106+
old_pte &= ~H_PAGE_HASHPTE;
107+
new_pte &= ~H_PAGE_HASHPTE;
108108
goto htab_insert_hpte;
109109
}
110110
/*
@@ -225,6 +225,7 @@ int __hash_page_64K(unsigned long ea, unsigned long access,
225225
unsigned long vsid, pte_t *ptep, unsigned long trap,
226226
unsigned long flags, int ssize)
227227
{
228+
real_pte_t rpte;
228229
unsigned long hpte_group;
229230
unsigned long rflags, pa;
230231
unsigned long old_pte, new_pte;
@@ -261,23 +262,21 @@ int __hash_page_64K(unsigned long ea, unsigned long access,
261262
} while (!pte_xchg(ptep, __pte(old_pte), __pte(new_pte)));
262263

263264
rflags = htab_convert_pte_flags(new_pte);
265+
rpte = __real_pte(__pte(old_pte), ptep);
264266

265267
if (cpu_has_feature(CPU_FTR_NOEXECUTE) &&
266268
!cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
267269
rflags = hash_page_do_lazy_icache(rflags, __pte(old_pte), trap);
268270

269271
vpn = hpt_vpn(ea, vsid, ssize);
270272
if (unlikely(old_pte & H_PAGE_HASHPTE)) {
273+
unsigned long gslot;
274+
271275
/*
272276
* There MIGHT be an HPTE for this pte
273277
*/
274-
hash = hpt_hash(vpn, shift, ssize);
275-
if (old_pte & H_PAGE_F_SECOND)
276-
hash = ~hash;
277-
slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
278-
slot += (old_pte & H_PAGE_F_GIX) >> H_PAGE_F_GIX_SHIFT;
279-
280-
if (mmu_hash_ops.hpte_updatepp(slot, rflags, vpn, MMU_PAGE_64K,
278+
gslot = pte_get_hash_gslot(vpn, shift, ssize, rpte, 0);
279+
if (mmu_hash_ops.hpte_updatepp(gslot, rflags, vpn, MMU_PAGE_64K,
281280
MMU_PAGE_64K, ssize,
282281
flags) == -1)
283282
old_pte &= ~_PAGE_HPTEFLAGS;
@@ -326,9 +325,9 @@ int __hash_page_64K(unsigned long ea, unsigned long access,
326325
MMU_PAGE_64K, MMU_PAGE_64K, old_pte);
327326
return -1;
328327
}
328+
329329
new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | H_PAGE_HASHPTE;
330-
new_pte |= (slot << H_PAGE_F_GIX_SHIFT) &
331-
(H_PAGE_F_SECOND | H_PAGE_F_GIX);
330+
new_pte |= pte_set_hidx(ptep, rpte, 0, slot);
332331
}
333332
*ptep = __pte(new_pte & ~H_PAGE_BUSY);
334333
return 0;

arch/powerpc/mm/hugetlbpage-hash64.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
2323
pte_t *ptep, unsigned long trap, unsigned long flags,
2424
int ssize, unsigned int shift, unsigned int mmu_psize)
2525
{
26+
real_pte_t rpte;
2627
unsigned long vpn;
2728
unsigned long old_pte, new_pte;
2829
unsigned long rflags, pa, sz;
@@ -62,6 +63,7 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
6263
} while(!pte_xchg(ptep, __pte(old_pte), __pte(new_pte)));
6364

6465
rflags = htab_convert_pte_flags(new_pte);
66+
rpte = __real_pte(__pte(old_pte), ptep);
6567

6668
sz = ((1UL) << shift);
6769
if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
@@ -72,15 +74,10 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
7274
/* Check if pte already has an hpte (case 2) */
7375
if (unlikely(old_pte & H_PAGE_HASHPTE)) {
7476
/* There MIGHT be an HPTE for this pte */
75-
unsigned long hash, slot;
77+
unsigned long gslot;
7678

77-
hash = hpt_hash(vpn, shift, ssize);
78-
if (old_pte & H_PAGE_F_SECOND)
79-
hash = ~hash;
80-
slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
81-
slot += (old_pte & H_PAGE_F_GIX) >> H_PAGE_F_GIX_SHIFT;
82-
83-
if (mmu_hash_ops.hpte_updatepp(slot, rflags, vpn, mmu_psize,
79+
gslot = pte_get_hash_gslot(vpn, shift, ssize, rpte, 0);
80+
if (mmu_hash_ops.hpte_updatepp(gslot, rflags, vpn, mmu_psize,
8481
mmu_psize, ssize, flags) == -1)
8582
old_pte &= ~_PAGE_HPTEFLAGS;
8683
}
@@ -107,8 +104,7 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
107104
return -1;
108105
}
109106

110-
new_pte |= (slot << H_PAGE_F_GIX_SHIFT) &
111-
(H_PAGE_F_SECOND | H_PAGE_F_GIX);
107+
new_pte |= pte_set_hidx(ptep, rpte, 0, slot);
112108
}
113109

114110
/*

0 commit comments

Comments
 (0)