From patchwork Mon Dec 5 08:59:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 129245 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 9D2571007D6 for ; Mon, 5 Dec 2011 19:58:37 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754312Ab1LEI6b (ORCPT ); Mon, 5 Dec 2011 03:58:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17067 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753601Ab1LEI6a (ORCPT ); Mon, 5 Dec 2011 03:58:30 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pB58wNkK004072 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Dec 2011 03:58:23 -0500 Received: from dhcp-8-146.nay.redhat.com (dhcp-8-146.nay.redhat.com [10.66.8.146]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pB58wJEp006794; Mon, 5 Dec 2011 03:58:20 -0500 Subject: [net-next RFC PATCH 3/5] macvtap: flow director support To: krkumar2@in.ibm.com, kvm@vger.kernel.org, mst@redhat.com, netdev@vger.kernel.org, rusty@rustcorp.com.au, virtualization@lists.linux-foundation.org, levinsasha928@gmail.com, bhutchings@solarflare.com From: Jason Wang Date: Mon, 05 Dec 2011 16:59:06 +0800 Message-ID: <20111205085906.6116.84426.stgit@dhcp-8-146.nay.redhat.com> In-Reply-To: <20111205085603.6116.65101.stgit@dhcp-8-146.nay.redhat.com> References: <20111205085603.6116.65101.stgit@dhcp-8-146.nay.redhat.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Jason Wang --- drivers/net/macvlan.c | 4 ++++ drivers/net/macvtap.c | 36 ++++++++++++++++++++++++++++++++++-- include/linux/if_macvlan.h | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 7413497..b0cb7ce 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -706,6 +706,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, vlan->port = port; vlan->receive = receive; vlan->forward = forward; + vlan->fd_page[0] = NULL; vlan->mode = MACVLAN_MODE_VEPA; if (data && data[IFLA_MACVLAN_MODE]) @@ -749,6 +750,9 @@ void macvlan_dellink(struct net_device *dev, struct list_head *head) { struct macvlan_dev *vlan = netdev_priv(dev); + if (vlan->fd_page[0]) + put_page(vlan->fd_page[0]); + list_del(&vlan->list); unregister_netdevice_queue(dev, head); } diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c index 504c745..a34eb84 100644 --- a/drivers/net/macvtap.c +++ b/drivers/net/macvtap.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -62,6 +63,8 @@ static DEFINE_IDR(minor_idr); static struct class *macvtap_class; static struct cdev macvtap_cdev; +#define TAP_HASH_MASK 0xFF + static const struct proto_ops macvtap_socket_ops; /* @@ -189,6 +192,11 @@ static struct macvtap_queue *macvtap_get_queue(struct net_device *dev, /* Check if we can use flow to select a queue */ rxq = skb_get_rxhash(skb); if (rxq) { + if (vlan->fd_page[0]) { + u16 *table = kmap_atomic(vlan->fd_page[0]); + rxq = table[rxq & TAP_HASH_MASK]; + kunmap_atomic(table); + } tap = rcu_dereference(vlan->taps[rxq % numvtaps]); if (tap) goto out; @@ -851,6 +859,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, { struct macvtap_queue *q = file->private_data; struct macvlan_dev *vlan; + struct tun_fd tfd; void __user *argp = (void __user *)arg; struct ifreq __user *ifr = argp; unsigned int __user *up = argp; @@ -891,8 +900,8 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, return ret; case TUNGETFEATURES: - if (put_user(IFF_TAP | IFF_NO_PI | IFF_VNET_HDR | IFF_RXHASH, - up)) + if (put_user(IFF_TAP | IFF_NO_PI | IFF_VNET_HDR | IFF_RXHASH | + IFF_FD, up)) return -EFAULT; return 0; @@ -918,6 +927,29 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, q->vnet_hdr_sz = s; return 0; + case TUNSETFD: + rcu_read_lock_bh(); + vlan = rcu_dereference(q->vlan); + if (!vlan) + ret = -ENOLINK; + else { + if (copy_from_user(&tfd, argp, sizeof(tfd))) + ret = -EFAULT; + if (vlan->fd_page[0]) { + put_page(vlan->fd_page[0]); + vlan->fd_page[0] = NULL; + } + + /* put_page() in macvlan_dellink() */ + if (get_user_pages_fast(tfd.addr, 1, 0, + &vlan->fd_page[0]) != 1) + ret = -EFAULT; + else + ret = 0; + } + rcu_read_unlock_bh(); + return ret; + case TUNSETOFFLOAD: /* let the user check for future flags */ if (arg & ~(TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6 | diff --git a/include/linux/if_macvlan.h b/include/linux/if_macvlan.h index d103dca..69a87a1 100644 --- a/include/linux/if_macvlan.h +++ b/include/linux/if_macvlan.h @@ -65,6 +65,7 @@ struct macvlan_dev { struct macvtap_queue *taps[MAX_MACVTAP_QUEUES]; int numvtaps; int minor; + struct page *fd_page[1]; }; static inline void macvlan_count_rx(const struct macvlan_dev *vlan,