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
#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: signature.asc
Description: This is a digitally signed message part

_______________________________________________
openib-general mailing list
[email protected]
http://openib.org/mailman/listinfo/openib-general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to