From patchwork Wed Aug 26 10:40:54 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Malz X-Patchwork-Id: 2292624 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hVLmK1RjSz1xtN for ; Wed, 26 Aug 2026 20:41:21 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1wzB4D-0004Tb-S0; Wed, 26 Aug 2026 10:41:13 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1wzB49-0004Pl-AP for kernel-team@lists.ubuntu.com; Wed, 26 Aug 2026 10:41:09 +0000 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (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 21D733FCA8 for ; Wed, 26 Aug 2026 10:41:09 +0000 (UTC) Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-c15fff01a30so56611566b.1 for ; Wed, 26 Aug 2026 03:41:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787740868; x=1788345668; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=HL0A7sLhdodFAZWlVRMFhIZwRDf3dqMYV13zKL3WB/8=; b=p4l9MRmGny6NYEjQSu1TMZ+bNINpryqF0MbZOVZSV0WmF2K4RQ++PHWvNPy8tea5Gg YMHEkDfNda1HB0Rf0Ouq2ucGWLl7NeHsZ86aP0M1bWmQ23VsTMoSgxdZFvZzS4l1NYOv qhZNvSDz2mld9LlKWX0S61zTXcXWStz1eHOcanD+WhfoidM7R5EklDm49xo5PraXBDn+ /QYss1aF8DLtCp2J8g7OQxgQu3Xo8j3I0BKxwkWbIgyBO1Ydky6F/mLtBL1rQBF4faBP z2BSbigi4U9o/5ZLhFXT3lbBnljz1YVme1TUTIiZ37hkfKkndynry/xmWny+RFhDHujm U2MA== X-Gm-Message-State: AFuF++lIhHRUTcpV7C3mQEpa5pn9Hycuv81lR0galpEKdPfjJVEIZrFD FVBAZh5YFNfZpnudcBWgjySmjCT/1efqi1mdGhDBt9yVK0UnisaeWN6jM0eIYbS5MrcTZT4qnR7 Q+f0eFxPQMyrIHodp6t7kqvoMOjPmyUyhU1DFIkIdEqn57hq8xm65fHl1DWr+R5T5/VnWP+dkkU S2HaG5IQXYb4ItIQ== X-Gm-Gg: AR+sD11yX2q6vMsj5ZLmT8GyKjEtdbD88hF/WUuhSwOHvIsvHa7o1u0xUgYw3leN9y1 NqeYWS8xrSA8lWSt0+8uC2djwcaZ4YQP8X+pOgIuhYNsJHrT6EY24yOlmQdMNZ/Digo6gOIHLuh /ftS5eHcqPFLb/m8H74GBhFwmXhnJious7QyfXqe82bFIGewJ2fz+wwY44Wgt72Pq5/oeiZr56r 7MQ4bq9pBpnim1ZN+Ye6TCwjLb99Thau2lS5tOwvowqC7LPExYoo1PB3DYGoHfkF1hkmtKHuEaE TTPHcdegQ8eVQHAiHKyRcGs4GXWco6xTDEGuPfSslvdslxXb3soDl78txH98yUIt6eq+NZBsQ5G cxraGTAJGukLxVVh+PK86uQmtMozvDh5T1t7B8g+Fq3M4iAL6k7pf3zsegrwvJlQbxxks1bTYYv /Wqg== X-Received: by 2002:a17:907:9808:b0:c19:6d4a:425b with SMTP id a640c23a62f3a-c250c321091mr616871866b.18.1787740868328; Wed, 26 Aug 2026 03:41:08 -0700 (PDT) X-Received: by 2002:a17:907:9808:b0:c19:6d4a:425b with SMTP id a640c23a62f3a-c250c321091mr616861566b.18.1787740867651; Wed, 26 Aug 2026 03:41:07 -0700 (PDT) Received: from localhost.localdomain (77-236-28-43.static.play.pl. [77.236.28.43]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a7303casm569439166b.25.2026.08.26.03.41.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2026 03:41:07 -0700 (PDT) To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 1/1] ice: acquire NVM lock around each flash read Date: Wed, 26 Aug 2026 12:40:54 +0200 Message-Id: <20260826104057.108100-2-robert.malz@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260826104057.108100-1-robert.malz@canonical.com> References: <20260826104057.108100-1-robert.malz@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Robert Malz via kernel-team From: Robert Malz Reply-To: Robert Malz Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/2163508 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. ice_read_sr_word() is now a thin wrapper, so ice_read_sr_word_aq() is folded into it. Fixes: e94509906d6b ("ice: create function to read a section of the NVM and Shadow RAM") Signed-off-by: Robert Malz Reviewed-by: Przemek Kitszel Reviewed-by: Marcin Szycik Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen (backported from commit df88d6f1ed653993bd5c8647aef0e6498f4b1647) [rmalz: changes from upstream: - 5.15 uses enum ice_status, ICE_ERR_AQ_ERROR and enum ice_aq_err rather than upstream's int and libie_aq_* types; - devlink changes are in ice_devlink.c instead of devlink/devlink.c; - the ice_get_eeprom() aq_err is logged via ice_aq_str(); - the ice_devlink_nvm_snapshot() is the single-read (non-block-loop) form, so different changes were required; - in the new lock-acquire failure path of ice_read_flat_nvm() the aq_err is logged with %d on hw->adminq.sq_last_status] Signed-off-by: Robert Malz --- drivers/net/ethernet/intel/ice/ice_devlink.c | 18 +--- drivers/net/ethernet/intel/ice/ice_ethtool.c | 18 +--- drivers/net/ethernet/intel/ice/ice_nvm.c | 91 ++++++++++---------- drivers/net/ethernet/intel/ice/ice_nvm.h | 2 +- 4 files changed, 55 insertions(+), 74 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_devlink.c b/drivers/net/ethernet/intel/ice/ice_devlink.c index 2ec5d5cb7280..c20bd31902ca 100644 --- a/drivers/net/ethernet/intel/ice/ice_devlink.c +++ b/drivers/net/ethernet/intel/ice/ice_devlink.c @@ -656,6 +656,7 @@ static int ice_devlink_nvm_snapshot(struct devlink *devlink, const struct devlink_region_ops *ops, struct netlink_ext_ack *extack, u8 **data) { + enum ice_aq_err read_aq_err = ICE_AQ_RC_OK; struct ice_pf *pf = devlink_priv(devlink); struct device *dev = ice_pf_to_dev(pf); struct ice_hw *hw = &pf->hw; @@ -668,27 +669,16 @@ static int ice_devlink_nvm_snapshot(struct devlink *devlink, if (!nvm_data) return -ENOMEM; - 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, 0, &nvm_size, nvm_data, false); + status = ice_read_flat_nvm(hw, 0, &nvm_size, nvm_data, false, + &read_aq_err); if (status) { dev_dbg(dev, "ice_read_flat_nvm failed after reading %u bytes, err %d aq_err %d\n", - nvm_size, status, hw->adminq.sq_last_status); + nvm_size, 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); - *data = nvm_data; return 0; diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c index 97a3def81d18..1086fca632e7 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c @@ -258,6 +258,7 @@ ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, u8 *bytes) { struct ice_netdev_priv *np = netdev_priv(netdev); + enum ice_aq_err read_aq_err = ICE_AQ_RC_OK; struct ice_vsi *vsi = np->vsi; struct ice_pf *pf = vsi->back; struct ice_hw *hw = &pf->hw; @@ -276,28 +277,17 @@ ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, if (!buf) return -ENOMEM; - status = ice_acquire_nvm(hw, ICE_RES_READ); - if (status) { - dev_err(dev, "ice_acquire_nvm failed, err %s aq_err %s\n", - ice_stat_str(status), - ice_aq_str(hw->adminq.sq_last_status)); - ret = -EIO; - goto out; - } - status = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->len, buf, - false); + false, &read_aq_err); if (status) { dev_err(dev, "ice_read_flat_nvm failed, err %s aq_err %s\n", ice_stat_str(status), - ice_aq_str(hw->adminq.sq_last_status)); + ice_aq_str(read_aq_err)); ret = -EIO; - goto release; + goto out; } 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/ethernet/intel/ice/ice_nvm.c index fee37a5844cf..5e78155b302a 100644 --- a/drivers/net/ethernet/intel/ice/ice_nvm.c +++ b/drivers/net/ethernet/intel/ice/ice_nvm.c @@ -52,17 +52,27 @@ ice_aq_read_nvm(struct ice_hw *hw, u16 module_typeid, u32 offset, u16 length, * @length: (in) number of bytes to read; (out) number of bytes actually read * @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 correctly * breaks read requests across Shadow RAM sectors and ensures that no single * 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 multiple + * 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. */ enum ice_status ice_read_flat_nvm(struct ice_hw *hw, u32 offset, u32 *length, u8 *data, - bool read_shadow_ram) + bool read_shadow_ram, enum ice_aq_err *read_aq_err) { enum ice_status status; u32 inlen = *length; @@ -91,12 +101,30 @@ 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) { + ice_debug(hw, ICE_DBG_NVM, "Failed to acquire NVM lock, err %d aq_err %d\n", + status, hw->adminq.sq_last_status); + break; + } + status = 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 = hw->adminq.sq_last_status; + + ice_release_nvm(hw); break; + } + + ice_release_nvm(hw); bytes_read += read_size; offset += read_size; @@ -177,15 +205,19 @@ ice_aq_erase_nvm(struct ice_hw *hw, u16 module_typeid, struct ice_sq_cd *cd) } /** - * ice_read_sr_word_aq - Reads Shadow RAM via AQ + * 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 ice_read_flat_nvm. + * + * 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 held. + * + * Return: zero on success, or a negative error code on failure. */ -static enum ice_status -ice_read_sr_word_aq(struct ice_hw *hw, u16 offset, u16 *data) +enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data) { u32 bytes = sizeof(u16); enum ice_status status; @@ -195,7 +227,7 @@ ice_read_sr_word_aq(struct ice_hw *hw, u16 offset, u16 *data) * Shadow RAM sector restrictions necessary when reading from the NVM. */ status = ice_read_flat_nvm(hw, offset * sizeof(u16), &bytes, - (__force u8 *)&data_local, true); + (__force u8 *)&data_local, true, NULL); if (status) return status; @@ -332,13 +364,8 @@ ice_read_flash_module(struct ice_hw *hw, enum ice_bank_select bank, u16 module, return ICE_ERR_PARAM; } - status = ice_acquire_nvm(hw, ICE_RES_READ); - if (status) - return status; - - status = ice_read_flat_nvm(hw, start + offset, &length, data, false); - - ice_release_nvm(hw); + status = ice_read_flat_nvm(hw, start + offset, &length, data, false, + NULL); return status; } @@ -406,27 +433,6 @@ ice_read_netlist_module(struct ice_hw *hw, enum ice_bank_select bank, u32 offset return status; } -/** - * ice_read_sr_word - Reads Shadow RAM word and acquire NVM if necessary - * @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. - */ -enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data) -{ - enum ice_status status; - - status = ice_acquire_nvm(hw, ICE_RES_READ); - if (!status) { - status = ice_read_sr_word_aq(hw, offset, data); - ice_release_nvm(hw); - } - - return status; -} - /** * ice_get_pfa_module_tlv - Reads sub module TLV from NVM PFA * @hw: pointer to hardware structure @@ -807,20 +813,18 @@ enum ice_status ice_get_inactive_netlist_ver(struct ice_hw *hw, struct ice_netli static enum ice_status ice_discover_flash_size(struct ice_hw *hw) { u32 min_size = 0, max_size = ICE_AQC_NVM_MAX_OFFSET + 1; - enum ice_status status; - - status = ice_acquire_nvm(hw, ICE_RES_READ); - if (status) - return status; + enum ice_status status = 0; while ((max_size - min_size) > 1) { + enum ice_aq_err read_aq_err = ICE_AQ_RC_OK; u32 offset = (max_size + min_size) / 2; u32 len = 1; u8 data; - status = ice_read_flat_nvm(hw, offset, &len, &data, false); + status = ice_read_flat_nvm(hw, offset, &len, &data, false, + &read_aq_err); if (status == ICE_ERR_AQ_ERROR && - hw->adminq.sq_last_status == ICE_AQ_RC_EINVAL) { + read_aq_err == ICE_AQ_RC_EINVAL) { ice_debug(hw, ICE_DBG_NVM, "%s: New upper bound of %u bytes\n", __func__, offset); status = 0; @@ -831,7 +835,7 @@ static enum ice_status ice_discover_flash_size(struct ice_hw *hw) min_size = offset; } else { /* an unexpected error occurred */ - goto err_read_flat_nvm; + return status; } } @@ -839,9 +843,6 @@ static enum ice_status ice_discover_flash_size(struct ice_hw *hw) hw->flash.flash_size = max_size; -err_read_flat_nvm: - ice_release_nvm(hw); - return status; } diff --git a/drivers/net/ethernet/intel/ice/ice_nvm.h b/drivers/net/ethernet/intel/ice/ice_nvm.h index c6f05f43d593..371da1b69022 100644 --- a/drivers/net/ethernet/intel/ice/ice_nvm.h +++ b/drivers/net/ethernet/intel/ice/ice_nvm.h @@ -17,7 +17,7 @@ ice_acquire_nvm(struct ice_hw *hw, enum ice_aq_res_access_type access); void ice_release_nvm(struct ice_hw *hw); enum ice_status ice_read_flat_nvm(struct ice_hw *hw, u32 offset, u32 *length, u8 *data, - bool read_shadow_ram); + bool read_shadow_ram, enum ice_aq_err *read_aq_err); enum ice_status ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, u16 module_type);