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 v6 11/19] xen/riscv: implement p2m_set_range()
Date: Tue, 9 Dec 2025 12:47:26 +0100 [thread overview]
Message-ID: <021bdde7-ea62-447f-a788-dc31c6a930bd@gmail.com> (raw)
In-Reply-To: <8b95ccca-7924-4cf8-818a-094782c6bbea@suse.com>
On 12/8/25 5:52 PM, Jan Beulich wrote:
> On 24.11.2025 13:33, Oleksii Kurochko wrote:
>> @@ -28,6 +36,77 @@ unsigned char get_max_supported_mode(void)
>> return max_gstage_mode.mode;
>> }
>>
>> +static inline unsigned int calc_offset(const struct p2m_domain *p2m,
>> + const unsigned int lvl,
>> + const paddr_t gpa)
>> +{
>> + unsigned int off = (gpa >> P2M_GFN_LEVEL_SHIFT(lvl)) &
>> + P2M_TABLE_OFFSET(p2m, lvl);
>> +
>> + /*
>> + * For P2M_ROOT_LEVEL, `offset` ranges from 0 to 2047, since the root
>> + * page table spans 4 consecutive 4KB pages.
>> + * We want to return an index within one of these 4 pages.
>> + * The specific page to use is determined by `p2m_get_root_pointer()`.
>> + *
>> + * Example: if `offset == 512`:
>> + * - A single 4KB page holds 512 entries.
>> + * - Therefore, entry 512 corresponds to index 0 of the second page.
>> + *
>> + * At all other levels, only one page is allocated, and `offset` is
>> + * always in the range 0 to 511, since the VPN is 9 bits long.
>> + */
>> + return off & (PAGETABLE_ENTRIES - 1);
>> +}
>> +
>> +#define P2M_MAX_ROOT_LEVEL 5
>> +
>> +#define P2M_BUILD_LEVEL_OFFSETS(p2m, var, addr) \
>> + unsigned int var[P2M_MAX_ROOT_LEVEL] = {-1}; \
> What use is this initializer? Slot 0 ...
I wanted a way to detect if something mistakenly tries to access an uninitialized
array element, and using -1 would help distinguish whether an element was truly
uninitialized or if calc_offset() simply returned 0. However, you’re right, it
doesn’t work because only Slot 0 is initialized with -1. So...
>
>> + BUG_ON(P2M_ROOT_LEVEL(p2m) >= P2M_MAX_ROOT_LEVEL); \
>> + for ( unsigned int i = 0; i <= P2M_ROOT_LEVEL(p2m); i++ ) \
>> + var[i] = calc_offset(p2m, i, addr);
> ... is guaranteed to be written to, afaics. With this simplified (or an
> explanation given for why it is needed)
... I will just drop an initializer and let var[] to be initialized with 0s.
> Acked-by: Jan Beulich <jbeulich@suse.com>
Thanks.
~ Oleksii
next prev parent reply other threads:[~2025-12-09 11:47 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-24 12:33 [PATCH v6 00/19] xen/riscv: introduce p2m functionality Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 01/19] xen/riscv: avoid redundant HGATP*_MODE_SHIFT and HGATP*_VMID_SHIFT Oleksii Kurochko
2025-12-08 16:13 ` Jan Beulich
2025-11-24 12:33 ` [PATCH v6 02/19] xen/riscv: detect and initialize G-stage mode Oleksii Kurochko
2025-12-08 16:22 ` Jan Beulich
2025-12-09 9:54 ` Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 03/19] xen/riscv: introduce VMID allocation and manegement Oleksii Kurochko
2025-12-08 16:31 ` Jan Beulich
2025-12-09 10:35 ` Oleksii Kurochko
2025-12-09 10:52 ` Jan Beulich
2025-12-08 17:28 ` Teddy Astie
2025-12-09 7:51 ` Jan Beulich
2025-12-09 10:40 ` Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 04/19] xen/riscv: introduce things necessary for p2m initialization Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 05/19] xen/riscv: construct the P2M pages pool for guests Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 06/19] xen/riscv: add root page table allocation Oleksii Kurochko
2025-12-08 16:40 ` Jan Beulich
2025-11-24 12:33 ` [PATCH v6 07/19] xen/riscv: introduce pte_{set,get}_mfn() Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 08/19] xen/riscv: add new p2m types and helper macros for type classification Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 09/19] xen/dom0less: abstract Arm-specific p2m type name for device MMIO mappings Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 10/19] xen/riscv: implement function to map memory in guest p2m Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 11/19] xen/riscv: implement p2m_set_range() Oleksii Kurochko
2025-12-08 16:52 ` Jan Beulich
2025-12-09 11:47 ` Oleksii Kurochko [this message]
2025-11-24 12:33 ` [PATCH v6 12/19] xen/riscv: Implement p2m_free_subtree() and related helpers Oleksii Kurochko
2025-12-08 16:56 ` Jan Beulich
2025-11-24 12:33 ` [PATCH v6 13/19] xen/riscv: Implement p2m_pte_from_mfn() and support PBMT configuration Oleksii Kurochko
2025-12-09 11:22 ` Jan Beulich
2025-11-24 12:33 ` [PATCH v6 14/19] xen/riscv: implement p2m_next_level() Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 15/19] xen/riscv: Implement superpage splitting for p2m mappings Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 16/19] xen/riscv: implement put_page() Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 17/19] xen/riscv: implement mfn_valid() and page reference, ownership handling helpers Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 18/19] xen/riscv: add support of page lookup by GFN Oleksii Kurochko
2025-12-09 11:38 ` Jan Beulich
2025-12-09 15:41 ` Oleksii Kurochko
2025-12-09 15:49 ` Jan Beulich
2025-12-10 11:36 ` Oleksii Kurochko
2025-12-10 11:44 ` Jan Beulich
2025-12-10 12:19 ` Oleksii Kurochko
2025-12-10 15:23 ` Oleksii Kurochko
2025-12-11 9:34 ` Jan Beulich
2025-12-11 13:00 ` Oleksii Kurochko
2025-12-11 13:40 ` Jan Beulich
2025-12-11 14:20 ` Oleksii Kurochko
2025-11-24 12:33 ` [PATCH v6 19/19] xen/riscv: introduce metadata table to store P2M type Oleksii Kurochko
2025-12-09 13:47 ` Jan Beulich
2025-12-09 17:09 ` Oleksii Kurochko
2025-12-10 7:06 ` Jan Beulich
2025-12-10 12:44 ` Oleksii Kurochko
2025-12-11 9:39 ` Jan Beulich
2025-12-11 16:42 ` Oleksii Kurochko
2025-12-15 8:28 ` Jan Beulich
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=021bdde7-ea62-447f-a788-dc31c6a930bd@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.