diff options
author | John Levon <john.levon@nutanix.com> | 2023-01-03 12:23:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 12:23:43 +0000 |
commit | 3eb7ff6579740a5b962c1a52804b0ec5b29a4c42 (patch) | |
tree | f7a519153645a4560eae19e3e9843adafef3cd9c /test | |
parent | ad96efb02c27ec22116fb5800b48a6c9df27958f (diff) | |
download | libvfio-user-3eb7ff6579740a5b962c1a52804b0ec5b29a4c42.zip libvfio-user-3eb7ff6579740a5b962c1a52804b0ec5b29a4c42.tar.gz libvfio-user-3eb7ff6579740a5b962c1a52804b0ec5b29a4c42.tar.bz2 |
fix FLR reset callback (#729)
A reset callback is allowed to call functions disallowed in quiescent
state. However, the FLR reset path neglected to account for this
properly, causing an incorrect assert to be triggered if, for example,
vfu_sgl_put() is called. To fix this, make sure all reset paths go
through call_reset_cb().
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/py/libvfio_user.py | 10 | ||||
-rw-r--r-- | test/py/test_pci_caps.py | 19 | ||||
-rw-r--r-- | test/py/test_quiesce.py | 22 |
3 files changed, 37 insertions, 14 deletions
diff --git a/test/py/libvfio_user.py b/test/py/libvfio_user.py index 5f0872a..73fad5a 100644 --- a/test/py/libvfio_user.py +++ b/test/py/libvfio_user.py @@ -869,6 +869,16 @@ def __dma_unregister(ctx, info): dma_unregister(ctx, copy.copy(info.contents)) +def setup_flrc(ctx): + # flrc + cap = struct.pack("ccHHcc52c", to_byte(PCI_CAP_ID_EXP), b'\0', 0, 0, b'\0', + b'\x10', *[b'\0' for _ in range(52)]) + # FIXME adding capability after we've realized the device only works + # because of bug #618. + pos = vfu_pci_add_capability(ctx, pos=0, flags=0, data=cap) + assert pos == PCI_STD_HEADER_SIZEOF + + def quiesce_cb(ctx): return 0 diff --git a/test/py/test_pci_caps.py b/test/py/test_pci_caps.py index 24e992f..edd1683 100644 --- a/test/py/test_pci_caps.py +++ b/test/py/test_pci_caps.py @@ -314,16 +314,6 @@ def __test_pci_cap_write_pmcs(sock): count=len(data), data=data, expect=errno.ENOTSUP) -def _setup_flrc(ctx): - # flrc - cap = struct.pack("ccHHcc52c", to_byte(PCI_CAP_ID_EXP), b'\0', 0, 0, b'\0', - b'\x10', *[b'\0' for _ in range(52)]) - # FIXME adding capability after we've realized the device only works - # because of bug #618. - pos = vfu_pci_add_capability(ctx, pos=0, flags=0, data=cap) - assert pos == PCI_STD_HEADER_SIZEOF - - @patch("libvfio_user.reset_cb", return_value=0) @patch('libvfio_user.quiesce_cb') def test_pci_cap_write_px(mock_quiesce, mock_reset): @@ -333,7 +323,7 @@ def test_pci_cap_write_px(mock_quiesce, mock_reset): setup_pci_dev(realize=True) sock = connect_client(ctx) - _setup_flrc(ctx) + setup_flrc(ctx) # iflr offset = PCI_STD_HEADER_SIZEOF + 8 @@ -421,7 +411,7 @@ def test_pci_cap_write_pxdc2(): setup_pci_dev(realize=True) sock = connect_client(ctx) - _setup_flrc(ctx) + setup_flrc(ctx) offset = (vfu_pci_find_capability(ctx, False, PCI_CAP_ID_EXP) + PCI_EXP_DEVCTL2) @@ -436,9 +426,10 @@ def test_pci_cap_write_pxdc2(): def test_pci_cap_write_pxlc2(): setup_pci_dev(realize=True) - _setup_flrc(ctx) - sock = connect_client(ctx) + + setup_flrc(ctx) + offset = (vfu_pci_find_capability(ctx, False, PCI_CAP_ID_EXP) + PCI_EXP_LNKCTL2) data = b'\xbe\xef' diff --git a/test/py/test_quiesce.py b/test/py/test_quiesce.py index 0e2a980..b1fb2fd 100644 --- a/test/py/test_quiesce.py +++ b/test/py/test_quiesce.py @@ -247,4 +247,26 @@ def test_allowed_funcs_in_quiesced_reset_busy(mock_quiesce, mock_reset): mock_reset.assert_called_once_with(ctx, VFU_RESET_DEVICE) +@patch('libvfio_user.reset_cb', side_effect=_side_effect) +@patch('libvfio_user.quiesce_cb') +def test_flr(mock_quiesce, mock_reset): + """Test that an FLR reset callback is still able to call functions not + allowed in quiescent state.""" + + global ctx, sock + + _map_dma_region(ctx, sock) + + setup_flrc(ctx) + + # iflr + offset = PCI_STD_HEADER_SIZEOF + 8 + data = b'\x00\x80' + write_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, + count=len(data), data=data) + + mock_quiesce.assert_called_with(ctx) + mock_reset.assert_called_once_with(ctx, VFU_RESET_PCI_FLR) + + # ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: # |