From patchwork Thu Oct 28 10:00:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12589699 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F7B9C433FE for ; Thu, 28 Oct 2021 10:01:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E730610D2 for ; Thu, 28 Oct 2021 10:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230093AbhJ1KDe (ORCPT ); Thu, 28 Oct 2021 06:03:34 -0400 Received: from mail-dm6nam10on2121.outbound.protection.outlook.com ([40.107.93.121]:38624 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229974AbhJ1KDc (ORCPT ); Thu, 28 Oct 2021 06:03:32 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qwtp3yTuo0uIQdj5/GeZzxFelll5Y3LqJD8epjh/BWM++fJsrmZdgrKChGcDgwn03BCbw8MLxjG2TB0WYzk6QNySlpRCAxM3zYZ8n92VJzrjCYzi19J/sQyYnkswNYYK6rZ4phYP3cDqJmfSXuCxHSK3Jb/qqJt/zNxLKZRdrHu2uzHrfOU9oTaM3CUOBElvJPTJo7LHI6PqKZ8ScKT2YwzGiTslm/nR7sUlZMSmXY51Yvm5piYhJE4vK1ubE9J1w8puipGtaWevkQnwyiR0DxG1t4zEfYrvLW2TaY16EqBIcLFwAd+PBMnyFcdSt3/31iMpK9UpgDyB/OdaDXBnmg== 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=yPdouMOJI3zhtxu1653kN/OGmHIbxetZPRC22a1mVi4=; b=dqnqr+mTJdiH/uenUsMJQ2PzgiRT9rRiRqLfwxZaieegIZNfsyqkFe672R/KvELViNXYTRCn/y2mFg/jdHNqC88d9/cQaGuN6KZcUOysw00bE93xUdh0j2npvCrfuXEVsODRwuPf+tK98h2FeDB2fPWXZ2jZkCJdgnl9q5zTGT0APoNtXnz1VO3CXWjPln0av2P9/FZwc27L7vL1t6HRyQBk6Jh6MUzVsd27JYEf/n+BiGVkSe+DM1i3s/8s8JTrTut6pfiitxNUsXVYIGnPbw9IPPfZHEkRq5bM4mmzNe1qgaEuuK7rx9T+LHozHe7mNX3GMWIkP27mfYZNqX/aQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yPdouMOJI3zhtxu1653kN/OGmHIbxetZPRC22a1mVi4=; b=tUtsCEMCmPSv9rbl4KluZqkasOrJ6AdYifGkj09Ct1aVnEoHPgT7ibNqN0uRsWDVL1qFep9/aOGeoXWONYtQxm1B8zitU3O4WTPYjECLtVjfp4OEcGm3NcXZ0Ze4P9ZRzwGMP3Z81JbHeJV6gwGS1h4X/wqaDFQMdVcJQZI0W/o= Authentication-Results: davemloft.net; dkim=none (message not signed) header.d=none;davemloft.net; dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB5520.namprd13.prod.outlook.com (2603:10b6:510:12b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.12; Thu, 28 Oct 2021 10:01:03 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90%9]) with mapi id 15.20.4669.005; Thu, 28 Oct 2021 10:01:03 +0000 From: Simon Horman To: David Miller , Jakub Kicinski Cc: netdev@vger.kernel.org, oss-drivers@corigine.com, Yu Xiao , Yinjun Zhang , Niklas Soderlund , Simon Horman Subject: [PATCH net v2] nfp: bpf: relax prog rejection for mtu check through max_pkt_offset Date: Thu, 28 Oct 2021 12:00:36 +0200 Message-Id: <20211028100036.8477-1-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 X-ClientProxiedBy: AM0PR07CA0024.eurprd07.prod.outlook.com (2603:10a6:208:ac::37) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 Received: from momiji.horms.nl (2001:982:756:703:d63d:7eff:fe99:ac9d) by AM0PR07CA0024.eurprd07.prod.outlook.com (2603:10a6:208:ac::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.4 via Frontend Transport; Thu, 28 Oct 2021 10:01:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37747f0b-d747-452d-3ca8-08d999f9d9e3 X-MS-TrafficTypeDiagnostic: PH0PR13MB5520: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /cbD3j2XX1SSZF5A/cNoZZRgfO3Fq3lOAyC5ilpUYph3qvgbJVoh0Y5JRr9RUtJIN87uawLM6Mxz6qWjLhIH7kz4zBPGe3WsIXxCQ56RD1VDKlbqq5rloPZ9yvzbJ/hdB3YfZ3oH2gknOiwoTdeHDhaswH8W4YADZJoVUyzL4oWXKVtpLUSvpTAET6riRNgyj+mERa68FbywBrWSAypDrV9bBvc5sW2/OJqR5MUTxQrblbCFtduXIMNiXQN8rCAcxz07PFuxIOCdsuZa6BA8b5vP2Mni1amZfDAP4BUV9bGxgJOsJNKPx4H7C/HoV+2Ye4Z79keNQzXqtSDzD5/uZB8RgPC/a7oSiElfCKOdTgxajMkV6O+c4cY29vJRZKX9aIpgqEubNtu3KoluMr3SB9ctwAfQlq/NrqX5qmFjgWcPkhD2Fl79ASCbZESdURvNrZ6PWro9LJnhIfVRh/NovhMAe+g2Gb8rTRJVAERdf7ksYs8n7t1GS8qYfhi3hLAE17zCW7ZlOO0GXOnORuok0/n7QSyhx0LM9b1v1bDCKpTzvOBSsF2EgV6xijt0i4y0pcWWMz6OLEyrCFlgco97RT6MKmvbOv6Gxa/PSdPQRy1PpHExzntmuW0dtdOEUaY1ttMDeVOONNnztPN/u3nwCQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(396003)(346002)(366004)(39830400003)(376002)(66556008)(66476007)(36756003)(54906003)(110136005)(5660300002)(6512007)(2906002)(66946007)(6506007)(186003)(107886003)(6486002)(8936002)(508600001)(6666004)(2616005)(86362001)(44832011)(83380400001)(4326008)(8676002)(1076003)(316002)(38100700002)(52116002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hr5Fh9qsOj1nSljt0lqN9QjGft2c1qupjN47c9WRMq+noLjOQgWZHejq1/Ae3cQaeZ9YwWSXzd3aOV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9KZ108TdRp6CZ2sOI6ZanI3Ci3jsSx+DDw0XaiFUtuXGxkiad/O4B5Fn1XGGwWI/lstLYqHaykg3aaT3gdfjs8yUw88G7KM5zI6/oSBUtitf4GG2EuS+OCVbUt7BS/2JeOACG8m2q2RJ4e7Re7L+wSE0RAi0FZ93lpUNkUFbNt/WKB4cc6xnOreSaUFNdrCNMpOznxLLjHiF1B9dsdJYn3mVtRjdQIv3YOvcXrtSQZfVEPTPDkMCb/s6LnxbYUXYQFCFZ2cMKq69OSBUvLHMqzcVDwoMMLbR0CDbWFtHt7vsXhT6kEqB+WQejgAydOTCezlwT/H+AmPpL8YfRqKDFhsWYwnplb1ukY0q6HrlNQrHosrvyZZAyMzcO1Gjv0qFeVQJrUoO3/Ir84VI2btlU3jMCnV4mi58HrP+qIBhK3f/vPgTuSyyiDSBblCrs+8SWWsNriLjMyoxG556pNKvUXUHRQkT9p4fMQ9WGV32hzTs2iOVGoqeqnminUTgwh2yt7yRvdVRNSDlok9EDAA21UTLovcDbXf8q9jGyAJWgZa/sBJ1WS7q9usdMhQIZQ7tDnvR4QEgdxQ9Ftbk5P7Z9Eg== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37747f0b-d747-452d-3ca8-08d999f9d9e3 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2021 10:01:03.4624 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CaoADtZYXMPFCPUJco1gEPY8dutfZ6XGRK8Q7Ls8MrKlVGzaXYBqM3oDeBva+fo8Gmm2+kwn4Fpl5dZGPkJ77uZBoCnMECTkONuJf1Nq+E0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5520 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Yu Xiao MTU change is refused whenever the value of new MTU is bigger than the max packet bytes that fits in NFP Cluster Target Memory (CTM). However, an eBPF program doesn't always need to access the whole packet data. The maximum direct packet access (DPA) offset has always been caculated by verifier and stored in the max_pkt_offset field of prog aux data. Signed-off-by: Yu Xiao Reviewed-by: Yinjun Zhang Reviewed-by: Niklas Soderlund Signed-off-by: Simon Horman --- drivers/net/ethernet/netronome/nfp/bpf/main.c | 16 +++++++++++----- drivers/net/ethernet/netronome/nfp/bpf/main.h | 2 ++ .../net/ethernet/netronome/nfp/bpf/offload.c | 17 +++++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/bpf/main.c b/drivers/net/ethernet/netronome/nfp/bpf/main.c index 11c83a99b014..f469950c7265 100644 --- a/drivers/net/ethernet/netronome/nfp/bpf/main.c +++ b/drivers/net/ethernet/netronome/nfp/bpf/main.c @@ -182,15 +182,21 @@ static int nfp_bpf_check_mtu(struct nfp_app *app, struct net_device *netdev, int new_mtu) { struct nfp_net *nn = netdev_priv(netdev); - unsigned int max_mtu; + struct nfp_bpf_vnic *bv; + struct bpf_prog *prog; if (~nn->dp.ctrl & NFP_NET_CFG_CTRL_BPF) return 0; - max_mtu = nn_readb(nn, NFP_NET_CFG_BPF_INL_MTU) * 64 - 32; - if (new_mtu > max_mtu) { - nn_info(nn, "BPF offload active, MTU over %u not supported\n", - max_mtu); + if (nn->xdp_hw.prog) { + prog = nn->xdp_hw.prog; + } else { + bv = nn->app_priv; + prog = bv->tc_prog; + } + + if (nfp_bpf_offload_check_mtu(nn, prog, new_mtu)) { + nn_info(nn, "BPF offload active, potential packet access beyond hardware packet boundary"); return -EBUSY; } return 0; diff --git a/drivers/net/ethernet/netronome/nfp/bpf/main.h b/drivers/net/ethernet/netronome/nfp/bpf/main.h index d0e17eebddd9..16841bb750b7 100644 --- a/drivers/net/ethernet/netronome/nfp/bpf/main.h +++ b/drivers/net/ethernet/netronome/nfp/bpf/main.h @@ -560,6 +560,8 @@ bool nfp_is_subprog_start(struct nfp_insn_meta *meta); void nfp_bpf_jit_prepare(struct nfp_prog *nfp_prog); int nfp_bpf_jit(struct nfp_prog *prog); bool nfp_bpf_supported_opcode(u8 code); +bool nfp_bpf_offload_check_mtu(struct nfp_net *nn, struct bpf_prog *prog, + unsigned int mtu); int nfp_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn_idx); diff --git a/drivers/net/ethernet/netronome/nfp/bpf/offload.c b/drivers/net/ethernet/netronome/nfp/bpf/offload.c index 53851853562c..9d97cd281f18 100644 --- a/drivers/net/ethernet/netronome/nfp/bpf/offload.c +++ b/drivers/net/ethernet/netronome/nfp/bpf/offload.c @@ -481,19 +481,28 @@ int nfp_bpf_event_output(struct nfp_app_bpf *bpf, const void *data, return 0; } +bool nfp_bpf_offload_check_mtu(struct nfp_net *nn, struct bpf_prog *prog, + unsigned int mtu) +{ + unsigned int fw_mtu, pkt_off; + + fw_mtu = nn_readb(nn, NFP_NET_CFG_BPF_INL_MTU) * 64 - 32; + pkt_off = min(prog->aux->max_pkt_offset, mtu); + + return fw_mtu < pkt_off; +} + static int nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog, struct netlink_ext_ack *extack) { struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv; - unsigned int fw_mtu, pkt_off, max_stack, max_prog_len; + unsigned int max_stack, max_prog_len; dma_addr_t dma_addr; void *img; int err; - fw_mtu = nn_readb(nn, NFP_NET_CFG_BPF_INL_MTU) * 64 - 32; - pkt_off = min(prog->aux->max_pkt_offset, nn->dp.netdev->mtu); - if (fw_mtu < pkt_off) { + if (nfp_bpf_offload_check_mtu(nn, prog, nn->dp.netdev->mtu)) { NL_SET_ERR_MSG_MOD(extack, "BPF offload not supported with potential packet access beyond HW packet split boundary"); return -EOPNOTSUPP; }