mmap to PCI bars fails in SLES15 OS.

I am trying to do mmap to PCI CSR bar. mmap fails with error EINVAL. The value obtained for sb.st_size is 65536. But mmap failed with error string “Invalid argument”. The same code snippet works fine in RHEL 7.2 but fails in SLES15 operating system. Below is my code snippet.



snprintf(csr_bar_path,256,"/sys/bus/pci/devices/0000:16:00.0/resource2");
csr_fd = open(csr_bar_path,O_RDWR | O_SYNC);
if(csr_fd < 0)
{
    printf("Cannot open CSR bar file %s
",csr_bar_path);
}
if(fstat(csr_fd,&sb) == -1)
{
    printf("CSR file size = %d
",sb.st_size);
    close(csr_fd);
}
printf("CSR file size OK = %d
",sb.st_size);
csr_bar = (unsigned char *)mmap(NULL,sb.st_size,PROT_READ | 
                                  PROT_WRITE,MAP_SHARED,csr_fd,0);
if(csr_bar == (void *) -1)
{
    printf("mmap failed for CSR bar %s %d
",strerror(errno),errno);
    close(csr_fd);
}

While it is possible that your code is so generic that it also fits other operating systems, I think you should be aware that these here are the openSUSE forums and not the SLES/SLED forums.

They are at https://forums.suse.com/forum.php , same username/password as here.

There is likely some confusion here.

AFAIK SUSE latest version is SUSE 12 SP3
while
openSUSE 15 is launching shortly.

TSU

Regarding your code snippet,
It’s never enough to say simply that code “fails.”
The way and at what point the code fails is always telling.

So,
If you’re coding in an IDE you can generally insert breakpoints.
If you’re not coding in an IDE, then you may have to insert temporary code that instruments what is happening at a more detailed level.
So, for instance I see I see several statements that require a number of parameters to be true, you may have to check that each are not null.

HTH,
TSU

On Tue 22 May 2018 01:46:02 PM CDT, tsu2 wrote:

There is likely some confusion here.

AFAIK SUSE latest version is SUSE 12 SP3
while
openSUSE 15 is launching shortly.

TSU

Hi
SLES 15 is still in beta (see my signature) but due out soon… OP
should post in the Beta Mailing List…


Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
SLES 15 RC4 | GNOME Shell 3.26.2 | 4.12.14-18-default
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below… Thanks!