From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.125.188.123 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796270052; b=KXqS5NqsAIzVRal1xSkvopdGxBX80/wUJFPK1JuePDaxWMSOQR7cYsdSYX/QFDrbpw8T q8HpheKm3dauQdvTkglbkIt9zafvFFllfVmETey/wmM2KfdCn3AXzLgsZhmKMnbBWxu+Y BYnQuv2VPsxj9Dlqz4C60ZjxARmKVqI47tnRPyR1x5Q0UGOH2ZOBwufJ8VEjXUeRfNjaO ENyiOCuUmvDodQ/+8owOw694u724f0gkPq1yv4RMdbReoAECVhWgE05QOxJviCAhYBSgw S1Afh8HfysCBUnRCJMeo0Jz3Bh6DX3/MV7xf8/LwLUY8EM2WKwcYjYJ3X9wfahW6j6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796270052; h=DMARC-Filter:Received:DKIM-Signature:Received: X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State: X-Gm-Gg:X-Received:X-Received:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=KQwB2IgG3eDPQ4mdUDE93hibP5KrM6ugZ/Or3v/gHEo=; b=aCg3BJe9Ggj6d2Fv/yAbQ2QvGb2LaJ4m3ROB2WodaIE+b2EOUefD775rjAnuBKjyV2dK CObMa5EFCQf+o0J1zAlyH4AxMJoNnrqRRcShXMUKOsdUSC4ppy/C290PEBZSaWdvI+HvX pxnvqaISoFie7D/LvmUZgj2RksklTmSJ3aH4mX9z5aNVav2jrna577AELldZqPF9XAmpz JWZ0Hsh3LyxEKNTw36fvdgtYGUovndm+q7+3gWUeDmMIH7VKaKatKcoNMvOmQnLumTTnR Bp83EYCORwvJK55YIblUZtgZ5wBzfPcpYZYQdKSrzq/01PF9CFs/+mDdfXH7UWW+Rjw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b=lec2BZbe; arc=none smtp.remote-ip=185.125.188.123 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BA34606A32C for ; Thu, 3 Dec 2026 03:54:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4BA34606A32C 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.a=rsa-sha256 header.s=20251003 header.b=lec2BZbe Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.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-1.canonical.com (Postfix) with ESMTPS id D928A3F7D0 for ; Thu, 3 Dec 2026 03:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1796270049; bh=KQwB2IgG3eDPQ4mdUDE93hibP5KrM6ugZ/Or3v/gHEo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lec2BZbeLmKxYupUJDhjTXZNpE3qiYXdX+Mvx1T4V6U5PUr6PpSR3+gKEEYnElmuF V5MYaJWWbOOUE3uGHL+x4dZI1JMyKxdibbdEjqQpwmpJdVfP31mjh4NeCQHGBs2fX9 pRLW8CezLiVKr6K+800vuAF5c1Bsar1IwMGnYp0QdcMMX0JXTNcF0e6SHVhgQualGN mpJf5IJ11z+JwZluaGTR0+8JRiSTYusNWEb/NbT9lK3klO0BUNbtxBzxtR25k523MG j9xh4eqNP5ZOuFcUmtZXofiJMBC1IvxkIdR9JNUyAQBRzCP7u5y1FwI5GxzTBC/+6V SnyD9FShXfiQS0yfemgN8bTpX2g9oL6zrcxZ/0MqXj+24LqwHaloCDBpHf8SUiMXtd lDARLG7pD/AfXkmEOGYZrfgT0G97YSj2I259b9HrJTIgtuDoQNw1KHToGb0zIeYuXK t/wvHLkMs0hFZjf+XBFMk/mzeL1W8lt5ixLfpe4+6OQSRrpME3Oi4QWN33TActdJ+F ly+qsicvska/4/lurN92g4eX7hbPv0SYLhH/7ohBw/HK4PrS8oHn2IrmzYJOOQtK56 iV5P5GFPPT39zIs6NVz6IoQBhWsJKG59JkWbELnVrasyvXj9nsAcaQzGnz5VuwQj8A Lg3h8ZN/zUlysrQIY+aUh33w= Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-5c157e38aedso241180e87.0 for ; Wed, 02 Dec 2026 19:54:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796270049; x=1796874849; h=content-transfer-encoding:mime-version:references:in-reply-to :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=KQwB2IgG3eDPQ4mdUDE93hibP5KrM6ugZ/Or3v/gHEo=; b=lilVCtwdlZThZAga5AR6Xx/kj1BxxbIl+kHnaPLOssuBzCGQRRjH8BR3Rc47MdXEMj GYkB9qu+VWHliKO4Vc8WxL/SGirT4PlxBqpMBvgMzOiz4huv0iDpi+880qiF/R1CcnU+ 83PmDyGaHD4tlmbjE8BoEIszrtkhMVDFdTHmBVSBoh7J5KRwRx4fz6qHM5ZHtY7AUuHK 6aNtZvouAO2aQBVhQ+5s8vkXGh/koLnbEx2JLFsorrbOOZUlNv82RCghkkFkJPl04Aw0 sDjXXM85TWWzpVhjTAr9R6sespJGk+ZFjRY+q2cqbeqqCw7m18neSFGpmzURUS0pSHVG +LHw== X-Forwarded-Encrypted: i=1; AL+hErHDnTrcnHGUCijb0BtprM41PadNk8GkCbCT5GLqeE9WbKoKM1BuGkrrhOCJvdVb6T+fV0jUS2w=@vger.kernel.org X-Gm-Message-State: APuU4Z9XqPS90ojQRJ7b4hUr6oD4E1/UQZoNiLWfsHWqpJ75cBhWLfOO bHEe7Ea67FDQF+DzSpdSFgJr10jytuSc3kSfxzz1MfMur/JnTeLEr2rVv5iG4obYFotSFwo/nz7 NhpFcMpKDQ6C44vYNonQbXcw4y+mazbcw6PKt0RxZFRqEKaQCTgS+MVst4tBEOgsTV8cOUdEvcA == X-Gm-Gg: AZFdTZegwf2naepuESlpVDXta3Dmt+OVja/EXy3/vv3tCPY3VekkGRLDCd2R7QjnSV5 kZo2pKxVfPixpz1MvQAZ7sximCLQlNBsdR8phrcBXdmEnOMUyA8ro6tNC8cD8THiAP9nzfWvnmt y7cFJgbwuN/KX12kM7SDa74t52pOw7Q4t9VGXdIRfSeCn+9WtVLkmLiQIa5yyeYmHLGl2dFDi2a 9pXnRx6mpUd9xjGQ5S2E3Q2BgRd0XAtL3TBrxEVMCNozJzLFM3Ybdw/t1meixS1Kx+odablxK75 HBggxwP3d7Bv4wdc1KrUojw+c7WYEWe0MxKbwkcLt3YDOXV2FoF3qr5Dq7S+SaHZNdN/TEH6ZW7 bCvHpU9Gbe/exu5B8jKLZR2Ha+wp3Ysoie+NxSBq9SuDH749iKTe6UIbEsYMaiOS6fz7VD6rjDQ g5277PD1GhrgxUk21vRpa6BX6r+BfRQF6MHz6iAaUmATFEAQFAezAVTIdTOrUA9cuJKGpJLwJVd QwAB+IZgrkgwco0JldJjYBsspyVqZnasNUD+RNkkyPXkdmtPOhukX2fPmcnEsvLHB54diI0znMM RfOiPekYvMSibA== X-Received: by 2002:a05:6512:a94:b0:5c1:4e4a:1321 with SMTP id 2adb3069b0e04-5c379a1e447mr148309e87.37.1796270048843; Wed, 02 Dec 2026 19:54:08 -0800 (PST) X-Received: by 2002:a05:6512:a94:b0:5c1:4e4a:1321 with SMTP id 2adb3069b0e04-5c379a1e447mr148295e87.37.1796270048446; Wed, 02 Dec 2026 19:54:08 -0800 (PST) Received: from u-ThinkPad-X1-Extreme-Gen-4i ([103.155.100.1]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bd080528sm10087417e87.83.2026.12.02.19.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 19:54:06 -0800 (PST) From: Aaron Ma To: Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Cc: Henry Tieman , intel-wired-lan@lists.osuosl.org Subject: [PATCH net v3 2/2] ice: clear Flow Director entries before reset cleanup Date: Thu, 3 Dec 2026 11:53:20 +0800 Message-ID: <20261203035320.187412-2-aaron.ma@canonical.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261203035320.187412-1-aaron.ma@canonical.com> References: <20261203035320.187412-1-aaron.ma@canonical.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit PF and VF Flow Director profiles keep handles to flow entries freed by ice_clear_hw_tbls() during reset. If PF rebuild fails during system resume before replay replaces them, driver unload dereferences a freed entry: KASAN: maybe wild-memory-access in range [0xdead000000000108-...] RIP: ice_flow_rem_entry+0xaf/0x170 [ice] ice_fdir_erase_flow_from_hw+0x1ee/0x420 [ice] By code inspection, VF Flow Director profiles are not replayed across reset, and ice_fdir_replay_flows() uses hw_prof without checking ice_flow_add_prof(). Free VF Flow Director profiles under vf->cfg_lock and invalidate PF flow handles and profile IDs before ice_clear_hw_tbls(). Serialize PF Flow Director updates, reset cleanup, and replay with hw->fdir_fltr_lock across the service task lifetime, and check ice_flow_add_prof() during replay. Fixes: 148beb612031 ("ice: Initialize Flow Director resources") Signed-off-by: Aaron Ma --- v2 -> v3: - Free VF Flow Director profiles under vf->cfg_lock before ice_clear_hw_tbls(). - Invalidate full prof->entry_h and prof->prof_id, and check ice_flow_add_prof() in ice_fdir_replay_flows(). - Hold hw->fdir_fltr_lock across PF Flow Director init, updates, reset cleanup, and replay, and tie its lifetime to ice_init_dev() and ice_deinit_dev(). - Drop Przemek's Reviewed-by due to substantial changes. v1 -> v2: - Acquire hw->fdir_fltr_lock in ice_fdir_clear_flow_handles() to synchronize with concurrent ethtool filter add/del. drivers/net/ethernet/intel/ice/ice.h | 3 +- .../ethernet/intel/ice/ice_ethtool_ntuple.c | 109 +++++++++++++----- drivers/net/ethernet/intel/ice/ice_main.c | 32 +++-- drivers/net/ethernet/intel/ice/virt/fdir.c | 16 ++- drivers/net/ethernet/intel/ice/virt/fdir.h | 2 + 5 files changed, 119 insertions(+), 43 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h index 432da05c48c08..9c43b7b530b96 100644 --- a/drivers/net/ethernet/intel/ice/ice.h +++ b/drivers/net/ethernet/intel/ice/ice.h @@ -1023,7 +1023,7 @@ void ice_fdir_del_all_fltrs(struct ice_vsi *vsi); int ice_fdir_write_fltr(struct ice_pf *pf, struct ice_ntuple_fltr *input, bool add, bool is_tun); -void ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena); +int ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena); int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd); int ice_del_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd); int ice_get_ethtool_fdir_entry(struct ice_hw *hw, struct ethtool_rxnfc *cmd); @@ -1032,6 +1032,7 @@ ice_get_fdir_fltr_ids(struct ice_hw *hw, struct ethtool_rxnfc *cmd, u32 *rule_locs); void ice_fdir_rem_adq_chnl(struct ice_hw *hw, u16 vsi_idx); void ice_fdir_release_flows(struct ice_hw *hw); +void ice_fdir_clear_flow_handles(struct ice_hw *hw); void ice_fdir_replay_flows(struct ice_hw *hw); void ice_fdir_replay_fltrs(struct ice_pf *pf); int ice_fdir_create_dflt_rules(struct ice_pf *pf); diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c index 8805f0efe9773..38d7aea103ee6 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c @@ -286,8 +286,9 @@ void ice_fdir_rem_adq_chnl(struct ice_hw *hw, u16 vsi_idx) { int status, flow; + mutex_lock(&hw->fdir_fltr_lock); if (!hw->fdir_prof) - return; + goto release_lock; for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) { struct ice_fd_hw_prof *prof = hw->fdir_prof[flow]; @@ -322,6 +323,8 @@ void ice_fdir_rem_adq_chnl(struct ice_hw *hw, u16 vsi_idx) } prof->cnt--; } +release_lock: + mutex_unlock(&hw->fdir_fltr_lock); } /** @@ -415,6 +418,25 @@ void ice_fdir_release_flows(struct ice_hw *hw) ice_fdir_erase_flow_from_hw(hw, ICE_BLK_FD, flow); } +/** + * ice_fdir_clear_flow_handles - clear handles freed during reset + * @hw: pointer to HW instance + */ +void ice_fdir_clear_flow_handles(struct ice_hw *hw) +{ + int flow; + + for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) { + struct ice_fd_hw_prof *prof = hw->fdir_prof[flow]; + + if (!prof) + continue; + + memset(prof->entry_h, 0, sizeof(prof->entry_h)); + memset(prof->prof_id, 0xff, sizeof(prof->prof_id)); + } +} + /** * ice_fdir_replay_flows - replay HW Flow Director filter info * @hw: pointer to HW instance @@ -431,16 +453,25 @@ void ice_fdir_replay_flows(struct ice_hw *hw) for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) { struct ice_flow_prof *hw_prof; struct ice_fd_hw_prof *prof; - int j; + int err, j; prof = hw->fdir_prof[flow]; - ice_flow_add_prof(hw, ICE_BLK_FD, ICE_FLOW_RX, - prof->fdir_seg[tun], TNL_SEG_CNT(tun), - false, &hw_prof); + if (!prof->fdir_seg[tun]) + continue; + + err = ice_flow_add_prof(hw, ICE_BLK_FD, ICE_FLOW_RX, + prof->fdir_seg[tun], + TNL_SEG_CNT(tun), false, + &hw_prof); + if (err) { + dev_err(ice_hw_to_dev(hw), "Could not replay Flow Director, flow type %d\n", + flow); + continue; + } + prof->prof_id[tun] = hw_prof->id; for (j = 0; j < prof->cnt; j++) { enum ice_flow_priority prio; u64 entry_h = 0; - int err; prio = ICE_FLOW_PRIO_NORMAL; err = ice_flow_add_entry(hw, ICE_BLK_FD, @@ -454,7 +485,6 @@ void ice_fdir_replay_flows(struct ice_hw *hw) flow); continue; } - prof->prof_id[tun] = hw_prof->id; prof->entry_h[j][tun] = entry_h; } } @@ -1636,20 +1666,27 @@ void ice_fdir_del_all_fltrs(struct ice_vsi *vsi) * ice_vsi_manage_fdir - turn on/off flow director * @vsi: the VSI being changed * @ena: boolean value indicating if this is an enable or disable request + * + * Return: 0 on success, negative errno on failure. */ -void ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena) +int ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena) { struct ice_pf *pf = vsi->back; struct ice_hw *hw = &pf->hw; enum ice_fltr_ptype flow; - - if (ena) { - set_bit(ICE_FLAG_FD_ENA, pf->flags); - ice_fdir_create_dflt_rules(pf); - return; - } + int ret = 0; mutex_lock(&hw->fdir_fltr_lock); + if (ena) { + if (ice_is_reset_in_progress(pf->state)) { + ret = -EBUSY; + goto release_lock; + } + set_bit(ICE_FLAG_FD_ENA, pf->flags); + ice_fdir_create_dflt_rules(pf); + goto release_lock; + } + if (!test_and_clear_bit(ICE_FLAG_FD_ENA, pf->flags)) goto release_lock; @@ -1663,6 +1700,7 @@ void ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena) release_lock: mutex_unlock(&hw->fdir_fltr_lock); + return ret; } /** @@ -1758,13 +1796,14 @@ int ice_del_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) if (!test_bit(ICE_FLAG_FD_ENA, pf->flags)) return -EOPNOTSUPP; + mutex_lock(&hw->fdir_fltr_lock); /* Do not delete filters during reset */ if (ice_is_reset_in_progress(pf->state)) { + mutex_unlock(&hw->fdir_fltr_lock); dev_err(ice_pf_to_dev(pf), "Device is resetting - deleting Flow Director filters not supported during reset\n"); return -EBUSY; } - mutex_lock(&hw->fdir_fltr_lock); val = ice_ntuple_update_list_entry(pf, NULL, fsp->location); mutex_unlock(&hw->fdir_fltr_lock); @@ -1986,29 +2025,36 @@ int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) if (!test_bit(ICE_FLAG_FD_ENA, pf->flags)) return -EOPNOTSUPP; + mutex_lock(&hw->fdir_fltr_lock); /* Do not program filters during reset */ if (ice_is_reset_in_progress(pf->state)) { dev_err(dev, "Device is resetting - adding Flow Director filters not supported during reset\n"); - return -EBUSY; + ret = -EBUSY; + goto release_lock; } fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; - if (ice_parse_rx_flow_user_data(fsp, &userdata)) - return -EINVAL; + if (ice_parse_rx_flow_user_data(fsp, &userdata)) { + ret = -EINVAL; + goto release_lock; + } - if (fsp->flow_type & FLOW_MAC_EXT) - return -EINVAL; + if (fsp->flow_type & FLOW_MAC_EXT) { + ret = -EINVAL; + goto release_lock; + } ret = ice_cfg_fdir_xtrct_seq(pf, fsp, &userdata); if (ret) - return ret; + goto release_lock; max_location = ice_get_fdir_cnt_all(hw); if (fsp->location >= max_location) { dev_err(dev, "Failed to add filter. The number of ntuple filters or provided location exceed max %d.\n", max_location); - return -ENOSPC; + ret = -ENOSPC; + goto release_lock; } /* return error if not an update and no available filters */ @@ -2016,21 +2062,23 @@ int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) if (!ice_fdir_find_fltr_by_idx(hw, fsp->location) && ice_fdir_num_avail_fltr(hw, pf->vsi[vsi->idx]) < fltrs_needed) { dev_err(dev, "Failed to add filter. The maximum number of flow director filters has been reached.\n"); - return -ENOSPC; + ret = -ENOSPC; + goto release_lock; } input = devm_kzalloc_obj(dev, *input); - if (!input) - return -ENOMEM; + if (!input) { + ret = -ENOMEM; + goto release_lock; + } ret = ice_ntuple_set_input_set(vsi, fsp, input); if (ret) goto free_input; - mutex_lock(&hw->fdir_fltr_lock); if (ice_fdir_is_dup_fltr(hw, input)) { ret = -EINVAL; - goto release_lock; + goto free_input; } if (userdata.flex_fltr) { @@ -2046,7 +2094,7 @@ int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) /* input struct is added to the HW filter list */ ret = ice_ntuple_update_list_entry(pf, input, fsp->location); if (ret) - goto release_lock; + goto free_input; ret = ice_fdir_write_all_fltr(pf, input, true); if (ret) @@ -2059,11 +2107,10 @@ int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) /* update sb-filters count, specific to ring->channel */ ice_update_per_q_fltr(vsi, input->orig_q_index, false); list_del(&input->fltr_node); +free_input: + devm_kfree(dev, input); release_lock: mutex_unlock(&hw->fdir_fltr_lock); -free_input: - if (ret) - devm_kfree(dev, input); return ret; } diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index a664fbde49d17..a21b505395d9f 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -556,8 +556,12 @@ ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type) /* Disable VFs until reset is completed */ mutex_lock(&pf->vfs.table_lock); - ice_for_each_vf(pf, bkt, vf) + ice_for_each_vf(pf, bkt, vf) { + mutex_lock(&vf->cfg_lock); ice_set_vf_state_dis(vf); + ice_vc_fdir_free_prof_all(vf); + mutex_unlock(&vf->cfg_lock); + } mutex_unlock(&pf->vfs.table_lock); if (ice_is_eswitch_mode_switchdev(pf)) { @@ -602,7 +606,11 @@ ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type) skip: /* clear SW filtering DB */ + mutex_lock(&hw->fdir_fltr_lock); + if (hw->fdir_prof) + ice_fdir_clear_flow_handles(hw); ice_clear_hw_tbls(hw); + mutex_unlock(&hw->fdir_fltr_lock); /* disable the VSIs and their queues that are not already DOWN */ set_bit(ICE_VSI_REBUILD_PENDING, ice_get_main_vsi(pf)->state); ice_pf_dis_all_vsi(pf, false); @@ -4398,16 +4406,18 @@ static int ice_init_fdir(struct ice_pf *pf) goto err_vsi_open; } - mutex_init(&pf->hw.fdir_fltr_lock); - + mutex_lock(&pf->hw.fdir_fltr_lock); err = ice_fdir_create_dflt_rules(pf); - if (err) + if (err) { + ice_fdir_release_flows(&pf->hw); goto err_fdir_rule; + } + mutex_unlock(&pf->hw.fdir_fltr_lock); return 0; err_fdir_rule: - ice_fdir_release_flows(&pf->hw); + mutex_unlock(&pf->hw.fdir_fltr_lock); ice_vsi_close(ctrl_vsi); err_vsi_open: ice_vsi_release(ctrl_vsi); @@ -4431,8 +4441,6 @@ static void ice_deinit_fdir(struct ice_pf *pf) pf->vsi[pf->ctrl_vsi_idx] = NULL; pf->ctrl_vsi_idx = ICE_NO_VSI; } - - mutex_destroy(&(&pf->hw)->fdir_fltr_lock); } /** @@ -4746,6 +4754,7 @@ int ice_init_dev(struct ice_pf *pf) return -EIO; } + mutex_init(&pf->hw.fdir_fltr_lock); ice_start_service_task(pf); return 0; @@ -4754,6 +4763,7 @@ int ice_init_dev(struct ice_pf *pf) void ice_deinit_dev(struct ice_pf *pf) { ice_service_task_stop(pf); + mutex_destroy(&pf->hw.fdir_fltr_lock); /* Service task is already stopped, so call reset directly. */ ice_reset(&pf->hw, ICE_RESET_PFR); @@ -6544,7 +6554,9 @@ ice_set_features(struct net_device *netdev, netdev_features_t features) if (changed & NETIF_F_NTUPLE) { bool ena = !!(features & NETIF_F_NTUPLE); - ice_vsi_manage_fdir(vsi, ena); + ret = ice_vsi_manage_fdir(vsi, ena); + if (ret) + return ret; ena ? ice_init_arfs(vsi) : ice_clear_arfs(vsi); } @@ -7840,11 +7852,13 @@ static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type) } /* replay HW Flow Director recipes */ + mutex_lock(&hw->fdir_fltr_lock); if (hw->fdir_prof) ice_fdir_replay_flows(hw); /* replay Flow Director filters */ ice_fdir_replay_fltrs(pf); + mutex_unlock(&hw->fdir_fltr_lock); ice_rebuild_arfs(pf); } @@ -8591,6 +8605,7 @@ static int ice_add_vsi_to_fdir(struct ice_pf *pf, struct ice_vsi *vsi) return -EINVAL; hw = &pf->hw; + mutex_lock(&hw->fdir_fltr_lock); for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) { struct ice_fd_hw_prof *prof; int tun, status; @@ -8628,6 +8643,7 @@ static int ice_add_vsi_to_fdir(struct ice_pf *pf, struct ice_vsi *vsi) dev_dbg(dev, "VSI idx %d added to fdir group %d\n", vsi->idx, flow); } + mutex_unlock(&hw->fdir_fltr_lock); if (!added) dev_dbg(dev, "VSI idx %d not added to fdir groups\n", vsi->idx); diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c index aeddb91528224..fca78c3ff2dd8 100644 --- a/drivers/net/ethernet/intel/ice/virt/fdir.c +++ b/drivers/net/ethernet/intel/ice/virt/fdir.c @@ -200,14 +200,24 @@ static void ice_vc_fdir_free_prof(struct ice_vf *vf, enum ice_fltr_ptype flow) { struct ice_vf_fdir *fdir = &vf->fdir; + struct ice_fd_hw_prof *vf_prof; + struct device *dev; + int tun; if (!fdir->fdir_prof) return; - if (!fdir->fdir_prof[flow]) + vf_prof = fdir->fdir_prof[flow]; + if (!vf_prof) return; - devm_kfree(ice_pf_to_dev(vf->pf), fdir->fdir_prof[flow]); + dev = ice_pf_to_dev(vf->pf); + for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) { + devm_kfree(dev, vf_prof->fdir_seg[tun]); + fdir->prof_entry_cnt[flow][tun] = 0; + } + + devm_kfree(dev, vf_prof); fdir->fdir_prof[flow] = NULL; } @@ -215,7 +225,7 @@ ice_vc_fdir_free_prof(struct ice_vf *vf, enum ice_fltr_ptype flow) * ice_vc_fdir_free_prof_all - free all the profile for this VF * @vf: pointer to the VF structure */ -static void ice_vc_fdir_free_prof_all(struct ice_vf *vf) +void ice_vc_fdir_free_prof_all(struct ice_vf *vf) { struct ice_vf_fdir *fdir = &vf->fdir; enum ice_fltr_ptype flow; diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.h b/drivers/net/ethernet/intel/ice/virt/fdir.h index ac6dcab454b49..1d72522f2339a 100644 --- a/drivers/net/ethernet/intel/ice/virt/fdir.h +++ b/drivers/net/ethernet/intel/ice/virt/fdir.h @@ -45,6 +45,7 @@ int ice_vc_add_fdir_fltr(struct ice_vf *vf, u8 *msg); int ice_vc_del_fdir_fltr(struct ice_vf *vf, u8 *msg); void ice_vf_fdir_init(struct ice_vf *vf); void ice_vf_fdir_exit(struct ice_vf *vf); +void ice_vc_fdir_free_prof_all(struct ice_vf *vf); void ice_vc_fdir_irq_handler(struct ice_vsi *ctrl_vsi, union ice_32b_rx_flex_desc *rx_desc); @@ -53,5 +54,6 @@ void ice_flush_fdir_ctx(struct ice_pf *pf); static inline void ice_vc_fdir_irq_handler(struct ice_vsi *ctrl_vsi, union ice_32b_rx_flex_desc *rx_desc) { } static inline void ice_flush_fdir_ctx(struct ice_pf *pf) { } +static inline void ice_vc_fdir_free_prof_all(struct ice_vf *vf) { } #endif /* CONFIG_PCI_IOV */ #endif /* _ICE_VIRTCHNL_FDIR_H_ */ -- 2.55.0