aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2012-07-30 17:42:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-30 20:25:20 -0400
commit079a96ae3871f0ed9083aac2218136ccec5b9877 (patch)
tree52acdeda67006d3d85eee0a17d6241657ba270dc
parent63dca8d5b5ef7effb58b8d6892a024125c0fab0b (diff)
ipc: add COMPAT_SHMLBA support
If the SHMLBA definition for a native task differs from the definition for a compat task, the do_shmat() function would need to handle both. This patch introduces COMPAT_SHMLBA, which is used by the compat shmat syscall when calling the ipc code and allows architectures such as AArch64 (where the native SHMLBA is 64k but the compat (AArch32) definition is 16k) to provide the correct semantics for compat IPC system calls. Cc: David S. Miller <davem@davemloft.net> Cc: Chris Zankel <chris@zankel.net> Cc: Arnd Bergmann <arnd@arndb.de> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/sparc/kernel/sys_sparc_64.c2
-rw-r--r--arch/xtensa/kernel/syscall.c2
-rw-r--r--include/linux/shm.h6
-rw-r--r--ipc/compat.c8
-rw-r--r--ipc/shm.c9
-rw-r--r--ipc/syscall.c2
6 files changed, 18 insertions, 11 deletions
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index c38e5aaae56f..0dc1f5786081 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -470,7 +470,7 @@ SYSCALL_DEFINE6(sparc_ipc, unsigned int, call, int, first, unsigned long, second
470 switch (call) { 470 switch (call) {
471 case SHMAT: { 471 case SHMAT: {
472 ulong raddr; 472 ulong raddr;
473 err = do_shmat(first, ptr, (int)second, &raddr); 473 err = do_shmat(first, ptr, (int)second, &raddr, SHMLBA);
474 if (!err) { 474 if (!err) {
475 if (put_user(raddr, 475 if (put_user(raddr,
476 (ulong __user *) third)) 476 (ulong __user *) third))
diff --git a/arch/xtensa/kernel/syscall.c b/arch/xtensa/kernel/syscall.c
index 816e6d0d686c..05b3f093d5d7 100644
--- a/arch/xtensa/kernel/syscall.c
+++ b/arch/xtensa/kernel/syscall.c
@@ -44,7 +44,7 @@ asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg)
44 unsigned long ret; 44 unsigned long ret;
45 long err; 45 long err;
46 46
47 err = do_shmat(shmid, shmaddr, shmflg, &ret); 47 err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
48 if (err) 48 if (err)
49 return err; 49 return err;
50 return (long)ret; 50 return (long)ret;
diff --git a/include/linux/shm.h b/include/linux/shm.h
index 92808b86703b..edd086883ccb 100644
--- a/include/linux/shm.h
+++ b/include/linux/shm.h
@@ -107,12 +107,14 @@ struct shmid_kernel /* private to the kernel */
107#define SHM_NORESERVE 010000 /* don't check for reservations */ 107#define SHM_NORESERVE 010000 /* don't check for reservations */
108 108
109#ifdef CONFIG_SYSVIPC 109#ifdef CONFIG_SYSVIPC
110long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr); 110long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr,
111 unsigned long shmlba);
111extern int is_file_shm_hugepages(struct file *file); 112extern int is_file_shm_hugepages(struct file *file);
112extern void exit_shm(struct task_struct *task); 113extern void exit_shm(struct task_struct *task);
113#else 114#else
114static inline long do_shmat(int shmid, char __user *shmaddr, 115static inline long do_shmat(int shmid, char __user *shmaddr,
115 int shmflg, unsigned long *addr) 116 int shmflg, unsigned long *addr,
117 unsigned long shmlba)
116{ 118{
117 return -ENOSYS; 119 return -ENOSYS;
118} 120}
diff --git a/ipc/compat.c b/ipc/compat.c
index a6df704f521e..53cebdf80e3c 100644
--- a/ipc/compat.c
+++ b/ipc/compat.c
@@ -514,6 +514,10 @@ long compat_sys_msgctl(int first, int second, void __user *uptr)
514 return err; 514 return err;
515} 515}
516 516
517#ifndef COMPAT_SHMLBA
518#define COMPAT_SHMLBA SHMLBA
519#endif
520
517#ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC 521#ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
518long compat_sys_shmat(int first, int second, compat_uptr_t third, int version, 522long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
519 void __user *uptr) 523 void __user *uptr)
@@ -524,7 +528,7 @@ long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
524 528
525 if (version == 1) 529 if (version == 1)
526 return -EINVAL; 530 return -EINVAL;
527 err = do_shmat(first, uptr, second, &raddr); 531 err = do_shmat(first, uptr, second, &raddr, COMPAT_SHMLBA);
528 if (err < 0) 532 if (err < 0)
529 return err; 533 return err;
530 uaddr = compat_ptr(third); 534 uaddr = compat_ptr(third);
@@ -536,7 +540,7 @@ long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg)
536 unsigned long ret; 540 unsigned long ret;
537 long err; 541 long err;
538 542
539 err = do_shmat(shmid, compat_ptr(shmaddr), shmflg, &ret); 543 err = do_shmat(shmid, compat_ptr(shmaddr), shmflg, &ret, COMPAT_SHMLBA);
540 if (err) 544 if (err)
541 return err; 545 return err;
542 force_successful_syscall_return(); 546 force_successful_syscall_return();
diff --git a/ipc/shm.c b/ipc/shm.c
index 41c1285d697a..00faa05cf72a 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -953,7 +953,8 @@ out:
953 * "raddr" thing points to kernel space, and there has to be a wrapper around 953 * "raddr" thing points to kernel space, and there has to be a wrapper around
954 * this. 954 * this.
955 */ 955 */
956long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr) 956long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
957 unsigned long shmlba)
957{ 958{
958 struct shmid_kernel *shp; 959 struct shmid_kernel *shp;
959 unsigned long addr; 960 unsigned long addr;
@@ -973,9 +974,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
973 if (shmid < 0) 974 if (shmid < 0)
974 goto out; 975 goto out;
975 else if ((addr = (ulong)shmaddr)) { 976 else if ((addr = (ulong)shmaddr)) {
976 if (addr & (SHMLBA-1)) { 977 if (addr & (shmlba - 1)) {
977 if (shmflg & SHM_RND) 978 if (shmflg & SHM_RND)
978 addr &= ~(SHMLBA-1); /* round down */ 979 addr &= ~(shmlba - 1); /* round down */
979 else 980 else
980#ifndef __ARCH_FORCE_SHMLBA 981#ifndef __ARCH_FORCE_SHMLBA
981 if (addr & ~PAGE_MASK) 982 if (addr & ~PAGE_MASK)
@@ -1107,7 +1108,7 @@ SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg)
1107 unsigned long ret; 1108 unsigned long ret;
1108 long err; 1109 long err;
1109 1110
1110 err = do_shmat(shmid, shmaddr, shmflg, &ret); 1111 err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
1111 if (err) 1112 if (err)
1112 return err; 1113 return err;
1113 force_successful_syscall_return(); 1114 force_successful_syscall_return();
diff --git a/ipc/syscall.c b/ipc/syscall.c
index 1d6f53f6b562..0d1e32ce048e 100644
--- a/ipc/syscall.c
+++ b/ipc/syscall.c
@@ -73,7 +73,7 @@ SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
73 default: { 73 default: {
74 unsigned long raddr; 74 unsigned long raddr;
75 ret = do_shmat(first, (char __user *)ptr, 75 ret = do_shmat(first, (char __user *)ptr,
76 second, &raddr); 76 second, &raddr, SHMLBA);
77 if (ret) 77 if (ret)
78 return ret; 78 return ret;
79 return put_user(raddr, (unsigned long __user *) third); 79 return put_user(raddr, (unsigned long __user *) third);