From nobody Sat Jul 25 05:17:35 2026 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3E173F824A for ; Fri, 17 Jul 2026 12:12:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784290367; cv=none; b=hPxPTymxeP4wk4OQtCHAMEIl1fkHa8HRThkp3YCxSsD0gKCnMfm2vr0q/WamKikN71CAUFBaHG83vAGMuC4TZM0v0o4etWSDXQoB93UHMjuWZiPYQssUUKHQUE9KOlFnJ/XyuXirMohKEMKjuOqN+Kq2y2vQ6E5E/X9+vTBPWAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784290367; c=relaxed/simple; bh=1rbT1yC0vmDaTG6eHu8P7u1RmzgUxhffv2hoyE/jfGw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=IskslgIgTtjTeYQUC9B6fd/6o5dpK4K9qcV2xmU5dmyTy/cHdr9hTHMA9oSMhXCVuO0oGw/JG4lK0lAdxQjNPkUcKkJrLnS1ZBlJY+nOGsGn1BQxyYLZ9VaaBuAwe1NssycAo6ydBnMOENzTRT8VNt8FUI/CFj15CPtIfvJea2E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (4096-bit key) header.d=canonical.com header.i=@canonical.com header.b=gZr2ebKq; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=canonical.com header.i=@canonical.com header.b="gZr2ebKq" Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 741173F643 for ; Fri, 17 Jul 2026 12:12:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1784290356; bh=GBrdyPkwul5YJYP1uT72mZnAeocwxHHV9yqEnrWzVTs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=gZr2ebKqfEpq2Se21ttZHYJKC65HO6rSr7vNsliXdApj1YxDJW5yEyh58EDSqlTAI Se5BrdJOlMXB2diQcMlBgs/WRzCqMVS5i2i8Ej1xOj6Qw7ESI6KUI3lFfFxzb9qe+o Byr728O9ATp0NZKzjb5ZI0vgLMJORP3XswswAA8845eNAyNsXjrhfjp6ZIoQl9YBY8 Krv32HznUn2NR6eq7vbceoPXQ39hYOY4nu9XV9EfxlwIGVJ5scpM/xfE33TQJ2Ghxm DryJ/Zl3531UazrxUObUj+2TERem+KkwqDOZW5bePAwlv6dSxryRx4Nqlb9vdm746V /RluqvlLgm+GXpm3T8npNH/8fGN6nvqX+R4Wlb2nwAOxDYueIhMjKQkKkPBZ4PYovX 5QiVLM03XovgAYZDNr9S3bjCRhRNqcnroyBbfuvMs0Lsnd17J3cL4pXSXzCCcj8LWU C9fHtwhXMevNmo5M6lZOOMwUhSHt3EMLK1wK8Ld7QqXYI1SzZKIEAn61J4lae0dj7a 46gqlN8g/X2oYyDcPSIEAapFGWNx6BJlFnERgIEjFxMF5UDVXB7iii8kLxnRMQzk8a opcXpr6i6a+7iqYdPQg9LvF0V6t9R7GwhXhMxMu4XJ7r/zDC9XDX+cwlTZetK6anGD 4SM/U0uvGbgfcRf+sT0EmsfU= Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c15fff01a30so385391966b.1 for ; Fri, 17 Jul 2026 05:12:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784290356; x=1784895156; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GBrdyPkwul5YJYP1uT72mZnAeocwxHHV9yqEnrWzVTs=; b=sgX7RJdo4ikXNBXw87RQG0Cz/GaEoQcI1sSA4DkVkyjqFSZgQL2/BmOcOorQezQJXn KduJ5Try3PKkDE/Q+l6FVuAdCBcjBQ6XNswNdKd1j3uD8ugf0Tp+zDJqUXz6cZmlMxVS s1c+5u7ziom+4Gj/fMIWPwrp3/B1cxmjU05EHuxmLJE8TwEB/UfCXH+WW6VBOluu4BN1 Q2snOCCS+dovNnUXMxOZ0p9qnD0IdUsU5f/UwxiIYWX+1L9PzbIPM2TYxB1RUQppa7ZG G3Je+LqbrE8EzwH/+eeTcW70UkOKkdmAgki86Jx2E3n/NkNc532XfX6fGTvdoE0rjtcZ rfWw== X-Forwarded-Encrypted: i=1; AHgh+RrL/y/aIXlyf/+LrpWLEOqU6eLt5gXqhqGoRBZtA4qhh72z/j+5hTRF8ehlhbHEG+GB24ZNC0M2YPkGQkk=@vger.kernel.org X-Gm-Message-State: AOJu0YzKGvGXMWCoMSck5zzBlY17iw2L2wX4eX4ekPDlrTiF9rTBGc03 mOpSkPxyFt1CvalyOMgy65ksU4fwrrMTOM2GX1Q5322aGha9dqU41KhPgNfkG2NcAdodcyQ5jAx iU3AyEcyNi1j0CFqz7LvIfxherPHI4NtGbKUK5GmLgnKVmM3eHeUdSJw7SSM/B4uOfEhii6jSd8 /0m2PM1g== X-Gm-Gg: AfdE7cmu03O3AGOnswa6k1+jWflhmhlM3brdOwiJpmtJHvgKxI/v+58DRWj+ZrXWf4P CXP6zvC0jQVpoqniZ56lVjB7ldxCF35IbatgmUBN7FdzNsd7Qs2fiZr3Fik7rPe7QbzF2n1kmWF 37gzKOatVFlTv7WeiL2ncDq0e11dkvToJxGqClpKEP6zkxm3s/NOR8Ks6q6rrNstvig/i8UMiO5 ZeuHsQxGK/ewHObRLb8hFD5C20kQCp/F8BsnL5cbm5Px+AmMsGIM0u3BuxRJ2Tv54zJtwnQnid7 wwRmbcCswtLDB1adixxJilLGJJDZOwTLMRcfq0dcOsgZoRpKy9oQCGTyw8vcZQm/BIRtk2ejHmB Yyg== X-Received: by 2002:a17:907:944a:b0:c12:e178:9e68 with SMTP id a640c23a62f3a-c16b470c47amr101220966b.19.1784290355542; Fri, 17 Jul 2026 05:12:35 -0700 (PDT) X-Received: by 2002:a17:907:944a:b0:c12:e178:9e68 with SMTP id a640c23a62f3a-c16b470c47amr101218466b.19.1784290354880; Fri, 17 Jul 2026 05:12:34 -0700 (PDT) Received: from rmalz.. ([194.182.29.251]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-69e6fef2477sm595249a12.7.2026.07.17.05.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 05:12:34 -0700 (PDT) From: Robert Malz To: Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexander Lobakin , Jacob Keller , Jesse Brandeburg Cc: Robert Malz , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH iwl v2] ice: acquire NVM lock around each flash read Date: Fri, 17 Jul 2026 14:12:23 +0200 Message-Id: <20260717121224.3908963-1-robert.malz@canonical.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" FW caps the NVM read lock at a maximum of 3000ms regardless of the timeout requested via ice_acquire_nvm(). ice_read_flat_nvm() splits a read into multiple ice_aq_read_nvm() commands, one per 4KB sector, all issued under a single lock taken by the caller. Reading a large region can exceed 3000ms, so FW reclaims the lock mid-read and the remaining commands might fail. Move the lock acquire/release into ice_read_flat_nvm() so it brackets each individual ice_aq_read_nvm() command, ensuring the lock is never held across more than one FW read. ice_release_nvm() issues its own AQ command and overwrites hw->adminq.sq_last_status, which some callers inspect after a failed read. Add an optional read_aq_err output parameter to ice_read_flat_nvm() to capture the failing read's AQ error before the release; callers that need it (ice_discover_flash_size() and the ethtool/devlink log paths) use it instead of sq_last_status, others pass NULL. Callers that previously took the lock around ice_read_flat_nvm(), ice_read_sr_word() or ice_read_flash_module() now call them without it. The now-redundant per-block locking in ice_devlink_nvm_snapshot() is dropped. Fixes: e94509906d6b ("ice: create function to read a section of the NVM and= Shadow RAM") Signed-off-by: Robert Malz Reviewed-by: Aleksandr Loktionov --- v2: - Replace the save/restore of sq_last_status across ice_release_nvm(), which could race with a concurrent AdminQ command, with a new optional read_aq_err output parameter. - Add missing "Return:" kdoc to ice_read_sr_word(). --- .../net/ethernet/intel/ice/devlink/devlink.c | 32 ++------ drivers/net/ethernet/intel/ice/ice_ethtool.c | 16 +--- drivers/net/ethernet/intel/ice/ice_nvm.c | 76 +++++++++++-------- drivers/net/ethernet/intel/ice/ice_nvm.h | 2 +- 4 files changed, 56 insertions(+), 70 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink.c b/drivers/net= /ethernet/intel/ice/devlink/devlink.c index 22b7d8e6bd9e..5a1ab9654fb8 100644 --- a/drivers/net/ethernet/intel/ice/devlink/devlink.c +++ b/drivers/net/ethernet/intel/ice/devlink/devlink.c @@ -1856,6 +1856,7 @@ static int ice_devlink_nvm_snapshot(struct devlink *d= evlink, { struct ice_pf *pf =3D devlink_priv(devlink); struct device *dev =3D ice_pf_to_dev(pf); + enum libie_aq_err read_aq_err =3D LIBIE_AQ_RC_OK; struct ice_hw *hw =3D &pf->hw; bool read_shadow_ram; u8 *nvm_data, *tmp, i; @@ -1891,26 +1892,16 @@ static int ice_devlink_nvm_snapshot(struct devlink = *devlink, for (i =3D 0; i < num_blks; i++) { u32 read_sz =3D min_t(u32, ICE_DEVLINK_READ_BLK_SIZE, left); =20 - status =3D ice_acquire_nvm(hw, ICE_RES_READ); - if (status) { - dev_dbg(dev, "ice_acquire_nvm failed, err %d aq_err %d\n", - status, hw->adminq.sq_last_status); - NL_SET_ERR_MSG_MOD(extack, "Failed to acquire NVM semaphore"); - vfree(nvm_data); - return -EIO; - } - status =3D ice_read_flat_nvm(hw, i * ICE_DEVLINK_READ_BLK_SIZE, - &read_sz, tmp, read_shadow_ram); + &read_sz, tmp, read_shadow_ram, + &read_aq_err); if (status) { dev_dbg(dev, "ice_read_flat_nvm failed after reading %u bytes, err %d a= q_err %d\n", - read_sz, status, hw->adminq.sq_last_status); + read_sz, status, read_aq_err); NL_SET_ERR_MSG_MOD(extack, "Failed to read NVM contents"); - ice_release_nvm(hw); vfree(nvm_data); return -EIO; } - ice_release_nvm(hw); =20 tmp +=3D read_sz; left -=3D read_sz; @@ -1945,6 +1936,7 @@ static int ice_devlink_nvm_read(struct devlink *devli= nk, { struct ice_pf *pf =3D devlink_priv(devlink); struct device *dev =3D ice_pf_to_dev(pf); + enum libie_aq_err read_aq_err =3D LIBIE_AQ_RC_OK; struct ice_hw *hw =3D &pf->hw; bool read_shadow_ram; u64 nvm_size; @@ -1966,24 +1958,14 @@ static int ice_devlink_nvm_read(struct devlink *dev= link, return -ERANGE; } =20 - status =3D ice_acquire_nvm(hw, ICE_RES_READ); - if (status) { - dev_dbg(dev, "ice_acquire_nvm failed, err %d aq_err %d\n", - status, hw->adminq.sq_last_status); - NL_SET_ERR_MSG_MOD(extack, "Failed to acquire NVM semaphore"); - return -EIO; - } - status =3D ice_read_flat_nvm(hw, (u32)offset, &size, data, - read_shadow_ram); + read_shadow_ram, &read_aq_err); if (status) { dev_dbg(dev, "ice_read_flat_nvm failed after reading %u bytes, err %d aq= _err %d\n", - size, status, hw->adminq.sq_last_status); + size, status, read_aq_err); NL_SET_ERR_MSG_MOD(extack, "Failed to read NVM contents"); - ice_release_nvm(hw); return -EIO; } - ice_release_nvm(hw); =20 return 0; } diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/eth= ernet/intel/ice/ice_ethtool.c index 49371b065845..ce5f5fbaea69 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c @@ -854,6 +854,7 @@ ice_get_eeprom(struct net_device *netdev, struct ethtoo= l_eeprom *eeprom, u8 *bytes) { struct ice_pf *pf =3D ice_netdev_to_pf(netdev); + enum libie_aq_err read_aq_err =3D LIBIE_AQ_RC_OK; struct ice_hw *hw =3D &pf->hw; struct device *dev; int ret; @@ -869,24 +870,15 @@ ice_get_eeprom(struct net_device *netdev, struct etht= ool_eeprom *eeprom, if (!buf) return -ENOMEM; =20 - ret =3D ice_acquire_nvm(hw, ICE_RES_READ); - if (ret) { - dev_err(dev, "ice_acquire_nvm failed, err %d aq_err %s\n", - ret, libie_aq_str(hw->adminq.sq_last_status)); - goto out; - } - ret =3D ice_read_flat_nvm(hw, eeprom->offset, &eeprom->len, buf, - false); + false, &read_aq_err); if (ret) { dev_err(dev, "ice_read_flat_nvm failed, err %d aq_err %s\n", - ret, libie_aq_str(hw->adminq.sq_last_status)); - goto release; + ret, libie_aq_str(read_aq_err)); + goto out; } =20 memcpy(bytes, buf, eeprom->len); -release: - ice_release_nvm(hw); out: kfree(buf); return ret; diff --git a/drivers/net/ethernet/intel/ice/ice_nvm.c b/drivers/net/etherne= t/intel/ice/ice_nvm.c index 7e187a804dfa..5b7373a1c06d 100644 --- a/drivers/net/ethernet/intel/ice/ice_nvm.c +++ b/drivers/net/ethernet/intel/ice/ice_nvm.c @@ -53,17 +53,27 @@ int ice_aq_read_nvm(struct ice_hw *hw, u16 module_typei= d, u32 offset, * @length: (in) number of bytes to read; (out) number of bytes actually r= ead * @data: buffer to return data in (sized to fit the specified length) * @read_shadow_ram: if true, read from shadow RAM instead of NVM + * @read_aq_err: if non-NULL, receives the AQ error status of the failing = read * * Reads a portion of the NVM, as a flat memory space. This function corre= ctly * breaks read requests across Shadow RAM sectors and ensures that no sing= le * read request exceeds the maximum 4KB read for a single AdminQ command. * + * FW caps the read lock at a maximum of 3000ms, so a read spanning multip= le + * 4KB sectors cannot be done under a single lock without FW reclaiming it + * mid-read. The NVM lock is therefore acquired and released around each AQ + * read, so this function must be called without the lock held. + * + * Since ice_release_nvm() issues an AQ command that overwrites + * hw->adminq.sq_last_status, callers that need the failing read's AQ error + * must use @read_aq_err rather than inspecting sq_last_status afterwards. + * * Returns a status code on failure. Note that the data pointer may be * partially updated if some reads succeed before a failure. */ int ice_read_flat_nvm(struct ice_hw *hw, u32 offset, u32 *length, u8 *data, - bool read_shadow_ram) + bool read_shadow_ram, enum libie_aq_err *read_aq_err) { u32 inlen =3D *length; u32 bytes_read =3D 0; @@ -92,12 +102,27 @@ ice_read_flat_nvm(struct ice_hw *hw, u32 offset, u32 *= length, u8 *data, =20 last_cmd =3D !(bytes_read + read_size < inlen); =20 + status =3D ice_acquire_nvm(hw, ICE_RES_READ); + if (status) + break; + status =3D ice_aq_read_nvm(hw, ICE_AQC_NVM_START_POINT, offset, read_size, data + bytes_read, last_cmd, read_shadow_ram, NULL); - if (status) + if (status) { + /* Capture the read's AQ error before ice_release_nvm() + * issues its own AQ command and overwrites + * sq_last_status. + */ + if (read_aq_err) + *read_aq_err =3D hw->adminq.sq_last_status; + + ice_release_nvm(hw); break; + } + + ice_release_nvm(hw); =20 bytes_read +=3D read_size; offset +=3D read_size; @@ -194,7 +219,7 @@ static int ice_read_sr_word_aq(struct ice_hw *hw, u16 o= ffset, u16 *data) * Shadow RAM sector restrictions necessary when reading from the NVM. */ status =3D ice_read_flat_nvm(hw, offset * sizeof(u16), &bytes, - (__force u8 *)&data_local, true); + (__force u8 *)&data_local, true, NULL); if (status) return status; =20 @@ -330,13 +355,8 @@ ice_read_flash_module(struct ice_hw *hw, enum ice_bank= _select bank, u16 module, return -EINVAL; } =20 - status =3D ice_acquire_nvm(hw, ICE_RES_READ); - if (status) - return status; - - status =3D ice_read_flat_nvm(hw, start + offset, &length, data, false); - - ice_release_nvm(hw); + status =3D ice_read_flat_nvm(hw, start + offset, &length, data, false, + NULL); =20 return status; } @@ -419,24 +439,21 @@ ice_read_netlist_module(struct ice_hw *hw, enum ice_b= ank_select bank, u32 offset } =20 /** - * ice_read_sr_word - Reads Shadow RAM word and acquire NVM if necessary + * ice_read_sr_word - Reads Shadow RAM word * @hw: pointer to the HW structure * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF) * @data: word read from the Shadow RAM * - * Reads one 16 bit word from the Shadow RAM using the ice_read_sr_word_aq. + * Reads one 16 bit word from the Shadow RAM using ice_read_sr_word_aq. + * + * The NVM lock is acquired and released internally by ice_read_flat_nvm() + * around the FW read, so this function must be called without the lock he= ld. + * + * Return: zero on success, or a negative error code on failure. */ int ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data) { - int status; - - status =3D ice_acquire_nvm(hw, ICE_RES_READ); - if (!status) { - status =3D ice_read_sr_word_aq(hw, offset, data); - ice_release_nvm(hw); - } - - return status; + return ice_read_sr_word_aq(hw, offset, data); } =20 /** @@ -856,20 +873,18 @@ int ice_get_inactive_netlist_ver(struct ice_hw *hw, s= truct ice_netlist_info *net static int ice_discover_flash_size(struct ice_hw *hw) { u32 min_size =3D 0, max_size =3D ICE_AQC_NVM_MAX_OFFSET + 1; - int status; - - status =3D ice_acquire_nvm(hw, ICE_RES_READ); - if (status) - return status; + int status =3D 0; =20 while ((max_size - min_size) > 1) { u32 offset =3D (max_size + min_size) / 2; + enum libie_aq_err read_aq_err =3D LIBIE_AQ_RC_OK; u32 len =3D 1; u8 data; =20 - status =3D ice_read_flat_nvm(hw, offset, &len, &data, false); + status =3D ice_read_flat_nvm(hw, offset, &len, &data, false, + &read_aq_err); if (status =3D=3D -EIO && - hw->adminq.sq_last_status =3D=3D LIBIE_AQ_RC_EINVAL) { + read_aq_err =3D=3D LIBIE_AQ_RC_EINVAL) { ice_debug(hw, ICE_DBG_NVM, "%s: New upper bound of %u bytes\n", __func__, offset); status =3D 0; @@ -880,7 +895,7 @@ static int ice_discover_flash_size(struct ice_hw *hw) min_size =3D offset; } else { /* an unexpected error occurred */ - goto err_read_flat_nvm; + return status; } } =20 @@ -888,9 +903,6 @@ static int ice_discover_flash_size(struct ice_hw *hw) =20 hw->flash.flash_size =3D max_size; =20 -err_read_flat_nvm: - ice_release_nvm(hw); - return status; } =20 diff --git a/drivers/net/ethernet/intel/ice/ice_nvm.h b/drivers/net/etherne= t/intel/ice/ice_nvm.h index 63cdc6bdac58..e1d1a11f5ca4 100644 --- a/drivers/net/ethernet/intel/ice/ice_nvm.h +++ b/drivers/net/ethernet/intel/ice/ice_nvm.h @@ -19,7 +19,7 @@ int ice_aq_read_nvm(struct ice_hw *hw, u16 module_typeid,= u32 offset, bool read_shadow_ram, struct ice_sq_cd *cd); int ice_read_flat_nvm(struct ice_hw *hw, u32 offset, u32 *length, u8 *data, - bool read_shadow_ram); + bool read_shadow_ram, enum libie_aq_err *read_aq_err); int ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv= _len, u16 module_type); --=20 2.34.1