Skip to content

Commit 697ece7

Browse files
chleroympe
authored andcommitted
powerpc/32s: reorder Linux PTE bits to better match Hash PTE bits.
Reorder Linux PTE bits to (almost) match Hash PTE bits. RW Kernel : PP = 00 RO Kernel : PP = 00 RW User : PP = 01 RO User : PP = 11 So naturally, we should have _PAGE_USER = 0x001 _PAGE_RW = 0x002 Today 0x001 and 0x002 and _PAGE_PRESENT and _PAGE_HASHPTE which both are software only bits. Switch _PAGE_USER and _PAGE_PRESET Switch _PAGE_RW and _PAGE_HASHPTE This allows to remove a few insns. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/c4d6c18a7f8d9d3b899bc492f55fbc40ef38896a.1583861325.git.christophe.leroy@c-s.fr
1 parent af92bad commit 697ece7

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
* updating the accessed and modified bits in the page table tree.
1818
*/
1919

20-
#define _PAGE_PRESENT 0x001 /* software: pte contains a translation */
21-
#define _PAGE_HASHPTE 0x002 /* hash_page has made an HPTE for this pte */
22-
#define _PAGE_USER 0x004 /* usermode access allowed */
20+
#define _PAGE_USER 0x001 /* usermode access allowed */
21+
#define _PAGE_RW 0x002 /* software: user write access allowed */
22+
#define _PAGE_PRESENT 0x004 /* software: pte contains a translation */
2323
#define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2424
#define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2525
#define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2626
#define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2727
#define _PAGE_DIRTY 0x080 /* C: page changed */
2828
#define _PAGE_ACCESSED 0x100 /* R: page referenced */
2929
#define _PAGE_EXEC 0x200 /* software: exec allowed */
30-
#define _PAGE_RW 0x400 /* software: user write access allowed */
30+
#define _PAGE_HASHPTE 0x400 /* hash_page has made an HPTE for this pte */
3131
#define _PAGE_SPECIAL 0x800 /* software: Special page */
3232

3333
#ifdef CONFIG_PTE_64BIT

arch/powerpc/kernel/head_32.S

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ BEGIN_MMU_FTR_SECTION
348348
andis. r0, r5, (DSISR_BAD_FAULT_32S | DSISR_DABRMATCH)@h
349349
#endif
350350
bne handle_page_fault_tramp_2 /* if not, try to put a PTE */
351-
rlwinm r3, r5, 32 - 15, 21, 21 /* DSISR_STORE -> _PAGE_RW */
351+
rlwinm r3, r5, 32 - 24, 30, 30 /* DSISR_STORE -> _PAGE_RW */
352352
bl hash_page
353353
b handle_page_fault_tramp_1
354354
FTR_SECTION_ELSE
@@ -497,7 +497,6 @@ InstructionTLBMiss:
497497
andc. r1,r1,r0 /* check access & ~permission */
498498
bne- InstructionAddressInvalid /* return if access not permitted */
499499
/* Convert linux-style PTE to low word of PPC-style PTE */
500-
rlwimi r0,r0,32-2,31,31 /* _PAGE_USER -> PP lsb */
501500
ori r1, r1, 0xe06 /* clear out reserved bits */
502501
andc r1, r0, r1 /* PP = user? 1 : 0 */
503502
BEGIN_FTR_SECTION
@@ -565,9 +564,8 @@ DataLoadTLBMiss:
565564
* we would need to update the pte atomically with lwarx/stwcx.
566565
*/
567566
/* Convert linux-style PTE to low word of PPC-style PTE */
568-
rlwinm r1,r0,32-9,30,30 /* _PAGE_RW -> PP msb */
569-
rlwimi r0,r0,32-1,30,30 /* _PAGE_USER -> PP msb */
570-
rlwimi r0,r0,32-1,31,31 /* _PAGE_USER -> PP lsb */
567+
rlwinm r1,r0,0,30,30 /* _PAGE_RW -> PP msb */
568+
rlwimi r0,r0,1,30,30 /* _PAGE_USER -> PP msb */
571569
ori r1,r1,0xe04 /* clear out reserved bits */
572570
andc r1,r0,r1 /* PP = user? rw? 1: 3: 0 */
573571
BEGIN_FTR_SECTION
@@ -645,7 +643,6 @@ DataStoreTLBMiss:
645643
* we would need to update the pte atomically with lwarx/stwcx.
646644
*/
647645
/* Convert linux-style PTE to low word of PPC-style PTE */
648-
rlwimi r0,r0,32-2,31,31 /* _PAGE_USER -> PP lsb */
649646
li r1,0xe06 /* clear out reserved bits & PP msb */
650647
andc r1,r0,r1 /* PP = user? 1: 0 */
651648
BEGIN_FTR_SECTION

arch/powerpc/mm/book3s32/hash_low.S

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mmu_hash_lock:
3535
/*
3636
* Load a PTE into the hash table, if possible.
3737
* The address is in r4, and r3 contains an access flag:
38-
* _PAGE_RW (0x400) if a write.
38+
* _PAGE_RW (0x002) if a write.
3939
* r9 contains the SRR1 value, from which we use the MSR_PR bit.
4040
* SPRG_THREAD contains the physical address of the current task's thread.
4141
*
@@ -69,7 +69,7 @@ _GLOBAL(hash_page)
6969
blt+ 112f /* assume user more likely */
7070
lis r5, (swapper_pg_dir - PAGE_OFFSET)@ha /* if kernel address, use */
7171
addi r5 ,r5 ,(swapper_pg_dir - PAGE_OFFSET)@l /* kernel page table */
72-
rlwimi r3,r9,32-12,29,29 /* MSR_PR -> _PAGE_USER */
72+
rlwimi r3,r9,32-14,31,31 /* MSR_PR -> _PAGE_USER */
7373
112:
7474
#ifndef CONFIG_PTE_64BIT
7575
rlwimi r5,r4,12,20,29 /* insert top 10 bits of address */
@@ -94,7 +94,7 @@ _GLOBAL(hash_page)
9494
#else
9595
rlwimi r8,r4,23,20,28 /* compute pte address */
9696
#endif
97-
rlwinm r0,r3,32-3,24,24 /* _PAGE_RW access -> _PAGE_DIRTY */
97+
rlwinm r0,r3,6,24,24 /* _PAGE_RW access -> _PAGE_DIRTY */
9898
ori r0,r0,_PAGE_ACCESSED|_PAGE_HASHPTE
9999

100100
/*
@@ -310,11 +310,9 @@ Hash_msk = (((1 << Hash_bits) - 1) * 64)
310310

311311
_GLOBAL(create_hpte)
312312
/* Convert linux-style PTE (r5) to low word of PPC-style PTE (r8) */
313-
rlwinm r8,r5,32-9,30,30 /* _PAGE_RW -> PP msb */
314313
rlwinm r0,r5,32-6,30,30 /* _PAGE_DIRTY -> PP msb */
315-
and r8,r8,r0 /* writable if _RW & _DIRTY */
316-
rlwimi r5,r5,32-1,30,30 /* _PAGE_USER -> PP msb */
317-
rlwimi r5,r5,32-2,31,31 /* _PAGE_USER -> PP lsb */
314+
and r8,r5,r0 /* writable if _RW & _DIRTY */
315+
rlwimi r5,r5,1,30,30 /* _PAGE_USER -> PP msb */
318316
ori r8,r8,0xe04 /* clear out reserved bits */
319317
andc r8,r5,r8 /* PP = user? (rw&dirty? 1: 3): 0 */
320318
BEGIN_FTR_SECTION
@@ -566,7 +564,7 @@ _GLOBAL(flush_hash_pages)
566564
33: lwarx r8,0,r5 /* fetch the pte flags word */
567565
andi. r0,r8,_PAGE_HASHPTE
568566
beq 8f /* done if HASHPTE is already clear */
569-
rlwinm r8,r8,0,31,29 /* clear HASHPTE bit */
567+
rlwinm r8,r8,0,~_PAGE_HASHPTE /* clear HASHPTE bit */
570568
stwcx. r8,0,r5 /* update the pte */
571569
bne- 33b
572570

0 commit comments

Comments
 (0)