Netdev List
 help / color / mirror / Atom feed
From: Jonas Jelonek <jelonek.jonas@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: linux@armlinux.org.uk, andrew@lunn.ch, hkallweit1@gmail.com,
	davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	maxime.chevallier@bootlin.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, bjorn@mork.no, horms@kernel.org
Subject: Re: [PATCH net-next v8 2/2] net: sfp: extend SMBus support
Date: Fri, 22 May 2026 23:24:20 +0200	[thread overview]
Message-ID: <afbd1b31-ef30-4e5e-97dd-54cceafdf2d3@gmail.com> (raw)
In-Reply-To: <20260520234208.565366-1-kuba@kernel.org>

Hi,

On 21.05.26 01:42, Jakub Kicinski wrote:
> This is an AI-generated review of your patch. The human sending this
> email has considered the AI review valid, or at least plausible.
> ---
> net: sfp: extend SMBus support
>
> Extend SFP SMBus read/write helpers to use SMBus word access and I2C block
> access when advertised by the adapter, picking the largest supported transfer
> per chunk.
>
>> diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
>> --- a/drivers/net/phy/sfp.c
>> +++ b/drivers/net/phy/sfp.c
>> @@ -756,50 +757,110 @@ static int sfp_i2c_write(struct sfp *sfp, bool a2, u8 dev_addr, void *buf,
>> [ ... ]
>> -static int sfp_smbus_byte_read(struct sfp *sfp, bool a2, u8 dev_addr,
>> -			       void *buf, size_t len)
>> +static int sfp_smbus_read(struct sfp *sfp, bool a2, u8 dev_addr, void *buf,
>> +			  size_t len)
>>  {
>> -	union i2c_smbus_data smbus_data;
>> +	union i2c_smbus_data smbus_data = {0};
>>  	u8 bus_addr = a2 ? 0x51 : 0x50;
>> +	size_t this_len, transferred;
>> +	u32 functionality;
>>  	u8 *data = buf;
>>  	int ret;
>>  
>> -	while (len) {
>> -		ret = i2c_smbus_xfer(sfp->i2c, bus_addr, 0,
>> -				     I2C_SMBUS_READ, dev_addr,
>> -				     I2C_SMBUS_BYTE_DATA, &smbus_data);
>> -		if (ret < 0)
>> -			return ret;
>> +	functionality = i2c_get_functionality(sfp->i2c);
>>  
>> -		*data = smbus_data.byte;
>> +	while (len) {
>> +		this_len = min(len, sfp->i2c_block_size);
>> +
> Does this introduce an -EINVAL regression for ethtool -m during the initial
> 300ms module insertion window?
>
> When an SFP module is inserted, sfp_check_state() sets the SFP_F_PRESENT
> flag and schedules sfp_sm_mod_probe() to run after a 300ms delay.
> Because sfp->i2c_block_size isn't initialized until sfp_sm_mod_probe()
> runs, it remains 0 during this window.
>
> If ethtool -m is run during this 300ms window, sfp_module_eeprom() proceeds
> because SFP_F_PRESENT is set. This means this_len will evaluate to 0.
> For adapters supporting I2C_FUNC_SMBUS_READ_I2C_BLOCK, the code attempts
> a 0-length I2C block read, which the I2C subsystem core explicitly rejects
> with -EINVAL.
>
> Prior to this patch, sfp_smbus_byte_read() bypassed the block size entirely
> and safely executed 1-byte transfers during the 300ms window.
>
> This also seems to expose a pre-existing deadlock in the pure I2C path.
> For pure I2C controllers, sfp_i2c_read() is used. If this_len evaluates
> to 0, i2c_transfer() is called with a 0-length read message. If the I2C
> adapter returns success, the loop variables remain unchanged, causing an
> infinite loop while holding rtnl_lock, which deadlocks the networking stack.
>
> Is there a way to prevent reads before sfp->i2c_block_size is properly
> initialized, or fall back to 1-byte reads when the block size is 0?

Valid finding. I would fix this by setting sfp->i2c_block_size in
sfp_i2c_configure to the known adapter maximum size at that point.
This way, it is filled non-zero and the issue cannot come up.

If there's another suggestion, please raise your hand.

>> +		if (functionality & I2C_FUNC_SMBUS_READ_I2C_BLOCK) {
>> +			smbus_data.block[0] = this_len;
>> +			ret = i2c_smbus_xfer(sfp->i2c, bus_addr, 0,
>> +					     I2C_SMBUS_READ, dev_addr,
>> +					     I2C_SMBUS_I2C_BLOCK_DATA, &smbus_data);
>> +			if (ret < 0)
>> +				return ret;
>> +
>> +			memcpy(data, &smbus_data.block[1], this_len);
>> +			transferred = this_len;

Regards,
Jonas

      reply	other threads:[~2026-05-22 21:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-16 13:54 [PATCH net-next v8 0/2] net: sfp: extend SMBus support Jonas Jelonek
2026-05-16 13:54 ` [PATCH net-next v8 1/2] net: sfp: apply I2C adapter quirks to limit block size Jonas Jelonek
2026-05-20 23:42   ` Jakub Kicinski
2026-05-22 21:36     ` Jonas Jelonek
2026-05-16 13:54 ` [PATCH net-next v8 2/2] net: sfp: extend SMBus support Jonas Jelonek
2026-05-19  8:05   ` Maxime Chevallier
2026-05-20 23:42   ` Jakub Kicinski
2026-05-22 21:24     ` Jonas Jelonek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=afbd1b31-ef30-4e5e-97dd-54cceafdf2d3@gmail.com \
    --to=jelonek.jonas@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=bjorn@mork.no \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox