[PATCH v3 08/22] mm: Allow page table accessors to be non-idempotent

Samuel Holland samuel.holland at sifive.com
Wed Dec 10 16:33:41 PST 2025


On 2025-11-28 2:47 AM, David Hildenbrand (Red Hat) wrote:
> On 11/27/25 17:57, Ryan Roberts wrote:
>> On 13/11/2025 01:45, Samuel Holland wrote:
>>> Currently, some functions such as pte_offset_map() are passed both
>>> pointers to hardware page tables, and pointers to previously-read PMD
>>> entries on the stack. To ensure correctness in the first case, these
>>> functions must use the page table accessor function (pmdp_get()) to
>>> dereference the supplied pointer. However, this means pmdp_get() is
>>> called twice in the second case. This double call must be avoided if
>>> pmdp_get() applies some non-idempotent transformation to the value.
>>>
>>> Avoid the double transformation by calling set_pmd() on the stack
>>> variables where necessary to keep set_pmd()/pmdp_get() calls balanced.
>>
>> I don't think this is a good solution.
> 
> Agreed,
> 
>     set_pmd(&pmd, pmd);
> 
> is rather horrible.
I agree that this patch is ugly. The only way I see to avoid code like this is
to refactor (or duplicate) the functions so no function takes pointers to both
hardware page tables and on-stack page table entries. Is that sort of
refactoring the right direction to go for v4?

Regards,
Samuel




More information about the linux-riscv mailing list