fs/proc/task_mmu: Add display flag for VM_MAYOVERLAY

Message ID 20240208084805.1252337-1-anshuman.khandual@arm.com
State New
Headers
Series fs/proc/task_mmu: Add display flag for VM_MAYOVERLAY |

Commit Message

Anshuman Khandual Feb. 8, 2024, 8:48 a.m. UTC
  VM_UFFD_MISSING flag is mutually exclussive with VM_MAYOVERLAY flag as they
both use the same bit position i.e 0x00000200 in the vm_flags. Let's update
show_smap_vma_flags() to display the correct flags depending on CONFIG_MMU.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
This applies on v6.8-rc3

 fs/proc/task_mmu.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

David Hildenbrand Feb. 8, 2024, 4:48 p.m. UTC | #1
On 08.02.24 09:48, Anshuman Khandual wrote:
> VM_UFFD_MISSING flag is mutually exclussive with VM_MAYOVERLAY flag as they
> both use the same bit position i.e 0x00000200 in the vm_flags. Let's update
> show_smap_vma_flags() to display the correct flags depending on CONFIG_MMU.
> 
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-fsdevel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
> This applies on v6.8-rc3
> 
>   fs/proc/task_mmu.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 3f78ebbb795f..1c4eb25cfc17 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -681,7 +681,11 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
>   		[ilog2(VM_HUGEPAGE)]	= "hg",
>   		[ilog2(VM_NOHUGEPAGE)]	= "nh",
>   		[ilog2(VM_MERGEABLE)]	= "mg",
> +#ifdef CONFIG_MMU
>   		[ilog2(VM_UFFD_MISSING)]= "um",
> +#else
> +		[ilog2(VM_MAYOVERLAY)]	= "ov",
> +#endif /* CONFIG_MMU */
>   		[ilog2(VM_UFFD_WP)]	= "uw",
>   #ifdef CONFIG_ARM64_MTE
>   		[ilog2(VM_MTE)]		= "mt",

Reviewed-by: David Hildenbrand <david@redhat.com>
  
Andrew Morton Feb. 8, 2024, 8:40 p.m. UTC | #2
On Thu, 8 Feb 2024 17:48:26 +0100 David Hildenbrand <david@redhat.com> wrote:

> On 08.02.24 09:48, Anshuman Khandual wrote:
> > VM_UFFD_MISSING flag is mutually exclussive with VM_MAYOVERLAY flag as they
> > both use the same bit position i.e 0x00000200 in the vm_flags. Let's update
> > show_smap_vma_flags() to display the correct flags depending on CONFIG_MMU.
> > 
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: David Hildenbrand <david@redhat.com>
> > Cc: linux-kernel@vger.kernel.org
> > Cc: linux-fsdevel@vger.kernel.org
> > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> > ---
> > This applies on v6.8-rc3
> > 
> >   fs/proc/task_mmu.c | 4 ++++
> >   1 file changed, 4 insertions(+)
> > 
> > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> > index 3f78ebbb795f..1c4eb25cfc17 100644
> > --- a/fs/proc/task_mmu.c
> > +++ b/fs/proc/task_mmu.c
> > @@ -681,7 +681,11 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
> >   		[ilog2(VM_HUGEPAGE)]	= "hg",
> >   		[ilog2(VM_NOHUGEPAGE)]	= "nh",
> >   		[ilog2(VM_MERGEABLE)]	= "mg",
> > +#ifdef CONFIG_MMU
> >   		[ilog2(VM_UFFD_MISSING)]= "um",
> > +#else
> > +		[ilog2(VM_MAYOVERLAY)]	= "ov",
> > +#endif /* CONFIG_MMU */
> >   		[ilog2(VM_UFFD_WP)]	= "uw",
> >   #ifdef CONFIG_ARM64_MTE
> >   		[ilog2(VM_MTE)]		= "mt",
> 
> Reviewed-by: David Hildenbrand <david@redhat.com>

I'm thinking

Fixes: b6b7a8faf05c ("mm/nommu: don't use VM_MAYSHARE for MAP_PRIVATE mappings")
Cc: <stable@vger.kernel.org>
  
David Hildenbrand Feb. 9, 2024, 10:31 p.m. UTC | #3
On 08.02.24 21:40, Andrew Morton wrote:
> On Thu, 8 Feb 2024 17:48:26 +0100 David Hildenbrand <david@redhat.com> wrote:
> 
>> On 08.02.24 09:48, Anshuman Khandual wrote:
>>> VM_UFFD_MISSING flag is mutually exclussive with VM_MAYOVERLAY flag as they
>>> both use the same bit position i.e 0x00000200 in the vm_flags. Let's update
>>> show_smap_vma_flags() to display the correct flags depending on CONFIG_MMU.
>>>
>>> Cc: Andrew Morton <akpm@linux-foundation.org>
>>> Cc: David Hildenbrand <david@redhat.com>
>>> Cc: linux-kernel@vger.kernel.org
>>> Cc: linux-fsdevel@vger.kernel.org
>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>>> ---
>>> This applies on v6.8-rc3
>>>
>>>    fs/proc/task_mmu.c | 4 ++++
>>>    1 file changed, 4 insertions(+)
>>>
>>> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
>>> index 3f78ebbb795f..1c4eb25cfc17 100644
>>> --- a/fs/proc/task_mmu.c
>>> +++ b/fs/proc/task_mmu.c
>>> @@ -681,7 +681,11 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
>>>    		[ilog2(VM_HUGEPAGE)]	= "hg",
>>>    		[ilog2(VM_NOHUGEPAGE)]	= "nh",
>>>    		[ilog2(VM_MERGEABLE)]	= "mg",
>>> +#ifdef CONFIG_MMU
>>>    		[ilog2(VM_UFFD_MISSING)]= "um",
>>> +#else
>>> +		[ilog2(VM_MAYOVERLAY)]	= "ov",
>>> +#endif /* CONFIG_MMU */
>>>    		[ilog2(VM_UFFD_WP)]	= "uw",
>>>    #ifdef CONFIG_ARM64_MTE
>>>    		[ilog2(VM_MTE)]		= "mt",
>>
>> Reviewed-by: David Hildenbrand <david@redhat.com>
> 
> I'm thinking
> 
> Fixes: b6b7a8faf05c ("mm/nommu: don't use VM_MAYSHARE for MAP_PRIVATE mappings")
> Cc: <stable@vger.kernel.org>

I'm having a hard time believing that anybody that runs a !MMU kernel 
would actually care about this bit being exposed as "ov" instead of "uw".

So in my thinking, one could even update 
Documentation/filesystems/proc.rst to just mention that "uw" on !MMU is 
only used for internal purposes.

But now, I actually read what that structure says:

"Don't forget to update Documentation/ on changes."

So, let's look there: Documentation/filesystems/proc.rst

"Note that there is no guarantee that every flag and associated mnemonic 
will be present in all further kernel releases. Things get changed, the 
flags may be vanished or the reverse -- new added. Interpretation of 
their meaning might change in future as well. So each consumer of these 
flags has to follow each specific kernel version for the exact semantic.

This file is only present if the CONFIG_MMU kernel configuration option 
is enabled."

And in fact

$ git grep MMU fs/proc/Makefile
fs/proc/Makefile:proc-$(CONFIG_MMU)     := task_mmu.o


So I rewoke my RB, this patch should be dropped and was never even 
tested unless I am missing something important.
  
Anshuman Khandual Feb. 12, 2024, 2 a.m. UTC | #4
On 2/10/24 04:01, David Hildenbrand wrote:
> On 08.02.24 21:40, Andrew Morton wrote:
>> On Thu, 8 Feb 2024 17:48:26 +0100 David Hildenbrand <david@redhat.com> wrote:
>>
>>> On 08.02.24 09:48, Anshuman Khandual wrote:
>>>> VM_UFFD_MISSING flag is mutually exclussive with VM_MAYOVERLAY flag as they
>>>> both use the same bit position i.e 0x00000200 in the vm_flags. Let's update
>>>> show_smap_vma_flags() to display the correct flags depending on CONFIG_MMU.
>>>>
>>>> Cc: Andrew Morton <akpm@linux-foundation.org>
>>>> Cc: David Hildenbrand <david@redhat.com>
>>>> Cc: linux-kernel@vger.kernel.org
>>>> Cc: linux-fsdevel@vger.kernel.org
>>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>>>> ---
>>>> This applies on v6.8-rc3
>>>>
>>>>    fs/proc/task_mmu.c | 4 ++++
>>>>    1 file changed, 4 insertions(+)
>>>>
>>>> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
>>>> index 3f78ebbb795f..1c4eb25cfc17 100644
>>>> --- a/fs/proc/task_mmu.c
>>>> +++ b/fs/proc/task_mmu.c
>>>> @@ -681,7 +681,11 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
>>>>            [ilog2(VM_HUGEPAGE)]    = "hg",
>>>>            [ilog2(VM_NOHUGEPAGE)]    = "nh",
>>>>            [ilog2(VM_MERGEABLE)]    = "mg",
>>>> +#ifdef CONFIG_MMU
>>>>            [ilog2(VM_UFFD_MISSING)]= "um",
>>>> +#else
>>>> +        [ilog2(VM_MAYOVERLAY)]    = "ov",
>>>> +#endif /* CONFIG_MMU */
>>>>            [ilog2(VM_UFFD_WP)]    = "uw",
>>>>    #ifdef CONFIG_ARM64_MTE
>>>>            [ilog2(VM_MTE)]        = "mt",
>>>
>>> Reviewed-by: David Hildenbrand <david@redhat.com>
>>
>> I'm thinking
>>
>> Fixes: b6b7a8faf05c ("mm/nommu: don't use VM_MAYSHARE for MAP_PRIVATE mappings")
>> Cc: <stable@vger.kernel.org>
> 
> I'm having a hard time believing that anybody that runs a !MMU kernel would actually care about this bit being exposed as "ov" instead of "uw".
> 
> So in my thinking, one could even update Documentation/filesystems/proc.rst to just mention that "uw" on !MMU is only used for internal purposes.
> 
> But now, I actually read what that structure says:
> 
> "Don't forget to update Documentation/ on changes."
> 
> So, let's look there: Documentation/filesystems/proc.rst
> 
> "Note that there is no guarantee that every flag and associated mnemonic will be present in all further kernel releases. Things get changed, the flags may be vanished or the reverse -- new added. Interpretation of their meaning might change in future as well. So each consumer of these flags has to follow each specific kernel version for the exact semantic.
> 
> This file is only present if the CONFIG_MMU kernel configuration option is enabled."
> 
> And in fact
> 
> $ git grep MMU fs/proc/Makefile
> fs/proc/Makefile:proc-$(CONFIG_MMU)     := task_mmu.o

Ahh! you are right, completely missed that.

> 
> 
> So I rewoke my RB, this patch should be dropped and was never even tested unless I am missing something important.

Fair enough, let's drop this patch. I found this via code inspection while
looking into VM_UFFD_MISSING definition, booted with default configs which
has CONFIG_MMU enabled. But this was an oversight, my bad.
  
David Hildenbrand Feb. 12, 2024, 9:05 a.m. UTC | #5
On 12.02.24 03:00, Anshuman Khandual wrote:
> 
> On 2/10/24 04:01, David Hildenbrand wrote:
>> On 08.02.24 21:40, Andrew Morton wrote:
>>> On Thu, 8 Feb 2024 17:48:26 +0100 David Hildenbrand <david@redhat.com> wrote:
>>>
>>>> On 08.02.24 09:48, Anshuman Khandual wrote:
>>>>> VM_UFFD_MISSING flag is mutually exclussive with VM_MAYOVERLAY flag as they
>>>>> both use the same bit position i.e 0x00000200 in the vm_flags. Let's update
>>>>> show_smap_vma_flags() to display the correct flags depending on CONFIG_MMU.
>>>>>
>>>>> Cc: Andrew Morton <akpm@linux-foundation.org>
>>>>> Cc: David Hildenbrand <david@redhat.com>
>>>>> Cc: linux-kernel@vger.kernel.org
>>>>> Cc: linux-fsdevel@vger.kernel.org
>>>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>>>>> ---
>>>>> This applies on v6.8-rc3
>>>>>
>>>>>     fs/proc/task_mmu.c | 4 ++++
>>>>>     1 file changed, 4 insertions(+)
>>>>>
>>>>> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
>>>>> index 3f78ebbb795f..1c4eb25cfc17 100644
>>>>> --- a/fs/proc/task_mmu.c
>>>>> +++ b/fs/proc/task_mmu.c
>>>>> @@ -681,7 +681,11 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
>>>>>             [ilog2(VM_HUGEPAGE)]    = "hg",
>>>>>             [ilog2(VM_NOHUGEPAGE)]    = "nh",
>>>>>             [ilog2(VM_MERGEABLE)]    = "mg",
>>>>> +#ifdef CONFIG_MMU
>>>>>             [ilog2(VM_UFFD_MISSING)]= "um",
>>>>> +#else
>>>>> +        [ilog2(VM_MAYOVERLAY)]    = "ov",
>>>>> +#endif /* CONFIG_MMU */
>>>>>             [ilog2(VM_UFFD_WP)]    = "uw",
>>>>>     #ifdef CONFIG_ARM64_MTE
>>>>>             [ilog2(VM_MTE)]        = "mt",
>>>>
>>>> Reviewed-by: David Hildenbrand <david@redhat.com>
>>>
>>> I'm thinking
>>>
>>> Fixes: b6b7a8faf05c ("mm/nommu: don't use VM_MAYSHARE for MAP_PRIVATE mappings")
>>> Cc: <stable@vger.kernel.org>
>>
>> I'm having a hard time believing that anybody that runs a !MMU kernel would actually care about this bit being exposed as "ov" instead of "uw".
>>
>> So in my thinking, one could even update Documentation/filesystems/proc.rst to just mention that "uw" on !MMU is only used for internal purposes.
>>
>> But now, I actually read what that structure says:
>>
>> "Don't forget to update Documentation/ on changes."
>>
>> So, let's look there: Documentation/filesystems/proc.rst
>>
>> "Note that there is no guarantee that every flag and associated mnemonic will be present in all further kernel releases. Things get changed, the flags may be vanished or the reverse -- new added. Interpretation of their meaning might change in future as well. So each consumer of these flags has to follow each specific kernel version for the exact semantic.
>>
>> This file is only present if the CONFIG_MMU kernel configuration option is enabled."
>>
>> And in fact
>>
>> $ git grep MMU fs/proc/Makefile
>> fs/proc/Makefile:proc-$(CONFIG_MMU)     := task_mmu.o
> 
> Ahh! you are right, completely missed that.
> 
>>
>>
>> So I rewoke my RB, this patch should be dropped and was never even tested unless I am missing something important.
> 
> Fair enough, let's drop this patch. I found this via code inspection while
> looking into VM_UFFD_MISSING definition, booted with default configs which
> has CONFIG_MMU enabled. But this was an oversight, my bad.
> 

No worries, NUMMU is just absolutely weird :)
  

Patch

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 3f78ebbb795f..1c4eb25cfc17 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -681,7 +681,11 @@  static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
 		[ilog2(VM_HUGEPAGE)]	= "hg",
 		[ilog2(VM_NOHUGEPAGE)]	= "nh",
 		[ilog2(VM_MERGEABLE)]	= "mg",
+#ifdef CONFIG_MMU
 		[ilog2(VM_UFFD_MISSING)]= "um",
+#else
+		[ilog2(VM_MAYOVERLAY)]	= "ov",
+#endif /* CONFIG_MMU */
 		[ilog2(VM_UFFD_WP)]	= "uw",
 #ifdef CONFIG_ARM64_MTE
 		[ilog2(VM_MTE)]		= "mt",