Re: 64-bit shm: abi problems

Manfred Spraul (manfreds@colorfullife.com)
Tue, 14 Dec 1999 10:00:17 +0100


This is a multi-part message in MIME format.
--------------55945C8BC6CDC262286403D4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Kanoj Sarcar wrote:
>
> Due to 64 bit padding of the shmid_ds structure fields, the size
> of the shmid_ds has _not_ changed. For >2Gb segments,
> IPC_STAT/SHM_STAT will report wrong (truncated) sizes, but that
> should be acceptable (this is an API breakage).
>

Could you please read the thread "2.3.31 - shm broken on Alpha"? The
current code fails on Alpha, ie we _must_ change it. There _is_ an ABI
problem. After I changed shmid_ds, the problem was gone.

- as I wrote Chris has prepared a patch for 32-bit uids. This patch adds
new structures and conversion functions. We will extend that field as
soon as we add that patch to the standard kernel.

- I added a new shmget64 because I don't know if we can assume that the
high bits are always zero. What if an optimizing compiler didn't
initialize them? Note that the new sysctl is not required for Sparc64:
the size variable is type size_t, and it's downcasted in
arch/sparc64/kernel/sys?.c

I've attached a new patch:
* fix shminfo
* change ipc/util.c, now the patch should compile with CONFIG_SYSVIPC
disabled.

--
	Manfred
--------------55945C8BC6CDC262286403D4
Content-Type: text/plain; charset=us-ascii;
 name="patch-shm64"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="patch-shm64"

// $Header: /pub/cvs/ms/patches/patch-shm64,v 1.2 1999/12/14 09:00:02 manfreds Exp $ // Kernel Version: // VERSION = 2 // PATCHLEVEL = 3 // SUBLEVEL = 31 // EXTRAVERSION = diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/include/asm-alpha/unistd.h build-2.3/include/asm-alpha/unistd.h --- 2.3/include/asm-alpha/unistd.h Wed Sep 1 18:22:46 1999 +++ build-2.3/include/asm-alpha/unistd.h Mon Dec 13 23:35:26 1999 @@ -310,6 +310,7 @@ #define __NR_sendfile 370 #define __NR_setresgid 371 #define __NR_getresgid 372 +#define __NR_shmget64 373 #if defined(__LIBRARY__) && defined(__GNUC__) diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/include/asm-i386/unistd.h build-2.3/include/asm-i386/unistd.h --- 2.3/include/asm-i386/unistd.h Wed Dec 8 23:17:19 1999 +++ build-2.3/include/asm-i386/unistd.h Mon Dec 13 23:34:32 1999 @@ -199,6 +199,18 @@ #define __NR_mmap2 192 #define __NR_truncate64 193 #define __NR_ftruncate64 194 +#define __NR_msgget 195 +#define __NR_msgctl 196 +#define __NR_msgsnd 197 +#define __NR_msgrcv 198 +#define __NR_semget 199 +#define __NR_semctl 200 +#define __NR_semop 201 +#define __NR_shmget64 202 +#define __NR_shmctl 203 +#define __NR_shmat 204 +#define __NR_shmdt 205 + /* user-visible error numbers are in the range -1 - -124: see <asm-i386/errno.h> */ diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/include/linux/shm.h build-2.3/include/linux/shm.h --- 2.3/include/linux/shm.h Sun Nov 7 10:20:50 1999 +++ build-2.3/include/linux/shm.h Tue Dec 14 09:52:14 1999 @@ -18,7 +18,7 @@ struct shmid_ds { struct ipc_perm shm_perm; /* operation perms */ - size_t shm_segsz; /* size of segment (bytes) */ + int shm_segsz; /* size of segment (bytes) */ __kernel_time_t shm_atime; /* last attach time */ __kernel_time_t shm_dtime; /* last detach time */ __kernel_time_t shm_ctime; /* last change time */ @@ -48,7 +48,7 @@ #define SHM_INFO 14 struct shminfo { - size_t shmmax; + int shmmax; int shmmin; int shmmni; int shmseg; @@ -70,7 +70,7 @@ #define SHM_DEST 01000 /* segment will be destroyed on last detach */ #define SHM_LOCKED 02000 /* segment will not be swapped */ -asmlinkage long sys_shmget (key_t key, size_t size, int flag); +asmlinkage long sys_shmget64 (key_t key, size_t size, int flag); asmlinkage long sys_shmat (int shmid, char *shmaddr, int shmflg, unsigned long *addr); asmlinkage long sys_shmdt (char *shmaddr); asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds *buf); diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/ipc/shm.c build-2.3/ipc/shm.c --- 2.3/ipc/shm.c Wed Dec 8 23:17:05 1999 +++ build-2.3/ipc/shm.c Tue Dec 14 09:56:51 1999 @@ -32,6 +32,7 @@ struct shmid_kernel /* extend struct shmis_ds with private fields */ { struct shmid_ds u; + size_t real_segsz; unsigned long shm_npages; /* size of segment (pages) */ pte_t **shm_dir; /* ptr to array of ptrs to frames -> SHMMAX */ struct vm_area_struct *attaches; /* descriptors for attaches */ @@ -89,7 +90,6 @@ /* some statistics */ static ulong swap_attempts = 0; static ulong swap_successes = 0; -static ulong used_segs = 0; void __init shm_init (void) { @@ -204,7 +204,11 @@ } shp->u.shm_perm.key = key; shp->u.shm_perm.mode = (shmflg & S_IRWXUGO); - shp->u.shm_segsz = size; + shp->real_segsz = size; + if(size < INT_MAX) + shp->u.shm_segsz = size; + else + shp->u.shm_segsz = INT_MAX; shp->u.shm_cpid = current->pid; shp->attaches = NULL; shp->u.shm_lpid = shp->u.shm_nattch = 0; @@ -220,7 +224,7 @@ return shm_buildid(id,shp->u.shm_perm.seq); } -asmlinkage long sys_shmget (key_t key, size_t size, int shmflg) +asmlinkage long sys_shmget64 (key_t key, size_t size, int shmflg) { struct shmid_kernel *shp; int err, id = 0; @@ -316,10 +320,15 @@ case IPC_INFO: { struct shminfo shminfo; + size_t shmmax; memset(&shminfo,0,sizeof(shminfo)); shminfo.shmmni = shminfo.shmseg = shm_ctlmni; - shminfo.shmmax = shm_ctlmax; + shmmax = shm_ctlmax; + if(shmmax < INT_MAX) + shminfo.shmmax = shmmax; + else + shminfo.shmmax = INT_MAX; shminfo.shmall = shm_ctlall; shminfo.shmmin = SHMMIN; @@ -337,7 +346,7 @@ memset(&shm_info,0,sizeof(shm_info)); shm_lockall(); - shm_info.used_ids = used_segs; + shm_info.used_ids = shm_ids.in_use; shm_info.shm_rss = shm_rss; shm_info.shm_tot = shm_tot; shm_info.shm_swp = shm_swp; @@ -566,7 +575,7 @@ err = -ENOMEM; addr = 0; again: - if (!(addr = get_unmapped_area(addr, (unsigned long)shp->u.shm_segsz))) + if (!(addr = get_unmapped_area(addr, (unsigned long)shp->real_segsz))) goto out_unlock_up; if(addr & (SHMLBA - 1)) { addr = (addr + (SHMLBA - 1)) & ~(SHMLBA - 1); @@ -593,7 +602,7 @@ if (addr < current->mm->start_stack && addr > current->mm->start_stack - PAGE_SIZE*(shp->shm_npages + 4)) goto out_unlock_up; - if (!(shmflg & SHM_REMAP) && find_vma_intersection(current->mm, addr, addr + (unsigned long)shp->u.shm_segsz)) + if (!(shmflg & SHM_REMAP) && find_vma_intersection(current->mm, addr, addr + (unsigned long)shp->real_segsz)) goto out_unlock_up; shm_unlock(shmid); @@ -957,7 +966,7 @@ shp->u.shm_perm.key, shm_buildid(i, shp->u.shm_perm.seq), shp->u.shm_perm.mode, - shp->u.shm_segsz, + shp->real_segsz, shp->u.shm_cpid, shp->u.shm_lpid, shp->u.shm_nattch, diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/ipc/util.c build-2.3/ipc/util.c --- 2.3/ipc/util.c Wed Dec 8 23:17:05 1999 +++ build-2.3/ipc/util.c Tue Dec 14 09:53:30 1999 @@ -255,7 +255,7 @@ return -ENOSYS; } -asmlinkage long sys_shmget (key_t key, size_t size, int shmflag) +asmlinkage long sys_shmget64 (key_t key, size_t size, int shmflag) { return -ENOSYS; } diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/arch/i386/kernel/entry.S build-2.3/arch/i386/kernel/entry.S --- 2.3/arch/i386/kernel/entry.S Wed Dec 8 23:17:11 1999 +++ build-2.3/arch/i386/kernel/entry.S Mon Dec 13 23:45:24 1999 @@ -595,7 +595,18 @@ .long SYMBOL_NAME(sys_mmap2) .long SYMBOL_NAME(sys_truncate64) .long SYMBOL_NAME(sys_ftruncate64) - /* 195 */ + .long SYMBOL_NAME(sys_msgget) + .long SYMBOL_NAME(sys_msgctl) + .long SYMBOL_NAME(sys_msgsnd) + .long SYMBOL_NAME(sys_msgrcv) + .long SYMBOL_NAME(sys_semget) + .long SYMBOL_NAME(sys_semctl) /* 200 */ + .long SYMBOL_NAME(sys_semop) + .long SYMBOL_NAME(sys_shmget64) + .long SYMBOL_NAME(sys_shmctl) + .long SYMBOL_NAME(sys_shmat) + .long SYMBOL_NAME(sys_shmdt) + /* 206 */ /* * NOTE!! This doesn't have to be exact - we just have @@ -603,6 +614,6 @@ * entries. Don't panic if you notice that this hasn't * been shrunk every time we add a new system call. */ - .rept NR_syscalls-194 + .rept NR_syscalls-205 .long SYMBOL_NAME(sys_ni_syscall) .endr diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/arch/i386/kernel/sys_i386.c build-2.3/arch/i386/kernel/sys_i386.c --- 2.3/arch/i386/kernel/sys_i386.c Wed Dec 8 23:17:11 1999 +++ build-2.3/arch/i386/kernel/sys_i386.c Mon Dec 13 23:47:09 1999 @@ -201,7 +201,7 @@ case SHMDT: return sys_shmdt ((char *)ptr); case SHMGET: - return sys_shmget (first, second, third); + return sys_shmget64 (first, second, third); case SHMCTL: return sys_shmctl (first, second, (struct shmid_ds *) ptr); diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/arch/alpha/kernel/entry.S build-2.3/arch/alpha/kernel/entry.S --- 2.3/arch/alpha/kernel/entry.S Wed Sep 1 18:22:16 1999 +++ build-2.3/arch/alpha/kernel/entry.S Mon Dec 13 23:40:03 1999 @@ -1149,3 +1149,4 @@ .quad sys_sendfile /* 370 */ .quad sys_setresgid .quad sys_getresgid + .quad sys_shmget64 diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/arch/alpha/kernel/osf_sys.c build-2.3/arch/alpha/kernel/osf_sys.c --- 2.3/arch/alpha/kernel/osf_sys.c Tue Aug 10 09:53:54 1999 +++ build-2.3/arch/alpha/kernel/osf_sys.c Mon Dec 13 23:44:01 1999 @@ -31,6 +31,7 @@ #include <linux/shm.h> #include <linux/poll.h> #include <linux/file.h> +#include <linux/shm.h> #include <asm/fpu.h> #include <asm/io.h> @@ -1442,3 +1443,9 @@ return ret; } + +asmlinkage long sys_shmget (key_t key, int size, int flag) +{ + return sys_shmget64(key,size,flag) +} +

--------------55945C8BC6CDC262286403D4--

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/