[PATCH v3 06/22] mm/mshare: Add a vma flag to indicate an mshare region

Anthony Yznaga posted 22 patches 1 month, 2 weeks ago
[PATCH v3 06/22] mm/mshare: Add a vma flag to indicate an mshare region
Posted by Anthony Yznaga 1 month, 2 weeks ago
From: Khalid Aziz <khalid@kernel.org>

An mshare region contains zero or more actual vmas that map objects
in the mshare range with shared page tables.

Signed-off-by: Khalid Aziz <khalid@kernel.org>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
---
 include/linux/mm.h             | 19 +++++++++++++++++++
 include/trace/events/mmflags.h |  7 +++++++
 2 files changed, 26 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 76ee2bfaa8bd..aca853b4c5dc 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -431,6 +431,13 @@ extern unsigned int kobjsize(const void *objp);
 #define VM_SEALED	VM_NONE
 #endif
 
+#ifdef CONFIG_MSHARE
+#define VM_MSHARE_BIT	43
+#define VM_MSHARE	BIT(VM_MSHARE_BIT)
+#else
+#define VM_MSHARE	VM_NONE
+#endif
+
 /* Bits set in the VMA until the stack is in its final location */
 #define VM_STACK_INCOMPLETE_SETUP (VM_RAND_READ | VM_SEQ_READ | VM_STACK_EARLY)
 
@@ -991,6 +998,18 @@ static inline bool vma_is_anon_shmem(struct vm_area_struct *vma) { return false;
 
 int vma_is_stack_for_current(struct vm_area_struct *vma);
 
+#ifdef CONFIG_MSHARE
+static inline bool vma_is_mshare(const struct vm_area_struct *vma)
+{
+	return vma->vm_flags & VM_MSHARE;
+}
+#else
+static inline bool vma_is_mshare(const struct vm_area_struct *vma)
+{
+	return false;
+}
+#endif
+
 /* flush_tlb_range() takes a vma, not a mm, and can care about flags */
 #define TLB_FLUSH_VMA(mm,flags) { .vm_mm = (mm), .vm_flags = (flags) }
 
diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h
index aa441f593e9a..a9b13a8513d0 100644
--- a/include/trace/events/mmflags.h
+++ b/include/trace/events/mmflags.h
@@ -200,6 +200,12 @@ IF_HAVE_PG_ARCH_3(arch_3)
 # define IF_HAVE_VM_DROPPABLE(flag, name)
 #endif
 
+#ifdef CONFIG_MSHARE
+# define IF_HAVE_VM_MSHARE(flag, name) {flag, name},
+#else
+# define IF_HAVE_VM_MSHARE(flag, name)
+#endif
+
 #define __def_vmaflag_names						\
 	{VM_READ,			"read"		},		\
 	{VM_WRITE,			"write"		},		\
@@ -233,6 +239,7 @@ IF_HAVE_VM_SOFTDIRTY(VM_SOFTDIRTY,	"softdirty"	)		\
 	{VM_HUGEPAGE,			"hugepage"	},		\
 	{VM_NOHUGEPAGE,			"nohugepage"	},		\
 IF_HAVE_VM_DROPPABLE(VM_DROPPABLE,	"droppable"	)		\
+IF_HAVE_VM_MSHARE(VM_MSHARE,		"mshare"	)		\
 	{VM_MERGEABLE,			"mergeable"	}		\
 
 #define show_vma_flags(flags)						\
-- 
2.47.1
Re: [PATCH v3 06/22] mm/mshare: Add a vma flag to indicate an mshare region
Posted by David Hildenbrand 3 weeks, 4 days ago
On 20.08.25 03:03, Anthony Yznaga wrote:
> From: Khalid Aziz <khalid@kernel.org>
> 
> An mshare region contains zero or more actual vmas that map objects
> in the mshare range with shared page tables.
> 
> Signed-off-by: Khalid Aziz <khalid@kernel.org>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
> ---

Why can't we query the mapping instead?

-- 
Cheers

David / dhildenb
Re: [PATCH v3 06/22] mm/mshare: Add a vma flag to indicate an mshare region
Posted by Anthony Yznaga 3 weeks, 4 days ago

On 9/8/25 11:45 AM, David Hildenbrand wrote:
> On 20.08.25 03:03, Anthony Yznaga wrote:
>> From: Khalid Aziz <khalid@kernel.org>
>>
>> An mshare region contains zero or more actual vmas that map objects
>> in the mshare range with shared page tables.
>>
>> Signed-off-by: Khalid Aziz <khalid@kernel.org>
>> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
>> Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
>> ---
> 
> Why can't we query the mapping instead?
> 


The bit check is nice and zippy since vma_is_mshare() is called for 
every fault, but it's not required. The check could be made to be:

	return vma->vm_ops == &msharefs_vm_ops;
Re: [PATCH v3 06/22] mm/mshare: Add a vma flag to indicate an mshare region
Posted by David Hildenbrand 3 weeks, 4 days ago
On 08.09.25 20:56, Anthony Yznaga wrote:
> 
> 
> On 9/8/25 11:45 AM, David Hildenbrand wrote:
>> On 20.08.25 03:03, Anthony Yznaga wrote:
>>> From: Khalid Aziz <khalid@kernel.org>
>>>
>>> An mshare region contains zero or more actual vmas that map objects
>>> in the mshare range with shared page tables.
>>>
>>> Signed-off-by: Khalid Aziz <khalid@kernel.org>
>>> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
>>> Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
>>> ---
>>
>> Why can't we query the mapping instead?
>>
> 
> 
> The bit check is nice and zippy since vma_is_mshare() is called for
> every fault, but it's not required. The check could be made to be:
> 
> 	return vma->vm_ops == &msharefs_vm_ops;

Yes, like we do in secretmem_mapping(), for example.

(there, we also have a vma_is_secretmem()).

-- 
Cheers

David / dhildenb
Re: [PATCH v3 06/22] mm/mshare: Add a vma flag to indicate an mshare region
Posted by Anthony Yznaga 3 weeks, 4 days ago

On 9/8/25 12:02 PM, David Hildenbrand wrote:
> On 08.09.25 20:56, Anthony Yznaga wrote:
>>
>>
>> On 9/8/25 11:45 AM, David Hildenbrand wrote:
>>> On 20.08.25 03:03, Anthony Yznaga wrote:
>>>> From: Khalid Aziz <khalid@kernel.org>
>>>>
>>>> An mshare region contains zero or more actual vmas that map objects
>>>> in the mshare range with shared page tables.
>>>>
>>>> Signed-off-by: Khalid Aziz <khalid@kernel.org>
>>>> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
>>>> Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
>>>> ---
>>>
>>> Why can't we query the mapping instead?
>>>
>>
>>
>> The bit check is nice and zippy since vma_is_mshare() is called for
>> every fault, but it's not required. The check could be made to be:
>>
>>     return vma->vm_ops == &msharefs_vm_ops;
> 
> Yes, like we do in secretmem_mapping(), for example.
> 
> (there, we also have a vma_is_secretmem()).
> 

Okay, I'll make that change. Thanks!