From patchwork Wed Jun 27 02:46:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 935235 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=dev.mellanox.co.il Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=dev-mellanox-co-il.20150623.gappssmtp.com header.i=@dev-mellanox-co-il.20150623.gappssmtp.com header.b="vGk1vSbt"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41FnNx6RGkz9s0n for ; Wed, 27 Jun 2018 12:46:41 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932135AbeF0Cqk (ORCPT ); Tue, 26 Jun 2018 22:46:40 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:42842 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751924AbeF0Cqg (ORCPT ); Tue, 26 Jun 2018 22:46:36 -0400 Received: by mail-pf0-f194.google.com with SMTP id w7-v6so269362pfn.9 for ; Tue, 26 Jun 2018 19:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dev-mellanox-co-il.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BBxusQg1kVf0RA0T9WSUGDy/DwQ/jjg97slBT18O4Ic=; b=vGk1vSbtBWWZoroPfws46sXzhmp1HFzSnAXFD4HcfuS+FcoXz94hxoZb9IoJTOvT0B EEszdZrjv2LhGt+oVf6A3LP1DKlOlDXhuzxww9dLFhBCEINkp2V8HuufZTrbN9z3qk7H JeyChD/2B/MC7TiO5cptcEaWGhbxQosYpNey1i1Ck1KlGjSfp1pievPX41yIHT6IB3BF 7eGF1uzos04mcBWdFl+Hbv8Ir3MaHsvqDSb0wrAGNjNsMxuuQhoCsEpAjY35Xehlyrew GKeK3n1WsPPFvoqnd9ykBPVv48pzlqgoQ6D3vAR71EXYm4RR3NM6bfN8Ui51MfuqA+rw soTw== 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; bh=BBxusQg1kVf0RA0T9WSUGDy/DwQ/jjg97slBT18O4Ic=; b=Dy8hFPVMO9CuP4TifTgfnekypWOVz4Zt7nEPGKD2A6YpLakn+bU7FXQtRYHhHdHp/1 LUhrU291P7jE9yXleO5hR8Olhepq6P4yJRIOtN+ZhenOJe6urmCQhinVadUmcV9n7TvY NP2eUih0mleqz7AsWrRp8L1voWcsx7hnR4sk5RAnGgBlBGXDyn8AZ6CIPH0rmHapHkcb uV+paOb0jWj/m8gChOHlkcjhJw3LM02ksSIprS+QEfA/athyebbZz/A6xDEZAvZJn+oU F84uqPcG6e5kcpotQ/mVVAgyXL+jxxJeWT7w4DeaYl+2CI74M1f3cDJKV1hpmX0PI37p dx9w== X-Gm-Message-State: APt69E3RkQYtEU4ulApvfv70rGo/3ZL7uL2Yuar96YXoiWz1HGaxKvMk J6RYTlFfgWjiUlAiXIQ2ntKQWw== X-Google-Smtp-Source: AAOMgpcha81ZflJwFBkaAFv6UAJR9woip3HBXT/yphhe7NHNG18tkHdlAuGBeiY3xzeI1cQWfM0FtA== X-Received: by 2002:a65:62d0:: with SMTP id m16-v6mr459602pgv.281.1530067595915; Tue, 26 Jun 2018 19:46:35 -0700 (PDT) Received: from stpd.hsd1.ca.comcast.net ([2601:647:4000:4586::4088]) by smtp.gmail.com with ESMTPSA id j21-v6sm3950904pfn.121.2018.06.26.19.46.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Jun 2018 19:46:34 -0700 (PDT) From: Saeed Mahameed X-Google-Original-From: Saeed Mahameed To: Jesper Dangaard Brouer , Alexei Starovoitov , Daniel Borkmann Cc: neerav.parikh@intel.com, pjwaskiewicz@gmail.com, ttoukan.linux@gmail.com, Tariq Toukan , alexander.h.duyck@intel.com, peter.waskiewicz.jr@intel.com, Opher Reviv , Rony Efraim , netdev@vger.kernel.org, Saeed Mahameed Subject: [RFC bpf-next 1/6] net: xdp: Add support for meta data flags requests Date: Tue, 26 Jun 2018 19:46:10 -0700 Message-Id: <20180627024615.17856-2-saeedm@mellanox.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180627024615.17856-1-saeedm@mellanox.com> References: <20180627024615.17856-1-saeedm@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org A user space application can request to enable a specific set of meta data to be reported in every xdp buffer provided to the xdp program. When meta_data flags are required, XDP devices must respond to XDP_QUERY_META_FLAGS command with all the meta data flags the device actually supports, and the kernel will cross check them with the requested flags, in case of discrepancy the xdp install will fail. If the flags are supported, the device must guarantee to deliver all RX packets with only the meta data requested in meta data_flags on xdp_install operation. The following flags are added, and can be provided by the netlink xdp flags field. +#define XDP_FLAGS_META_HASH (1U << 16) +#define XDP_FLAGS_META_FLOW_MARK (1U << 17) +#define XDP_FLAGS_META_VLAN (1U << 18) +#define XDP_FLAGS_META_CSUM_COMPLETE (1U << 19) The format, device delivery methods and XDP program access to such meta data is discussed in a later patch. TODO: use a different flags field for XDP meta data, to make sure we have more free bits. Signed-off-by: Saeed Mahameed --- include/linux/netdevice.h | 9 +++++++++ include/uapi/linux/if_link.h | 16 +++++++++++++++- net/core/dev.c | 20 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 3ec9850c7936..fc8b6ce48a0f 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -812,6 +812,10 @@ enum bpf_netdev_command { * is equivalent to XDP_ATTACHED_DRV. */ XDP_QUERY_PROG, + /* Query Supported XDP_FLAGS_META_*, Called before new XDP program setup + * and only if meta_flags were requested by the user to validate if the + * device supports the requested flags, if not program setup will fail */ + XDP_QUERY_META_FLAGS, /* BPF program for offload callbacks, invoked at program load time. */ BPF_OFFLOAD_VERIFIER_PREP, BPF_OFFLOAD_TRANSLATE, @@ -842,6 +846,11 @@ struct netdev_bpf { /* flags with which program was installed */ u32 prog_flags; }; + /* XDP_QUERY_META_FLAGS */ + struct { + /* TODO u64 */ + u32 meta_flags; + }; /* BPF_OFFLOAD_VERIFIER_PREP */ struct { struct bpf_prog *prog; diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index cf01b6824244..dfb1e26bacef 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -911,8 +911,22 @@ enum { #define XDP_FLAGS_MODES (XDP_FLAGS_SKB_MODE | \ XDP_FLAGS_DRV_MODE | \ XDP_FLAGS_HW_MODE) + +/* TODO : add new netlink xdp u64 meta_flags + * for meta data only + */ +#define XDP_FLAGS_META_HASH (1U << 16) +#define XDP_FLAGS_META_MARK (1U << 17) +#define XDP_FLAGS_META_VLAN (1U << 18) +#define XDP_FLAGS_META_CSUM_COMPLETE (1U << 19) +#define XDP_FLAGS_META_ALL (XDP_FLAGS_META_HASH | \ + XDP_FLAGS_META_MARK | \ + XDP_FLAGS_META_VLAN | \ + XDP_FLAGS_META_CSUM_COMPLETE) + #define XDP_FLAGS_MASK (XDP_FLAGS_UPDATE_IF_NOEXIST | \ - XDP_FLAGS_MODES) + XDP_FLAGS_MODES | \ + XDP_FLAGS_META_ALL) /* These are stored into IFLA_XDP_ATTACHED on dump. */ enum { diff --git a/net/core/dev.c b/net/core/dev.c index a5aa1c7444e6..8a5cc2c731ec 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -7295,6 +7295,21 @@ static u8 __dev_xdp_attached(struct net_device *dev, bpf_op_t bpf_op) return xdp.prog_attached; } +static bool __dev_xdp_meta_supported(struct net_device *dev, + bpf_op_t bpf_op, u32 meta_flags) +{ + struct netdev_bpf xdp = {}; + + /* Backward compatible, all devices support no meta_flags */ + if (!meta_flags) + return true; + + xdp.command = XDP_QUERY_META_FLAGS; + bpf_op(dev, &xdp); + + return ((xdp.meta_flags & meta_flags) == meta_flags); +} + static int dev_xdp_install(struct net_device *dev, bpf_op_t bpf_op, struct netlink_ext_ack *extack, u32 flags, struct bpf_prog *prog) @@ -7362,12 +7377,17 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, bpf_chk = generic_xdp_install; if (fd >= 0) { + u32 meta_flags = (flags & XDP_FLAGS_META_ALL); + if (bpf_chk && __dev_xdp_attached(dev, bpf_chk)) return -EEXIST; if ((flags & XDP_FLAGS_UPDATE_IF_NOEXIST) && __dev_xdp_attached(dev, bpf_op)) return -EBUSY; + if (!__dev_xdp_meta_supported(dev, bpf_op, meta_flags)) + return -EINVAL; + prog = bpf_prog_get_type_dev(fd, BPF_PROG_TYPE_XDP, bpf_op == ops->ndo_bpf); if (IS_ERR(prog))