From patchwork Sat Apr 2 00:21:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 12798871 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4197FC43219 for ; Sat, 2 Apr 2022 00:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353579AbiDBAXU (ORCPT ); Fri, 1 Apr 2022 20:23:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353528AbiDBAXS (ORCPT ); Fri, 1 Apr 2022 20:23:18 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 991311AC42A for ; Fri, 1 Apr 2022 17:21:27 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id x14so533007pjf.2 for ; Fri, 01 Apr 2022 17:21:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rUCoJwRG6uYy4sxxy0GpZ+5krDGq6Oa0W/tZrkMg2+I=; b=dIY7efO1ay0LTT2jrqB1uDDpVHPeAGrvb/yj8+vFUajlaWKByE/BahEqsKffnjl4ka TgEd9wmxs0ZqfHpAHlRBP+eG48N/pF+GrHlxK9ZKhCRvd/weUyR9jBJMTuqESq3raCOI AVBqSVZ9xaltwt3BiBB41j4oB/D/6Faj2prPg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rUCoJwRG6uYy4sxxy0GpZ+5krDGq6Oa0W/tZrkMg2+I=; b=WblmMINzVj35XO9dWa+ETq008TwV4zNclK09gdGC33wRQZAs/HO7t2XSbXBzi29JaR KDyNa568TRAl14gjAxJLFNGCYw4QraFpUo5T2Z4qdVtKN7Hhl8SvXu/wvVy35e5FlBUY nDA6ILtRS6WoR0yaNK2Q3wczlqP5OsNA2Yy3HHSnSg0FtQNX4luGWro0ipAWE1Ttj6uL BklrRshykHMBOfq0l6sh11pPB31NycM4DmzX/Z8fFctHTRJhUL1qoSk2aKDUGpvPnq04 UZnfyro7bAqio+bYE7L6KA5nAVlaoKpUiZ8q6kVBXRqZ7p2QXwugkku0xsImt59qsL61 8TkQ== X-Gm-Message-State: AOAM531eqhHyHBgojKbc9p7NU7M2iknGekbmcdnXBCVhDYsZJDui5vbm e3RebEJN8b5sTcL6kwKmXEVnzw== X-Google-Smtp-Source: ABdhPJxO8BFF9MOpu8VKJ0T0ybqrIQFfG9BYI+gHRClBXgGDwMfpFGKWVDYUV5RSTAIuDQBgGOEBtQ== X-Received: by 2002:a17:90b:3447:b0:1c6:fe01:675c with SMTP id lj7-20020a17090b344700b001c6fe01675cmr14294126pjb.59.1648858886266; Fri, 01 Apr 2022 17:21:26 -0700 (PDT) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id k10-20020a056a00168a00b004f7e2a550ccsm4295050pfc.78.2022.04.01.17.21.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Apr 2022 17:21:25 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, kuba@kernel.org, gospo@broadcom.com, bpf@vger.kernel.org, Ray Jui Subject: [PATCH net 3/3] bnxt_en: Prevent XDP redirect from running when stopping TX queue Date: Fri, 1 Apr 2022 20:21:12 -0400 Message-Id: <1648858872-14682-4-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648858872-14682-1-git-send-email-michael.chan@broadcom.com> References: <1648858872-14682-1-git-send-email-michael.chan@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Ray Jui Add checks in the XDP redirect callback to prevent XDP from running when the TX ring is undergoing shutdown. Also remove redundant checks in the XDP redirect callback to validate the txr and the flag that indicates the ring supports XDP. The modulo arithmetic on 'tx_nr_rings_xdp' already guarantees the derived TX ring is an XDP ring. txr is also guaranteed to be valid after checking BNXT_STATE_OPEN and within RCU grace period. Fixes: f18c2b77b2e4 ("bnxt_en: optimized XDP_REDIRECT support") Reviewed-by: Vladimir Olovyannikov Signed-off-by: Ray Jui Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c index c0541ff00ac8..03b1d6c04504 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c @@ -229,14 +229,16 @@ int bnxt_xdp_xmit(struct net_device *dev, int num_frames, ring = smp_processor_id() % bp->tx_nr_rings_xdp; txr = &bp->tx_ring[ring]; + if (READ_ONCE(txr->dev_state) == BNXT_DEV_STATE_CLOSING) + return -EINVAL; + if (static_branch_unlikely(&bnxt_xdp_locking_key)) spin_lock(&txr->xdp_tx_lock); for (i = 0; i < num_frames; i++) { struct xdp_frame *xdp = frames[i]; - if (!txr || !bnxt_tx_avail(bp, txr) || - !(bp->bnapi[ring]->flags & BNXT_NAPI_FLAG_XDP)) + if (!bnxt_tx_avail(bp, txr)) break; mapping = dma_map_single(&pdev->dev, xdp->data, xdp->len,