* [dts] [PATCH V2 1/3] tests/malicious_driver_event_indication: upload automation
2020-04-30 8:55 [dts] [PATCH V2 0/3] tests/malicious_driver_event_indication: upload test plan and automation script yufengmx
@ 2020-04-30 8:55 ` yufengmx
2020-04-30 8:55 ` [dts] [PATCH V2 2/3] tests/malicious_driver_event_indication: update test plan yufengmx
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: yufengmx @ 2020-04-30 8:55 UTC (permalink / raw)
To: dts, lei.a.yao; +Cc: yufengmx
script
Malicious driver event indication process in FVL PF driver.
Signed-off-by: yufengmx <yufengx.mo@intel.com>
---
...Suite_malicious_driver_event_indication.py | 327 ++++++++++++++++++
1 file changed, 327 insertions(+)
create mode 100644 tests/TestSuite_malicious_driver_event_indication.py
diff --git a/tests/TestSuite_malicious_driver_event_indication.py b/tests/TestSuite_malicious_driver_event_indication.py
new file mode 100644
index 0000000..87718d3
--- /dev/null
+++ b/tests/TestSuite_malicious_driver_event_indication.py
@@ -0,0 +1,327 @@
+# BSD LICENSE
+#
+# Copyright(c) 2010-2020 Intel Corporation. All rights reserved.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""
+DPDK Test suite.
+Malicious driver event indication process test suite.
+"""
+import os
+import re
+import time
+import traceback
+
+from exception import VerifyFailure
+from test_case import TestCase
+import utils
+
+
+class TestSuiteMaliciousDrvEventIndication(TestCase):
+
+ def d_con(self, cmd):
+ _cmd = [cmd, '# ', 10] if isinstance(cmd, str) else cmd
+ return self.dut.send_expect(*_cmd)
+
+ def d_a_con(self, cmd):
+ _cmd = [cmd, '# ', 10] if isinstance(cmd, str) else cmd
+ return self.dut.alt_session.send_expect(*_cmd)
+
+ def vf_pmd_con(self, cmd):
+ if not self.vf_pmd_session:
+ return
+ _cmd = [cmd, '# ', 10] if isinstance(cmd, str) else cmd
+ output = self.vf_pmd_session.session.send_expect(*_cmd)
+ return output
+
+ @property
+ def target_dir(self):
+ # get absolute directory of target source code
+ target_dir = '/root' + self.dut.base_dir[1:] \
+ if self.dut.base_dir.startswith('~') else \
+ self.dut.base_dir
+ return target_dir
+
+ def preset_dpdk_compilation(self):
+ cmd = ';'.join([
+ 'cd %s',
+ 'rm -f app/test-pmd/bak_txonly.c',
+ 'cp -f app/test-pmd/txonly.c app/test-pmd/bak_txonly.c',
+ "sed -i 's/nb_tx = rte_eth_tx_burst/for \(nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt\+\+\) "
+ "\{ pkts_burst\[nb_pkt\]->data_len = 15 ;\} nb_tx = rte_eth_tx_burst/g' app/test-pmd/txonly.c"]) % self.target_dir
+ self.d_a_con(cmd)
+ # rebuild dpdk source code
+ self.dut.build_install_dpdk(self.target)
+
+ def restore_dpdk_compilation(self):
+ cmd = ';'.join([
+ 'cd {target}',
+ 'rm -f app/test-pmd/txonly.c',
+ 'cp -f app/test-pmd/bak_txonly.c app/test-pmd/txonly.c',
+ ]).format(**{
+ 'target': self.target_dir, })
+ self.d_a_con(cmd)
+ # rebuild dpdk source code
+ self.dut.build_install_dpdk(self.target)
+
+ def vf_create(self):
+ port_id = 0
+ port_obj = self.dut.ports_info[port_id]['port']
+ self.dut.generate_sriov_vfs_by_port(port_id, 1)
+ pf_pci = port_obj.pci
+ sriov_vfs_port = self.dut.ports_info[port_id].get('vfs_port')
+ if not sriov_vfs_port:
+ msg = "failed to create vf on dut port {}".format(pf_pci)
+ raise VerifyFailure(msg)
+ for port in sriov_vfs_port:
+ port.bind_driver(driver=self.drivername)
+ vf_mac = "00:12:34:56:78:01"
+ self.vf_ports_info[port_id] = {
+ 'pf_pci': pf_pci,
+ 'vfs_pci': port_obj.get_sriov_vfs_pci(),
+ 'vf_mac': vf_mac, }
+ time.sleep(1)
+
+ def vf_destroy(self):
+ if not self.vf_ports_info:
+ return
+ for port_id, _ in self.vf_ports_info.items():
+ self.dut.destroy_sriov_vfs_by_port(port_id)
+ port_obj = self.dut.ports_info[port_id]['port']
+ port_obj.bind_driver(self.drivername)
+ self.vf_ports_info = None
+
+ def init_pf_testpmd(self):
+ self.pf_testpmd = "{}/{}/app/testpmd".format(
+ self.target_dir, self.dut.target)
+
+ def start_pf_testpmd(self):
+ core_mask = utils.create_mask(self.pf_pmd_cores)
+ cmd = (
+ "{bin} "
+ "-v "
+ "-c {core_mask} "
+ "-n {mem_channel} "
+ "--file-prefix={prefix} "
+ "{whitelist} "
+ "-- -i ").format(**{
+ 'bin': self.pf_testpmd,
+ 'core_mask': core_mask,
+ 'mem_channel': self.dut.get_memory_channels(),
+ 'whitelist': self.pf_pmd_whitelist,
+ 'prefix': 'pf_pmd', })
+ self.d_con([cmd, "testpmd> ", 120])
+ self.is_pf_pmd_on = True
+ time.sleep(1)
+
+ def close_pf_testpmd(self):
+ if not self.is_pf_pmd_on:
+ return
+ self.d_con(['quit', '# ', 15])
+ self.is_pf_pmd_on = False
+
+ def get_pf_testpmd_reponse(self):
+ output = self.dut.get_session_output(timeout=2)
+ return output
+
+ def init_vf_testpmd(self):
+ self.vf_pmd_session_name = 'vf_testpmd'
+ self.vf_pmd_session = self.dut.create_session(self.vf_pmd_session_name)
+ self.vf_testpmd = "{}/{}/app/testpmd_vf".format(
+ self.target_dir, self.dut.target)
+ cmd = 'rm -f {vf_pmd};cp -f {pf_pmd} {vf_pmd}'.format(
+ **{'pf_pmd': self.pf_testpmd, 'vf_pmd': self.vf_testpmd})
+ self.d_a_con(cmd)
+
+ def start_vf_testpmd(self):
+ core_mask = utils.create_mask(self.vf_pmd_cores)
+ cmd = (
+ "{bin} "
+ "-v "
+ "-c {core_mask} "
+ "-n {mem_channel} "
+ "--file-prefix={prefix} "
+ "{whitelist} "
+ "-- -i ").format(**{
+ 'bin': self.vf_testpmd,
+ 'core_mask': core_mask,
+ 'mem_channel': self.dut.get_memory_channels(),
+ 'whitelist': self.vf_pmd_whitelist,
+ 'prefix': 'vf_pmd', })
+ self.vf_pmd_con([cmd, "testpmd> ", 120])
+ self.is_vf_pmd_on = True
+ cmds = [
+ 'set fwd txonly',
+ 'start', ]
+ [self.vf_pmd_con([cmd, "testpmd> ", 15]) for cmd in cmds]
+ time.sleep(1)
+
+ def close_vf_testpmd(self):
+ if not self.is_vf_pmd_on:
+ return
+ self.vf_pmd_con(['quit', '# ', 15])
+ self.is_vf_pmd_on = False
+
+ def get_vf_testpmd_reponse(self):
+ if not self.vf_pmd_session:
+ return ''
+ output = self.vf_pmd_session.session.get_output_all()
+ return output
+
+ def check_event_is_detected(self):
+ pf_output = self.get_pf_testpmd_reponse()
+ expected_strs = [
+ 'malicious programming detected',
+ 'TX driver issue detected on PF',
+ 'TX driver issue detected on VF 0 1times', ]
+ for expected_str in expected_strs:
+ msg = "'{}' not display".format(expected_str)
+ self.verify(expected_str in pf_output, msg)
+ pat = 'Malicious Driver Detection event 0x(\d+) on TX queue (\d+) PF number 0x(\d+) VF number 0x(\d+) device ' + self.vf_ports_info[0].get('pf_pci')
+ result = re.findall(pat, pf_output)
+ msg = "'Malicious Driver Detection event not detected"
+ self.verify(result and len(result), msg)
+
+ def check_event_counter_number(self, total):
+ pf_output = self.get_pf_testpmd_reponse()
+ expected_str = "TX driver issue detected on VF 0 {0}times".format(total)
+ msg = "'{}' not display".format(expected_str)
+ self.verify(expected_str in pf_output, msg)
+
+ def verify_malicious_driver_event_detected(self):
+ except_content = None
+ try:
+ self.start_pf_testpmd()
+ self.start_vf_testpmd()
+ self.check_event_is_detected()
+ except Exception as e:
+ self.logger.error(traceback.format_exc())
+ except_content = e
+ finally:
+ self.close_vf_testpmd()
+ self.close_pf_testpmd()
+ # re-raise verify exception result
+ if except_content:
+ raise VerifyFailure(except_content)
+
+ def verify_malicious_driver_event_counter_number(self):
+ except_content = None
+ try:
+ self.start_pf_testpmd()
+ total = 3
+ for _ in range(total):
+ self.start_vf_testpmd()
+ self.close_vf_testpmd()
+ self.check_event_counter_number(total)
+ except Exception as e:
+ self.logger.error(traceback.format_exc())
+ except_content = e
+ finally:
+ self.close_vf_testpmd()
+ self.close_pf_testpmd()
+ # re-raise verify exception result
+ if except_content:
+ raise VerifyFailure(except_content)
+
+ def verify_supported_nic(self):
+ supported_drivers = ['i40e']
+ result = all([self.dut.ports_info[index]['port'].default_driver in
+ supported_drivers
+ for index in self.dut_ports])
+ msg = "current nic <0> is not supported".format(self.nic)
+ self.verify(result, msg)
+
+ def preset_pmd_res(self):
+ # get whitelist and cores
+ socket = self.dut.get_numa_id(self.dut_ports[0])
+ corelist = self.dut.get_core_list("1S/6C/1T", socket=socket)[2:]
+ self.pf_pmd_whitelist = '-w ' + self.vf_ports_info[0].get('pf_pci')
+ self.pf_pmd_cores = corelist[:2]
+ self.vf_pmd_whitelist = '-w ' + self.vf_ports_info[0].get('vfs_pci')[0]
+ self.vf_pmd_cores = corelist[2:]
+
+ def preset_test_environment(self):
+ self.is_pf_pmd_on = self.is_vf_pmd_on = None
+ self.vf_ports_info = {}
+ self.preset_dpdk_compilation()
+ self.init_pf_testpmd()
+ self.init_vf_testpmd()
+ self.vf_create()
+ # get socket and cores
+ self.preset_pmd_res()
+
+ def destroy_resource(self):
+ self.vf_destroy()
+ if self.vf_pmd_session:
+ self.dut.close_session(self.vf_pmd_session)
+ self.vf_pmd_session = None
+ self.restore_dpdk_compilation()
+
+ #
+ # Test cases.
+ #
+ def set_up_all(self):
+ """
+ Run at the start of each test suite.
+ """
+ self.dut_ports = self.dut.get_ports(self.nic)
+ self.verify(len(self.dut_ports) >= 1, "Not enough ports")
+ self.verify_supported_nic()
+ # prepare testing environment
+ self.preset_test_environment()
+
+ def tear_down_all(self):
+ """
+ Run after each test suite.
+ """
+ self.destroy_resource()
+
+ def set_up(self):
+ """
+ Run before each test case.
+ """
+ pass
+
+ def tear_down(self):
+ """
+ Run after each test case.
+ """
+ self.dut.kill_all()
+
+ def test_malicious_driver_event_detected(self):
+ """
+ Check log output when malicious driver events is detected
+ """
+ self.verify_malicious_driver_event_detected()
+
+ def test_malicious_driver_event_counter_number(self):
+ """
+ Check the event counter number for malicious driver events
+ """
+ self.verify_malicious_driver_event_counter_number()
--
2.21.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [dts] [PATCH V2 2/3] tests/malicious_driver_event_indication: update test plan
2020-04-30 8:55 [dts] [PATCH V2 0/3] tests/malicious_driver_event_indication: upload test plan and automation script yufengmx
2020-04-30 8:55 ` [dts] [PATCH V2 1/3] tests/malicious_driver_event_indication: upload automation yufengmx
@ 2020-04-30 8:55 ` yufengmx
2020-04-30 8:55 ` [dts] [PATCH V2 3/3] tests/malicious_driver_event_indication: add " yufengmx
2020-05-06 1:40 ` [dts] [PATCH V2 0/3] tests/malicious_driver_event_indication: upload test plan and automation script Mo, YufengX
3 siblings, 0 replies; 5+ messages in thread
From: yufengmx @ 2020-04-30 8:55 UTC (permalink / raw)
To: dts, lei.a.yao; +Cc: yufengmx
Malicious driver event indication process in FVL PF driver.
Signed-off-by: yufengmx <yufengx.mo@intel.com>
---
...ious_driver_event_indication_test_plan.rst | 96 +++++++++++++++++++
1 file changed, 96 insertions(+)
create mode 100644 test_plans/malicious_driver_event_indication_test_plan.rst
diff --git a/test_plans/malicious_driver_event_indication_test_plan.rst b/test_plans/malicious_driver_event_indication_test_plan.rst
new file mode 100644
index 0000000..2813df8
--- /dev/null
+++ b/test_plans/malicious_driver_event_indication_test_plan.rst
@@ -0,0 +1,96 @@
+.. Copyright (c) <2019>, Intel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Intel Corporation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE.
+
+==========================================================
+Malicious driver event indication process in FVL PF driver
+==========================================================
+
+Need modify the testpmd APP to generate invalid packets in tx only mode
+
+.. code-block:: console
+
+ diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
+ index 3caf281cb..448aab715 100644
+ --- a/app/test-pmd/txonly.c
+ +++ b/app/test-pmd/txonly.c
+ @@ -299,6 +299,11 @@ pkt_burst_transmit(struct fwd_stream *fs)
+ if (nb_pkt == 0)
+ return;
+
+ + for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++){
+ + pkts_burst[nb_pkt]->data_len = 15;
+ + }
+ +
+ +
+ nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
+ /*
+ * Retry if necessary
+
+
+Test Case1: Check log output when malicious driver events is detected
+======================================================================
+1. Generate i40e VF when PF is binded to igb_uio driver
+ echo 1 > /sys/bus/pci/devices/0000\:18\:00.1/max_vfs
+
+2. Launch PF by testpmd
+ ./x86_64-native-linuxapp-gcc/app/testpmd -c 0x03 -n 4 --file-prefix=test1 -w [pic of PF] -- -i
+
+3. Launch VF by testpmd
+ ./x86_64-native-linuxapp-gcc/app/testpmd -c 0x03 -n 4 --file-prefix=lei1 -w [pic of VF] -- -i
+ > set fwd txonly
+ > start
+
+4. Check the PF can detect the VF's unexpected behavior and output warning log
+ testpmd>
+ i40e_dev_alarm_handler(): ICR0: malicious programming detected
+ i40e_handle_mdd_event(): Malicious Driver Detection event 0x00 on TX queue 65 PF number 0x01 VF number 0x40 device 0000:18:00.1
+ i40e_handle_mdd_event(): TX driver issue detected on PF
+ i40e_handle_mdd_event(): TX driver issue detected on VF 0 1times
+
+
+Test Case2: Check the event counter number for malicious driver events
+=======================================================================
+1. Generate i40e VF when PF is binded to igb_uio driver
+ echo 1 > /sys/bus/pci/devices/0000\:18\:00.1/max_vfs
+
+2. Launch PF by testpmd
+ ./x86_64-native-linuxapp-gcc/app/testpmd -c 0x03 -n 4 --file-prefix=test1 -w [pic of PF] -- -i
+
+3. launch VF by testpmd and start txonly mode 3 times:
+ repeat following step 3 times
+ ./x86_64-native-linuxapp-gcc/app/testpmd -c 0x03 -n 4 --file-prefix=lei1 -w [pic of VF] -- -i
+ > set fwd txonly
+ > start
+ > quit
+
+4. Check the PF can detect the malicious driver events number directly in the log:
+ i40e_handle_mdd_event(): TX driver issue detected on VF 0 3times
\ No newline at end of file
--
2.21.0
^ permalink raw reply [flat|nested] 5+ messages in thread