All of lore.kernel.org
 help / color / mirror / Atom feed
* [merged mm-hotfixes-stable] proc-nommu-fix-empty-proc-pid-maps.patch removed from -mm tree
@ 2023-09-19 20:22 Andrew Morton
  2023-09-19 22:15 ` Liam R. Howlett
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2023-09-19 20:22 UTC (permalink / raw)
  To: mm-commits, willy, vbabka, oleg, Liam.Howlett, giulio.benetti,
	dave, ben.wolsieffer, akpm


The quilt patch titled
     Subject: proc: nommu: fix empty /proc/<pid>/maps
has been removed from the -mm tree.  Its filename was
     proc-nommu-fix-empty-proc-pid-maps.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch
of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Ben Wolsieffer <ben.wolsieffer@hefring.com>
Subject: proc: nommu: fix empty /proc/<pid>/maps
Date: Fri, 15 Sep 2023 12:00:56 -0400

On no-MMU, /proc/<pid>/maps reads as an empty file.  This happens because
find_vma(mm, 0) always returns NULL (assuming no vma actually contains the
zero address, which is normally the case).

To fix this bug and improve the maintainability in the future, this patch
makes the no-MMU implementation as similar as possible to the MMU
implementation.

The only remaining differences are the lack of hold/release_task_mempolicy
and the extra code to shoehorn the gate vma into the iterator.

This has been tested on top of 6.5.3 on an STM32F746.

Link: https://lkml.kernel.org/r/20230915160055.971059-2-ben.wolsieffer@hefring.com
Fixes: 0c563f148043 ("proc: remove VMA rbtree use from nommu")
Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Giulio Benetti <giulio.benetti@benettiengineering.com>
Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 fs/proc/internal.h   |    2 --
 fs/proc/task_nommu.c |   37 ++++++++++++++++++++++---------------
 2 files changed, 22 insertions(+), 17 deletions(-)

--- a/fs/proc/internal.h~proc-nommu-fix-empty-proc-pid-maps
+++ a/fs/proc/internal.h
@@ -289,9 +289,7 @@ struct proc_maps_private {
 	struct inode *inode;
 	struct task_struct *task;
 	struct mm_struct *mm;
-#ifdef CONFIG_MMU
 	struct vma_iterator iter;
-#endif
 #ifdef CONFIG_NUMA
 	struct mempolicy *task_mempolicy;
 #endif
--- a/fs/proc/task_nommu.c~proc-nommu-fix-empty-proc-pid-maps
+++ a/fs/proc/task_nommu.c
@@ -175,15 +175,28 @@ static int show_map(struct seq_file *m,
 	return nommu_vma_show(m, _p);
 }
 
-static void *m_start(struct seq_file *m, loff_t *pos)
+static struct vm_area_struct *proc_get_vma(struct proc_maps_private *priv,
+						loff_t *ppos)
+{
+	struct vm_area_struct *vma = vma_next(&priv->iter);
+
+	if (vma) {
+		*ppos = vma->vm_start;
+	} else {
+		*ppos = -1UL;
+	}
+
+	return vma;
+}
+
+static void *m_start(struct seq_file *m, loff_t *ppos)
 {
 	struct proc_maps_private *priv = m->private;
+	unsigned long last_addr = *ppos;
 	struct mm_struct *mm;
-	struct vm_area_struct *vma;
-	unsigned long addr = *pos;
 
-	/* See m_next(). Zero at the start or after lseek. */
-	if (addr == -1UL)
+	/* See proc_get_vma(). Zero at the start or after lseek. */
+	if (last_addr == -1UL)
 		return NULL;
 
 	/* pin the task and mm whilst we play with them */
@@ -205,12 +218,9 @@ static void *m_start(struct seq_file *m,
 		return ERR_PTR(-EINTR);
 	}
 
-	/* start the next element from addr */
-	vma = find_vma(mm, addr);
-	if (vma)
-		return vma;
+	vma_iter_init(&priv->iter, mm, last_addr);
 
-	return NULL;
+	return proc_get_vma(priv, ppos);
 }
 
 static void m_stop(struct seq_file *m, void *v)
@@ -227,12 +237,9 @@ static void m_stop(struct seq_file *m, v
 	priv->task = NULL;
 }
 
-static void *m_next(struct seq_file *m, void *_p, loff_t *pos)
+static void *m_next(struct seq_file *m, void *_p, loff_t *ppos)
 {
-	struct vm_area_struct *vma = _p;
-
-	*pos = vma->vm_end;
-	return find_vma(vma->vm_mm, vma->vm_end);
+	return proc_get_vma(m->private, ppos);
 }
 
 static const struct seq_operations proc_pid_maps_ops = {
_

Patches currently in -mm which might be from ben.wolsieffer@hefring.com are



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [merged mm-hotfixes-stable] proc-nommu-fix-empty-proc-pid-maps.patch removed from -mm tree
  2023-09-19 20:22 [merged mm-hotfixes-stable] proc-nommu-fix-empty-proc-pid-maps.patch removed from -mm tree Andrew Morton
@ 2023-09-19 22:15 ` Liam R. Howlett
  2023-09-19 22:47   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Liam R. Howlett @ 2023-09-19 22:15 UTC (permalink / raw)
  To: Andrew Morton
  Cc: mm-commits, willy, vbabka, oleg, giulio.benetti, dave,
	ben.wolsieffer


I think this has the wrong fixes tag, as pointed out by willy.

It also does not fix the underlying failure of find_vma() not doing what
is expected in nommu context.


* Andrew Morton <akpm@linux-foundation.org> [230919 16:22]:
> 
> The quilt patch titled
>      Subject: proc: nommu: fix empty /proc/<pid>/maps
> has been removed from the -mm tree.  Its filename was
>      proc-nommu-fix-empty-proc-pid-maps.patch
> 
> This patch was dropped because it was merged into the mm-hotfixes-stable branch
> of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> 
> ------------------------------------------------------
> From: Ben Wolsieffer <ben.wolsieffer@hefring.com>
> Subject: proc: nommu: fix empty /proc/<pid>/maps
> Date: Fri, 15 Sep 2023 12:00:56 -0400
> 
> On no-MMU, /proc/<pid>/maps reads as an empty file.  This happens because
> find_vma(mm, 0) always returns NULL (assuming no vma actually contains the
> zero address, which is normally the case).
> 
> To fix this bug and improve the maintainability in the future, this patch
> makes the no-MMU implementation as similar as possible to the MMU
> implementation.
> 
> The only remaining differences are the lack of hold/release_task_mempolicy
> and the extra code to shoehorn the gate vma into the iterator.
> 
> This has been tested on top of 6.5.3 on an STM32F746.
> 
> Link: https://lkml.kernel.org/r/20230915160055.971059-2-ben.wolsieffer@hefring.com
> Fixes: 0c563f148043 ("proc: remove VMA rbtree use from nommu")
> Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com>
> Cc: Davidlohr Bueso <dave@stgolabs.net>
> Cc: Giulio Benetti <giulio.benetti@benettiengineering.com>
> Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
> 
>  fs/proc/internal.h   |    2 --
>  fs/proc/task_nommu.c |   37 ++++++++++++++++++++++---------------
>  2 files changed, 22 insertions(+), 17 deletions(-)
> 
> --- a/fs/proc/internal.h~proc-nommu-fix-empty-proc-pid-maps
> +++ a/fs/proc/internal.h
> @@ -289,9 +289,7 @@ struct proc_maps_private {
>  	struct inode *inode;
>  	struct task_struct *task;
>  	struct mm_struct *mm;
> -#ifdef CONFIG_MMU
>  	struct vma_iterator iter;
> -#endif
>  #ifdef CONFIG_NUMA
>  	struct mempolicy *task_mempolicy;
>  #endif
> --- a/fs/proc/task_nommu.c~proc-nommu-fix-empty-proc-pid-maps
> +++ a/fs/proc/task_nommu.c
> @@ -175,15 +175,28 @@ static int show_map(struct seq_file *m,
>  	return nommu_vma_show(m, _p);
>  }
>  
> -static void *m_start(struct seq_file *m, loff_t *pos)
> +static struct vm_area_struct *proc_get_vma(struct proc_maps_private *priv,
> +						loff_t *ppos)
> +{
> +	struct vm_area_struct *vma = vma_next(&priv->iter);
> +
> +	if (vma) {
> +		*ppos = vma->vm_start;
> +	} else {
> +		*ppos = -1UL;
> +	}
> +
> +	return vma;
> +}
> +
> +static void *m_start(struct seq_file *m, loff_t *ppos)
>  {
>  	struct proc_maps_private *priv = m->private;
> +	unsigned long last_addr = *ppos;
>  	struct mm_struct *mm;
> -	struct vm_area_struct *vma;
> -	unsigned long addr = *pos;
>  
> -	/* See m_next(). Zero at the start or after lseek. */
> -	if (addr == -1UL)
> +	/* See proc_get_vma(). Zero at the start or after lseek. */
> +	if (last_addr == -1UL)
>  		return NULL;
>  
>  	/* pin the task and mm whilst we play with them */
> @@ -205,12 +218,9 @@ static void *m_start(struct seq_file *m,
>  		return ERR_PTR(-EINTR);
>  	}
>  
> -	/* start the next element from addr */
> -	vma = find_vma(mm, addr);
> -	if (vma)
> -		return vma;
> +	vma_iter_init(&priv->iter, mm, last_addr);
>  
> -	return NULL;
> +	return proc_get_vma(priv, ppos);
>  }
>  
>  static void m_stop(struct seq_file *m, void *v)
> @@ -227,12 +237,9 @@ static void m_stop(struct seq_file *m, v
>  	priv->task = NULL;
>  }
>  
> -static void *m_next(struct seq_file *m, void *_p, loff_t *pos)
> +static void *m_next(struct seq_file *m, void *_p, loff_t *ppos)
>  {
> -	struct vm_area_struct *vma = _p;
> -
> -	*pos = vma->vm_end;
> -	return find_vma(vma->vm_mm, vma->vm_end);
> +	return proc_get_vma(m->private, ppos);
>  }
>  
>  static const struct seq_operations proc_pid_maps_ops = {
> _
> 
> Patches currently in -mm which might be from ben.wolsieffer@hefring.com are
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [merged mm-hotfixes-stable] proc-nommu-fix-empty-proc-pid-maps.patch removed from -mm tree
  2023-09-19 22:15 ` Liam R. Howlett
@ 2023-09-19 22:47   ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2023-09-19 22:47 UTC (permalink / raw)
  To: Liam R. Howlett
  Cc: mm-commits, willy, vbabka, oleg, giulio.benetti, dave,
	ben.wolsieffer

On Tue, 19 Sep 2023 18:15:11 -0400 "Liam R. Howlett" <Liam.Howlett@Oracle.com> wrote:

> 
> I think this has the wrong fixes tag, as pointed out by willy.

Well kinda.  Do we have a better Fixes:?  

> It also does not fix the underlying failure of find_vma() not doing what
> is expected in nommu context.

It does fix the immediate /proc/N/maps problem though.  So I'm inclined
to run with this patch for now.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-19 22:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-19 20:22 [merged mm-hotfixes-stable] proc-nommu-fix-empty-proc-pid-maps.patch removed from -mm tree Andrew Morton
2023-09-19 22:15 ` Liam R. Howlett
2023-09-19 22:47   ` Andrew Morton

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.