From patchwork Tue Jan 17 09:25:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 13104407 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 C1DC9C6379F for ; Tue, 17 Jan 2023 09:27:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236629AbjAQJ1z (ORCPT ); Tue, 17 Jan 2023 04:27:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236582AbjAQJ1Q (ORCPT ); Tue, 17 Jan 2023 04:27:16 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4DF815567; Tue, 17 Jan 2023 01:25:59 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id c10-20020a05600c0a4a00b003db0636ff84so1048610wmq.0; Tue, 17 Jan 2023 01:25:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qAUfOgwTFuIvNwuhx5n2F0/0oHdZLDnXBOo9K0VmpcQ=; b=CWtyl5xVAN8hDnS+osaxQdP5svguFEVGu+ZeXMtdRw3eRHlOE/vA/IYhk/kfGU3GAH hVuHssnTRYINV7FlfDIUsyQlOvRZkc6OH3B70eG6eWmsyaEZaihqU1tMb2w2uZ6eKYmO 6+cm3IsMfMWgLzdHFXRxNegoPQfXf8ghmzi00CDMYxK5rO/9etaH7I35oV89SJsXGH3j mw/KNj6pNs92b7fJk2WThTpCGq12pSu4rKfQkCHpd4yaZvNqj21rOOJZW/opXEZ2nX6u kWG+fWpHrhqDx7ZrhZ2zZw8qojOBUm+cin3YPkJeV/G+FdiB970Tnwha+pOZ5TiHbieT ae7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=qAUfOgwTFuIvNwuhx5n2F0/0oHdZLDnXBOo9K0VmpcQ=; b=6RzOPnkfuTTSG8Ddn+NXz5x0mW+TEjPvDvQB8jS//K6gllNCkLJY1DgBuRPBwX7UDy KddPEXbsycSyv1/H/ewNKHgUmMsOFNF1kFTiokH8NCfAdnsCVupbK5X3YMkkBpPuSN9t Lg23Tv6uBxYWnRKdSQH7Qh+pXfV0COYHNF7S9SxSNKdt3Wgi1NcJgS1TYrwE2L0vM4Fo fZjQ4co0O6HKg2hM0/U5toyORAzvPXiN2/E53PVxEq1LJjfvXC+b41RGC00fRZENG6fs FOSlWRsd1OdyPL5Df/AK849QhbtUPtuBtahlSHOb3h19LloNlJaYelaASzAkflLKAQJf mPSw== X-Gm-Message-State: AFqh2kobv0ihZJZyTYBVV5D1KI7d/mHIdsiusR7BYZGMJCzOXicw1tyA 9x0bIrStgxyH6UREm9S4xdA= X-Google-Smtp-Source: AMrXdXtKyFP8bM66TzUWLToIZLcryLHL4fR0j/jL6Fd7JFFRr2/Frp8JmnrnOF4nJMhclqcklA5QGw== X-Received: by 2002:a7b:c5cb:0:b0:3da:fac4:7da3 with SMTP id n11-20020a7bc5cb000000b003dafac47da3mr2243545wmk.36.1673947558214; Tue, 17 Jan 2023 01:25:58 -0800 (PST) Received: from localhost.localdomain (h-176-10-254-193.A165.priv.bahnhof.se. [176.10.254.193]) by smtp.gmail.com with ESMTPSA id u21-20020a7bc055000000b003d9aa76dc6asm48008881wmc.0.2023.01.17.01.25.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2023 01:25:57 -0800 (PST) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, jonathan.lemon@gmail.com, maciej.fijalkowski@intel.com, kuba@kernel.org, toke@redhat.com, pabeni@redhat.com, davem@davemloft.net, aelior@marvell.com, manishc@marvell.com, horatiu.vultur@microchip.com, UNGLinuxDriver@microchip.com, mst@redhat.com, jasowang@redhat.com, ioana.ciornei@nxp.com, madalin.bucur@nxp.com Cc: bpf@vger.kernel.org Subject: [PATCH net 1/5] qede: execute xdp_do_flush() before napi_complete_done() Date: Tue, 17 Jan 2023 10:25:29 +0100 Message-Id: <20230117092533.5804-2-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230117092533.5804-1-magnus.karlsson@gmail.com> References: <20230117092533.5804-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Magnus Karlsson Make sure that xdp_do_flush() is always executed before napi_complete_done(). This is important for two reasons. First, a redirect to an XSKMAP assumes that a call to xdp_do_redirect() from napi context X on CPU Y will be follwed by a xdp_do_flush() from the same napi context and CPU. This is not guaranteed if the napi_complete_done() is executed before xdp_do_flush(), as it tells the napi logic that it is fine to schedule napi context X on another CPU. Details from a production system triggering this bug using the veth driver can be found following the first link below. The second reason is that the XDP_REDIRECT logic in itself relies on being inside a single NAPI instance through to the xdp_do_flush() call for RCU protection of all in-kernel data structures. Details can be found in the second link below. Fixes: d1b25b79e162b ("qede: add .ndo_xdp_xmit() and XDP_REDIRECT support") Signed-off-by: Magnus Karlsson Link: https://lore.kernel.org/r/20221220185903.1105011-1-sbohrer@cloudflare.com Link: https://lore.kernel.org/all/20210624160609.292325-1-toke@redhat.com/ --- drivers/net/ethernet/qlogic/qede/qede_fp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qede/qede_fp.c b/drivers/net/ethernet/qlogic/qede/qede_fp.c index 7c2af482192d..cb1746bc0e0c 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_fp.c +++ b/drivers/net/ethernet/qlogic/qede/qede_fp.c @@ -1438,6 +1438,10 @@ int qede_poll(struct napi_struct *napi, int budget) rx_work_done = (likely(fp->type & QEDE_FASTPATH_RX) && qede_has_rx_work(fp->rxq)) ? qede_rx_int(fp, budget) : 0; + + if (fp->xdp_xmit & QEDE_XDP_REDIRECT) + xdp_do_flush(); + /* Handle case where we are called by netpoll with a budget of 0 */ if (rx_work_done < budget || !budget) { if (!qede_poll_is_more_work(fp)) { @@ -1457,9 +1461,6 @@ int qede_poll(struct napi_struct *napi, int budget) qede_update_tx_producer(fp->xdp_tx); } - if (fp->xdp_xmit & QEDE_XDP_REDIRECT) - xdp_do_flush_map(); - return rx_work_done; } From patchwork Tue Jan 17 09:25:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 13104408 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 CB504C678D4 for ; Tue, 17 Jan 2023 09:28:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236419AbjAQJ2F (ORCPT ); Tue, 17 Jan 2023 04:28:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236601AbjAQJ1g (ORCPT ); Tue, 17 Jan 2023 04:27:36 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 558591E1ED; Tue, 17 Jan 2023 01:26:02 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id o17-20020a05600c511100b003db021ef437so2549514wms.4; Tue, 17 Jan 2023 01:26:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Lf+DfBr7EiMoGbNIDvvLlIXu7J9dT9iJQIWXw6brQfg=; b=bPFSAcWHTn+xs92Sh1lDRG6xAyGayL0MRYw5UGd3RHdEYEUk6obwfMQS3RClnrNJl4 4fPcGGnbEB3ja/5aFsxgltIARJxHiDS8H7uUPCmCFb1BU+fT9mxP64ySh94tnRi62hh1 hrYRwaQ5fRMgvRG0GFlhV4Dhj8zZCEuYhsMywAbdql8pBY2FeiV+BbMsLjnz2v28ZJ8t Xz4NIy1qjBeBwXrwPVPQWRuQ80yRC9Zo+gCv77X1bOnJXeEP369HzzLztlzlfmmP/VVq axrRKf4H2YbTPgOdaVZx8pQHNYcADg/iaKQ5hv1YbVlcBj/hWBr880eqYGvXIvLd/87n SPHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=Lf+DfBr7EiMoGbNIDvvLlIXu7J9dT9iJQIWXw6brQfg=; b=vFgI1IO2cAQKYA/AFaTxjftXpW4IR0lsIXHgmWmvh0TaQLBM09+/Oghmd1DaFcZUcC bSBzwfGZ9W9XK/L9iUksWOu5ct3yFLIzSUo0ZIvlWONJUran8oRcDHAeIQlimLHK5eQo p+pOnyn75E/qC6vRcyvfhLMEhHV1MMwLQXgTQlOfqMGg1qw+m4UWSuf8szAiBlBSj3ac k91cQY/krqlHAJ7WMB3VtAJOR7Ltr/ktgcfPqcM0VdhSdbykj5NP8yladQ9DHZyfEUeD NlqFYeIv15er1/EAfqqbiwurgsq1bHd2F7ei1Z6bYkTREnTvS4SRbNpj/M7j36Dm4EUG VbiA== X-Gm-Message-State: AFqh2kp+ZULxUcbBXPH8NPvGxq/nHZH1ZhMJVsA06Y4XEdMEWiD17jJW X4Qhk2MvPzDPdS3g3FEka/w= X-Google-Smtp-Source: AMrXdXsbGElYmFMwcKgfKSb/g0qJNV9oeYIXA1MZkaJB57yzw2vwFUS0+0EMZAZLWd9y+SElwx5NGw== X-Received: by 2002:a1c:cc17:0:b0:3d9:fb8a:b2c5 with SMTP id h23-20020a1ccc17000000b003d9fb8ab2c5mr2364821wmb.16.1673947560649; Tue, 17 Jan 2023 01:26:00 -0800 (PST) Received: from localhost.localdomain (h-176-10-254-193.A165.priv.bahnhof.se. [176.10.254.193]) by smtp.gmail.com with ESMTPSA id u21-20020a7bc055000000b003d9aa76dc6asm48008881wmc.0.2023.01.17.01.25.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2023 01:25:59 -0800 (PST) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, jonathan.lemon@gmail.com, maciej.fijalkowski@intel.com, kuba@kernel.org, toke@redhat.com, pabeni@redhat.com, davem@davemloft.net, aelior@marvell.com, manishc@marvell.com, horatiu.vultur@microchip.com, UNGLinuxDriver@microchip.com, mst@redhat.com, jasowang@redhat.com, ioana.ciornei@nxp.com, madalin.bucur@nxp.com Cc: bpf@vger.kernel.org Subject: [PATCH net 2/5] lan966x: execute xdp_do_flush() before napi_complete_done() Date: Tue, 17 Jan 2023 10:25:30 +0100 Message-Id: <20230117092533.5804-3-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230117092533.5804-1-magnus.karlsson@gmail.com> References: <20230117092533.5804-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Magnus Karlsson Make sure that xdp_do_flush() is always executed before napi_complete_done(). This is important for two reasons. First, a redirect to an XSKMAP assumes that a call to xdp_do_redirect() from napi context X on CPU Y will be follwed by a xdp_do_flush() from the same napi context and CPU. This is not guaranteed if the napi_complete_done() is executed before xdp_do_flush(), as it tells the napi logic that it is fine to schedule napi context X on another CPU. Details from a production system triggering this bug using the veth driver can be found following the first link below. The second reason is that the XDP_REDIRECT logic in itself relies on being inside a single NAPI instance through to the xdp_do_flush() call for RCU protection of all in-kernel data structures. Details can be found in the second link below. Fixes: a825b611c7c1 ("net: lan966x: Add support for XDP_REDIRECT") Signed-off-by: Magnus Karlsson Link: https://lore.kernel.org/r/20221220185903.1105011-1-sbohrer@cloudflare.com Link: https://lore.kernel.org/all/20210624160609.292325-1-toke@redhat.com/ Acked-by: Steen Hegelund --- drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 5314c064ceae..55b484b10562 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -608,12 +608,12 @@ static int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight) lan966x_fdma_rx_reload(rx); } - if (counter < weight && napi_complete_done(napi, counter)) - lan_wr(0xff, lan966x, FDMA_INTR_DB_ENA); - if (redirect) xdp_do_flush(); + if (counter < weight && napi_complete_done(napi, counter)) + lan_wr(0xff, lan966x, FDMA_INTR_DB_ENA); + return counter; } From patchwork Tue Jan 17 09:25:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 13104409 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 B8268C63797 for ; Tue, 17 Jan 2023 09:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236602AbjAQJ2Q (ORCPT ); Tue, 17 Jan 2023 04:28:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236456AbjAQJ1j (ORCPT ); Tue, 17 Jan 2023 04:27:39 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE4C20046; Tue, 17 Jan 2023 01:26:03 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id c10-20020a05600c0a4a00b003db0636ff84so1048762wmq.0; Tue, 17 Jan 2023 01:26:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DvSs2sfx/PVbNBqoq0YVCcet27URCbN7ELh13cYBY48=; b=KvsjpNOJ6J5rx5VyuOe1FdOI3OYANDJfftWLYf8M8ij6cQh3xgZUbjijU3KQ242yAu 32EfjcrUGStzZ4zHm/heXh99z+ZM4XaFDvfYGL1sIWf4TQWLCjf5kOpWBQrxociDkgXv 5s+JMXkGat7ipO615mAZn9mJgBboFE3xRbn/rgRjoYuOpEQjIzq+4SEPfsCSrwtkifFc 7jdMMtxiI+xzyL3gJb8iTfbRDges2914KJD8SBpbhZHCBJcTMU3bnqlqtRk//6uc2q0f g01S29xTwgcx+ySAGAxn41ymQeUViSLp95ptVnVsISMJRHoAa5oSoXHyO0Sz08RXWqQ5 NYMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=DvSs2sfx/PVbNBqoq0YVCcet27URCbN7ELh13cYBY48=; b=pnxk+fOKNcOYHrbURvFDeScv7p2TBqd7M2wEG5ABZrVeuv1lc9vyFRq4GjInlm5GdJ Up8gf/7za16jdyVbQqnNl42C5zQya4zzX2hdfWPW2bV/Ttlt6Q3LGyh+qU2mLXrLVicE 0RIfCorngTBBarsS2Uxpl+aYFUQzQ7uDg7wZlAKT8oXlrGvVwV7FbAOAKDRVFR5pQiig ioOAquNW0h1p9aph5nD1PvXIWgAPjINku2MC4osHaMdhvKoYde7QF3mjzb1x1C6jo5bx Q38PDiOpmDIFqzIRfWys9ccCxyEMzq4VcOKSymNRjsceY1ZBSUmm+3EkfIfB19IT+m8t 0iRg== X-Gm-Message-State: AFqh2kqjM3n66C+rl8IGSelt78B6VLDc0xqK7a9hdKRsg5F6QpqnykVY A5u20y7fsRNdzCzC2y/FR8I= X-Google-Smtp-Source: AMrXdXukdK76oaSHmCtQtqtznspBQIe1WjApGWOcMfh1xZAt3e/p8Q75Uq8IX42KBw5FS6j8pKkdSw== X-Received: by 2002:a05:600c:224a:b0:3da:fa15:8658 with SMTP id a10-20020a05600c224a00b003dafa158658mr6756704wmm.32.1673947563106; Tue, 17 Jan 2023 01:26:03 -0800 (PST) Received: from localhost.localdomain (h-176-10-254-193.A165.priv.bahnhof.se. [176.10.254.193]) by smtp.gmail.com with ESMTPSA id u21-20020a7bc055000000b003d9aa76dc6asm48008881wmc.0.2023.01.17.01.26.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2023 01:26:02 -0800 (PST) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, jonathan.lemon@gmail.com, maciej.fijalkowski@intel.com, kuba@kernel.org, toke@redhat.com, pabeni@redhat.com, davem@davemloft.net, aelior@marvell.com, manishc@marvell.com, horatiu.vultur@microchip.com, UNGLinuxDriver@microchip.com, mst@redhat.com, jasowang@redhat.com, ioana.ciornei@nxp.com, madalin.bucur@nxp.com Cc: bpf@vger.kernel.org Subject: [PATCH net 3/5] virtio-net: execute xdp_do_flush() before napi_complete_done() Date: Tue, 17 Jan 2023 10:25:31 +0100 Message-Id: <20230117092533.5804-4-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230117092533.5804-1-magnus.karlsson@gmail.com> References: <20230117092533.5804-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Magnus Karlsson Make sure that xdp_do_flush() is always executed before napi_complete_done(). This is important for two reasons. First, a redirect to an XSKMAP assumes that a call to xdp_do_redirect() from napi context X on CPU Y will be follwed by a xdp_do_flush() from the same napi context and CPU. This is not guaranteed if the napi_complete_done() is executed before xdp_do_flush(), as it tells the napi logic that it is fine to schedule napi context X on another CPU. Details from a production system triggering this bug using the veth driver can be found following the first link below. The second reason is that the XDP_REDIRECT logic in itself relies on being inside a single NAPI instance through to the xdp_do_flush() call for RCU protection of all in-kernel data structures. Details can be found in the second link below. Fixes: 186b3c998c50 ("virtio-net: support XDP_REDIRECT") Signed-off-by: Magnus Karlsson Link: https://lore.kernel.org/r/20221220185903.1105011-1-sbohrer@cloudflare.com Link: https://lore.kernel.org/all/20210624160609.292325-1-toke@redhat.com/ --- drivers/net/virtio_net.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 7723b2a49d8e..bc4d79fe3c83 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1677,13 +1677,13 @@ static int virtnet_poll(struct napi_struct *napi, int budget) received = virtnet_receive(rq, budget, &xdp_xmit); + if (xdp_xmit & VIRTIO_XDP_REDIR) + xdp_do_flush(); + /* Out of packets? */ if (received < budget) virtqueue_napi_complete(napi, rq->vq, received); - if (xdp_xmit & VIRTIO_XDP_REDIR) - xdp_do_flush(); - if (xdp_xmit & VIRTIO_XDP_TX) { sq = virtnet_xdp_get_sq(vi); if (virtqueue_kick_prepare(sq->vq) && virtqueue_notify(sq->vq)) { From patchwork Tue Jan 17 09:25:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 13104420 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 B083EC3DA78 for ; Tue, 17 Jan 2023 09:28:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236068AbjAQJ2i (ORCPT ); Tue, 17 Jan 2023 04:28:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236430AbjAQJ1p (ORCPT ); Tue, 17 Jan 2023 04:27:45 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07DDC265AC; Tue, 17 Jan 2023 01:26:07 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id l41-20020a05600c1d2900b003daf986faaeso4029833wms.3; Tue, 17 Jan 2023 01:26:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HLCA8Czl5WQ/VKvIIWxUV8C56Hw+2JQ+C9JrrfhSbGo=; b=jTru5zR2JAPq4quFWC8I79DsdGsYxCoutSgm2m7XyTev2bPe3VOuXAt4cXu3wrcaSB BKs+loD/1MuvBKN4SKpUg9c8HOHlQDOAdsbWYxovyxdTOGLDcfn9fxjJsyjxoIxPl7+v Qmfu2H19gDKtKGlrKzEvm3JT1numjOmNllTy2d8g3d+Wq4OvsNcDC4j+sqh9yWoy+r5q 37SIfnpuwgXeQWM2nCNLPu+okXuxdHUJI1P7YMwNEdb8oAOOwPKicqjXN/k8cCKySGna I0uDDSVYMK+EtqAg3BlyS7QKRq4XqnqNVIuKigq2nRt3kqmfqegsdyhBZvnVkD7w62/h GkqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=HLCA8Czl5WQ/VKvIIWxUV8C56Hw+2JQ+C9JrrfhSbGo=; b=Fb9prVRS67IHuGBcmktjq1B9ziUGQ2geMZRFzVZ3HFtzGhW4b78rLfHcb10/TH/NIV Yd1Ad6iNvmVlxVp34b+DuNMHk2Po3BcZ/TecB1YLflQdBWUuKw3NQ/wRRBo6JhQnZjuw vUkx9ePqyj+jW3KVCPOqruqsY0P3yw43v3XCbERQvzv5CXJoLKCxRWV7182cUslmUsrn SWfIJMen3AgF0USR5Iqww26z6pjJ4KE6WxSS2PZuec9pBnlCZO2oxko6kSOrdO1y/dr+ FJkN/OTGH71bJ3Da3yc3vgYNiU2Hxhj5bO1oxozurbuEun5tYJH6NYQW91ztdZ2xXDFS Dn/w== X-Gm-Message-State: AFqh2kpjTpn5H9EKzX6FJI92cFJqF9/sJ+j8peMl0lPoIK4MQ97mZmxC 18tlcEyJZ5nBZtlvcbYccvY= X-Google-Smtp-Source: AMrXdXvHuCNk1VtpA0OUrQyo1zFtGnK0IGNQIdV6FDXstsNqEBiwNf2yQsBIuxfMYjbnhS2So5UMHw== X-Received: by 2002:a05:600c:33a8:b0:3d9:ed3b:5b3e with SMTP id o40-20020a05600c33a800b003d9ed3b5b3emr2291508wmp.19.1673947565533; Tue, 17 Jan 2023 01:26:05 -0800 (PST) Received: from localhost.localdomain (h-176-10-254-193.A165.priv.bahnhof.se. [176.10.254.193]) by smtp.gmail.com with ESMTPSA id u21-20020a7bc055000000b003d9aa76dc6asm48008881wmc.0.2023.01.17.01.26.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2023 01:26:04 -0800 (PST) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, jonathan.lemon@gmail.com, maciej.fijalkowski@intel.com, kuba@kernel.org, toke@redhat.com, pabeni@redhat.com, davem@davemloft.net, aelior@marvell.com, manishc@marvell.com, horatiu.vultur@microchip.com, UNGLinuxDriver@microchip.com, mst@redhat.com, jasowang@redhat.com, ioana.ciornei@nxp.com, madalin.bucur@nxp.com Cc: bpf@vger.kernel.org Subject: [PATCH net 4/5] dpaa_eth: execute xdp_do_flush() before napi_complete_done() Date: Tue, 17 Jan 2023 10:25:32 +0100 Message-Id: <20230117092533.5804-5-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230117092533.5804-1-magnus.karlsson@gmail.com> References: <20230117092533.5804-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Magnus Karlsson Make sure that xdp_do_flush() is always executed before napi_complete_done(). This is important for two reasons. First, a redirect to an XSKMAP assumes that a call to xdp_do_redirect() from napi context X on CPU Y will be follwed by a xdp_do_flush() from the same napi context and CPU. This is not guaranteed if the napi_complete_done() is executed before xdp_do_flush(), as it tells the napi logic that it is fine to schedule napi context X on another CPU. Details from a production system triggering this bug using the veth driver can be found following the first link below. The second reason is that the XDP_REDIRECT logic in itself relies on being inside a single NAPI instance through to the xdp_do_flush() call for RCU protection of all in-kernel data structures. Details can be found in the second link below. Fixes: a1e031ffb422 ("dpaa_eth: add XDP_REDIRECT support") Signed-off-by: Magnus Karlsson Link: https://lore.kernel.org/r/20221220185903.1105011-1-sbohrer@cloudflare.com Link: https://lore.kernel.org/all/20210624160609.292325-1-toke@redhat.com/ --- drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c index 3f8032947d86..027fff9f7db0 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c @@ -2410,6 +2410,9 @@ static int dpaa_eth_poll(struct napi_struct *napi, int budget) cleaned = qman_p_poll_dqrr(np->p, budget); + if (np->xdp_act & XDP_REDIRECT) + xdp_do_flush(); + if (cleaned < budget) { napi_complete_done(napi, cleaned); qman_p_irqsource_add(np->p, QM_PIRQ_DQRI); @@ -2417,9 +2420,6 @@ static int dpaa_eth_poll(struct napi_struct *napi, int budget) qman_p_irqsource_add(np->p, QM_PIRQ_DQRI); } - if (np->xdp_act & XDP_REDIRECT) - xdp_do_flush(); - return cleaned; } From patchwork Tue Jan 17 09:25:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 13104421 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 49302C63797 for ; Tue, 17 Jan 2023 09:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236408AbjAQJ2j (ORCPT ); Tue, 17 Jan 2023 04:28:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236587AbjAQJ1t (ORCPT ); Tue, 17 Jan 2023 04:27:49 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78A2C2B0A8; Tue, 17 Jan 2023 01:26:08 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id f25-20020a1c6a19000000b003da221fbf48so7616037wmc.1; Tue, 17 Jan 2023 01:26:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xuCStn9V5oARcXzlZlnENM3b/8Cc1xy/rZz8yfu4umE=; b=PJn4IsJGWNquOVoX8uL9scHqVHfzRajzDZEFkK2LdugQseNexbc8pSDFCYwDMLZheg Ym7No27ExKWVxoYMOHV2mm9v/bDZrw5umNjsVYLgyhFxg7+e6JO1laoSJFDmZCzjmSKB CON13JslubqUQEOxvaKDycXJmc1jjyOqlhfMdEqdoTHUNvXDoO6d2Q3kFwm5qedk2Z+V RMs58griQ0c7us6XdvdFYvp0Hmx6Ux5C7rpBM/NIrFhl214Pe9ew9VBvgh2SLGZntBaB fqx0XtwcClTYJ3emRj6LZxHQzDYv1zozQndy9bSG4DNs/aMAZ89Srt1O3tggxu1meLEU 7Ytg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=xuCStn9V5oARcXzlZlnENM3b/8Cc1xy/rZz8yfu4umE=; b=AUMcyYkZzKofBccGybzQs3eBbHGZGvHN9cQVIwRZPC5cJhu+9FM/wrUrH8RX2fBfk0 w2P+uS5/FAxujdLcsEepZ4Ax4XgvESGhxzbrCUOBYFRmOXZWeUFNG/7Ce58SI9BLSOjR MvX6pypqV0XRklDslMxG2qu7RUX0vARWWk6c8Dkp6T+/fXkmI/GkG+uwO/5/TwzzC6UJ 8/TQ+sqkOK32aHCWlGcwRHXN4EaOexWtTXmUeNaNc2yAyErhffJ17X51rbX21ep7g6qL YhuZE+aZl4BxILF8jxzmGnQPdWRQnPj0A/XlxfK5ss311r2D0DOEmFfJlyCeR6acWYX5 t5VA== X-Gm-Message-State: AFqh2koc61pEsr0IF6AlVtM/i/2ghjuEJihyvp/yJVoIFqxfOd/v6Bh3 a9B+RmJcuWhVeZaIsCuPEdg= X-Google-Smtp-Source: AMrXdXvDjoxt129uWZFHqLVwl/vcOBXNnnJ3Rjx+QizZos3M3OWWOqB8EhGi1c311sBxHjDl+rkofw== X-Received: by 2002:a05:600c:b54:b0:3c6:e60f:3f6f with SMTP id k20-20020a05600c0b5400b003c6e60f3f6fmr2283961wmr.38.1673947568043; Tue, 17 Jan 2023 01:26:08 -0800 (PST) Received: from localhost.localdomain (h-176-10-254-193.A165.priv.bahnhof.se. [176.10.254.193]) by smtp.gmail.com with ESMTPSA id u21-20020a7bc055000000b003d9aa76dc6asm48008881wmc.0.2023.01.17.01.26.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2023 01:26:07 -0800 (PST) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, jonathan.lemon@gmail.com, maciej.fijalkowski@intel.com, kuba@kernel.org, toke@redhat.com, pabeni@redhat.com, davem@davemloft.net, aelior@marvell.com, manishc@marvell.com, horatiu.vultur@microchip.com, UNGLinuxDriver@microchip.com, mst@redhat.com, jasowang@redhat.com, ioana.ciornei@nxp.com, madalin.bucur@nxp.com Cc: bpf@vger.kernel.org Subject: [PATCH net 5/5] dpaa2-eth: execute xdp_do_flush() before napi_complete_done() Date: Tue, 17 Jan 2023 10:25:33 +0100 Message-Id: <20230117092533.5804-6-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230117092533.5804-1-magnus.karlsson@gmail.com> References: <20230117092533.5804-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Magnus Karlsson Make sure that xdp_do_flush() is always executed before napi_complete_done(). This is important for two reasons. First, a redirect to an XSKMAP assumes that a call to xdp_do_redirect() from napi context X on CPU Y will be follwed by a xdp_do_flush() from the same napi context and CPU. This is not guaranteed if the napi_complete_done() is executed before xdp_do_flush(), as it tells the napi logic that it is fine to schedule napi context X on another CPU. Details from a production system triggering this bug using the veth driver can be found following the first link below. The second reason is that the XDP_REDIRECT logic in itself relies on being inside a single NAPI instance through to the xdp_do_flush() call for RCU protection of all in-kernel data structures. Details can be found in the second link below. Fixes: d678be1dc1ec ("dpaa2-eth: add XDP_REDIRECT support") Signed-off-by: Magnus Karlsson Link: https://lore.kernel.org/r/20221220185903.1105011-1-sbohrer@cloudflare.com Link: https://lore.kernel.org/all/20210624160609.292325-1-toke@redhat.com/ --- drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c index 0c35abb7d065..2e79d18fc3c7 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -1993,10 +1993,15 @@ static int dpaa2_eth_poll(struct napi_struct *napi, int budget) if (rx_cleaned >= budget || txconf_cleaned >= DPAA2_ETH_TXCONF_PER_NAPI) { work_done = budget; + if (ch->xdp.res & XDP_REDIRECT) + xdp_do_flush(); goto out; } } while (store_cleaned); + if (ch->xdp.res & XDP_REDIRECT) + xdp_do_flush(); + /* Update NET DIM with the values for this CDAN */ dpaa2_io_update_net_dim(ch->dpio, ch->stats.frames_per_cdan, ch->stats.bytes_per_cdan); @@ -2032,9 +2037,7 @@ static int dpaa2_eth_poll(struct napi_struct *napi, int budget) txc_fq->dq_bytes = 0; } - if (ch->xdp.res & XDP_REDIRECT) - xdp_do_flush_map(); - else if (rx_cleaned && ch->xdp.res & XDP_TX) + if (rx_cleaned && ch->xdp.res & XDP_TX) dpaa2_eth_xdp_tx_flush(priv, ch, &priv->fq[flowid]); return work_done;