0

I am trying to monitor all times the PCIe stack writes configures to a device. In the absence of a PCI equivalent of usbmon, I thought to monitor all times the pci_bus_write_config_byte() function is called. I wanted to write a kernel module that essentially did this:

int (*original)(struct pci_bus *, unsigned int, int, u8);
original = &pci_bus_write_config_byte;
pci_bus_write_config_byte = &my_custom_func;

And then my custom function will printk() whatever data is passed, and return the original pci_bus_write_config_byte. However, when I load the module nothing happens. I suspect this is due to some sort of RW protection.

My google searches revealed that set_memory_rw() is supposed to make a function pointer writable, but I am not able to properly include it or use this function - when I go to insmod the module, the kernel says there are unknown symbols.

Any ideas on how one would do this?

Farhan Yusufzai
  • 297
  • 6
  • 23
  • Why not use [ftrace](https://www.kernel.org/doc/Documentation/trace/ftrace.txt) to trace all function calls to `pci_bus_write_config_byte`? – dirkt Mar 12 '17 at 06:57
  • I read a few guides on ftrace, but was not clear on how to configure it to do that. Can you give me a quick primer on that? – Farhan Yusufzai Mar 12 '17 at 18:20
  • I did `echo "pci_bus_write_config_byte" > set_ftrace_filter` and then did `cat trace_pipe`, while loading the kernel module in question. I know for certain it calls `pci_bus_write_config_byte`, but did not get anything outputted. – Farhan Yusufzai Mar 12 '17 at 21:49
  • My solution was to use systemtap. Its basically like Solaris's dtrace, but for Linux. I could never make heads or tales of ftrace. – Farhan Yusufzai Mar 14 '17 at 18:00
  • If you can writeup an overview of your solution as an answer, the next person with a similar problem will have it easier. – dirkt Mar 14 '17 at 18:33

0 Answers0