Skip to content

Commit 69a1593

Browse files
chleroympe
authored andcommitted
powerpc/32s: Setup the early hash table at all time.
At the time being, an early hash table is set up when CONFIG_KASAN is selected. There is nothing wrong with setting such an early hash table all the time, even if it is not used. This is a statically allocated 256 kB table which lies in the init data section. This makes the code simpler and may in the future allow to setup early IO mappings with fixmap instead of hard coding BATs. Put create_hpte() and flush_hash_pages() in the .ref.text section in order to avoid warning for the reference to early_hash[]. This reference is removed by MMU_init_hw_patch() before init memory is freed. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/b8f8101c368b8a6451844a58d7bd7d83c14cf2aa.1601566529.git.christophe.leroy@csgroup.eu
1 parent 63f9d9d commit 69a1593

4 files changed

Lines changed: 17 additions & 38 deletions

File tree

arch/powerpc/kernel/head_32.S

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ __after_mmu_off:
155155

156156
bl initial_bats
157157
bl load_segment_registers
158-
#ifdef CONFIG_KASAN
158+
BEGIN_MMU_FTR_SECTION
159159
bl early_hash_table
160-
#endif
160+
END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE)
161161
#if defined(CONFIG_BOOTX_TEXT)
162162
bl setup_disp_bat
163163
#endif
@@ -936,7 +936,6 @@ _ENTRY(__restore_cpu_setup)
936936
* Load stuff into the MMU. Intended to be called with
937937
* IR=0 and DR=0.
938938
*/
939-
#ifdef CONFIG_KASAN
940939
early_hash_table:
941940
sync /* Force all PTE updates to finish */
942941
isync
@@ -947,8 +946,10 @@ early_hash_table:
947946
lis r6, early_hash - PAGE_OFFSET@h
948947
ori r6, r6, 3 /* 256kB table */
949948
mtspr SPRN_SDR1, r6
949+
lis r6, early_hash@h
950+
lis r3, Hash@ha
951+
stw r6, Hash@l(r3)
950952
blr
951-
#endif
952953

953954
load_up_mmu:
954955
sync /* Force all PTE updates to finish */
@@ -1037,11 +1038,7 @@ start_here:
10371038
bl machine_init
10381039
bl __save_cpu_setup
10391040
bl MMU_init
1040-
#ifdef CONFIG_KASAN
1041-
BEGIN_MMU_FTR_SECTION
10421041
bl MMU_init_hw_patch
1043-
END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE)
1044-
#endif
10451042

10461043
/*
10471044
* Go back to running unmapped so we can load up new values

arch/powerpc/mm/book3s32/hash_low.S

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <linux/pgtable.h>
18+
#include <linux/init.h>
1819
#include <asm/reg.h>
1920
#include <asm/page.h>
2021
#include <asm/cputable.h>
@@ -284,9 +285,9 @@ _ASM_NOKPROBE_SYMBOL(add_hash_page)
284285
*
285286
* For speed, 4 of the instructions get patched once the size and
286287
* physical address of the hash table are known. These definitions
287-
* of Hash_base and Hash_bits below are just an example.
288+
* of Hash_base and Hash_bits below are for the early hash table.
288289
*/
289-
Hash_base = 0xc0180000
290+
Hash_base = early_hash
290291
Hash_bits = 12 /* e.g. 256kB hash table */
291292
Hash_msk = (((1 << Hash_bits) - 1) * 64)
292293

@@ -307,6 +308,7 @@ Hash_msk = (((1 << Hash_bits) - 1) * 64)
307308
#define HASH_LEFT 31-(LG_PTEG_SIZE+Hash_bits-1)
308309
#define HASH_RIGHT 31-LG_PTEG_SIZE
309310

311+
__REF
310312
_GLOBAL(create_hpte)
311313
/* Convert linux-style PTE (r5) to low word of PPC-style PTE (r8) */
312314
rlwinm r8,r5,32-9,30,30 /* _PAGE_RW -> PP msb */
@@ -473,6 +475,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
473475

474476
sync /* make sure pte updates get to memory */
475477
blr
478+
.previous
476479
_ASM_NOKPROBE_SYMBOL(create_hpte)
477480

478481
.section .bss
@@ -493,6 +496,7 @@ htab_hash_searches:
493496
*
494497
* We assume that there is a hash table in use (Hash != 0).
495498
*/
499+
__REF
496500
_GLOBAL(flush_hash_pages)
497501
/*
498502
* We disable interrupts here, even on UP, because we want
@@ -626,6 +630,7 @@ _GLOBAL(flush_hash_pages)
626630
19: mtmsr r10
627631
isync
628632
blr
633+
.previous
629634
EXPORT_SYMBOL(flush_hash_pages)
630635
_ASM_NOKPROBE_SYMBOL(flush_hash_pages)
631636

arch/powerpc/mm/book3s32/mmu.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
#include <mm/mmu_decl.h>
3333

34+
u8 __initdata early_hash[SZ_256K] __aligned(SZ_256K) = {0};
35+
3436
struct hash_pte *Hash;
3537
static unsigned long Hash_size, Hash_mask;
3638
unsigned long _SDR1;
@@ -395,22 +397,16 @@ void __init MMU_init_hw(void)
395397
hash_mb2 = hash_mb = 32 - LG_HPTEG_SIZE - lg_n_hpteg;
396398
if (lg_n_hpteg > 16)
397399
hash_mb2 = 16 - LG_HPTEG_SIZE;
398-
399-
/*
400-
* When KASAN is selected, there is already an early temporary hash
401-
* table and the switch to the final hash table is done later.
402-
*/
403-
if (IS_ENABLED(CONFIG_KASAN))
404-
return;
405-
406-
MMU_init_hw_patch();
407400
}
408401

409402
void __init MMU_init_hw_patch(void)
410403
{
411404
unsigned int hmask = Hash_mask >> (16 - LG_HPTEG_SIZE);
412405
unsigned int hash = (unsigned int)Hash - PAGE_OFFSET;
413406

407+
if (!mmu_has_feature(MMU_FTR_HPTE_TABLE))
408+
return;
409+
414410
if (ppc_md.progress)
415411
ppc_md.progress("hash:patch", 0x345);
416412
if (ppc_md.progress)

arch/powerpc/mm/kasan/kasan_init_32.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,6 @@ void __init kasan_late_init(void)
174174
kasan_unmap_early_shadow_vmalloc();
175175
}
176176

177-
#ifdef CONFIG_PPC_BOOK3S_32
178-
u8 __initdata early_hash[256 << 10] __aligned(256 << 10) = {0};
179-
180-
static void __init kasan_early_hash_table(void)
181-
{
182-
unsigned int hash = __pa(early_hash);
183-
184-
modify_instruction_site(&patch__hash_page_A0, 0xffff, hash >> 16);
185-
modify_instruction_site(&patch__flush_hash_A0, 0xffff, hash >> 16);
186-
187-
Hash = (struct hash_pte *)early_hash;
188-
}
189-
#else
190-
static void __init kasan_early_hash_table(void) {}
191-
#endif
192-
193177
void __init kasan_early_init(void)
194178
{
195179
unsigned long addr = KASAN_SHADOW_START;
@@ -205,7 +189,4 @@ void __init kasan_early_init(void)
205189
next = pgd_addr_end(addr, end);
206190
pmd_populate_kernel(&init_mm, pmd, kasan_early_shadow_pte);
207191
} while (pmd++, addr = next, addr != end);
208-
209-
if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE))
210-
kasan_early_hash_table();
211192
}

0 commit comments

Comments
 (0)