From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <wujingji@shecgisg004.sh.intel.com>
Received: from mga11.intel.com (mga11.intel.com [192.55.52.93])
 by dpdk.org (Postfix) with ESMTP id 97592231C
 for <dev@dpdk.org>; Tue, 13 Oct 2015 09:19:00 +0200 (CEST)
Received: from orsmga003.jf.intel.com ([10.7.209.27])
 by fmsmga102.fm.intel.com with ESMTP; 13 Oct 2015 00:18:59 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.17,676,1437462000"; d="scan'208";a="663206374"
Received: from shvmail01.sh.intel.com ([10.239.29.42])
 by orsmga003.jf.intel.com with ESMTP; 13 Oct 2015 00:18:57 -0700
Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com
 [10.239.29.89])
 by shvmail01.sh.intel.com with ESMTP id t9D7ItLG025257;
 Tue, 13 Oct 2015 15:18:55 +0800
Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1])
 by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id
 t9D7Ipxf000822; Tue, 13 Oct 2015 15:18:53 +0800
Received: (from wujingji@localhost)
 by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id t9D7Ipus000818;
 Tue, 13 Oct 2015 15:18:51 +0800
From: Jingjing Wu <jingjing.wu@intel.com>
To: dev@dpdk.org
Date: Tue, 13 Oct 2015 15:18:49 +0800
Message-Id: <1444720729-788-1-git-send-email-jingjing.wu@intel.com>
X-Mailer: git-send-email 1.7.4.1
In-Reply-To: <1443170678-7249-1-git-send-email-jingjing.wu@intel.com>
References: <1443170678-7249-1-git-send-email-jingjing.wu@intel.com>
Cc: yulong.pei@intel.com
Subject: [dpdk-dev] [PATCH v2] i40e: Add a workaround to drop flow control
	frames from VFs
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Tue, 13 Oct 2015 07:19:01 -0000

This patch adds a workaround to drop flow control frames from being
transmitted from VSIs.
With this patch in place a malicious VF cannot send flow control or PFC
packets out on the wire.

Signed-off-by: Jingjing Wu <jingjing.wu@intel.com>
---
v2:
 - reword comments

 drivers/net/i40e/i40e_ethdev.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 2dd9fdc..3d19f42 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -382,6 +382,30 @@ static inline void i40e_flex_payload_reg_init(struct i40e_hw *hw)
 	I40E_WRITE_REG(hw, I40E_GLQF_PIT(17), 0x00007440);
 }
 
+#define I40E_FLOW_CONTROL_ETHERTYPE  0x8808
+
+/*
+ * Add a ethertype filter to drop all flow control frames transimited
+ * from VSIs.
+*/
+static void
+i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
+{
+	struct i40e_hw *hw = I40E_PF_TO_HW(pf);
+	uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
+			I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
+			I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
+	int ret;
+
+	ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
+				I40E_FLOW_CONTROL_ETHERTYPE, flags,
+				pf->main_vsi_seid, 0,
+				TRUE, NULL, NULL);
+	if (ret)
+		PMD_INIT_LOG(ERR, "Failed to add filter to drop flow control "
+				  " frames from VSIs.");
+}
+
 static int
 eth_i40e_dev_init(struct rte_eth_dev *dev)
 {
@@ -584,6 +608,12 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
 
 	/* enable uio intr after callback register */
 	rte_intr_enable(&(pci_dev->intr_handle));
+	/*
+	 * Add an ethertype filter to drop all flow control frames transimited
+	 * from VSIs. By doing so, we stop VF from sening out PAUSE or PFC
+	 * frames to wire.
+	 */
+	i40e_add_tx_flow_control_drop_filter(pf);
 
 	/* initialize mirror rule list */
 	TAILQ_INIT(&pf->mirror_list);
-- 
2.4.0