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 13/14] sparc64 mm: add shared context support to mmap() and shmat() APIs
Date: Fri, 16 Dec 2016 10:35:36 -0800 [thread overview]
Message-ID: <1481913337-9331-14-git-send-email-mike.kravetz@oracle.com> (raw)
In-Reply-To: <1481913337-9331-1-git-send-email-mike.kravetz@oracle.com>
Add new mmap(MAP_SHAREDCTX) and shm(SHM_SHAREDCTX) flags to specify
desire for shared context mappings. This only works on HUGETLB
mappings. In addition, the mappings must be SHARED and at a FIXED
address otherwize EINVAL will be returned.
Also, populate the sparc specific hooks to mmap and shmat that perform
shared context processing.
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
arch/sparc/include/asm/hugetlb.h | 4 +++
arch/sparc/include/asm/mman.h | 6 ++++
arch/sparc/include/asm/mmu_context_64.h | 62 ++++++++++++++++++++++++++++++++-
arch/sparc/include/uapi/asm/mman.h | 1 +
arch/sparc/kernel/sys_sparc_64.c | 17 +++++++++
arch/sparc/mm/init_64.c | 36 +++++++++++++++++++
include/uapi/linux/shm.h | 1 +
7 files changed, 126 insertions(+), 1 deletion(-)
diff --git a/arch/sparc/include/asm/hugetlb.h b/arch/sparc/include/asm/hugetlb.h
index dcbf985..13157b3 100644
--- a/arch/sparc/include/asm/hugetlb.h
+++ b/arch/sparc/include/asm/hugetlb.h
@@ -78,4 +78,8 @@ void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
unsigned long end, unsigned long floor,
unsigned long ceiling);
+#if defined(CONFIG_SHARED_MMU_CTX)
+void huge_get_shared_ctx(struct mm_struct *mm, unsigned long addr);
+#endif
+
#endif /* _ASM_SPARC64_HUGETLB_H */
diff --git a/arch/sparc/include/asm/mman.h b/arch/sparc/include/asm/mman.h
index 59bb593..cbe384e 100644
--- a/arch/sparc/include/asm/mman.h
+++ b/arch/sparc/include/asm/mman.h
@@ -6,5 +6,11 @@
#ifndef __ASSEMBLY__
#define arch_mmap_check(addr,len,flags) sparc_mmap_check(addr,len)
int sparc_mmap_check(unsigned long addr, unsigned long len);
+
+#if defined(CONFIG_SHARED_MMU_CTX)
+#define arch_shmat_check(file, shmflg, flags) \
+ sparc_shmat_check(file, shmflg, flags)
+int sparc_shmat_check(struct file *file, int shmflg, unsigned long *flags);
+#endif
#endif
#endif /* __SPARC_MMAN_H__ */
diff --git a/arch/sparc/include/asm/mmu_context_64.h b/arch/sparc/include/asm/mmu_context_64.h
index 46c2c7e..8ab05f2 100644
--- a/arch/sparc/include/asm/mmu_context_64.h
+++ b/arch/sparc/include/asm/mmu_context_64.h
@@ -7,7 +7,6 @@
#include <linux/spinlock.h>
#include <asm/spitfire.h>
-#include <asm-generic/mm_hooks.h>
static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
{
@@ -24,6 +23,13 @@ void put_shared_context(struct mm_struct *mm);
void set_mm_shared_ctx(struct mm_struct *mm, struct shared_mmu_ctx *ctx);
void destroy_shared_context(struct mm_struct *mm);
void set_vma_shared_ctx(struct vm_area_struct *vma);
+void sparc64_exit_mmap(struct mm_struct *mm);
+void sparc64_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
+ unsigned long start, unsigned long end);
+unsigned long sparc64_pre_mmap_flags(struct file *file, unsigned long flags,
+ vm_flags_t *vm_flags);
+void sparc64_post_mmap(struct mm_struct *mm, unsigned long addr,
+ vm_flags_t vm_flags);
#endif
#ifdef CONFIG_SMP
void smp_new_mmu_context_version(void);
@@ -208,6 +214,60 @@ static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm
spin_unlock_irqrestore(&mm->context.lock, flags);
}
+#if defined(CONFIG_SHARED_MMU_CTX)
+/*
+ * mm_hooks only needed for CONFIG_SHARED_MMU_CTX
+ */
+static inline unsigned long arch_pre_mmap_flags(struct file *file,
+ unsigned long flags,
+ vm_flags_t *vm_flags)
+{
+ return sparc64_pre_mmap_flags(file, flags, vm_flags);
+}
+
+static inline void arch_post_mmap(struct mm_struct *mm, unsigned long addr,
+ vm_flags_t vm_flags)
+{
+ sparc64_post_mmap(mm, addr, vm_flags);
+}
+
+static inline void arch_dup_mmap(struct mm_struct *oldmm,
+ struct mm_struct *mm)
+{
+}
+
+static inline void arch_exit_mmap(struct mm_struct *mm)
+{
+ sparc64_exit_mmap(mm);
+}
+
+static inline void arch_unmap(struct mm_struct *mm,
+ struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ sparc64_unmap(mm, vma, start, end);
+}
+
+static inline void arch_bprm_mm_init(struct mm_struct *mm,
+ struct vm_area_struct *vma)
+{
+}
+
+static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
+ bool write, bool execute, bool foreign)
+{
+ /* by default, allow everything */
+ return true;
+}
+
+static inline bool arch_pte_access_permitted(pte_t pte, bool write)
+{
+ /* by default, allow everything */
+ return true;
+}
+#else
+#include <asm-generic/mm_hooks.h>
+#endif
#endif /* !(__ASSEMBLY__) */
#endif /* !(__SPARC64_MMU_CONTEXT_H) */
diff --git a/arch/sparc/include/uapi/asm/mman.h b/arch/sparc/include/uapi/asm/mman.h
index 9765896..a52c6fe 100644
--- a/arch/sparc/include/uapi/asm/mman.h
+++ b/arch/sparc/include/uapi/asm/mman.h
@@ -23,6 +23,7 @@
#define MAP_NONBLOCK 0x10000 /* do not block on IO */
#define MAP_STACK 0x20000 /* give out an address that is best suited for process/thread stacks */
#define MAP_HUGETLB 0x40000 /* create a huge page mapping */
+#define MAP_SHAREDCTX 0x80000 /* request shared cxt mapping */
#endif /* _UAPI__SPARC_MMAN_H__ */
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index fe8b8ee..23fa538 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -25,6 +25,7 @@
#include <linux/random.h>
#include <linux/export.h>
#include <linux/context_tracking.h>
+#include <linux/hugetlb.h>
#include <asm/uaccess.h>
#include <asm/utrap.h>
@@ -444,6 +445,22 @@ int sparc_mmap_check(unsigned long addr, unsigned long len)
return 0;
}
+int sparc_shmat_check(struct file *file, int shmflg, unsigned long *flags)
+{
+ if (shmflg & SHM_SHAREDCTX) {
+ if ((*flags & (MAP_SHARED | MAP_FIXED)) !=
+ (unsigned long)(MAP_SHARED | MAP_FIXED))
+ return -EINVAL;
+
+ if (!is_file_hugepages(file))
+ return -EINVAL;
+
+ *flags |= MAP_SHAREDCTX;
+ }
+
+ return 0;
+}
+
/* Linux version of mmap */
SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
unsigned long, prot, unsigned long, flags, unsigned long, fd,
diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
index 25ad5bd..0637762 100644
--- a/arch/sparc/mm/init_64.c
+++ b/arch/sparc/mm/init_64.c
@@ -27,6 +27,7 @@
#include <linux/memblock.h>
#include <linux/mmzone.h>
#include <linux/gfp.h>
+#include <linux/mman.h>
#include <asm/head.h>
#include <asm/page.h>
@@ -832,6 +833,41 @@ void set_vma_shared_ctx(struct vm_area_struct *vma)
atomic_inc(&mm->context.shared_ctx->refcount);
vma->vm_shared_mmu_ctx.ctx = mm->context.shared_ctx;
}
+
+unsigned long sparc64_pre_mmap_flags(struct file *file, unsigned long flags,
+ vm_flags_t *vm_flags)
+{
+ if (flags & MAP_SHAREDCTX) {
+ /* Must be a shared huge page mapping */
+ if (!(flags & (MAP_SHARED | MAP_FIXED)))
+ return -EINVAL;
+ if (!(flags & MAP_HUGETLB) &&
+ !(file && is_file_hugepages(file)))
+ return -EINVAL;
+
+ *vm_flags |= VM_SHARED_CTX;
+ }
+
+ return 0;
+}
+
+void sparc64_post_mmap(struct mm_struct *mm, unsigned long addr,
+ vm_flags_t vm_flags)
+{
+ if (vm_flags & VM_SHARED_CTX)
+ huge_get_shared_ctx(mm, addr);
+}
+
+void sparc64_exit_mmap(struct mm_struct *mm)
+{
+ put_shared_context(mm);
+}
+
+void sparc64_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ put_shared_context(mm);
+}
#endif
static int numa_enabled = 1;
diff --git a/include/uapi/linux/shm.h b/include/uapi/linux/shm.h
index 1fbf24e..3373567 100644
--- a/include/uapi/linux/shm.h
+++ b/include/uapi/linux/shm.h
@@ -49,6 +49,7 @@ struct shmid_ds {
#define SHM_RND 020000 /* round attach address to SHMLBA boundary */
#define SHM_REMAP 040000 /* take-over region on attach */
#define SHM_EXEC 0100000 /* execution access */
+#define SHM_SHAREDCTX 0200000 /* share context (TLB entries) if possible */
/* super user shmctl commands */
#define SHM_LOCK 11
--
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 ` [RFC PATCH 12/14] mm: add mmap and shmat arch hooks for shared context Mike Kravetz
2016-12-16 18:35 ` Mike Kravetz [this message]
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-14-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;
as well as URLs for NNTP newsgroup(s).