From: Mike Kravetz <mike.kravetz@oracle.com>
To: sparclinux@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
Bob Picco <bob.picco@oracle.com>,
Nitin Gupta <nitin.m.gupta@oracle.com>,
Vijay Kumar <vijay.ac.kumar@oracle.com>,
Julian Calaby <julian.calaby@gmail.com>,
Adam Buchbinder <adam.buchbinder@gmail.com>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
Michal Hocko <mhocko@suse.com>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Kravetz <mike.kravetz@oracle.com>
Subject: [RFC PATCH 12/14] mm: add mmap and shmat arch hooks for shared context
Date: Fri, 16 Dec 2016 10:35:35 -0800 [thread overview]
Message-ID: <1481913337-9331-13-git-send-email-mike.kravetz@oracle.com> (raw)
In-Reply-To: <1481913337-9331-1-git-send-email-mike.kravetz@oracle.com>
Shared context will require some additional checking and processing
when mappings are created. To faciliate this, add new mmap hooks
arch_pre_mmap_flags and arch_post_mmap to generic mm_hooks. For
shmat, a new hook arch_shmat_check is added.
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
arch/powerpc/include/asm/mmu_context.h | 12 ++++++++++++
arch/s390/include/asm/mmu_context.h | 12 ++++++++++++
arch/unicore32/include/asm/mmu_context.h | 12 ++++++++++++
arch/x86/include/asm/mmu_context.h | 12 ++++++++++++
include/asm-generic/mm_hooks.h | 18 +++++++++++++++---
ipc/shm.c | 13 +++++++++++++
mm/mmap.c | 10 ++++++++++
7 files changed, 86 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h
index 5c45114..d5ce33a 100644
--- a/arch/powerpc/include/asm/mmu_context.h
+++ b/arch/powerpc/include/asm/mmu_context.h
@@ -133,6 +133,18 @@ static inline void enter_lazy_tlb(struct mm_struct *mm,
#endif
}
+static inline unsigned long arch_pre_mmap_flags(struct file *file,
+ unsigned long flags,
+ vm_flags_t *vm_flags)
+{
+ return 0; /* no errors */
+}
+
+static inline void arch_post_mmap(struct mm_struct *mm, unsigned long addr,
+ vm_flags_t vm_flags)
+{
+}
+
static inline void arch_dup_mmap(struct mm_struct *oldmm,
struct mm_struct *mm)
{
diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h
index 515fea5..0a2322d 100644
--- a/arch/s390/include/asm/mmu_context.h
+++ b/arch/s390/include/asm/mmu_context.h
@@ -129,6 +129,18 @@ static inline void activate_mm(struct mm_struct *prev,
set_user_asce(next);
}
+static inline unsigned long arch_pre_mmap_flags(struct file *file,
+ unsigned long flags,
+ vm_flags_t *vm_flags)
+{
+ return 0; /* no errors */
+}
+
+static inline void arch_post_mmap(struct mm_struct *mm, unsigned long addr,
+ vm_flags_t vm_flags)
+{
+}
+
static inline void arch_dup_mmap(struct mm_struct *oldmm,
struct mm_struct *mm)
{
diff --git a/arch/unicore32/include/asm/mmu_context.h b/arch/unicore32/include/asm/mmu_context.h
index 62dfc64..8b57b9d 100644
--- a/arch/unicore32/include/asm/mmu_context.h
+++ b/arch/unicore32/include/asm/mmu_context.h
@@ -81,6 +81,18 @@ do { \
} \
} while (0)
+static inline unsigned long arch_pre_mmap_flags(struct file *file,
+ unsigned long flags,
+ vm_flags_t *vm_flags)
+{
+ return 0; /* no errors */
+}
+
+static inline void arch_post_mmap(struct mm_struct *mm, unsigned long addr,
+ vm_flags_t vm_flags)
+{
+}
+
static inline void arch_dup_mmap(struct mm_struct *oldmm,
struct mm_struct *mm)
{
diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
index 8e0a9fe..fe60309 100644
--- a/arch/x86/include/asm/mmu_context.h
+++ b/arch/x86/include/asm/mmu_context.h
@@ -151,6 +151,18 @@ do { \
} while (0)
#endif
+static inline unsigned long arch_pre_mmap_flags(struct file *file,
+ unsigned long flags,
+ vm_flags_t *vm_flags)
+{
+ return 0; /* no errors */
+}
+
+static inline void arch_post_mmap(struct mm_struct *mm, unsigned long addr,
+ vm_flags_t vm_flags)
+{
+}
+
static inline void arch_dup_mmap(struct mm_struct *oldmm,
struct mm_struct *mm)
{
diff --git a/include/asm-generic/mm_hooks.h b/include/asm-generic/mm_hooks.h
index cc5d9a1..c742e52 100644
--- a/include/asm-generic/mm_hooks.h
+++ b/include/asm-generic/mm_hooks.h
@@ -1,11 +1,23 @@
/*
- * Define generic no-op hooks for arch_dup_mmap, arch_exit_mmap
- * and arch_unmap to be included in asm-FOO/mmu_context.h for any
- * arch FOO which doesn't need to hook these.
+ * Define generic no-op hooks for mmap and protection related routines
+ * to be included in asm-FOO/mmu_context.h for any arch FOO which doesn't
+ * need to hook these.
*/
#ifndef _ASM_GENERIC_MM_HOOKS_H
#define _ASM_GENERIC_MM_HOOKS_H
+static inline unsigned long arch_pre_mmap_flags(struct file *file,
+ unsigned long flags,
+ vm_flags_t *vm_flags)
+{
+ return 0; /* no errors */
+}
+
+static inline void arch_post_mmap(struct mm_struct *mm, unsigned long addr,
+ vm_flags_t vm_flags)
+{
+}
+
static inline void arch_dup_mmap(struct mm_struct *oldmm,
struct mm_struct *mm)
{
diff --git a/ipc/shm.c b/ipc/shm.c
index dbac886..dab6cd1 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
#endif
+#ifndef arch_shmat_check
+#define arch_shmat_check(file, shmflg, flags) (0)
+#endif
+
+#ifndef arch_shmat_check
+#define arch_shmat_check(file, shmflg, flags) (0)
+#endif
+
void shm_init_ns(struct ipc_namespace *ns)
{
ns->shm_ctlmax = SHMMAX;
@@ -1149,6 +1157,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
goto out_unlock;
}
+ /* arch specific check and possible flag modification */
+ err = arch_shmat_check(shp->shm_file, shmflg, &flags);
+ if (err)
+ goto out_unlock;
+
err = -EACCES;
if (ipcperms(ns, &shp->shm_perm, acc_mode))
goto out_unlock;
diff --git a/mm/mmap.c b/mm/mmap.c
index 1af87c1..7fc946b 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1307,6 +1307,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
unsigned long pgoff, unsigned long *populate)
{
struct mm_struct *mm = current->mm;
+ unsigned long ret;
int pkey = 0;
*populate = 0;
@@ -1314,6 +1315,11 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
if (!len)
return -EINVAL;
+ /* arch specific check and possible modification of vm_flags */
+ ret = arch_pre_mmap_flags(file, flags, &vm_flags);
+ if (ret)
+ return ret;
+
/*
* Does the application expect PROT_READ to imply PROT_EXEC?
*
@@ -1452,6 +1458,10 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
((vm_flags & VM_LOCKED) ||
(flags & (MAP_POPULATE | MAP_NONBLOCK)) == MAP_POPULATE))
*populate = len;
+
+ if (!IS_ERR_VALUE(addr))
+ arch_post_mmap(mm, addr, vm_flags);
+
return addr;
}
--
2.7.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2016-12-16 18:36 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-16 18:35 [RFC PATCH 00/14] sparc64 shared context/TLB support Mike Kravetz
2016-12-16 18:35 ` [RFC PATCH 01/14] sparc64: placeholder for needed mmu shared context patching Mike Kravetz
2016-12-16 18:35 ` [RFC PATCH 02/14] sparc64: add new fields to mmu context for shared context support Mike Kravetz
2016-12-17 7:34 ` Sam Ravnborg
2016-12-18 23:33 ` Mike Kravetz
2016-12-21 18:12 ` Sam Ravnborg
2016-12-17 7:38 ` Sam Ravnborg
2016-12-18 23:45 ` Mike Kravetz
2016-12-21 18:13 ` Sam Ravnborg
2016-12-16 18:35 ` [RFC PATCH 03/14] sparc64: routines for basic mmu shared context structure management Mike Kravetz
2016-12-18 3:07 ` David Miller
2016-12-16 18:35 ` [RFC PATCH 04/14] sparc64: load shared id into context register 1 Mike Kravetz
2016-12-17 7:45 ` Sam Ravnborg
2016-12-19 0:22 ` Mike Kravetz
2016-12-21 18:16 ` Sam Ravnborg
2016-12-18 3:14 ` David Miller
2016-12-19 0:06 ` Mike Kravetz
2016-12-20 18:33 ` David Miller
2016-12-20 20:27 ` Mike Kravetz
2016-12-21 18:17 ` Sam Ravnborg
2016-12-16 18:35 ` [RFC PATCH 05/14] sparc64: Add PAGE_SHR_CTX flag Mike Kravetz
2016-12-18 3:12 ` David Miller
2016-12-19 0:42 ` Mike Kravetz
2016-12-20 18:33 ` David Miller
2016-12-16 18:35 ` [RFC PATCH 06/14] sparc64: general shared context tsb creation and support Mike Kravetz
2016-12-17 7:53 ` Sam Ravnborg
2016-12-19 0:52 ` Mike Kravetz
2016-12-16 18:35 ` [RFC PATCH 07/14] sparc64: move COMPUTE_TAG_TARGET and COMPUTE_TSB_PTR to header file Mike Kravetz
2016-12-16 18:35 ` [RFC PATCH 08/14] sparc64: shared context tsb handling at context switch time Mike Kravetz
2016-12-16 18:35 ` [RFC PATCH 09/14] sparc64: TLB/TSB miss handling for shared context Mike Kravetz
2016-12-16 18:35 ` [RFC PATCH 10/14] mm: add shared context to vm_area_struct Mike Kravetz
2016-12-16 18:35 ` [RFC PATCH 11/14] sparc64: add routines to look for vmsa which can share context Mike Kravetz
2016-12-16 18:35 ` Mike Kravetz [this message]
2016-12-16 18:35 ` [RFC PATCH 13/14] sparc64 mm: add shared context support to mmap() and shmat() APIs Mike Kravetz
2016-12-16 18:35 ` [RFC PATCH 14/14] sparc64: add SHARED_MMU_CTX Kconfig option Mike Kravetz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1481913337-9331-13-git-send-email-mike.kravetz@oracle.com \
--to=mike.kravetz@oracle.com \
--cc=adam.buchbinder@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bob.picco@oracle.com \
--cc=davem@davemloft.net \
--cc=julian.calaby@gmail.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=nitin.m.gupta@oracle.com \
--cc=sparclinux@vger.kernel.org \
--cc=vijay.ac.kumar@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox