Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2271021rwl; Sun, 26 Mar 2023 19:48:34 -0700 (PDT) X-Google-Smtp-Source: AKy350ZOt11HBZ71Nk3lfZzH8cNkfAXQzPbYk1g5vtmHMvU7CNEfHOnaExG9Dpqk2KTP3Jt1Q5aH X-Received: by 2002:a05:6402:10d7:b0:4fd:2675:3783 with SMTP id p23-20020a05640210d700b004fd26753783mr10775944edu.1.1679885314201; Sun, 26 Mar 2023 19:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679885314; cv=none; d=google.com; s=arc-20160816; b=dNuDGOgAU1ajJMi85z6S/1keHcpQGu9h4tTBylnRMw4sqyiI03x8B5miMC2I/g12th nR5VxEoreHWuuQRHSTnUxqDG2OzrmrSounU7XSoIQdG2oDtpRxJaCz4NtuqQHEN4Nd+O BbfbAoE01MfrxnGErQQtqsgWTFq2NcUnk8QIl3f/QhfPmQdCjLU83aM8wMZidHiTgHBv syiqqbEkhaQypnw2XP1Mttpm+DEw8iuC9nC4E9E4MWZfLYtCePgZkdQ86Kau5BXTEWIU uDSDG9zSp6o0Q919+o8uBlJKYtLdxIFGFkl2fZ4XFGyj9Si4D2uIoK63It2ZO/4BkqNZ CrUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=6WQh8DFlIUFAoe6CD871YIQT7zlRrIbVfDsOcaDVxO8=; b=kOxXXw0jc5ZTfFirKqRhuDc/62uF0Zxgv4ns6UCW2kBK3FACLHkmdGT2RvNinsPFmB Vn2DNafYg6uYhIf1sJOQTMTPD7JG3aqBAkQS3/U3UpLlY2SyaSEyJbq1zLTiAILxVGCy m05SClIpEnrII5JYlv7Dkg1252vpyGSkF7qON+g1SxlYcn4588qvtO/wjmEJVs4tx0AY iUCRkP7zP9+Ner4qvDb0a3TcX5uJmGAyyNLfVKSeY6MdkZmIC8JnAXHuZ0thSNSvPt8x msdJ3/ysbUVcaZmAUdblF8YqM4Uh5dFqoXWWC0CbKSn3P/2r+OQrmvVmWRL3rq0BAysU juqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cRPQntf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020aa7c24e000000b004ad15de0646si5785554edo.591.2023.03.26.19.48.10; Sun, 26 Mar 2023 19:48:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cRPQntf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231929AbjC0Cq3 (ORCPT + 99 others); Sun, 26 Mar 2023 22:46:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbjC0Cq1 (ORCPT ); Sun, 26 Mar 2023 22:46:27 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 376F244B5; Sun, 26 Mar 2023 19:46:26 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id ek18so29960114edb.6; Sun, 26 Mar 2023 19:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679885184; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6WQh8DFlIUFAoe6CD871YIQT7zlRrIbVfDsOcaDVxO8=; b=cRPQntf31DinXZlVfGGDpBKfUmyiIOuBVPDWAdjL7XRw4ROKwFwpblTZuEbQn1Qqj9 mPBwO2tySYTwo74LMixlktTXT2Av59yCzMfMmNRE0vew+g+6rwHpejYPrtl3yiOdi1NS Ts1CnL2Em0n8wizTS7U/FJjw+r8fZD59acCN6MAceUElYFsWXs6/Po48PcamJ4hhwZhx HSm7ID3AXzmF4oRq7lSDYOeKzVjie3ccUS5gzKAP7/loltCwkyxBQeMlBbxqXFItU++z KiNZ9ToxGTUk02hLTzaIBiVdRoXtmW5IM865K6HwCvaGe+tk2nd8LZjeQwaBFl9HU+Uj 1xjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679885184; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6WQh8DFlIUFAoe6CD871YIQT7zlRrIbVfDsOcaDVxO8=; b=6pNyfWJmO8b1PZf5J+YWiU0cGNX5JTkSzSvFO23X+gD9Chi02+dyEeqK6q9ykPaN+b 5dXo0rtve8WPDE8gR5EIrbpiq/B+hz3weoD4oUuxxMAUbYaWbOmcWJpFVUfsAJR7ryAu lZGL7qOzAYWMZFMJyOR1Ib35Znq5P3lG/NEESOjHZL6QVo1JOvtNd3qW1QVDi+1rlslg FhoQRDBgWXJyy7QQhDKWT4pcQ0chiZxc2eWaU96EawsRIeW2sfz0wPzTltn/42dg0Ugr hmTb1+dQzaaEKzdiCZfo8shPYCe1liFZCkNdRAN3VR+srhqdjG2iHMSILpa3CdyPjznp IZLg== X-Gm-Message-State: AAQBX9fUtnb2vXj0yS/I6c1bXcy558lpC07K3F6JnBlSZhEWuFbjsAUs OuuPhV7rjvcKgtlcaBatLAEUOaPeEp1Z+smr9qw= X-Received: by 2002:a50:ab5a:0:b0:4bb:e549:a2ad with SMTP id t26-20020a50ab5a000000b004bbe549a2admr5032610edc.4.1679885184546; Sun, 26 Mar 2023 19:46:24 -0700 (PDT) MIME-Version: 1.0 References: <20230308220756.587317-1-jjh@daedalian.us> In-Reply-To: From: Jason Xing Date: Mon, 27 Mar 2023 10:45:48 +0800 Message-ID: Subject: Re: [Intel-wired-lan] [PATCH net v3] ixgbe: Panic during XDP_TX with > 64 CPUs To: Paul Menzel Cc: John Hickey , Shujin Li , Jesper Dangaard Brouer , Daniel Borkmann , netdev@vger.kernel.org, John Fastabend , Alexei Starovoitov , Jesse Brandeburg , Eric Dumazet , Tony Nguyen , Jakub Kicinski , intel-wired-lan@lists.osuosl.org, bpf@vger.kernel.org, Paolo Abeni , "David S. Miller" , linux-kernel@vger.kernel.org, Jason Xing Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 26, 2023 at 11:50=E2=80=AFPM Paul Menzel wrote: > > [Cc: Remove undeliverable ] Ah, It's my previous company email. Sorry to notice this email so late. > > Am 26.03.23 um 17:03 schrieb Paul Menzel: > > Dear John, > > > > > > Thank you for your patch. > > > > I=E2=80=99d recommend, to use a statement in the git commit message/sum= mary by > > adding a verb (in imperative mood). Maybe: > > > > Fix panic during XDP_TX with > 64 CPUs > > > > Am 08.03.23 um 23:07 schrieb John Hickey: > >> In commit 'ixgbe: let the xdpdrv work with more than 64 cpus' > >> (4fe815850bdc), support was added to allow XDP programs to run on syst= ems > > > > I think it=E2=80=99s more common to write it like: > > > > In commit 4fe815850bdc (ixgbe: let the xdpdrv work with more than 64 > > cpus) =E2=80=A6 > > > > Even shorter > > > > Commit 4fe815850bdc (ixgbe: let the xdpdrv work with more than 64 cpus) > > adds support to allow XDP programs =E2=80=A6 > > > >> with more than 64 CPUs by locking the XDP TX rings and indexing them > >> using cpu % 64 (IXGBE_MAX_XDP_QS). > >> > >> Upon trying this out patch via the Intel 5.18.6 out of tree driver > > > > Upon trying this patch out via =E2=80=A6 > > > >> on a system with more than 64 cores, the kernel paniced with an > >> array-index-out-of-bounds at the return in ixgbe_determine_xdp_ring in > >> ixgbe.h, which means ixgbe_determine_xdp_q_idx was just returning the > >> cpu instead of cpu % IXGBE_MAX_XDP_QS. An example splat: > > > > Please add, that you have UBSAN enabled, or does it happen without? > > > >> > >> > >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D > >> UBSAN: array-index-out-of-bounds in > >> /var/lib/dkms/ixgbe/5.18.6+focal-1/build/src/ixgbe.h:1147:26 > >> index 65 is out of range for type 'ixgbe_ring *[64]' > >> > >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D > >> BUG: kernel NULL pointer dereference, address: 0000000000000058 > >> #PF: supervisor read access in kernel mode > >> #PF: error_code(0x0000) - not-present page > >> PGD 0 P4D 0 > >> Oops: 0000 [#1] SMP NOPTI > >> CPU: 65 PID: 408 Comm: ksoftirqd/65 > >> Tainted: G IOE 5.15.0-48-generic #54~20.04.1-Ubuntu > >> Hardware name: Dell Inc. PowerEdge R640/0W23H8, BIOS 2.5.4 01/13/202= 0 > >> RIP: 0010:ixgbe_xmit_xdp_ring+0x1b/0x1c0 [ixgbe] > >> Code: 3b 52 d4 cf e9 42 f2 ff ff 66 0f 1f 44 00 00 0f 1f 44 00 00 55= b9 > >> 00 00 00 00 48 89 e5 41 57 41 56 41 55 41 54 53 48 83 ec 08 <44> 0f = b7 > >> 47 58 0f b7 47 5a 0f b7 57 54 44 0f b7 76 08 66 41 39 c0 > > > > If you do not it yet, `scripts/decode_stacktrace.sh` helps decoding > > these traces. > > > >> RSP: 0018:ffffbc3fcd88fcb0 EFLAGS: 00010282 > >> RAX: ffff92a253260980 RBX: ffffbc3fe68b00a0 RCX: 0000000000000000 > >> RDX: ffff928b5f659000 RSI: ffff928b5f659000 RDI: 0000000000000000 > >> RBP: ffffbc3fcd88fce0 R08: ffff92b9dfc20580 R09: 0000000000000001 > >> R10: 3d3d3d3d3d3d3d3d R11: 3d3d3d3d3d3d3d3d R12: 0000000000000000 > >> R13: ffff928b2f0fa8c0 R14: ffff928b9be20050 R15: 000000000000003c > >> FS: 0000000000000000(0000) GS:ffff92b9dfc00000(0000) > >> knlGS:0000000000000000 > >> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > >> CR2: 0000000000000058 CR3: 000000011dd6a002 CR4: 00000000007706e0 > >> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > >> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > >> PKRU: 55555554 > >> Call Trace: > >> > >> ixgbe_poll+0x103e/0x1280 [ixgbe] > >> ? sched_clock_cpu+0x12/0xe0 > >> __napi_poll+0x30/0x160 > >> net_rx_action+0x11c/0x270 > >> __do_softirq+0xda/0x2ee > >> run_ksoftirqd+0x2f/0x50 > >> smpboot_thread_fn+0xb7/0x150 > >> ? sort_range+0x30/0x30 > >> kthread+0x127/0x150 > >> ? set_kthread_struct+0x50/0x50 > >> ret_from_fork+0x1f/0x30 > >> > >> > >> I think this is how it happens: > >> > >> Upon loading the first XDP program on a system with more than 64 CPUs, > >> ixgbe_xdp_locking_key is incremented in ixgbe_xdp_setup. However, > >> immediately after this, the rings are reconfigured by ixgbe_setup_tc. > >> ixgbe_setup_tc calls ixgbe_clear_interrupt_scheme which calls > >> ixgbe_free_q_vectors which calls ixgbe_free_q_vector in a loop. > >> ixgbe_free_q_vector decrements ixgbe_xdp_locking_key once per call if > >> it is non-zero. Commenting out the decrement in ixgbe_free_q_vector > >> stopped my system from panicing. > >> > >> I suspect to make the original patch work, I would need to load an XDP > >> program and then replace it in order to get ixgbe_xdp_locking_key back > >> above 0 since ixgbe_setup_tc is only called when transitioning between > >> XDP and non-XDP ring configurations, while ixgbe_xdp_locking_key is > >> incremented every time ixgbe_xdp_setup is called. > >> > >> Also, ixgbe_setup_tc can be called via ethtool --set-channels, so this > >> becomes another path to decrement ixgbe_xdp_locking_key to 0 on system= s > >> with greater than 64 CPUs. > > > > =E2=80=A6 with more than 64 CPUs. > > > >> For this patch, I have changed static_branch_inc to static_branch_enab= le > >> in ixgbe_setup_xdp. We weren't counting references. The > >> ixgbe_xdp_locking_key only protects code in the XDP_TX path, which is > >> not run when an XDP program is loaded. The other condition for settin= g > >> it on is the number of CPUs, which I assume is static. > >> > >> Fixes: 4fe815850bdc ("ixgbe: let the xdpdrv work with more than 64 cpu= s") > >> Signed-off-by: John Hickey > >> --- > >> v1 -> v2: > >> Added Fixes and net tag. No code changes. > >> v2 -> v3: > >> Added splat. Slight clarification as to why ixgbe_xdp_locking_key > >> is not turned off. Based on feedback from Maciej Fijalkowski. > >> --- > >> drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c | 3 --- > >> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 +- > >> 2 files changed, 1 insertion(+), 4 deletions(-) > >> > >> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c > >> b/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c > >> index f8156fe4b1dc..0ee943db3dc9 100644 > >> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c > >> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c > >> @@ -1035,9 +1035,6 @@ static void ixgbe_free_q_vector(struct > >> ixgbe_adapter *adapter, int v_idx) > >> adapter->q_vector[v_idx] =3D NULL; > >> __netif_napi_del(&q_vector->napi); > >> - if (static_key_enabled(&ixgbe_xdp_locking_key)) > >> - static_branch_dec(&ixgbe_xdp_locking_key); > >> - > >> /* > >> * after a call to __netif_napi_del() napi may still be used and > >> * ixgbe_get_stats64() might access the rings on this vector, > >> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > >> b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > >> index ab8370c413f3..cd2fb72c67be 100644 > >> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > >> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > >> @@ -10283,7 +10283,7 @@ static int ixgbe_xdp_setup(struct net_device > >> *dev, struct bpf_prog *prog) > >> if (nr_cpu_ids > IXGBE_MAX_XDP_QS * 2) > >> return -ENOMEM; > >> else if (nr_cpu_ids > IXGBE_MAX_XDP_QS) > >> - static_branch_inc(&ixgbe_xdp_locking_key); > >> + static_branch_enable(&ixgbe_xdp_locking_key); > >> old_prog =3D xchg(&adapter->xdp_prog, prog); > >> need_reset =3D (!!prog !=3D !!old_prog); > > > > > > Kind regards, > > > > Paul