[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250820010415.699353-9-anthony.yznaga@oracle.com>
Date: Tue, 19 Aug 2025 18:04:01 -0700
From: Anthony Yznaga <anthony.yznaga@...cle.com>
To: linux-mm@...ck.org
Cc: akpm@...ux-foundation.org, andreyknvl@...il.com, arnd@...db.de,
bp@...en8.de, brauner@...nel.org, bsegall@...gle.com, corbet@....net,
dave.hansen@...ux.intel.com, david@...hat.com,
dietmar.eggemann@....com, ebiederm@...ssion.com, hpa@...or.com,
jakub.wartak@...lbox.org, jannh@...gle.com, juri.lelli@...hat.com,
khalid@...nel.org, liam.howlett@...cle.com, linyongting@...edance.com,
lorenzo.stoakes@...cle.com, luto@...nel.org, markhemm@...glemail.com,
maz@...nel.org, mhiramat@...nel.org, mgorman@...e.de, mhocko@...e.com,
mingo@...hat.com, muchun.song@...ux.dev, neilb@...e.de,
osalvador@...e.de, pcc@...gle.com, peterz@...radead.org,
pfalcato@...e.de, rostedt@...dmis.org, rppt@...nel.org,
shakeel.butt@...ux.dev, surenb@...gle.com, tglx@...utronix.de,
vasily.averin@...ux.dev, vbabka@...e.cz, vincent.guittot@...aro.org,
viro@...iv.linux.org.uk, vschneid@...hat.com, willy@...radead.org,
x86@...nel.org, xhao@...ux.alibaba.com, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-arch@...r.kernel.org
Subject: [PATCH v3 08/22] mm/mshare: flush all TLBs when updating PTEs in an mshare range
Unlike the mm of a task, an mshare host mm is not updated on context
switch. In particular this means that mm_cpumask is never updated
which results in TLB flushes for updates to mshare PTEs only being
done on the local CPU. To ensure entries are flushed for non-local
TLBs, set up an mmu notifier on the mshare mm and use the
.arch_invalidate_secondary_tlbs callback to flush all TLBs.
arch_invalidate_secondary_tlbs guarantees that TLB entries will be
flushed before pages are freed when unmapping pages in an mshare region.
Signed-off-by: Anthony Yznaga <anthony.yznaga@...cle.com>
---
mm/mshare.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/mm/mshare.c b/mm/mshare.c
index e0dc42602f7f..be7cae739225 100644
--- a/mm/mshare.c
+++ b/mm/mshare.c
@@ -16,8 +16,10 @@
#include <linux/fs.h>
#include <linux/fs_context.h>
#include <linux/mman.h>
+#include <linux/mmu_notifier.h>
#include <uapi/linux/magic.h>
#include <linux/falloc.h>
+#include <asm/tlbflush.h>
const unsigned long mshare_align = P4D_SIZE;
const unsigned long mshare_base = mshare_align;
@@ -30,6 +32,7 @@ struct mshare_data {
unsigned long start;
unsigned long size;
unsigned long flags;
+ struct mmu_notifier mn;
};
static inline bool mshare_is_initialized(struct mshare_data *m_data)
@@ -37,6 +40,16 @@ static inline bool mshare_is_initialized(struct mshare_data *m_data)
return test_bit(MSHARE_INITIALIZED, &m_data->flags);
}
+static void mshare_invalidate_tlbs(struct mmu_notifier *mn, struct mm_struct *mm,
+ unsigned long start, unsigned long end)
+{
+ flush_tlb_all();
+}
+
+static const struct mmu_notifier_ops mshare_mmu_ops = {
+ .arch_invalidate_secondary_tlbs = mshare_invalidate_tlbs,
+};
+
static int mshare_vm_op_split(struct vm_area_struct *vma, unsigned long addr)
{
return -EINVAL;
@@ -238,6 +251,10 @@ msharefs_fill_mm(struct inode *inode)
goto err_free;
m_data->mm = mm;
m_data->start = mshare_base;
+ m_data->mn.ops = &mshare_mmu_ops;
+ ret = mmu_notifier_register(&m_data->mn, mm);
+ if (ret)
+ goto err_free;
refcount_set(&m_data->ref, 1);
inode->i_private = m_data;
--
2.47.1
Powered by blists - more mailing lists