Re: [PATCH v2 6/6] mm: constify the pte_offset_map_ro_nolock() return value
"Christophe Leroy (CS GROUP)" <[email protected]> Wed, 5 Aug 2026 07:58:02 +0200
| Newsgroups | gmane.linux.ports.parisc,gmane.linux.ports.arm.kernel,gmane.linux.kernel,gmane.linux.ports.ppc64.devel,gmane.linux.kernel.mm,gmane.linux.file-systems |
|---|---|
| Message-ID | <[email protected]> |
Le 04/08/2026 à 21:22, Pedro Falcato a écrit :
> On Tue, Aug 04, 2026 at 12:22:19PM +0100, Lorenzo Stoakes (ARM) wrote:
>
>>
>>> if (!pte) {
>>> mmap_read_unlock(mm);
>>> result = SCAN_NO_PTE_TABLE;
>>> diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
>>> index b91b1a98029c..2cfc6e608ef4 100644
>>> --- a/mm/pgtable-generic.c
>>> +++ b/mm/pgtable-generic.c
>>> @@ -308,8 +308,8 @@ pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp)
>>> return NULL;
>>> }
>>>
>>> -pte_t *pte_offset_map_ro_nolock(struct mm_struct *mm, pmd_t *pmd,
>>> - unsigned long addr, spinlock_t **ptlp)
>>> +const pte_t *pte_offset_map_ro_nolock(struct mm_struct *mm, pmd_t *pmd,
>>
>> Can pmd be const too?
>
> I was going to say "yes but then pmdp_get() also needs to be constfified" but
> actually no, it can't:
>
> pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp) {
> if (unlikely(pmd_bad(pmdval))) {
> pmd_clear_bad(pmd);
> goto nomap;
> }
> }
>
> so PTE mapping actually needs to write to the pmdp if the pmd looks bad.
> Tricky stuff :)
But if pmd is const, can it be bad at all ?
Christophe