Re: [PATCH RFC 03/14] xen/grant-table: stop setting PG_private on pages for grant mapping

"Zi Yan" <[email protected]> Sat, 01 Aug 2026 21:24:18 -0400
Newsgroups gmane.linux.kernel,gmane.linux.kernel.mm,gmane.comp.emulators.xen.devel
Message-ID <[email protected]>
On Sat Aug 1, 2026 at 10:42 AM EDT, Usama Arif wrote:
> On Fri, 31 Jul 2026 22:13:26 -0400 Zi Yan <[email protected]> wrote:
>
>> gnttab_alloc_pages() stores xen_page_foreign in allocated page->private.
>
> in allocated page->private "for 32-bit only".

I will remove "allocated" in the sentence. That should cover both 32-bit
and 64-bit cases.

>
>> On 32-bit, a pointer to xen_page_foreign is stored; on 64-bit,
>> xen_page_foreign is stored inline. Checking page->private !=3D NULL is e=
nough
>> to tell whether a xen_page_foreign needs to be freed on 32-bit and
>> page->private is zeroed unconditionally on 64-bit.
>>=20
>> It prepares for a future commit that remove PG_private.
>>=20
>> No funtional change intended.
>>=20
>> Assisted-by: Claude:claude-opus-4-8
>> Assisted-by: Codex:gpt-5
>> Signed-off-by: Zi Yan <[email protected]>
>> To: Juergen Gross <[email protected]>
>> To: Stefano Stabellini <[email protected]>
>> Cc: Oleksandr Tyshchenko <[email protected]>
>> Cc: [email protected]
>> Cc: [email protected]
>> ---
>>  drivers/xen/balloon.c     | 5 +++++
>>  drivers/xen/grant-table.c | 7 +++----
>>  2 files changed, 8 insertions(+), 4 deletions(-)
>>=20
>> diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
>> index e7f1d4ca6d753..7f47b0ad05607 100644
>> --- a/drivers/xen/balloon.c
>> +++ b/drivers/xen/balloon.c
>> @@ -182,6 +182,11 @@ static struct page *balloon_retrieve(bool require_l=
owmem)
>> =20
>>  	__ClearPageOffline(page);
>>  	dec_node_page_state(page, NR_BALLOON_PAGES);
>> +	/*
>> +	 * clear page->private before giving it out, since it might be used to
>> +	 * store xen_page_foreign info.
>> +	 */
>> +	set_page_private(page, 0);
>> =20
>>  	return page;
>>  }
>> diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
>> index 35f879dc5dfb8..cc348ba2e0786 100644
>> --- a/drivers/xen/grant-table.c
>> +++ b/drivers/xen/grant-table.c
>> @@ -875,7 +875,7 @@ int gnttab_pages_set_private(int nr_pages, struct pa=
ge **pages)
>> =20
>>  		set_page_private(pages[i], (unsigned long)foreign);
>>  #endif
>> -		SetPagePrivate(pages[i]);
>> +		/* Data is stored in page->private on 64-bit */
>
> On 64-bit arch you just iterate an empty for loop. Cleaner to put the
> whole for loop in ifdef?

Sure. Will do that.
>
>>  	}
>> =20
>>  	return 0;
>> @@ -1031,12 +1031,11 @@ void gnttab_pages_clear_private(int nr_pages, st=
ruct page **pages)
>>  	int i;
>> =20
>>  	for (i =3D 0; i < nr_pages; i++) {
>> -		if (PagePrivate(pages[i])) {
>>  #if BITS_PER_LONG < 64
>> +		if (page_private(pages[i]))
>>  			kfree((void *)page_private(pages[i]));
>>  #endif
>> -			ClearPagePrivate(pages[i]);
>> -		}
>> +		set_page_private(pages[i], 0);
>>  	}
>>  }
>>  EXPORT_SYMBOL_GPL(gnttab_pages_clear_private);
>>=20
>> --=20
>> 2.53.0
>>=20
>>=20




--=20
Best Regards,
Yan, Zi