From patchwork Sat Apr 2 01:21:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brenden Blanco X-Patchwork-Id: 605374 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 3qcL8C5dgtz9sDG for ; Sat, 2 Apr 2016 12:22:19 +1100 (AEDT) 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=19cGasmP; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932100AbcDBBWR (ORCPT ); Fri, 1 Apr 2016 21:22:17 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:36519 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757046AbcDBBWO (ORCPT ); Fri, 1 Apr 2016 21:22:14 -0400 Received: by mail-pa0-f42.google.com with SMTP id tt10so102625768pab.3 for ; Fri, 01 Apr 2016 18:22:13 -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=V8j+y4LmACwEFG2herXD2KGEgZk2B3RKiBcKjTmpbzg=; b=19cGasmP/FKvhqnDDLOT7GrF72hpxnjXIwe1HBLFC6kQMUvuMbfiCZ1Mh+Vx59ZagZ MHx/y/Zsij1+AdfYds5mom3YPGN45Zq1sSXAUkHj8o6PursrEhjR1PfUvapEU2x3W6w6 Y4clOjNL88Kf9YosDuIDQ4PU0YZlpulqWXDVEPi1lUoY5oQSz4wZ7SEaGg3azYEPqEag 3ZTdxfisy4PtyMgRw959OO742vUy3REXLNJBPIGcRdT+BENXH6kPEJKII9Wooxhi0d8g Vx53Qr1jU2drL67IT1HkccNqzgadtAZCnIo2FS4aZu3xcJ4T96XmRA3lnLK1F1ypIfbs UnXQ== 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=V8j+y4LmACwEFG2herXD2KGEgZk2B3RKiBcKjTmpbzg=; b=T0FveCJGz0ZIp8PDGYNIuOPqxndsBQv30e4uVzZnwNhrYbETHfkLpu7XYsc/IR2Tcm A5ITWHnJqIIHal+hTBOhQsKnpNb54chYppiRT/kk4h0tovb92MpLPnV731QeJ1ZJ03SJ zz1WygZd5Y1SwFt3Hozt0MufDmgNLNGprXbRnKx3dJ5VIHuL48pTqsPMBrLD3Aq9mocI tX1HpW9DDMSG5krsSleV9ezNcJQ2qcBhx8UTJD77Xlx8tbnG1lb5k+uwb0VckQeBrQ1M 6/XjclXq93p7CjVKZrBGl9dhfI0vM/8/t0vX4J0qfN/zicgn7HtCGLjx8oVMIQ4dZnzP la8g== X-Gm-Message-State: AD7BkJJski4ar0ZVnFQwsoZSYSZkcER3qs/CmxPSFETy0sbHk43fJVquglqC2jpDOHWh+nEI X-Received: by 10.66.63.7 with SMTP id c7mr35182043pas.104.1459560133334; Fri, 01 Apr 2016 18:22:13 -0700 (PDT) Received: from iovisor-test1.plumgrid.com ([12.97.19.201]) by smtp.gmail.com with ESMTPSA id kl14sm24742480pab.23.2016.04.01.18.22.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Apr 2016 18:22:12 -0700 (PDT) From: Brenden Blanco To: davem@davemloft.net Cc: Brenden Blanco , netdev@vger.kernel.org, tom@herbertland.com, alexei.starovoitov@gmail.com, gerlitz@mellanox.com, daniel@iogearbox.net, john.fastabend@gmail.com, brouer@redhat.com Subject: [RFC PATCH 2/5] net: add ndo to set bpf prog in adapter rx Date: Fri, 1 Apr 2016 18:21:55 -0700 Message-Id: <1459560118-5582-3-git-send-email-bblanco@plumgrid.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1459560118-5582-1-git-send-email-bblanco@plumgrid.com> References: <1459560118-5582-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 a new netdev op for drivers implementing the BPF_PROG_TYPE_PHYS_DEV filter to get configuration. Since the fd is only used by the driver to fetch the prog, the netdev should just keep a bit to indicate the program is valid. Signed-off-by: Brenden Blanco --- include/linux/netdevice.h | 8 ++++++++ net/core/dev.c | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index cb0d5d0..c46e2e3 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1102,6 +1102,11 @@ 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_bpf_set)(struct net_device *dev, int fd); + * This function is used to set or clear a bpf program used in the + * earliest stages of packet rx. The fd must be a program loaded as + * BPF_PROG_TYPE_PHYS_DEV. Negative values of fd indicate the program + * should be removed. * */ struct net_device_ops { @@ -1292,6 +1297,7 @@ struct net_device_ops { struct sk_buff *skb); void (*ndo_set_rx_headroom)(struct net_device *dev, int needed_headroom); + int (*ndo_bpf_set)(struct net_device *dev, int fd); }; /** @@ -1875,6 +1881,7 @@ struct net_device { struct phy_device *phydev; struct lock_class_key *qdisc_tx_busylock; bool proto_down; + bool bpf_valid; }; #define to_net_dev(d) container_of(d, struct net_device, dev) @@ -3268,6 +3275,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_bpf_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 b9bcbe7..eb93414 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6480,6 +6480,18 @@ int dev_change_proto_down(struct net_device *dev, bool proto_down) } EXPORT_SYMBOL(dev_change_proto_down); +int dev_change_bpf_fd(struct net_device *dev, int fd) +{ + const struct net_device_ops *ops = dev->netdev_ops; + + if (!ops->ndo_bpf_set) + return -EOPNOTSUPP; + if (!netif_device_present(dev)) + return -ENODEV; + return ops->ndo_bpf_set(dev, fd); +} +EXPORT_SYMBOL(dev_change_bpf_fd); + /** * dev_new_index - allocate an ifindex * @net: the applicable net namespace