How to handle Hotplug with UIO userspace driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,

We're working on a custom PCIe based hardware, which can be hotplugged into the system.

We're using the UIO approach of having a minimal kernel driver which basically handles the interrupt and provides a mmap of the device memory to userspace and userspace driver which mmap's the provided memory and manages the device.

We're using systemd and udev rules to spawn off a user process whenever the hardware is plugged into the system.

Now my question is, how can we gracefully inform the userspace process if someone pulls out the hardware (sitting on a PCI slot). Even with full hotplug support, there can always be a case of "surprise removal", where someone yanks the board without going through the whole "attention button" routine.

While the kernel driver has no problem with hot-removal, I see that if I "unregister" our UIO driver in response to the removal, then the mapping for the hardware's physical memory would become "invalid" (done by UIO on unregsiter). This could possibly cause the user-space process to crash due to illegal memory access.

Is there a "standard" way to handle this scenario, i.e for hotpluggable hardware using UIO?

Basically, we'd want to "unregister" the UIO device only after the userspace process is informed of the removal so that it could unmap/close the device and exit gracefully.

We could try doing it using some systemd trick, where we put a dependency on one of the UIO created files (/dev/uioX), so that when the file is destroyed, systemd could kill/shutdown the process. Although, there's no guarantee that the userspace process won't try to access the mmaped space during that interval, so this isn't a reliable solution either.

Any hints, thoughts?

Thanks.,
-mandeep

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux