All of lore.kernel.org
 help / color / mirror / Atom feed
* mmap(/dev/mem) causing sigbus
@ 2005-01-13 23:12 Tom Duffy
  2005-01-13 23:29 ` David S. Miller
  2005-01-14 22:30 ` [openib-general] " Tom Duffy
  0 siblings, 2 replies; 3+ messages in thread
From: Tom Duffy @ 2005-01-13 23:12 UTC (permalink / raw)
  To: sparclinux


[-- Attachment #1.1: Type: text/plain, Size: 1383 bytes --]

It seems that there is an issue with either mmap or mmap'ing /dev/mem on
sparc64.  A tool (mstflint) for flashing firmware for Mellanox
Infiniband HCA's is crashing on sparc64.  It mmap's /dev/mem and when it
accesses it, a bus error is generated.

Should this work?

Attached is a small test program to demonstrate.  Change BAR0 to
something in your PCI address space (grab an address from /proc/iomem).

# cat /proc/iomem
<snip>
  1ff00100000-1ff001fffff : 0000:81:00.0
    1ff00180680-1ff0018070f : ib_mthca
    1ff001f00d8-1ff001f00df : ib_mthca
  1ff00800000-1ff00ffffff : 0000:81:00.0
    1ff00800000-1ff00ffffff : ib_mthca
  1ff08000000-1ff0fffffff : 0000:81:00.0

# gdb ./mmap-test
(gdb) run
Starting program: /root/mmap-test
warning: linux_test_for_tracefork: unexpected result from waitpid (3298, status 0xb7f)

Program received signal SIGBUS, Bus error.
0x00010630 in main () at mmap-test.c:29
29              value= *( (unsigned*)(ptr + 0x000f0014) );
(gdb) print ptr
$1 = (void *) 0x7018c000
(gdb) print ptr + 0x000f0014
$2 = (void *) 0x7027c014
(gdb) x 0x7027c014
0x7027c014:     Cannot access memory at address 0x7027c014

# cat /proc/3317/maps
<snip>
7018c000-7028c000 rw-s 1ff00100000 00:0d 316                             /dev/mem

# uname -a
Linux tat 2.6.10 #14 SMP Mon Jan 3 12:30:51 PST 2005 sparc64 GNU/Linux

-tduffy

[-- Attachment #1.2: mmap-test.c --]
[-- Type: text/x-csrc, Size: 659 bytes --]

#define BAR0 0x1ff00100000ull
#define _XOPEN_SOURCE 500
#define _FILE_OFFSET_BITS 64
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main()
{
	int fd;
	void *ptr;
	unsigned value;
	unsigned long long offset = BAR0;
	fd = open("/dev/mem",O_RDWR | O_SYNC);
	if (fd<0) {
		perror("open");
		return 1;
	}

	ptr = mmap(NULL, 0x100000, PROT_READ | PROT_WRITE,
			MAP_SHARED, fd, offset);

	if ( (! ptr) || (ptr == MAP_FAILED) ) {
		perror("map");
		return 1;
	}

	value= *( (unsigned*)(ptr + 0x000f0014) );
	
	printf("value at 0x000f0014 is %#8.8x\n", value);

	return 0;
err:
	return 1;
}


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: mmap(/dev/mem) causing sigbus
  2005-01-13 23:12 mmap(/dev/mem) causing sigbus Tom Duffy
@ 2005-01-13 23:29 ` David S. Miller
  2005-01-14 22:30 ` [openib-general] " Tom Duffy
  1 sibling, 0 replies; 3+ messages in thread
From: David S. Miller @ 2005-01-13 23:29 UTC (permalink / raw)
  To: sparclinux

On Thu, 13 Jan 2005 15:12:14 -0800
Tom Duffy <tomduffy@dslextreme.com> wrote:

> It seems that there is an issue with either mmap or mmap'ing /dev/mem on
> sparc64.  A tool (mstflint) for flashing firmware for Mellanox
> Infiniband HCA's is crashing on sparc64.  It mmap's /dev/mem and when it
> accesses it, a bus error is generated.
> 
> Should this work?

It's not meant to be used at all.  We have abstracted out a way
to portably mmap() pci devices by opening /proc/bus/pci/* nodes,
running the appropriate ioctl() to choose I/O or MEM space,
then mmap()'ing on the fd to mmap the PCI device resources.

At the very least, i386 and ppc support this interface as well.

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

* Re: [openib-general] Re: mmap(/dev/mem) causing sigbus
  2005-01-13 23:12 mmap(/dev/mem) causing sigbus Tom Duffy
  2005-01-13 23:29 ` David S. Miller
@ 2005-01-14 22:30 ` Tom Duffy
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Duffy @ 2005-01-14 22:30 UTC (permalink / raw)
  To: sparclinux

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

On Thu, 2005-01-13 at 15:29 -0800, David S. Miller wrote:
> It's not meant to be used at all.  We have abstracted out a way
> to portably mmap() pci devices by opening /proc/bus/pci/* nodes,
> running the appropriate ioctl() to choose I/O or MEM space,
> then mmap()'ing on the fd to mmap the PCI device resources.
> 
> At the very least, i386 and ppc support this interface as well.

Dave, thanks for the info.  The maintainer of the tool has updated it to
use the /proc/bus/pci method.

-tduffy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2005-01-14 22:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-13 23:12 mmap(/dev/mem) causing sigbus Tom Duffy
2005-01-13 23:29 ` David S. Miller
2005-01-14 22:30 ` [openib-general] " Tom Duffy

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.