From patchwork Fri Jul 8 02:15:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brenden Blanco X-Patchwork-Id: 646276 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rlylc75Y1z9sBg for ; Fri, 8 Jul 2016 12:16:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=plumgrid-com.20150623.gappssmtp.com header.i=@plumgrid-com.20150623.gappssmtp.com header.b=zk0rerli; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754021AbcGHCQL (ORCPT ); Thu, 7 Jul 2016 22:16:11 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:35985 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753645AbcGHCPh (ORCPT ); Thu, 7 Jul 2016 22:15:37 -0400 Received: by mail-pa0-f50.google.com with SMTP id uj8so10962389pab.3 for ; Thu, 07 Jul 2016 19:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plumgrid-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HpJ1u63L2nTNzsx0qYbUOhNoEJrqOkmq53FcfveUhR8=; b=zk0rerlil9/yVAkYr5OW0IKmAzAdt+Lmt/CHO2FiwKjdtKkvrdw9X577JOLgKUcOnu 0X4foF2ymuqtW20Ys3tkAOIgcb1osCLthjbz8nkp9ZNgBB3cTdkqeuup2Ekfr5Gz2gg4 qoUywoQ+JvI1HNU2n4RqSek5rkNDFem31oiOZlbRil52L606UY7KNrw5+vu4rLTImX3m Zn8wO2G3ZlZBshFwPBT1edSvvQ4DRdMy0VZwzzPrTaw/hFgzVF5JT0VjXgTBqBG7iUhq ZAIkzzIFoCrl3dPl4UO5UoIUpNoypjhnjQdLRIV9ZIBZQE34N9HaBc8gsaw58eRQTZWR gAWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HpJ1u63L2nTNzsx0qYbUOhNoEJrqOkmq53FcfveUhR8=; b=WvcdWoroW0oN0eGSB0KzRAE8TSTGmjGZl0i9IqA6RZzpoDy+MyAUclIElzUvS7ZN/d 7IaOvGSuXGNHJYKXYf3Pt4gYM8CQEiKYNOjFr5I0vFGIJuI6b+7fSwVjEJ4cF1PTCYZH RQAyVrGC1HgYksNFzKKAJtfID1UvPKTnV+nXFUjV5hPaKNdh3eTllIAAdBc8QMnVfh/E Amw5zxEe7t+PM3WnWHCmtmWQ9hTvqLjGjMr6iOqSdI2EUPEpnFHakNWbS3IG9ljkBc/8 FkowtSjpDFea+h0Yca3dn9PDbU8cNY2TTilvi9+VY2LSSd5cOdgjDbXIzfJf9Z4sYVlj 7sKw== X-Gm-Message-State: ALyK8tJaHm/zoQhuiSCmLttxoPRPE8t+JtEKd6oT5eNndYU+43n+ZNQrPLDigbEX66PG3IG1 X-Received: by 10.66.251.170 with SMTP id zl10mr5626341pac.25.1467944136043; Thu, 07 Jul 2016 19:15:36 -0700 (PDT) Received: from iovisor-test1.plumgrid.com ([12.97.19.201]) by smtp.gmail.com with ESMTPSA id jh3sm401497pac.14.2016.07.07.19.15.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Jul 2016 19:15:35 -0700 (PDT) From: Brenden Blanco To: davem@davemloft.net, netdev@vger.kernel.org Cc: Brenden Blanco , Martin KaFai Lau , Jesper Dangaard Brouer , Ari Saha , Alexei Starovoitov , Or Gerlitz , john.fastabend@gmail.com, hannes@stressinduktion.org, Thomas Graf , Tom Herbert , Daniel Borkmann Subject: [PATCH v6 02/12] net: add ndo to set xdp prog in adapter rx Date: Thu, 7 Jul 2016 19:15:14 -0700 Message-Id: <1467944124-14891-3-git-send-email-bblanco@plumgrid.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1467944124-14891-1-git-send-email-bblanco@plumgrid.com> References: <1467944124-14891-1-git-send-email-bblanco@plumgrid.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add two new set/check netdev ops for drivers implementing the BPF_PROG_TYPE_XDP filter. Signed-off-by: Brenden Blanco --- include/linux/netdevice.h | 14 ++++++++++++++ net/core/dev.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 49736a3..36ae955 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -63,6 +63,7 @@ struct wpan_dev; struct mpls_dev; /* UDP Tunnel offloads */ struct udp_tunnel_info; +struct bpf_prog; void netdev_set_default_ethtool_ops(struct net_device *dev, const struct ethtool_ops *ops); @@ -1087,6 +1088,15 @@ struct tc_to_netdev { * appropriate rx headroom value allows avoiding skb head copy on * forward. Setting a negative value resets the rx headroom to the * default value. + * int (*ndo_xdp_set)(struct net_device *dev, struct bpf_prog *prog); + * This function is used to set or clear a bpf program used in the + * earliest stages of packet rx. The prog will have been loaded as + * BPF_PROG_TYPE_XDP. The callee is responsible for calling bpf_prog_put + * on any old progs that are stored, but not on the passed in prog. + * bool (*ndo_xdp_attached)(struct net_device *dev); + * This function is used to check if a bpf program is set on the device. + * The callee should return true if a program is currently attached and + * running. * */ struct net_device_ops { @@ -1271,6 +1281,9 @@ struct net_device_ops { struct sk_buff *skb); void (*ndo_set_rx_headroom)(struct net_device *dev, int needed_headroom); + int (*ndo_xdp_set)(struct net_device *dev, + struct bpf_prog *prog); + bool (*ndo_xdp_attached)(struct net_device *dev); }; /** @@ -3257,6 +3270,7 @@ int dev_get_phys_port_id(struct net_device *dev, int dev_get_phys_port_name(struct net_device *dev, char *name, size_t len); int dev_change_proto_down(struct net_device *dev, bool proto_down); +int dev_change_xdp_fd(struct net_device *dev, int fd); struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev); struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, struct netdev_queue *txq, int *ret); diff --git a/net/core/dev.c b/net/core/dev.c index b92d63b..154b057 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -94,6 +94,7 @@ #include #include #include +#include #include #include #include @@ -6615,6 +6616,35 @@ int dev_change_proto_down(struct net_device *dev, bool proto_down) EXPORT_SYMBOL(dev_change_proto_down); /** + * dev_change_xdp_fd - set or clear a bpf program for a device rx path + * @dev: device + * @fd: new program fd or negative value to clear + * + * Set or clear a bpf program for a device + */ +int dev_change_xdp_fd(struct net_device *dev, int fd) +{ + const struct net_device_ops *ops = dev->netdev_ops; + struct bpf_prog *prog = NULL; + int err; + + if (!ops->ndo_xdp_set) + return -EOPNOTSUPP; + if (fd >= 0) { + prog = bpf_prog_get_type(fd, BPF_PROG_TYPE_XDP); + if (IS_ERR(prog)) + return PTR_ERR(prog); + } + + err = ops->ndo_xdp_set(dev, prog); + if (err < 0 && prog) + bpf_prog_put(prog); + + return err; +} +EXPORT_SYMBOL(dev_change_xdp_fd); + +/** * dev_new_index - allocate an ifindex * @net: the applicable net namespace *