Skip to content

Commit 7025776

Browse files
ozbenhmpe
authored andcommitted
powerpc/mm: Move hash table ops to a separate structure
Moving probe_machine() to after mmu init will cause the ppc_md fields relative to the hash table management to be overwritten. Since we have essentially disconnected the machine type from the hash backend ops, finish the job by moving them to a different structure. The only callback that didn't quite fix is update_partition_table since this is not specific to hash, so I moved it to a standalone variable for now. We can revisit later if needed. Signed-off-by: Benjamin Herrenschmidt <[email protected]> [mpe: Fix ppc64e build failure in kexec] Signed-off-by: Michael Ellerman <[email protected]>
1 parent b521f57 commit 7025776

13 files changed

+151
-128
lines changed

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

+39
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,45 @@
124124

125125
#ifndef __ASSEMBLY__
126126

127+
struct mmu_hash_ops {
128+
void (*hpte_invalidate)(unsigned long slot,
129+
unsigned long vpn,
130+
int bpsize, int apsize,
131+
int ssize, int local);
132+
long (*hpte_updatepp)(unsigned long slot,
133+
unsigned long newpp,
134+
unsigned long vpn,
135+
int bpsize, int apsize,
136+
int ssize, unsigned long flags);
137+
void (*hpte_updateboltedpp)(unsigned long newpp,
138+
unsigned long ea,
139+
int psize, int ssize);
140+
long (*hpte_insert)(unsigned long hpte_group,
141+
unsigned long vpn,
142+
unsigned long prpn,
143+
unsigned long rflags,
144+
unsigned long vflags,
145+
int psize, int apsize,
146+
int ssize);
147+
long (*hpte_remove)(unsigned long hpte_group);
148+
int (*hpte_removebolted)(unsigned long ea,
149+
int psize, int ssize);
150+
void (*flush_hash_range)(unsigned long number, int local);
151+
void (*hugepage_invalidate)(unsigned long vsid,
152+
unsigned long addr,
153+
unsigned char *hpte_slot_array,
154+
int psize, int ssize, int local);
155+
/*
156+
* Special for kexec.
157+
* To be called in real mode with interrupts disabled. No locks are
158+
* taken as such, concurrent access on pre POWER5 hardware could result
159+
* in a deadlock.
160+
* The linear mapping is destroyed as well.
161+
*/
162+
void (*hpte_clear_all)(void);
163+
};
164+
extern struct mmu_hash_ops mmu_hash_ops;
165+
127166
struct hash_pte {
128167
__be64 v;
129168
__be64 r;

arch/powerpc/include/asm/machdep.h

-36
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,6 @@ struct pci_host_bridge;
3434
struct machdep_calls {
3535
char *name;
3636
#ifdef CONFIG_PPC64
37-
void (*hpte_invalidate)(unsigned long slot,
38-
unsigned long vpn,
39-
int bpsize, int apsize,
40-
int ssize, int local);
41-
long (*hpte_updatepp)(unsigned long slot,
42-
unsigned long newpp,
43-
unsigned long vpn,
44-
int bpsize, int apsize,
45-
int ssize, unsigned long flags);
46-
void (*hpte_updateboltedpp)(unsigned long newpp,
47-
unsigned long ea,
48-
int psize, int ssize);
49-
long (*hpte_insert)(unsigned long hpte_group,
50-
unsigned long vpn,
51-
unsigned long prpn,
52-
unsigned long rflags,
53-
unsigned long vflags,
54-
int psize, int apsize,
55-
int ssize);
56-
long (*hpte_remove)(unsigned long hpte_group);
57-
int (*hpte_removebolted)(unsigned long ea,
58-
int psize, int ssize);
59-
void (*flush_hash_range)(unsigned long number, int local);
60-
void (*hugepage_invalidate)(unsigned long vsid,
61-
unsigned long addr,
62-
unsigned char *hpte_slot_array,
63-
int psize, int ssize, int local);
64-
/*
65-
* Special for kexec.
66-
* To be called in real mode with interrupts disabled. No locks are
67-
* taken as such, concurrent access on pre POWER5 hardware could result
68-
* in a deadlock.
69-
* The linear mapping is destroyed as well.
70-
*/
71-
void (*hpte_clear_all)(void);
72-
7337
void __iomem * (*ioremap)(phys_addr_t addr, unsigned long size,
7438
unsigned long flags, void *caller);
7539
void (*iounmap)(volatile void __iomem *token);

arch/powerpc/kernel/machine_kexec_64.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int default_machine_kexec_prepare(struct kimage *image)
5555
const unsigned long *basep;
5656
const unsigned int *sizep;
5757

58-
if (!ppc_md.hpte_clear_all)
58+
if (!mmu_hash_ops.hpte_clear_all)
5959
return -ENOENT;
6060

6161
/*
@@ -380,7 +380,12 @@ void default_machine_kexec(struct kimage *image)
380380
*/
381381
kexec_sequence(&kexec_stack, image->start, image,
382382
page_address(image->control_code_page),
383-
ppc_md.hpte_clear_all);
383+
#ifdef CONFIG_PPC_STD_MMU
384+
mmu_hash_ops.hpte_clear_all
385+
#else
386+
NULL
387+
#endif
388+
);
384389
/* NOTREACHED */
385390
}
386391

arch/powerpc/kernel/misc_64.S

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ _GLOBAL(kexec_sequence)
667667
mr r12,r27
668668
#endif
669669
mtctr r12
670-
bctrl /* ppc_md.hpte_clear_all(void); */
670+
bctrl /* mmu_hash_ops.hpte_clear_all(void); */
671671
#endif /* !CONFIG_PPC_BOOK3E */
672672

673673
/*

arch/powerpc/kvm/book3s_64_mmu_host.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434

3535
void kvmppc_mmu_invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte)
3636
{
37-
ppc_md.hpte_invalidate(pte->slot, pte->host_vpn,
38-
pte->pagesize, pte->pagesize, MMU_SEGSIZE_256M,
39-
false);
37+
mmu_hash_ops.hpte_invalidate(pte->slot, pte->host_vpn,
38+
pte->pagesize, pte->pagesize,
39+
MMU_SEGSIZE_256M, false);
4040
}
4141

4242
/* We keep 512 gvsid->hvsid entries, mapping the guest ones to the array using
@@ -169,13 +169,13 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte,
169169

170170
/* In case we tried normal mapping already, let's nuke old entries */
171171
if (attempt > 1)
172-
if (ppc_md.hpte_remove(hpteg) < 0) {
172+
if (mmu_hash_ops.hpte_remove(hpteg) < 0) {
173173
r = -1;
174174
goto out_unlock;
175175
}
176176

177-
ret = ppc_md.hpte_insert(hpteg, vpn, hpaddr, rflags, vflags,
178-
hpsize, hpsize, MMU_SEGSIZE_256M);
177+
ret = mmu_hash_ops.hpte_insert(hpteg, vpn, hpaddr, rflags, vflags,
178+
hpsize, hpsize, MMU_SEGSIZE_256M);
179179

180180
if (ret < 0) {
181181
/* If we couldn't map a primary PTE, try a secondary */
@@ -187,8 +187,10 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte,
187187
trace_kvm_book3s_64_mmu_map(rflags, hpteg,
188188
vpn, hpaddr, orig_pte);
189189

190-
/* The ppc_md code may give us a secondary entry even though we
191-
asked for a primary. Fix up. */
190+
/*
191+
* The mmu_hash_ops code may give us a secondary entry even
192+
* though we asked for a primary. Fix up.
193+
*/
192194
if ((ret & _PTEIDX_SECONDARY) && !(vflags & HPTE_V_SECONDARY)) {
193195
hash = ~hash;
194196
hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);

arch/powerpc/mm/hash64_4k.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
7070
slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
7171
slot += (old_pte & H_PAGE_F_GIX) >> H_PAGE_F_GIX_SHIFT;
7272

73-
if (ppc_md.hpte_updatepp(slot, rflags, vpn, MMU_PAGE_4K,
74-
MMU_PAGE_4K, ssize, flags) == -1)
73+
if (mmu_hash_ops.hpte_updatepp(slot, rflags, vpn, MMU_PAGE_4K,
74+
MMU_PAGE_4K, ssize, flags) == -1)
7575
old_pte &= ~_PAGE_HPTEFLAGS;
7676
}
7777

@@ -84,21 +84,23 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
8484
hpte_group = ((hash & htab_hash_mask) * HPTES_PER_GROUP) & ~0x7UL;
8585

8686
/* Insert into the hash table, primary slot */
87-
slot = ppc_md.hpte_insert(hpte_group, vpn, pa, rflags, 0,
88-
MMU_PAGE_4K, MMU_PAGE_4K, ssize);
87+
slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa, rflags, 0,
88+
MMU_PAGE_4K, MMU_PAGE_4K, ssize);
8989
/*
9090
* Primary is full, try the secondary
9191
*/
9292
if (unlikely(slot == -1)) {
9393
hpte_group = ((~hash & htab_hash_mask) * HPTES_PER_GROUP) & ~0x7UL;
94-
slot = ppc_md.hpte_insert(hpte_group, vpn, pa,
95-
rflags, HPTE_V_SECONDARY,
96-
MMU_PAGE_4K, MMU_PAGE_4K, ssize);
94+
slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa,
95+
rflags,
96+
HPTE_V_SECONDARY,
97+
MMU_PAGE_4K,
98+
MMU_PAGE_4K, ssize);
9799
if (slot == -1) {
98100
if (mftb() & 0x1)
99101
hpte_group = ((hash & htab_hash_mask) *
100102
HPTES_PER_GROUP) & ~0x7UL;
101-
ppc_md.hpte_remove(hpte_group);
103+
mmu_hash_ops.hpte_remove(hpte_group);
102104
/*
103105
* FIXME!! Should be try the group from which we removed ?
104106
*/

arch/powerpc/mm/hash64_64k.c

+22-17
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
133133
slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
134134
slot += hidx & _PTEIDX_GROUP_IX;
135135

136-
ret = ppc_md.hpte_updatepp(slot, rflags, vpn,
137-
MMU_PAGE_4K, MMU_PAGE_4K,
138-
ssize, flags);
136+
ret = mmu_hash_ops.hpte_updatepp(slot, rflags, vpn,
137+
MMU_PAGE_4K, MMU_PAGE_4K,
138+
ssize, flags);
139139
/*
140140
*if we failed because typically the HPTE wasn't really here
141141
* we try an insertion.
@@ -166,21 +166,22 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
166166
hpte_group = ((hash & htab_hash_mask) * HPTES_PER_GROUP) & ~0x7UL;
167167

168168
/* Insert into the hash table, primary slot */
169-
slot = ppc_md.hpte_insert(hpte_group, vpn, pa, rflags, 0,
170-
MMU_PAGE_4K, MMU_PAGE_4K, ssize);
169+
slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa, rflags, 0,
170+
MMU_PAGE_4K, MMU_PAGE_4K, ssize);
171171
/*
172172
* Primary is full, try the secondary
173173
*/
174174
if (unlikely(slot == -1)) {
175175
hpte_group = ((~hash & htab_hash_mask) * HPTES_PER_GROUP) & ~0x7UL;
176-
slot = ppc_md.hpte_insert(hpte_group, vpn, pa,
177-
rflags, HPTE_V_SECONDARY,
178-
MMU_PAGE_4K, MMU_PAGE_4K, ssize);
176+
slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa,
177+
rflags, HPTE_V_SECONDARY,
178+
MMU_PAGE_4K, MMU_PAGE_4K,
179+
ssize);
179180
if (slot == -1) {
180181
if (mftb() & 0x1)
181182
hpte_group = ((hash & htab_hash_mask) *
182183
HPTES_PER_GROUP) & ~0x7UL;
183-
ppc_md.hpte_remove(hpte_group);
184+
mmu_hash_ops.hpte_remove(hpte_group);
184185
/*
185186
* FIXME!! Should be try the group from which we removed ?
186187
*/
@@ -272,8 +273,9 @@ int __hash_page_64K(unsigned long ea, unsigned long access,
272273
slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
273274
slot += (old_pte & H_PAGE_F_GIX) >> H_PAGE_F_GIX_SHIFT;
274275

275-
if (ppc_md.hpte_updatepp(slot, rflags, vpn, MMU_PAGE_64K,
276-
MMU_PAGE_64K, ssize, flags) == -1)
276+
if (mmu_hash_ops.hpte_updatepp(slot, rflags, vpn, MMU_PAGE_64K,
277+
MMU_PAGE_64K, ssize,
278+
flags) == -1)
277279
old_pte &= ~_PAGE_HPTEFLAGS;
278280
}
279281

@@ -286,21 +288,24 @@ int __hash_page_64K(unsigned long ea, unsigned long access,
286288
hpte_group = ((hash & htab_hash_mask) * HPTES_PER_GROUP) & ~0x7UL;
287289

288290
/* Insert into the hash table, primary slot */
289-
slot = ppc_md.hpte_insert(hpte_group, vpn, pa, rflags, 0,
290-
MMU_PAGE_64K, MMU_PAGE_64K, ssize);
291+
slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa, rflags, 0,
292+
MMU_PAGE_64K, MMU_PAGE_64K,
293+
ssize);
291294
/*
292295
* Primary is full, try the secondary
293296
*/
294297
if (unlikely(slot == -1)) {
295298
hpte_group = ((~hash & htab_hash_mask) * HPTES_PER_GROUP) & ~0x7UL;
296-
slot = ppc_md.hpte_insert(hpte_group, vpn, pa,
297-
rflags, HPTE_V_SECONDARY,
298-
MMU_PAGE_64K, MMU_PAGE_64K, ssize);
299+
slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa,
300+
rflags,
301+
HPTE_V_SECONDARY,
302+
MMU_PAGE_64K,
303+
MMU_PAGE_64K, ssize);
299304
if (slot == -1) {
300305
if (mftb() & 0x1)
301306
hpte_group = ((hash & htab_hash_mask) *
302307
HPTES_PER_GROUP) & ~0x7UL;
303-
ppc_md.hpte_remove(hpte_group);
308+
mmu_hash_ops.hpte_remove(hpte_group);
304309
/*
305310
* FIXME!! Should be try the group from which we removed ?
306311
*/

arch/powerpc/mm/hash_native_64.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -739,14 +739,14 @@ static int native_register_proc_table(unsigned long base, unsigned long page_siz
739739

740740
void __init hpte_init_native(void)
741741
{
742-
ppc_md.hpte_invalidate = native_hpte_invalidate;
743-
ppc_md.hpte_updatepp = native_hpte_updatepp;
744-
ppc_md.hpte_updateboltedpp = native_hpte_updateboltedpp;
745-
ppc_md.hpte_insert = native_hpte_insert;
746-
ppc_md.hpte_remove = native_hpte_remove;
747-
ppc_md.hpte_clear_all = native_hpte_clear;
748-
ppc_md.flush_hash_range = native_flush_hash_range;
749-
ppc_md.hugepage_invalidate = native_hugepage_invalidate;
742+
mmu_hash_ops.hpte_invalidate = native_hpte_invalidate;
743+
mmu_hash_ops.hpte_updatepp = native_hpte_updatepp;
744+
mmu_hash_ops.hpte_updateboltedpp = native_hpte_updateboltedpp;
745+
mmu_hash_ops.hpte_insert = native_hpte_insert;
746+
mmu_hash_ops.hpte_remove = native_hpte_remove;
747+
mmu_hash_ops.hpte_clear_all = native_hpte_clear;
748+
mmu_hash_ops.flush_hash_range = native_flush_hash_range;
749+
mmu_hash_ops.hugepage_invalidate = native_hugepage_invalidate;
750750

751751
if (cpu_has_feature(CPU_FTR_ARCH_300))
752752
ppc_md.register_process_table = native_register_proc_table;

0 commit comments

Comments
 (0)