On 30.09.2025 17:37, Oleksii Kurochko wrote:
> On 9/22/25 10:46 PM, Jan Beulich wrote:
>> On 17.09.2025 23:55, Oleksii Kurochko wrote:
>>> + if ( rc != P2M_TABLE_NORMAL )
>>> + break;
>>> + }
>>> +
>>> + entry = table[offsets[level]];
>>> +
>>> + if ( pte_is_valid(entry) )
>>> + {
>>> + if ( t )
>>> + *t = p2m_get_type(entry);
>>> +
>>> + mfn = pte_get_mfn(entry);
>>> + /*
>>> + * The entry may point to a superpage. Find the MFN associated
>>> + * to the GFN.
>>> + */
>>> + mfn = mfn_add(mfn,
>>> + gfn_x(gfn) & (BIT(P2M_LEVEL_ORDER(level), UL) - 1));
>> May want to assert that the respective bits of "mfn" are actually clear
>> before this calculation.
>
> ASSERT(!(mfn & (BIT(P2M_LEVEL_ORDER(level), UL) - 1)));
> Do you mean something like that?
Yes.
> I am not 100% sure that there is really need for that as page-fault exception
> is raised if the PA is insufficienlty aligned:
> Any level of PTE may be a leaf PTE, so in addition to 4 KiB pages, Sv39
> supports
> 2 MiB megapages and 1 GiB gigapages, each of which must be virtually and
> physically aligned to a boundary equal to its size. A page-fault exception
> is
> raised if the physical address is insufficiently aligned.
But that would be raised only when a page walk encounters such a PTE. You may
be altering a PTE here which never was involved in a page walk, though.
Jan