<div dir="ltr">Hi All,<div><br></div><div>We&#39;re working on a custom PCIe based hardware, which can be hotplugged into the system.</div><div><br></div><div>We&#39;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&#39;s the provided memory and manages the device.</div><div><br></div><div>We&#39;re using systemd and udev rules to spawn off a user process whenever the hardware is plugged into the system.</div><div><br></div><div>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 &quot;surprise removal&quot;, where someone yanks the board without going through the whole &quot;attention button&quot; routine.</div><div><br></div><div>While the kernel driver has no problem with hot-removal, I see that if I &quot;unregister&quot; our UIO driver in response to the removal, then the mapping for the hardware&#39;s physical memory would become &quot;invalid&quot; (done by UIO on unregsiter). This could possibly cause the user-space process to crash due to illegal memory access.</div><div><br></div><div>Is there a &quot;standard&quot; way to handle this scenario, i.e for hotpluggable hardware using UIO?</div><div><br></div><div>Basically, we&#39;d want to &quot;unregister&quot; the UIO device only after the userspace process is informed of the removal so that it could unmap/close the device and exit gracefully.</div><div><br></div><div><div>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&#39;s no guarantee that the userspace process won&#39;t try to access the mmaped space during that interval, so this isn&#39;t a reliable solution either.</div></div><div><br></div><div>Any hints, thoughts?</div><div><br></div><div>Thanks.,</div><div>-mandeep</div><div><br></div></div>