Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Czapnik <lukasz.czapnik@intel.com>
To: "intel-wired-lan@lists.osuosl.org" <intel-wired-lan@lists.osuosl.org>
Subject: Re: [PATCH iwl-net v3] ice: Fix "Unknown bps" during link events
Date: Tue, 17 Nov 2026 14:45:56 +0100	[thread overview]
Message-ID: <bcab144d-79d2-4e0d-9e0d-34ca8758d46d@intel.com> (raw)
In-Reply-To: <sashiko-outbox-174243@kernel.org>

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


On 10/16/2026 1:26 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] ice: data race on bitfields in struct ice_vsi causing state corruption
> - [Medium] ice: unsynchronized RMW of phy_info->link_info in ice_link_event()
> --
>
> commit 35fcfc2f1fd4d9de2d01f00551ed70ac2dd02bbf
> Author: Jakub Kaminski<jakub.kaminski@intel.com>
> Subject: ice: Fix "Unknown bps" during link events
>
> The commit refactors the link event flow in the ice driver to use refreshed
> link state rather than event values when the status read succeeds. It also
> safely caches event values on read failures, introduces ice_update_media_caps(),
> and updates ice_print_link_msg() to take the link speed as a parameter.
>
>> diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
>> index c26cef0214552..ac0867ef812a0 100644
>> --- a/drivers/net/ethernet/intel/ice/ice_main.c
>> +++ b/drivers/net/ethernet/intel/ice/ice_main.c
>> @@ -844,8 +844,9 @@ static void ice_print_topo_conflict(struct ice_vsi *vsi)
>>    * ice_print_link_msg - print link up or down message
>>    * @vsi: the VSI whose link status is being queried
>>    * @isup: boolean for if the link is now up or down
>> + * @link_speed: current link speed value to display
>>    */
>> -void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
>> +void ice_print_link_msg(struct ice_vsi *vsi, bool isup, u16 link_speed)
>>   {
> [Severity: High]
> Does this function trigger a data race on the bitfields in struct ice_vsi
> that can cause state corruption?
>
> The current_isup, irqs_ready, and stat_offsets_loaded bitfields share a
> single byte in struct ice_vsi:
>
> 	u8 irqs_ready:1;
> 	u8 current_isup:1;		 /* Sync 'link up' logging */
> 	u8 stat_offsets_loaded:1;
>
> Compilers implement assignments to these bitfields as non-atomic
> read-modify-write (RMW) operations on the shared byte. This function
> modifies current_isup locklessly from the ice_service_task workqueue.
>
> Concurrently, ice_vsi_req_irq_msix(), ice_vsi_free_irq(), and
> ice_up_complete() modify irqs_ready and stat_offsets_loaded from process
> context (e.g., ndo_open/ndo_stop) protected by the RTNL lock.
>
> A concurrent RMW by the service task can silently overwrite and revert
> changes to irqs_ready or stat_offsets_loaded. Reverting irqs_ready to true
> after it was set to false during interface teardown can lead to a double-free
> of IRQs on the next down operation, or missed interrupts if reverted to false.
>
> [ ... ]

The bitfield sharing comes from 0ab54c5f2fe89 ("ice: Use bitfields when possible").
This patch doesn't add a writer to that byte; it only changes where the printed
speed comes from, and the unlocked current_isup store in ice_print_link_msg() is
unchanged. The race also doesn't depend on ice_print_link_msg(): the service task
writes stat_offsets_loaded via ice_watchdog_subtask() -> ice_update_vsi_stats() ->
ice_update_eth_stats() without rtnl. It predates this patch and is outside the scope
of this fix.

>> @@ -1188,23 +1190,32 @@ ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
>>   	old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
>>   	old_link_speed = phy_info->link_info_old.link_speed;
>>   
>> +	/* don't drop an event that the refreshed link info no longer shows */
>> +	changed = link_up != old_link || link_speed != old_link_speed;
>> +
>>   	/* update the link info structures and re-enable link events,
>>   	 * don't bail on failure due to other book keeping needed
>>   	 */
>> -	status = ice_update_link_info(pi);
>> -	if (status)
>> +	err = ice_aq_get_link_info(pi, true, NULL, NULL);
>> +	if (!err) {
>> +		link_up = phy_info->link_info.link_info & ICE_AQ_LINK_UP;
>> +		link_speed = phy_info->link_info.link_speed;
>> +		err = ice_update_media_caps(pi);
>> +	} else {
>> +		/* read failed, keep the cache in sync with the applied state */
>> +		if (link_up)
>> +			phy_info->link_info.link_info |= ICE_AQ_LINK_UP;
>> +		else
>> +			phy_info->link_info.link_info &= ~ICE_AQ_LINK_UP;
> [Severity: Medium]
> Does this code introduce an unprotected read-modify-write operation on the
> shared link_info member?
>
> The driver's service task handles link events via ice_link_event(). On this
> newly added failure path for ice_aq_get_link_info(), the code performs a
> read-modify-write (RMW) operation on a shared structure field:
> phy_info->link_info.link_info |= ICE_AQ_LINK_UP;
>
> Concurrently, other execution paths (e.g., ethtool callbacks like
> ice_set_link_ksettings() running under the RTNL lock) can trigger
> ice_aq_get_link_info(), which unconditionally updates the same
> pi->phy.link_info cache without holding any locks.
>
> While the commit message acknowledges that accesses to phy.link_info are not
> serialized between the service task and other contexts, adding a new bitwise
> RMW operation on the error path increases the risk of tearing the link_info
> byte or silently clobbering concurrent state updates.
>
The store only happens when this context's link status read failed. Losing
a concurrent update would need another context's read to succeed at the
same time and land its store between our load and store of that byte;
the worst case is a stale link_info byte until the next successful read.
The commit message already notes that phy.link_info updates are
not serialized against the service task, including the event state stored
on a failed read. Adding that serialization is a broader change,
outside the scope of this fix.

Both of those issues are problems preexisting before this patch.
I do not want to fix it in this series.

[-- Attachment #2: Type: text/html, Size: 6511 bytes --]

      reply	other threads:[~2026-11-17 13:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 11:16 [PATCH iwl-net v3] ice: Fix "Unknown bps" during link events Lukasz Czapnik
2026-10-16 11:26 ` sashiko-bot
2026-11-17 13:45   ` Lukasz Czapnik [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=bcab144d-79d2-4e0d-9e0d-34ca8758d46d@intel.com \
    --to=lukasz.czapnik@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    /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