From patchwork Fri Jan 5 23:54:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13512621 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF681364AB for ; Fri, 5 Jan 2024 23:55:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="XgdpPoPf" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-42836658198so590071cf.0 for ; Fri, 05 Jan 2024 15:55:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1704498899; x=1705103699; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=6Krmv7CmuXfl7DXk8aTDpoDj3ZUAd1H4d9ePlsNjgV4=; b=XgdpPoPfuLeBoykSDtvf4Y+4l07mtwejZOzlbfete81SI180V2M58LnPWWxxzN6RKR eQEqpHISkUduvK/ZA0E7ilg4X2h1SW/GKxasVGoB5z3XJ96ialzydq0ZFP02eEYK3Emk IbxpT5E6gCNryIHyjqUqiykCuLCoLfbixAfIg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704498899; x=1705103699; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6Krmv7CmuXfl7DXk8aTDpoDj3ZUAd1H4d9ePlsNjgV4=; b=Hsf9vkfJuIv7yxfBJF6xbYb7rEczTL+pjyEDuYQLgAnQPIgPUXYKGk4ee41k4cb3J+ zdPHFUjhKNHXxD/3oMRkhLo96cd/nn8J3O/BSLLgWO3ePYNImJ8KOEvD8BJ/x5MgiDic jwPKn4+aZT6X1iRS++RDoak6D3DFOrDSJQocQCS5R6Ur/1Wn6X0qzNv3/w3B1KLKBOYp OHFm1h7zDAgHiXAU3ygWiw3WcfMxiv/d/QryN5yalM7R3TLBVpi51WQdTe88Bz7JBqdG 7R0jyr1TEi0VOlAQ/PqaHDGC/Rlfh8ixGYlNHPej/Fn8EgSaK3bAqZHc9jcgO+0gTsH6 T7dQ== X-Gm-Message-State: AOJu0YwjdgVqW2HCYszQ4k5AXk0X7gZQSBRXv18UshReWcedxLFFHK+7 q15f9sL+mLemCv5cQHZMaDd5kn6VwDD8 X-Google-Smtp-Source: AGHT+IHOGxl2DJ91VGKdocgJyX85wLVWWnTUncnToxFWx1KOeMiDmWFex6MMMftXmAAofw2rAtSUzA== X-Received: by 2002:ac8:7d88:0:b0:429:7b92:4dd8 with SMTP id c8-20020ac87d88000000b004297b924dd8mr284834qtd.91.1704498899436; Fri, 05 Jan 2024 15:54:59 -0800 (PST) Received: from lvnvda5233.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id fb27-20020a05622a481b00b00427f0fdcd44sm1185612qtb.1.2024.01.05.15.54.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jan 2024 15:54:59 -0800 (PST) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pavan.chebbi@broadcom.com, andrew.gospodarek@broadcom.com, horms@kernel.org Subject: [PATCH net-next 2/3] bnxt_en: Fix RCU locking for ntuple filters in bnxt_srxclsrldel() Date: Fri, 5 Jan 2024 15:54:38 -0800 Message-Id: <20240105235439.28282-3-michael.chan@broadcom.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20240105235439.28282-1-michael.chan@broadcom.com> References: <20240105235439.28282-1-michael.chan@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org After looking up an ntuple filter from a RCU hash list, the rcu_read_unlock() call should be made after reading the structure, or after determining that the filter cannot age out (by aRFS). The existing code was calling rcu_read_unlock() too early in bnxt_srxclsrldel(). As suggested by Simon Horman, change the code to handle the error case of fltr_base not found in the if condition. The code looks cleaner this way. Fixes: 8d7ba028aa9a ("bnxt_en: Add support for ntuple filter deletion by ethtool.") Suggested-by: Simon Horman Reported-by: Jakub Kicinski Link: https://lore.kernel.org/netdev/20240104145955.5a6df702@kernel.org/ Signed-off-by: Michael Chan Reviewed-by: Simon Horman --- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c index 5629ba9f4b2e..27b983c0a8a9 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c @@ -1345,25 +1345,26 @@ static int bnxt_srxclsrldel(struct bnxt *bp, struct ethtool_rxnfc *cmd) { struct ethtool_rx_flow_spec *fs = &cmd->fs; struct bnxt_filter_base *fltr_base; + struct bnxt_ntuple_filter *fltr; rcu_read_lock(); fltr_base = bnxt_get_one_fltr_rcu(bp, bp->ntp_fltr_hash_tbl, BNXT_NTP_FLTR_HASH_SIZE, fs->location); - if (fltr_base) { - struct bnxt_ntuple_filter *fltr; - - fltr = container_of(fltr_base, struct bnxt_ntuple_filter, base); + if (!fltr_base) { rcu_read_unlock(); - if (!(fltr->base.flags & BNXT_ACT_NO_AGING)) - return -EINVAL; - bnxt_hwrm_cfa_ntuple_filter_free(bp, fltr); - bnxt_del_ntp_filter(bp, fltr); - return 0; + return -ENOENT; } + fltr = container_of(fltr_base, struct bnxt_ntuple_filter, base); + if (!(fltr->base.flags & BNXT_ACT_NO_AGING)) { + rcu_read_unlock(); + return -EINVAL; + } rcu_read_unlock(); - return -ENOENT; + bnxt_hwrm_cfa_ntuple_filter_free(bp, fltr); + bnxt_del_ntp_filter(bp, fltr); + return 0; } static u64 get_ethtool_ipv4_rss(struct bnxt *bp)