Skip to contentSkip to conversation

fixup for mm/debug: print vm_refcnt state when dumping the vma

PATCH In review Suren Baghdasaryan 2 participants 4 messages Dec 26, 2024 – Jan 8, 2025

Subsystems (3)
lore
Share & tools
lore

Suren Baghdasaryan

author reviewer
#0 lore raw

PATCH 1/1 fixup for mm/debug: print vm_refcnt state when dumping the vma

vma->vm_refcnt does not exist when CONFIG_PER_VMA_LOCK=n, therefore when CONFIG_PER_VMA_LOCK=n and CONFIG_DEBUG_VM=y we need to avoid its usage in dump_vma().

---
Fixes https://lore.kernel.org/all/[email protected]/
posted over mm-unstable.

 mm/debug.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/debug.c +12 -0
index 68b3ba3cf603..9c4cbc3733b0 100644
@@ -178,6 +178,7 @@ EXPORT_SYMBOL(dump_page);
 
 void dump_vma(const struct vm_area_struct *vma)
 {
+#ifdef CONFIG_PER_VMA_LOCK
 	pr_emerg("vma %px start %px end %px mm %px\n"
 		"prot %lx anon_vma %px vm_ops %px\n"
 		"pgoff %lx file %px private_data %px\n"
@@ -187,6 +188,17 @@ void dump_vma(const struct vm_area_struct *vma)
 		vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
 		vma->vm_file, vma->vm_private_data,
 		vma->vm_flags, &vma->vm_flags, refcount_read(&vma->vm_refcnt));
+#else
+	pr_emerg("vma %px start %px end %px mm %px\n"
+		"prot %lx anon_vma %px vm_ops %px\n"
+		"pgoff %lx file %px private_data %px\n"
+		"flags: %#lx(%pGv)\n",
+		vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_mm,
+		(unsigned long)pgprot_val(vma->vm_page_prot),
+		vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
+		vma->vm_file, vma->vm_private_data,
+		vma->vm_flags, &vma->vm_flags);
+#endif
 }
 EXPORT_SYMBOL(dump_vma);
 
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
#1 lore raw
Quoted 3 lines · Suren Baghdasaryan

vma->vm_refcnt does not exist when CONFIG_PER_VMA_LOCK=n, therefore when CONFIG_PER_VMA_LOCK=n and CONFIG_DEBUG_VM=y we need to avoid its usage in dump_vma().

It might be worth having a function that decodes the information in the vma lock and outputs a string that spells out what is going on, and another that just outputs "not supported" or something.

This has the benefit of spelling out the state and only having one place to update in future dump_vma() changes.

Quoted 44 lines

---
Fixes https://lore.kernel.org/all/[email protected]/
posted over mm-unstable.

 mm/debug.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/debug.c +12 -0
index 68b3ba3cf603..9c4cbc3733b0 100644
@@ -178,6 +178,7 @@ EXPORT_SYMBOL(dump_page);
 
 void dump_vma(const struct vm_area_struct *vma)
 {
+#ifdef CONFIG_PER_VMA_LOCK
 	pr_emerg("vma %px start %px end %px mm %px\n"
 		"prot %lx anon_vma %px vm_ops %px\n"
 		"pgoff %lx file %px private_data %px\n"
@@ -187,6 +188,17 @@ void dump_vma(const struct vm_area_struct *vma)
 		vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
 		vma->vm_file, vma->vm_private_data,
 		vma->vm_flags, &vma->vm_flags, refcount_read(&vma->vm_refcnt));
+#else
+	pr_emerg("vma %px start %px end %px mm %px\n"
+		"prot %lx anon_vma %px vm_ops %px\n"
+		"pgoff %lx file %px private_data %px\n"
+		"flags: %#lx(%pGv)\n",
+		vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_mm,
+		(unsigned long)pgprot_val(vma->vm_page_prot),
+		vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
+		vma->vm_file, vma->vm_private_data,
+		vma->vm_flags, &vma->vm_flags);
+#endif
 }
 EXPORT_SYMBOL(dump_vma);
 
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
author reviewer
#2 lore raw
Quoted 8 lines · Liam R. Howlett
Quoted 3 lines · Suren Baghdasaryan

vma->vm_refcnt does not exist when CONFIG_PER_VMA_LOCK=n, therefore when CONFIG_PER_VMA_LOCK=n and CONFIG_DEBUG_VM=y we need to avoid its usage in dump_vma().

It might be worth having a function that decodes the information in the vma lock and outputs a string that spells out what is going on,

You mean something like "attached, 2 reader(s), 0 writer(s)" instead of "refcnt 0x3" ?

Quoted 2 lines

and
another that just outputs "not supported" or something.

Do you mean we should report "not supported" when CONFIG_PER_VMA_LOCK=n?

Quoted 48 lines

This has the benefit of spelling out the state and only having one place to update in future dump_vma() changes.

Quoted 44 lines

---
Fixes https://lore.kernel.org/all/[email protected]/
posted over mm-unstable.

 mm/debug.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/debug.c +12 -1
index 68b3ba3cf603..9c4cbc3733b0 100644
@@ -178,6 +178,7 @@ EXPORT_SYMBOL(dump_page);
 
 void dump_vma(const struct vm_area_struct *vma)
 {
+#ifdef CONFIG_PER_VMA_LOCK
      pr_emerg("vma %px start %px end %px mm %px\n"
              "prot %lx anon_vma %px vm_ops %px\n"
              "pgoff %lx file %px private_data %px\n"
@@ -187,6 +188,17 @@ void dump_vma(const struct vm_area_struct *vma)
              vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
              vma->vm_file, vma->vm_private_data,
              vma->vm_flags, &vma->vm_flags, refcount_read(&vma->vm_refcnt));
+#else
+     pr_emerg("vma %px start %px end %px mm %px\n"
+             "prot %lx anon_vma %px vm_ops %px\n"
+             "pgoff %lx file %px private_data %px\n"
+             "flags: %#lx(%pGv)\n",
+             vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_mm,
+             (unsigned long)pgprot_val(vma->vm_page_prot),
+             vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
+             vma->vm_file, vma->vm_private_data,
+             vma->vm_flags, &vma->vm_flags);
+#endif
 }
 EXPORT_SYMBOL(dump_vma);
 
--

2.47.1.613.gc27f4b7a9f-goog

author reviewer
#3 lore raw
Quoted 11 lines · Suren Baghdasaryan
Quoted 8 lines · Liam R. Howlett
Quoted 3 lines · Suren Baghdasaryan

vma->vm_refcnt does not exist when CONFIG_PER_VMA_LOCK=n, therefore when CONFIG_PER_VMA_LOCK=n and CONFIG_DEBUG_VM=y we need to avoid its usage in dump_vma().

It might be worth having a function that decodes the information in the vma lock and outputs a string that spells out what is going on,

Quoted 7 lines

You mean something like "attached, 2 reader(s), 0 writer(s)" instead of "refcnt 0x3" ?

Quoted 2 lines

and
another that just outputs "not supported" or something.

Do you mean we should report "not supported" when CONFIG_PER_VMA_LOCK=n?

Hi Liam,
I have v8 ready for posting except for this patch which I'm not clear how you wanted to change. I thought printing the raw vm_refcnt for debugging would be consistent with how we output other fields, like vm_flags for example (without interpreting each bit).
Could you please clarify, preferably with a sample output, how you
would like to see vm_refcnt printed? I can also keep this patch out of the series for now if we are not sure yet how it should be displayed. It's not critical and can be added later.
Thanks,
Suren.

Quoted 49 lines
Quoted 49 lines

This has the benefit of spelling out the state and only having one place to update in future dump_vma() changes.

Quoted 44 lines

---
Fixes https://lore.kernel.org/all/[email protected]/
posted over mm-unstable.

 mm/debug.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/debug.c +12 -1
index 68b3ba3cf603..9c4cbc3733b0 100644
@@ -178,6 +178,7 @@ EXPORT_SYMBOL(dump_page);
 
 void dump_vma(const struct vm_area_struct *vma)
 {
+#ifdef CONFIG_PER_VMA_LOCK
      pr_emerg("vma %px start %px end %px mm %px\n"
              "prot %lx anon_vma %px vm_ops %px\n"
              "pgoff %lx file %px private_data %px\n"
@@ -187,6 +188,17 @@ void dump_vma(const struct vm_area_struct *vma)
              vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
              vma->vm_file, vma->vm_private_data,
              vma->vm_flags, &vma->vm_flags, refcount_read(&vma->vm_refcnt));
+#else
+     pr_emerg("vma %px start %px end %px mm %px\n"
+             "prot %lx anon_vma %px vm_ops %px\n"
+             "pgoff %lx file %px private_data %px\n"
+             "flags: %#lx(%pGv)\n",
+             vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_mm,
+             (unsigned long)pgprot_val(vma->vm_page_prot),
+             vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
+             vma->vm_file, vma->vm_private_data,
+             vma->vm_flags, &vma->vm_flags);
+#endif
 }
 EXPORT_SYMBOL(dump_vma);
 
--

2.47.1.613.gc27f4b7a9f-goog