Skip to contentSkip to conversation

GENL interface for ACPI _DSM methods

RFC In review Wathsala Vithanage 5 participants 14 messages Jan 6, 2025 – Jan 9, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover GENL interface for ACPI _DSM methods

Linux v6.13-rc1 added support for PCIe TPH and direct cache injection. As already described in the patch set[1] that introduced this feature, the cache injection in supported hardware allows optimal utilization of platform resources for specific requests on the PCIe bus. However, the patch set [1] implements the functionality for usage within the kernel. But certain user space applications, especially those whose performance is sensitive to the latency of inbound writes as seen by a CPU core, may benefit from using this information (E.g., the DPDK cache stashing feature discussed in RFC [2]). This RFC is an attempt to obtain the PCIe steering tag information from the kernel to be used by user mode applications. We understand that there is more than one way to provide this information. Please review and suggest alternatives if necessary.

The first of the two patches introduced in this RFC attempts to overcome the kernel-only limitation by providing an API to kernel subsystems to hook up relevant _DSM methods to a GENL interface. User space applications can invoke a _DSM hooked up to this interface via the "acpi-event" GENL family socket, granted they have the minimum capabilities and message formats demanded by the kernel subsystem that hooked up the _DSM method. This feature is added by extending the "acpi-event" GENL family that multicasts ACPI events to the user-space applications such as acpid.

The second patch of this RFC hooks up the PCIe root-port TLP Processing Hints (TPH) _DSM to the ACPI GENL interface. User space applications like [2] can now request the kernel to execute the _DSM on their behalf and return steering-tag information.

[1] lore.kernel.org/linux-pci/[email protected]
[2] inbox.dpdk.org/dev/[email protected]

Wathsala Vithanage (2):
ACPI: Add support for invoking select _DSM methods from user space
PCI: Add generic netlink interface to TPH _DSM

 drivers/acpi/Makefile                 |   3 +-
 drivers/acpi/{event.c => acpi_genl.c} | 110 ++++++++++++++++++++++-
 drivers/acpi/acpi_genl_dsm.c          |  76 ++++++++++++++++
 drivers/pci/tph.c                     | 121 ++++++++++++++++++++++++++
 include/acpi/acpi_genl.h              |  54 ++++++++++++
 include/linux/acpi.h                  |   1 +
 6 files changed, 360 insertions(+), 5 deletions(-)
 rename drivers/acpi/{event.c => acpi_genl.c} (63%)
 create mode 100644 drivers/acpi/acpi_genl_dsm.c
 create mode 100644 include/acpi/acpi_genl.h
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/2 ACPI: Add support for invoking select _DSM methods from user space

Applications that bypass the kernel to access devices can benefit from the ability to execute ACPI _DSM methods from the user space. This commit introduces a generic netlink interface for user-space applications to invoke _DSM methods registered by kernel subsystems for the user space. User space applications invoke these _DSMs by sending an ACPI_GENL_CMD_DSM-typed message to an "acpi-event" GENL family socket. Irrespective of the _DSM being invoked, all messages typed ACPI_GENL_CMD_DSM must be prefixed by a struct acpi_genl_dsm_id header to uniquely identify the target _DSM as specified by the ACPI firmware specification. Reminder of the message is specific to the _DSM being invoked. Data from the _DSM method will be returned to the application as a response with the same message header. In addition, the calling user application needs the minimal capabilities and message lengths (including the header) specified by the kernel subsystem that registers the callback for the _DSM method.

The GENL message header for _DSM (acpi_genl_dsm_id header) has the following format.

0 1 2 3 4 5 6 7

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                          _DSM GUID                            +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|        _DSM REVISION          |     _DSM FUNCTION INDEX       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
---
 drivers/acpi/Makefile                 |   3 +-
 drivers/acpi/{event.c => acpi_genl.c} | 110 +++++++++++++++++++++++++-
 drivers/acpi/acpi_genl_dsm.c          |  79 ++++++++++++++++++
 include/acpi/acpi_genl.h              |  61 ++++++++++++++
 include/linux/acpi.h                  |   1 +
 5 files changed, 249 insertions(+), 5 deletions(-)
 rename drivers/acpi/{event.c => acpi_genl.c} (63%)
 create mode 100644 drivers/acpi/acpi_genl_dsm.c
 create mode 100644 include/acpi/acpi_genl.h
drivers/acpi/Makefile +2 -1
index 40208a0f5dfb..4b1db58ff33a 100644
@@ -49,7 +49,8 @@ acpi-y				+= acpi_apd.o
 acpi-y				+= acpi_platform.o
 acpi-y				+= acpi_pnp.o
 acpi-y				+= power.o
-acpi-y				+= event.o
+acpi-y				+= acpi_genl.o
+acpi-y				+= acpi_genl_dsm.o
 acpi-y				+= evged.o
 acpi-y				+= sysfs.o
 acpi-y				+= property.o
drivers/acpi/acpi_genl.c renamed from drivers/acpi/event.c +106 -4

159 lines not on this page · raw message

drivers/acpi/acpi_genl_dsm.c new file +79 -0

79 lines not on this page · raw message

include/acpi/acpi_genl.h new file +61 -0

61 lines not on this page · raw message

include/linux/acpi.h +1 -0
index 6adcd1b92b20..ff15ec320705 100644
@@ -38,6 +38,7 @@ struct irq_domain_ops;
 #include <acpi/acpi_drivers.h>
 #include <acpi/acpi_io.h>
 #include <asm/acpi.h>
+#include <acpi/acpi_genl.h>
 
 #ifdef CONFIG_ACPI_TABLE_LIB
 #define EXPORT_SYMBOL_ACPI_LIB(x) EXPORT_SYMBOL_NS_GPL(x, "ACPI")
Signature · 1 line
2.43.0
#2 lore raw

Re: [RFC PATCH 1/2] ACPI: Add support for invoking select _DSM methods from user space

kernel test robot noticed the following build warnings:

Hi Wathsala,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on rafael-pm/bleeding-edge pci/next pci/for-linus linus/master v6.13-rc6 next-20250106] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wathsala-Vithanage/ACPI-Add-support-for-invoking-select-_DSM-methods-from-user-space/20250107-003201
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link:    https://lore.kernel.org/r/20250106163045.508959-2-wathsala.vithanage%40arm.com
patch subject: [RFC PATCH 1/2] ACPI: Add support for invoking select _DSM methods from user space
config: loongarch-randconfig-002-20250107 (https://download.01.org/0day-ci/archive/20250107/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250107/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/acpi/acpi_genl_dsm.c:28: warning: Function parameter or struct member 'handle' not described in 'acpi_genl_dsm_add_handle'
>> drivers/acpi/acpi_genl_dsm.c:28: warning: Excess function parameter 'dsm_handle' description in 'acpi_genl_dsm_add_handle'

vim +28 drivers/acpi/acpi_genl_dsm.c

    19	
    20	/**
    21	 * acpi_genl_dsm_add_handle - add netlink handle to invoke _DSM via netlink.
    22	 * @dsm_handle: _DSM handle
    23	 *
    24	 * Add handle to a _DSM method that will be invoked when user space calls it
    25	 * via netlink.
    26	 */
    27	int acpi_genl_dsm_add_handle(struct acpi_genl_dsm_handle *handle)
  > 28	{
    29		if (!handle)
    30			return -EINVAL;
    31		u32 id_hash = acpi_genl_dsm_hash_key(handle->id);
    32	
    33		hash_add_rcu(acpi_dsm_tbl, &handle->entry, id_hash);
    34		return 0;
    35	}
    36	EXPORT_SYMBOL(acpi_genl_dsm_add_handle);
    37	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

RFC PATCH 2/2 PCI: Add generic netlink interface to TPH _DSM

In reply to Wathsala Vithanage

Applications capable of configuring direct cache injection for PCIe devices from the user space require steering tags extracted from the PCIe root port’s TPH _DSM method. This patch exposes the TPH _DSM method via the ACPI GENL interface for such applications. The messages sent over the GNEL interface querying PCIe steering tags should be prefixed with an acpi_genl_dsm_id header and PCI domain, slot, and function information, as shown in the message format diagram. PKG ARG0, ARG1, and ARG2 correspond to input structures defined in PCIe firmware specification ECN titled "Revised _DSM for Cache Locality TPH Features."

0 1 2 3 4 5 6 7

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   +                     acpi_genl_dsm_id header                   +
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
16 |           PCI DOMAIN          |           PCI SLOT            |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |           PCI DEVFN           |           PKG ARG0            |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |           PKG ARG1            |           PKG ARG2            |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Kernel responds via the same GENL socket with the steering tag info and a status code in the following format. Steering tag info is the same structure returned by TPH _DSM of the root port as specified in the PCI firmware specification ECN titled "Revised _DSM for Cache Locality TPH Features."

0 1 2 3 4 5 6 7

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   +                     acpi_genl_dsm_id header                   +
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
16 |            Status             |       Steering Tag Info       |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

The status code is always 0 for successful invocations of the _DSM. Status is -EINVAL, -ENODEV, or -EOPNOTSUPP if ACPI or TPH is disabled, No PCI device found or TPH is not supported respectively.

---
 drivers/pci/tph.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)
drivers/pci/tph.c +119 -0
index 1e604fbbda65..8a70b663cb78 100644
@@ -53,6 +53,36 @@ union st_info {
 	u64 value;
 };
 
+/*
+ * The tph_genl_dsm_info struct defines both the input and the return container
+ * for Generic Netlink interface of the TPH _DSM of PCIe root ports.
+ */
+struct tph_genl_dsm_info {
+	/* _DSM method identfier {GUID, REV, FUNCTION-INDEX}*/
+	struct acpi_genl_dsm_id id;
+	union {
+		struct {
+			/* bus, dev, devfn of the PCIe device */
+			int bus;
+			u32 dev;
+			u32 devfn;
+			/*
+			 * args for the TPH _DSM of the PCIe root-port of
+			 * the specified device.
+			 */
+			u32 pkg_arg0;
+			u32 pkg_arg1;
+			u64 pkg_arg2;
+		} arg;
+		struct {
+			/* return status */
+			int status;
+			/* st_info returned by the PCIe root-port TPH _DSM */
+			union st_info st;
+		} ret;
+	} info;
+};
+
 static u16 tph_extract_tag(enum tph_mem_type mem_type, u8 req_type,
 			   union st_info *info)
 {
@@ -130,6 +160,95 @@ static acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid,
 
 	return AE_OK;
 }
+
+static int tph_invoke_dsm_genl_cb(struct acpi_genl_dsm_id *in,
+				  struct acpi_genl_dsm_id *out)
+{
+	struct pci_dev *pdev, *pdev_rp;
+	acpi_handle handle;
+	u32 cpu_uid;
+	int status = 0;
+
+	struct tph_genl_dsm_info *arg = (struct tph_genl_dsm_info *)in;
+	struct tph_genl_dsm_info *ret = (struct tph_genl_dsm_info *)out;
+
+	/* Honor  notph and acpi kernel parameters */
+	if (acpi_disabled || acpi_pci_disabled || pci_tph_disabled) {
+		status = -EINVAL;
+		goto out;
+	}
+
+	/*
+	 * pkg_arg1 contains the kernel logical CPU id provided by the user,
+	 * make sure it's a valid CPU id before passing it to down to firmware.
+	 * pkg_arg2 is not use by tph_invoke_dsm, hence no validation is
+	 * required.
+	 */
+	if (!(arg->info.arg.pkg_arg1 < nr_cpu_ids &&
+	    cpu_present(arg->info.arg.pkg_arg1))) {
+		status = -EINVAL;
+		goto out;
+	}
+
+	cpu_uid = topology_core_id(arg->info.arg.pkg_arg1);
+
+	ret->id.guid = pci_acpi_dsm_guid;
+	ret->id.rev = 7;
+	ret->id.func = TPH_ST_DSM_FUNC_INDEX;
+
+	pdev = pci_get_domain_bus_and_slot(arg->info.arg.bus, arg->info.arg.dev,
+					   arg->info.arg.devfn);
+	if (!pdev) {
+		status = -ENODEV;
+		goto out;
+	}
+
+	pdev_rp = pcie_find_root_port(pdev);
+	if (!pdev_rp || !pdev_rp->bus || !pdev_rp->bus->bridge) {
+		status = -ENODEV;
+		goto out;
+	}
+
+	handle = ACPI_HANDLE(pdev_rp->bus->bridge);
+
+	if (tph_invoke_dsm(handle, arg->info.arg.pkg_arg1, &ret->info.ret.st) !=
+			   AE_OK) {
+		status = -EOPNOTSUPP;
+		goto out;
+	}
+out:
+	ret->info.ret.status = status;
+	return 0;
+}
+
+static int tph_register_genl_cb(void)
+{
+	int err = 0;
+	struct acpi_genl_dsm_handle *handle =
+		kzalloc(sizeof(struct acpi_genl_dsm_handle), GFP_ATOMIC);
+	if (!handle) {
+		err = -ENOMEM;
+		goto out;
+	}
+
+	handle->id.guid = pci_acpi_dsm_guid;
+	handle->id.rev  = 7;
+	handle->id.func = TPH_ST_DSM_FUNC_INDEX;
+	handle->arg_len = sizeof(struct tph_genl_dsm_info);
+	handle->ret_len = sizeof(struct tph_genl_dsm_info);
+	handle->dsm_cb  = tph_invoke_dsm_genl_cb;
+	handle->cap     = CAP_SYS_ADMIN;
+
+	err = acpi_genl_dsm_add_handle(handle);
+	if (err) {
+		kfree(handle);
+		goto out;
+	}
+out:
+	return err;
+}
+
+late_initcall(tph_register_genl_cb);
 #endif
 
 /* Update the TPH Requester Enable field of TPH Control Register */
Signature · 1 line
2.43.0
#4 lore raw

Re: [RFC PATCH 2/2] PCI: Add generic netlink interface to TPH _DSM

kernel test robot noticed the following build warnings:

Hi Wathsala,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on rafael-pm/bleeding-edge pci/next pci/for-linus linus/master v6.13-rc6 next-20250107] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wathsala-Vithanage/ACPI-Add-support-for-invoking-select-_DSM-methods-from-user-space/20250107-003201
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link:    https://lore.kernel.org/r/20250106163045.508959-3-wathsala.vithanage%40arm.com
patch subject: [RFC PATCH 2/2] PCI: Add generic netlink interface to TPH _DSM
config: loongarch-randconfig-002-20250107 (https://download.01.org/0day-ci/archive/20250107/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250107/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/pci/tph.c: In function 'tph_invoke_dsm_genl_cb':

>> drivers/pci/tph.c:169:13: warning: variable 'cpu_uid' set but not used [-Wunused-but-set-variable]
     169 |         u32 cpu_uid;
         |             ^~~~~~~

vim +/cpu_uid +169 drivers/pci/tph.c

163
164 static int tph_invoke_dsm_genl_cb(struct acpi_genl_dsm_id *in,
165 struct acpi_genl_dsm_id *out)
166 {
167 struct pci_dev *pdev, *pdev_rp;
168 acpi_handle handle;

 > 169		u32 cpu_uid;

170 int status = 0;
171
172 struct tph_genl_dsm_info *arg = (struct tph_genl_dsm_info *)in;
173 struct tph_genl_dsm_info *ret = (struct tph_genl_dsm_info *)out;
174
175 /* Honor notph and acpi kernel parameters */
176 if (acpi_disabled || acpi_pci_disabled || pci_tph_disabled) {
177 status = -EINVAL;
178 goto out;
179 }
180
181 /*
182 * pkg_arg1 contains the kernel logical CPU id provided by the user,
183 * make sure it's a valid CPU id before passing it to down to firmware.
184 * pkg_arg2 is not use by tph_invoke_dsm, hence no validation is
185 * required.
186 */
187 if (!(arg->info.arg.pkg_arg1 < nr_cpu_ids &&
188 cpu_present(arg->info.arg.pkg_arg1))) {
189 status = -EINVAL;
190 goto out;
191 }
192
193 cpu_uid = topology_core_id(arg->info.arg.pkg_arg1);
194
195 ret->id.guid = pci_acpi_dsm_guid;
196 ret->id.rev = 7;
197 ret->id.func = TPH_ST_DSM_FUNC_INDEX;
198
199 pdev = pci_get_domain_bus_and_slot(arg->info.arg.bus, arg->info.arg.dev,
200 arg->info.arg.devfn);
201 if (!pdev) {
202 status = -ENODEV;
203 goto out;
204 }
205
206 pdev_rp = pcie_find_root_port(pdev);
207 if (!pdev_rp || !pdev_rp->bus || !pdev_rp->bus->bridge) {
208 status = -ENODEV;
209 goto out;
210 }
211
212 handle = ACPI_HANDLE(pdev_rp->bus->bridge);
213
214 if (tph_invoke_dsm(handle, arg->info.arg.pkg_arg1, &ret->info.ret.st) !=
215 AE_OK) {
216 status = -EOPNOTSUPP;
217 goto out;
218 }
219 out:
220 ret->info.ret.status = status;
221 return 0;
222 }
223

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw
In reply to Wathsala Vithanage
Quoted 23 lines · On Mon, 6 Jan 2025 16:30:43 +0000 Wathsala Vithanage…

Linux v6.13-rc1 added support for PCIe TPH and direct cache injection. As already described in the patch set[1] that introduced this feature, the cache injection in supported hardware allows optimal utilization of platform resources for specific requests on the PCIe bus. However, the patch set [1] implements the functionality for usage within the kernel. But certain user space applications, especially those whose performance is sensitive to the latency of inbound writes as seen by a CPU core, may benefit from using this information (E.g., the DPDK cache stashing feature discussed in RFC [2]). This RFC is an attempt to obtain the PCIe steering tag information from the kernel to be used by user mode applications. We understand that there is more than one way to provide this information. Please review and suggest alternatives if necessary.

The first of the two patches introduced in this RFC attempts to overcome the kernel-only limitation by providing an API to kernel subsystems to hook up relevant _DSM methods to a GENL interface. User space applications can invoke a _DSM hooked up to this interface via the "acpi-event" GENL family socket, granted they have the minimum capabilities and message formats demanded by the kernel subsystem that hooked up the _DSM method. This feature is added by extending the "acpi-event" GENL family that multicasts ACPI events to the user-space applications such as acpid.

Quoted 7 lines

The second patch of this RFC hooks up the PCIe root-port TLP Processing Hints (TPH) _DSM to the ACPI GENL interface. User space applications like [2] can now request the kernel to execute the _DSM on their behalf and return steering-tag information.

[1] lore.kernel.org/linux-pci/[email protected]
[2] inbox.dpdk.org/dev/[email protected]

Hi Wathsala,

Superficially this feels like another potential interface that could be wrapped up under appropriate fwctl. Jason, what do you think?

Mind you I'm not personally convinced that an interface that focuses on exposing _DSM calls to userspace makes sense as opposed to subsystem specific stuff.

Maybe consider associating the actual interface with the individual PCI functions (which provides the first chunk of the message directly).

Also, _DSM is just one form of firmware interface used for PCI supporting system. Tying the userspace interface to that feels unwise. I can certainly foresee a PSCI/SCMI or similar interface for this on ARM platforms wrapped up in _DSM where ACPI is present but directly accessed when DT is in use.

I'd also request that you break out what goes in ARG0,1,2 as that is all stuff that the kernel is aware of and not all reviewers have access to the ECN (I do though). In particular the fact there are ACPI UIDs may need a more generic solution.

Jonathan

Quoted 15 lines

Wathsala Vithanage (2):
ACPI: Add support for invoking select _DSM methods from user space
PCI: Add generic netlink interface to TPH _DSM

 drivers/acpi/Makefile                 |   3 +-
 drivers/acpi/{event.c => acpi_genl.c} | 110 ++++++++++++++++++++++-
 drivers/acpi/acpi_genl_dsm.c          |  76 ++++++++++++++++
 drivers/pci/tph.c                     | 121 ++++++++++++++++++++++++++
 include/acpi/acpi_genl.h              |  54 ++++++++++++
 include/linux/acpi.h                  |   1 +
 6 files changed, 360 insertions(+), 5 deletions(-)
 rename drivers/acpi/{event.c => acpi_genl.c} (63%)
 create mode 100644 drivers/acpi/acpi_genl_dsm.c
 create mode 100644 include/acpi/acpi_genl.h
#6 lore raw

Hi,

Quoted 39 lines · Jonathan Cameron
Quoted 23 lines · On Mon, 6 Jan 2025 16:30:43 +0000 Wathsala Vithanage…

Linux v6.13-rc1 added support for PCIe TPH and direct cache injection. As already described in the patch set[1] that introduced this feature, the cache injection in supported hardware allows optimal utilization of platform resources for specific requests on the PCIe bus. However, the patch set [1] implements the functionality for usage within the kernel. But certain user space applications, especially those whose performance is sensitive to the latency of inbound writes as seen by a CPU core, may benefit from using this information (E.g., the DPDK cache stashing feature discussed in RFC [2]). This RFC is an attempt to obtain the PCIe steering tag information from the kernel to be used by user mode applications. We understand that there is more than one way to provide this information. Please review and suggest alternatives if necessary.

The first of the two patches introduced in this RFC attempts to overcome the kernel-only limitation by providing an API to kernel subsystems to hook up relevant _DSM methods to a GENL interface. User space applications can invoke a _DSM hooked up to this interface via the "acpi-event" GENL family socket, granted they have the minimum capabilities and message formats demanded by the kernel subsystem that hooked up the _DSM method. This feature is added by extending the "acpi-event" GENL family that multicasts ACPI events to the user-space applications such as acpid.

Quoted 7 lines

The second patch of this RFC hooks up the PCIe root-port TLP Processing Hints (TPH) _DSM to the ACPI GENL interface. User space applications like [2] can now request the kernel to execute the _DSM on their behalf and return steering-tag information.

[1] lore.kernel.org/linux-pci/[email protected]
[2] inbox.dpdk.org/dev/[email protected]

Hi Wathsala,

Superficially this feels like another potential interface that could be wrapped up under appropriate fwctl. Jason, what do you think?

Quoted 6 lines

Mind you I'm not personally convinced that an interface that focuses on exposing _DSM calls to userspace makes sense as opposed to subsystem specific stuff.

Maybe consider associating the actual interface with the individual PCI functions (which provides the first chunk of the message directly).

Right,

I think this was similar to a conversation we had internally, which was basically to detect the PCIe extended capability and export a 'steering' entry in sysfs on each PCIe device which can take a logical cpu/cache value, translate those on write to the ACPI cpu/cache id's, make the firmware call, then directly update the PCIe device's capability with the result. This also leaves the door open for future cpu/cache->steering tag translation methods to transparently replace the _DSM call while leaving the userspace API the same.

Quoted 30 lines

Also, _DSM is just one form of firmware interface used for PCI supporting system. Tying the userspace interface to that feels unwise. I can certainly foresee a PSCI/SCMI or similar interface for this on ARM platforms wrapped up in _DSM where ACPI is present but directly accessed when DT is in use.

I'd also request that you break out what goes in ARG0,1,2 as that is all stuff that the kernel is aware of and not all reviewers have access to the ECN (I do though). In particular the fact there are ACPI UIDs may need a more generic solution.

Jonathan

Quoted 15 lines

Wathsala Vithanage (2):
ACPI: Add support for invoking select _DSM methods from user space
PCI: Add generic netlink interface to TPH _DSM

  drivers/acpi/Makefile                 |   3 +-
  drivers/acpi/{event.c => acpi_genl.c} | 110 ++++++++++++++++++++++-
  drivers/acpi/acpi_genl_dsm.c          |  76 ++++++++++++++++
  drivers/pci/tph.c                     | 121 ++++++++++++++++++++++++++
  include/acpi/acpi_genl.h              |  54 ++++++++++++
  include/linux/acpi.h                  |   1 +
  6 files changed, 360 insertions(+), 5 deletions(-)

rename drivers/acpi/{event.c => acpi_genl.c} (63%) create mode 100644 drivers/acpi/acpi_genl_dsm.c create mode 100644 include/acpi/acpi_genl.h

#7 lore raw
Quoted 15 lines · Jeremy Linton

Hi,

Quoted 12 lines · Jonathan Cameron
Quoted 9 lines · On Mon, 6 Jan 2025 16:30:43 +0000 Wathsala Vithanage…

Linux v6.13-rc1 added support for PCIe TPH and direct cache injection. As already described in the patch set[1] that introduced this feature, the cache injection in supported hardware allows optimal utilization of platform resources for specific requests on the PCIe bus. However, the patch set [1] implements the functionality for usage within the kernel. But certain user space applications, especially those whose performance is sensitive to the latency of inbound writes as seen by a CPU core, may benefit from using this information (E.g., the DPDK cache stashing feature discussed in RFC [2]).

There is no way for userspace to program TPH information into a PCI device without going through a kernel driver, and the kernel driver must be the exclusive owner of the steering tag configuration or chaos would ensue. Having a way for sysfs to override this seems very wrong to me, and I think you should not go in this direction.

DPDK runs on VFIO or RDMA. It would natural to have an VFIO native API to manipulate the steering tags, and we are already discussing what RDMA support for steering tag would look like.

Quoted 2 lines
Quoted 2 lines

Superficially this feels like another potential interface that could be wrapped up under appropriate fwctl. Jason, what do you think?

As above, I think this very squarely belongs under the appropriate subsystems that are providing the kernel drivers for the device. There is no reasonable way to share steering tags with unrelated userspace through any mechanism. Basically it fails the independence test of fwctl.

Quoted 5 lines

I think this was similar to a conversation we had internally, which was basically to detect the PCIe extended capability and export a 'steering' entry in sysfs on each PCIe device which can take a logical cpu/cache value, translate those on write to the ACPI cpu/cache id's, make the firmware call, then directly update the PCIe device's capability with the result.

Seems wrong, driver must do this. If the driver was already using that entry for something else you've just wrecked it.

Jason

#8 lore raw

Hi,

Quoted 36 lines · Jason Gunthorpe
Quoted 15 lines · Jeremy Linton

Hi,

Quoted 12 lines · Jonathan Cameron
Quoted 9 lines · On Mon, 6 Jan 2025 16:30:43 +0000 Wathsala Vithanage…

Linux v6.13-rc1 added support for PCIe TPH and direct cache injection. As already described in the patch set[1] that introduced this feature, the cache injection in supported hardware allows optimal utilization of platform resources for specific requests on the PCIe bus. However, the patch set [1] implements the functionality for usage within the kernel. But certain user space applications, especially those whose performance is sensitive to the latency of inbound writes as seen by a CPU core, may benefit from using this information (E.g., the DPDK cache stashing feature discussed in RFC [2]).

There is no way for userspace to program TPH information into a PCI device without going through a kernel driver, and the kernel driver must be the exclusive owner of the steering tag configuration or chaos would ensue. Having a way for sysfs to override this seems very wrong to me, and I think you should not go in this direction.

DPDK runs on VFIO or RDMA. It would natural to have an VFIO native API to manipulate the steering tags, and we are already discussing what RDMA support for steering tag would look like.

Quoted 2 lines
Quoted 2 lines

Superficially this feels like another potential interface that could be wrapped up under appropriate fwctl. Jason, what do you think?

As above, I think this very squarely belongs under the appropriate subsystems that are providing the kernel drivers for the device. There is no reasonable way to share steering tags with unrelated userspace through any mechanism. Basically it fails the independence test of fwctl.

Quoted 8 lines
Quoted 5 lines

I think this was similar to a conversation we had internally, which was basically to detect the PCIe extended capability and export a 'steering' entry in sysfs on each PCIe device which can take a logical cpu/cache value, translate those on write to the ACPI cpu/cache id's, make the firmware call, then directly update the PCIe device's capability with the result.

Seems wrong, driver must do this. If the driver was already using that entry for something else you've just wrecked it.

Can you clarify what you mean by 'wrecked'? AFAIK a valid, if poorly chosen, steering tag is going to be sub-optimal performance.

I'm under the impression this is a similar problem to cpu/irq/numa affinity where the driver/subsystem should be making the choice, but the user is provided the opportunity to override the defaults if they think there is benefit in their environment. Again AFAIK, the whole OS/software stashing is already well down the 'I know better than the HW where to store this data' rabbit hole.

Thanks,

#9 lore raw
Quoted 4 lines · Jeremy Linton

I'm under the impression this is a similar problem to cpu/irq/numa affinity where the driver/subsystem should be making the choice, but the user is provided the opportunity to override the defaults if they think there is benefit in their environment.

Which I think has been proven to have been a mistake. Instead over overriding irq affinity though proc/irq under the covers of the driver and hoping for the best the driver itself should have the opportinuty to set the affinity for its objects directly.

Lets us not repeat this mistake with steering tag. The driver should always be involved in this stuff, if you want it to work with DPDK then go through the kernel driver that DPDK is running on top of (VFIO or RDMA)

Jason

#10 lore raw
Quoted 12 lines · Jeremy Linton
Quoted 5 lines

I'm under the impression this is a similar problem to cpu/irq/numa affinity where the driver/subsystem should be making the choice, but the user is provided the opportunity to override the defaults if they think there is benefit in their environment.

Which I think has been proven to have been a mistake. Instead over overriding irq affinity though proc/irq under the covers of the driver and hoping for the best the driver itself should have the opportinuty to set the affinity for its objects directly.

Do you mean that the driver should handle affinity requests from the user directly as per its policy?

Quoted 4 lines

Lets us not repeat this mistake with steering tag. The driver should always be involved in this stuff, if you want it to work with DPDK then go through the kernel driver that DPDK is running on top of (VFIO or RDMA)

This RFC is only about acquiring the steering tag from the ACPI _DSM, which the DPDK user space driver will set in the queue context of the device it manages. Setting of the steering tag part happens in the DPDK device driver.
Are you suggesting that I should instead pass a CPU and a cache ID to VFIO and let VFIO decide what's right for the application?

--wathsala

#11 lore raw
Quoted 11 lines · Wathsala Wathawana Vithanage
Quoted 8 lines
Quoted 4 lines

I'm under the impression this is a similar problem to cpu/irq/numa affinity where the driver/subsystem should be making the choice, but the user is provided the opportunity to override the defaults if they think there is benefit in their environment.

Which I think has been proven to have been a mistake. Instead over overriding irq affinity though proc/irq under the covers of the driver and hoping for the best the driver itself should have the opportinuty to set the affinity for its objects directly.

Do you mean that the driver should handle affinity requests from the user directly as per its policy?

Yes, not every driver has tidy mappings of objects to interrupts vectors.

Quoted 9 lines
Quoted 3 lines

Lets us not repeat this mistake with steering tag. The driver should always be involved in this stuff, if you want it to work with DPDK then go through the kernel driver that DPDK is running on top of (VFIO or RDMA)

This RFC is only about acquiring the steering tag from the ACPI _DSM, which the DPDK user space driver will set in the queue context of the device it manages. Setting of the steering tag part happens in the DPDK device driver.
Are you suggesting that I should instead pass a CPU and a cache ID to VFIO and let VFIO decide what's right for the application?

I think that would be better, yes. Get VFIO to give you the steering tag information, and any related control of the config space you may need, via an IOCTL.

Jason

#12 lore raw
Quoted 23 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

I'm under the impression this is a similar problem to cpu/irq/numa affinity where the driver/subsystem should be making the choice, but the user is provided the opportunity to override the defaults if they think there is benefit in their environment.

Which I think has been proven to have been a mistake. Instead over overriding irq affinity though proc/irq under the covers of the driver and hoping for the best the driver itself should have the opportinuty to

set the affinity for its objects directly.

Quoted 3 lines

Do you mean that the driver should handle affinity requests from the user directly as per its policy?

Yes, not every driver has tidy mappings of objects to interrupts vectors.

Quoted 7 lines
Quoted 4 lines

Lets us not repeat this mistake with steering tag. The driver should always be involved in this stuff, if you want it to work with DPDK then go through the kernel driver that DPDK is running on top of (VFIO or RDMA)

This RFC is only about acquiring the steering tag from the ACPI _DSM, which the DPDK user space driver will set in the queue context of the device it

Quoted 8 lines

manages.

Quoted 3 lines

Setting of the steering tag part happens in the DPDK device driver. Are you suggesting that I should instead pass a CPU and a cache ID to VFIO and let VFIO decide what's right for the application?

I think that would be better, yes. Get VFIO to give you the steering tag information, and any related control of the config space you may need, via an IOCTL.

Sounds good, I like that idea.

--wathsala

#13 lore raw
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

This RFC is only about acquiring the steering tag from the ACPI _DSM, which the DPDK user space driver will set in the queue context of the device it manages.
Setting of the steering tag part happens in the DPDK device driver. Are you suggesting that I should instead pass a CPU and a cache ID to VFIO and let VFIO decide what's right for the application?

Quoted 5 lines
Quoted 3 lines

I think that would be better, yes. Get VFIO to give you the steering tag information, and any related control of the config space you may need, via an IOCTL.

Sounds good, I like that idea.

Yeah, remember there is a broad complexity here. Some devices want to setup their steering tag information through the MSI-X table, for instance. VFIO is the right place to assist DPDK with all of these cases that need kernel involvement.

Jason