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 v1 1/3] xen/riscv: implement software page table walking
Date: Wed, 29 Jan 2025 16:34:00 +0100 [thread overview]
Message-ID: <b468ef6e-0745-4962-a555-216406257602@gmail.com> (raw)
In-Reply-To: <47fb2f0f-fb75-4343-8f7c-cf8b27857d67@suse.com>
[-- Attachment #1: Type: text/plain, Size: 5855 bytes --]
On 1/29/25 3:01 PM, Jan Beulich wrote:
> On 29.01.2025 14:12, Oleksii Kurochko wrote:
>> On 1/28/25 9:14 AM, Jan Beulich wrote:
>>> On 27.01.2025 18:22, Oleksii Kurochko wrote:
>>>> On 1/27/25 1:57 PM, Jan Beulich wrote:
>>>>> On 27.01.2025 13:29, Oleksii Kurochko wrote:
>>>>>> On 1/27/25 11:06 AM, Jan Beulich wrote:
>>>>>>> On 20.01.2025 17:54, Oleksii Kurochko wrote:
>>>>>>>> RISC-V doesn't have hardware feature to ask MMU to translate
>>>>>>>> virtual address to physical address ( like Arm has, for example ),
>>>>>>>> so software page table walking in implemented.
>>>>>>>>
>>>>>>>> Signed-off-by: Oleksii Kurochko<oleksii.kurochko@gmail.com>
>>>>>>>> ---
>>>>>>>> xen/arch/riscv/include/asm/mm.h | 2 ++
>>>>>>>> xen/arch/riscv/pt.c | 56 +++++++++++++++++++++++++++++++++
>>>>>>>> 2 files changed, 58 insertions(+)
>>>>>>>>
>>>>>>>> diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/mm.h
>>>>>>>> index 292aa48fc1..d46018c132 100644
>>>>>>>> --- a/xen/arch/riscv/include/asm/mm.h
>>>>>>>> +++ b/xen/arch/riscv/include/asm/mm.h
>>>>>>>> @@ -15,6 +15,8 @@
>>>>>>>>
>>>>>>>> extern vaddr_t directmap_virt_start;
>>>>>>>>
>>>>>>>> +paddr_t pt_walk(vaddr_t va);
>>>>>>> In the longer run, is returning just the PA really going to be sufficient?
>>>>>>> If not, perhaps say a word on the limitation in the description.
>>>>>> In the long run, this function's prototype looks like|paddr_t pt_walk(vaddr_t root, vaddr_t va, bool is_xen)| [1]. However, I'm not sure if it will stay that way,
>>>>>> as I think|is_xen| could be skipped, since using|map_table()| should be sufficient (as it now considers|system_state|) and I'm not really sure if I need root argument
>>>>>> as initial goal was to use this function for debug only purposes and I've never used it for guest page table (stage-1) walking.
>>>>>> Anyway, yes, it is still returning a physical address, and that seems enough to me.
>>>>>>
>>>>>> Could you share your thoughts on what I should take into account for returning value, probably, I am missing something really useful?
>>>>> Often you care about the permissions as well. Sometimes it may even be relevant
>>>>> to know the (super-)page size of the mapping.
>>>> Perhaps it would be better to change the prototype to:
>>>> bool pt_walk(vaddr_t va, mfn_t *ret_pa);
>>>> or even
>>>> void pt_walk(vaddr_t va, mfn_t *ret_pa);
>>>> In this case,|ret_pa = INVALID_MFN| could serve as a signal that|pt_walk()| failed.
>>>> If there's a need to return permissions or (super-)page size in the future, another argument could be added.
>>>>
>>>> What do you think? Would this approach be better?
>>>>
>>>> I am also considering returning a structure containing the|mfn| (or|paddr_t|) and adding other properties (such as permissions or
>>>> page size) as needed in the future. Both solutions seem more or less equivalent.
>>> Imo the most natural thing for a page walking function would be to return the
>>> leaf PTE (or the leaf-most not-present [or otherwise "no-access"] one). That
>>> would provide (almost) all possible information to the caller. "Almost"
>>> because depending on how page walk works, permissions may combine across page
>>> table levels. Yet then (see also the "no-access" above) this would also
>>> require further input, to specify the context for which the translation is
>>> being seeked. For example, the intention to write may want to yield no valid
>>> PTE when there are present ones down to the leaf, but effective permissions
>>> say "read-only".
>> Perhaps returning the leaf PTE could be a really good option.
>>
>> I'm not entirely sure I understand what you mean by "leaf-most not-present". Could you please try to explain this moment one more time?
>> My expectation was that the function should return an existing leaf PTE (from which "access" rights could be determined)
>> or|NULL| to indicate that no leaf PTE was found.
> "no leaf PTE" may be for a variety of reasons. Hence why I think returning
> the PTE at which the walk stopped (leaf or leaf-most not-present) is likely
> best. Such a not-present PTE may, after all, still contain valuable
> information; it's not like it has to be all zero.
Thanks, it is clearer now.
It will complicate a little bit vmap_to_mfn() (as we should to check that pt_walk()
returns a leaf; otherwise something wrong happens), but I think it is not really
critical as you mentioned before, and for convenience it would be better to implement
it as a static inline function:
static inline mfn_t vmap_to_mfn(vaddr_t va)
{
pte_t *entry = pt_walk(va, NULL);
BUG_ON(!pte_is_mapping(*entry));
return mfn_from_pte(*entry);
}
>> Another thing I'm curious about is whether this would be sufficient for determining the level.
>> It seems clear that, given a PTE and a virtual address, we could compute:
>> |mask = VA | paddr_from_pte(pte)|
> What would this value represent? No, from holding a PTE in your hands you
> can't determine the level it came from. So yes, ...
>
>> Then, iterating through each level, we could apply and understand on which one level it was mapped:
>> |mask & (BIT(XEN_PT_LEVEL_ORDER(i), UL) - 1)|.
>>
>> If I haven't overlooked any other way to calculate the page table level, would it be better to simply add another argument
>> to|pt_walk()| to return the level.
> ... for callers who care doing this might then be necessary (this would be
> a pointer parameter, and since I expect many callers wouldn't care about
> the level, it likely wants to be permissible to pass in NULL).
>
> Question then is whether it's better to hand back the level or the page
> order of the mapping. On x86 we return the latter from P2M lookups, for
> example.
Actually, I think for proper calculation of order in pt_update().
Thanks.
~ Oleksii
[-- Attachment #2: Type: text/html, Size: 7590 bytes --]
next prev parent reply other threads:[~2025-01-29 15:34 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-20 16:54 [PATCH for 4.20? v1 0/3] Fixes for vmap_to_mfn() and pt_mapping_level Oleksii Kurochko
2025-01-20 16:54 ` [PATCH v1 1/3] xen/riscv: implement software page table walking Oleksii Kurochko
2025-01-27 10:06 ` Jan Beulich
2025-01-27 12:29 ` Oleksii Kurochko
2025-01-27 12:57 ` Jan Beulich
2025-01-27 17:22 ` Oleksii Kurochko
2025-01-27 17:41 ` Oleksii Kurochko
2025-01-28 8:07 ` Jan Beulich
2025-01-28 8:14 ` Jan Beulich
2025-01-29 13:12 ` Oleksii Kurochko
2025-01-29 14:01 ` Jan Beulich
2025-01-29 15:34 ` Oleksii Kurochko [this message]
2025-01-20 16:54 ` [PATCH v1 2/3] xen/riscv: update defintion of vmap_to_mfn() Oleksii Kurochko
2025-01-27 10:09 ` Jan Beulich
2025-01-27 12:32 ` Oleksii Kurochko
2025-01-20 16:54 ` [PATCH v1 3/3] xen/riscv: update mfn calculation in pt_mapping_level() Oleksii Kurochko
2025-01-27 10:24 ` Jan Beulich
2025-01-27 12:51 ` 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=b468ef6e-0745-4962-a555-216406257602@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.