Hi,
I've got a PCIe board with a FPGA and my own kernel device driver.
When the FPGA is loaded, I need to rescan the PCIe tree.
I used the regular /sys/bus/pci/devices/xxx/remove + /sys/bus/pci/rescan to do that.
The access to these file must be done with root privileges and it could be a pain for my users.
Is it possible to do the rescan from my kernel device driver ?
I tried to call pci_remove_bus () + pci_rescan_bus () in the open call but I've got a kernel panic:
Code:
[ 245.469829] pci_bus 0000:01: busn_res: [bus 01] is released
[ 245.469883] BUG: unable to handle kernel NULL pointer dereference at 00000000000000d0
[ 245.469887] IP: [<ffffffff81400d36>] pci_proc_detach_bus+0x6/0x20
[ 245.469893] PGD 87c9f067 PUD 87d63067 PMD 0
[ 245.469897] Oops: 0000 [#1] SMP
[ 245.469899] Modules linked in: zebra(OE) nfsv3 rpcsec_gss_krb5 nfsv4 nvidia_modeset(POE) autofs4 bnep rfcomm bluetooth nfsd auth_rpcgss nfs_acl nfs lockd grace sunrpc fscache nvidia(POE) nls_iso8859_1 snd_hda_codec_hdmi input_leds joydev snd_hda_codec_realtek snd_hda_codec_generic i915 drm_kms_helper i2c_algo_bit snd_hda_intel snd_hda_codec dell_wmi snd_hda_core sparse_keymap snd_hwdep dcdbas dell_smm_hwmon intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp snd_pcm snd_seq_midi kvm_intel snd_seq_midi_event kvm crct10dif_pclmul crc32_pclmul snd_rawmidi aesni_intel aes_x86_64 snd_seq lrw gf128mul glue_helper ablk_helper cryptd snd_seq_device snd_timer drm snd mipso(OE) serio_raw soundcore shpchp mei_me mei wmi 8250_fintek video pinctrl_sunrisepoint pinctrl_intel intel_lpss_acpi intel_lpss i2c_hid acpi_pad mac_hid acpi_als kfifo_buf industrialio parport_pc ppdev lp parport hid_generic usbhid hid e1000e psmouse ptp ahci pps_core libahci [last unloaded: zebra]
[ 245.469946] CPU: 0 PID: 2542 Comm: zebra_tools Tainted: P OE 4.2.0-36-generic #42~14.04.1-Ubuntu
[ 245.469948] Hardware name: Dell Inc. Precision Tower 3620/09WH54, BIOS 1.3.2 01/25/2016
[ 245.469949] task: ffff88008a080000 ti: ffff880087d4c000 task.ti: ffff880087d4c000
[ 245.469951] RIP: 0010:[<ffffffff81400d36>] [<ffffffff81400d36>] pci_proc_detach_bus+0x6/0x20
[ 245.469955] RSP: 0018:ffff880087d4fb88 EFLAGS: 00010292
[ 245.469956] RAX: ffff880251b00000 RBX: 0000000000000000 RCX: 0000000000000000
[ 245.469958] RDX: 00000000000001ff RSI: 0000000000019a20 RDI: 0000000000000000
[ 245.469959] RBP: ffff880087d4fba8 R08: ffff880263f11718 R09: 00000001820001ff
[ 245.469960] R10: ffffea00098fc440 R11: ffffffff813ad855 R12: 0000000000000428
[ 245.469962] R13: ffff880260be14d8 R14: ffff880253e2e800 R15: 0000000000000000
[ 245.469963] FS: 00007f994cf4be00(0000) GS:ffff88026dc00000(0000) knlGS:0000000000000000
[ 245.469965] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 245.469967] CR2: 00000000000000d0 CR3: 0000000087d16000 CR4: 00000000003406f0
[ 245.469968] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 245.469969] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 245.469970] Stack:
[ 245.469972] ffff880087d4fba8 ffffffff813f30b6 0000000000000006 ffff88008a080000
[ 245.469975] ffff880087d4fc28 ffffffffc0395298 ffff88000000000c ffffffff0000001b
[ 245.469977] 0000000000000004 00000000000000f3 ffffffff811f25e0 00000000594bb798
[ 245.469980] Call Trace:
[ 245.469984] [<ffffffff813f30b6>] ? pci_remove_bus+0x16/0x80
[ 245.469988] [<ffffffffc0395298>] mpdd_open+0x138/0x170 [zebra]
[ 245.469992] [<ffffffff811f25e0>] ? mount_fs+0x160/0x160
[ 245.469995] [<ffffffff811f2f41>] chrdev_open+0xb1/0x190
[ 245.469998] [<ffffffff811ec487>] do_dentry_open+0x227/0x320
[ 245.470001] [<ffffffff811f2e90>] ? cdev_put+0x30/0x30
[ 245.470003] [<ffffffff811ed5a7>] vfs_open+0x57/0x60
[ 245.470006] [<ffffffff811fc1f1>] path_openat+0x1b1/0x1360
[ 245.470009] [<ffffffff811fe46a>] do_filp_open+0x7a/0xd0
[ 245.470012] [<ffffffff811fd57f>] ? getname_flags+0x4f/0x1f0
[ 245.470015] [<ffffffff8120b606>] ? __alloc_fd+0x46/0x110
[ 245.470018] [<ffffffff811ed919>] do_sys_open+0x129/0x270
[ 245.470020] [<ffffffff811eda7e>] SyS_open+0x1e/0x20
[ 245.470024] [<ffffffff817c35b2>] entry_SYSCALL_64_fastpath+0x16/0x75
[ 245.470025] Code: 89 fb 48 83 ec 08 48 8b 7f 28 e8 e6 aa e5 ff 48 c7 43 28 00 00 00 00 48 83 c4 08 31 c0 5b 5d c3 0f 1f 44 00 00 0f 1f 44 00 00 55 <48> 8b bf d0 00 00 00 48 89 e5 e8 bb aa e5 ff 31 c0 5d c3 0f 1f
[ 245.470053] RIP [<ffffffff81400d36>] pci_proc_detach_bus+0x6/0x20
[ 245.470056] RSP <ffff880087d4fb88>
[ 245.470058] CR2: 00000000000000d0
[ 245.470060] ---[ end trace a475d7aa7a8c58e9 ]---
Where can I find an example of pci_remove_bus () + pci_rescan_bus () use ?
Thanks,
Fred