How to handle Hotplug with UIO userspace driver

Greg KH greg at kroah.com
Wed Nov 26 14:50:01 EST 2014


On Wed, Nov 26, 2014 at 11:27:07AM -0800, Mandeep Sandhu wrote:
> 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.

You should just get 0xff on the memory reads, right?  You can catch the
signal for invalid memory accesses.

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

Your kernel driver knows when the device is removed, so have it tell
userspace this.  Or, just tie into libudev and have your userspace
program be notified when the device goes away.

Do you have a pointer to the source of your uio kernel driver anywhere?

thanks,

greg k-h



More information about the Kernelnewbies mailing list