[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250124235454.84587-18-anthony.yznaga@oracle.com>
Date: Fri, 24 Jan 2025 15:54:51 -0800
From: Anthony Yznaga <anthony.yznaga@...cle.com>
To: akpm@...ux-foundation.org, willy@...radead.org, markhemm@...glemail.com,
viro@...iv.linux.org.uk, david@...hat.com, khalid@...nel.org
Cc: anthony.yznaga@...cle.com, jthoughton@...gle.com, corbet@....net,
dave.hansen@...el.com, kirill@...temov.name, luto@...nel.org,
brauner@...nel.org, arnd@...db.de, ebiederm@...ssion.com,
catalin.marinas@....com, mingo@...hat.com, peterz@...radead.org,
liam.howlett@...cle.com, lorenzo.stoakes@...cle.com, vbabka@...e.cz,
jannh@...gle.com, hannes@...xchg.org, mhocko@...nel.org,
roman.gushchin@...ux.dev, shakeel.butt@...ux.dev,
muchun.song@...ux.dev, tglx@...utronix.de, cgroups@...r.kernel.org,
x86@...nel.org, linux-doc@...r.kernel.org, linux-arch@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org, mhiramat@...nel.org,
rostedt@...dmis.org, vasily.averin@...ux.dev, xhao@...ux.alibaba.com,
pcc@...gle.com, neilb@...e.de, maz@...nel.org
Subject: [PATCH 17/20] mshare: add MSHAREFS_UNMAP
Add an ioctl for unmapping objects in an mshare region.
Signed-off-by: Anthony Yznaga <anthony.yznaga@...cle.com>
---
include/uapi/linux/msharefs.h | 7 ++++++
mm/mshare.c | 44 +++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/include/uapi/linux/msharefs.h b/include/uapi/linux/msharefs.h
index fea0afdf000d..f7af1f2b5ee7 100644
--- a/include/uapi/linux/msharefs.h
+++ b/include/uapi/linux/msharefs.h
@@ -21,6 +21,7 @@
#define MSHAREFS_GET_SIZE _IOR('x', 0, struct mshare_info)
#define MSHAREFS_SET_SIZE _IOW('x', 1, struct mshare_info)
#define MSHAREFS_CREATE_MAPPING _IOW('x', 2, struct mshare_create)
+#define MSHAREFS_UNMAP _IOW('x', 3, struct mshare_unmap)
struct mshare_info {
__u64 start;
@@ -35,4 +36,10 @@ struct mshare_create {
__u32 flags;
__u32 fd;
};
+
+struct mshare_unmap {
+ __u64 addr;
+ __u64 size;
+};
+
#endif
diff --git a/mm/mshare.c b/mm/mshare.c
index d70f10210b46..8f53b8132895 100644
--- a/mm/mshare.c
+++ b/mm/mshare.c
@@ -241,6 +241,32 @@ msharefs_create_mapping(struct mm_struct *host_mm, struct mshare_data *m_data,
return err;
}
+static long
+msharefs_unmap(struct mm_struct *host_mm, struct mshare_data *m_data,
+ struct mshare_unmap *m_unmap)
+{
+ unsigned long mshare_start, mshare_end;
+ unsigned long addr = m_unmap->addr;
+ unsigned long size = m_unmap->size;
+ int err;
+
+ mshare_start = m_data->minfo.start;
+ mshare_end = mshare_start + m_data->minfo.size;
+
+ if ((addr < mshare_start) || (addr >= mshare_end) ||
+ (addr + size > mshare_end))
+ return -EINVAL;
+
+ if (mmap_write_lock_killable(host_mm))
+ return -EINTR;
+
+ err = do_munmap(host_mm, addr, size, NULL);
+
+ mmap_write_unlock(host_mm);
+
+ return err;
+}
+
static long
msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
@@ -248,6 +274,7 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
struct mm_struct *host_mm = m_data->mm;
struct mshare_info minfo;
struct mshare_create mcreate;
+ struct mshare_unmap m_unmap;
switch (cmd) {
case MSHAREFS_GET_SIZE:
@@ -293,6 +320,23 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
return msharefs_create_mapping(host_mm, m_data, &mcreate);
+ case MSHAREFS_UNMAP:
+ if (copy_from_user(&m_unmap, (struct mshare_unmap __user *)arg,
+ sizeof(m_unmap)))
+ return -EFAULT;
+
+ /*
+ * validate mshare region
+ */
+ spin_lock(&m_data->m_lock);
+ if (m_data->minfo.size == 0) {
+ spin_unlock(&m_data->m_lock);
+ return -EINVAL;
+ }
+ spin_unlock(&m_data->m_lock);
+
+ return msharefs_unmap(host_mm, m_data, &m_unmap);
+
default:
return -ENOTTY;
}
--
2.43.5
Powered by blists - more mailing lists