Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - [QNX7] pci_device_read_* segfaults, then hangs: (4 Items)
   
[QNX7] pci_device_read_* segfaults, then hangs  
Hello,

I am familiarising myself with the new pci-server of QNX7. That is why I wrote a tiny example tool that enumerates all 
PCI devices and reads the device ID, as follows:

//------------------------------------------------------
#include <stdio.h>

#include <pci/pci.h>
#include <pci/cap_pcie.h>

int main() {

  uint_t idx = 0;
  pci_bdf_t bdf;
  while ((bdf = pci_device_find(idx, PCI_VID_ANY, PCI_DID_ANY, PCI_CCODE_ANY)) != PCI_BDF_NONE)
  {
      /* get next device instance */
      printf("Found device %d\n", idx);

      pci_err_t err;
      pci_did_t did;
      err = pci_device_read_did(bdf, &did);

      ++idx;

  }

  printf("Exited main\n");
  return 0;
}
//------------------------------------------------------


The problem is that this program segfaults when I run it, here's the telnet output:

#
# /tmp/qnx7test_c
Found device 0

Process 213017 (qnx7test_c) terminated SIGSEGV code=4 fltno=2 ip=b822afa7(/lib/dll/pci/pci_hw-Intel_x86.so@hwmod_init+
0x00000207) mapaddr=00005fa7.
Memory fault (core dumped)
#
#


The "pci_device_read_did" command caused the segfault. When I run the program again, it simply blocks at the exact same 
place (no segfault anymore though!).

I am completely stumped, I have no idea what the problem could be.

Can anyone help me?

Best regards,
Benjamin
Re: [QNX7] pci_device_read_* segfaults, then hangs  
SIGSEGV/4/2 is a general protection fault. You are probably reading
from the wrong address.

--Elad

On Thu, 2018-01-25 at 09:21 -0500, Benjamin Richner wrote:
> Hello,
> 
> I am familiarising myself with the new pci-server of QNX7. That is
> why I wrote a tiny example tool that enumerates all PCI devices and
> reads the device ID, as follows:
> 
> //------------------------------------------------------
> #include <stdio.h>
> 
> #include <pci/pci.h>
> #include <pci/cap_pcie.h>
> 
> int main() {
> 
>   uint_t idx = 0;
>   pci_bdf_t bdf;
>   while ((bdf = pci_device_find(idx, PCI_VID_ANY, PCI_DID_ANY,
> PCI_CCODE_ANY)) != PCI_BDF_NONE)
>   {
>       /* get next device instance */
>       printf("Found device %d\n", idx);
> 
>       pci_err_t err;
>       pci_did_t did;
>       err = pci_device_read_did(bdf, &did);
> 
>       ++idx;
> 
>   }
> 
>   printf("Exited main\n");
>   return 0;
> }
> //------------------------------------------------------
> 
> 
> The problem is that this program segfaults when I run it, here's the
> telnet output:
> 
> #
> # /tmp/qnx7test_c
> Found device 0
> 
> Process 213017 (qnx7test_c) terminated SIGSEGV code=4 fltno=2
> ip=b822afa7(/lib/dll/pci/pci_hw-Intel_x86.so@hwmod_init+0x00000207)
> mapaddr=00005fa7.
> Memory fault (core dumped)
> #
> #
> 
> 
> The "pci_device_read_did" command caused the segfault. When I run the
> program again, it simply blocks at the exact same place (no segfault
> anymore though!).
> 
> I am completely stumped, I have no idea what the problem could be.
> 
> Can anyone help me?
> 
> Best regards,
> Benjamin
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post118465
> To cancel your subscription to this discussion, please e-mail ostech-
> core_os-unsubscribe@community.qnx.com
Re: [QNX7] pci_device_read_* segfaults, then hangs  
Thank you for you reply, Elad Lahav.

So, how can it happen I'm reading from the wrong address? bdf is a direct, valid result from pci_device_find. The 
library pci_hw-Intel_x86.so exists and is at the specified path. All I'm doing is use pci_device_read_did. I have no 
influence over what kinds of reads this function does - that's closed source QNX code.

So I'm afraid I still do not understand how to fix this.
Re: [QNX7] pci_device_read_* segfaults, then hangs  
I found it out. My program first had to gain the rights to do PCI IO, using the line

ThreadCtl(_NTO_TCTL_IO, 0);

That was it. It's no longer segfaulting. *facepalm*

However, I do think it's weird that an application that does not do this can lock up the entire pci server. I consider 
that a bug.