[RFC PATCH 19/34] x86: power: use proper set_pXd() for generic compile-time folded patable in resume_one_md_table_init()

Dave Hansen dave.hansen at intel.com
Mon Jul 13 07:38:11 PDT 2026


On 7/13/26 06:55, Yeoreum Yun wrote:
> @@ -134,11 +129,12 @@ static inline void resume_init_first_level_page_table(pgd_t *pg_dir)
>  {
>  #ifdef CONFIG_X86_PAE
>  	int i;
> +	pud_t *pud = pud_offset(p4d_offset(pg_dir, 0), 0);
>  
>  	/* Init entries of the first-level page table to the zero page */
>  	for (i = 0; i < PTRS_PER_PGD; i++)
> -		set_pgd(pg_dir + i,
> -			__pgd(__pa(empty_zero_page) | _PAGE_PRESENT));
> +		set_pud(pud + i,
> +			__pud(__pa(empty_zero_page) | _PAGE_PRESENT));
>  #endif
>  }

If this is the way forward, it's going to require the retraining of some
awfully old brain cells.

It also doesn't really read correctly. Loop over each PGD entry:

	for (i = 0; i < PTRS_PER_PGD; i++)

... and set a pud?

		set_pud(...)

I'm not sure how I'd ever learn the rules to write this code from
scratch. Right now, the code says: "The pgd_t is the top level of the
page tables. I know there are PTRS_PER_PGD of those top level entries
entries I need to 'zero'."

You don't have to know what is folded, just that you're dealing with the
top level.

But *this* code says:

1. The pgd_t is the top level of the page tables. Start there.
2. "Walk" down *two* (folded) levels
3. Set the third-level (pud) entries to 'zero'

So the code now *has* to know how the folding occurs.

This seems really hard to work with to me.



More information about the kvm-riscv mailing list