Debian Codegraph @

contrib/pci_traffic/README

raw
1 INTRODUCTION
2 ============
3 Sometimes, it is useful to check what the driver is doing with
4 the PCI registers.
5
6 As it took me some time to get the right info from the Intenet,
7 and to write a few patches to enable debug, and to write them
8 to a file, I'm documenting here the procedure I used, as it
9 may be useful for the others.
10
11 One of the ways to see what a driver is doing with PCI registers
12 is to write several debug printk's. Another way is to enable PCI
13 device access at a VM machine, and catch the PCI emulation logs.
14
15 To use the second case, one of the ways is to modify the qemu-kvm
16 package. In my case, I wrote some patches for
17 qemu-kvm-0.12.1.2-2.113.el6.x86_64 (shipped with RHEL6), but they
18 probably apply on other versions of qemu.
19
20 Be careful: in order to get the PCI writes, the patches I'm using
21 intercepts all calls to PCI write/read to the mapped devices. This
22 is slow, and may cause machine hangs. If you're willing to use it,
23 you'll likely need to do on a separate machine, used just for
24 tests. On my test machine, they work fine for digital TV, but hangs
25 the machine with analog TV (probably because digital streams use
26 compressed traffic).
27
28 PATCHES FOR QEMU-KVM
29 ====================
30
31 There are a few patches that are needed to allow getting a kvm log
32 from the PCI traffic.
33
34 The patches should be applied on this order:
35
36 kvm-allow-assigned-different-than-4K.patch
37 kvm-dev-assign-debug.patch
38 write_log_to_file.patch
39
40 1) kvm-allow-assigned-different-than-4K.patch
41
42 This patch came from qemu-kvm git tree. It will likely be available
43 on some stable version soon. It is needed for some devices.
44
45 2) kvm-dev-assign-debug.patch
46 This patch were written by me. It basically enables some debug
47 logs. It is licensed with GPLv2;
48
49 3) write_log_to_file.patch
50
51 This patch were written by me. It changes the debug logic to write
52 logs on a file, instead of stderr. The file is: /var/log/qemu_hw_pci.log.
53 You'll need to create it previously, change its ownership to match
54 qemu user, and fix selinux permissions (if you're using selinux).
55 In the case of RHEL6, I'm using:
56
57 -rw-r--r--. qemu qemu system_u:system_r:svirt_t:s0 qemu_hw_pci.log
58
59 IRQ CONFLICTS
60 =============
61
62 You need to be sure that IRQ's are not shared between the device you
63 want to sniff and any other device, otherwise, kvm won't allow you
64 to see the physical device. This is (currently) a kvm restriction.
65
66 You may check it by looking at /proc/interrupts.
67
68 In my case, ehci_hcd and uhci_hcd shares interrrupts with devices I
69 plug on my PCI slots. So, I wrote a script to disconnect all USB buses
70 from my test machine. The script is:
71
72 disconnect_usb.sh
73
74 MAPPING THE PHYSICAL DEVICE ON QEMU
75 ===================================
76
77 You'll need to use an option for KVM to map the PCI device at the
78 machine. In my case, I'm using those lines:
79
80 -device pci-assign,host=37:09.0,id=hostdev0,configfd=22,bus=pci.0,addr=0x6
81 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
82
83 The actual line depends on the PCI device that you're using. The above
84 example assumes a device at PCI address 37:09.0.
85
86 You may also use virt-manager to configure physical access to your PCI
87 device.
88
89 I hope this may be useful for you.
90 Mauro Carvalho Chehab <[email protected]>