Skip to contentSkip to conversation

ice: acquire NVM lock around each flash read

PATCH Superseded Robert Malz 2 participants 4 messages Jul 17 – Jul 31

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ice: acquire NVM lock around each flash read

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")

---
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(-)
drivers/net/ethernet/intel/ice/devlink/devlink.c +7 -25
index 22b7d8e6bd9e..5a1ab9654fb8 100644
@@ -1856,6 +1856,7 @@ static int ice_devlink_nvm_snapshot(struct devlink *devlink,
 {
 	struct ice_pf *pf = devlink_priv(devlink);
 	struct device *dev = ice_pf_to_dev(pf);
+	enum libie_aq_err read_aq_err = LIBIE_AQ_RC_OK;
 	struct ice_hw *hw = &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 = 0; i < num_blks; i++) {
 		u32 read_sz = min_t(u32, ICE_DEVLINK_READ_BLK_SIZE, left);
 
-		status = 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 = 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 aq_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);
 
 		tmp += read_sz;
 		left -= read_sz;
@@ -1945,6 +1936,7 @@ static int ice_devlink_nvm_read(struct devlink *devlink,
 {
 	struct ice_pf *pf = devlink_priv(devlink);
 	struct device *dev = ice_pf_to_dev(pf);
+	enum libie_aq_err read_aq_err = LIBIE_AQ_RC_OK;
 	struct ice_hw *hw = &pf->hw;
 	bool read_shadow_ram;
 	u64 nvm_size;
@@ -1966,24 +1958,14 @@ static int ice_devlink_nvm_read(struct devlink *devlink,
 		return -ERANGE;
 	}
 
-	status = 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 = 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);
 
 	return 0;
 }
drivers/net/ethernet/intel/ice/ice_ethtool.c +4 -12
index 49371b065845..ce5f5fbaea69 100644
@@ -854,6 +854,7 @@ ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
 	       u8 *bytes)
 {
 	struct ice_pf *pf = ice_netdev_to_pf(netdev);
+	enum libie_aq_err read_aq_err = LIBIE_AQ_RC_OK;
 	struct ice_hw *hw = &pf->hw;
 	struct device *dev;
 	int ret;
@@ -869,24 +870,15 @@ ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
 	if (!buf)
 		return -ENOMEM;
 
-	ret = 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 = 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;
 	}
 
 	memcpy(bytes, buf, eeprom->len);
-release:
-	ice_release_nvm(hw);
 out:
 	kfree(buf);
 	return ret;
drivers/net/ethernet/intel/ice/ice_nvm.c +44 -32

153 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_nvm.h +1 -1
index 63cdc6bdac58..e1d1a11f5ca4 100644
@@ -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);
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 81 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Robert Malz via Intel-wired-lan
Sent: Friday, July 17, 2026 2:12 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Lobakin, Aleksander <[email protected]>; Keller, Jacob E <[email protected]>; Jesse Brandeburg <[email protected]>
Cc: Robert Malz <[email protected]>; intel-wired- [email protected]; [email protected]; linux- [email protected]
Subject: [Intel-wired-lan] [PATCH iwl v2] ice: acquire NVM lock around each flash read

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")

---
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 +++++++++++-------
(quoted diff) +0 -1
-
 drivers/net/ethernet/intel/ice/ice_nvm.h      |  2 +-
 4 files changed, 56 insertions(+), 70 deletions(-)
drivers/net/ethernet/intel/ice/devlink/devlink.c +1 -0
index 22b7d8e6bd9e..5a1ab9654fb8 100644
@@ -1856,6 +1856,7 @@ static int ice_devlink_nvm_snapshot(struct
 devlink *devlink,  {
 	struct ice_pf *pf = devlink_priv(devlink);
 	struct device *dev = ice_pf_to_dev(pf);
+	enum libie_aq_err read_aq_err = LIBIE_AQ_RC_OK;
 	struct ice_hw *hw = &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 = 0; i < num_blks; i++) {
 		u32 read_sz = min_t(u32, ICE_DEVLINK_READ_BLK_SIZE,
 left);
 

...

Quoted 6 lines

int
ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16
*module_tlv_len,
u16 module_type);
--
2.34.1

#2 lore raw
In reply to Robert Malz
Quoted 81 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Robert Malz via Intel-wired-lan
Sent: Friday, July 17, 2026 2:12 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Lobakin, Aleksander <[email protected]>; Keller, Jacob E <[email protected]>; Jesse Brandeburg <[email protected]>
Cc: Robert Malz <[email protected]>; intel-wired- [email protected]; [email protected]; linux- [email protected]
Subject: [Intel-wired-lan] [PATCH iwl v2] ice: acquire NVM lock around each flash read

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")

---
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 +++++++++++-------
(quoted diff) +0 -1
-
 drivers/net/ethernet/intel/ice/ice_nvm.h      |  2 +-
 4 files changed, 56 insertions(+), 70 deletions(-)
drivers/net/ethernet/intel/ice/devlink/devlink.c +1 -0
index 22b7d8e6bd9e..5a1ab9654fb8 100644
@@ -1856,6 +1856,7 @@ static int ice_devlink_nvm_snapshot(struct
 devlink *devlink,  {
 	struct ice_pf *pf = devlink_priv(devlink);
 	struct device *dev = ice_pf_to_dev(pf);
+	enum libie_aq_err read_aq_err = LIBIE_AQ_RC_OK;
 	struct ice_hw *hw = &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 = 0; i < num_blks; i++) {
 		u32 read_sz = min_t(u32, ICE_DEVLINK_READ_BLK_SIZE,
 left);
 

...

drivers/net/ethernet/intel/ice/devlink/devlink.c ice_read_flat_nvm(struct ice_hw *hw, u32 offset, · line 107

Quoted 10 lines

{

drivers/net/ethernet/intel/ice/devlink/devlink.c +2 -0
 	u32 inlen = *length;
 	u32 bytes_read = 0;
@@ -92,12 +102,27 @@ ice_read_flat_nvm(struct ice_hw *hw, u32 offset,
 u32 *length, u8 *data,
 
 		last_cmd = !(bytes_read + read_size < inlen);
 
+		status = ice_acquire_nvm(hw, ICE_RES_READ);
+		if (status)

Silent lock failure without any traces in dmesg looks scary! I'm pretty sure we need at least log an warning or error.

Quoted 2 lines
drivers/net/ethernet/intel/ice/devlink/devlink.c +2 -0
+			break;
+

...

Quoted 6 lines

int
ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16
*module_tlv_len,
u16 module_type);
--
2.34.1

#3 lore raw

Hey Aleksandr,
Thanks for the review.
Added debug logs instead of warning as some callers are already logging errors in case of ice_read_flat_nvm failure. Let me know if that works for you.

v3 for reference:
https://lists.osuosl.org/pipermail/intel-wired-lan/Week-of-Mon-20260727/056245.html

Regards,
Robert

Quoted 109 lines · Aleksandr
Quoted 82 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Robert Malz via Intel-wired-lan
Sent: Friday, July 17, 2026 2:12 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Lobakin, Aleksander <[email protected]>; Keller, Jacob E <[email protected]>; Jesse Brandeburg <[email protected]>
Cc: Robert Malz <[email protected]>; intel-wired- [email protected]; [email protected]; linux- [email protected]
Subject: [Intel-wired-lan] [PATCH iwl v2] ice: acquire NVM lock around each flash read

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")

---
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 +++++++++++-------
(quoted diff) +0 -1
-
 drivers/net/ethernet/intel/ice/ice_nvm.h      |  2 +-
 4 files changed, 56 insertions(+), 70 deletions(-)
drivers/net/ethernet/intel/ice/devlink/devlink.c +1 -0
index 22b7d8e6bd9e..5a1ab9654fb8 100644
@@ -1856,6 +1856,7 @@ static int ice_devlink_nvm_snapshot(struct
 devlink *devlink,  {
      struct ice_pf *pf = devlink_priv(devlink);
      struct device *dev = ice_pf_to_dev(pf);
+     enum libie_aq_err read_aq_err = LIBIE_AQ_RC_OK;
      struct ice_hw *hw = &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 = 0; i < num_blks; i++) {
              u32 read_sz = min_t(u32, ICE_DEVLINK_READ_BLK_SIZE,
 left);
 

...

drivers/net/ethernet/intel/ice/devlink/devlink.c ice_read_flat_nvm(struct ice_hw *hw, u32 offset, · line 107

Quoted 10 lines
 {
      u32 inlen = *length;
      u32 bytes_read = 0;
drivers/net/ethernet/intel/ice/devlink/devlink.c +2 -0
@@ -92,12 +102,27 @@ ice_read_flat_nvm(struct ice_hw *hw, u32 offset,
 u32 *length, u8 *data,
 
              last_cmd = !(bytes_read + read_size < inlen);
 
+             status = ice_acquire_nvm(hw, ICE_RES_READ);
+             if (status)

Silent lock failure without any traces in dmesg looks scary! I'm pretty sure we need at least log an warning or error.

Quoted 2 lines
drivers/net/ethernet/intel/ice/devlink/devlink.c +2 -0
+                     break;
+

...

Quoted 6 lines

int
ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16
*module_tlv_len,

                     u16 module_type);

--
2.34.1