On Sat, Jun 05, 2021 at 10:02:05AM +0800, Huacai Chen wrote: > On Sat, Jun 5, 2021 at 3:56 AM Bjorn Helgaas <helgaas@xxxxxxxxxx> wrote: > > On Fri, Jun 04, 2021 at 12:50:03PM +0800, Huacai Chen wrote: > > > On Thu, Jun 3, 2021 at 2:31 AM Bjorn Helgaas <bhelgaas@xxxxxxxxxx> wrote: > > > > I think the simplest solution, which I suggested earlier [1], > > > > would be to explicitly call vga_arbiter_add_pci_device() > > > > directly from the PCI core when it enumerates a VGA device. > > > > Then there's no initcall and no need for the > > > > BUS_NOTIFY_ADD/DEL_DEVICE stuff. vga_arbiter_add_pci_device() > > > > could set the default VGA device when it is enumerated, and > > > > change the default device if we enumerate a "better" one. And > > > > hotplug VGA devices would work automatically. > > > > > > Emm, It seems that your solution has some difficulties to remove > > > the whole initcall(vga_arb_device_init): we call > > > vga_arbiter_add_pci_device() in pci_bus_add_device(), the > > > list_for_each_entry() loop can be moved to > > > vga_arbiter_check_bridge_sharing(), > > > vga_arb_select_default_device() can be renamed to > > > vga_arb_update_default_device() and be called in > > > vga_arbiter_add_pci_device(), but how to handle > > > misc_register(&vga_arb_device)? > > > > Might need to keep vga_arb_device_init() as an initcall, but > > remove everything from it except the misc_register(). > > OK, let me try. But I think call vga_arbiter_add_pci_device() in > pci core is nearly the same as notifier. Anyway, I will send a new > patch later. Notifiers are useful in some situations, for example, if a loadable module needs to be called when a device is added or removed. But when possible, I will always choose a direct call instead because it's much less complicated. The VGA arbiter cannot be a loadable module, so I don't think there's any reason to use a notifier in this case. Bjorn