From patchwork Wed Oct 10 00:41:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shannon Nelson X-Patchwork-Id: 981636 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=pass (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="oOs/7hjj"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42VFfB0LDrz9sBk for ; Wed, 10 Oct 2018 11:41:38 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726825AbeJJIBF (ORCPT ); Wed, 10 Oct 2018 04:01:05 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:48504 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726468AbeJJIBF (ORCPT ); Wed, 10 Oct 2018 04:01:05 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9A0cZUp140099; Wed, 10 Oct 2018 00:41:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=r5Rf399gMAB8zwXwtNJFRd3LGpKyepWhZkusi4w9nxo=; b=oOs/7hjjmUKRmS0NaRHN5h9XbXe8nWrsNc3yMiv0Meko+5mxwqqNbZSZAoaf6Owz7L61 w0fSQrzA8aVKT6eJMX5zkrlc098a7Ef6gQ+0E/BqUQ5vWb6mQ/99NHPX5al03CJRxnGW lwY38nL8w4GMACXAxAjHKAqwjwLl2IuKjaduRmHzQRU9FDR0q5CAjg5DSvRbDTzBagD9 ttxFClxpkNL2sQR8BSr6CLmIaWuctvniefWp6mUihxmKJip6Dv5vWRpXSU4hFSA8Swc2 Zp05RApztOiNh4cMFOvsNjiqaqlV0SDZywWeOEUGWn9BQ4rUmfe+PpEDAHrXD2diKtIW Eg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2mxmftrxqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:41:30 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9A0fTDm007701 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:41:30 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9A0fThG031211; Wed, 10 Oct 2018 00:41:29 GMT Received: from slnelson-mint18.us.oracle.com (/10.159.244.67) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 10 Oct 2018 00:41:28 +0000 From: Shannon Nelson To: davem@davemloft.net, netdev@vger.kernel.org Cc: silviu.smarandache@oracle.com Subject: [PATCH net-next] net: enable RPS on vlan devices Date: Tue, 9 Oct 2018 17:41:02 -0700 Message-Id: <1539132062-4348-1-git-send-email-shannon.nelson@oracle.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9041 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810100005 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Silviu Smarandache This patch modifies the RPS processing code so that it searches for a matching vlan interface on the packet and then uses the RPS settings of the vlan interface.  If no vlan interface is found or the vlan interface does not have RPS enabled, it will fall back to the RPS settings of the underlying device. In supporting VMs where we can't control the OS being used, we'd like to separate the VM cpu processing from the host's cpus as a way to help mitigate the impact of the L1TF issue. When running the VM's traffic on a vlan we can stick the Rx processing on one set of cpus separate from the VM's cpus. Yes, choosing to use this may cause a bit of throughput pain when the packets are actually passed into the VM and have to move from one cache to another. Orabug: 28645929 Signed-off-by: Silviu Smarandache Signed-off-by: Shannon Nelson --- net/core/dev.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 0b2d777..1da3f63 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3971,8 +3971,8 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb, * CPU from the RPS map of the receiving queue for a given skb. * rcu_read_lock must be held on entry. */ -static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb, - struct rps_dev_flow **rflowp) +static int __get_rps_cpu(struct net_device *dev, struct sk_buff *skb, + struct rps_dev_flow **rflowp) { const struct rps_sock_flow_table *sock_flow_table; struct netdev_rx_queue *rxqueue = dev->_rx; @@ -4066,6 +4066,35 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb, return cpu; } +static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb, + struct rps_dev_flow **rflowp) +{ + /* Check for a vlan device with RPS settings */ + if (skb_vlan_tag_present(skb)) { + struct net_device *vdev; + u16 vid; + + vid = skb_vlan_tag_get_id(skb); + vdev = __vlan_find_dev_deep_rcu(dev, skb->vlan_proto, vid); + if (vdev) { + /* recorded queue is not referring to the vlan device. + * Save and restore it + */ + int cpu; + u16 queue_mapping = skb_get_queue_mapping(skb); + + skb_set_queue_mapping(skb, 0); + cpu = __get_rps_cpu(vdev, skb, rflowp); + skb_set_queue_mapping(skb, queue_mapping); + if (cpu != -1) + return cpu; + } + } + + /* Fall back to RPS settings of original device */ + return __get_rps_cpu(dev, skb, rflowp); +} + #ifdef CONFIG_RFS_ACCEL /** @@ -4437,12 +4466,23 @@ static int netif_rx_internal(struct sk_buff *skb) preempt_disable(); rcu_read_lock(); + /* strip any vlan tag before calling get_rps_cpu() */ + if (skb->protocol == cpu_to_be16(ETH_P_8021Q) || + skb->protocol == cpu_to_be16(ETH_P_8021AD)) { + skb = skb_vlan_untag(skb); + if (unlikely(!skb)) { + ret = NET_RX_DROP; + goto unlock; + } + } + cpu = get_rps_cpu(skb->dev, skb, &rflow); if (cpu < 0) cpu = smp_processor_id(); ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail); +unlock: rcu_read_unlock(); preempt_enable(); } else @@ -5095,8 +5135,19 @@ static int netif_receive_skb_internal(struct sk_buff *skb) #ifdef CONFIG_RPS if (static_key_false(&rps_needed)) { struct rps_dev_flow voidflow, *rflow = &voidflow; - int cpu = get_rps_cpu(skb->dev, skb, &rflow); + int cpu; + + /* strip any vlan tag before calling get_rps_cpu() */ + if (skb->protocol == cpu_to_be16(ETH_P_8021Q) || + skb->protocol == cpu_to_be16(ETH_P_8021AD)) { + skb = skb_vlan_untag(skb); + if (unlikely(!skb)) { + ret = NET_RX_DROP; + goto out; + } + } + cpu = get_rps_cpu(skb->dev, skb, &rflow); if (cpu >= 0) { ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail); rcu_read_unlock(); @@ -5105,6 +5156,8 @@ static int netif_receive_skb_internal(struct sk_buff *skb) } #endif ret = __netif_receive_skb(skb); + +out: rcu_read_unlock(); return ret; }