Re: [PATCH] fpga: dfl: release irq triggers when a feature device is removed

From: Ionut Nechita (Wind River)

Date: Mon Nov 30 2026 - 13:05:15 EST


On Sun, Nov 29, 2026 at 01:38:29AM +0800, Xu Yilun wrote:
> On Tue, Nov 24, 2026 at 04:57:34PM +0200, Ionut Nechita (Wind River) wrote:
> > Release all triggers in dfl_fpga_dev_feature_uinit(), which runs on the
> > remove path of both the FME and the port device before the parent
> > frees the irq vectors. Do it after the sub-feature ops have been
> > cleared, so that the ioctls no longer reach the sub-features. The
>
> Why? I don't see dfl_fpga_dev_feature_uinit() sync with any ioctl.

You're right. fme_ioctl() and afu_ioctl() read f->ops without a lock,
so clearing it orders nothing. A DFL_FPGA_*_SET_IRQ ioctl that is
already past the check can take fdata->lock after my loop and bind a
trigger again, on an irq that is about to be freed. That sentence in
the changelog is wrong.

> > release() handler then finds no triggers left to free.
>
> I don't think this method makes things clear. Now the problem is that
> cdev operations don't sync with pci driver remove, so make them synced?

Agreed, and it is worse than the irq leak. Since commit 39ea74e33edc
("fpga: dfl: factor out feature device data from platform device
data"), the feature device data is allocated with devm on the PCI
device. Once dfl-pci is unbound, a release(), ioctl() or mmap() on a
device file that is still open uses freed memory, including the
release() that v1 relies on.

Please drop v1. For v2 I am splitting the fix in two:

1. Sync the file operations with the removal: a rw_semaphore in the
feature platform data, which the open cdev keeps alive, held for
read around open/release/ioctl/mmap and for write in
dfl_fpga_dev_ops_unregister(). That marks the ops as unregistered,
so later calls fail with -ENODEV and release() no longer touches
the feature device data.

2. Release the irq triggers in dfl_fpga_dev_ops_unregister(), under
the write lock, once no ioctl can bind them again.

It builds, but I want to test it on an N3000 first: removing the card
with the FME and port files held open and irqs bound, with SET_IRQ
racing the removal. I expect to send v2 in the next few days. If you
would prefer the sync done differently, let me know and I will follow
that.

Thanks for the review,
Ionut