Skip to content

fpga: dfl: fix kernel warning on port release/assign for SRIOV

Peter Colberg linux-fpga lkml 4 versions – Applied

Status from this message: Applied this series to for-next.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest18 patches 1 replyApplied
  2. v419 patches 14 repliesSuperseded
  3. v39 patches 11 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v2 RFC9 patches17 repliesSuperseded

Changes in v5 from the cover letter

- Merge patch "convert is_feature_dev_detected() to use FIU type" into subsequent patch "allocate platform device after feature device data". After the former patch was applied but not yet the latter patch, there was a window between binfo->type already holding a valid DFL id but binfo->feature_dev still NULL, where is_feature_dev_detected() would yield a different result, e.g., when build_info_create_dev() failed.
- In the patch "fpga: dfl: store platform device id in feature", in the function dfl_fpga_feature_devs_remove(), remove braces around single-line conditional statement.
- Move reset of device pointer in feature data to NULL in the function feature_dev_unregister() from the patch "fpga: dfl: factor out feature device registration" to the patch "allocate platform device after feature device data". The latter patch contains the corresponding initialization of the device pointer in feature_dev_register().
- In the patch "allocate platform device after feature device data", in the function feature_dev_unregister(), reset the device pointer of each sub feature to NULL for consistency.
- Revise commit description of patch "fpga: dfl: remove unneeded function build_info_create_dev()" to be confirmative, from (the function) "may be removed" to "Remove the function".

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/18fpga: dfl: omit unneeded argument pdata from dfl_feature_instance_init()drivers/fpga/dfl.c+1 -30 replies
2/18fpga: dfl: return platform data from dfl_fpga_inode_to_feature_dev_data()drivers/fpga/dfl-afu-main.c drivers/fpga/dfl-fme-main.c drivers/fpga/dfl.h+7 -140 replies
3/18fpga: dfl: afu: use parent device to log errors on port enable/disabledrivers/fpga/dfl-afu-main.c+4 -20 replies
4/18fpga: dfl: afu: define local pointer to feature devicedrivers/fpga/dfl-afu-dma-region.c drivers/fpga/dfl-afu-region.c+8 -60 replies
5/18fpga: dfl: pass feature platform data instead of device as argumentdrivers/fpga/dfl-afu-error.c drivers/fpga/dfl-afu-main.c drivers/fpga/dfl-afu.h +6 more+150 -1470 replies
6/18fpga: dfl: factor out feature data creation from build_info_commit_dev()drivers/fpga/dfl.c+40 -320 replies
7/18fpga: dfl: store FIU type in feature platform datadrivers/fpga/dfl.c drivers/fpga/dfl.h+29 -290 replies
8/18fpga: dfl: refactor internal DFL APIs to take/return feature device datadrivers/fpga/dfl-afu-dma-region.c drivers/fpga/dfl-afu-error.c drivers/fpga/dfl-afu-main.c +8 more+544 -5410 replies
9/18fpga: dfl: factor out feature device registrationdrivers/fpga/dfl.c+26 -40 replies
10/18fpga: dfl: factor out feature device data from platform device datadrivers/fpga/dfl.c drivers/fpga/dfl.h+35 -230 replies
11/18fpga: dfl: convert features from flexible array member to separate arraydrivers/fpga/dfl.c drivers/fpga/dfl.h+7 -20 replies
12/18fpga: dfl: store MMIO resources in feature device datadrivers/fpga/dfl.c drivers/fpga/dfl.h+17 -80 replies
13/18fpga: dfl: store platform device name in feature device datadrivers/fpga/dfl.c drivers/fpga/dfl.h+4 -10 replies
14/18fpga: dfl: store platform device id in feature device datadrivers/fpga/dfl.c drivers/fpga/dfl.h+25 -230 replies
15/18fpga: dfl: allocate platform device after feature device datadrivers/fpga/dfl.c+34 -380 replies
16/18fpga: dfl: remove unneeded function build_info_create_dev()drivers/fpga/dfl.c+2 -150 replies
17/18fpga: dfl: drop unneeded get_device() and put_device() of feature devicedrivers/fpga/dfl-fme-br.c drivers/fpga/dfl.c drivers/fpga/dfl.h+5 -180 replies
18/18fpga: dfl: destroy/recreate feature platform device on port release/assigndrivers/fpga/dfl.c+6 -170 replies

Reviews trailers per patch

All 18 patches have a Reviewed-by or Acked-by.

PatchMatthew GerlachBasheer Ahmed MuddebihalXu Yilun
1/18R-b R-b A-b
2/18R-b R-b A-b
3/18R-b R-b A-b
4/18R-b R-b A-b
5/18R-b R-b A-b
6/18R-b R-b A-b
7/18R-b R-b A-b
8/18R-b R-b A-b
9/18R-b R-b A-b
10/18R-b R-b A-b
11/18R-b R-b A-b
12/18R-b R-b A-b
13/18R-b R-b A-b
14/18R-b R-b
15/18R-b R-b
16/18R-b R-b
17/18R-b R-b A-b
18/18R-b R-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v5 thread

Cover letter [PATCH v5 00/18] fpga: dfl: fix kernel warning on port release/assign for SRIOV

With the Intel FPGA PAC D5005, DFL ports are registered as platform devices in PF mode. The port device must be removed from the host when the user wants to configure the port as a VF for use by a user-space driver, e.g., for pass-through to a virtual machine. The FME device ioctls DFL_FPGA_FME_PORT_RELEASE/ASSIGN are assigned for this purpose.

In the previous implementation, the port platform device is not completely destroyed on port release: it is removed from the system by platform_device_del(), but the platform device instance is retained. When DFL_FPGA_FME_PORT_ASSIGN is called, the platform device is added back with platform_device_add(), which conflicts with this comment of device_add(): "Do not call this routine more than once for any device structure", and would previously cause a kernel warning at runtime.

This patch completely unregisters the port platform device on release and registers a new device on assign. But the main work is to remove the dependency on struct dfl_feature_platform_data for many internal DFL APIs. This structure holds many DFL enumeration infos for feature devices. Many DFL APIs are expected to work with these infos even when the port platform device is unregistered. But after this change, the platform_data will be freed on port release. Hence this patch introduces a new structure dfl_feature_dev_data, which acts similarly to the previous dfl_feature_platform_data. dfl_feature_platform_data then only needs a pointer to dfl_feature_dev_data to query DFL enumeration infos.

Changes since v4:
- Merge patch "convert is_feature_dev_detected() to use FIU type" into subsequent patch "allocate platform device after feature device data". After the former patch was applied but not yet the latter patch, there was a window between binfo->type already holding a valid DFL id but binfo->feature_dev still NULL, where is_feature_dev_detected() would yield a different result, e.g., when build_info_create_dev() failed.
- In the patch "fpga: dfl: store platform device id in feature", in the function dfl_fpga_feature_devs_remove(), remove braces around single-line conditional statement.
- Move reset of device pointer in feature data to NULL in the function feature_dev_unregister() from the patch "fpga: dfl: factor out feature device registration" to the patch "allocate platform device after feature device data". The latter patch contains the corresponding initialization of the device pointer in feature_dev_register().
- In the patch "allocate platform device after feature device data", in the function feature_dev_unregister(), reset the device pointer of each sub feature to NULL for consistency.
- Revise commit description of patch "fpga: dfl: remove unneeded function build_info_create_dev()" to be confirmative, from (the function) "may be removed" to "Remove the function".

Changes since v3:
- The last patch of the v3 series has been broken up into smaller, self-contained patches, which carry out and describe each cosmetic or functional transformation separately to ensure its correctness.
- When a port had been released using the DFL_FPGA_FME_PORT_RELEASE ioctl, the corresponding device id was no longer being released as part of dfl_fpga_feature_devs_remove(). Instead of manually cleaning up feature device ids, use devm_add_action_or_reset() to automatically free the device id right before the corresponding feature device data is freed.

Changes since v2:
- Restructure series to break monolithic v1 patch into logical, self-contained patches, instead of per-file patches as in v2. In particular, the next-to-last patch only contains non-functional changes that are strictly limited to replacing pdata with fdata.
- Omit unneeded null pointer check from fme_open(), the same as for afu_open(). Refactor dfl_fpga_inode_to_feature_dev_data() to directly return the platform data and retrieve the device from the data.
- Fix missing free() of type in binfo_create_feature_dev_data(). Free allocated FIU type when devm_kmemdup() returns a NULL pointer.
- Store fdata instead of pdata as file descriptor private data in fme_open() since pdata is only used to look up fdata.
- Remove pdata pointers that are only used to look up fdata, in dfl_fpga_dev_feature_uinit() and dfl_feature_ioctl_set_irq().
- Omit unneeded argument pdata from dfl_feature_instance_init().
- Drop redundant 0 in zero initializer of dfl_feature_platform_data in feature_dev_register().
- Revert defining pointer to device when the pointer is only used once per function, in afu_dma_region_add() and afu_dma_region_add().
- Revert minor, unneeded code formatting changes to reduce noise.

Changes since v1:
- Split monolithic patch into series at request of maintainer.
- Substitute binfo->type for removed function feature_dev_id_type() in parse_feature_irqs().
- Return ERR_PTR(-ENOMEM) on !feature->params in binfo_create_feature_dev_data().
- Reorder cdev as first member of struct dfl_feature_platform_data such that container_of() to obtain pdata evaluates to a no-op.
- Change afu_ioctl_*() to receive dfl_feature_dev_data instead of dfl_feature_platform_data.
- Change fme_hdr_ioctl_*() to receive dfl_feature_dev_data instead of dfl_feature_platform_data.
- Replace local variable pdata with fdata in afu_mmap().
- Remove unused local variable pdata in afu_dev_{init,destroy}().
- Remove unused local variable pdata in fme_dev_{init,destroy}().
- Reorder local variables in afu_dma_unpin_pages() to reverse Christmas tree order.
- Align kernel-doc function name for __dfl_fpga_cdev_find_port_data().
- Substitute @fdata for @pdata in kernel-doc comments for dfl_fme_create_mgr() and dfl_fme_destroy_mgr().

Peter Colberg (17):
fpga: dfl: omit unneeded argument pdata from
dfl_feature_instance_init()
fpga: dfl: return platform data from
dfl_fpga_inode_to_feature_dev_data()
fpga: dfl: afu: use parent device to log errors on port enable/disable
fpga: dfl: afu: define local pointer to feature device
fpga: dfl: pass feature platform data instead of device as argument
fpga: dfl: factor out feature data creation from
build_info_commit_dev()
fpga: dfl: store FIU type in feature platform data
fpga: dfl: refactor internal DFL APIs to take/return feature device
data
fpga: dfl: factor out feature device registration
fpga: dfl: factor out feature device data from platform device data
fpga: dfl: convert features from flexible array member to separate
array
fpga: dfl: store MMIO resources in feature device data
fpga: dfl: store platform device name in feature device data
fpga: dfl: store platform device id in feature device data
fpga: dfl: allocate platform device after feature device data
fpga: dfl: remove unneeded function build_info_create_dev()
fpga: dfl: drop unneeded get_device() and put_device() of feature
device

Xu Yilun (1):
fpga: dfl: destroy/recreate feature platform device on port
release/assign

 drivers/fpga/dfl-afu-dma-region.c | 117 ++++----
 drivers/fpga/dfl-afu-error.c      |  59 ++--
 drivers/fpga/dfl-afu-main.c       | 278 +++++++++----------
 drivers/fpga/dfl-afu-region.c     |  51 ++--
 drivers/fpga/dfl-afu.h            |  26 +-
 drivers/fpga/dfl-fme-br.c         |  24 +-
 drivers/fpga/dfl-fme-error.c      |  98 +++----
 drivers/fpga/dfl-fme-main.c       |  95 +++----
 drivers/fpga/dfl-fme-pr.c         |  86 +++---
 drivers/fpga/dfl.c                | 441 +++++++++++++++---------------
 drivers/fpga/dfl.h                | 140 ++++++----
 11 files changed, 718 insertions(+), 697 deletions(-)
Signature · 1 line
2.47.0