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

From: Anthony Yznaga
Date: Fri Jan 24 2025 - 18:57:26 EST


From: Khalid Aziz <khalid@xxxxxxxxxx>

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@xxxxxxxxxx>
Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
Signed-off-by: Anthony Yznaga <anthony.yznaga@xxxxxxxxxx>
---
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 8483e09aeb2c..bca7aee40f4d 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -440,6 +440,13 @@ extern unsigned int kobjsize(const void *objp);
#define VM_DROPPABLE VM_NONE
#endif

+#ifdef CONFIG_MSHARE
+#define VM_MSHARE_BIT 41
+#define VM_MSHARE BIT(VM_MSHARE_BIT)
+#else
+#define VM_MSHARE VM_NONE
+#endif
+
#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
#define VM_SEALED _BITUL(63)
@@ -1092,6 +1099,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 3bc8656c8359..0c7d50ab56cd 100644
--- a/include/trace/events/mmflags.h
+++ b/include/trace/events/mmflags.h
@@ -160,6 +160,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" }, \
@@ -193,6 +199,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.43.5