All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V1 RESEND 0/4] Infrastructure to define apertures in a PCIe device with a flattened device tree
@ 2022-03-05  5:23 Lizhi Hou
  2022-03-05  5:23 ` [PATCH V1 RESEND 1/4] pci: add interface to create pci-ep device tree node Lizhi Hou
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Lizhi Hou @ 2022-03-05  5:23 UTC (permalink / raw)
  To: linux-pci, devicetree, robh
  Cc: Lizhi Hou, yilun.xu, maxz, sonal.santan, yliu, michal.simek,
	stefanos, trix, mdf, dwmw2, linux-kernel

Hello,

This V1 of patch series is to provide the required pci OF interfaces for
the PCIe device which uses flattened device tree to describe apertures in
its PCIe BARs. e.g, Xilinx Alveo PCIe accelerator. This requires a base
device tree which contains nodes for PCIe devices. A PCIe device driver
can then overlay a flattened device tree on the PCIe device tree node.
There are two separate parts for this to work. First, not all system has
a base device tree created by default. Thus, a patch to create an empty
device tree root node has been submitted.
  https://lore.kernel.org/lkml/20220216050056.311496-1-lizhi.hou@xilinx.com/
Second, PCIe is self discoverable bus and there might not be a device tree
node created for PCIe device. This patch provides a new interface to create
a ‘pci-ep-bus’ node under the base device tree root node. PCIe device
driver may call this interface in its probe routine to create device tree
node, then overlays its device tree to the node.
For the overlayed device tree nodes, each node presents a hardware aperture
implemented in its PCIe BARs. The aperture register address consists of BAR
index and offset. It uses the following encoding:
  0xIooooooo 0xoooooooo
Where:
  I = BAR index
  ooooooo oooooooo = BAR offset
The ‘pci-ep-bus’ node been created is compatible with ‘simple-bus’ and
contains ‘ranges’ property for translating aperture address to CPU address.
The last patch enhances of_overlay_fdt_apply(). The ‘pci-ep-bus’ device
node is created dynamically. The flattened device tree may not specify an
fixed target overlay path in front. Instead, a relative path to the
‘pci-ep-bus’ node is specified in the flattened tree. Thus, a new
parameter is added to point the target base node which is ‘pci-ep-bus’
node in this case. Then the entire overlay target path is target base node
path plus the relative path specified in the flattened device tree.

Lizhi Hou (4):
  pci: add interface to create pci-ep device tree node
  Documentation: devicetree: bindings: add binding for PCIe endpoint bus
  fpga: xrt: management physical function driver
  of: enhance overlay applying interface to specific target base node

 .../devicetree/bindings/bus/pci-ep-bus.yaml   |  72 +++++++
 drivers/fpga/Kconfig                          |   3 +
 drivers/fpga/Makefile                         |   3 +
 drivers/fpga/xrt/Kconfig                      |  24 +++
 drivers/fpga/xrt/Makefile                     |   8 +
 drivers/fpga/xrt/mgmt/Makefile                |  13 ++
 drivers/fpga/xrt/mgmt/dt-test.dts             |  15 ++
 drivers/fpga/xrt/mgmt/dt-test.h               |  15 ++
 drivers/fpga/xrt/mgmt/xmgmt-drv.c             | 102 ++++++++++
 drivers/gpu/drm/rcar-du/rcar_du_of.c          |   2 +-
 drivers/of/overlay.c                          |  37 ++--
 drivers/of/unittest.c                         |   2 +-
 drivers/pci/of.c                              | 180 ++++++++++++++++++
 include/linux/of.h                            |   2 +-
 include/linux/of_pci.h                        |  15 ++
 15 files changed, 479 insertions(+), 14 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/bus/pci-ep-bus.yaml
 create mode 100644 drivers/fpga/xrt/Kconfig
 create mode 100644 drivers/fpga/xrt/Makefile
 create mode 100644 drivers/fpga/xrt/mgmt/Makefile
 create mode 100644 drivers/fpga/xrt/mgmt/dt-test.dts
 create mode 100644 drivers/fpga/xrt/mgmt/dt-test.h
 create mode 100644 drivers/fpga/xrt/mgmt/xmgmt-drv.c

-- 
2.27.0


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: [PATCH V1 RESEND 1/4] pci: add interface to create pci-ep device tree node
@ 2022-03-09  6:51 kernel test robot
  0 siblings, 0 replies; 20+ messages in thread
From: kernel test robot @ 2022-03-09  6:51 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 21961 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220305052304.726050-2-lizhi.hou@xilinx.com>
References: <20220305052304.726050-2-lizhi.hou@xilinx.com>
TO: Lizhi Hou <lizhi.hou@xilinx.com>
TO: linux-pci(a)vger.kernel.org
TO: devicetree(a)vger.kernel.org
TO: robh(a)kernel.org
CC: Lizhi Hou <lizhi.hou@xilinx.com>
CC: yilun.xu(a)intel.com
CC: maxz(a)xilinx.com
CC: sonal.santan(a)xilinx.com
CC: yliu(a)xilinx.com
CC: michal.simek(a)xilinx.com
CC: stefanos(a)xilinx.com
CC: trix(a)redhat.com
CC: mdf(a)kernel.org
CC: dwmw2(a)infradead.org
CC: linux-kernel(a)vger.kernel.org
CC: Max Zhen <max.zhen@xilinx.com>

Hi Lizhi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on robh/for-next]
[also build test WARNING on helgaas-pci/next linus/master pinchartl-media/drm/du/next v5.17-rc7 next-20220308]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Lizhi-Hou/Infrastructure-to-define-apertures-in-a-PCIe-device-with-a-flattened-device-tree/20220307-141939
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: x86_64-randconfig-c007-20220307 (https://download.01.org/0day-ci/archive/20220309/202203091459.fdySi5dj-lkp(a)intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project d271fc04d5b97b12e6b797c6067d3c96a8d7470e)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/3a2c08c0f0ef77bf1db2f1677721dd87f46df294
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Lizhi-Hou/Infrastructure-to-define-apertures-in-a-PCIe-device-with-a-flattened-device-tree/20220307-141939
        git checkout 3a2c08c0f0ef77bf1db2f1677721dd87f46df294
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)
   include/acpi/acexcep.h:58:41: note: expanded from macro 'ACPI_FAILURE'
   #define ACPI_FAILURE(a)                 (a)
                                           ^~~
   drivers/acpi/acpica/hwsleep.c:75:2: note: Taking false branch
           if (ACPI_FAILURE(status)) {
           ^
   drivers/acpi/acpica/hwsleep.c:78:20: note: Assuming the condition is false
           ACPI_DEBUG_PRINT((ACPI_DB_INIT,
                             ^
   include/acpi/acoutput.h:115:37: note: expanded from macro 'ACPI_DB_INIT'
   #define ACPI_DB_INIT                ACPI_DEBUG_LEVEL (ACPI_LV_INIT)
                                       ^
   include/acpi/acoutput.h:107:37: note: expanded from macro 'ACPI_DEBUG_LEVEL'
   #define ACPI_DEBUG_LEVEL(dl)        (u32) dl,ACPI_DEBUG_PARAMETERS
                                       ^
   include/acpi/acoutput.h:313:59: note: expanded from macro 'ACPI_DEBUG_PRINT'
   #define ACPI_DEBUG_PRINT(plist)         ACPI_ACTUAL_DEBUG plist
                                           ~~~~~~~~~~~~~~~~~~^~~~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/acpi/acoutput.h:299:30: note: expanded from macro 'ACPI_DO_DEBUG_PRINT'
                   if (ACPI_IS_DEBUG_ENABLED (level, component)) \
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
   include/acpi/acoutput.h:263:4: note: expanded from macro 'ACPI_IS_DEBUG_ENABLED'
           ((level & acpi_dbg_level) && (component & acpi_dbg_layer))
             ^
   include/acpi/acoutput.h:281:44: note: expanded from macro 'ACPI_DO_WHILE0'
   #define ACPI_DO_WHILE0(a)               do a while(0)
                                              ^
   drivers/acpi/acpica/hwsleep.c:78:2: note: Left side of '&&' is false
           ACPI_DEBUG_PRINT((ACPI_DB_INIT,
           ^
   include/acpi/acoutput.h:313:41: note: expanded from macro 'ACPI_DEBUG_PRINT'
   #define ACPI_DEBUG_PRINT(plist)         ACPI_ACTUAL_DEBUG plist
                                           ^
   include/acpi/acoutput.h:306:2: note: expanded from macro 'ACPI_ACTUAL_DEBUG'
           ACPI_DO_DEBUG_PRINT (acpi_debug_print, level, line, \
           ^
   include/acpi/acoutput.h:299:7: note: expanded from macro 'ACPI_DO_DEBUG_PRINT'
                   if (ACPI_IS_DEBUG_ENABLED (level, component)) \
                       ^
   include/acpi/acoutput.h:263:28: note: expanded from macro 'ACPI_IS_DEBUG_ENABLED'
           ((level & acpi_dbg_level) && (component & acpi_dbg_layer))
                                     ^
   drivers/acpi/acpica/hwsleep.c:78:2: note: Loop condition is false.  Exiting loop
           ACPI_DEBUG_PRINT((ACPI_DB_INIT,
           ^
   include/acpi/acoutput.h:313:41: note: expanded from macro 'ACPI_DEBUG_PRINT'
   #define ACPI_DEBUG_PRINT(plist)         ACPI_ACTUAL_DEBUG plist
                                           ^
   include/acpi/acoutput.h:306:2: note: expanded from macro 'ACPI_ACTUAL_DEBUG'
           ACPI_DO_DEBUG_PRINT (acpi_debug_print, level, line, \
           ^
   include/acpi/acoutput.h:298:2: note: expanded from macro 'ACPI_DO_DEBUG_PRINT'
           ACPI_DO_WHILE0 ({ \
           ^
   include/acpi/acoutput.h:281:41: note: expanded from macro 'ACPI_DO_WHILE0'
   #define ACPI_DO_WHILE0(a)               do a while(0)
                                           ^
   drivers/acpi/acpica/hwsleep.c:102:6: note: Assuming 'status' is 0
           if (ACPI_FAILURE(status)) {
               ^
   include/acpi/acexcep.h:58:41: note: expanded from macro 'ACPI_FAILURE'
   #define ACPI_FAILURE(a)                 (a)
                                           ^~~
   drivers/acpi/acpica/hwsleep.c:102:2: note: Taking false branch
           if (ACPI_FAILURE(status)) {
           ^
   drivers/acpi/acpica/hwsleep.c:113:6: note: Assuming 'sleep_state' is < ACPI_STATE_S4
           if (sleep_state < ACPI_STATE_S4) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/acpica/hwsleep.c:113:2: note: Taking true branch
           if (sleep_state < ACPI_STATE_S4) {
           ^
   drivers/acpi/acpica/hwsleep.c:114:3: note: Calling 'wbinvd'
                   ACPI_FLUSH_CPU_CACHE();
                   ^
   arch/x86/include/asm/acenv.h:16:32: note: expanded from macro 'ACPI_FLUSH_CPU_CACHE'
   #define ACPI_FLUSH_CPU_CACHE()  wbinvd()
                                   ^~~~~~~~
   arch/x86/include/asm/paravirt.h:183:2: note: Assigned value is garbage or undefined
           PVOP_ALT_VCALL0(cpu.wbinvd, "wbinvd", ALT_NOT(X86_FEATURE_XENPV));
           ^
   arch/x86/include/asm/paravirt_types.h:516:2: note: expanded from macro 'PVOP_ALT_VCALL0'
           __PVOP_ALT_VCALL(op, alt, cond)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/x86/include/asm/paravirt_types.h:496:8: note: expanded from macro '__PVOP_ALT_VCALL'
           (void)____PVOP_ALT_CALL(, op, alt, cond, CLBR_ANY,              \
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/x86/include/asm/paravirt_types.h:461:3: note: expanded from macro '____PVOP_ALT_CALL'
                   PVOP_CALL_ARGS;                                         \
                   ^~~~~~~~~~~~~~
   arch/x86/include/asm/paravirt_types.h:405:16: note: expanded from macro 'PVOP_CALL_ARGS'
           unsigned long __edi = __edi, __esi = __esi,             \
                         ^       ~~~~~
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
>> drivers/pci/of.c:762:2: warning: Argument to kfree() is the address of a global variable, which is not memory allocated by malloc() [clang-analyzer-unix.Malloc]
           kfree(prop);
           ^     ~~~~
   drivers/pci/of.c:689:7: note: 'node' is non-null
           if (!node)
                ^~~~
   drivers/pci/of.c:689:2: note: Taking false branch
           if (!node)
           ^
   drivers/pci/of.c:695:6: note: 'ret' is -12
           if (ret)
               ^~~
   drivers/pci/of.c:695:2: note: Taking true branch
           if (ret)
           ^
   drivers/pci/of.c:696:3: note: Control jumps to line 762
                   goto cleanup;
                   ^
   drivers/pci/of.c:762:2: note: Argument to kfree() is the address of a global variable, which is not memory allocated by malloc()
           kfree(prop);
           ^     ~~~~
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   include/linux/fsnotify_backend.h:279:18: warning: Access to field 'dentry' results in a dereference of a null pointer (loaded from variable 'data') [clang-analyzer-core.NullDereference]
                   return d_inode(((const struct path *)data)->dentry);
                                  ^
   fs/notify/fsnotify.c:184:22: note: Assuming 'path' is null
           struct mount *mnt = path ? real_mount(path->mnt) : NULL;
                               ^~~~
   fs/notify/fsnotify.c:184:22: note: '?' condition is false
   fs/notify/fsnotify.c:199:6: note: Assuming field 'i_fsnotify_marks' is non-null
           if (!inode->i_fsnotify_marks && !inode->i_sb->s_fsnotify_marks &&
               ^~~~~~~~~~~~~~~~~~~~~~~~
   fs/notify/fsnotify.c:199:31: note: Left side of '&&' is false
           if (!inode->i_fsnotify_marks && !inode->i_sb->s_fsnotify_marks &&
                                        ^
   fs/notify/fsnotify.c:204:18: note: Calling 'fsnotify_event_needs_parent'
           parent_needed = fsnotify_event_needs_parent(inode, mnt, mask);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/notify/fsnotify.c:152:6: note: Assuming the condition is true
           if (mask & FS_ISDIR)
               ^~~~~~~~~~~~~~~
   fs/notify/fsnotify.c:152:2: note: Taking true branch
           if (mask & FS_ISDIR)
           ^
   fs/notify/fsnotify.c:153:3: note: Returning zero, which participates in a condition later
                   return false;
                   ^~~~~~~~~~~~
   fs/notify/fsnotify.c:204:18: note: Returning from 'fsnotify_event_needs_parent'
           parent_needed = fsnotify_event_needs_parent(inode, mnt, mask);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/notify/fsnotify.c:205:6: note: Assuming 'parent_watched' is true
           if (!parent_watched && !parent_needed)
               ^~~~~~~~~~~~~~~
   fs/notify/fsnotify.c:205:22: note: Left side of '&&' is false
           if (!parent_watched && !parent_needed)
                               ^
   fs/notify/fsnotify.c:212:15: note: 'parent_watched' is true
           if (unlikely(parent_watched && !p_mask))
                        ^
   include/linux/compiler.h:78:42: note: expanded from macro 'unlikely'
   # define unlikely(x)    __builtin_expect(!!(x), 0)
                                               ^
   fs/notify/fsnotify.c:212:15: note: Left side of '&&' is true
           if (unlikely(parent_watched && !p_mask))
                        ^
   fs/notify/fsnotify.c:212:33: note: Assuming 'p_mask' is not equal to 0
           if (unlikely(parent_watched && !p_mask))
                                          ^
   include/linux/compiler.h:78:42: note: expanded from macro 'unlikely'
   # define unlikely(x)    __builtin_expect(!!(x), 0)
                                               ^
   fs/notify/fsnotify.c:212:2: note: Taking false branch
           if (unlikely(parent_watched && !p_mask))
           ^
   fs/notify/fsnotify.c:220:6: note: 'parent_needed' is false
           if (parent_needed || parent_interested) {
               ^~~~~~~~~~~~~
   fs/notify/fsnotify.c:220:6: note: Left side of '||' is false
   fs/notify/fsnotify.c:220:23: note: Assuming 'parent_interested' is true
           if (parent_needed || parent_interested) {
                                ^~~~~~~~~~~~~~~~~
   fs/notify/fsnotify.c:220:2: note: Taking true branch
           if (parent_needed || parent_interested) {
           ^
   fs/notify/fsnotify.c:222:45: note: Passing null pointer value via 1st parameter 'data'
                   WARN_ON_ONCE(inode != fsnotify_data_inode(data, data_type));
                                                             ^
   include/asm-generic/bug.h:104:25: note: expanded from macro 'WARN_ON_ONCE'
           int __ret_warn_on = !!(condition);                      \
                                  ^~~~~~~~~

vim +762 drivers/pci/of.c

3a2c08c0f0ef77b Lizhi Hou 2022-03-04  663  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  664  /**
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  665   * devm_of_pci_create_bus_endpoint - Create a device node for the given pci device.
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  666   * @pdev: PCI device pointer.
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  667   *
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  668   * For PCI device which uses flattened device tree to describe apertures in its BARs,
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  669   * a device node for the given pci device is required. Then the flattened device tree
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  670   * overlay from the device can be applied to the base tree.
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  671   * The device node is under root node and act like bus node. It contains a "ranges"
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  672   * property which is used for address translation of its children. Each child node
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  673   * corresponds an aperture and use BAR index and offset as its address.
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  674  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  675   * Returns 0 on success or a negative error-code on failure.
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  676   */
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  677  int devm_of_pci_create_bus_endpoint(struct pci_dev *pdev)
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  678  {
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  679  	struct property *proplist = NULL;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  680  	struct device *dev = &pdev->dev;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  681  	int range_ncells, addr_ncells;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  682  	struct device_node *node;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  683  	void *prop = NULL;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  684  	u32 *range_cell;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  685  	__be32 val;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  686  	int i, ret;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  687  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  688  	node = of_ep_alloc_node(pdev, "pci-ep-bus");
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  689  	if (!node)
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  690  		return -ENOMEM;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  691  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  692  	/* the endpoint node works as 'simple-bus' to translate aperture addresses. */
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  693  	prop = "simple-bus";
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  694  	ret = of_ep_add_property(dev, &proplist, "compatible", strlen(prop) + 1, prop);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  695  	if (ret)
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  696  		goto cleanup;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  697  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  698  	/* The address and size cells of nodes underneath are 2 */
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  699  	val = cpu_to_be32(2);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  700  	ret = of_ep_add_property(dev, &proplist, "#address-cells", sizeof(u32), &val);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  701  	if (ret)
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  702  		goto cleanup;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  703  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  704  	ret = of_ep_add_property(dev, &proplist, "#size-cells", sizeof(u32), &val);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  705  	if (ret)
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  706  		goto cleanup;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  707  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  708  	/* child address format: 0xIooooooo oooooooo, I = bar index, o = offset on bar */
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  709  	addr_ncells = of_n_addr_cells(node);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  710  	if (addr_ncells > 2) {
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  711  		/* does not support number of address cells greater than 2 */
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  712  		ret = -EINVAL;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  713  		goto cleanup;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  714  	}
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  715  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  716  	/* range cells include <node addr cells> <child addr cells> <child size cells> */
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  717  	range_ncells = addr_ncells + 4;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  718  	prop = kzalloc(range_ncells * sizeof(u32) * PCI_STD_NUM_BARS, GFP_KERNEL);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  719  	if (!prop) {
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  720  		ret = -ENOMEM;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  721  		goto cleanup;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  722  	}
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  723  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  724  	range_cell = prop;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  725  	for (i = 0; i < PCI_STD_NUM_BARS; i++) {
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  726  		if (!pci_resource_len(pdev, i))
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  727  			continue;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  728  		/* highest 4 bits of address are bar index */
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  729  		*(__be64 *)range_cell = cpu_to_be64((u64)i << 60);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  730  		range_cell += 2;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  731  		if (addr_ncells == 2)
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  732  			*(__be64 *)range_cell = cpu_to_be64((u64)pci_resource_start(pdev, i));
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  733  		else
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  734  			*(__be32 *)range_cell = cpu_to_be32((u32)pci_resource_start(pdev, i));
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  735  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  736  		range_cell += addr_ncells;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  737  		*(__be64 *)range_cell = cpu_to_be64((u64)pci_resource_len(pdev, i));
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  738  		range_cell += 2;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  739  	}
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  740  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  741  	/* error out if there is not PCI BAR been found */
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  742  	if ((void *)range_cell == prop) {
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  743  		ret = -EINVAL;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  744  		goto cleanup;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  745  	}
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  746  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  747  	ret = of_ep_add_property(dev, &proplist, "ranges", (void *)range_cell - prop, prop);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  748  	kfree(prop);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  749  	if (ret)
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  750  		goto cleanup;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  751  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  752  	node->properties = proplist;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  753  	ret = of_attach_node(node);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  754  	if (ret)
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  755  		goto cleanup;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  756  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  757  	devres_add(dev, node);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  758  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  759  	return 0;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  760  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  761  cleanup:
3a2c08c0f0ef77b Lizhi Hou 2022-03-04 @762  	kfree(prop);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  763  	if (node)
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  764  		devres_free(node);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  765  
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  766  	return ret;
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  767  }
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  768  EXPORT_SYMBOL_GPL(devm_of_pci_create_bus_endpoint);
3a2c08c0f0ef77b Lizhi Hou 2022-03-04  769  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: [PATCH V1 RESEND 1/4] pci: add interface to create pci-ep device tree node
  2022-03-05  5:23 ` [PATCH V1 RESEND 1/4] pci: add interface to create pci-ep device tree node Lizhi Hou
  2022-03-10 19:34   ` Bjorn Helgaas
@ 2022-03-10 10:02 ` Dan Carpenter
  1 sibling, 0 replies; 20+ messages in thread
From: kernel test robot @ 2022-03-09 19:14 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 9585 bytes --]

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220305052304.726050-2-lizhi.hou@xilinx.com>
References: <20220305052304.726050-2-lizhi.hou@xilinx.com>
TO: Lizhi Hou <lizhi.hou@xilinx.com>
TO: linux-pci(a)vger.kernel.org
TO: devicetree(a)vger.kernel.org
TO: robh(a)kernel.org
CC: Lizhi Hou <lizhi.hou@xilinx.com>
CC: yilun.xu(a)intel.com
CC: maxz(a)xilinx.com
CC: sonal.santan(a)xilinx.com
CC: yliu(a)xilinx.com
CC: michal.simek(a)xilinx.com
CC: stefanos(a)xilinx.com
CC: trix(a)redhat.com
CC: mdf(a)kernel.org
CC: dwmw2(a)infradead.org
CC: linux-kernel(a)vger.kernel.org
CC: Max Zhen <max.zhen@xilinx.com>

Hi Lizhi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on robh/for-next]
[also build test WARNING on helgaas-pci/next linus/master pinchartl-media/drm/du/next v5.17-rc7 next-20220309]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Lizhi-Hou/Infrastructure-to-define-apertures-in-a-PCIe-device-with-a-flattened-device-tree/20220307-141939
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
config: i386-randconfig-m021-20220307 (https://download.01.org/0day-ci/archive/20220310/202203100338.8jox1rCr-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/pci/of.c:762 devm_of_pci_create_bus_endpoint() error: double free of 'prop'

vim +/prop +762 drivers/pci/of.c

3a2c08c0f0ef77 Lizhi Hou 2022-03-04  663  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  664  /**
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  665   * devm_of_pci_create_bus_endpoint - Create a device node for the given pci device.
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  666   * @pdev: PCI device pointer.
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  667   *
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  668   * For PCI device which uses flattened device tree to describe apertures in its BARs,
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  669   * a device node for the given pci device is required. Then the flattened device tree
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  670   * overlay from the device can be applied to the base tree.
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  671   * The device node is under root node and act like bus node. It contains a "ranges"
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  672   * property which is used for address translation of its children. Each child node
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  673   * corresponds an aperture and use BAR index and offset as its address.
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  674  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  675   * Returns 0 on success or a negative error-code on failure.
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  676   */
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  677  int devm_of_pci_create_bus_endpoint(struct pci_dev *pdev)
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  678  {
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  679  	struct property *proplist = NULL;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  680  	struct device *dev = &pdev->dev;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  681  	int range_ncells, addr_ncells;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  682  	struct device_node *node;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  683  	void *prop = NULL;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  684  	u32 *range_cell;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  685  	__be32 val;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  686  	int i, ret;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  687  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  688  	node = of_ep_alloc_node(pdev, "pci-ep-bus");
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  689  	if (!node)
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  690  		return -ENOMEM;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  691  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  692  	/* the endpoint node works as 'simple-bus' to translate aperture addresses. */
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  693  	prop = "simple-bus";
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  694  	ret = of_ep_add_property(dev, &proplist, "compatible", strlen(prop) + 1, prop);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  695  	if (ret)
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  696  		goto cleanup;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  697  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  698  	/* The address and size cells of nodes underneath are 2 */
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  699  	val = cpu_to_be32(2);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  700  	ret = of_ep_add_property(dev, &proplist, "#address-cells", sizeof(u32), &val);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  701  	if (ret)
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  702  		goto cleanup;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  703  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  704  	ret = of_ep_add_property(dev, &proplist, "#size-cells", sizeof(u32), &val);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  705  	if (ret)
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  706  		goto cleanup;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  707  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  708  	/* child address format: 0xIooooooo oooooooo, I = bar index, o = offset on bar */
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  709  	addr_ncells = of_n_addr_cells(node);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  710  	if (addr_ncells > 2) {
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  711  		/* does not support number of address cells greater than 2 */
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  712  		ret = -EINVAL;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  713  		goto cleanup;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  714  	}
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  715  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  716  	/* range cells include <node addr cells> <child addr cells> <child size cells> */
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  717  	range_ncells = addr_ncells + 4;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  718  	prop = kzalloc(range_ncells * sizeof(u32) * PCI_STD_NUM_BARS, GFP_KERNEL);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  719  	if (!prop) {
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  720  		ret = -ENOMEM;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  721  		goto cleanup;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  722  	}
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  723  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  724  	range_cell = prop;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  725  	for (i = 0; i < PCI_STD_NUM_BARS; i++) {
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  726  		if (!pci_resource_len(pdev, i))
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  727  			continue;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  728  		/* highest 4 bits of address are bar index */
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  729  		*(__be64 *)range_cell = cpu_to_be64((u64)i << 60);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  730  		range_cell += 2;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  731  		if (addr_ncells == 2)
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  732  			*(__be64 *)range_cell = cpu_to_be64((u64)pci_resource_start(pdev, i));
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  733  		else
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  734  			*(__be32 *)range_cell = cpu_to_be32((u32)pci_resource_start(pdev, i));
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  735  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  736  		range_cell += addr_ncells;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  737  		*(__be64 *)range_cell = cpu_to_be64((u64)pci_resource_len(pdev, i));
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  738  		range_cell += 2;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  739  	}
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  740  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  741  	/* error out if there is not PCI BAR been found */
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  742  	if ((void *)range_cell == prop) {
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  743  		ret = -EINVAL;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  744  		goto cleanup;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  745  	}
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  746  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  747  	ret = of_ep_add_property(dev, &proplist, "ranges", (void *)range_cell - prop, prop);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  748  	kfree(prop);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  749  	if (ret)
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  750  		goto cleanup;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  751  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  752  	node->properties = proplist;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  753  	ret = of_attach_node(node);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  754  	if (ret)
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  755  		goto cleanup;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  756  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  757  	devres_add(dev, node);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  758  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  759  	return 0;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  760  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  761  cleanup:
3a2c08c0f0ef77 Lizhi Hou 2022-03-04 @762  	kfree(prop);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  763  	if (node)
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  764  		devres_free(node);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  765  
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  766  	return ret;
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  767  }
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  768  EXPORT_SYMBOL_GPL(devm_of_pci_create_bus_endpoint);
3a2c08c0f0ef77 Lizhi Hou 2022-03-04  769  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2023-06-30 16:38 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-05  5:23 [PATCH V1 RESEND 0/4] Infrastructure to define apertures in a PCIe device with a flattened device tree Lizhi Hou
2022-03-05  5:23 ` [PATCH V1 RESEND 1/4] pci: add interface to create pci-ep device tree node Lizhi Hou
2022-03-10 19:34   ` Bjorn Helgaas
2022-06-21 15:12   ` Manivannan Sadhasivam
2022-03-05  5:23 ` [PATCH V1 RESEND 2/4] Documentation: devicetree: bindings: add binding for PCIe endpoint bus Lizhi Hou
2022-03-06 15:37   ` Tom Rix
2022-03-07 14:07     ` Rob Herring
2022-04-22 21:57       ` Lizhi Hou
2022-05-13 15:19         ` Lizhi Hou
2022-06-21 15:06   ` Manivannan Sadhasivam
2022-03-05  5:23 ` [PATCH V1 RESEND 3/4] fpga: xrt: management physical function driver Lizhi Hou
2022-06-21 15:16   ` Manivannan Sadhasivam
2023-06-30 16:38   ` Bjorn Helgaas
2022-03-05  5:23 ` [PATCH V1 RESEND 4/4] of: enhance overlay applying interface to specific target base node Lizhi Hou
2022-03-10 20:07   ` Rob Herring
2022-03-10 19:27 ` [PATCH V1 RESEND 0/4] Infrastructure to define apertures in a PCIe device with a flattened device tree Bjorn Helgaas
2022-03-09  6:51 [PATCH V1 RESEND 1/4] pci: add interface to create pci-ep device tree node kernel test robot
2022-03-09 19:14 kernel test robot
2022-03-10 10:02 ` Dan Carpenter
2022-03-10 10:02 ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.