From: Oleksii Kurochko <oleksii.kurochko@gmail.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Alistair Francis" <alistair.francis@wdc.com>,
"Bob Eshleman" <bobbyeshleman@gmail.com>,
"Connor Davis" <connojdavis@gmail.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Julien Grall" <julien@xen.org>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v3 13/20] xen/riscv: Implement p2m_free_subtree() and related helpers
Date: Mon, 18 Aug 2025 10:22:29 +0200 [thread overview]
Message-ID: <3fc9f081-e358-4972-a39b-fab0494433c4@gmail.com> (raw)
In-Reply-To: <117e35e0-d23e-4527-964a-82fa2bed57fd@suse.com>
[-- Attachment #1: Type: text/plain, Size: 4421 bytes --]
On 8/14/25 5:17 PM, Jan Beulich wrote:
> On 14.08.2025 17:09, Oleksii Kurochko wrote:
>> On 8/6/25 5:55 PM, Jan Beulich wrote:
>>> On 31.07.2025 17:58, Oleksii Kurochko wrote:
>>>> +/* Put any references on the page referenced by pte. */
>>>> +static void p2m_put_page(const pte_t pte, unsigned int level)
>>>> +{
>>>> + mfn_t mfn = pte_get_mfn(pte);
>>>> + p2m_type_t p2m_type = p2m_get_type(pte);
>>>> +
>>>> + ASSERT(pte_is_valid(pte));
>>>> +
>>>> + /*
>>>> + * TODO: Currently we don't handle level 2 super-page, Xen is not
>>>> + * preemptible and therefore some work is needed to handle such
>>>> + * superpages, for which at some point Xen might end up freeing memory
>>>> + * and therefore for such a big mapping it could end up in a very long
>>>> + * operation.
>>>> + */
>>>> + switch ( level )
>>>> + {
>>>> + case 1:
>>>> + return p2m_put_2m_superpage(mfn, p2m_type);
>>>> +
>>>> + case 0:
>>>> + return p2m_put_4k_page(mfn, p2m_type);
>>>> + }
>>> Yet despite the comment not even an assertion for level 2 and up?
>> Not sure that an ASSERT() is needed here as a reference(s) for such page(s)
>> will be put during domain_relinquish_resources() as there we could do preemption.
>> Something like Arm does here:
>> https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/arm/mmu/p2m.c?ref_type=heads#L1587
>>
>> I'm thinking that probably it makes sense to put only 4k page(s) and
>> all other cases postpone until domain_relinquish_resources() is called.
> How can you defer to domain cleanup? How would handling of foreign mappings
> (or e.g. ballooning? not sure) work when you don't drop references as
> necessary?
I was confused by the code in|relinquish_p2m_mapping()|, since it removes
foreign mappings from the P2M. My current understanding is that it is called
for foreign mappings that weren’t explicitly unmapped, in order to drop the
page reference taken when the mapping was created. Initially, I thought it
would be enough to just perform the (un)map in the P2M page tables to have
foreign mapping working, but that could result in a page never being fully
released, which would in turn break or confuse other logic.
So, yes, I agree that your initial suggestion to add ASSERT() is useful to
be sure that no one is using level 2 super-pages for foreign mapping.
>>>> /* Free pte sub-tree behind an entry */
>>>> static void p2m_free_subtree(struct p2m_domain *p2m,
>>>> pte_t entry, unsigned int level)
>>>> {
>>>> - panic("%s: hasn't been implemented yet\n", __func__);
>>>> + unsigned int i;
>>>> + pte_t *table;
>>>> + mfn_t mfn;
>>>> + struct page_info *pg;
>>>> +
>>>> + /* Nothing to do if the entry is invalid. */
>>>> + if ( !pte_is_valid(entry) )
>>>> + return;
>>>> +
>>>> + if ( pte_is_superpage(entry, level) || (level == 0) )
>>> Perhaps swap the two conditions around?
>>>
>>>> + {
>>>> +#ifdef CONFIG_IOREQ_SERVER
>>>> + /*
>>>> + * If this gets called then either the entry was replaced by an entry
>>>> + * with a different base (valid case) or the shattering of a superpage
>>>> + * has failed (error case).
>>>> + * So, at worst, the spurious mapcache invalidation might be sent.
>>>> + */
>>>> + if ( p2m_is_ram(p2m_get_type(p2m, entry)) &&
>>>> + domain_has_ioreq_server(p2m->domain) )
>>>> + ioreq_request_mapcache_invalidate(p2m->domain);
>>>> +#endif
>>>> +
>>>> + p2m_put_page(entry, level);
>>>> +
>>>> + return;
>>>> + }
>>>> +
>>>> + table = map_domain_page(pte_get_mfn(entry));
>>>> + for ( i = 0; i < XEN_PT_ENTRIES; i++ )
>>>> + p2m_free_subtree(p2m, table[i], level - 1);
>>> In p2m_put_page() you comment towards concerns for level >= 2; no similar
>>> concerns for the resulting recursion here?
>> This function is generic enough to handle any level.
>>
>> Except that it is possible that it will be needed, for example, to split 1G mapping
>> into something smaller then p2m_free_subtree() could be called for freeing a subtree
>> of 1gb mapping.
> The question wasn't about it being generic enough, but it possibly taking
> too much time for level >= 2.
In this terms it makes sense to add such an assertion which will check that we are
working with levels <= 2.
Thanks.
~ Oleksii
[-- Attachment #2: Type: text/html, Size: 5797 bytes --]
next prev parent reply other threads:[~2025-08-18 8:22 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-31 15:57 [PATCH v3 00/20] xen/riscv: introduce p2m functionality Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 01/20] xen/riscv: implement sbi_remote_hfence_gvma() Oleksii Kurochko
2025-08-04 13:52 ` Jan Beulich
2025-08-05 14:45 ` Oleksii Kurochko
2025-08-05 15:01 ` Jan Beulich
2025-07-31 15:58 ` [PATCH v3 02/20] xen/riscv: introduce sbi_remote_hfence_gvma_vmid() Oleksii Kurochko
2025-08-04 13:55 ` Jan Beulich
2025-08-05 14:57 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 03/20] xen/riscv: introduce VMID allocation and manegement Oleksii Kurochko
2025-08-04 15:19 ` Jan Beulich
2025-08-06 11:33 ` Oleksii Kurochko
2025-08-06 12:05 ` Jan Beulich
2025-08-06 16:24 ` Oleksii Kurochko
2025-08-06 16:50 ` Demi Marie Obenour
2025-08-07 8:43 ` Oleksii Kurochko
2025-08-07 10:11 ` Jan Beulich
2025-08-07 14:45 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 04/20] xen/riscv: introduce things necessary for p2m initialization Oleksii Kurochko
2025-08-04 15:53 ` Jan Beulich
2025-08-06 11:43 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 05/20] xen/riscv: construct the P2M pages pool for guests Oleksii Kurochko
2025-08-04 15:58 ` Jan Beulich
2025-08-05 10:40 ` Jan Beulich
2025-08-06 12:01 ` Oleksii Kurochko
2025-08-06 12:07 ` Jan Beulich
2025-07-31 15:58 ` [PATCH v3 06/20] xen/riscv: add root page table allocation Oleksii Kurochko
2025-08-05 10:37 ` Jan Beulich
2025-08-07 12:00 ` Oleksii Kurochko
2025-08-07 15:30 ` Jan Beulich
2025-08-07 15:59 ` Oleksii Kurochko
2025-08-07 16:03 ` Jan Beulich
2025-08-05 10:43 ` Jan Beulich
2025-08-07 13:35 ` Oleksii Kurochko
2025-08-07 15:57 ` Jan Beulich
2025-08-08 9:14 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 07/20] xen/riscv: introduce pte_{set,get}_mfn() Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 08/20] xen/riscv: add new p2m types and helper macros for type classification Oleksii Kurochko
2025-08-04 14:16 ` Jan Beulich
2025-08-07 15:41 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 09/20] xen/dom0less: abstract Arm-specific p2m type name for device MMIO mappings Oleksii Kurochko
2025-08-04 14:11 ` Jan Beulich
2025-08-07 15:23 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 10/20] xen/riscv: introduce page_{get,set}_xenheap_gfn() Oleksii Kurochko
2025-08-05 14:11 ` Jan Beulich
2025-08-08 9:16 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 11/20] xen/riscv: implement function to map memory in guest p2m Oleksii Kurochko
2025-08-05 15:20 ` Jan Beulich
2025-08-08 13:46 ` Oleksii Kurochko
2025-08-11 7:28 ` Jan Beulich
2025-08-11 9:29 ` Oleksii Kurochko
2025-08-11 9:35 ` Jan Beulich
2025-07-31 15:58 ` [PATCH v3 12/20] xen/riscv: implement p2m_set_range() Oleksii Kurochko
2025-08-05 16:04 ` Jan Beulich
2025-08-15 9:52 ` Oleksii Kurochko
2025-08-15 12:50 ` Jan Beulich
2025-08-18 11:03 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 13/20] xen/riscv: Implement p2m_free_subtree() and related helpers Oleksii Kurochko
2025-08-06 15:55 ` Jan Beulich
2025-08-14 15:09 ` Oleksii Kurochko
2025-08-14 15:17 ` Jan Beulich
2025-08-18 8:22 ` Oleksii Kurochko [this message]
2025-07-31 15:58 ` [PATCH v3 14/20] xen/riscv: Implement p2m_pte_from_mfn() and support PBMT configuration Oleksii Kurochko
2025-08-11 11:36 ` Jan Beulich
2025-08-11 14:44 ` Oleksii Kurochko
2025-08-11 15:11 ` Jan Beulich
2025-07-31 15:58 ` [PATCH v3 15/20] xen/riscv: implement p2m_next_level() Oleksii Kurochko
2025-08-11 11:44 ` Jan Beulich
2025-07-31 15:58 ` [PATCH v3 16/20] xen/riscv: Implement superpage splitting for p2m mappings Oleksii Kurochko
2025-08-11 11:59 ` Jan Beulich
2025-08-11 15:19 ` Oleksii Kurochko
2025-08-11 15:47 ` Jan Beulich
2025-07-31 15:58 ` [PATCH v3 17/20] xen/riscv: implement put_page() Oleksii Kurochko
2025-08-11 12:43 ` Jan Beulich
2025-08-11 15:32 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 18/20] xen/riscv: implement mfn_valid() and page reference, ownership handling helpers Oleksii Kurochko
2025-08-11 12:50 ` Jan Beulich
2025-08-11 15:34 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 19/20] xen/riscv: add support of page lookup by GFN Oleksii Kurochko
2025-08-11 13:25 ` Jan Beulich
2025-08-12 11:42 ` Oleksii Kurochko
2025-08-22 8:39 ` Oleksii Kurochko
2025-07-31 15:58 ` [PATCH v3 20/20] xen/riscv: introduce metadata table to store P2M type Oleksii Kurochko
2025-08-11 15:44 ` Jan Beulich
2025-08-12 14:52 ` Oleksii Kurochko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3fc9f081-e358-4972-a39b-fab0494433c4@gmail.com \
--to=oleksii.kurochko@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=bobbyeshleman@gmail.com \
--cc=connojdavis@gmail.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.