Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1776937ybl; Sat, 11 Jan 2020 02:36:39 -0800 (PST) X-Google-Smtp-Source: APXvYqy8gTSXKQ09jwYSL9VNfWUQuxU9wqgk1tPmpkw3yZ/us2NZgp3jsX+/xsBz7bFEuTI1Uuov X-Received: by 2002:aca:4d4f:: with SMTP id a76mr6026069oib.26.1578738999218; Sat, 11 Jan 2020 02:36:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578738999; cv=none; d=google.com; s=arc-20160816; b=h92sdUGVubCaGXTomRzRM83slRJj5/bF2W3spbd5GVZRSbK9ltqhug/mbdxSL2WvW7 v1bjedruLAZpOWL+cH7+mi7PRe72+Mr8i4HQ9mEqYFuWBJYlrf3W0ti9jw1V0s2zZmk7 A1EKsvBdnxEoV+I1HIijDfIm0NBcOTx1AteQ7U4mpGr5XkuP6fyRHV5L3lzI7Fr8Gshb F6gSKg4g0jGgXrISP6kICsteDqmCR9mxjz80PBi8JBB/FqBnpNr4xnaQPIv1Wp7q/4IG x0bio4EBwW5F9xV5IxOBx/12hu4pLDOdYG6ZL1qZuAKUGQjiRuFwxiLwcmFMeJcW3SMz 6Aog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NIBVfmOMif5g/2rZ3KU6cuXG36ypFeBDyJULxdR2fbs=; b=pYXK2YgnyR6kL2vr87/ORoUHKEhEoySMUV36U5Q+Xe0sYigGGqctSbAx4UHXIrYwXw B08/N2Sq4N4dmY5FYCU0TqMUR8z3ZZqVb7S3QS0MJ22qlhMT8wj9robpcpzq4y08vyOk 7ZDm/21d9hAzjk8yAIHYb4TYr1+ZSx6X6Zz3XCHawO2fSeqZzrII1htq596dQ6BSYyOM QuYF3wJES7+LXpX5D3LeBYiIp/cSTKvz9tKCpd/03IOhZyNPO+ygwovw+KZzVLBeRVAK NNPIsAo/xF9mqdbponELpsm1SIVkJ27jmu4t2pVvTDczlcfSKLBBW2s3PsrXSF6r8nlX teeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qtDcRQhT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si3356576oto.169.2020.01.11.02.36.27; Sat, 11 Jan 2020 02:36:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qtDcRQhT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731675AbgAKKeS (ORCPT + 99 others); Sat, 11 Jan 2020 05:34:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:49938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731664AbgAKKeL (ORCPT ); Sat, 11 Jan 2020 05:34:11 -0500 Received: from localhost (unknown [62.119.166.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D03D820882; Sat, 11 Jan 2020 10:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578738850; bh=OGdi3cRaoNqr0Vcs1iz9PDm0wsGbqlSnYfM4JsxQ1Eg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qtDcRQhTAjBmX/V/OBBxCd6Q/4DJ2KpU2oLSuxXEU2vL8yQ0MHwI9Eu0qK1FdV1mA FA/BGc9cq+GpDubJKRniK6dmkTCPwcXXXdxhsR9ywWPuTJHVAlA/hMgazDN2DhblXe 6yZEcu74dD2pbBv7cAAXY8pdXrIaCG7q2c35LUfI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yevgeny Kliteynik , Alex Vesker , Saeed Mahameed Subject: [PATCH 5.4 159/165] net/mlx5: DR, No need for atomic refcount for internal SW steering resources Date: Sat, 11 Jan 2020 10:51:18 +0100 Message-Id: <20200111094942.499776527@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200111094921.347491861@linuxfoundation.org> References: <20200111094921.347491861@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yevgeny Kliteynik [ Upstream commit 4ce380ca477507e2f413584cdd99e1698d6682d6 ] No need for an atomic refcounter for the STE and hashtables. These are internal SW steering resources and they are always under domain mutex. This also fixes the following refcount error: refcount_t: addition on 0; use-after-free. WARNING: CPU: 9 PID: 3527 at lib/refcount.c:25 refcount_warn_saturate+0x81/0xe0 Call Trace: dr_table_init_nic+0x10d/0x110 [mlx5_core] mlx5dr_table_create+0xb4/0x230 [mlx5_core] mlx5_cmd_dr_create_flow_table+0x39/0x120 [mlx5_core] __mlx5_create_flow_table+0x221/0x5f0 [mlx5_core] esw_create_offloads_fdb_tables+0x180/0x5a0 [mlx5_core] ... Fixes: 26d688e33f88 ("net/mlx5: DR, Add Steering entry (STE) utilities") Signed-off-by: Yevgeny Kliteynik Reviewed-by: Alex Vesker Signed-off-by: Saeed Mahameed Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c | 2 - drivers/net/ethernet/mellanox/mlx5/core/steering/dr_ste.c | 10 ++++---- drivers/net/ethernet/mellanox/mlx5/core/steering/dr_types.h | 14 ++++++------ 3 files changed, 14 insertions(+), 12 deletions(-) --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c @@ -209,7 +209,7 @@ static void dr_rule_rehash_copy_ste_ctrl /* We need to copy the refcount since this ste * may have been traversed several times */ - refcount_set(&new_ste->refcount, refcount_read(&cur_ste->refcount)); + new_ste->refcount = cur_ste->refcount; /* Link old STEs rule_mem list to the new ste */ mlx5dr_rule_update_rule_member(cur_ste, new_ste); --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_ste.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_ste.c @@ -340,7 +340,7 @@ static void dr_ste_replace(struct mlx5dr if (dst->next_htbl) dst->next_htbl->pointing_ste = dst; - refcount_set(&dst->refcount, refcount_read(&src->refcount)); + dst->refcount = src->refcount; INIT_LIST_HEAD(&dst->rule_list); list_splice_tail_init(&src->rule_list, &dst->rule_list); @@ -557,7 +557,7 @@ bool mlx5dr_ste_is_not_valid_entry(u8 *p bool mlx5dr_ste_not_used_ste(struct mlx5dr_ste *ste) { - return !refcount_read(&ste->refcount); + return !ste->refcount; } /* Init one ste as a pattern for ste data array */ @@ -681,14 +681,14 @@ struct mlx5dr_ste_htbl *mlx5dr_ste_htbl_ htbl->ste_arr = chunk->ste_arr; htbl->hw_ste_arr = chunk->hw_ste_arr; htbl->miss_list = chunk->miss_list; - refcount_set(&htbl->refcount, 0); + htbl->refcount = 0; for (i = 0; i < chunk->num_of_entries; i++) { struct mlx5dr_ste *ste = &htbl->ste_arr[i]; ste->hw_ste = htbl->hw_ste_arr + i * DR_STE_SIZE_REDUCED; ste->htbl = htbl; - refcount_set(&ste->refcount, 0); + ste->refcount = 0; INIT_LIST_HEAD(&ste->miss_list_node); INIT_LIST_HEAD(&htbl->miss_list[i]); INIT_LIST_HEAD(&ste->rule_list); @@ -705,7 +705,7 @@ out_free_htbl: int mlx5dr_ste_htbl_free(struct mlx5dr_ste_htbl *htbl) { - if (refcount_read(&htbl->refcount)) + if (htbl->refcount) return -EBUSY; mlx5dr_icm_free_chunk(htbl->chunk); --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_types.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_types.h @@ -117,7 +117,7 @@ struct mlx5dr_matcher_rx_tx; struct mlx5dr_ste { u8 *hw_ste; /* refcount: indicates the num of rules that using this ste */ - refcount_t refcount; + u32 refcount; /* attached to the miss_list head at each htbl entry */ struct list_head miss_list_node; @@ -149,7 +149,7 @@ struct mlx5dr_ste_htbl_ctrl { struct mlx5dr_ste_htbl { u8 lu_type; u16 byte_mask; - refcount_t refcount; + u32 refcount; struct mlx5dr_icm_chunk *chunk; struct mlx5dr_ste *ste_arr; u8 *hw_ste_arr; @@ -200,13 +200,14 @@ int mlx5dr_ste_htbl_free(struct mlx5dr_s static inline void mlx5dr_htbl_put(struct mlx5dr_ste_htbl *htbl) { - if (refcount_dec_and_test(&htbl->refcount)) + htbl->refcount--; + if (!htbl->refcount) mlx5dr_ste_htbl_free(htbl); } static inline void mlx5dr_htbl_get(struct mlx5dr_ste_htbl *htbl) { - refcount_inc(&htbl->refcount); + htbl->refcount++; } /* STE utils */ @@ -248,14 +249,15 @@ static inline void mlx5dr_ste_put(struct struct mlx5dr_matcher *matcher, struct mlx5dr_matcher_rx_tx *nic_matcher) { - if (refcount_dec_and_test(&ste->refcount)) + ste->refcount--; + if (!ste->refcount) mlx5dr_ste_free(ste, matcher, nic_matcher); } /* initial as 0, increased only when ste appears in a new rule */ static inline void mlx5dr_ste_get(struct mlx5dr_ste *ste) { - refcount_inc(&ste->refcount); + ste->refcount++; } void mlx5dr_ste_set_hit_addr_by_next_htbl(u8 *hw_ste,