From: Yishai Hadas <yishaih@nvidia.com>
To: <linux-rdma@vger.kernel.org>
Cc: <jgg@nvidia.com>, <yishaih@nvidia.com>, <maorg@nvidia.com>,
<markzhang@nvidia.com>, <edwards@nvidia.com>,
Ido Kalir <idok@nvidia.com>
Subject: [PATCH rdma-core 27/27] tests: Add a test for mlx5 over VFIO
Date: Tue, 20 Jul 2021 11:16:47 +0300 [thread overview]
Message-ID: <20210720081647.1980-28-yishaih@nvidia.com> (raw)
In-Reply-To: <20210720081647.1980-1-yishaih@nvidia.com>
From: Edward Srouji <edwards@nvidia.com>
Add a test that opens an mlx5 vfio context, creates two DevX QPs on
it, and modifies them to RTS state. Then performs traffic with SEND_IMM.
An additional cmd line argument was added for the tests, to allow users
to pass a PCI device instead of an RDMA device for this test.
Reviewed-by: Ido Kalir <idok@nvidia.com>
Signed-off-by: Edward Srouji <edwards@nvidia.com>
---
tests/CMakeLists.txt | 1 +
tests/args_parser.py | 5 +++
tests/test_mlx5_vfio.py | 104 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 110 insertions(+)
create mode 100644 tests/test_mlx5_vfio.py
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7b079d8..cabeba0 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -36,6 +36,7 @@ rdma_python_test(tests
test_mlx5_uar.py
test_mlx5_udp_sport.py
test_mlx5_var.py
+ test_mlx5_vfio.py
test_mr.py
test_odp.py
test_pd.py
diff --git a/tests/args_parser.py b/tests/args_parser.py
index 5bc53b0..4312121 100644
--- a/tests/args_parser.py
+++ b/tests/args_parser.py
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright (c) 2020 Kamal Heib <kamalheib1@gmail.com>, All rights reserved. See COPYING file
+# Copyright (c) 2021 Nvidia, Inc. All rights reserved. See COPYING file
import argparse
import sys
@@ -16,6 +17,10 @@ class ArgsParser(object):
parser = argparse.ArgumentParser()
parser.add_argument('--dev',
help='RDMA device to run the tests on')
+ parser.add_argument('--pci-dev',
+ help='PCI device to run the tests on, which is '
+ 'needed by some tests where the RDMA device is '
+ 'not available (e.g. VFIO)')
parser.add_argument('--port',
help='Use port <port> of RDMA device', type=int,
default=1)
diff --git a/tests/test_mlx5_vfio.py b/tests/test_mlx5_vfio.py
new file mode 100644
index 0000000..06da8dd
--- /dev/null
+++ b/tests/test_mlx5_vfio.py
@@ -0,0 +1,104 @@
+# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
+# Copyright (c) 2021 Nvidia, Inc. All rights reserved. See COPYING file
+"""
+Test module for pyverbs' mlx5_vfio module.
+"""
+
+from threading import Thread
+import unittest
+import select
+import errno
+
+from pyverbs.providers.mlx5.mlx5_vfio import Mlx5VfioAttr, Mlx5VfioContext
+from tests.mlx5_base import Mlx5DevxRcResources, Mlx5DevxTrafficBase
+from pyverbs.pyverbs_error import PyverbsRDMAError
+
+
+class Mlx5VfioResources(Mlx5DevxRcResources):
+ def __init__(self, ib_port, pci_name, gid_index=None, ctx=None):
+ self.pci_name = pci_name
+ self.ctx = ctx
+ super().__init__(None, ib_port, gid_index)
+
+ def create_context(self):
+ """
+ Opens an mlx5 VFIO context.
+ Since only one context is allowed to be opened on a VFIO, the user must
+ pass that context for the remaining resources, which in that case, the
+ same context would be used.
+ :return: None
+ """
+ if self.ctx:
+ return
+ try:
+ vfio_attr = Mlx5VfioAttr(pci_name=self.pci_name)
+ vfio_attr.pci_name = self.pci_name
+ self.ctx = Mlx5VfioContext(attr=vfio_attr)
+ except PyverbsRDMAError as ex:
+ if ex.error_code == errno.EOPNOTSUPP:
+ raise unittest.SkipTest(f'Mlx5 VFIO is not supported ({ex})')
+ raise ex
+
+ def query_gid(self):
+ """
+ Currently Mlx5VfioResources does not support Eth port type.
+ Query GID would just be skipped.
+ """
+ pass
+
+
+class Mlx5VfioTrafficTest(Mlx5DevxTrafficBase):
+ """
+ Test various functionality of an mlx5-vfio device.
+ """
+ def setUp(self):
+ """
+ Verifies that the user has passed a PCI device name to work with.
+ """
+ self.pci_dev = self.config['pci_dev']
+ if not self.pci_dev:
+ raise unittest.SkipTest('PCI device must be passed by the user')
+
+ def create_players(self):
+ self.server = Mlx5VfioResources(ib_port=self.ib_port, pci_name=self.pci_dev)
+ self.client = Mlx5VfioResources(ib_port=self.ib_port, pci_name=self.pci_dev,
+ ctx=self.server.ctx)
+
+ def vfio_processs_events(self):
+ """
+ Processes mlx5 vfio device events.
+ This method should run from application thread to maintain the events.
+ """
+ # Server and client use the same context
+ events_fd = self.server.ctx.get_events_fd()
+ with select.epoll() as epoll_events:
+ epoll_events.register(events_fd, select.EPOLLIN)
+ while self.proc_events:
+ for fd, event in epoll_events.poll(timeout=0.1):
+ if fd == events_fd:
+ if not (event & select.EPOLLIN):
+ self.event_ex.append(PyverbsRDMAError(f'Unexpected vfio event: {event}'))
+ self.server.ctx.process_events()
+
+ def test_mlx5vfio_rc_qp_send_imm_traffic(self):
+ """
+ Opens one mlx5 vfio context, creates two DevX RC QPs on it, and modifies
+ them to RTS state.
+ Then does SEND_IMM traffic.
+ """
+ self.create_players()
+ if self.server.is_eth():
+ raise unittest.SkipTest(f'{self.__class__.__name__} is currently supported over IB only')
+ self.event_ex = []
+ self.proc_events = True
+ proc_events = Thread(target=self.vfio_processs_events)
+ proc_events.start()
+ # Move the DevX QPs ro RTS state
+ self.pre_run()
+ # Send traffic
+ self.send_imm_traffic()
+ # Stop listening to events
+ self.proc_events = False
+ proc_events.join()
+ if self.event_ex:
+ raise PyverbsRDMAError(f'Received unexpected vfio events: {self.event_ex}')
--
1.8.3.1
next prev parent reply other threads:[~2021-07-20 8:18 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-20 8:16 [PATCH rdma-core 00/27] Introduce mlx5 user space driver over VFIO Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 01/27] Update kernel headers Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 02/27] mlx5: Introduce mlx5dv_get_vfio_device_list() Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 03/27] mlx5: Enable debug functionality for vfio Yishai Hadas
2021-07-20 8:51 ` Leon Romanovsky
2021-07-20 9:27 ` Yishai Hadas
2021-07-20 12:27 ` Leon Romanovsky
2021-07-20 14:57 ` Yishai Hadas
2021-07-21 7:05 ` Gal Pressman
2021-07-21 7:58 ` Yishai Hadas
2021-07-21 8:51 ` Gal Pressman
2021-07-20 8:16 ` [PATCH rdma-core 04/27] util: Add interval_set support Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 05/27] verbs: Enable verbs_open_device() to work over non sysfs devices Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 06/27] mlx5: Setup mlx5 vfio context Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 07/27] mlx5: Add mlx5_vfio_cmd_exec() support Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 08/27] mlx5: vfio setup function support Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 09/27] mlx5: vfio setup basic caps Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 10/27] mlx5: Support fast teardown over vfio Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 11/27] mlx5: Enable interrupt command mode " Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 12/27] mlx5: Introduce vfio APIs to process events Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 13/27] mlx5: VFIO poll_health support Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 14/27] mlx5: Implement basic verbs operation for PD and MR over vfio Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 15/27] mlx5: Set DV context ops Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 16/27] mlx5: Support initial DEVX/DV APIs over vfio Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 17/27] mlx5: Implement mlx5dv devx_obj " Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 18/27] pyverbs: Support DevX UMEM registration Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 19/27] pyverbs/mlx5: Support EQN querying Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 20/27] pyverbs/mlx5: Support more DevX objects Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 21/27] pyverbs: Add auxiliary memory functions Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 22/27] pyverbs/mlx5: Add support to extract mlx5dv objects Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 23/27] pyverbs/mlx5: Wrap mlx5_cqe64 struct and add enums Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 24/27] tests: Add MAC address to the tests' args Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 25/27] tests: Add mlx5 DevX data path test Yishai Hadas
2021-07-20 8:16 ` [PATCH rdma-core 26/27] pyverbs/mlx5: Support mlx5 devices over VFIO Yishai Hadas
2021-07-20 8:16 ` Yishai Hadas [this message]
2021-08-01 8:00 ` [PATCH rdma-core 00/27] Introduce mlx5 user space driver " Yishai Hadas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210720081647.1980-28-yishaih@nvidia.com \
--to=yishaih@nvidia.com \
--cc=edwards@nvidia.com \
--cc=idok@nvidia.com \
--cc=jgg@nvidia.com \
--cc=linux-rdma@vger.kernel.org \
--cc=maorg@nvidia.com \
--cc=markzhang@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).