All of lore.kernel.org
 help / color / mirror / Atom feed
* Linux Shared Memory Issue
@ 2002-04-24 21:27 Maurice Turcotte
  2002-04-24 22:03 ` Jun Sun
  2002-04-25 15:36 ` Florian Lohoff
  0 siblings, 2 replies; 14+ messages in thread
From: Maurice Turcotte @ 2002-04-24 21:27 UTC (permalink / raw)
  To: linux-mips; +Cc: Maurice Turcotte

Greetings:

I am having a problem with Linux Kernel 2.4.5 on a mips.

I have two processes using share memory for IPC. This same
code works fine with Kernel 2.4.7 on a x86. The problem is 
that the second process reads old data out of the shared
memory.

The executive summary->

Process #1 writes "A" to shared memory at 0x2aac7210
Process #2 reads 0 from shared memory at address 0x2aaca210
Process #1 writes "B" to shared memory at 0x2aac7210
Process #2 read "A" from shared memory at address 0x2aaca210
Process #1 writes "C" to shared memory at 0x2aac7210
Process #2 read "B" from shared memory at address 0x2aaca210

It is interesting that the processes get different addresses
associated with the same shmId. I assume this is because of 
some user-space mapping that is going on.

I left out the semaphore diddling, but I believe that part of
the code is correct because it works flawlessly on the 2.4.7 x86.

Any tips on debugging this would be greatly appreciated. If this
is not the proper forum for questions like this, please point me
in the right direction.

Thanks,

mturc

^ permalink raw reply	[flat|nested] 14+ messages in thread
* SysV IPC shared memory and virtual alising
@ 2001-08-06  7:44 Atsushi Nemoto
  2001-08-06  8:50 ` Dominic Sweetman
  2001-08-14  8:49 ` Ralf Baechle
  0 siblings, 2 replies; 14+ messages in thread
From: Atsushi Nemoto @ 2001-08-06  7:44 UTC (permalink / raw)
  To: linux-mips, linux-mips

[-- Attachment #1: Type: Text/Plain, Size: 297 bytes --]

Here is an patch to fix virtual aliasing problem with SysV IPC shared
memory.  I tested this patch on a r4k cpu with 32Kb D-cache.

If D-cache is smaller than PAGE_SIZE this patch is not needed at all,
but I think it is not so bad unconditionally forcing alignment to
SHMLBA.

---
Atsushi Nemoto


[-- Attachment #2: unmapped_area.patch --]
[-- Type: Text/Plain, Size: 2204 bytes --]

diff -ur linux.sgi/arch/mips/kernel/syscall.c linux/arch/mips/kernel/syscall.c
--- linux.sgi/arch/mips/kernel/syscall.c	Thu Apr  5 13:56:09 2001
+++ linux/arch/mips/kernel/syscall.c	Mon Aug  6 16:16:36 2001
@@ -30,6 +30,7 @@
 #include <asm/signal.h>
 #include <asm/stackframe.h>
 #include <asm/uaccess.h>
+#include <asm/shmparam.h>
 
 extern asmlinkage void syscall_trace(void);
 typedef asmlinkage int (*syscall_t)(void *a0,...);
@@ -91,6 +92,47 @@
 {
 	return do_mmap2(addr, len, prot, flags, fd, pgoff);
 }
+
+#ifdef HAVE_ARCH_UNMAPPED_AREA
+/* solve cache aliasing problem (see Documentation/cache.txt and
+   arch/sparc64/kernel/sys_sparc.c */
+#define COLOUR_ALIGN(addr)	(((addr)+SHMLBA-1)&~(SHMLBA-1))
+
+unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
+{
+	struct vm_area_struct * vmm;
+
+	if (flags & MAP_FIXED) {
+		/* We do not accept a shared mapping if it would violate
+		 * cache aliasing constraints.
+		 */
+		if ((flags & MAP_SHARED) && (addr & (SHMLBA - 1)))
+			return -EINVAL;
+		return addr;
+	}
+
+	if (len > TASK_SIZE)
+		return -ENOMEM;
+	if (!addr)
+		addr = TASK_UNMAPPED_BASE;
+
+	if (flags & MAP_SHARED)
+		addr = COLOUR_ALIGN(addr);
+	else
+		addr = PAGE_ALIGN(addr);
+
+	for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
+		/* At this point:  (!vmm || addr < vmm->vm_end). */
+		if (TASK_SIZE - len < addr)
+			return -ENOMEM;
+		if (!vmm || addr + len <= vmm->vm_start)
+			return addr;
+		addr = vmm->vm_end;
+		if (flags & MAP_SHARED)
+			addr = COLOUR_ALIGN(addr);
+	}
+}
+#endif /* HAVE_ARCH_UNMAPPED_AREA */
 
 save_static_function(sys_fork);
 static_unused int _sys_fork(struct pt_regs regs)
diff -ur linux.sgi/include/asm-mips/pgtable.h linux/include/asm-mips/pgtable.h
--- linux.sgi/include/asm-mips/pgtable.h	Sun Aug  5 23:41:28 2001
+++ linux/include/asm-mips/pgtable.h	Mon Aug  6 16:17:11 2001
@@ -740,6 +740,9 @@
 
 #include <asm-generic/pgtable.h>
 
+/* We provide our own get_unmapped_area to cope with VA holes for userland */
+#define HAVE_ARCH_UNMAPPED_AREA
+
 #endif /* !defined (_LANGUAGE_ASSEMBLY) */
 
 #define io_remap_page_range remap_page_range

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2002-05-07  6:47 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-24 21:27 Linux Shared Memory Issue Maurice Turcotte
2002-04-24 22:03 ` Jun Sun
2002-04-25  5:25   ` Atsushi Nemoto
2002-04-25 18:46     ` Jun Sun
2002-04-26  3:11       ` Atsushi Nemoto
2002-04-27 21:45   ` XSHM/shared-pixmap fix Was: " Florian Lohoff
2002-05-06 11:04     ` Maciej W. Rozycki
2002-04-25 15:36 ` Florian Lohoff
  -- strict thread matches above, loose matches on Subject: below --
2001-08-06  7:44 SysV IPC shared memory and virtual alising Atsushi Nemoto
2001-08-06  8:50 ` Dominic Sweetman
2001-08-14  8:24   ` Ralf Baechle
2001-08-14  8:49 ` Ralf Baechle
2001-08-16  3:04   ` Atsushi Nemoto
2002-05-07  6:48   ` XSHM/shared-pixmap fix Was: Linux Shared Memory Issue Atsushi Nemoto

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.