LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 06-22-2017, 08:08 AM   #1
fdumoulin
LQ Newbie
 
Registered: Jun 2017
Posts: 2

Rep: Reputation: Disabled
PCIe rescan from kernel device driver


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
 
Old 06-27-2017, 08:42 AM   #2
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
Hi & Welcome to LQ. Sorry you didn't get an answer yet (maybe because such a specialized topic).

Maybe you could make a SUID-root pgm/script (to write to /sys/bus/pci) [?]

A web-search of that function (plus the word "my", to get someone's use of it) finds a few, e.g.:
https://community.nxp.com/thread/305355

Any new progress over the past week? Best wishes!
 
Old 06-27-2017, 09:57 AM   #3
fdumoulin
LQ Newbie
 
Registered: Jun 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi,

Thanks Jjanel for your suggestion but I'd like to avoid suid-root scripts for security reasons.

If it's not possible to call rescan functions from my own module, may it be possible to write to /sys/bus/pci/devices/xxx/remove + /sys/bus/pci/rescan from the module ?


Regards,
Fred
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux PCIE and PCI device driver difference? ningzhanghnu Linux - General 2 03-04-2012 10:30 AM
[SOLVED] Device Driver Install PCIe card blackmagic010216 Linux - Newbie 4 06-30-2010 04:30 AM
Writing PCIe device driver pythonarms Linux - Kernel 0 02-23-2009 01:45 PM
Doubts about PCIe device driver rwpa Linux - Newbie 4 12-10-2008 08:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration