Skip to contentSkip to conversation

i2c: SMBus ARP support

PATCH In review Heikki Krogerus 4 participants 18 messages Jan 21 – Feb 2

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

v2 cover i2c: SMBus ARP support

Hi,

Changed in v2:

- Using kzalloc instead of kzalloc_obj. kzalloc_obj() is clearly not ready yet (scripts/checkpatch.pl should not promote it yet).

Original cover letter:

I know there has been a couple of PoCs for ARP over the years, but for what ever reason none of them were ever made part of the kernel. I don't know how common ARP-capable devices are, but since they do exist, we really should enumerate them as intended. I'm guessing that in Linux ARP-capable devices have so far been left mostly undetected.

The problem I'm trying to tackle with these is to detect SMBus devices on discrete components like PCIe cards. We obviously won't have any kind ACPI or DT description for those, so we would always have to create the device for them in the drivers. Unfortunately in some cases it's actually very difficult to know what exactly is attached to the I2C on those cards because the vendors can put what ever they like there - this is the case at least with some of the GPUs it seems. But luckily those I2C/SMBus devices are at least in some cases fully ARP-capable.

I'm including a patch that binds the detected ARP-capable MCTP devices to the driver. There is also a target mode test driver.

thanks,

Heikki Krogerus (4):
i2c: SMBus Address Resolution Protocol implementation for host side
i2c: Sysfs attribute files for the Unique Device Identifier fields mctp i2c: Enable SMBus ARP discovery
i2c: Add SMBus ARP target mode test driver

 Documentation/ABI/testing/sysfs-bus-i2c |  53 ++++
 drivers/i2c/Kconfig                     |   6 +
 drivers/i2c/Makefile                    |   3 +-
 drivers/i2c/i2c-core-arp.c              | 334 ++++++++++++++++++++++++
 drivers/i2c/i2c-core-base.c             | 154 ++++++++++-
 drivers/i2c/i2c-core.h                  |   8 +
 drivers/i2c/i2c-target-arp.c            | 201 ++++++++++++++
 drivers/net/mctp/mctp-i2c.c             |   8 +
 include/linux/i2c-smbus.h               |  67 +++++
 include/linux/i2c.h                     |  10 +
 include/linux/mod_devicetable.h         |  13 +
 scripts/mod/devicetable-offsets.c       |   8 +
 scripts/mod/file2alias.c                |  24 ++
 13 files changed, 878 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c
 create mode 100644 drivers/i2c/i2c-core-arp.c
 create mode 100644 drivers/i2c/i2c-target-arp.c
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/4 i2c: SMBus Address Resolution Protocol implementation for host side

SMBus Address Resolution Protocol (ARP) is a standard (but optional) method to detect and identify devices on SMBus. The ARP is higher level message protocol that can be fully emulated. ARP will therefore always be supported, and the ARP-capable devices will be scanned automatically for every adapter that is registered.

The ARP devices are identified with the Unique Device Identifier (UDID). The UDID can be used for device matching in drivers with a new struct smbus_device_id.

The function i2c_handle_smbus_host_notify() is also modified so that the hotplugged ARP devices that send Notify ARP Controller command can be detected.

---
 drivers/i2c/Makefile              |   2 +-
 drivers/i2c/i2c-core-arp.c        | 334 ++++++++++++++++++++++++++++++
 drivers/i2c/i2c-core-base.c       |  47 ++++-
 drivers/i2c/i2c-core.h            |   8 +
 include/linux/i2c-smbus.h         |  67 ++++++
 include/linux/i2c.h               |  10 +
 include/linux/mod_devicetable.h   |  13 ++
 scripts/mod/devicetable-offsets.c |   8 +
 scripts/mod/file2alias.c          |  24 +++
 9 files changed, 503 insertions(+), 10 deletions(-)
 create mode 100644 drivers/i2c/i2c-core-arp.c
drivers/i2c/Makefile +1 -1
index d27de18de46f..4fdb37b94aa4 100644
@@ -5,7 +5,7 @@
 
 obj-$(CONFIG_I2C_BOARDINFO)	+= i2c-boardinfo.o
 obj-$(CONFIG_I2C)		+= i2c-core.o
-i2c-core-y			:= i2c-core-base.o i2c-core-smbus.o
+i2c-core-y			:= i2c-core-base.o i2c-core-smbus.o i2c-core-arp.o
 i2c-core-$(CONFIG_ACPI)		+= i2c-core-acpi.o
 i2c-core-$(CONFIG_I2C_SLAVE)	+= i2c-core-slave.o
 i2c-core-$(CONFIG_OF)		+= i2c-core-of.o
drivers/i2c/i2c-core-arp.c new file +334 -0

334 lines not on this page · raw message

drivers/i2c/i2c-core-base.c +38 -9

107 lines not on this page · raw message

drivers/i2c/i2c-core.h +8 -0
index 4797ba88331c..c8f7d8e49621 100644
@@ -60,6 +60,8 @@ static inline int __i2c_check_suspended(struct i2c_adapter *adap)
 	return 0;
 }
 
+int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr);
+
 #ifdef CONFIG_ACPI
 void i2c_acpi_register_devices(struct i2c_adapter *adap);
 
@@ -106,3 +108,9 @@ static inline int i2c_setup_smbus_alert(struct i2c_adapter *adap)
 	return 0;
 }
 #endif
+
+const struct smbus_device_id *i2c_smbus_match_id(const struct i2c_client *client,
+						 const struct smbus_device_id *id);
+int i2c_smbus_arp_detect(struct i2c_adapter *adapter, u8 target_address);
+int i2c_smbus_arp_probe(struct i2c_adapter *adapter);
+void i2c_smbus_arp_remove(struct i2c_adapter *adapter);
include/linux/i2c-smbus.h +67 -0

71 lines not on this page · raw message

include/linux/i2c.h +10 -0
index 20fd41b51d5c..1f0cd285e711 100644
@@ -34,6 +34,8 @@ struct i2c_adapter;
 struct i2c_client;
 struct i2c_driver;
 struct i2c_device_identity;
+struct i2c_smbus_arp;
+struct i2c_arp_udid;
 union i2c_smbus_data;
 struct i2c_board_info;
 enum i2c_slave_event;
@@ -242,6 +244,7 @@ enum i2c_driver_flags {
  * @command: Callback for bus-wide signaling (optional)
  * @driver: Device driver model driver
  * @id_table: List of I2C devices supported by this driver
+ * @smbus_id_table: SMBus ARP devices supported by this driver
  * @detect: Callback for device detection
  * @address_list: The I2C addresses to probe (for detect)
  * @clients: List of detected clients we created (for i2c-core use only)
@@ -295,6 +298,7 @@ struct i2c_driver {
 
 	struct device_driver driver;
 	const struct i2c_device_id *id_table;
+	const struct smbus_device_id *smbus_id_table;
 
 	/* Device detection callback for automatic device creation */
 	int (*detect)(struct i2c_client *client, struct i2c_board_info *info);
@@ -311,6 +315,7 @@ struct i2c_driver {
  * @addr: Address used on the I2C bus connected to the parent adapter.
  * @name: Indicates the type of the device, usually a chip name that's
  *	generic enough to hide second-sourcing and compatible revisions.
+ * @udid: SMBus ARP Unique Device Identifier
  * @adapter: manages the bus segment hosting this I2C device
  * @dev: Driver model device node for the slave.
  * @init_irq: IRQ that was set at initialization
@@ -343,6 +348,7 @@ struct i2c_client {
 					/* addresses are stored in the	*/
 					/* _LOWER_ 7 bits		*/
 	char name[I2C_NAME_SIZE];
+	struct i2c_arp_udid *udid;	/* Unique Device Identifier	*/
 	struct i2c_adapter *adapter;	/* the adapter we sit on	*/
 	struct device dev;		/* the device structure		*/
 	int init_irq;			/* irq set at initialization	*/
@@ -410,6 +416,7 @@ static inline bool i2c_detect_slave_mode(struct device *dev) { return false; }
  * @resources: resources associated with the device
  * @num_resources: number of resources in the @resources array
  * @irq: stored in i2c_client.irq
+ * @udid: SMBus ARP Unique Device Identifier
  *
  * I2C doesn't actually support hardware probing, although controllers and
  * devices may be able to use I2C_SMBUS_QUICK to tell whether or not there's
@@ -433,6 +440,7 @@ struct i2c_board_info {
 	const struct resource *resources;
 	unsigned int	num_resources;
 	int		irq;
+	struct i2c_arp_udid *udid;
 };
 
 /**
@@ -755,6 +763,8 @@ struct i2c_adapter {
 	struct mutex userspace_clients_lock;
 	struct list_head userspace_clients;
 
+	struct i2c_smbus_arp *arp;
+
 	struct i2c_bus_recovery_info *bus_recovery_info;
 	const struct i2c_adapter_quirks *quirks;
 
include/linux/mod_devicetable.h +13 -0
index 24eb5a88a5c5..9d75cdb81e25 100644
@@ -480,6 +480,19 @@ struct i2c_device_id {
 	kernel_ulong_t driver_data;	/* Data private to the driver */
 };
 
+#define SMBUS_ANY_ID			0xffff
+#define SMBUS_ANY_VENDOR_SPECIFIC_ID	0xffffffff
+
+struct smbus_device_id {
+	__u16 vendor;
+	__u16 device;
+	__u16 interface;
+	__u16 subvendor;
+	__u16 subdevice;
+	__u32 vendor_specific_id;
+	kernel_ulong_t driver_data;	/* Data private to the driver */
+};
+
 /* pci_epf */
 
 #define PCI_EPF_NAME_SIZE	20
scripts/mod/devicetable-offsets.c +8 -0
index b4178c42d08f..cd53628e1470 100644
@@ -147,6 +147,14 @@ int main(void)
 	DEVID(i2c_device_id);
 	DEVID_FIELD(i2c_device_id, name);
 
+	DEVID(smbus_device_id);
+	DEVID_FIELD(smbus_device_id, vendor);
+	DEVID_FIELD(smbus_device_id, device);
+	DEVID_FIELD(smbus_device_id, interface);
+	DEVID_FIELD(smbus_device_id, subvendor);
+	DEVID_FIELD(smbus_device_id, subdevice);
+	DEVID_FIELD(smbus_device_id, vendor_specific_id);
+
 	DEVID(i3c_device_id);
 	DEVID_FIELD(i3c_device_id, match_flags);
 	DEVID_FIELD(i3c_device_id, dcr);
scripts/mod/file2alias.c +24 -0
index 4e99393a35f1..66efff6d3623 100644
@@ -840,6 +840,29 @@ static void do_i2c_entry(struct module *mod, void *symval)
 	module_alias_printf(mod, false, I2C_MODULE_PREFIX "%s", *name);
 }
 
+/* Looks like: smbus:vNdNiNsvNsdNvsiN*/
+static void do_smbus_entry(struct module *mod, void *symval)
+{
+	char alias[256] = {};
+
+	DEF_FIELD(symval, smbus_device_id, vendor);
+	DEF_FIELD(symval, smbus_device_id, device);
+	DEF_FIELD(symval, smbus_device_id, interface);
+	DEF_FIELD(symval, smbus_device_id, subvendor);
+	DEF_FIELD(symval, smbus_device_id, subdevice);
+	DEF_FIELD(symval, smbus_device_id, vendor_specific_id);
+
+	ADD(alias, "v", vendor != SMBUS_ANY_ID, vendor);
+	ADD(alias, "d", device != SMBUS_ANY_ID, device);
+	ADD(alias, "i", interface != SMBUS_ANY_ID, interface);
+	ADD(alias, "sv", subvendor != SMBUS_ANY_ID, subvendor);
+	ADD(alias, "sd", subdevice != SMBUS_ANY_ID, subdevice);
+	ADD(alias, "vsi", vendor_specific_id != SMBUS_ANY_VENDOR_SPECIFIC_ID,
+	    vendor_specific_id);
+
+	module_alias_printf(mod, true, "smbus:%s", alias);
+}
+
 static void do_i3c_entry(struct module *mod, void *symval)
 {
 	char alias[256] = {};
@@ -1439,6 +1462,7 @@ static const struct devtable devtable[] = {
 	{"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
 	{"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry},
 	{"i2c", SIZE_i2c_device_id, do_i2c_entry},
+	{"smbus", SIZE_smbus_device_id, do_smbus_entry},
 	{"i3c", SIZE_i3c_device_id, do_i3c_entry},
 	{"slim", SIZE_slim_device_id, do_slim_entry},
 	{"spi", SIZE_spi_device_id, do_spi_entry},
Signature · 1 line
2.50.1
#2 lore raw

PATCH v2 2/4 i2c: Sysfs attribute files for the Unique Device Identifier fields

In reply to Heikki Krogerus

In order to utilise the SMBus Address Resolution Protocol's (ARP) Unique Device Identifier (UDID) also in user space, the UDID details need to be exposed. With ARP the address is also dynamically assigned (and may be reset) so it also needs to be exposed to the user space with its own file.

The UDID details are only visible with ARP devices, but the address file is made always visible for all I2C client devices.

---
 Documentation/ABI/testing/sysfs-bus-i2c |  53 ++++++++++++
 drivers/i2c/i2c-core-base.c             | 107 +++++++++++++++++++++++-
 2 files changed, 159 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c
Documentation/ABI/testing/sysfs-bus-i2c new file +53 -0
new file mode 100644
index 000000000000..b9ebfc2e1b9d
@@ -0,0 +1,53 @@
+What:		/sys/bus/i2c/devices/.../address
+Date:		September 2025
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		This file has the target address the I2C client responds to.
+
+What:		/sys/bus/i2c/devices/.../vendor
+Date:		September 2025
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		This file is only visible for ARP devices. It returns the Vendor
+		ID field from the SMBus ARP Unique Device Identifier. It is the
+		device manufacturer's ID assigned by the SBS Implementers Forum
+		or the PCI SIG.
+
+What:		/sys/bus/i2c/devices/.../device
+Date:		September 2025
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		This file is only visible for ARP devices. It returns the Device
+		ID field from the SMBus ARP Unique Device Identifier. The
+		device ID is assigned by the device manufacturer.
+
+What:		/sys/bus/i2c/devices/.../interface
+Date:		September 2025
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		This file is only visible for ARP devices. It returns the
+		Interface field from the SMBus ARP Unique Device Identifier.
+
+What:		/sys/bus/i2c/devices/.../subsystem_vendor
+Date:		September 2025
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		This file is only visible for ARP devices. It returns the
+		Subsystem Vendor ID field from the SMBus ARP Unique Device
+		Identifier.
+
+What:		/sys/bus/i2c/devices/.../subsystem_device
+Date:		September 2025
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		This file is only visible for ARP devices. It returns the
+		Subsystem Device ID field from the SMBus ARP Unique Device
+		Identifier.
+
+What:		/sys/bus/i2c/devices/.../vendor_specific_id
+Date:		September 2025
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		This file is only visible for ARP devices. It returns the
+		Vendor Specific ID field from the SMBus ARP Unique Device
+		Identifier.
drivers/i2c/i2c-core-base.c +106 -1

123 lines not on this page · raw message

Signature · 1 line
2.50.1
#3 lore raw

PATCH v2 3/4 mctp i2c: Enable SMBus ARP discovery

In reply to Heikki Krogerus

Since the SMBus Address Resolution Protocol (ARP) is now supported with all I2C host adapters, every ARP-capable MCTP device will get automatically enumerated. Those devices just need to be bind to this driver.

The SMBus ARP-capable MCTP devices are identified by checking the interface (MCTP SMBus/I2C Transport Binding Specification section 6.5). The interface must match the ASF protocol, so all devices that use the ASF protocol as their interface will be probed by this driver.

---
 drivers/net/mctp/mctp-i2c.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/net/mctp/mctp-i2c.c +8 -0
index 8043b57bdf25..47d7f6b5212e 100644
@@ -21,6 +21,7 @@
 #include <linux/netdevice.h>
 #include <linux/i2c.h>
 #include <linux/i2c-mux.h>
+#include <linux/i2c-smbus.h>
 #include <linux/if_arp.h>
 #include <net/mctp.h>
 #include <net/mctpdevice.h>
@@ -1105,6 +1106,12 @@ static const struct i2c_device_id mctp_i2c_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, mctp_i2c_id);
 
+static const struct smbus_device_id mctp_smbus_id[] = {
+	{ SMBUS_INTERFACE_ASF },
+	{}
+};
+MODULE_DEVICE_TABLE(smbus, mctp_smbus_id);
+
 static const struct of_device_id mctp_i2c_of_match[] = {
 	{ .compatible = "mctp-i2c-controller" },
 	{},
@@ -1119,6 +1126,7 @@ static struct i2c_driver mctp_i2c_driver = {
 	.probe = mctp_i2c_probe,
 	.remove = mctp_i2c_remove,
 	.id_table = mctp_i2c_id,
+	.smbus_id_table = mctp_smbus_id,
 };
 
 static __init int mctp_i2c_mod_init(void)
Signature · 1 line
2.50.1
maintainer
#4 lore raw

Re: [PATCH v2 3/4] mctp i2c: Enable SMBus ARP discovery

Quoted 5 lines · Heikki Krogerus

Since the SMBus Address Resolution Protocol (ARP) is now supported with all I2C host adapters, every ARP-capable MCTP device will get automatically enumerated. Those devices just need to be bind to this driver.

Quoted 8 lines

The SMBus ARP-capable MCTP devices are identified by checking the interface (MCTP SMBus/I2C Transport Binding Specification section 6.5). The interface must match the ASF protocol, so all devices that use the ASF protocol as their interface will be probed by this driver.

This patch depends on 1/4 but it looks like it could be a follow-up to the main series. If so, I think it would be better to re-submit it after the relevant code landed in net-next to avoid cross sub-tree problems.

Otherwise I think it should go via I2C tree - and we will solve conflicts as needed later on.

Thanks,

Paolo

maintainer
#5 lore raw

Re: [PATCH v2 3/4] mctp i2c: Enable SMBus ARP discovery

Quoted 15 lines · On Thu, 22 Jan 2026 15:36:05 +0100 Paolo Abeni wrote:
Quoted 5 lines · Heikki Krogerus

Since the SMBus Address Resolution Protocol (ARP) is now supported with all I2C host adapters, every ARP-capable MCTP device will get automatically enumerated. Those devices just need to be bind to this driver.

Quoted 8 lines

The SMBus ARP-capable MCTP devices are identified by checking the interface (MCTP SMBus/I2C Transport Binding Specification section 6.5). The interface must match the ASF protocol, so all devices that use the ASF protocol as their interface will be probed by this driver.

Quoted 6 lines

This patch depends on 1/4 but it looks like it could be a follow-up to the main series. If so, I think it would be better to re-submit it after the relevant code landed in net-next to avoid cross sub-tree problems.

Otherwise I think it should go via I2C tree - and we will solve conflicts as needed later on.

+1 I don't wanna speak for Jeremy and Matt but with their Ack, and assuming there's no dependency in net-next I think i2c tree may be the easiest path? There isn't much code in the series under drivers/net.

maintainer
#6 lore raw

Re: [PATCH v2 3/4] mctp i2c: Enable SMBus ARP discovery

Hi Heikki and Jakub,

Quoted 3 lines

+1 I don't wanna speak for Jeremy and Matt but with their Ack, and assuming there's no dependency in net-next I think i2c tree may be the easiest path?

Yes, given this is more i2c- than net-related, I would be fine for the changes to go via the i2c tree there. Staging the core via i2c and then (subsequently) this one via net would also work, but seems to be overkill for a minor change to the net driver.

I have some overall comments on the i2c side though, I'll follow up with those separately.

Cheers,

Jeremy

#7 lore raw

Re: [PATCH v2 3/4] mctp i2c: Enable SMBus ARP discovery

Fri, Jan 23, 2026 at 11:18:42AM +1100, Jeremy Kerr kirjoitti:

Quoted 10 lines

Hi Heikki and Jakub,

Quoted 3 lines

+1 I don't wanna speak for Jeremy and Matt but with their Ack, and assuming there's no dependency in net-next I think i2c tree may be the easiest path?

Yes, given this is more i2c- than net-related, I would be fine for the changes to go via the i2c tree there. Staging the core via i2c and then (subsequently) this one via net would also work, but seems to be overkill for a minor change to the net driver.

OK. I'll drop this one from v3 and send it separately later as a follow-up, once we have the i2c side ready.

Quoted 2 lines

I have some overall comments on the i2c side though, I'll follow up with those separately.

thanks,

Signature · 1 line
heikki
maintainer Acked-by
#8 lore raw

Re: [PATCH v2 3/4] mctp i2c: Enable SMBus ARP discovery

Quoted 11 lines · On Fri, 23 Jan 2026 10:46:38 +0200 Heikki Krogerus wrote:
Quoted 8 lines
Quoted 3 lines

+1 I don't wanna speak for Jeremy and Matt but with their Ack, and assuming there's no dependency in net-next I think i2c tree may be the easiest path?

Yes, given this is more i2c- than net-related, I would be fine for the changes to go via the i2c tree there. Staging the core via i2c and then (subsequently) this one via net would also work, but seems to be overkill for a minor change to the net driver.

OK. I'll drop this one from v3 and send it separately later as a follow-up, once we have the i2c side ready.

FWIW my reading of Jeremy's reply was that we're okay with these patches going via i2c, so:

and no need to drop this from the series.

#9 lore raw

PATCH v2 4/4 i2c: Add SMBus ARP target mode test driver

In reply to Heikki Krogerus

Backend that the hosts can enumerate by using the SMBus Address Resolution Protocol.

---
 drivers/i2c/Kconfig          |   6 ++
 drivers/i2c/Makefile         |   1 +
 drivers/i2c/i2c-target-arp.c | 201 +++++++++++++++++++++++++++++++++++
 3 files changed, 208 insertions(+)
 create mode 100644 drivers/i2c/i2c-target-arp.c
drivers/i2c/Kconfig +6 -0
index c232054fddd6..4b97a66fc698 100644
@@ -134,6 +134,12 @@ config I2C_SLAVE_TESTUNIT
 	  multi-master, SMBus Host Notify, etc. Please read
 	  Documentation/i2c/slave-testunit-backend.rst for further details.
 
+config I2C_TARGET_ARP
+	tristate "SMBus ARP target mode test driver"
+	help
+	  This backend makes Linux respond to SMBus Address Resolution Protocol
+	  commands.
+
 endif
 
 config I2C_DEBUG_CORE
drivers/i2c/Makefile +1 -0
index 4fdb37b94aa4..3ea292dab065 100644
@@ -19,5 +19,6 @@ obj-y				+= algos/ busses/ muxes/
 obj-$(CONFIG_I2C_STUB)		+= i2c-stub.o
 obj-$(CONFIG_I2C_SLAVE_EEPROM)	+= i2c-slave-eeprom.o
 obj-$(CONFIG_I2C_SLAVE_TESTUNIT)	+= i2c-slave-testunit.o
+obj-$(CONFIG_I2C_TARGET_ARP)	+= i2c-target-arp.o
 
 ccflags-$(CONFIG_I2C_DEBUG_CORE) := -DDEBUG
drivers/i2c/i2c-target-arp.c new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
2.50.1
maintainer
#10 lore raw
In reply to Heikki Krogerus

Hi Heikki,

Thanks for submitting these. Supporting SMBus ARP for MCTP has been on my wishlist for a while, so it's great to have a solid proposal here.

I'm curious about why you're proposing a kernel approach though; the actual ARP protocol implementation would likely be implementable in userspace. I think the only kernel facility we would need is a notification facility for the possible presence of ARP-able devices (ie, through a Notify ARP Master, or another mechanism described by 5.6.3.9). I *think* we have existing interfaces for the rest of the ARP process.

It's entirely possible I've missed something there; perhaps it's neater with the match tables and address allocation being all in-kernel. I'm keen to hear a bit of the rationale for the in-kernel implementation overall.

Cheers,

Jeremy

#11 lore raw

Hi Jeremy,

Quoted 12 lines · Jeremy Kerr

Hi Heikki,

Thanks for submitting these. Supporting SMBus ARP for MCTP has been on my wishlist for a while, so it's great to have a solid proposal here.

I'm curious about why you're proposing a kernel approach though; the actual ARP protocol implementation would likely be implementable in userspace. I think the only kernel facility we would need is a notification facility for the possible presence of ARP-able devices (ie, through a Notify ARP Master, or another mechanism described by 5.6.3.9). I *think* we have existing interfaces for the rest of the ARP process.

Quoted 4 lines

It's entirely possible I've missed something there; perhaps it's neater with the match tables and address allocation being all in-kernel. I'm keen to hear a bit of the rationale for the in-kernel implementation overall.

Since we use kernel mode device drivers, we need the kernel device instances (struct device) that bind to them. If you want to deal with user mode drivers then you can always do that with the i2c-dev interface, but then you will not be using the kernel drivers such as the mctp-i2c.c in this case. But just to be clear, this is not only about MCTP. The ARP-capable i2c-clients can be anything.

So even if you still want to scan the ARP-devices in user space separately, the kernel must enumerate those devices independently in any case.

I should also point out that to my surprise the i2c-dev interface (I2C_CHARDEV) isn't always enabled, even when I2C seems to be otherwise fully supported in the kernel. We simply can't assume that it's always available.

thanks,

Signature · 1 line
heikki
maintainer
#12 lore raw

Hi Heikki,

Quoted 5 lines

Since we use kernel mode device drivers, we need the kernel device instances (struct device) that bind to them. If you want to deal with user mode drivers then you can always do that with the i2c-dev interface, but then you will not be using the kernel drivers such as the mctp-i2c.c in this case.

Sure you could - the userspace ARP implementation would be responsible for binding an existing kernel driver to the newly-allocated dynamic i2c address - say, through the new_device interface. The choice of driver would typically depend on the enumerated UDID.

Quoted 2 lines

But just to be clear, this is not only
about MCTP. The ARP-capable i2c-clients can be anything.

Yes, I'm not just talking about MCTP here either.

Quoted 8 lines

So even if you still want to scan the ARP-devices in user space separately, the kernel must enumerate those devices independently in any case.

I should also point out that to my surprise the i2c-dev interface (I2C_CHARDEV) isn't always enabled, even when I2C seems to be otherwise fully supported in the kernel. We simply can't assume that it's always available.

I don't think requiring a specific functionality to be enabled would be a showstopper for any particular implementation. We need CONFIG_I2C already, why is CONFIG_I2C_CHARDEV any different?

Cheers,

Jeremy

#13 lore raw

Hi,

Quoted 8 lines · Jeremy Kerr

Hi Heikki,

Quoted 5 lines

Since we use kernel mode device drivers, we need the kernel device instances (struct device) that bind to them. If you want to deal with user mode drivers then you can always do that with the i2c-dev interface, but then you will not be using the kernel drivers such as the mctp-i2c.c in this case.

Quoted 4 lines

Sure you could - the userspace ARP implementation would be responsible for binding an existing kernel driver to the newly-allocated dynamic i2c address - say, through the new_device interface. The choice of driver would typically depend on the enumerated UDID.

Uh, no. You should only use interfaces like new_device with the devices that really can't be detected in kernel, which isn't the case here. There is nothing preventing the kernel from detecting the ARP devices.

So that really can not be the solution that we'll use with these devices, but regardless of that, relying on user space in general with the ARP protocol has considerable challenges that I don't see that could be solved easily:

- You still need to deliver the UDID to the kernel because of things like the PEC flag, and the drivers will also need information from it.
- With the static (not hotplugged) devices you need to assign the correct ACPI node (or what ever fwnode) to the ARP-device.
- When the device is hotplugged, you would need new ABI, like I think you already noticed, but this really does not make any sense. We simply don't need it, because the kernel can process this information on its own very simply.

On top of those there were concerns, like what if an ARP-device is needed relatively early on during the system bootup, but I don't actually know how big issues things like that are.

But in any case, I don't think you would ever be able to make the ARP work from user space except with the simples cases (possibly not reliable even with those because of things like the PEC flag) which is not enough.

So why would you want involve the user space at all since it would just add complexity and limitations without any benefits? The SMBus ARP is a standard, and _simple_, method of enumerating devices, so why in earth would you not just let the kernel always take care of it?

Quoted 9 lines
Quoted 2 lines

But just to be clear, this is not only
about MCTP. The ARP-capable i2c-clients can be anything.

Yes, I'm not just talking about MCTP here either.

Quoted 4 lines

So even if you still want to scan the ARP-devices in user space separately, the kernel must enumerate those devices independently in any case.

Quoted 8 lines
Quoted 4 lines

I should also point out that to my surprise the i2c-dev interface (I2C_CHARDEV) isn't always enabled, even when I2C seems to be otherwise fully supported in the kernel. We simply can't assume that it's always available.

I don't think requiring a specific functionality to be enabled would be a showstopper for any particular implementation. We need CONFIG_I2C already, why is CONFIG_I2C_CHARDEV any different?

Oh, if I just had the power, I would place this requirement on everyone and everything. Unfortunately I don't have that power :(

I think this would mean that either we take care of the ARP enumeration in kernel, like honestly it really has to be done (regardless of this requirement), or we have to continue maintaining (and adding :-( ) the code in the drivers and board files that create the i2c-clients for these devices.

Br,

Signature · 1 line
heikki
maintainer
#14 lore raw

Hi Heikki,

Quoted 3 lines

Uh, no. You should only use interfaces like new_device with the devices that really can't be detected in kernel, which isn't the case here.

Who is deciding this "you should only" case? If the facility works, it's suitable. You raise some good points that may mean it is not a suitable approach for an ARP implementation, but we should still make sure we're taking the right approach.

[You seem pretty defensive here? I'm not saying no to the kernel implementation, just doing our homework before agreeing to it]

Quoted 2 lines

So why would you want involve the user space at all since it would just add complexity and limitations without any benefits?

Because we have fewer risks implementing this in userspace.

As an example, you currently seem to have a stack information leak in the proposed Get UDID implementation, which would be much less of an issue for the equivalent protocol handling implemented in userspace.

Quoted 3 lines

- You still need to deliver the UDID to the kernel because of things like the PEC flag, and the drivers will also need information from it.

That seems like the main reason for requiring a kernel approach, in that we need more information than just the assigned address. It's not possible (at present) to specify the PEC flag through existing interfaces, right?

For me, this would be the deciding factor to go for a kernel approach, in that we otherwise cannot properly describe ARPed devices to the i2c subsystem. We *could* push a new_device with a UDID, but I'm not sure that's a great idea.

Quoted 2 lines

- With the static (not hotplugged) devices you need to assign the correct ACPI node (or what ever fwnode) to the ARP-device.

Is that possible at present? how are you planning to represent ARPed devices in the DT - or more importantly, correlate DT (or other fwnode) nodes to discovered devices?

Quoted 4 lines

- When the device is hotplugged, you would need new ABI, like I think you already noticed, but this really does not make any sense. We simply don't need it, because the kernel can process this information on its own very simply.

Even this "very simple" implementation may have bugs.

Assuming we go with a kernel approach: For the MCTP case, for full ARP support of MCTP endpoints, we would still need to consume a hotplug event that indicates that the device is available at its new address
- there is no kernel driver bound for the remote MCTP endpoints. This event would be consumed by the (existing) MCTP infrastructure in order to start MCTP enumeration. Is this something you have looked at already? If so, if you can send an example of an actual event, I will look at the mctpd part of this.

Cheers,

Jeremy

#15 lore raw

Hi Jeremy,

There seems to be another a bit more severe issue with ARP and i2c-dev. Right now it seems that anything that can access the i2c character devices can silently (without the kernel having any idea what's going on) assign a conflicting address to a dynamically addressed ARP-device. Perhaps more importantly, the user space can remove access to an ARP-device by silently assigning a new address to it or simply by resetting its state with Prepare to ARP.

That can happen accidentally, but it can also be done intentionally.

Unless I've missed something, this really is a major threat that we have to solve. Right now the only idea that I have is that we simply prevent the i2c-dev from using the SMBus Default Address.

Quoted 11 lines · Jeremy Kerr
Quoted 3 lines

Uh, no. You should only use interfaces like new_device with the devices that really can't be detected in kernel, which isn't the case here.

Who is deciding this "you should only" case? If the facility works, it's suitable. You raise some good points that may mean it is not a suitable approach for an ARP implementation, but we should still make sure we're taking the right approach.

[You seem pretty defensive here? I'm not saying no to the kernel implementation, just doing our homework before agreeing to it]

I'm sorry if I sounded arrogant, it was not my intention. We don't control the user space, so we can not rely on it to enumerate devices like this. We will not be always even able to wait for user space with them. The kernel will also still need to be in full control of the device, also with the ARP protocol, in order to deal with things like conflicts. So consider for example hotplugged devices that are not ARP-capable. If the device has a conflicting address with a dynamically addressed ARP-device, then kernel really has to be able to assign new address to the ARP-device completely independently.

Quoted 8 lines
Quoted 2 lines

So why would you want involve the user space at all since it would just add complexity and limitations without any benefits?

Because we have fewer risks implementing this in userspace.

As an example, you currently seem to have a stack information leak in the proposed Get UDID implementation, which would be much less of an issue for the equivalent protocol handling implemented in userspace.

If there are bugs in the code then we need to fix them. Can you please comment to the patch that has the problem?

Quoted 14 lines
Quoted 3 lines

- You still need to deliver the UDID to the kernel because of things like the PEC flag, and the drivers will also need information from it.

That seems like the main reason for requiring a kernel approach, in that we need more information than just the assigned address. It's not possible (at present) to specify the PEC flag through existing interfaces, right?

For me, this would be the deciding factor to go for a kernel approach, in that we otherwise cannot properly describe ARPed devices to the i2c subsystem. We *could* push a new_device with a UDID, but I'm not sure that's a great idea.

Quoted 6 lines
Quoted 2 lines

- With the static (not hotplugged) devices you need to assign the correct ACPI node (or what ever fwnode) to the ARP-device.

Is that possible at present? how are you planning to represent ARPed devices in the DT - or more importantly, correlate DT (or other fwnode) nodes to discovered devices?

I don't know about DT, but with ACPI the devices are expected to either be fixed address devices or just use target address that matches to the address in the I2C Serial Bus Connection Resource Descriptor. The mapping is not yet done, but the idea is to just assign the detected UDID to the i2c-client that was already created from the fwnode.

Quoted 7 lines
Quoted 4 lines

- When the device is hotplugged, you would need new ABI, like I think you already noticed, but this really does not make any sense. We simply don't need it, because the kernel can process this information on its own very simply.

Even this "very simple" implementation may have bugs.

Quoted 8 lines

Assuming we go with a kernel approach: For the MCTP case, for full ARP support of MCTP endpoints, we would still need to consume a hotplug event that indicates that the device is available at its new address
- there is no kernel driver bound for the remote MCTP endpoints. This event would be consumed by the (existing) MCTP infrastructure in order to start MCTP enumeration. Is this something you have looked at already? If so, if you can send an example of an actual event, I will look at the mctpd part of this.

We will have the address attribute file that the user space can use. If the address changes uevent will be send it.

thanks,

Signature · 1 line
heikki
maintainer
#16 lore raw

Hi Heikki,

Quoted 8 lines

There seems to be another a bit more severe issue with ARP and i2c-dev. Right now it seems that anything that can access the i2c character devices can silently (without the kernel having any idea what's going on) assign a conflicting address to a dynamically addressed ARP-device. Perhaps more importantly, the user space can remove access to an ARP-device by silently assigning a new address to it or simply by resetting its state with Prepare to ARP.

Quoted 5 lines

That can happen accidentally, but it can also be done intentionally.

Unless I've missed something, this really is a major threat that we have to solve. Right now the only idea that I have is that we simply prevent the i2c-dev from using the SMBus Default Address.

I don't necessarily see this as an issue; access to the chardev somewhat implies full access to the i2c bus, and so arbitrary interactions with devices to alter device states. Including the i2c address as part of the affected state doesn't seem like a huge difference in access.

There may be a specific case that is interesting though:

- an ARP-able device is in use by a kernel driver, which excludes access through the chardev

- interactions with that device are possible using ARP commands to address 0x61 over the chardev

- so, the device may be re-addressed, now allowing accesses through the chardev

However, I am not sure there are existing cases where access to the chardev is a distinct privilege domain to not just unbind the driver anyway.

Quoted 1 line

I'm sorry if I sounded arrogant, it was not my intention.

No problem, just trying to keep things collaborative!

Quoted 3 lines

We don't control the user space, so we can not rely on it to enumerate devices like this. We will not be always even able to wait for user space with them.

Could you give some details on your intended use-case? That might help to understand the constraints you're facing.

Quoted 6 lines

The kernel will also still need to be in full control of the device, also with the ARP protocol, in order to deal with things like conflicts. So consider for example hotplugged devices that are not ARP-capable. If the device has a conflicting address with a dynamically addressed ARP-device, then kernel really has to be able to assign new address to the ARP-device completely independently.

Yeah, managing the bus addressing would definitely be simpler in-kernel.

So I think there's sufficient justification for your approach here, but I would have a few requests:

- that ARP is enabled explicitly. I'd be interested in having a DT property on the controller node that allows us to enable ARP on a per-bus basis.

Otherwise, I'm pretty sure we'll break someone's existing platform by assuming we can start interactions on the SMBus default address.

Is there some equivalent facility for ACPI based config?

- I'd need to ensure that the i2c_client doesn't conflict with the MCTP transport's use of the device, post-ARP. I'll get a test setup sorted here, but I think that requires some changes to the controller driver that I'm using.

Quoted 11 lines
Quoted 8 lines
Quoted 2 lines

So why would you want involve the user space at all since it would just add complexity and limitations without any benefits?

Because we have fewer risks implementing this in userspace.

As an example, you currently seem to have a stack information leak in the proposed Get UDID implementation, which would be much less of an issue for the equivalent protocol handling implemented in userspace.

If there are bugs in the code then we need to fix them. Can you please comment to the patch that has the problem?

Of course, yes. I'd just like to sort the structural things before dealing with implementation.

Quoted 10 lines
Quoted 3 lines

Is that possible at present? how are you planning to represent ARPed devices in the DT - or more importantly, correlate DT (or other fwnode) nodes to discovered devices?

I don't know about DT, but with ACPI the devices are expected to either be fixed address devices or just use target address that matches to the address in the I2C Serial Bus Connection Resource Descriptor. The mapping is not yet done, but the idea is to just assign the detected UDID to the i2c-client that was already created from the fwnode.

OK, but how do you map the UDID to the resource descriptor? I don't know much about ACPI, but the descriptor seems to be only keyed on a target address, which is now dynamic.

(same with DT, devices are keyed by target address)

Quoted 11 lines
Quoted 8 lines

Assuming we go with a kernel approach: For the MCTP case, for full ARP support of MCTP endpoints, we would still need to consume a hotplug event that indicates that the device is available at its new address
- there is no kernel driver bound for the remote MCTP endpoints. This event would be consumed by the (existing) MCTP infrastructure in order to start MCTP enumeration. Is this something you have looked at already? If so, if you can send an example of an actual event, I will look at the mctpd part of this.

We will have the address attribute file that the user space can use. If the address changes uevent will be send it.

Sounds good, but for MCTP there is no struct device bound to the remote i2c device/address. Are you proposing we change that?

Cheers,

Jeremy

#17 lore raw

Hi,

Quoted 27 lines
Quoted 8 lines

There seems to be another a bit more severe issue with ARP and i2c-dev. Right now it seems that anything that can access the i2c character devices can silently (without the kernel having any idea what's going on) assign a conflicting address to a dynamically addressed ARP-device. Perhaps more importantly, the user space can remove access to an ARP-device by silently assigning a new address to it or simply by resetting its state with Prepare to ARP.

Quoted 5 lines

That can happen accidentally, but it can also be done intentionally.

Unless I've missed something, this really is a major threat that we have to solve. Right now the only idea that I have is that we simply prevent the i2c-dev from using the SMBus Default Address.

I don't necessarily see this as an issue; access to the chardev somewhat implies full access to the i2c bus, and so arbitrary interactions with devices to alter device states. Including the i2c address as part of the affected state doesn't seem like a huge difference in access.

There may be a specific case that is interesting though:

- an ARP-able device is in use by a kernel driver, which excludes access through the chardev

- interactions with that device are possible using ARP commands to address 0x61 over the chardev

Quoted 6 lines

- so, the device may be re-addressed, now allowing accesses through the chardev

However, I am not sure there are existing cases where access to the chardev is a distinct privilege domain to not just unbind the driver anyway.

Thanks for the answer. I don't think this is necessarily a major problem either, but since it was raiced (internally) I had to make a note. Let's not worry about this for now.

Quoted 10 lines

I would have a few requests:

- that ARP is enabled explicitly. I'd be interested in having a DT property on the controller node that allows us to enable ARP on a per-bus basis.

Otherwise, I'm pretty sure we'll break someone's existing platform by assuming we can start interactions on the SMBus default address.

Is there some equivalent facility for ACPI based config?

With ACPI systems, we just don't know what the platform is going to be used for in the end. This is a bit tricky with ACPI.

But I'll make the registration of the feature conditional somehow in any case.

Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

Is that possible at present? how are you planning to represent ARPed devices in the DT - or more importantly, correlate DT (or other fwnode) nodes to discovered devices?

I don't know about DT, but with ACPI the devices are expected to either be fixed address devices or just use target address that matches to the address in the I2C Serial Bus Connection Resource Descriptor. The mapping is not yet done, but the idea is to just assign the detected UDID to the i2c-client that was already created from the fwnode.

Quoted 5 lines

OK, but how do you map the UDID to the resource descriptor? I don't know much about ACPI, but the descriptor seems to be only keyed on a target address, which is now dynamic.

(same with DT, devices are keyed by target address)

I don't know how a dynamically addressed device, that does not return any kind of target address with the UDID, could be mapped to the fwnode.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

Assuming we go with a kernel approach: For the MCTP case, for full ARP support of MCTP endpoints, we would still need to consume a hotplug event that indicates that the device is available at its new address
- there is no kernel driver bound for the remote MCTP endpoints. This event would be consumed by the (existing) MCTP infrastructure in order to start MCTP enumeration. Is this something you have looked at already? If so, if you can send an example of an actual event, I will look at the mctpd part of this.

Quoted 5 lines
Quoted 2 lines

We will have the address attribute file that the user space can use. If the address changes uevent will be send it.

Sounds good, but for MCTP there is no struct device bound to the remote i2c device/address. Are you proposing we change that?

I'm sorry, I'm probable missing something here. If the address gets changed, then you have to inform the remote endpoint about the new address somehow in any case, right? So how did you do that with the user space approach?

Br,

Signature · 1 line
heikki