@@ -273,82 +273,30 @@ static long native_hpte_remove(unsigned long hpte_group)
273273 return i ;
274274}
275275
276- static inline int __hpte_actual_psize (unsigned int lp , int psize )
277- {
278- int i , shift ;
279- unsigned int mask ;
280-
281- /* start from 1 ignoring MMU_PAGE_4K */
282- for (i = 1 ; i < MMU_PAGE_COUNT ; i ++ ) {
283-
284- /* invalid penc */
285- if (mmu_psize_defs [psize ].penc [i ] == -1 )
286- continue ;
287- /*
288- * encoding bits per actual page size
289- * PTE LP actual page size
290- * rrrr rrrz >=8KB
291- * rrrr rrzz >=16KB
292- * rrrr rzzz >=32KB
293- * rrrr zzzz >=64KB
294- * .......
295- */
296- shift = mmu_psize_defs [i ].shift - LP_SHIFT ;
297- if (shift > LP_BITS )
298- shift = LP_BITS ;
299- mask = (1 << shift ) - 1 ;
300- if ((lp & mask ) == mmu_psize_defs [psize ].penc [i ])
301- return i ;
302- }
303- return -1 ;
304- }
305-
306- static inline int hpte_actual_psize (struct hash_pte * hptep , int psize )
307- {
308- /* Look at the 8 bit LP value */
309- unsigned int lp = (hptep -> r >> LP_SHIFT ) & ((1 << LP_BITS ) - 1 );
310-
311- if (!(hptep -> v & HPTE_V_VALID ))
312- return -1 ;
313-
314- /* First check if it is large page */
315- if (!(hptep -> v & HPTE_V_LARGE ))
316- return MMU_PAGE_4K ;
317-
318- return __hpte_actual_psize (lp , psize );
319- }
320-
321276static long native_hpte_updatepp (unsigned long slot , unsigned long newpp ,
322- unsigned long vpn , int psize , int ssize ,
323- int local )
277+ unsigned long vpn , int bpsize ,
278+ int apsize , int ssize , int local )
324279{
325280 struct hash_pte * hptep = htab_address + slot ;
326281 unsigned long hpte_v , want_v ;
327282 int ret = 0 ;
328- int actual_psize ;
329283
330- want_v = hpte_encode_avpn (vpn , psize , ssize );
284+ want_v = hpte_encode_avpn (vpn , bpsize , ssize );
331285
332286 DBG_LOW (" update(vpn=%016lx, avpnv=%016lx, group=%lx, newpp=%lx)" ,
333287 vpn , want_v & HPTE_V_AVPN , slot , newpp );
334288
335289 native_lock_hpte (hptep );
336290
337291 hpte_v = hptep -> v ;
338- actual_psize = hpte_actual_psize (hptep , psize );
339292 /*
340293 * We need to invalidate the TLB always because hpte_remove doesn't do
341294 * a tlb invalidate. If a hash bucket gets full, we "evict" a more/less
342295 * random entry from it. When we do that we don't invalidate the TLB
343296 * (hpte_remove) because we assume the old translation is still
344297 * technically "valid".
345298 */
346- if (actual_psize < 0 ) {
347- actual_psize = psize ;
348- ret = -1 ;
349- goto err_out ;
350- }
351- if (!HPTE_V_COMPARE (hpte_v , want_v )) {
299+ if (!HPTE_V_COMPARE (hpte_v , want_v ) || !(hpte_v & HPTE_V_VALID )) {
352300 DBG_LOW (" -> miss\n" );
353301 ret = -1 ;
354302 } else {
@@ -357,11 +305,10 @@ static long native_hpte_updatepp(unsigned long slot, unsigned long newpp,
357305 hptep -> r = (hptep -> r & ~(HPTE_R_PP | HPTE_R_N )) |
358306 (newpp & (HPTE_R_PP | HPTE_R_N | HPTE_R_C ));
359307 }
360- err_out :
361308 native_unlock_hpte (hptep );
362309
363310 /* Ensure it is out of the tlb too. */
364- tlbie (vpn , psize , actual_psize , ssize , local );
311+ tlbie (vpn , bpsize , apsize , ssize , local );
365312
366313 return ret ;
367314}
@@ -402,7 +349,6 @@ static long native_hpte_find(unsigned long vpn, int psize, int ssize)
402349static void native_hpte_updateboltedpp (unsigned long newpp , unsigned long ea ,
403350 int psize , int ssize )
404351{
405- int actual_psize ;
406352 unsigned long vpn ;
407353 unsigned long vsid ;
408354 long slot ;
@@ -415,60 +361,82 @@ static void native_hpte_updateboltedpp(unsigned long newpp, unsigned long ea,
415361 if (slot == -1 )
416362 panic ("could not find page to bolt\n" );
417363 hptep = htab_address + slot ;
418- actual_psize = hpte_actual_psize (hptep , psize );
419- if (actual_psize < 0 )
420- actual_psize = psize ;
421364
422365 /* Update the HPTE */
423366 hptep -> r = (hptep -> r & ~(HPTE_R_PP | HPTE_R_N )) |
424367 (newpp & (HPTE_R_PP | HPTE_R_N ));
425-
426- /* Ensure it is out of the tlb too. */
427- tlbie (vpn , psize , actual_psize , ssize , 0 );
368+ /*
369+ * Ensure it is out of the tlb too. Bolted entries base and
370+ * actual page size will be same.
371+ */
372+ tlbie (vpn , psize , psize , ssize , 0 );
428373}
429374
430375static void native_hpte_invalidate (unsigned long slot , unsigned long vpn ,
431- int psize , int ssize , int local )
376+ int bpsize , int apsize , int ssize , int local )
432377{
433378 struct hash_pte * hptep = htab_address + slot ;
434379 unsigned long hpte_v ;
435380 unsigned long want_v ;
436381 unsigned long flags ;
437- int actual_psize ;
438382
439383 local_irq_save (flags );
440384
441385 DBG_LOW (" invalidate(vpn=%016lx, hash: %lx)\n" , vpn , slot );
442386
443- want_v = hpte_encode_avpn (vpn , psize , ssize );
387+ want_v = hpte_encode_avpn (vpn , bpsize , ssize );
444388 native_lock_hpte (hptep );
445389 hpte_v = hptep -> v ;
446390
447- actual_psize = hpte_actual_psize (hptep , psize );
448391 /*
449392 * We need to invalidate the TLB always because hpte_remove doesn't do
450393 * a tlb invalidate. If a hash bucket gets full, we "evict" a more/less
451394 * random entry from it. When we do that we don't invalidate the TLB
452395 * (hpte_remove) because we assume the old translation is still
453396 * technically "valid".
454397 */
455- if (actual_psize < 0 ) {
456- actual_psize = psize ;
457- native_unlock_hpte (hptep );
458- goto err_out ;
459- }
460- if (!HPTE_V_COMPARE (hpte_v , want_v ))
398+ if (!HPTE_V_COMPARE (hpte_v , want_v ) || !(hpte_v & HPTE_V_VALID ))
461399 native_unlock_hpte (hptep );
462400 else
463401 /* Invalidate the hpte. NOTE: this also unlocks it */
464402 hptep -> v = 0 ;
465403
466- err_out :
467404 /* Invalidate the TLB */
468- tlbie (vpn , psize , actual_psize , ssize , local );
405+ tlbie (vpn , bpsize , apsize , ssize , local );
406+
469407 local_irq_restore (flags );
470408}
471409
410+ static inline int __hpte_actual_psize (unsigned int lp , int psize )
411+ {
412+ int i , shift ;
413+ unsigned int mask ;
414+
415+ /* start from 1 ignoring MMU_PAGE_4K */
416+ for (i = 1 ; i < MMU_PAGE_COUNT ; i ++ ) {
417+
418+ /* invalid penc */
419+ if (mmu_psize_defs [psize ].penc [i ] == -1 )
420+ continue ;
421+ /*
422+ * encoding bits per actual page size
423+ * PTE LP actual page size
424+ * rrrr rrrz >=8KB
425+ * rrrr rrzz >=16KB
426+ * rrrr rzzz >=32KB
427+ * rrrr zzzz >=64KB
428+ * .......
429+ */
430+ shift = mmu_psize_defs [i ].shift - LP_SHIFT ;
431+ if (shift > LP_BITS )
432+ shift = LP_BITS ;
433+ mask = (1 << shift ) - 1 ;
434+ if ((lp & mask ) == mmu_psize_defs [psize ].penc [i ])
435+ return i ;
436+ }
437+ return -1 ;
438+ }
439+
472440static void hpte_decode (struct hash_pte * hpte , unsigned long slot ,
473441 int * psize , int * apsize , int * ssize , unsigned long * vpn )
474442{
0 commit comments