Re: [PATCH 1/2] fs/proc/task_mmu: change lock_vma_range() to return error code

From: Suren Baghdasaryan

Date: Mon Jun 08 2026 - 12:24:51 EST


On Mon, Jun 8, 2026 at 8:38 AM David Hildenbrand (Arm) <david@xxxxxxxxxx> wrote:
>
> On 6/6/26 03:57, Suren Baghdasaryan wrote:
> > To correctly propagate error code from lock_vma_range(), change it to
> > return the error code instead of the boolean. This simplifies error
> > propagation code.
> >
> > Signed-off-by: Suren Baghdasaryan <surenb@xxxxxxxxxx>
> > ---
> > fs/proc/task_mmu.c | 16 +++++++++-------
> > 1 file changed, 9 insertions(+), 7 deletions(-)
> >
> > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> > index d32408f7cd5e..023422fcee12 100644
> > --- a/fs/proc/task_mmu.c
> > +++ b/fs/proc/task_mmu.c
> > @@ -162,13 +162,13 @@ static void unlock_ctx_vma(struct proc_maps_locking_ctx *lock_ctx)
> > }
> > }
> >
> > -static inline bool lock_vma_range(struct seq_file *m,
> > - struct proc_maps_locking_ctx *lock_ctx)
> > +static inline int lock_vma_range(struct seq_file *m,
> > + struct proc_maps_locking_ctx *lock_ctx)
> > {
> > rcu_read_lock();
> > reset_lock_ctx(lock_ctx);
> >
> > - return true;
> > + return 0;
> > }
> >
> > static inline void unlock_vma_range(struct proc_maps_locking_ctx *lock_ctx)
> > @@ -245,10 +245,10 @@ static inline void unlock_ctx_mm(struct proc_maps_locking_ctx *lock_ctx)
> > mmap_read_unlock(lock_ctx->mm);
> > }
> >
> > -static inline bool lock_vma_range(struct seq_file *m,
> > +static inline int lock_vma_range(struct seq_file *m,
> > struct proc_maps_locking_ctx *lock_ctx)
> > {
> > - return lock_ctx_mm(lock_ctx) == 0;
> > + return lock_ctx_mm(lock_ctx);
> > }
> >
> > static inline void unlock_vma_range(struct proc_maps_locking_ctx *lock_ctx)
> > @@ -311,6 +311,7 @@ static void *m_start(struct seq_file *m, loff_t *ppos)
> > struct proc_maps_locking_ctx *lock_ctx;
> > loff_t last_addr = *ppos;
> > struct mm_struct *mm;
> > + int err;
> >
> > /* See m_next(). Zero at the start or after lseek. */
> > if (last_addr == SENTINEL_VMA_END)
> > @@ -328,11 +329,12 @@ static void *m_start(struct seq_file *m, loff_t *ppos)
> > return NULL;
> > }
> >
> > - if (!lock_vma_range(m, lock_ctx)) {
> > + err = lock_vma_range(m, lock_ctx);
> > + if (err) {
> > mmput(mm);
> > put_task_struct(priv->task);
> > priv->task = NULL;
> > - return ERR_PTR(-EINTR);
> > + return ERR_PTR(err);
>
> Looks good: down_read_killable() would also have returned -EINTR.

Yes. I also use lock_vma_range() in the next patch and this change
makes the code a bit more cleaner.

>
> Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

Thanks!

>
> --
> Cheers,
>
> David