From patchwork Fri Dec 4 10:28:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Majtyka X-Patchwork-Id: 11951449 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F40BC4361B for ; Fri, 4 Dec 2020 10:30:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1CB9E22AAE for ; Fri, 4 Dec 2020 10:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729736AbgLDKar (ORCPT ); Fri, 4 Dec 2020 05:30:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbgLDKaq (ORCPT ); Fri, 4 Dec 2020 05:30:46 -0500 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18023C061A4F; Fri, 4 Dec 2020 02:30:01 -0800 (PST) Received: by mail-lj1-x241.google.com with SMTP id r18so6044576ljc.2; Fri, 04 Dec 2020 02:30:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ntPyan2LMBW4YRlwZpm6QDwFqX2hAHbAcyK6DVkpbtY=; b=VImxvOU5OT46FYPftU8rCcEoZ7SnblVXIkJJEu1KiCOo+BSHuF43pD94Ym23tDk7B6 6EvZ770shWSdVlfyEH40jcaP9pQSThrGMATnknJ6o7bkThs05uYyYMRN/6ssGfXHVGlO KOqawCtcalwVw5AKImOtBdFgNWMvqpaZvBgF6gygfl/krQ/JQPt8GEw7e1JrE7Ma/Evi VjvKGazy1JAZ7O295nxLdiPkghLLPnSnJ6W8NZApofndjDHJ1wMOVyJSWEahg7SOShrf A50Jg3rzK/ZL7xxCgUWJv7CQ3OnIXLa25iBru+dGPgfac5KcJPIEqcTH0RJqMN0R1gTD OllA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ntPyan2LMBW4YRlwZpm6QDwFqX2hAHbAcyK6DVkpbtY=; b=Jvopl8lYCh5AFw2r5ppBPnjBXJSmmBwyhtJxiwYj4tb63BeDQt1OJCdkid+3CHNWVQ FnNUrXakaQGnUe+STl8x3n2wQxMHIA2RXHjpeyPCQb5EsdM6xcpfsg0m7sMCYkhe8bUo s/oMZMNJCT6A8s4dfrPSr/GM2e6hPYgZ3Wxe7Z2rlCUcfTS8MfzZqxZbn1+c74NT8rP6 mZnBQTARvcgG+pfr0FpCZ6b6y4tyzuGTo/184BWLwzNNbR3mdmqaM/xiyBf2csFFgbd0 1YoXsNVRDmy5diwGerqLZF3c8LAmJfxsRv26QvNHHa0b867Fy0T8sUjvIm7gx2w3EcSl x3SQ== X-Gm-Message-State: AOAM530zh75D3MNj7TOlcLwj1dpmiDq0U6xntPvbkRifXXRHrsapnjhC 8VspzVjVm1yalbZJAp0R667F7Rh6O1o5lA== X-Google-Smtp-Source: ABdhPJwn1SV8gLhMfD+I0aFoQMed0TIb8GcL96twWjvp59TCO2/hyQvdWh2lcNc0uydjtZ2GPtyzKA== X-Received: by 2002:a2e:b0e6:: with SMTP id h6mr3080466ljl.196.1607077799596; Fri, 04 Dec 2020 02:29:59 -0800 (PST) Received: from localhost.localdomain (87-205-71-93.adsl.inetia.pl. [87.205.71.93]) by smtp.gmail.com with ESMTPSA id d9sm62738lfj.228.2020.12.04.02.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 02:29:58 -0800 (PST) From: alardam@gmail.com X-Google-Original-From: marekx.majtyka@intel.com To: magnus.karlsson@intel.com, bjorn.topel@intel.com, andrii.nakryiko@gmail.com, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, davem@davemloft.net, john.fastabend@gmail.com, hawk@kernel.org, toke@redhat.com Cc: maciej.fijalkowski@intel.com, jonathan.lemon@gmail.com, bpf@vger.kernel.org, jeffrey.t.kirsher@intel.com, maciejromanfijalkowski@gmail.com, intel-wired-lan@lists.osuosl.org, Marek Majtyka Subject: [PATCH v2 bpf 1/5] net: ethtool: add xdp properties flag set Date: Fri, 4 Dec 2020 11:28:57 +0100 Message-Id: <20201204102901.109709-2-marekx.majtyka@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201204102901.109709-1-marekx.majtyka@intel.com> References: <20201204102901.109709-1-marekx.majtyka@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Marek Majtyka Implement support for checking what kind of xdp functionality a netdev supports. Previously, there was no way to do this other than to try to create an AF_XDP socket on the interface or load an XDP program and see if it worked. This commit changes this by adding a new variable which describes all xdp supported functions on pretty detailed level: - aborted - drop - pass - tx - redirect - zero copy - hardware offload. Zerocopy mode requires that redirect xdp operation is implemented in a driver and the driver supports also zero copy mode. Full mode requires that all xdp operation are implemented in the driver. Basic mode is just full mode without redirect operation. Initially, these new flags are disabled for all drivers by default. Signed-off-by: Marek Majtyka --- .../networking/netdev-xdp-properties.rst | 42 ++++++++ include/linux/netdevice.h | 2 + include/linux/xdp_properties.h | 53 +++++++++++ include/net/xdp.h | 95 +++++++++++++++++++ include/net/xdp_sock_drv.h | 10 ++ include/uapi/linux/ethtool.h | 1 + include/uapi/linux/xdp_properties.h | 32 +++++++ net/ethtool/common.c | 11 +++ net/ethtool/common.h | 4 + net/ethtool/strset.c | 5 + 10 files changed, 255 insertions(+) create mode 100644 Documentation/networking/netdev-xdp-properties.rst create mode 100644 include/linux/xdp_properties.h create mode 100644 include/uapi/linux/xdp_properties.h diff --git a/Documentation/networking/netdev-xdp-properties.rst b/Documentation/networking/netdev-xdp-properties.rst new file mode 100644 index 000000000000..4a434a1c512b --- /dev/null +++ b/Documentation/networking/netdev-xdp-properties.rst @@ -0,0 +1,42 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================== +Netdev XDP properties +===================== + + * XDP PROPERTIES FLAGS + +Following netdev xdp properties flags can be retrieve over netlink ethtool +interface the same way as netdev feature flags. These properties flags are +read only and cannot be change in the runtime. + + +* XDP_ABORTED + +This property informs if netdev supports xdp aborted action. + +* XDP_DROP + +This property informs if netdev supports xdp drop action. + +* XDP_PASS + +This property informs if netdev supports xdp pass action. + +* XDP_TX + +This property informs if netdev supports xdp tx action. + +* XDP_REDIRECT + +This property informs if netdev supports xdp redirect action. +It assumes the all beforehand mentioned flags are enabled. + +* XDP_ZEROCOPY + +This property informs if netdev driver supports xdp zero copy. +It assumes the all beforehand mentioned flags are enabled. + +* XDP_HW_OFFLOAD + +This property informs if netdev driver supports xdp hw oflloading. diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 52d1cc2bd8a7..2544c7f0e1b7 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -43,6 +43,7 @@ #include #include +#include #include #include #include @@ -2171,6 +2172,7 @@ struct net_device { /* protected by rtnl_lock */ struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE]; + xdp_properties_t xdp_properties; }; #define to_net_dev(d) container_of(d, struct net_device, dev) diff --git a/include/linux/xdp_properties.h b/include/linux/xdp_properties.h new file mode 100644 index 000000000000..c72c9bcc50de --- /dev/null +++ b/include/linux/xdp_properties.h @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Network device xdp properties. + */ +#ifndef _LINUX_XDP_PROPERTIES_H +#define _LINUX_XDP_PROPERTIES_H + +#include +#include +#include + +typedef u64 xdp_properties_t; + +enum { + XDP_F_ABORTED_BIT, + XDP_F_DROP_BIT, + XDP_F_PASS_BIT, + XDP_F_TX_BIT, + XDP_F_REDIRECT_BIT, + XDP_F_ZEROCOPY_BIT, + XDP_F_HW_OFFLOAD_BIT, + + /* + * Add your fresh new property above and remember to update + * xdp_properties_strings [] in net/core/ethtool.c and maybe + * some xdp_properties mask #defines below. Please also describe it + * in Documentation/networking/xdp_properties.rst. + */ + + /**/XDP_PROPERTIES_COUNT +}; + +#define __XDP_F_BIT(bit) ((xdp_properties_t)1 << (bit)) +#define __XDP_F(name) __XDP_F_BIT(XDP_F_##name##_BIT) + +#define XDP_F_ABORTED __XDP_F(ABORTED) +#define XDP_F_DROP __XDP_F(DROP) +#define XDP_F_PASS __XDP_F(PASS) +#define XDP_F_TX __XDP_F(TX) +#define XDP_F_REDIRECT __XDP_F(REDIRECT) +#define XDP_F_ZEROCOPY __XDP_F(ZEROCOPY) +#define XDP_F_HW_OFFLOAD __XDP_F(HW_OFFLOAD) + +#define XDP_F_BASIC (XDP_F_ABORTED | \ + XDP_F_DROP | \ + XDP_F_PASS | \ + XDP_F_TX) + +#define XDP_F_FULL (XDP_F_BASIC | XDP_F_REDIRECT) + +#define XDP_F_FULL_ZC (XDP_F_FULL | XDP_F_ZEROCOPY) + +#endif /* _LINUX_XDP_PROPERTIES_H */ diff --git a/include/net/xdp.h b/include/net/xdp.h index 700ad5db7f5d..a9fabc1282cf 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -7,6 +7,7 @@ #define __LINUX_NET_XDP_H__ #include /* skb_shared_info */ +#include /** * DOC: XDP RX-queue information @@ -255,6 +256,100 @@ struct xdp_attachment_info { u32 flags; }; +#if defined(CONFIG_NET) && defined(CONFIG_BPF_SYSCALL) + +static __always_inline void +xdp_set_aborted_property(xdp_properties_t *properties) +{ + *properties |= XDP_F_ABORTED; +} + +static __always_inline void +xdp_set_pass_property(xdp_properties_t *properties) +{ + *properties |= XDP_F_PASS; +} + +static __always_inline void +xdp_set_drop_property(xdp_properties_t *properties) +{ + *properties |= XDP_F_DROP; +} + +static __always_inline void +xdp_set_tx_property(xdp_properties_t *properties) +{ + *properties |= XDP_F_TX; +} + +static __always_inline void +xdp_set_redirect_property(xdp_properties_t *properties) +{ + *properties |= XDP_F_REDIRECT; +} + +static __always_inline void +xdp_set_hw_offload_property(xdp_properties_t *properties) +{ + *properties |= XDP_F_HW_OFFLOAD; +} + +static __always_inline void +xdp_set_basic_properties(xdp_properties_t *properties) +{ + *properties |= XDP_F_BASIC; +} + +static __always_inline void +xdp_set_full_properties(xdp_properties_t *properties) +{ + *properties |= XDP_F_FULL; +} + +#else + +static __always_inline void +xdp_set_aborted_property(xdp_properties_t *properties) +{ +} + +static __always_inline void +xdp_set_pass_property(xdp_properties_t *properties) +{ +} + +static __always_inline void +xdp_set_drop_property(xdp_properties_t *properties) +{ +} + +static __always_inline void +xdp_set_tx_property(xdp_properties_t *properties) +{ +} + +static __always_inline void +xdp_set_redirect_property(xdp_properties_t *properties) +{ +} + +static __always_inline void +xdp_set_hw_offload_property(xdp_properties_t *properties) +{ +} + +static __always_inline void +xdp_set_basic_properties(xdp_properties_t *properties) +{ +} + +static __always_inline void +xdp_set_full_properties(xdp_properties_t *properties) +{ +} + +#endif + struct netdev_bpf; bool xdp_attachment_flags_ok(struct xdp_attachment_info *info, struct netdev_bpf *bpf); diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h index 4e295541e396..48a3b6d165c7 100644 --- a/include/net/xdp_sock_drv.h +++ b/include/net/xdp_sock_drv.h @@ -8,6 +8,7 @@ #include #include +#include #ifdef CONFIG_XDP_SOCKETS @@ -117,6 +118,11 @@ static inline void xsk_buff_raw_dma_sync_for_device(struct xsk_buff_pool *pool, xp_dma_sync_for_device(pool, dma, size); } +static inline void xsk_set_zc_property(xdp_properties_t *properties) +{ + *properties |= XDP_F_ZEROCOPY; +} + #else static inline void xsk_tx_completed(struct xsk_buff_pool *pool, u32 nb_entries) @@ -242,6 +248,10 @@ static inline void xsk_buff_raw_dma_sync_for_device(struct xsk_buff_pool *pool, { } +static inline void xsk_set_zc_property(xdp_properties_t *properties) +{ +} + #endif /* CONFIG_XDP_SOCKETS */ #endif /* _LINUX_XDP_SOCK_DRV_H */ diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index 9ca87bc73c44..dfcb0e2c98b2 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -688,6 +688,7 @@ enum ethtool_stringset { ETH_SS_TS_TX_TYPES, ETH_SS_TS_RX_FILTERS, ETH_SS_UDP_TUNNEL_TYPES, + ETH_SS_XDP_PROPERTIES, /* add new constants above here */ ETH_SS_COUNT diff --git a/include/uapi/linux/xdp_properties.h b/include/uapi/linux/xdp_properties.h new file mode 100644 index 000000000000..e85be03eb707 --- /dev/null +++ b/include/uapi/linux/xdp_properties.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +/* + * Copyright (c) 2020 Intel + */ + +#ifndef __UAPI_LINUX_XDP_PROPERTIES__ +#define __UAPI_LINUX_XDP_PROPERTIES__ + +/* ETH_GSTRING_LEN define is needed. */ +#include + +#define XDP_PROPERTIES_ABORTED_STR "xdp-aborted" +#define XDP_PROPERTIES_DROP_STR "xdp-drop" +#define XDP_PROPERTIES_PASS_STR "xdp-pass" +#define XDP_PROPERTIES_TX_STR "xdp-tx" +#define XDP_PROPERTIES_REDIRECT_STR "xdp-redirect" +#define XDP_PROPERTIES_ZEROCOPY_STR "xdp-zerocopy" +#define XDP_PROPERTIES_HW_OFFLOAD_STR "xdp-hw-offload" + +#define DECLARE_XDP_PROPERTIES_TABLE(name) \ + const char name[][ETH_GSTRING_LEN] = { \ + XDP_PROPERTIES_ABORTED_STR, \ + XDP_PROPERTIES_DROP_STR, \ + XDP_PROPERTIES_PASS_STR, \ + XDP_PROPERTIES_TX_STR, \ + XDP_PROPERTIES_REDIRECT_STR, \ + XDP_PROPERTIES_ZEROCOPY_STR, \ + XDP_PROPERTIES_HW_OFFLOAD_STR, \ + } + +#endif /* __UAPI_LINUX_XDP_PROPERTIES__ */ diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 24036e3055a1..8f15f96b8922 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "common.h" @@ -283,6 +284,16 @@ const char udp_tunnel_type_names[][ETH_GSTRING_LEN] = { static_assert(ARRAY_SIZE(udp_tunnel_type_names) == __ETHTOOL_UDP_TUNNEL_TYPE_CNT); +const char xdp_properties_strings[XDP_PROPERTIES_COUNT][ETH_GSTRING_LEN] = { + [XDP_F_ABORTED_BIT] = XDP_PROPERTIES_ABORTED_STR, + [XDP_F_DROP_BIT] = XDP_PROPERTIES_DROP_STR, + [XDP_F_PASS_BIT] = XDP_PROPERTIES_PASS_STR, + [XDP_F_TX_BIT] = XDP_PROPERTIES_TX_STR, + [XDP_F_REDIRECT_BIT] = XDP_PROPERTIES_REDIRECT_STR, + [XDP_F_ZEROCOPY_BIT] = XDP_PROPERTIES_ZEROCOPY_STR, + [XDP_F_HW_OFFLOAD_BIT] = XDP_PROPERTIES_HW_OFFLOAD_STR, +}; + /* return false if legacy contained non-0 deprecated fields * maxtxpkt/maxrxpkt. rest of ksettings always updated */ diff --git a/net/ethtool/common.h b/net/ethtool/common.h index 3d9251c95a8b..85a35f8781eb 100644 --- a/net/ethtool/common.h +++ b/net/ethtool/common.h @@ -5,8 +5,10 @@ #include #include +#include #define ETHTOOL_DEV_FEATURE_WORDS DIV_ROUND_UP(NETDEV_FEATURE_COUNT, 32) +#define ETHTOOL_XDP_PROPERTIES_WORDS DIV_ROUND_UP(XDP_PROPERTIES_COUNT, 32) /* compose link mode index from speed, type and duplex */ #define ETHTOOL_LINK_MODE(speed, type, duplex) \ @@ -22,6 +24,8 @@ extern const char tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN]; extern const char phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN]; +extern const char +xdp_properties_strings[XDP_PROPERTIES_COUNT][ETH_GSTRING_LEN]; extern const char link_mode_names[][ETH_GSTRING_LEN]; extern const char netif_msg_class_names[][ETH_GSTRING_LEN]; extern const char wol_mode_names[][ETH_GSTRING_LEN]; diff --git a/net/ethtool/strset.c b/net/ethtool/strset.c index 0baad0ce1832..684e751b31a9 100644 --- a/net/ethtool/strset.c +++ b/net/ethtool/strset.c @@ -80,6 +80,11 @@ static const struct strset_info info_template[] = { .count = __ETHTOOL_UDP_TUNNEL_TYPE_CNT, .strings = udp_tunnel_type_names, }, + [ETH_SS_XDP_PROPERTIES] = { + .per_dev = false, + .count = ARRAY_SIZE(xdp_properties_strings), + .strings = xdp_properties_strings, + }, }; struct strset_req_info { From patchwork Fri Dec 4 10:28:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Majtyka X-Patchwork-Id: 11951445 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2024EC4361A for ; Fri, 4 Dec 2020 10:30:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B755922AAA for ; Fri, 4 Dec 2020 10:30:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729625AbgLDKao (ORCPT ); Fri, 4 Dec 2020 05:30:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbgLDKan (ORCPT ); Fri, 4 Dec 2020 05:30:43 -0500 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12758C061A51; Fri, 4 Dec 2020 02:30:03 -0800 (PST) Received: by mail-lf1-x12c.google.com with SMTP id s27so6974217lfp.5; Fri, 04 Dec 2020 02:30:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1aFRlI4fXaEVeSmIkxNMWXJSVPFP7SIfGNqf3YjlK88=; b=odb/3GuHRfPSJGUYct9gfeG6YBCEcxqSDfKh1Eicm7rho/UZGfsh4QeqB+EJfguW6Y R+3QVPTYwayKVu0so9T336C9PBBDl+PWdIj3Prfh5LGUZqcFe+JVE25sX0ZSAz/3lbSr C+r8NXCUO4yLk5D27hWmHZgjpnxIEb1L/W/rvwll9TqsnAT+ZK9BT40493trBRG5nJBx 7a0zQHFaPWASFMX6xQALTWAP1A2QYdUd46xpekTFITs4httbaHgX9W7Y9vdfSq8HGE9B di7GYRkYESSo14K1WMecU+Icniv8NPoP8TvpWTxD2yVUEJ8r/CbTT/Yxx2w6svjuME9l KmVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1aFRlI4fXaEVeSmIkxNMWXJSVPFP7SIfGNqf3YjlK88=; b=R2voED/+CtYgqPJXK5HYCrHEKe3iuIVClCJ55ipENbIeu9efbZoaTWtJ8UCufKRk4E ctOoC7OG6L89bS1tUbKfRP1G1mW1cMpJf2YR8t0p/SwT03J4sxmkvExKrKU50w2eWxj0 ty+mb1MYOEpwnjRiyRvdnre4dEvdZ2rhadq2o99sowXrA3/dnlXfq2npB4/AlRuzG3/W e4/B1hULgJf4+jyczWnukVX/Zfzgn1Vl5t9ygPNGRe8BtxCzBw04x7sqzvHbDPy4Yg92 7Pp+s1QQWyW2ovH01IZcBQbc+WTG4dA8fCZeffHxxh/9jhRykQ+pkcvWocHBh8UfcGZv NqpA== X-Gm-Message-State: AOAM533T3vRkL/0fYJ+Sbixew/nEe+i+BAVsawaYZkrVB1RLcBDi7BB6 6ur//um0CFPXOfJDt+DO/mg= X-Google-Smtp-Source: ABdhPJyQfEehQIdMVx05bZCQHV2oYzq3h7hwmh3DbMe5tSIo62sTBok+wgnK6kFhQcQfRzXAVOM5Gw== X-Received: by 2002:a19:5205:: with SMTP id m5mr2902610lfb.310.1607077801535; Fri, 04 Dec 2020 02:30:01 -0800 (PST) Received: from localhost.localdomain (87-205-71-93.adsl.inetia.pl. [87.205.71.93]) by smtp.gmail.com with ESMTPSA id d9sm62738lfj.228.2020.12.04.02.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 02:30:00 -0800 (PST) From: alardam@gmail.com X-Google-Original-From: marekx.majtyka@intel.com To: magnus.karlsson@intel.com, bjorn.topel@intel.com, andrii.nakryiko@gmail.com, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, davem@davemloft.net, john.fastabend@gmail.com, hawk@kernel.org, toke@redhat.com Cc: maciej.fijalkowski@intel.com, jonathan.lemon@gmail.com, bpf@vger.kernel.org, jeffrey.t.kirsher@intel.com, maciejromanfijalkowski@gmail.com, intel-wired-lan@lists.osuosl.org, Marek Majtyka Subject: [PATCH v2 bpf 2/5] drivers/net: turn XDP properties on Date: Fri, 4 Dec 2020 11:28:58 +0100 Message-Id: <20201204102901.109709-3-marekx.majtyka@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201204102901.109709-1-marekx.majtyka@intel.com> References: <20201204102901.109709-1-marekx.majtyka@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Marek Majtyka Turn 'hw-offload' property flag on for: - netronome. Turn 'native' and 'zerocopy' properties flags on for: - i40e - ice - ixgbe - mlx5. Turn 'native' properties flags on for: - igb - tun - veth - dpaa2 - mvneta - mvpp2 - qede - sfc - netsec - cpsw - xen - virtio_net. Turn 'basic' (tx, pass, aborted and drop) properties flags on for: - netronome - ena - mlx4. Signed-off-by: Marek Majtyka Reported-by: kernel test robot --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 2 ++ drivers/net/ethernet/broadcom/bnxt/bnxt.c | 1 + drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 1 + drivers/net/ethernet/intel/i40e/i40e_main.c | 3 +++ drivers/net/ethernet/intel/ice/ice_main.c | 4 ++++ drivers/net/ethernet/intel/igb/igb_main.c | 2 ++ drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 3 +++ drivers/net/ethernet/marvell/mvneta.c | 3 +++ drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 3 +++ drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 2 ++ drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 3 +++ drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 5 +++++ drivers/net/ethernet/qlogic/qede/qede_main.c | 2 ++ drivers/net/ethernet/sfc/efx.c | 2 ++ drivers/net/ethernet/socionext/netsec.c | 2 ++ drivers/net/ethernet/ti/cpsw.c | 3 +++ drivers/net/ethernet/ti/cpsw_new.c | 2 ++ drivers/net/tun.c | 4 ++++ drivers/net/veth.c | 2 ++ drivers/net/virtio_net.c | 2 ++ drivers/net/xen-netfront.c | 2 ++ 21 files changed, 53 insertions(+) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 6ad59f0068f6..a0a7558d733b 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -4290,6 +4290,8 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->priv_flags |= IFF_UNICAST_FLT; + xdp_set_basic_properties(&netdev->xdp_properties); + u64_stats_init(&adapter->syncp); rc = ena_enable_msix_and_set_admin_interrupts(adapter); diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 725d929eddb1..5a153102d73b 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -12604,6 +12604,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->features |= dev->hw_features | NETIF_F_HIGHDMA; if (dev->features & NETIF_F_GRO_HW) dev->features &= ~NETIF_F_LRO; + xdp_set_full_properties(&dev->xdp_properties); dev->priv_flags |= IFF_UNICAST_FLT; #ifdef CONFIG_BNXT_SRIOV diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c index 40953980e846..abdd4ceed6f2 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -4014,6 +4014,7 @@ static int dpaa2_eth_netdev_init(struct net_device *net_dev) NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_LLTX | NETIF_F_HW_TC; net_dev->hw_features = net_dev->features; + xdp_set_full_properties(&net_dev->xdp_properties); return 0; } diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 4f8a2154b93f..6e5dae9b871f 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -12875,6 +12875,9 @@ static int i40e_config_netdev(struct i40e_vsi *vsi) netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; + xdp_set_full_properties(&netdev->xdp_properties); + xsk_set_zc_property(&netdev->xdp_properties); + if (vsi->type == I40E_VSI_MAIN) { SET_NETDEV_DEV(netdev, &pf->pdev->dev); ether_addr_copy(mac_addr, hw->mac.perm_addr); diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index 2dea4d0e9415..638942df136b 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -13,6 +13,7 @@ #include "ice_dcb_lib.h" #include "ice_dcb_nl.h" #include "ice_devlink.h" +#include #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver" static const char ice_driver_string[] = DRV_SUMMARY; @@ -2979,6 +2980,9 @@ static int ice_cfg_netdev(struct ice_vsi *vsi) ice_set_netdev_features(netdev); + xdp_set_full_properties(&netdev->xdp_properties); + xsk_set_zc_properties(&netdev->xdp_properties); + ice_set_ops(netdev); if (vsi->type == ICE_VSI_PF) { diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index 6a4ef4934fcf..ed7e0a2efe1a 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -3297,6 +3297,8 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->priv_flags |= IFF_UNICAST_FLT; + xdp_set_full_properties(&netdev->xdp_properties); + /* MTU range: 68 - 9216 */ netdev->min_mtu = ETH_MIN_MTU; netdev->max_mtu = MAX_STD_JUMBO_FRAME_SIZE; diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c index 50e6b8b6ba7b..6fa98bf48e21 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c @@ -10844,6 +10844,9 @@ static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->priv_flags |= IFF_UNICAST_FLT; netdev->priv_flags |= IFF_SUPP_NOFCS; + xdp_set_full_properties(&netdev->xdp_properties); + xsk_set_zc_property(&netdev->xdp_properties); + /* MTU range: 68 - 9710 */ netdev->min_mtu = ETH_MIN_MTU; netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN); diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c index ba6dcb19bb1d..6431772b4706 100644 --- a/drivers/net/ethernet/marvell/mvneta.c +++ b/drivers/net/ethernet/marvell/mvneta.c @@ -5262,6 +5262,9 @@ static int mvneta_probe(struct platform_device *pdev) NETIF_F_TSO | NETIF_F_RXCSUM; dev->hw_features |= dev->features; dev->vlan_features |= dev->features; + + xdp_set_full_properties(&dev->xdp_properties); + dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; dev->gso_max_segs = MVNETA_MAX_TSO_SEGS; diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index 5504cbc24970..4d6a86b40403 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -6475,6 +6475,9 @@ static int mvpp2_port_probe(struct platform_device *pdev, mvpp2_set_hw_csum(port, port->pool_long->id); dev->vlan_features |= features; + + xdp_set_full_properties(&dev->xdp_properties); + dev->gso_max_segs = MVPP2_MAX_TSO_SEGS; dev->priv_flags |= IFF_UNICAST_FLT; diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c index 106513f772c3..3b81c98b85a0 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c @@ -3395,6 +3395,8 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, priv->rss_hash_fn = ETH_RSS_HASH_TOP; } + xdp_set_basic_properties(&dev->xdp_properties); + /* MTU range: 68 - hw-specific max */ dev->min_mtu = ETH_MIN_MTU; dev->max_mtu = priv->max_mtu; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 427fc376fe1a..0f6055528a32 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -4981,6 +4981,9 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev) netdev->features |= NETIF_F_HIGHDMA; netdev->features |= NETIF_F_HW_VLAN_STAG_FILTER; + xdp_set_full_properties(&netdev->xdp_properties); + xsk_set_zc_property(&netdev->xdp_properties); + netdev->priv_flags |= IFF_UNICAST_FLT; mlx5e_set_netdev_dev_addr(netdev); diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index b4acf2f41e84..37280465326c 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -4099,8 +4099,13 @@ int nfp_net_init(struct nfp_net *nn) return err; if (nn->dp.netdev) { + struct net_device *dev = nn->dp.netdev; + nfp_net_netdev_init(nn); + xdp_set_hw_offload_property(&dev->xdp_properties); + xdp_set_basic_properties(&dev->xdp_properties); + err = nfp_ccm_mbox_init(nn); if (err) return err; diff --git a/drivers/net/ethernet/qlogic/qede/qede_main.c b/drivers/net/ethernet/qlogic/qede/qede_main.c index 9cf960a6d007..fc11fae05857 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_main.c +++ b/drivers/net/ethernet/qlogic/qede/qede_main.c @@ -842,6 +842,8 @@ static void qede_init_ndev(struct qede_dev *edev) ndev->hw_features = hw_features; + xdp_set_full_properties(&ndev->xdp_properties); + /* MTU range: 46 - 9600 */ ndev->min_mtu = ETH_ZLEN - ETH_HLEN; ndev->max_mtu = QEDE_MAX_JUMBO_PACKET_SIZE; diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c index 718308076341..bbf6d3255040 100644 --- a/drivers/net/ethernet/sfc/efx.c +++ b/drivers/net/ethernet/sfc/efx.c @@ -1111,6 +1111,8 @@ static int efx_pci_probe(struct pci_dev *pci_dev, netif_info(efx, probe, efx->net_dev, "Solarflare NIC detected\n"); + xdp_set_full_properties(&efx->net_dev->xdp_properties); + if (!efx->type->is_vf) efx_probe_vpd_strings(efx); diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet/socionext/netsec.c index 27d3c9d9210e..df1f952f678a 100644 --- a/drivers/net/ethernet/socionext/netsec.c +++ b/drivers/net/ethernet/socionext/netsec.c @@ -2100,6 +2100,8 @@ static int netsec_probe(struct platform_device *pdev) NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; ndev->hw_features = ndev->features; + xdp_set_full_properties(&ndev->xdp_properties); + priv->rx_cksum_offload_flag = true; ret = netsec_register_mdio(priv, phy_addr); diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 9fd1f77190ad..02fd7275e477 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -1476,6 +1476,8 @@ static int cpsw_probe_dual_emac(struct cpsw_priv *priv) cpsw->slaves[1].ndev = ndev; ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_RX; + xdp_set_full_properties(&ndev->xdp_properties); + ndev->netdev_ops = &cpsw_netdev_ops; ndev->ethtool_ops = &cpsw_ethtool_ops; @@ -1654,6 +1656,7 @@ static int cpsw_probe(struct platform_device *pdev) cpsw->slaves[0].ndev = ndev; ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_RX; + xdp_set_full_properties(&ndev->xdp_properties); ndev->netdev_ops = &cpsw_netdev_ops; ndev->ethtool_ops = &cpsw_ethtool_ops; diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c index f779d2e1b5c5..22bf1b0d4d48 100644 --- a/drivers/net/ethernet/ti/cpsw_new.c +++ b/drivers/net/ethernet/ti/cpsw_new.c @@ -1416,6 +1416,8 @@ static int cpsw_create_ports(struct cpsw_common *cpsw) ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_NETNS_LOCAL; + xdp_set_full_properties(&ndev->xdp_properties); + ndev->netdev_ops = &cpsw_netdev_ops; ndev->ethtool_ops = &cpsw_ethtool_ops; SET_NETDEV_DEV(ndev, dev); diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 8867d39db6ac..6d16e878b1bd 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -2721,6 +2721,10 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) ~(NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX); + /* Currently tap does not support XDP, only tun does. */ + if (tun->flags == IFF_TUN) + xdp_set_full_properties(&dev->xdp_properties); + tun->flags = (tun->flags & ~TUN_FEATURES) | (ifr->ifr_flags & TUN_FEATURES); diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 9bd37c7151f8..5a48823a0377 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1270,6 +1270,8 @@ static void veth_setup(struct net_device *dev) dev->hw_features = VETH_FEATURES; dev->hw_enc_features = VETH_FEATURES; dev->mpls_features = NETIF_F_HW_CSUM | NETIF_F_GSO_SOFTWARE; + + xdp_set_full_properties(&dev->xdp_properties); } /* diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 052975ea0af4..f05a45942d37 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3018,6 +3018,8 @@ static int virtnet_probe(struct virtio_device *vdev) dev->vlan_features = dev->features; + xdp_set_full_properties(&dev->xdp_properties); + /* MTU range: 68 - 65535 */ dev->min_mtu = MIN_MTU; dev->max_mtu = MAX_MTU; diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index b01848ef4649..e2c3c668abae 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -1556,6 +1556,8 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev) */ netdev->features |= netdev->hw_features; + xdp_set_full_properties(&netdev->xdp_properties); + netdev->ethtool_ops = &xennet_ethtool_ops; netdev->min_mtu = ETH_MIN_MTU; netdev->max_mtu = XEN_NETIF_MAX_TX_SIZE; From patchwork Fri Dec 4 10:28:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Majtyka X-Patchwork-Id: 11951451 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03B6BC433FE for ; Fri, 4 Dec 2020 10:30:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA8B422AAE for ; Fri, 4 Dec 2020 10:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729854AbgLDKav (ORCPT ); Fri, 4 Dec 2020 05:30:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729787AbgLDKau (ORCPT ); Fri, 4 Dec 2020 05:30:50 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8656C061A52; Fri, 4 Dec 2020 02:30:04 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id u18so6946979lfd.9; Fri, 04 Dec 2020 02:30:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YRI79nwoijzX/iWn8fymlgJV8Mx6+kl0OyDyYdcy5/8=; b=sTXJuBWQ02jH1eABWxylyUBObW+swfrv1FjDsO7D2TYQVHzjtUJsoG8/syUsGhDzIO ZKbCwtyMnJFuUo1KVhcbL/1DUfPvwFHzv+WZ4enQGFb2GtJWsXqI8+0nTVywMNbUba19 st7aIDI9Og3jGGBhc5XcrDSb8U7SP4tcF42gvL+YeJJlVZGFzGkuiv9iGVhB/4Ny0UqH iv6NqUdCbcykijH2N45I5LgyXqvAHEyJcY87UVLceE/0a5CeSBgzeypYOnxJm+toq3fx yx7H6PfDZbUkmawtAB92w6gpVg6G3JH1UE20xFsQTGcY5NGXEdjAOa2jiIFfSwNxwG1C FLlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YRI79nwoijzX/iWn8fymlgJV8Mx6+kl0OyDyYdcy5/8=; b=aa+mhTE3gQCyzqx/lG6DfmT0lwn25rPBnji6NoFQXuGhyEL/j3xhoIl5cKLPogA323 0830himrhXcCaocwuO+e0lSvYpsBWW1vJGnAtEFc1rHlw399jjqzxmrWdz8IylVWty/5 QM2DvVk0rZlop2c7XsN9LX3Ch23n1dAC8iGVbLhF7fl3133MFx78OM5ziOMiAc0YXnAH k3ZOiUCeskxSuFiuZZ8K8Ef43XFY6SU2ZvlFw/jrJqSzYtUmS4K9eZODkm8OC5RkStJr rka5S/yhT7gM81jlfRIhUK/YXaZV7i56BD6cYHyZ8Vzg27TM5IXJ13eBsYIN0arY5cMV HC6A== X-Gm-Message-State: AOAM531xKD1LX/kKlpHHrYWNhabHc+cHa8cD36IBeO1mRax5BjleiZdB gl0CbWDN/OxKCCaBAR+kKtQ= X-Google-Smtp-Source: ABdhPJyL4Zxxy4VJ+kDP9SxTw7GsB2K5yVjMnvQrn0j2zNyGIMrCEz6yAxTfizyhhoPJ9FAbQtO5mQ== X-Received: by 2002:a19:cb52:: with SMTP id b79mr2901032lfg.223.1607077803308; Fri, 04 Dec 2020 02:30:03 -0800 (PST) Received: from localhost.localdomain (87-205-71-93.adsl.inetia.pl. [87.205.71.93]) by smtp.gmail.com with ESMTPSA id d9sm62738lfj.228.2020.12.04.02.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 02:30:02 -0800 (PST) From: alardam@gmail.com X-Google-Original-From: marekx.majtyka@intel.com To: magnus.karlsson@intel.com, bjorn.topel@intel.com, andrii.nakryiko@gmail.com, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, davem@davemloft.net, john.fastabend@gmail.com, hawk@kernel.org, toke@redhat.com Cc: maciej.fijalkowski@intel.com, jonathan.lemon@gmail.com, bpf@vger.kernel.org, jeffrey.t.kirsher@intel.com, maciejromanfijalkowski@gmail.com, intel-wired-lan@lists.osuosl.org, Marek Majtyka Subject: [PATCH v2 bpf 3/5] xsk: add usage of xdp properties flags Date: Fri, 4 Dec 2020 11:28:59 +0100 Message-Id: <20201204102901.109709-4-marekx.majtyka@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201204102901.109709-1-marekx.majtyka@intel.com> References: <20201204102901.109709-1-marekx.majtyka@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Marek Majtyka Change necessary condition check for XSK from ndo functions to xdp properties flags. Signed-off-by: Marek Majtyka --- net/xdp/xsk_buff_pool.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c index 96bb607853ad..7ff82e2b2b43 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -158,8 +158,7 @@ static int __xp_assign_dev(struct xsk_buff_pool *pool, /* For copy-mode, we are done. */ return 0; - if (!netdev->netdev_ops->ndo_bpf || - !netdev->netdev_ops->ndo_xsk_wakeup) { + if ((netdev->xdp_properties & XDP_F_FULL_ZC) != XDP_F_FULL_ZC) { err = -EOPNOTSUPP; goto err_unreg_pool; } From patchwork Fri Dec 4 10:29:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Majtyka X-Patchwork-Id: 11951447 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2457C193FE for ; Fri, 4 Dec 2020 10:30:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6653622AAE for ; Fri, 4 Dec 2020 10:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726014AbgLDKas (ORCPT ); Fri, 4 Dec 2020 05:30:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729777AbgLDKar (ORCPT ); Fri, 4 Dec 2020 05:30:47 -0500 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAF0DC061A53; Fri, 4 Dec 2020 02:30:06 -0800 (PST) Received: by mail-lf1-x141.google.com with SMTP id u9so1440167lfm.1; Fri, 04 Dec 2020 02:30:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=okK9R+EpQDmMtHiCvnMrxiTd1O0LGgdUU5QYwf1cWDY=; b=LK2No5YP826qKY0vcMrXrj5zqKZxlfTuNgxC7wwStUuQ7F97Npllq+4iwQ7BORmVJF nY1TM8WGi74JPaf65jEtFd+lSjxfQAfuFjDFmdLnKLFdcZEbXCCsAuR6qqni7jFhTUUR 4G70rrxDlkP74lQ6zQ7Slma9DmOuCeXIGCM048Fo4CyNxfPh3/83PDO5bgFfZYv9uxZT hwBnSw2U3Bj/Rbjr/oISau22euJYVTt7w+b0uViDyA+mq81xYqAaufWeALvv7D1EadNF FP8TSm7/4lrHB2DT6SIoVQqWHTEXp075hq27GuaXmfR9nFKpa7a6HJ/6kZvnj6ibz7xF CmYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=okK9R+EpQDmMtHiCvnMrxiTd1O0LGgdUU5QYwf1cWDY=; b=LX0cu+2ksJ55a8j+yfgUvRflpe8K5DhhxYv7CCMZ4vGSWnuW5VqAIpu+izLO4nYbUx Vyr7X5ZUgp7svLs5J+D1MVMlA4ybmP+z0sOC6KT26G0hbtsOPLPMQ0REYFvCUea/Iga4 /SAvEY6oXrtuRiZ4vZhryWETxVR0jsrTQ6cLPUCkDdPpEFPhwvb7RIbm4ThSmYJAnAmk sohenzJ8DFi2DRtYy3BtQnG9iQ0n5hski3dZIn7DhTqPorWsQe7cj2n864MuAQs9Jq6S 2RijS7PwocvCsK6embq2jRUsGTwHzjM98L/9QZ5duPQJnnMU8P6JzirXyKcKPmPdmM63 CNIw== X-Gm-Message-State: AOAM532yQ75gYK6RXyRYyoZ4aIIemzN5XdWIvEWSMXLYJf/cr2rllELf GuO94wHuCPUGfT+sig7H+RQ= X-Google-Smtp-Source: ABdhPJxkk+iECwG/S50v63B/0Tdh+L98gPLu8FcppDHXL5mUtgLV4biMQdvh0rY3kZCDcKhuPWgUHQ== X-Received: by 2002:a05:6512:48e:: with SMTP id v14mr3190398lfq.255.1607077805141; Fri, 04 Dec 2020 02:30:05 -0800 (PST) Received: from localhost.localdomain (87-205-71-93.adsl.inetia.pl. [87.205.71.93]) by smtp.gmail.com with ESMTPSA id d9sm62738lfj.228.2020.12.04.02.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 02:30:04 -0800 (PST) From: alardam@gmail.com X-Google-Original-From: marekx.majtyka@intel.com To: magnus.karlsson@intel.com, bjorn.topel@intel.com, andrii.nakryiko@gmail.com, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, davem@davemloft.net, john.fastabend@gmail.com, hawk@kernel.org, toke@redhat.com Cc: maciej.fijalkowski@intel.com, jonathan.lemon@gmail.com, bpf@vger.kernel.org, jeffrey.t.kirsher@intel.com, maciejromanfijalkowski@gmail.com, intel-wired-lan@lists.osuosl.org, Marek Majtyka Subject: [PATCH v2 bpf 4/5] xsk: add check for full support of XDP in bind Date: Fri, 4 Dec 2020 11:29:00 +0100 Message-Id: <20201204102901.109709-5-marekx.majtyka@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201204102901.109709-1-marekx.majtyka@intel.com> References: <20201204102901.109709-1-marekx.majtyka@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Marek Majtyka Add check for full support of XDP in AF_XDP socket bind. To be able to use an AF_XDP socket with zero-copy, there needs to be support for both XDP_REDIRECT in the driver (XDP native mode) and the driver needs to support zero-copy. The problem is that there are drivers out there that only support XDP partially, so it is possible to successfully load the XDP program in native mode, but it will still not be able to support zero-copy as it does not have XDP_REDIRECT support. We can now alleviate this problem by using the new XDP netdev capability that signifies if full XDP support is indeed present. This check can be triggered by a new bind flag called XDP_CHECK_NATIVE_MODE. To simplify usage, this check is triggered automatically from inside libbpf library via turning on the new XDP_CHECK_NATIVE_MODE flag if and only if the driver mode is selected for the socket. As a result, the xsk_bind function decides if the native mode for a given interface makes sense or not using xdp netdev feature flags. Eventually the xsk socket is bound or an error is returned. Apart from this change and to catch all invalid inputs in a single place, an additional check is set to forbid sbk mode and zero copy settings at the same time as that combination makes no sense. Signed-off-by: Marek Majtyka --- include/uapi/linux/if_xdp.h | 1 + net/xdp/xsk.c | 4 ++-- net/xdp/xsk_buff_pool.c | 17 ++++++++++++++++- tools/include/uapi/linux/if_xdp.h | 1 + tools/lib/bpf/xsk.c | 3 +++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h index a78a8096f4ce..8f47754dacce 100644 --- a/include/uapi/linux/if_xdp.h +++ b/include/uapi/linux/if_xdp.h @@ -25,6 +25,7 @@ * application. */ #define XDP_USE_NEED_WAKEUP (1 << 3) +#define XDP_CHECK_NATIVE_MODE (1 << 4) /* Flags for xsk_umem_config flags */ #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0) diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index 7588e599a048..3b45754274bb 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -764,7 +764,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) flags = sxdp->sxdp_flags; if (flags & ~(XDP_SHARED_UMEM | XDP_COPY | XDP_ZEROCOPY | - XDP_USE_NEED_WAKEUP)) + XDP_USE_NEED_WAKEUP | XDP_CHECK_NATIVE_MODE)) return -EINVAL; rtnl_lock(); @@ -792,7 +792,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) struct socket *sock; if ((flags & XDP_COPY) || (flags & XDP_ZEROCOPY) || - (flags & XDP_USE_NEED_WAKEUP)) { + (flags & XDP_USE_NEED_WAKEUP) || (flags & XDP_CHECK_NATIVE_MODE)) { /* Cannot specify flags for shared sockets. */ err = -EINVAL; goto out_unlock; diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c index 7ff82e2b2b43..47e283ea1dca 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -123,7 +123,7 @@ static void xp_disable_drv_zc(struct xsk_buff_pool *pool) static int __xp_assign_dev(struct xsk_buff_pool *pool, struct net_device *netdev, u16 queue_id, u16 flags) { - bool force_zc, force_copy; + bool force_zc, force_copy, force_check; struct netdev_bpf bpf; int err = 0; @@ -131,10 +131,24 @@ static int __xp_assign_dev(struct xsk_buff_pool *pool, force_zc = flags & XDP_ZEROCOPY; force_copy = flags & XDP_COPY; + force_check = flags & XDP_CHECK_NATIVE_MODE; + if (force_zc && force_copy) return -EINVAL; + if (!(flags & XDP_SHARED_UMEM)) { + if (force_check) { + /* forbid driver mode without full XDP support */ + if (!(XDP_F_REDIRECT & netdev->xdp_properties)) + return -EOPNOTSUPP; + } else { + /* forbid skb mode and zero copy */ + if (force_zc) + return -EINVAL; + } + } + if (xsk_get_pool_from_qid(netdev, queue_id)) return -EBUSY; @@ -204,6 +218,7 @@ int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_umem *umem, return -EINVAL; flags = umem->zc ? XDP_ZEROCOPY : XDP_COPY; + flags |= XDP_SHARED_UMEM; if (pool->uses_need_wakeup) flags |= XDP_USE_NEED_WAKEUP; diff --git a/tools/include/uapi/linux/if_xdp.h b/tools/include/uapi/linux/if_xdp.h index a78a8096f4ce..8f47754dacce 100644 --- a/tools/include/uapi/linux/if_xdp.h +++ b/tools/include/uapi/linux/if_xdp.h @@ -25,6 +25,7 @@ * application. */ #define XDP_USE_NEED_WAKEUP (1 << 3) +#define XDP_CHECK_NATIVE_MODE (1 << 4) /* Flags for xsk_umem_config flags */ #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0) diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c index e3e41ceeb1bc..c309d2c87be3 100644 --- a/tools/lib/bpf/xsk.c +++ b/tools/lib/bpf/xsk.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -901,6 +902,8 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr, sxdp.sxdp_shared_umem_fd = umem->fd; } else { sxdp.sxdp_flags = xsk->config.bind_flags; + if (xsk->config.xdp_flags & XDP_FLAGS_DRV_MODE) + sxdp.sxdp_flags |= XDP_CHECK_NATIVE_MODE; } err = bind(xsk->fd, (struct sockaddr *)&sxdp, sizeof(sxdp)); From patchwork Fri Dec 4 10:29:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Majtyka X-Patchwork-Id: 11951453 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C41FBC4361A for ; Fri, 4 Dec 2020 10:31:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8055322A85 for ; Fri, 4 Dec 2020 10:31:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729763AbgLDKbU (ORCPT ); Fri, 4 Dec 2020 05:31:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729386AbgLDKbT (ORCPT ); Fri, 4 Dec 2020 05:31:19 -0500 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EDD6C061A54; Fri, 4 Dec 2020 02:30:08 -0800 (PST) Received: by mail-lj1-x243.google.com with SMTP id y10so6006113ljc.7; Fri, 04 Dec 2020 02:30:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Uvlu8DVmiHM5LldiM3Sj+vrND7t9AuD6a1TdugQe0Ps=; b=E0ImlY99mCDfxsnPflJXi/cbWygBLBAM1yaa2KUG3MVLBPBohyqayrU5z/mhL6zPTl uhR/zcyVlioxpXqzWsRcoYO5oXSn16+3Xnkjg0jIV70KnCtXM3UgBob8hM5klIh87wxP xN5NrpC+SpiIUuEUcDAKQ/qvgxIUlp8OJGb5vJmlOGNhA5tZpOgP7AwTc4XOXUFgMnMJ Ts6a6nTwN12S6f4IGvO3VnMfCbe1qzIxHDN4bgynTwSc4y2OHCRmjny6rigIU+qSO3g/ Uq57ETHCJIXIeeP2ja5j+2P4FVx3dYNTVTPEIMQQVyYqApDiTEtPK5/nJfwCxfXrYQ6f nrzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Uvlu8DVmiHM5LldiM3Sj+vrND7t9AuD6a1TdugQe0Ps=; b=mMml+9GBkZYANY5P3vlEysC+q8jqkkGr1DCKE+zwXClUaOstXchc1XJpC+cYh0EKeQ /dBEL3sNxoqRmWTMWH1Vtnytz+ftR5Cwjcw86BqDxQCevnNSVPANMI/BlSp+QGKphBON VuF3fATseZpD4dBmczy4+xxzhF2SHFIDyqF+NDkDavFP+B/TWqoeYRY1NweY9Bzr6tQW /PIrXknx/rp/ZSabWhNH4DM0Nv65sqgd5i3Wfh+BYDpIbidZFRjCfJRyW2QAqnJznQhO RTO4tygVKZeKfmr3D3HnwqLr3rpK0cOXyIdLkZ+2oI51OiGZgS5O9F6sVieIA9VmaLMr sZrg== X-Gm-Message-State: AOAM5303gXc5lxxcle5nnnpO7072gevcpx+dY35kHWG0N/h/QCC4+AhW kJetbKz/po8lEjSAUydR+h0= X-Google-Smtp-Source: ABdhPJwE9keJgFWAavozwghMGSbG70PKlHN+4SLFpuQS41hEbwbptQ2DFJnf7iqWWTjKxFwCQoaeCw== X-Received: by 2002:a2e:9c51:: with SMTP id t17mr2971756ljj.302.1607077807064; Fri, 04 Dec 2020 02:30:07 -0800 (PST) Received: from localhost.localdomain (87-205-71-93.adsl.inetia.pl. [87.205.71.93]) by smtp.gmail.com with ESMTPSA id d9sm62738lfj.228.2020.12.04.02.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 02:30:06 -0800 (PST) From: alardam@gmail.com X-Google-Original-From: marekx.majtyka@intel.com To: magnus.karlsson@intel.com, bjorn.topel@intel.com, andrii.nakryiko@gmail.com, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, davem@davemloft.net, john.fastabend@gmail.com, hawk@kernel.org, toke@redhat.com Cc: maciej.fijalkowski@intel.com, jonathan.lemon@gmail.com, bpf@vger.kernel.org, jeffrey.t.kirsher@intel.com, maciejromanfijalkowski@gmail.com, intel-wired-lan@lists.osuosl.org, Marek Majtyka Subject: [PATCH v2 bpf 5/5] ethtool: provide xdp info with XDP_PROPERTIES_GET Date: Fri, 4 Dec 2020 11:29:01 +0100 Message-Id: <20201204102901.109709-6-marekx.majtyka@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201204102901.109709-1-marekx.majtyka@intel.com> References: <20201204102901.109709-1-marekx.majtyka@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Marek Majtyka Implement XDP_PROPERTIES_GET request to get network device information about supported xdp functionalities. Signed-off-by: Marek Majtyka --- include/uapi/linux/ethtool_netlink.h | 14 +++++ net/ethtool/Makefile | 2 +- net/ethtool/netlink.c | 38 +++++++++----- net/ethtool/netlink.h | 2 + net/ethtool/xdp.c | 76 ++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 15 deletions(-) create mode 100644 net/ethtool/xdp.c diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index e2bf36e6964b..764d6edc2862 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -42,6 +42,7 @@ enum { ETHTOOL_MSG_CABLE_TEST_ACT, ETHTOOL_MSG_CABLE_TEST_TDR_ACT, ETHTOOL_MSG_TUNNEL_INFO_GET, + ETHTOOL_MSG_XDP_PROPERTIES_GET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, @@ -80,6 +81,7 @@ enum { ETHTOOL_MSG_CABLE_TEST_NTF, ETHTOOL_MSG_CABLE_TEST_TDR_NTF, ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY, + ETHTOOL_MSG_XDP_PROPERTIES_GET_REPLY, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, @@ -628,6 +630,18 @@ enum { ETHTOOL_A_TUNNEL_INFO_MAX = (__ETHTOOL_A_TUNNEL_INFO_CNT - 1) }; +/* XDP_PROPERTIES */ + +enum { + ETHTOOL_A_XDP_PROPERTIES_UNSPEC, + ETHTOOL_A_XDP_PROPERTIES_HEADER, /* nest - _A_HEADER_* */ + ETHTOOL_A_XDP_PROPERTIES_DATA, /* bitset */ + + /* add new constants above here */ + __ETHTOOL_A_XDP_PROPERTIES_CNT, + ETHTOOL_A_XDP_PROPERTIES_MAX = __ETHTOOL_A_XDP_PROPERTIES_CNT - 1 +}; + /* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool" #define ETHTOOL_GENL_VERSION 1 diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile index 7a849ff22dad..23d49eb07a7f 100644 --- a/net/ethtool/Makefile +++ b/net/ethtool/Makefile @@ -7,4 +7,4 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \ linkstate.o debug.o wol.o features.o privflags.o rings.o \ channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \ - tunnels.o + tunnels.o xdp.o diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 50d3c8896f91..06c943c78a11 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -231,20 +231,21 @@ struct ethnl_dump_ctx { static const struct ethnl_request_ops * ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { - [ETHTOOL_MSG_STRSET_GET] = ðnl_strset_request_ops, - [ETHTOOL_MSG_LINKINFO_GET] = ðnl_linkinfo_request_ops, - [ETHTOOL_MSG_LINKMODES_GET] = ðnl_linkmodes_request_ops, - [ETHTOOL_MSG_LINKSTATE_GET] = ðnl_linkstate_request_ops, - [ETHTOOL_MSG_DEBUG_GET] = ðnl_debug_request_ops, - [ETHTOOL_MSG_WOL_GET] = ðnl_wol_request_ops, - [ETHTOOL_MSG_FEATURES_GET] = ðnl_features_request_ops, - [ETHTOOL_MSG_PRIVFLAGS_GET] = ðnl_privflags_request_ops, - [ETHTOOL_MSG_RINGS_GET] = ðnl_rings_request_ops, - [ETHTOOL_MSG_CHANNELS_GET] = ðnl_channels_request_ops, - [ETHTOOL_MSG_COALESCE_GET] = ðnl_coalesce_request_ops, - [ETHTOOL_MSG_PAUSE_GET] = ðnl_pause_request_ops, - [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, - [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops, + [ETHTOOL_MSG_STRSET_GET] = ðnl_strset_request_ops, + [ETHTOOL_MSG_LINKINFO_GET] = ðnl_linkinfo_request_ops, + [ETHTOOL_MSG_LINKMODES_GET] = ðnl_linkmodes_request_ops, + [ETHTOOL_MSG_LINKSTATE_GET] = ðnl_linkstate_request_ops, + [ETHTOOL_MSG_DEBUG_GET] = ðnl_debug_request_ops, + [ETHTOOL_MSG_WOL_GET] = ðnl_wol_request_ops, + [ETHTOOL_MSG_FEATURES_GET] = ðnl_features_request_ops, + [ETHTOOL_MSG_PRIVFLAGS_GET] = ðnl_privflags_request_ops, + [ETHTOOL_MSG_RINGS_GET] = ðnl_rings_request_ops, + [ETHTOOL_MSG_CHANNELS_GET] = ðnl_channels_request_ops, + [ETHTOOL_MSG_COALESCE_GET] = ðnl_coalesce_request_ops, + [ETHTOOL_MSG_PAUSE_GET] = ðnl_pause_request_ops, + [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, + [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops, + [ETHTOOL_MSG_XDP_PROPERTIES_GET] = ðnl_xdp_request_ops, }; static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) @@ -912,6 +913,15 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_tunnel_info_get_policy, .maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_XDP_PROPERTIES_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_properties_get_policy, + .maxattr = ARRAY_SIZE(ethnl_properties_get_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index d8efec516d86..c5875e97b707 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -344,6 +344,7 @@ extern const struct ethnl_request_ops ethnl_coalesce_request_ops; extern const struct ethnl_request_ops ethnl_pause_request_ops; extern const struct ethnl_request_ops ethnl_eee_request_ops; extern const struct ethnl_request_ops ethnl_tsinfo_request_ops; +extern const struct ethnl_request_ops ethnl_xdp_request_ops; extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1]; extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1]; @@ -375,6 +376,7 @@ extern const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_HEADER + extern const struct nla_policy ethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_HEADER + 1]; extern const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG + 1]; extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER + 1]; +extern const struct nla_policy ethnl_properties_get_policy[ETHTOOL_A_XDP_PROPERTIES_HEADER + 1]; int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info); int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info); diff --git a/net/ethtool/xdp.c b/net/ethtool/xdp.c new file mode 100644 index 000000000000..fc0e87b6ed80 --- /dev/null +++ b/net/ethtool/xdp.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include "netlink.h" +#include "common.h" +#include "bitset.h" + +struct properties_req_info { + struct ethnl_req_info base; +}; + +struct properties_reply_data { + struct ethnl_reply_data base; + u32 properties[ETHTOOL_XDP_PROPERTIES_WORDS]; +}; + +const struct nla_policy ethnl_properties_get_policy[] = { + [ETHTOOL_A_XDP_PROPERTIES_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), +}; + +#define PROPERTIES_REPDATA(__reply_base) \ + container_of(__reply_base, struct properties_reply_data, base) + +static void ethnl_properties_to_bitmap32(u32 *dest, xdp_properties_t src) +{ + unsigned int i; + + for (i = 0; i < ETHTOOL_XDP_PROPERTIES_WORDS; i++) + dest[i] = src >> (32 * i); +} + +static int properties_prepare_data(const struct ethnl_req_info *req_base, + struct ethnl_reply_data *reply_base, + struct genl_info *info) +{ + struct properties_reply_data *data = PROPERTIES_REPDATA(reply_base); + struct net_device *dev = reply_base->dev; + + ethnl_properties_to_bitmap32(data->properties, dev->xdp_properties); + + return 0; +} + +static int properties_reply_size(const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + const struct properties_reply_data *data = PROPERTIES_REPDATA(reply_base); + bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS; + + return ethnl_bitset32_size(data->properties, NULL, XDP_PROPERTIES_COUNT, + xdp_properties_strings, compact); +} + +static int properties_fill_reply(struct sk_buff *skb, + const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + const struct properties_reply_data *data = PROPERTIES_REPDATA(reply_base); + bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS; + + return ethnl_put_bitset32(skb, ETHTOOL_A_XDP_PROPERTIES_DATA, data->properties, + NULL, XDP_PROPERTIES_COUNT, + xdp_properties_strings, compact); +} + +const struct ethnl_request_ops ethnl_xdp_request_ops = { + .request_cmd = ETHTOOL_MSG_XDP_PROPERTIES_GET, + .reply_cmd = ETHTOOL_MSG_XDP_PROPERTIES_GET_REPLY, + .hdr_attr = ETHTOOL_A_XDP_PROPERTIES_HEADER, + .req_info_size = sizeof(struct properties_req_info), + .reply_data_size = sizeof(struct properties_reply_data), + + .prepare_data = properties_prepare_data, + .reply_size = properties_reply_size, + .fill_reply = properties_fill_reply, +};