Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp341184pxh; Tue, 9 Nov 2021 11:34:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2urgucJvjnXpo6HQqeBz6UPVqy3D3tEPuUmr/XBKoNaoe0H9s3QjYiwSUlJ/Qv26AFK4O X-Received: by 2002:a05:6e02:1b09:: with SMTP id i9mr7178506ilv.111.1636486495511; Tue, 09 Nov 2021 11:34:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1636486495; cv=pass; d=google.com; s=arc-20160816; b=dR9EsDfv537DHtHAW76Ao9cAqRJmbodkAA4yuWzPkQ136WFPf4/fzMvBvmffnAUtuJ YPoVepWr2rHxSzkwyy58hB8gOLoGubsbSqMURUJOBWt9Hh/Z1Iq4qtUenAaDaH4sjY5p JVedcJpumYBzDBPNwlJg46zGIwr6czYiKYrpBlLlOiLAdOv6HiYJj8F/vCTW0W9y/DCq m8qVL878tsTF7Ng316r9xX7Xmr0PsqqQCZ3fDgPcnup15OLEC3r86AlFu1MdHIxcf0p6 mLSdyQbVXO/mre7UDAI3nxQ5OgD/mjD8iwiXPBQC9+dkl7y9OZ93aqC5imjQgVrDq+DQ w6WQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=muwU5Ab53jdkRahd2AT/NSycEQBmewI7F9kt1A9r2ps=; b=AnYiV6f9G4MQ9S2dNB4k03k/Add0ra42NWoOQbg71hWxyOfmz3AarhTHzXWWSYB5gF o8MmEAlKJ9yVkNk2tzLACCyCVsUyULcio+4RQ22OAgGnyKmfbhUngpQSrQUEYeJ1s641 gN5KppyX6UMey/+4YyCQFn267Inm5K7vrbgT15IWmu9MCQBXHJLGaYArMVRvzv8JbWHk fL3M8cvRgsB/Ro+U1Yu6R8RWZEimGlVrtLPJuZaFFhl1pyDsgodLoGTeJg5oTj+RX2Av bFpJhMSzYBHTbcRkE/3Ism+KMfr/iOclZBKyQZFPLRUXMHJdl1SO0dgl32N0h98DsaZN Onpg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@eho.link header.s=selector1 header.b="YcIx/A/w"; arc=pass (i=1 spf=pass spfdomain=eho.link dkim=pass dkdomain=eho.link dmarc=pass fromdomain=eho.link); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=eho.link Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p11si4442918jal.39.2021.11.09.11.34.42; Tue, 09 Nov 2021 11:34:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@eho.link header.s=selector1 header.b="YcIx/A/w"; arc=pass (i=1 spf=pass spfdomain=eho.link dkim=pass dkdomain=eho.link dmarc=pass fromdomain=eho.link); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=eho.link Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245355AbhKIKeQ (ORCPT + 99 others); Tue, 9 Nov 2021 05:34:16 -0500 Received: from mail-db8eur05on2093.outbound.protection.outlook.com ([40.107.20.93]:21441 "EHLO EUR05-DB8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S245347AbhKIKeJ (ORCPT ); Tue, 9 Nov 2021 05:34:09 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hRRU4aXMF44nL/AhcNTjjoYd17RRks5uxf41BYezt4PsPmeOZVA/ut1/pcyOa5K+BEQhpuu3zDbjF9jQVTzEYLq2J4K6Bdbyss1TvVNHWWKi5Gb/xmBZIN6DEmBMW5S4mFgoOPN6emFFf+jfT+mEszAyKnzns0co59XI8NOhsEzRCxkuNTtOLpvLhTotl2XW6C9LbSfauzDC6HzkSK62eXyoRkXuBjN3vqDsnNqkNufl85vAqOVUF9GARPnzuHeZI60FvzMV9lh66FYgywMOCemZhk8eXKBnLj/Ckbv2oWDom/Q+iBRbQC+3t6BmXyzpmylc+mhk3wPGZoHWbFnU2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=muwU5Ab53jdkRahd2AT/NSycEQBmewI7F9kt1A9r2ps=; b=i7mQbxaNLI68qqNpRKPuYnzdtHUW9XBFomjznpLptx38EZYujKVlp3dw71ogFTgaPQ94Zv7Vw65SLSIXWwuf6b+scKAgQs2kFrGUr+Ryeznlz9A5+82OPcCTxfm0LI9s6Xpg7zcXgU1LqANhzcL6xj2O6rqplQjPbrZWi+KceC2+TH85y0p4PCToqM18C4SD1Q5jbaKCnPJJ7fBOtK6QJE9qI+FoBS1FLXrA/QxWC8UipsTgg5e5xjKYt2uj2iIwQOFhgXWtYJHXf12yHKXLttICgmMLsyIx74tGV4E0+vzHo197NYfPGU94OiEPQa6okETjjQL/jPCXEhQSo5GFLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=eho.link; dmarc=pass action=none header.from=eho.link; dkim=pass header.d=eho.link; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eho.link; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=muwU5Ab53jdkRahd2AT/NSycEQBmewI7F9kt1A9r2ps=; b=YcIx/A/wYdhacITbeJhgf33PiTppfTddEsKut79gY9sqpCPbJBm94L3dlpK5OR3k0v1mXyFQMUfpTsMxCdlzcCGqfMKJ0p8O0x8+8tGSe3xZE8sXsgfiHOJxqF2aPeBuI5BlPFaDycOeQUH0gli7Q3TPaHtE9f2jmKqJm8qbu4Mt6pzQhdBymBkT8mlf7E+JcvCiqH54CFPyO5AMf/yNmRk4cdS6Oe5HmfZ8FUGSltl0Lf45Q1btTD7Lwl8VNpO1jj8K6DB46r4pN2eqrNKl6JLNFw8QrnnyfGJDM/4MS5/zagYA6c8GYATPwvRyywYY75ywz1uJ9zPFreVEyahp1w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=eho.link; Received: from PAXPR06MB7517.eurprd06.prod.outlook.com (2603:10a6:102:12e::18) by PR3PR06MB6683.eurprd06.prod.outlook.com (2603:10a6:102:6b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13; Tue, 9 Nov 2021 10:31:21 +0000 Received: from PAXPR06MB7517.eurprd06.prod.outlook.com ([fe80::89b8:d738:4829:5a15]) by PAXPR06MB7517.eurprd06.prod.outlook.com ([fe80::89b8:d738:4829:5a15%8]) with mapi id 15.20.4669.016; Tue, 9 Nov 2021 10:31:21 +0000 From: Louis Amas To: Marcin Wojtas , Russell King , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh Cc: Louis Amas , Emmanuel Deloget , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH] net: mvpp2: fix XDP rx queues registering Date: Tue, 9 Nov 2021 11:31:00 +0100 Message-Id: <20211109103101.92382-1-louis.amas@eho.link> X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-ClientProxiedBy: PR1PR01CA0033.eurprd01.prod.exchangelabs.com (2603:10a6:102::46) To PAXPR06MB7517.eurprd06.prod.outlook.com (2603:10a6:102:12e::18) MIME-Version: 1.0 Received: from las.edt.fr.ehocorp.admin (2a10:d780:2:103:e360:3559:c48d:bc79) by PR1PR01CA0033.eurprd01.prod.exchangelabs.com (2603:10a6:102::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13 via Frontend Transport; Tue, 9 Nov 2021 10:31:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 784ca284-34a9-45f7-3bde-08d9a36c125a X-MS-TrafficTypeDiagnostic: PR3PR06MB6683: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vxuuE2FtkZlOAGG13qpdgY6WhdsERSO93lEwVpylUfRGjAION2jlyNCnXkeWTTS5tV0Vw12WSx7/9JcKTqlxehUP1Atek85EM3fPpIA4ymryiPJCpR7wapIGdVIlkg+DvQH6XeDpwX7O8OftkoSUnZda+ZZ9Un401jWurT8r40FP15HqIVn4i2gImvrPjsCXpSuPJs0sV3f1sXm6WlZTKIhyyVpATmGNp9nPw62zW8Y1hb+UtENKtinp/5mwcpsMmqTiIQazS3MMh1tev9dVGjVdnkKFtm8nKzrMyU43G0fUuqyxFVAG88mxNrxMmWo8hbaKT46+tju6iGFQnylT+wrNYtaiQG7b+CI3iDjjxjzVKDvtlsJrzKO6MsD2w4+Nsc0L/wmmt5DroIlstxug3Jjko1Tj1BOOzdEFCUUm8E2SEn0IkZLmHGIm7IZNywiVqjZCQsOeMbGq+rxDhsd516g3WLoplFv4ci79DHlaBHbTFkXMBiSOLCUAmE3U1BKZBz9YQyblFvAiu+iiftluAZVhtu44t4q3mSq/3T9OJAWUAp0WuaKPj31HMCVEjAhzCpB/os5c4YwvNqbozAqUy5Az8qSsyhQqTozJ3B6acjUB90lktKwsQKenH4i3dBZTz+CJzija3933OUc8DmHoer4w+9LbdvORqmviO5i0ylBSYxCc0HUKWMtqR5DPGRsI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR06MB7517.eurprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(39830400003)(136003)(376002)(396003)(366004)(6666004)(7416002)(45080400002)(2906002)(52116002)(110136005)(316002)(6506007)(5660300002)(36756003)(186003)(54906003)(921005)(83380400001)(4326008)(66556008)(2616005)(66946007)(508600001)(86362001)(6512007)(1076003)(8936002)(8676002)(66476007)(6486002)(44832011)(38100700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?mH/WT3uSBbx+2oENSib8M5fha4+SlphkNfB/vkhVbTHhTUsO0JtPxjWvQvf8?= =?us-ascii?Q?IOTnJD4GnXHg0/f38htKlwwXg7VIb8gVjWsHvqefTb2BoQxgcP9f70GDYhtI?= =?us-ascii?Q?CXOzxV4VFaeyrGymr93o6PGyUTMVkBsNlyyT584P1se8BcP8DQ/kjU7OJtXe?= =?us-ascii?Q?OxwVtcEwqyOJ3g40lU4P9Evu7o+X7ASOUHMlqhnktrwVvqVc0lpf+OXb9lcD?= =?us-ascii?Q?VxQ78OdsC+/21oSQ85f2MirGBAI1D17XQ2TryrmAuvXNSpFdXAEIhdUek8WE?= =?us-ascii?Q?1UlrLHXMFoMgS3uHSZKpKnjQZsGfLGkRrk8+GC4xQ1ifOvGvLCM/uU3l5Rr8?= =?us-ascii?Q?e/1ml7NFs2UHnaumbxSk09vaihJN3J6qeaFXKf6eFmjlIFTJMIaZBQ9+jecQ?= =?us-ascii?Q?LJXG9mHL9ny3k0hT9zOJLoPxEr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?= =?us-ascii?Q?vM3a96b5nnpg30HEApI2DAdnrkBjyDXkvENJPy9Nhjvb4tTWGv5qEDWDlQgl?= =?us-ascii?Q?Ub3X43I7Qcn4Otx5FT6fEcnU5FV0X1q5lm5/gs1bhV6PxBRv87KWa1Zozv5S?= =?us-ascii?Q?V9SIRr3dqhSEyQwcKBTbUlukF1kVrnFk/w54dLPl0l0fEfnNpVQ6NV4Xj8o+?= =?us-ascii?Q?7AMWBcqGu3cgBM1I3a1lwo6NV6nZVz5fiPkb8f137Oo34XcYqj/5kiw8OzVC?= =?us-ascii?Q?kYwbiNYWvZL61XAs+0TWgyr9t9iNlocf9hPUPawJsTKwgd9Kt8Q/SVBZl7Q/?= =?us-ascii?Q?K0zjF4bvvG5/rEI4zA5KIv1kI2NrwBakbTSxo1SrMX7NDwJShdNltdXrrFxB?= =?us-ascii?Q?wD0E7O7q9Kp0WDwIOzyIUJNS5Ns=3D?= X-OriginatorOrg: eho.link X-MS-Exchange-CrossTenant-Network-Message-Id: 784ca284-34a9-45f7-3bde-08d9a36c125a X-MS-Exchange-CrossTenant-AuthSource: PAXPR06MB7517.eurprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Nov 2021 10:31:21.0290 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 924d502f-ff7e-4272-8fa5-f920518a3f4c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WASN3yKf3aR0Dfl9JTPGag0DoXDgKF91k2vM/u2fhYaWVT+4U66ER/bdF1jfnaRDCn1PO8HKL/8M+WnPfyTzyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR06MB6683 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The registration of XDP queue information is incorrect because the RX queue= id we use is invalid. When port->id =3D=3D 0 it appears to works as expected yet it's no longer t= he case when port->id !=3D 0. This is due to the fact that the value we use (rxq->id) is not the per-port= queue index which XDP expects -- it's a global index which should not be used in this case. I= nstead we shall use rxq->logic_rxq which is the correct, per-port value. Signed-off-by: Louis Amas Signed-off-by: Emmanuel Deloget --- As we were trying to capture packets using XDP on our mv8040-powered MacchiatoBin, we experienced an issue related to rx queue numbering. Before I get to the problem itself, a bit of setup: * the Macchiato has several ports, all of them handled using the mvpp2 ethernet driver. We are able to reproduce our issue on any device whose port->id !=3D 0 (we used eth2 for our tests). When port->id =3D=3D 0 (for example on eth0) everything works as expected ; * we use xdp-tutorial for our tests ; more specifically, we used the advanced03-AF_XDP tutorial as it provides a simple testbed. We modified the kernel to simplify it: SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx) { int index =3D ctx->rx_queue_index; /* A set entry here means that the correspnding queue_id * has an active AF_XDP socket bound to it. */ if (bpf_map_lookup_elem(&xsks_map, &index)) return bpf_redirect_map(&xsks_map, index, 0); return XDP_PASS; } * we tested kernel 5.10 (out target) and 5.15 (for reference) ; both kernel= s exhibits the same symptoms ; I expect kernel 5.9 (the first linux kernel with XDP support in the mvpp2 driver) to exhibit the same problem. The normal invocation of this program would be: ./af_xdp_user -d ETHDEV We should then capture packets on this interface. When ETHDEV is eth0 (port->id =3D=3D 0) everything works as expcted ; when using ETHDEV =3D=3D = eth2 we fail to capture anything. We investigated the issue and found that XDP rx queues (setup as struct xdp_rxq_info by the mvpp2 driver) for this device were wrong. XDP expected them to be numbered in [0..3] but we found numbers in [32..35]. The reason for this lies in mvpp2_main.c at lines 2962 and 2966 which are of the form (symbolic notation, close to actual code, function mvpp2_rxq_init()): err =3D xdp_rxq_info_reg(&rxq->some_xdp_rxqinfo, port->dev, rxq->id= , 0); The rxq->id value we pass to this function is incorrect - it's a virtual qu= eue id which is computed as (symbolic notation, not actual code): rxq->id =3D port->id * max_rxq_count + queue_id In our case, max_rxq_count =3D=3D 32 and port->id =3D=3D 1 for eth2, meanin= g our rxq->id are in the range [32..35] (for 4 queues). We tried to force the rx queue id on the XDP side by using: ./af_xdp_user -d eth2 -Q 32 But that failed -- as expected, because we should not have more than 4 rx queues. The computing of rxq->id is valid, but the use of rxq->id in this context i= s not. What we really want here is the rx queue id for this port, and this va= lue is stored in rxq->logic_rxq -- as hinted by the code in mvpp2_rxq_init(). Replacing rxq->id by this value in the two xdp_rxq_info_reg() calls fixed t= he issue and allowed us to use XDP on all the Macchiato ethernet ports. drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/= ethernet/marvell/mvpp2/mvpp2_main.c index 587def69a6f7..f0ea377341c6 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -2959,11 +2959,11 @@ static int mvpp2_rxq_init(struct mvpp2_port *port, mvpp2_rxq_status_update(port, rxq->id, 0, rxq->size); if (priv->percpu_pools) { - err =3D xdp_rxq_info_reg(&rxq->xdp_rxq_short, port->dev, rx= q->id, 0); + err =3D xdp_rxq_info_reg(&rxq->xdp_rxq_short, port->dev, rx= q->logic_rxq, 0); if (err < 0) goto err_free_dma; - err =3D xdp_rxq_info_reg(&rxq->xdp_rxq_long, port->dev, rxq= ->id, 0); + err =3D xdp_rxq_info_reg(&rxq->xdp_rxq_long, port->dev, rxq= ->logic_rxq, 0); if (err < 0) goto err_unregister_rxq_short; -- 2.25.1 [eho.link event]