1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
|
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file
# Copyright (c) 2020 Kamal Heib <kamalheib1@gmail.com>, All rights reserved. See COPYING file
# Copyright 2020-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
"""
Test module for pyverbs' qp module.
"""
import unittest
import random
import errno
import os
from pyverbs.pyverbs_error import PyverbsRDMAError
from pyverbs.qp import QPAttr, QP
from tests.base import PyverbsAPITestCase, RDMATestCase, RCResources
import pyverbs.utils as pu
import pyverbs.device as d
from pyverbs.libibverbs_enums import ibv_qp_type, ibv_qp_state, ibv_qp_attr_mask, ibv_node_type, \
ibv_wr_opcode, ibv_query_qp_data_in_order_flags, ibv_query_qp_data_in_order_caps
from pyverbs.pd import PD
from pyverbs.cq import CQ
import tests.utils as u
class QPTest(PyverbsAPITestCase):
"""
Test various functionalities of the QP class.
"""
def create_qp(self, creator, qp_init_attr, is_ex, with_attr, port_num):
"""
Auxiliary function to create QP object.
"""
try:
qp_attr = (None, QPAttr(port_num=port_num))[with_attr]
return QP(creator, qp_init_attr, qp_attr)
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
with_str = ('without', 'with')[with_attr] + ('', ' extended')[is_ex]
qp_type_str = pu.qp_type_to_str(qp_init_attr.qp_type)
raise unittest.SkipTest(f'Create {qp_type_str} QP {with_str} attrs is not supported')
raise ex
def create_qp_common_test(self, qp_type, qp_state, is_ex, with_attr, qp_attr_edit_callback=None):
"""
Common function used by create QP tests.
"""
with PD(self.ctx) as pd:
with CQ(self.ctx, 100, None, None, 0) as cq:
if qp_type == ibv_qp_type.IBV_QPT_RAW_PACKET:
if not (u.is_eth(self.ctx, self.ib_port) and u.has_cap_net_raw()):
raise unittest.SkipTest('To Create RAW QP must be done by user with '\
'CAP_NET_RAW on Ethernet link layer')
if is_ex:
qia = get_qp_init_attr_ex(cq, pd, self.attr, self.attr_ex, qp_type)
creator = self.ctx
else:
qia = u.get_qp_init_attr(cq, self.attr)
qia.qp_type = qp_type
creator = pd
if qp_attr_edit_callback:
qia = qp_attr_edit_callback(qia)
qp = self.create_qp(creator, qia, is_ex, with_attr, self.ib_port)
qp_type_str = pu.qp_type_to_str(qp_type)
qp_state_str = pu.qp_state_to_str(qp_state)
assert qp.qp_state == qp_state , f'{qp_type_str} QP should have been in {qp_state_str}'
def test_create_rc_qp_no_attr(self):
"""
Test RC QP creation via ibv_create_qp without a QPAttr object provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_RC, ibv_qp_state.IBV_QPS_RESET, False, False)
def test_create_uc_qp_no_attr(self):
"""
Test UC QP creation via ibv_create_qp without a QPAttr object provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UC, ibv_qp_state.IBV_QPS_RESET, False, False)
def test_create_ud_qp_no_attr(self):
"""
Test UD QP creation via ibv_create_qp without a QPAttr object provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UD, ibv_qp_state.IBV_QPS_RESET, False, False)
def test_create_raw_qp_no_attr(self):
"""
Test RAW Packet QP creation via ibv_create_qp without a QPAttr object
provided.
Raw Packet is skipped for non-root users / Infiniband link layer.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_RAW_PACKET, ibv_qp_state.IBV_QPS_RESET, False, False)
def test_create_rc_qp_with_attr(self):
"""
Test RC QP creation via ibv_create_qp with a QPAttr object provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_RC, ibv_qp_state.IBV_QPS_INIT, False, True)
def test_create_uc_qp_with_attr(self):
"""
Test UC QP creation via ibv_create_qp with a QPAttr object provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UC, ibv_qp_state.IBV_QPS_INIT, False, True)
def test_create_ud_qp_with_attr(self):
"""
Test UD QP creation via ibv_create_qp with a QPAttr object provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UD, ibv_qp_state.IBV_QPS_RTS, False, True)
def test_create_raw_qp_with_attr(self):
"""
Test RAW Packet QP creation via ibv_create_qp with a QPAttr object
provided.
Raw Packet is skipped for non-root users / Infiniband link layer.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_RAW_PACKET, ibv_qp_state.IBV_QPS_RTS, False, True)
def test_create_rc_qp_ex_no_attr(self):
"""
Test RC QP creation via ibv_create_qp_ex without a QPAttr object
provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_RC, ibv_qp_state.IBV_QPS_RESET, True, False)
def test_create_uc_qp_ex_no_attr(self):
"""
Test UC QP creation via ibv_create_qp_ex without a QPAttr object
provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UC, ibv_qp_state.IBV_QPS_RESET, True, False)
def test_create_ud_qp_ex_no_attr(self):
"""
Test UD QP creation via ibv_create_qp_ex without a QPAttr object
provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UD, ibv_qp_state.IBV_QPS_RESET, True, False)
def test_create_raw_qp_ex_no_attr(self):
"""
Test Raw Packet QP creation via ibv_create_qp_ex without a QPAttr object
provided.
Raw Packet is skipped for non-root users / Infiniband link layer.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_RAW_PACKET, ibv_qp_state.IBV_QPS_RESET, True, False)
def test_create_rc_qp_ex_with_attr(self):
"""
Test RC QP creation via ibv_create_qp_ex with a QPAttr object provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_RC, ibv_qp_state.IBV_QPS_INIT, True, True)
def test_create_uc_qp_ex_with_attr(self):
"""
Test UC QP creation via ibv_create_qp_ex with a QPAttr object provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UC, ibv_qp_state.IBV_QPS_INIT, True, True)
def test_create_ud_qp_ex_with_attr(self):
"""
Test UD QP creation via ibv_create_qp_ex with a QPAttr object provided.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UD, ibv_qp_state.IBV_QPS_RTS, True, True)
def test_create_raw_qp_ex_with_attr(self):
"""
Test Raw Packet QP creation via ibv_create_qp_ex with a QPAttr object
provided.
Raw Packet is skipped for non-root users / Infiniband link layer.
"""
self.create_qp_common_test(ibv_qp_type.IBV_QPT_RAW_PACKET, ibv_qp_state.IBV_QPS_RTS, True, True)
def qp_attr_edit_max_send_wr_callback(self, qp_init_attr):
qp_init_attr.max_send_wr = 0xffffffff # max_uint32
return qp_init_attr
def qp_attr_edit_max_send_sge_callback(self, qp_init_attr):
qp_init_attr.max_send_sge = 0xffff # max_uint16
return qp_init_attr
def qp_attr_edit_max_recv_sge_callback(self, qp_init_attr):
qp_init_attr.max_recv_sge = 0xffff # max_uint16
return qp_init_attr
def qp_attr_edit_max_recv_wr_callback(self, qp_init_attr):
qp_init_attr.max_recv_wr = 0xffffffff # max_uint32
return qp_init_attr
def test_create_raw_qp_ex_with_illegal_caps_max_send_wr(self):
"""
Test Raw Packet QP creation via ibv_create_qp_ex with a QPAttr object with illegal max_send_wr.
"""
dev_attr = self.ctx.query_device()
if dev_attr.max_qp_wr < 0xffffffff:
with self.assertRaises(PyverbsRDMAError) as ex:
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UD, ibv_qp_state.IBV_QPS_RTS, False, True,
qp_attr_edit_callback=self.qp_attr_edit_max_send_wr_callback)
self.assertNotEqual(ex.exception.error_code, 0)
def test_create_raw_qp_ex_with_illegal_caps_max_send_sge(self):
"""
Test Raw Packet QP creation via ibv_create_qp_ex with a QPAttr object with illegal max_send_sge.
"""
dev_attr = self.ctx.query_device()
if dev_attr.max_sge < 0xffff:
with self.assertRaises(PyverbsRDMAError) as ex:
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UD, ibv_qp_state.IBV_QPS_RTS, False, True,
qp_attr_edit_callback=self.qp_attr_edit_max_send_sge_callback)
self.assertNotEqual(ex.exception.error_code, 0)
def test_create_raw_qp_ex_with_illegal_caps_max_recv_sge(self):
"""
Test Raw Packet QP creation via ibv_create_qp_ex with a QPAttr object with illegal max_recv_sge.
"""
dev_attr = self.ctx.query_device()
if dev_attr.max_sge < 0xffff:
with self.assertRaises(PyverbsRDMAError) as ex:
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UD, ibv_qp_state.IBV_QPS_RTS, False, True,
qp_attr_edit_callback=self.qp_attr_edit_max_recv_sge_callback)
self.assertNotEqual(ex.exception.error_code, 0)
def test_create_raw_qp_ex_with_illegal_caps_max_recv_wr(self):
"""
Test Raw Packet QP creation via ibv_create_qp_ex with a QPAttr object with illegal max_recv_wr.
"""
dev_attr = self.ctx.query_device()
if dev_attr.max_qp_wr < 0xffffffff:
with self.assertRaises(PyverbsRDMAError) as ex:
self.create_qp_common_test(ibv_qp_type.IBV_QPT_UD, ibv_qp_state.IBV_QPS_RTS, False, True,
qp_attr_edit_callback=self.qp_attr_edit_max_recv_wr_callback)
self.assertNotEqual(ex.exception.error_code, 0)
def verify_qp_attrs(self, orig_cap, state, init_attr, attr):
self.assertEqual(state, attr.qp_state)
self.assertLessEqual(orig_cap.max_send_wr, init_attr.cap.max_send_wr)
self.assertLessEqual(orig_cap.max_recv_wr, init_attr.cap.max_recv_wr)
self.assertLessEqual(orig_cap.max_send_sge, init_attr.cap.max_send_sge)
self.assertLessEqual(orig_cap.max_recv_sge, init_attr.cap.max_recv_sge)
self.assertLessEqual(orig_cap.max_inline_data, init_attr.cap.max_inline_data)
def get_node_type(self):
for dev in d.get_device_list():
if dev.name.decode() == self.ctx.name:
return dev.node_type
def query_qp_common_test(self, qp_type):
with PD(self.ctx) as pd:
with CQ(self.ctx, 100, None, None, 0) as cq:
if qp_type == ibv_qp_type.IBV_QPT_RAW_PACKET:
if not (u.is_eth(self.ctx, self.ib_port) and u.has_cap_net_raw()):
raise unittest.SkipTest('To Create RAW QP must be done by user with '\
'CAP_NET_RAW on Ethernet link layer')
# Legacy QP
qia = u.get_qp_init_attr(cq, self.attr)
qia.qp_type = qp_type
caps = qia.cap
qp = self.create_qp(pd, qia, False, False, self.ib_port)
qp_attr, qp_init_attr = qp.query(ibv_qp_attr_mask.IBV_QP_STATE | ibv_qp_attr_mask.IBV_QP_CAP)
if self.get_node_type() == ibv_node_type.IBV_NODE_RNIC:
self.verify_qp_attrs(caps, ibv_qp_state.IBV_QPS_INIT, qp_init_attr, qp_attr)
else:
self.verify_qp_attrs(caps, ibv_qp_state.IBV_QPS_RESET, qp_init_attr, qp_attr)
# Extended QP
qia = get_qp_init_attr_ex(cq, pd, self.attr, self.attr_ex, qp_type)
caps = qia.cap # Save them to verify values later
qp = self.create_qp(self.ctx, qia, True, False, self.ib_port)
qp_attr, qp_init_attr = qp.query(ibv_qp_attr_mask.IBV_QP_STATE | ibv_qp_attr_mask.IBV_QP_CAP)
if self.get_node_type() == ibv_node_type.IBV_NODE_RNIC:
self.verify_qp_attrs(caps, ibv_qp_state.IBV_QPS_INIT, qp_init_attr, qp_attr)
else:
self.verify_qp_attrs(caps, ibv_qp_state.IBV_QPS_RESET, qp_init_attr, qp_attr)
def test_query_rc_qp(self):
"""
Queries an RC QP after creation. Verifies that its properties are as
expected.
"""
self.query_qp_common_test(ibv_qp_type.IBV_QPT_RC)
def test_query_uc_qp(self):
"""
Queries an UC QP after creation. Verifies that its properties are as
expected.
"""
self.query_qp_common_test(ibv_qp_type.IBV_QPT_UC)
def test_query_ud_qp(self):
"""
Queries an UD QP after creation. Verifies that its properties are as
expected.
"""
self.query_qp_common_test(ibv_qp_type.IBV_QPT_UD)
def test_query_raw_qp(self):
"""
Queries an RAW Packet QP after creation. Verifies that its properties
are as expected.
Raw Packet is skipped for non-root users / Infiniband link layer.
"""
self.query_qp_common_test(ibv_qp_type.IBV_QPT_RAW_PACKET)
def test_query_data_in_order(self):
"""
Queries an UD QP data in order after moving it to RTS state.
Verifies that the result from the query is valid.
"""
with PD(self.ctx) as pd:
with CQ(self.ctx, 100, None, None, 0) as cq:
qia = u.get_qp_init_attr(cq, self.attr)
qia.qp_type = ibv_qp_type.IBV_QPT_UD
qp = self.create_qp(pd, qia, False, True, self.ib_port)
is_data_in_order = qp.query_data_in_order(ibv_wr_opcode.IBV_WR_SEND)
self.assertIn(is_data_in_order, [0, 1], 'Data in order result with flags=0 is not valid')
is_data_in_order = qp.query_data_in_order(ibv_wr_opcode.IBV_WR_SEND,
ibv_query_qp_data_in_order_flags.IBV_QUERY_QP_DATA_IN_ORDER_RETURN_CAPS)
valid_results = [0,
ibv_query_qp_data_in_order_caps.IBV_QUERY_QP_DATA_IN_ORDER_ALIGNED_128_BYTES,
ibv_query_qp_data_in_order_caps.IBV_QUERY_QP_DATA_IN_ORDER_WHOLE_MSG | \
ibv_query_qp_data_in_order_caps.IBV_QUERY_QP_DATA_IN_ORDER_ALIGNED_128_BYTES]
self.assertIn(is_data_in_order, valid_results, 'Data in order result with flags=1 is not valid')
@u.skip_unsupported
def test_modify_ud_qp(self):
"""
Queries a UD QP after calling modify(). Verifies that its properties are
as expected.
"""
with PD(self.ctx) as pd:
with CQ(self.ctx, 100, None, None, 0) as cq:
# Legacy QP
qia = u.get_qp_init_attr(cq, self.attr)
qia.qp_type = ibv_qp_type.IBV_QPT_UD
qp = self.create_qp(pd, qia, False, False, self.ib_port)
qa = QPAttr()
qa.qkey = 0x123
qp.to_init(qa)
qp_attr, _ = qp.query(ibv_qp_attr_mask.IBV_QP_QKEY)
assert qp_attr.qkey == qa.qkey, 'Legacy QP, QKey is not as expected'
qp.to_rtr(qa)
qa.sq_psn = 0x45
qp.to_rts(qa)
qp_attr, _ = qp.query(ibv_qp_attr_mask.IBV_QP_SQ_PSN)
assert qp_attr.sq_psn == qa.sq_psn, 'Legacy QP, SQ PSN is not as expected'
qa.qp_state = ibv_qp_state.IBV_QPS_RESET
qp.modify(qa, ibv_qp_attr_mask.IBV_QP_STATE)
assert qp.qp_state == ibv_qp_state.IBV_QPS_RESET, 'Legacy QP, QP state is not as expected'
# Extended QP
qia = get_qp_init_attr_ex(cq, pd, self.attr, self.attr_ex, ibv_qp_type.IBV_QPT_UD)
qp = self.create_qp(self.ctx, qia, True, False, self.ib_port)
qa = QPAttr()
qa.qkey = 0x123
qp.to_init(qa)
qp_attr, _ = qp.query(ibv_qp_attr_mask.IBV_QP_QKEY)
assert qp_attr.qkey == qa.qkey, 'Extended QP, QKey is not as expected'
qp.to_rtr(qa)
qa.sq_psn = 0x45
qp.to_rts(qa)
qp_attr, _ = qp.query(ibv_qp_attr_mask.IBV_QP_SQ_PSN)
assert qp_attr.sq_psn == qa.sq_psn, 'Extended QP, SQ PSN is not as expected'
qa.qp_state = ibv_qp_state.IBV_QPS_RESET
qp.modify(qa, ibv_qp_attr_mask.IBV_QP_STATE)
assert qp.qp_state == ibv_qp_state.IBV_QPS_RESET, 'Extended QP, QP state is not as expected'
@u.skip_unsupported
@u.requires_cap_net_raw()
def test_create_ud_qp_with_privileged_qkey(self):
"""
Test UD QP creation and modification with privileged QKEY 0x80000000.
Verifies that the privileged QKEY (IB_QP_PRIVILEGED_Q_KEY) can be set
and queried correctly for both legacy and extended QPs.
"""
privileged_qkey = 0x80000000 # IB_QP_PRIVILEGED_Q_KEY
with PD(self.ctx) as pd:
with CQ(self.ctx, 100, None, None, 0) as cq:
# Test Legacy QP with privileged QKEY
qia = u.get_qp_init_attr(cq, self.attr)
qia.qp_type = ibv_qp_type.IBV_QPT_UD
qp = self.create_qp(pd, qia, False, False, self.ib_port)
qa = QPAttr()
qa.qkey = privileged_qkey
qp.to_init(qa)
qp_attr, _ = qp.query(ibv_qp_attr_mask.IBV_QP_QKEY)
self.assertEqual(qp_attr.qkey, qa.qkey,
f'Legacy QP, Privileged QKey is not as '\
f'expected. Got: 0x{qp_attr.qkey:08x}, Expected: 0x{qa.qkey:08x}')
# Test Extended QP with privileged QKEY
qia = get_qp_init_attr_ex(cq, pd, self.attr, self.attr_ex, ibv_qp_type.IBV_QPT_UD)
qp = self.create_qp(self.ctx, qia, True, False, self.ib_port)
qa = QPAttr()
qa.qkey = privileged_qkey
qp.to_init(qa)
qp_attr, _ = qp.query(ibv_qp_attr_mask.IBV_QP_QKEY)
self.assertEqual(qp_attr.qkey, qa.qkey,
f'Extended QP, Privileged QKey is not as '\
f'expected. Got: 0x{qp_attr.qkey:08x}, Expected: 0x{qa.qkey:08x}')
class RCQPTest(RDMATestCase):
"""
Test various functionalities of the RC QP class.
"""
def test_modify_rc_qp_rd_atomic(self):
"""
This test verifies that the values of rd_atomic fields are
at least the requested value.
"""
self.max_rd_atomic = 12
self.max_dest_rd_atomic = 12
self.create_players(RCResources, max_rd_atomic=self.max_rd_atomic,
max_dest_rd_atomic=self.max_dest_rd_atomic)
qp_attr, _ = self.server.qp.query(ibv_qp_attr_mask.IBV_QP_MAX_QP_RD_ATOMIC | \
ibv_qp_attr_mask.IBV_QP_MAX_DEST_RD_ATOMIC)
self.assertGreaterEqual(qp_attr.max_rd_atomic, self.max_rd_atomic,
'Max RD Atomic value is less than requested.')
self.assertGreaterEqual(qp_attr.max_dest_rd_atomic, self.max_dest_rd_atomic,
'Max Dest RD Atomic is less than requested.')
def get_qp_init_attr_ex(cq, pd, attr, attr_ex, qpt):
"""
Creates a QPInitAttrEx object with a QP type of the provided <qpts> array
and other random values.
:param cq: CQ to be used as send and receive CQ
:param pd: A PD object to use
:param attr: Device attributes for capability checks
:param attr_ex: Extended device attributes for capability checks
:param qpt: QP type
:return: An initialized QPInitAttrEx object
"""
qia = u.random_qp_init_attr_ex(attr_ex, attr, qpt)
qia.send_cq = cq
qia.recv_cq = cq
qia.pd = pd # Only XRCD can be created without a PD
return qia
|