1
The following changes since commit 23919ddfd56135cad3cb468a8f54d5a595f024f4:
1
The following changes since commit 8e6c70b9d4a1b1f3011805947925cfdb31642f7f:
2
2
3
Merge remote-tracking branch 'remotes/aperard/tags/pull-xen-20190827' into staging (2019-08-27 15:52:36 +0100)
3
Merge tag 'kraxel-20220614-pull-request' of git://git.kraxel.org/qemu into staging (2022-06-14 06:21:46 -0700)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://github.com/XanClic/qemu.git tags/pull-block-2019-08-27
7
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
8
8
9
for you to fetch changes up to bb043c056cffcc2f3ce88bfdaf2e76e455c09e2c:
9
for you to fetch changes up to 99b969fbe105117f5af6060d3afef40ca39cc9c1:
10
10
11
iotests: Unify cache mode quoting (2019-08-27 19:48:44 +0200)
11
linux-aio: explain why max batch is checked in laio_io_unplug() (2022-06-15 16:43:42 +0100)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Block patches:
14
Pull request
15
- qemu-io now accepts a file to read a write pattern from
15
16
- Ensure that raw files have their first block allocated so we can probe
16
This pull request includes an important aio=native I/O stall fix, the
17
the O_DIRECT alignment if necessary
17
experimental vifo-user server, the io_uring_register_ring_fd() optimization for
18
- Various fixes
18
aio=io_uring, and an update to Vladimir Sementsov-Ogievskiy's maintainership
19
details.
19
20
20
----------------------------------------------------------------
21
----------------------------------------------------------------
21
Denis Plotnikov (1):
22
qemu-io: add pattern file for write command
23
22
24
Max Reitz (7):
23
Jagannathan Raman (14):
25
iotests: Fix _filter_img_create()
24
qdev: unplug blocker for devices
26
vmdk: Use bdrv_dirname() for relative extent paths
25
remote/machine: add HotplugHandler for remote machine
27
iotests: Keep testing broken relative extent paths
26
remote/machine: add vfio-user property
28
vmdk: Reject invalid compressed writes
27
vfio-user: build library
29
iotests: Disable broken streamOptimized tests
28
vfio-user: define vfio-user-server object
30
iotests: Disable 110 for vmdk.twoGbMaxExtentSparse
29
vfio-user: instantiate vfio-user context
31
iotests: Disable 126 for flat vmdk subformats
30
vfio-user: find and init PCI device
31
vfio-user: run vfio-user context
32
vfio-user: handle PCI config space accesses
33
vfio-user: IOMMU support for remote device
34
vfio-user: handle DMA mappings
35
vfio-user: handle PCI BAR accesses
36
vfio-user: handle device interrupts
37
vfio-user: handle reset of remote device
32
38
33
Nir Soffer (3):
39
Sam Li (1):
34
block: posix: Always allocate the first block
40
Use io_uring_register_ring_fd() to skip fd operations
35
iotests: Test allocate_first_block() with O_DIRECT
36
iotests: Unify cache mode quoting
37
41
38
Stefan Hajnoczi (1):
42
Stefan Hajnoczi (2):
39
file-posix: fix request_alignment typo
43
linux-aio: fix unbalanced plugged counter in laio_io_unplug()
40
44
linux-aio: explain why max batch is checked in laio_io_unplug()
41
Thomas Huth (2):
42
iotests: Check for enabled drivers before testing them
43
tests/check-block: Skip iotests when sanitizers are enabled
44
45
45
Vladimir Sementsov-Ogievskiy (1):
46
Vladimir Sementsov-Ogievskiy (1):
46
block: fix permission update in bdrv_replace_node
47
MAINTAINERS: update Vladimir's address and repositories
47
48
48
block.c | 5 +-
49
MAINTAINERS | 27 +-
49
block/file-posix.c | 53 +++++++++-
50
meson_options.txt | 2 +
50
block/vmdk.c | 64 ++++++++----
51
qapi/misc.json | 31 +
51
qemu-io-cmds.c | 99 +++++++++++++++++--
52
qapi/qom.json | 20 +-
52
tests/check-block.sh | 5 +
53
configure | 17 +
53
tests/qemu-iotests/002 | 1 +
54
meson.build | 24 +-
54
tests/qemu-iotests/003 | 1 +
55
include/exec/memory.h | 3 +
55
tests/qemu-iotests/005 | 3 +-
56
include/hw/pci/msi.h | 1 +
56
tests/qemu-iotests/009 | 1 +
57
include/hw/pci/msix.h | 1 +
57
tests/qemu-iotests/010 | 1 +
58
include/hw/pci/pci.h | 13 +
58
tests/qemu-iotests/011 | 1 +
59
include/hw/qdev-core.h | 29 +
59
tests/qemu-iotests/017 | 3 +-
60
include/hw/remote/iommu.h | 40 +
60
tests/qemu-iotests/018 | 3 +-
61
include/hw/remote/machine.h | 4 +
61
tests/qemu-iotests/019 | 3 +-
62
include/hw/remote/vfio-user-obj.h | 6 +
62
tests/qemu-iotests/020 | 3 +-
63
block/io_uring.c | 12 +-
63
tests/qemu-iotests/026 | 4 +-
64
block/linux-aio.c | 10 +-
64
tests/qemu-iotests/027 | 1 +
65
hw/core/qdev.c | 24 +
65
tests/qemu-iotests/032 | 1 +
66
hw/pci/msi.c | 49 +-
66
tests/qemu-iotests/033 | 1 +
67
hw/pci/msix.c | 35 +-
67
tests/qemu-iotests/034 | 3 +-
68
hw/pci/pci.c | 13 +
68
tests/qemu-iotests/037 | 3 +-
69
hw/remote/iommu.c | 131 ++++
69
tests/qemu-iotests/039 | 4 +-
70
hw/remote/machine.c | 88 ++-
70
tests/qemu-iotests/052 | 2 +-
71
hw/remote/vfio-user-obj.c | 958 ++++++++++++++++++++++++
71
tests/qemu-iotests/059 | 34 ++++++-
72
softmmu/physmem.c | 4 +-
72
tests/qemu-iotests/059.out | 26 +++--
73
softmmu/qdev-monitor.c | 4 +
73
tests/qemu-iotests/063 | 3 +-
74
stubs/vfio-user-obj.c | 6 +
74
tests/qemu-iotests/071 | 1 +
75
tests/qtest/fuzz/generic_fuzz.c | 9 +-
75
tests/qemu-iotests/072 | 1 +
76
.gitlab-ci.d/buildtest.yml | 1 +
76
tests/qemu-iotests/081 | 4 +-
77
.gitmodules | 3 +
77
tests/qemu-iotests/091 | 4 +-
78
Kconfig.host | 4 +
78
tests/qemu-iotests/099 | 1 +
79
hw/remote/Kconfig | 4 +
79
tests/qemu-iotests/105 | 3 +-
80
hw/remote/meson.build | 4 +
80
tests/qemu-iotests/110 | 3 +-
81
hw/remote/trace-events | 11 +
81
tests/qemu-iotests/120 | 1 +
82
scripts/meson-buildoptions.sh | 4 +
82
tests/qemu-iotests/126 | 2 +
83
stubs/meson.build | 1 +
83
tests/qemu-iotests/{150.out => 150.out.qcow2} | 0
84
subprojects/libvfio-user | 1 +
84
tests/qemu-iotests/150.out.raw | 12 +++
85
tests/docker/dockerfiles/centos8.docker | 2 +
85
tests/qemu-iotests/162 | 4 +-
86
37 files changed, 1565 insertions(+), 31 deletions(-)
86
tests/qemu-iotests/175 | 47 +++++++--
87
create mode 100644 include/hw/remote/iommu.h
87
tests/qemu-iotests/175.out | 16 ++-
88
create mode 100644 include/hw/remote/vfio-user-obj.h
88
tests/qemu-iotests/178.out.qcow2 | 4 +-
89
create mode 100644 hw/remote/iommu.c
89
tests/qemu-iotests/184 | 1 +
90
create mode 100644 hw/remote/vfio-user-obj.c
90
tests/qemu-iotests/186 | 1 +
91
create mode 100644 stubs/vfio-user-obj.c
91
tests/qemu-iotests/197 | 1 +
92
create mode 160000 subprojects/libvfio-user
92
tests/qemu-iotests/215 | 1 +
93
tests/qemu-iotests/221.out | 12 ++-
94
tests/qemu-iotests/251 | 1 +
95
tests/qemu-iotests/253.out | 12 ++-
96
tests/qemu-iotests/common.filter | 4 +-
97
tests/qemu-iotests/common.rc | 14 +++
98
50 files changed, 391 insertions(+), 87 deletions(-)
99
rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%)
100
create mode 100644 tests/qemu-iotests/150.out.raw
101
93
102
--
94
--
103
2.21.0
95
2.36.1
104
105
diff view generated by jsdifflib
1
From: Nir Soffer <nirsof@gmail.com>
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
2
2
3
Quoting cache mode is not needed, and most tests use unquoted values.
3
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
4
Unify all test to use the same style.
4
Message-id: 20220526115432.138384-1-vsementsov@yandex-team.ru
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
6
---
7
MAINTAINERS | 22 ++++++++++++----------
8
1 file changed, 12 insertions(+), 10 deletions(-)
5
9
6
Message-id: 20190827173432.7656-1-nsoffer@redhat.com
10
diff --git a/MAINTAINERS b/MAINTAINERS
7
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
11
index XXXXXXX..XXXXXXX 100644
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
--- a/MAINTAINERS
9
---
13
+++ b/MAINTAINERS
10
tests/qemu-iotests/026 | 4 ++--
14
@@ -XXX,XX +XXX,XX @@ F: scsi/*
11
tests/qemu-iotests/039 | 4 ++--
15
12
tests/qemu-iotests/052 | 2 +-
16
Block Jobs
13
tests/qemu-iotests/091 | 4 ++--
17
M: John Snow <jsnow@redhat.com>
14
4 files changed, 7 insertions(+), 7 deletions(-)
18
-M: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
15
19
+M: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
16
diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026
20
L: qemu-block@nongnu.org
17
index XXXXXXX..XXXXXXX 100755
21
S: Supported
18
--- a/tests/qemu-iotests/026
22
F: blockjob.c
19
+++ b/tests/qemu-iotests/026
23
@@ -XXX,XX +XXX,XX @@ F: block/aio_task.c
20
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
24
F: util/qemu-co-shared-resource.c
21
# Currently only qcow2 supports rebasing
25
F: include/qemu/co-shared-resource.h
22
_supported_fmt qcow2
26
T: git https://gitlab.com/jsnow/qemu.git jobs
23
_supported_proto file
27
-T: git https://src.openvz.org/scm/~vsementsov/qemu.git jobs
24
-_default_cache_mode "writethrough"
28
+T: git https://gitlab.com/vsementsov/qemu.git block
25
-_supported_cache_modes "writethrough" "none"
29
26
+_default_cache_mode writethrough
30
Block QAPI, monitor, command line
27
+_supported_cache_modes writethrough none
31
M: Markus Armbruster <armbru@redhat.com>
28
# The refcount table tests expect a certain minimum width for refcount entries
32
@@ -XXX,XX +XXX,XX @@ F: include/hw/cxl/
29
# (so that the refcount table actually needs to grow); that minimum is 16 bits,
33
30
# being the default refcount entry width.
34
Dirty Bitmaps
31
diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039
35
M: Eric Blake <eblake@redhat.com>
32
index XXXXXXX..XXXXXXX 100755
36
-M: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
33
--- a/tests/qemu-iotests/039
37
+M: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
34
+++ b/tests/qemu-iotests/039
38
R: John Snow <jsnow@redhat.com>
35
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
39
L: qemu-block@nongnu.org
36
_supported_fmt qcow2
40
S: Supported
37
_supported_proto file
41
@@ -XXX,XX +XXX,XX @@ F: util/hbitmap.c
38
_supported_os Linux
42
F: tests/unit/test-hbitmap.c
39
-_default_cache_mode "writethrough"
43
F: docs/interop/bitmaps.rst
40
-_supported_cache_modes "writethrough"
44
T: git https://repo.or.cz/qemu/ericb.git bitmaps
41
+_default_cache_mode writethrough
45
+T: git https://gitlab.com/vsementsov/qemu.git block
42
+_supported_cache_modes writethrough
46
43
47
Character device backends
44
size=128M
48
M: Marc-André Lureau <marcandre.lureau@redhat.com>
45
49
@@ -XXX,XX +XXX,XX @@ F: scripts/*.py
46
diff --git a/tests/qemu-iotests/052 b/tests/qemu-iotests/052
50
F: tests/*.py
47
index XXXXXXX..XXXXXXX 100755
51
48
--- a/tests/qemu-iotests/052
52
Benchmark util
49
+++ b/tests/qemu-iotests/052
53
-M: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
50
@@ -XXX,XX +XXX,XX @@ _supported_fmt generic
54
+M: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
51
_supported_proto file
55
S: Maintained
52
56
F: scripts/simplebench/
53
# Don't do O_DIRECT on tmpfs
57
-T: git https://src.openvz.org/scm/~vsementsov/qemu.git simplebench
54
-_supported_cache_modes "writeback" "writethrough" "unsafe"
58
+T: git https://gitlab.com/vsementsov/qemu.git simplebench
55
+_supported_cache_modes writeback writethrough unsafe
59
56
60
Transactions helper
57
size=128M
61
-M: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
58
_make_test_img $size
62
+M: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
59
diff --git a/tests/qemu-iotests/091 b/tests/qemu-iotests/091
63
S: Maintained
60
index XXXXXXX..XXXXXXX 100755
64
F: include/qemu/transactions.h
61
--- a/tests/qemu-iotests/091
65
F: util/transactions.c
62
+++ b/tests/qemu-iotests/091
66
+T: git https://gitlab.com/vsementsov/qemu.git block
63
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
67
64
_supported_fmt qcow2
68
QAPI
65
_supported_proto file
69
M: Markus Armbruster <armbru@redhat.com>
66
_supported_os Linux
70
@@ -XXX,XX +XXX,XX @@ F: block/iscsi-opts.c
67
-_default_cache_mode "none"
71
68
-_supported_cache_modes "writethrough" "none" "writeback"
72
Network Block Device (NBD)
69
+_default_cache_mode none
73
M: Eric Blake <eblake@redhat.com>
70
+_supported_cache_modes writethrough none writeback
74
-M: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
71
75
+M: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
72
size=1G
76
L: qemu-block@nongnu.org
73
77
S: Maintained
78
F: block/nbd*
79
@@ -XXX,XX +XXX,XX @@ F: docs/interop/nbd.txt
80
F: docs/tools/qemu-nbd.rst
81
F: tests/qemu-iotests/tests/*nbd*
82
T: git https://repo.or.cz/qemu/ericb.git nbd
83
-T: git https://src.openvz.org/scm/~vsementsov/qemu.git nbd
84
+T: git https://gitlab.com/vsementsov/qemu.git block
85
86
NFS
87
M: Peter Lieven <pl@kamp.de>
88
@@ -XXX,XX +XXX,XX @@ F: block/dmg.c
89
parallels
90
M: Stefan Hajnoczi <stefanha@redhat.com>
91
M: Denis V. Lunev <den@openvz.org>
92
-M: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
93
+M: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
94
L: qemu-block@nongnu.org
95
S: Supported
96
F: block/parallels.c
97
F: block/parallels-ext.c
98
F: docs/interop/parallels.txt
99
-T: git https://src.openvz.org/scm/~vsementsov/qemu.git parallels
100
+T: git https://gitlab.com/vsementsov/qemu.git block
101
102
qed
103
M: Stefan Hajnoczi <stefanha@redhat.com>
74
--
104
--
75
2.21.0
105
2.36.1
76
106
77
107
diff view generated by jsdifflib
New patch
1
From: Sam Li <faithilikerun@gmail.com>
1
2
3
Linux recently added a new io_uring(7) optimization API that QEMU
4
doesn't take advantage of yet. The liburing library that QEMU uses
5
has added a corresponding new API calling io_uring_register_ring_fd().
6
When this API is called after creating the ring, the io_uring_submit()
7
library function passes a flag to the io_uring_enter(2) syscall
8
allowing it to skip the ring file descriptor fdget()/fdput()
9
operations. This saves some CPU cycles.
10
11
Signed-off-by: Sam Li <faithilikerun@gmail.com>
12
Message-id: 20220531105011.111082-1-faithilikerun@gmail.com
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
---
15
meson.build | 1 +
16
block/io_uring.c | 12 +++++++++++-
17
2 files changed, 12 insertions(+), 1 deletion(-)
18
19
diff --git a/meson.build b/meson.build
20
index XXXXXXX..XXXXXXX 100644
21
--- a/meson.build
22
+++ b/meson.build
23
@@ -XXX,XX +XXX,XX @@ config_host_data.set('CONFIG_LIBNFS', libnfs.found())
24
config_host_data.set('CONFIG_LIBSSH', libssh.found())
25
config_host_data.set('CONFIG_LINUX_AIO', libaio.found())
26
config_host_data.set('CONFIG_LINUX_IO_URING', linux_io_uring.found())
27
+config_host_data.set('CONFIG_LIBURING_REGISTER_RING_FD', cc.has_function('io_uring_register_ring_fd', prefix: '#include <liburing.h>', dependencies:linux_io_uring))
28
config_host_data.set('CONFIG_LIBPMEM', libpmem.found())
29
config_host_data.set('CONFIG_NUMA', numa.found())
30
config_host_data.set('CONFIG_OPENGL', opengl.found())
31
diff --git a/block/io_uring.c b/block/io_uring.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/block/io_uring.c
34
+++ b/block/io_uring.c
35
@@ -XXX,XX +XXX,XX @@
36
#include "qapi/error.h"
37
#include "trace.h"
38
39
+
40
/* io_uring ring size */
41
#define MAX_ENTRIES 128
42
43
@@ -XXX,XX +XXX,XX @@ LuringState *luring_init(Error **errp)
44
}
45
46
ioq_init(&s->io_q);
47
+#ifdef CONFIG_LIBURING_REGISTER_RING_FD
48
+ if (io_uring_register_ring_fd(&s->ring) < 0) {
49
+ /*
50
+ * Only warn about this error: we will fallback to the non-optimized
51
+ * io_uring operations.
52
+ */
53
+ warn_report("failed to register linux io_uring ring file descriptor");
54
+ }
55
+#endif
56
+
57
return s;
58
-
59
}
60
61
void luring_cleanup(LuringState *s)
62
--
63
2.36.1
diff view generated by jsdifflib
New patch
1
From: Jagannathan Raman <jag.raman@oracle.com>
1
2
3
Add blocker to prevent hot-unplug of devices
4
5
TYPE_VFIO_USER_SERVER, which is introduced shortly, attaches itself to a
6
PCIDevice on which it depends. If the attached PCIDevice gets removed
7
while the server in use, it could cause it crash. To prevent this,
8
TYPE_VFIO_USER_SERVER adds an unplug blocker for the PCIDevice.
9
10
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
11
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
12
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
13
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Message-id: c41ef80b7cc063314d629737bed2159e5713f2e0.1655151679.git.jag.raman@oracle.com
15
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
16
---
17
include/hw/qdev-core.h | 29 +++++++++++++++++++++++++++++
18
hw/core/qdev.c | 24 ++++++++++++++++++++++++
19
softmmu/qdev-monitor.c | 4 ++++
20
3 files changed, 57 insertions(+)
21
22
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
23
index XXXXXXX..XXXXXXX 100644
24
--- a/include/hw/qdev-core.h
25
+++ b/include/hw/qdev-core.h
26
@@ -XXX,XX +XXX,XX @@ struct DeviceState {
27
int instance_id_alias;
28
int alias_required_for_version;
29
ResettableState reset;
30
+ GSList *unplug_blockers;
31
};
32
33
struct DeviceListener {
34
@@ -XXX,XX +XXX,XX @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
35
void qdev_machine_creation_done(void);
36
bool qdev_machine_modified(void);
37
38
+/**
39
+ * qdev_add_unplug_blocker: Add an unplug blocker to a device
40
+ *
41
+ * @dev: Device to be blocked from unplug
42
+ * @reason: Reason for blocking
43
+ */
44
+void qdev_add_unplug_blocker(DeviceState *dev, Error *reason);
45
+
46
+/**
47
+ * qdev_del_unplug_blocker: Remove an unplug blocker from a device
48
+ *
49
+ * @dev: Device to be unblocked
50
+ * @reason: Pointer to the Error used with qdev_add_unplug_blocker.
51
+ * Used as a handle to lookup the blocker for deletion.
52
+ */
53
+void qdev_del_unplug_blocker(DeviceState *dev, Error *reason);
54
+
55
+/**
56
+ * qdev_unplug_blocked: Confirm if a device is blocked from unplug
57
+ *
58
+ * @dev: Device to be tested
59
+ * @reason: Returns one of the reasons why the device is blocked,
60
+ * if any
61
+ *
62
+ * Returns: true if device is blocked from unplug, false otherwise
63
+ */
64
+bool qdev_unplug_blocked(DeviceState *dev, Error **errp);
65
+
66
/**
67
* GpioPolarity: Polarity of a GPIO line
68
*
69
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
70
index XXXXXXX..XXXXXXX 100644
71
--- a/hw/core/qdev.c
72
+++ b/hw/core/qdev.c
73
@@ -XXX,XX +XXX,XX @@ char *qdev_get_dev_path(DeviceState *dev)
74
return NULL;
75
}
76
77
+void qdev_add_unplug_blocker(DeviceState *dev, Error *reason)
78
+{
79
+ dev->unplug_blockers = g_slist_prepend(dev->unplug_blockers, reason);
80
+}
81
+
82
+void qdev_del_unplug_blocker(DeviceState *dev, Error *reason)
83
+{
84
+ dev->unplug_blockers = g_slist_remove(dev->unplug_blockers, reason);
85
+}
86
+
87
+bool qdev_unplug_blocked(DeviceState *dev, Error **errp)
88
+{
89
+ ERRP_GUARD();
90
+
91
+ if (dev->unplug_blockers) {
92
+ error_propagate(errp, error_copy(dev->unplug_blockers->data));
93
+ return true;
94
+ }
95
+
96
+ return false;
97
+}
98
+
99
static bool device_get_realized(Object *obj, Error **errp)
100
{
101
DeviceState *dev = DEVICE(obj);
102
@@ -XXX,XX +XXX,XX @@ static void device_finalize(Object *obj)
103
104
DeviceState *dev = DEVICE(obj);
105
106
+ g_assert(!dev->unplug_blockers);
107
+
108
QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) {
109
QLIST_REMOVE(ngl, node);
110
qemu_free_irqs(ngl->in, ngl->num_in);
111
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
112
index XXXXXXX..XXXXXXX 100644
113
--- a/softmmu/qdev-monitor.c
114
+++ b/softmmu/qdev-monitor.c
115
@@ -XXX,XX +XXX,XX @@ void qdev_unplug(DeviceState *dev, Error **errp)
116
HotplugHandlerClass *hdc;
117
Error *local_err = NULL;
118
119
+ if (qdev_unplug_blocked(dev, errp)) {
120
+ return;
121
+ }
122
+
123
if (dev->parent_bus && !qbus_is_hotpluggable(dev->parent_bus)) {
124
error_setg(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name);
125
return;
126
--
127
2.36.1
diff view generated by jsdifflib
1
Compressed writes generally have to write full clusters, not just in
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
theory but also in practice when it comes to vmdk's streamOptimized
3
subformat. It currently is just silently broken for writes with
4
non-zero in-cluster offsets:
5
2
6
$ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M
3
Allow hotplugging of PCI(e) devices to remote machine
7
$ qemu-io -c 'write 4k 4k' -c 'read 4k 4k' foo.vmdk
8
wrote 4096/4096 bytes at offset 4096
9
4 KiB, 1 ops; 00.01 sec (443.724 KiB/sec and 110.9309 ops/sec)
10
read failed: Invalid argument
11
4
12
(The technical reason is that vmdk_write_extent() just writes the
5
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
13
incomplete compressed data actually to offset 4k. When reading the
6
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
14
data, vmdk_read_extent() looks at offset 0 and finds the compressed data
7
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
15
size to be 0, because that is what it reads from there. This yields an
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
16
error.)
9
Message-id: d1e6cfa0afb528ad343758f9b1d918be0175c5e5.1655151679.git.jag.raman@oracle.com
17
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
18
For incomplete writes with zero in-cluster offsets, the error path when
19
reading the rest of the cluster is a bit different, but the result is
20
the same:
21
22
$ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M
23
$ qemu-io -c 'write 0k 4k' -c 'read 4k 4k' foo.vmdk
24
wrote 4096/4096 bytes at offset 0
25
4 KiB, 1 ops; 00.01 sec (362.641 KiB/sec and 90.6603 ops/sec)
26
read failed: Invalid argument
27
28
(Here, vmdk_read_extent() finds the data and then sees that the
29
uncompressed data is short.)
30
31
It is better to reject invalid writes than to make the user believe they
32
might have succeeded and then fail when trying to read it back.
33
34
Signed-off-by: Max Reitz <mreitz@redhat.com>
35
Reviewed-by: John Snow <jsnow@redhat.com>
36
Message-id: 20190815153638.4600-5-mreitz@redhat.com
37
Reviewed-by: John Snow <jsnow@redhat.com>
38
Signed-off-by: Max Reitz <mreitz@redhat.com>
39
---
11
---
40
block/vmdk.c | 10 ++++++++++
12
hw/remote/machine.c | 10 ++++++++++
41
1 file changed, 10 insertions(+)
13
1 file changed, 10 insertions(+)
42
14
43
diff --git a/block/vmdk.c b/block/vmdk.c
15
diff --git a/hw/remote/machine.c b/hw/remote/machine.c
44
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
45
--- a/block/vmdk.c
17
--- a/hw/remote/machine.c
46
+++ b/block/vmdk.c
18
+++ b/hw/remote/machine.c
47
@@ -XXX,XX +XXX,XX @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
19
@@ -XXX,XX +XXX,XX @@
48
if (extent->compressed) {
20
#include "qapi/error.h"
49
void *compressed_data;
21
#include "hw/pci/pci_host.h"
50
22
#include "hw/remote/iohub.h"
51
+ /* Only whole clusters */
23
+#include "hw/qdev-core.h"
52
+ if (offset_in_cluster ||
24
53
+ n_bytes > (extent->cluster_sectors * SECTOR_SIZE) ||
25
static void remote_machine_init(MachineState *machine)
54
+ (n_bytes < (extent->cluster_sectors * SECTOR_SIZE) &&
26
{
55
+ offset + n_bytes != extent->end_sector * SECTOR_SIZE))
27
@@ -XXX,XX +XXX,XX @@ static void remote_machine_init(MachineState *machine)
56
+ {
28
57
+ ret = -EINVAL;
29
pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq,
58
+ goto out;
30
&s->iohub, REMOTE_IOHUB_NB_PIRQS);
59
+ }
60
+
31
+
61
if (!extent->has_marker) {
32
+ qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s));
62
ret = -EINVAL;
33
}
63
goto out;
34
35
static void remote_machine_class_init(ObjectClass *oc, void *data)
36
{
37
MachineClass *mc = MACHINE_CLASS(oc);
38
+ HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
39
40
mc->init = remote_machine_init;
41
mc->desc = "Experimental remote machine";
42
+
43
+ hc->unplug = qdev_simple_device_unplug_cb;
44
}
45
46
static const TypeInfo remote_machine = {
47
@@ -XXX,XX +XXX,XX @@ static const TypeInfo remote_machine = {
48
.parent = TYPE_MACHINE,
49
.instance_size = sizeof(RemoteMachineState),
50
.class_init = remote_machine_class_init,
51
+ .interfaces = (InterfaceInfo[]) {
52
+ { TYPE_HOTPLUG_HANDLER },
53
+ { }
54
+ }
55
};
56
57
static void remote_machine_register_types(void)
64
--
58
--
65
2.21.0
59
2.36.1
66
67
diff view generated by jsdifflib
New patch
1
From: Jagannathan Raman <jag.raman@oracle.com>
1
2
3
Add vfio-user to x-remote machine. It is a boolean, which indicates if
4
the machine supports vfio-user protocol. The machine configures the bus
5
differently vfio-user and multiprocess protocols, so this property
6
informs it on how to configure the bus.
7
8
This property should be short lived. Once vfio-user fully replaces
9
multiprocess, this property could be removed.
10
11
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
12
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
13
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
14
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
15
Message-id: 5d51a152a419cbda35d070b8e49b772b60a7230a.1655151679.git.jag.raman@oracle.com
16
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
17
---
18
include/hw/remote/machine.h | 2 ++
19
hw/remote/machine.c | 23 +++++++++++++++++++++++
20
2 files changed, 25 insertions(+)
21
22
diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h
23
index XXXXXXX..XXXXXXX 100644
24
--- a/include/hw/remote/machine.h
25
+++ b/include/hw/remote/machine.h
26
@@ -XXX,XX +XXX,XX @@ struct RemoteMachineState {
27
28
RemotePCIHost *host;
29
RemoteIOHubState iohub;
30
+
31
+ bool vfio_user;
32
};
33
34
/* Used to pass to co-routine device and ioc. */
35
diff --git a/hw/remote/machine.c b/hw/remote/machine.c
36
index XXXXXXX..XXXXXXX 100644
37
--- a/hw/remote/machine.c
38
+++ b/hw/remote/machine.c
39
@@ -XXX,XX +XXX,XX @@ static void remote_machine_init(MachineState *machine)
40
qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s));
41
}
42
43
+static bool remote_machine_get_vfio_user(Object *obj, Error **errp)
44
+{
45
+ RemoteMachineState *s = REMOTE_MACHINE(obj);
46
+
47
+ return s->vfio_user;
48
+}
49
+
50
+static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp)
51
+{
52
+ RemoteMachineState *s = REMOTE_MACHINE(obj);
53
+
54
+ if (phase_check(PHASE_MACHINE_CREATED)) {
55
+ error_setg(errp, "Error enabling vfio-user - machine already created");
56
+ return;
57
+ }
58
+
59
+ s->vfio_user = value;
60
+}
61
+
62
static void remote_machine_class_init(ObjectClass *oc, void *data)
63
{
64
MachineClass *mc = MACHINE_CLASS(oc);
65
@@ -XXX,XX +XXX,XX @@ static void remote_machine_class_init(ObjectClass *oc, void *data)
66
mc->desc = "Experimental remote machine";
67
68
hc->unplug = qdev_simple_device_unplug_cb;
69
+
70
+ object_class_property_add_bool(oc, "vfio-user",
71
+ remote_machine_get_vfio_user,
72
+ remote_machine_set_vfio_user);
73
}
74
75
static const TypeInfo remote_machine = {
76
--
77
2.36.1
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
2
3
The sanitizers (especially the address sanitizer from Clang) are
3
add the libvfio-user library as a submodule. build it as a meson
4
sometimes printing out warnings or false positives - this spoils
4
subproject.
5
the output of the iotests, causing some of the tests to fail.
5
6
Thus let's skip the automatic iotests during "make check" when the
6
libvfio-user is distributed with BSD 3-Clause license and
7
user configured QEMU with --enable-sanitizers.
7
json-c with MIT (Expat) license
8
8
9
Signed-off-by: Thomas Huth <thuth@redhat.com>
9
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
10
Message-id: 20190823084203.29734-1-thuth@redhat.com
10
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
12
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
13
Message-id: c2adec87958b081d1dc8775d4aa05c897912f025.1655151679.git.jag.raman@oracle.com
14
15
[Changed submodule URL to QEMU's libvfio-user mirror on GitLab. The QEMU
16
project mirrors its dependencies so that it can provide full source code
17
even in the event that its dependencies become unavailable. Note that
18
the mirror repo is manually updated, so please contact me to make newer
19
libvfio-user commits available. If I become a bottleneck we can set up a
20
cronjob.
21
22
Updated scripts/meson-buildoptions.sh to match the meson_options.txt
23
change. Failure to do so can result in scripts/meson-buildoptions.sh
24
being modified by the build system later on and you end up with a dirty
25
working tree.
26
--Stefan]
27
28
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
---
29
---
13
tests/check-block.sh | 5 +++++
30
MAINTAINERS | 1 +
14
1 file changed, 5 insertions(+)
31
meson_options.txt | 2 ++
15
32
configure | 17 +++++++++++++++++
16
diff --git a/tests/check-block.sh b/tests/check-block.sh
33
meson.build | 23 ++++++++++++++++++++++-
34
.gitlab-ci.d/buildtest.yml | 1 +
35
.gitmodules | 3 +++
36
Kconfig.host | 4 ++++
37
hw/remote/Kconfig | 4 ++++
38
hw/remote/meson.build | 2 ++
39
scripts/meson-buildoptions.sh | 4 ++++
40
subprojects/libvfio-user | 1 +
41
tests/docker/dockerfiles/centos8.docker | 2 ++
42
12 files changed, 63 insertions(+), 1 deletion(-)
43
create mode 160000 subprojects/libvfio-user
44
45
diff --git a/MAINTAINERS b/MAINTAINERS
46
index XXXXXXX..XXXXXXX 100644
47
--- a/MAINTAINERS
48
+++ b/MAINTAINERS
49
@@ -XXX,XX +XXX,XX @@ F: hw/remote/proxy-memory-listener.c
50
F: include/hw/remote/proxy-memory-listener.h
51
F: hw/remote/iohub.c
52
F: include/hw/remote/iohub.h
53
+F: subprojects/libvfio-user
54
55
EBPF:
56
M: Jason Wang <jasowang@redhat.com>
57
diff --git a/meson_options.txt b/meson_options.txt
58
index XXXXXXX..XXXXXXX 100644
59
--- a/meson_options.txt
60
+++ b/meson_options.txt
61
@@ -XXX,XX +XXX,XX @@ option('cfi_debug', type: 'boolean', value: 'false',
62
description: 'Verbose errors in case of CFI violation')
63
option('multiprocess', type: 'feature', value: 'auto',
64
description: 'Out of process device emulation support')
65
+option('vfio_user_server', type: 'feature', value: 'disabled',
66
+ description: 'vfio-user server support')
67
option('dbus_display', type: 'feature', value: 'auto',
68
description: '-display dbus support')
69
option('tpm', type : 'feature', value : 'auto',
70
diff --git a/configure b/configure
17
index XXXXXXX..XXXXXXX 100755
71
index XXXXXXX..XXXXXXX 100755
18
--- a/tests/check-block.sh
72
--- a/configure
19
+++ b/tests/check-block.sh
73
+++ b/configure
20
@@ -XXX,XX +XXX,XX @@ if grep -q "TARGET_GPROF=y" *-softmmu/config-target.mak 2>/dev/null ; then
74
@@ -XXX,XX +XXX,XX @@ meson_args=""
21
exit 0
75
ninja=""
22
fi
76
bindir="bin"
23
77
skip_meson=no
24
+if grep -q "CFLAGS.*-fsanitize" config-host.mak 2>/dev/null ; then
78
+vfio_user_server="disabled"
25
+ echo "Sanitizers are enabled ==> Not running the qemu-iotests."
79
26
+ exit 0
80
# The following Meson options are handled manually (still they
27
+fi
81
# are included in the automatically generated help message)
28
+
82
@@ -XXX,XX +XXX,XX @@ for opt do
29
if [ -z "$(find . -name 'qemu-system-*' -print)" ]; then
83
;;
30
echo "No qemu-system binary available ==> Not running the qemu-iotests."
84
--disable-blobs) meson_option_parse --disable-install-blobs ""
31
exit 0
85
;;
86
+ --enable-vfio-user-server) vfio_user_server="enabled"
87
+ ;;
88
+ --disable-vfio-user-server) vfio_user_server="disabled"
89
+ ;;
90
--enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
91
;;
92
--enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
93
@@ -XXX,XX +XXX,XX @@ write_container_target_makefile() {
94
95
96
97
+##########################################
98
+# check for vfio_user_server
99
+
100
+case "$vfio_user_server" in
101
+ enabled )
102
+ if test "$git_submodules_action" != "ignore"; then
103
+ git_submodules="${git_submodules} subprojects/libvfio-user"
104
+ fi
105
+ ;;
106
+esac
107
+
108
##########################################
109
# End of CC checks
110
# After here, no more $cc or $ld runs
111
@@ -XXX,XX +XXX,XX @@ if test "$skip_meson" = no; then
112
test "$slirp" != auto && meson_option_add "-Dslirp=$slirp"
113
test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd"
114
test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
115
+ test "$vfio_user_server" != auto && meson_option_add "-Dvfio_user_server=$vfio_user_server"
116
run_meson() {
117
NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" "$source_path"
118
}
119
diff --git a/meson.build b/meson.build
120
index XXXXXXX..XXXXXXX 100644
121
--- a/meson.build
122
+++ b/meson.build
123
@@ -XXX,XX +XXX,XX @@ multiprocess_allowed = get_option('multiprocess') \
124
.require(targetos == 'linux', error_message: 'Multiprocess QEMU is supported only on Linux') \
125
.allowed()
126
127
+vfio_user_server_allowed = get_option('vfio_user_server') \
128
+ .require(targetos == 'linux', error_message: 'vfio-user server is supported only on Linux') \
129
+ .allowed()
130
+
131
have_tpm = get_option('tpm') \
132
.require(targetos != 'windows', error_message: 'TPM emulation only available on POSIX systems') \
133
.allowed()
134
@@ -XXX,XX +XXX,XX @@ host_kconfig = \
135
(have_virtfs ? ['CONFIG_VIRTFS=y'] : []) + \
136
('CONFIG_LINUX' in config_host ? ['CONFIG_LINUX=y'] : []) + \
137
(have_pvrdma ? ['CONFIG_PVRDMA=y'] : []) + \
138
- (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : [])
139
+ (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + \
140
+ (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=y'] : [])
141
142
ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ]
143
144
@@ -XXX,XX +XXX,XX @@ if have_system
145
endif
146
endif
147
148
+libvfio_user_dep = not_found
149
+if have_system and vfio_user_server_allowed
150
+ have_internal = fs.exists(meson.current_source_dir() / 'subprojects/libvfio-user/meson.build')
151
+
152
+ if not have_internal
153
+ error('libvfio-user source not found - please pull git submodule')
154
+ endif
155
+
156
+ libvfio_user_proj = subproject('libvfio-user')
157
+
158
+ libvfio_user_lib = libvfio_user_proj.get_variable('libvfio_user_dep')
159
+
160
+ libvfio_user_dep = declare_dependency(dependencies: [libvfio_user_lib])
161
+endif
162
+
163
fdt = not_found
164
if have_system
165
fdt_opt = get_option('fdt')
166
@@ -XXX,XX +XXX,XX @@ summary_info += {'target list': ' '.join(target_dirs)}
167
if have_system
168
summary_info += {'default devices': get_option('default_devices')}
169
summary_info += {'out of process emulation': multiprocess_allowed}
170
+ summary_info += {'vfio-user server': vfio_user_server_allowed}
171
endif
172
summary(summary_info, bool_yn: true, section: 'Targets and accelerators')
173
174
diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml
175
index XXXXXXX..XXXXXXX 100644
176
--- a/.gitlab-ci.d/buildtest.yml
177
+++ b/.gitlab-ci.d/buildtest.yml
178
@@ -XXX,XX +XXX,XX @@ build-system-centos:
179
IMAGE: centos8
180
CONFIGURE_ARGS: --disable-nettle --enable-gcrypt --enable-fdt=system
181
--enable-modules --enable-trace-backends=dtrace --enable-docs
182
+ --enable-vfio-user-server
183
TARGETS: ppc64-softmmu or1k-softmmu s390x-softmmu
184
x86_64-softmmu rx-softmmu sh4-softmmu nios2-softmmu
185
MAKE_CHECK_ARGS: check-build
186
diff --git a/.gitmodules b/.gitmodules
187
index XXXXXXX..XXXXXXX 100644
188
--- a/.gitmodules
189
+++ b/.gitmodules
190
@@ -XXX,XX +XXX,XX @@
191
[submodule "tests/lcitool/libvirt-ci"]
192
    path = tests/lcitool/libvirt-ci
193
    url = https://gitlab.com/libvirt/libvirt-ci.git
194
+[submodule "subprojects/libvfio-user"]
195
+    path = subprojects/libvfio-user
196
+    url = https://gitlab.com/qemu-project/libvfio-user.git
197
diff --git a/Kconfig.host b/Kconfig.host
198
index XXXXXXX..XXXXXXX 100644
199
--- a/Kconfig.host
200
+++ b/Kconfig.host
201
@@ -XXX,XX +XXX,XX @@ config MULTIPROCESS_ALLOWED
202
config FUZZ
203
bool
204
select SPARSE_MEM
205
+
206
+config VFIO_USER_SERVER_ALLOWED
207
+ bool
208
+ imply VFIO_USER_SERVER
209
diff --git a/hw/remote/Kconfig b/hw/remote/Kconfig
210
index XXXXXXX..XXXXXXX 100644
211
--- a/hw/remote/Kconfig
212
+++ b/hw/remote/Kconfig
213
@@ -XXX,XX +XXX,XX @@ config MULTIPROCESS
214
bool
215
depends on PCI && PCI_EXPRESS && KVM
216
select REMOTE_PCIHOST
217
+
218
+config VFIO_USER_SERVER
219
+ bool
220
+ depends on MULTIPROCESS
221
diff --git a/hw/remote/meson.build b/hw/remote/meson.build
222
index XXXXXXX..XXXXXXX 100644
223
--- a/hw/remote/meson.build
224
+++ b/hw/remote/meson.build
225
@@ -XXX,XX +XXX,XX @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c'))
226
remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c'))
227
remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c'))
228
229
+remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: libvfio_user_dep)
230
+
231
specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c'))
232
specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy-memory-listener.c'))
233
234
diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
235
index XXXXXXX..XXXXXXX 100644
236
--- a/scripts/meson-buildoptions.sh
237
+++ b/scripts/meson-buildoptions.sh
238
@@ -XXX,XX +XXX,XX @@ meson_options_help() {
239
printf "%s\n" ' usb-redir libusbredir support'
240
printf "%s\n" ' vde vde network backend support'
241
printf "%s\n" ' vdi vdi image format support'
242
+ printf "%s\n" ' vfio-user-server'
243
+ printf "%s\n" ' vfio-user server support'
244
printf "%s\n" ' vhost-crypto vhost-user crypto backend support'
245
printf "%s\n" ' vhost-kernel vhost kernel backend support'
246
printf "%s\n" ' vhost-net vhost-net kernel acceleration support'
247
@@ -XXX,XX +XXX,XX @@ _meson_option_parse() {
248
--disable-vde) printf "%s" -Dvde=disabled ;;
249
--enable-vdi) printf "%s" -Dvdi=enabled ;;
250
--disable-vdi) printf "%s" -Dvdi=disabled ;;
251
+ --enable-vfio-user-server) printf "%s" -Dvfio_user_server=enabled ;;
252
+ --disable-vfio-user-server) printf "%s" -Dvfio_user_server=disabled ;;
253
--enable-vhost-crypto) printf "%s" -Dvhost_crypto=enabled ;;
254
--disable-vhost-crypto) printf "%s" -Dvhost_crypto=disabled ;;
255
--enable-vhost-kernel) printf "%s" -Dvhost_kernel=enabled ;;
256
diff --git a/subprojects/libvfio-user b/subprojects/libvfio-user
257
new file mode 160000
258
index XXXXXXX..XXXXXXX
259
--- /dev/null
260
+++ b/subprojects/libvfio-user
261
@@ -0,0 +1 @@
262
+Subproject commit 0b28d205572c80b568a1003db2c8f37ca333e4d7
263
diff --git a/tests/docker/dockerfiles/centos8.docker b/tests/docker/dockerfiles/centos8.docker
264
index XXXXXXX..XXXXXXX 100644
265
--- a/tests/docker/dockerfiles/centos8.docker
266
+++ b/tests/docker/dockerfiles/centos8.docker
267
@@ -XXX,XX +XXX,XX @@ RUN dnf update -y && \
268
libbpf-devel \
269
libcacard-devel \
270
libcap-ng-devel \
271
+ libcmocka-devel \
272
libcurl-devel \
273
libdrm-devel \
274
libepoxy-devel \
275
@@ -XXX,XX +XXX,XX @@ RUN dnf update -y && \
276
libgcrypt-devel \
277
libiscsi-devel \
278
libjpeg-devel \
279
+ json-c-devel \
280
libnfs-devel \
281
libpmem-devel \
282
libpng-devel \
32
--
283
--
33
2.21.0
284
2.36.1
34
35
diff view generated by jsdifflib
1
From: Stefan Hajnoczi <stefanha@redhat.com>
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
2
3
Fixes: a6b257a08e3d72219f03e461a52152672fec0612
3
Define vfio-user object which is remote process server for QEMU. Setup
4
("file-posix: Handle undetectable alignment")
4
object initialization functions and properties necessary to instantiate
5
the object
6
7
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
8
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
9
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
10
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Message-id: e45a17001e9b38f451543a664ababdf860e5f2f2.1655151679.git.jag.raman@oracle.com
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
6
Message-id: 20190827101328.4062-1-stefanha@redhat.com
7
Reviewed-by: Thomas Huth <thuth@redhat.com>
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
---
13
---
10
block/file-posix.c | 2 +-
14
MAINTAINERS | 1 +
11
1 file changed, 1 insertion(+), 1 deletion(-)
15
qapi/qom.json | 20 +++-
12
16
include/hw/remote/machine.h | 2 +
13
diff --git a/block/file-posix.c b/block/file-posix.c
17
hw/remote/machine.c | 27 +++++
14
index XXXXXXX..XXXXXXX 100644
18
hw/remote/vfio-user-obj.c | 210 ++++++++++++++++++++++++++++++++++++
15
--- a/block/file-posix.c
19
hw/remote/meson.build | 1 +
16
+++ b/block/file-posix.c
20
hw/remote/trace-events | 3 +
17
@@ -XXX,XX +XXX,XX @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
21
7 files changed, 262 insertions(+), 2 deletions(-)
18
for (i = 0; i < ARRAY_SIZE(alignments); i++) {
22
create mode 100644 hw/remote/vfio-user-obj.c
19
align = alignments[i];
23
20
if (raw_is_io_aligned(fd, buf + align, max_align)) {
24
diff --git a/MAINTAINERS b/MAINTAINERS
21
- /* Fallback to request_aligment. */
25
index XXXXXXX..XXXXXXX 100644
22
+ /* Fallback to request_alignment. */
26
--- a/MAINTAINERS
23
s->buf_align = (align != 1) ? align : bs->bl.request_alignment;
27
+++ b/MAINTAINERS
24
break;
28
@@ -XXX,XX +XXX,XX @@ F: include/hw/remote/proxy-memory-listener.h
25
}
29
F: hw/remote/iohub.c
30
F: include/hw/remote/iohub.h
31
F: subprojects/libvfio-user
32
+F: hw/remote/vfio-user-obj.c
33
34
EBPF:
35
M: Jason Wang <jasowang@redhat.com>
36
diff --git a/qapi/qom.json b/qapi/qom.json
37
index XXXXXXX..XXXXXXX 100644
38
--- a/qapi/qom.json
39
+++ b/qapi/qom.json
40
@@ -XXX,XX +XXX,XX @@
41
{ 'struct': 'RemoteObjectProperties',
42
'data': { 'fd': 'str', 'devid': 'str' } }
43
44
+##
45
+# @VfioUserServerProperties:
46
+#
47
+# Properties for x-vfio-user-server objects.
48
+#
49
+# @socket: socket to be used by the libvfio-user library
50
+#
51
+# @device: the ID of the device to be emulated at the server
52
+#
53
+# Since: 7.1
54
+##
55
+{ 'struct': 'VfioUserServerProperties',
56
+ 'data': { 'socket': 'SocketAddress', 'device': 'str' } }
57
+
58
##
59
# @RngProperties:
60
#
61
@@ -XXX,XX +XXX,XX @@
62
'tls-creds-psk',
63
'tls-creds-x509',
64
'tls-cipher-suites',
65
- { 'name': 'x-remote-object', 'features': [ 'unstable' ] }
66
+ { 'name': 'x-remote-object', 'features': [ 'unstable' ] },
67
+ { 'name': 'x-vfio-user-server', 'features': [ 'unstable' ] }
68
] }
69
70
##
71
@@ -XXX,XX +XXX,XX @@
72
'tls-creds-psk': 'TlsCredsPskProperties',
73
'tls-creds-x509': 'TlsCredsX509Properties',
74
'tls-cipher-suites': 'TlsCredsProperties',
75
- 'x-remote-object': 'RemoteObjectProperties'
76
+ 'x-remote-object': 'RemoteObjectProperties',
77
+ 'x-vfio-user-server': 'VfioUserServerProperties'
78
} }
79
80
##
81
diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h
82
index XXXXXXX..XXXXXXX 100644
83
--- a/include/hw/remote/machine.h
84
+++ b/include/hw/remote/machine.h
85
@@ -XXX,XX +XXX,XX @@ struct RemoteMachineState {
86
RemoteIOHubState iohub;
87
88
bool vfio_user;
89
+
90
+ bool auto_shutdown;
91
};
92
93
/* Used to pass to co-routine device and ioc. */
94
diff --git a/hw/remote/machine.c b/hw/remote/machine.c
95
index XXXXXXX..XXXXXXX 100644
96
--- a/hw/remote/machine.c
97
+++ b/hw/remote/machine.c
98
@@ -XXX,XX +XXX,XX @@ static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp)
99
s->vfio_user = value;
100
}
101
102
+static bool remote_machine_get_auto_shutdown(Object *obj, Error **errp)
103
+{
104
+ RemoteMachineState *s = REMOTE_MACHINE(obj);
105
+
106
+ return s->auto_shutdown;
107
+}
108
+
109
+static void remote_machine_set_auto_shutdown(Object *obj, bool value,
110
+ Error **errp)
111
+{
112
+ RemoteMachineState *s = REMOTE_MACHINE(obj);
113
+
114
+ s->auto_shutdown = value;
115
+}
116
+
117
+static void remote_machine_instance_init(Object *obj)
118
+{
119
+ RemoteMachineState *s = REMOTE_MACHINE(obj);
120
+
121
+ s->auto_shutdown = true;
122
+}
123
+
124
static void remote_machine_class_init(ObjectClass *oc, void *data)
125
{
126
MachineClass *mc = MACHINE_CLASS(oc);
127
@@ -XXX,XX +XXX,XX @@ static void remote_machine_class_init(ObjectClass *oc, void *data)
128
object_class_property_add_bool(oc, "vfio-user",
129
remote_machine_get_vfio_user,
130
remote_machine_set_vfio_user);
131
+
132
+ object_class_property_add_bool(oc, "auto-shutdown",
133
+ remote_machine_get_auto_shutdown,
134
+ remote_machine_set_auto_shutdown);
135
}
136
137
static const TypeInfo remote_machine = {
138
.name = TYPE_REMOTE_MACHINE,
139
.parent = TYPE_MACHINE,
140
.instance_size = sizeof(RemoteMachineState),
141
+ .instance_init = remote_machine_instance_init,
142
.class_init = remote_machine_class_init,
143
.interfaces = (InterfaceInfo[]) {
144
{ TYPE_HOTPLUG_HANDLER },
145
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
146
new file mode 100644
147
index XXXXXXX..XXXXXXX
148
--- /dev/null
149
+++ b/hw/remote/vfio-user-obj.c
150
@@ -XXX,XX +XXX,XX @@
151
+/**
152
+ * QEMU vfio-user-server server object
153
+ *
154
+ * Copyright © 2022 Oracle and/or its affiliates.
155
+ *
156
+ * This work is licensed under the terms of the GNU GPL-v2, version 2 or later.
157
+ *
158
+ * See the COPYING file in the top-level directory.
159
+ *
160
+ */
161
+
162
+/**
163
+ * Usage: add options:
164
+ * -machine x-remote,vfio-user=on,auto-shutdown=on
165
+ * -device <PCI-device>,id=<pci-dev-id>
166
+ * -object x-vfio-user-server,id=<id>,type=unix,path=<socket-path>,
167
+ * device=<pci-dev-id>
168
+ *
169
+ * Note that x-vfio-user-server object must be used with x-remote machine only.
170
+ * This server could only support PCI devices for now.
171
+ *
172
+ * type - SocketAddress type - presently "unix" alone is supported. Required
173
+ * option
174
+ *
175
+ * path - named unix socket, it will be created by the server. It is
176
+ * a required option
177
+ *
178
+ * device - id of a device on the server, a required option. PCI devices
179
+ * alone are supported presently.
180
+ */
181
+
182
+#include "qemu/osdep.h"
183
+
184
+#include "qom/object.h"
185
+#include "qom/object_interfaces.h"
186
+#include "qemu/error-report.h"
187
+#include "trace.h"
188
+#include "sysemu/runstate.h"
189
+#include "hw/boards.h"
190
+#include "hw/remote/machine.h"
191
+#include "qapi/error.h"
192
+#include "qapi/qapi-visit-sockets.h"
193
+
194
+#define TYPE_VFU_OBJECT "x-vfio-user-server"
195
+OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
196
+
197
+/**
198
+ * VFU_OBJECT_ERROR - reports an error message. If auto_shutdown
199
+ * is set, it aborts the machine on error. Otherwise, it logs an
200
+ * error message without aborting.
201
+ */
202
+#define VFU_OBJECT_ERROR(o, fmt, ...) \
203
+ { \
204
+ if (vfu_object_auto_shutdown()) { \
205
+ error_setg(&error_abort, (fmt), ## __VA_ARGS__); \
206
+ } else { \
207
+ error_report((fmt), ## __VA_ARGS__); \
208
+ } \
209
+ } \
210
+
211
+struct VfuObjectClass {
212
+ ObjectClass parent_class;
213
+
214
+ unsigned int nr_devs;
215
+};
216
+
217
+struct VfuObject {
218
+ /* private */
219
+ Object parent;
220
+
221
+ SocketAddress *socket;
222
+
223
+ char *device;
224
+
225
+ Error *err;
226
+};
227
+
228
+static bool vfu_object_auto_shutdown(void)
229
+{
230
+ bool auto_shutdown = true;
231
+ Error *local_err = NULL;
232
+
233
+ if (!current_machine) {
234
+ return auto_shutdown;
235
+ }
236
+
237
+ auto_shutdown = object_property_get_bool(OBJECT(current_machine),
238
+ "auto-shutdown",
239
+ &local_err);
240
+
241
+ /*
242
+ * local_err would be set if no such property exists - safe to ignore.
243
+ * Unlikely scenario as auto-shutdown is always defined for
244
+ * TYPE_REMOTE_MACHINE, and TYPE_VFU_OBJECT only works with
245
+ * TYPE_REMOTE_MACHINE
246
+ */
247
+ if (local_err) {
248
+ auto_shutdown = true;
249
+ error_free(local_err);
250
+ }
251
+
252
+ return auto_shutdown;
253
+}
254
+
255
+static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name,
256
+ void *opaque, Error **errp)
257
+{
258
+ VfuObject *o = VFU_OBJECT(obj);
259
+
260
+ qapi_free_SocketAddress(o->socket);
261
+
262
+ o->socket = NULL;
263
+
264
+ visit_type_SocketAddress(v, name, &o->socket, errp);
265
+
266
+ if (o->socket->type != SOCKET_ADDRESS_TYPE_UNIX) {
267
+ error_setg(errp, "vfu: Unsupported socket type - %s",
268
+ SocketAddressType_str(o->socket->type));
269
+ qapi_free_SocketAddress(o->socket);
270
+ o->socket = NULL;
271
+ return;
272
+ }
273
+
274
+ trace_vfu_prop("socket", o->socket->u.q_unix.path);
275
+}
276
+
277
+static void vfu_object_set_device(Object *obj, const char *str, Error **errp)
278
+{
279
+ VfuObject *o = VFU_OBJECT(obj);
280
+
281
+ g_free(o->device);
282
+
283
+ o->device = g_strdup(str);
284
+
285
+ trace_vfu_prop("device", str);
286
+}
287
+
288
+static void vfu_object_init(Object *obj)
289
+{
290
+ VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj);
291
+ VfuObject *o = VFU_OBJECT(obj);
292
+
293
+ k->nr_devs++;
294
+
295
+ if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) {
296
+ error_setg(&o->err, "vfu: %s only compatible with %s machine",
297
+ TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE);
298
+ return;
299
+ }
300
+}
301
+
302
+static void vfu_object_finalize(Object *obj)
303
+{
304
+ VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj);
305
+ VfuObject *o = VFU_OBJECT(obj);
306
+
307
+ k->nr_devs--;
308
+
309
+ qapi_free_SocketAddress(o->socket);
310
+
311
+ o->socket = NULL;
312
+
313
+ g_free(o->device);
314
+
315
+ o->device = NULL;
316
+
317
+ if (!k->nr_devs && vfu_object_auto_shutdown()) {
318
+ qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
319
+ }
320
+}
321
+
322
+static void vfu_object_class_init(ObjectClass *klass, void *data)
323
+{
324
+ VfuObjectClass *k = VFU_OBJECT_CLASS(klass);
325
+
326
+ k->nr_devs = 0;
327
+
328
+ object_class_property_add(klass, "socket", "SocketAddress", NULL,
329
+ vfu_object_set_socket, NULL, NULL);
330
+ object_class_property_set_description(klass, "socket",
331
+ "SocketAddress "
332
+ "(ex: type=unix,path=/tmp/sock). "
333
+ "Only UNIX is presently supported");
334
+ object_class_property_add_str(klass, "device", NULL,
335
+ vfu_object_set_device);
336
+ object_class_property_set_description(klass, "device",
337
+ "device ID - only PCI devices "
338
+ "are presently supported");
339
+}
340
+
341
+static const TypeInfo vfu_object_info = {
342
+ .name = TYPE_VFU_OBJECT,
343
+ .parent = TYPE_OBJECT,
344
+ .instance_size = sizeof(VfuObject),
345
+ .instance_init = vfu_object_init,
346
+ .instance_finalize = vfu_object_finalize,
347
+ .class_size = sizeof(VfuObjectClass),
348
+ .class_init = vfu_object_class_init,
349
+ .interfaces = (InterfaceInfo[]) {
350
+ { TYPE_USER_CREATABLE },
351
+ { }
352
+ }
353
+};
354
+
355
+static void vfu_register_types(void)
356
+{
357
+ type_register_static(&vfu_object_info);
358
+}
359
+
360
+type_init(vfu_register_types);
361
diff --git a/hw/remote/meson.build b/hw/remote/meson.build
362
index XXXXXXX..XXXXXXX 100644
363
--- a/hw/remote/meson.build
364
+++ b/hw/remote/meson.build
365
@@ -XXX,XX +XXX,XX @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c'))
366
remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c'))
367
remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c'))
368
remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c'))
369
+remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: files('vfio-user-obj.c'))
370
371
remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: libvfio_user_dep)
372
373
diff --git a/hw/remote/trace-events b/hw/remote/trace-events
374
index XXXXXXX..XXXXXXX 100644
375
--- a/hw/remote/trace-events
376
+++ b/hw/remote/trace-events
377
@@ -XXX,XX +XXX,XX @@
378
379
mpqemu_send_io_error(int cmd, int size, int nfds) "send command %d size %d, %d file descriptors to remote process"
380
mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, %d file descriptors to remote process"
381
+
382
+# vfio-user-obj.c
383
+vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s"
26
--
384
--
27
2.21.0
385
2.36.1
28
386
29
387
diff view generated by jsdifflib
1
From: Nir Soffer <nirsof@gmail.com>
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
2
3
When creating an image with preallocation "off" or "falloc", the first
3
create a context with the vfio-user library to run a PCI device
4
block of the image is typically not allocated. When using Gluster
5
storage backed by XFS filesystem, reading this block using direct I/O
6
succeeds regardless of request length, fooling alignment detection.
7
4
8
In this case we fallback to a safe value (4096) instead of the optimal
5
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
9
value (512), which may lead to unneeded data copying when aligning
6
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
10
requests. Allocating the first block avoids the fallback.
7
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Message-id: a452871ac8c812ff96fc4f0ce6037f4769953fab.1655151679.git.jag.raman@oracle.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
12
hw/remote/vfio-user-obj.c | 82 +++++++++++++++++++++++++++++++++++++++
13
1 file changed, 82 insertions(+)
11
14
12
Since we allocate the first block even with preallocation=off, we no
15
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
13
longer create images with zero disk size:
14
15
$ ./qemu-img create -f raw test.raw 1g
16
Formatting 'test.raw', fmt=raw size=1073741824
17
18
$ ls -lhs test.raw
19
4.0K -rw-r--r--. 1 nsoffer nsoffer 1.0G Aug 16 23:48 test.raw
20
21
And converting the image requires additional cluster:
22
23
$ ./qemu-img measure -f raw -O qcow2 test.raw
24
required size: 458752
25
fully allocated size: 1074135040
26
27
When using format like vmdk with multiple files per image, we allocate
28
one block per file:
29
30
$ ./qemu-img create -f vmdk -o subformat=twoGbMaxExtentFlat test.vmdk 4g
31
Formatting 'test.vmdk', fmt=vmdk size=4294967296 compat6=off hwversion=undefined subformat=twoGbMaxExtentFlat
32
33
$ ls -lhs test*.vmdk
34
4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f001.vmdk
35
4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f002.vmdk
36
4.0K -rw-r--r--. 1 nsoffer nsoffer 353 Aug 27 03:23 test.vmdk
37
38
I did quick performance test for copying disks with qemu-img convert to
39
new raw target image to Gluster storage with sector size of 512 bytes:
40
41
for i in $(seq 10); do
42
rm -f dst.raw
43
sleep 10
44
time ./qemu-img convert -f raw -O raw -t none -T none src.raw dst.raw
45
done
46
47
Here is a table comparing the total time spent:
48
49
Type Before(s) After(s) Diff(%)
50
---------------------------------------
51
real 530.028 469.123 -11.4
52
user 17.204 10.768 -37.4
53
sys 17.881 7.011 -60.7
54
55
We can see very clear improvement in CPU usage.
56
57
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
58
Message-id: 20190827010528.8818-2-nsoffer@redhat.com
59
Reviewed-by: Max Reitz <mreitz@redhat.com>
60
Signed-off-by: Max Reitz <mreitz@redhat.com>
61
---
62
block/file-posix.c | 51 +++++++++++++++++++
63
tests/qemu-iotests/059.out | 2 +-
64
tests/qemu-iotests/{150.out => 150.out.qcow2} | 0
65
tests/qemu-iotests/150.out.raw | 12 +++++
66
tests/qemu-iotests/175 | 19 ++++---
67
tests/qemu-iotests/175.out | 8 +--
68
tests/qemu-iotests/178.out.qcow2 | 4 +-
69
tests/qemu-iotests/221.out | 12 +++--
70
tests/qemu-iotests/253.out | 12 +++--
71
9 files changed, 99 insertions(+), 21 deletions(-)
72
rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%)
73
create mode 100644 tests/qemu-iotests/150.out.raw
74
75
diff --git a/block/file-posix.c b/block/file-posix.c
76
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
77
--- a/block/file-posix.c
17
--- a/hw/remote/vfio-user-obj.c
78
+++ b/block/file-posix.c
18
+++ b/hw/remote/vfio-user-obj.c
79
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque)
19
@@ -XXX,XX +XXX,XX @@
80
return ret;
20
#include "hw/remote/machine.h"
21
#include "qapi/error.h"
22
#include "qapi/qapi-visit-sockets.h"
23
+#include "qemu/notify.h"
24
+#include "sysemu/sysemu.h"
25
+#include "libvfio-user.h"
26
27
#define TYPE_VFU_OBJECT "x-vfio-user-server"
28
OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
29
@@ -XXX,XX +XXX,XX @@ struct VfuObject {
30
char *device;
31
32
Error *err;
33
+
34
+ Notifier machine_done;
35
+
36
+ vfu_ctx_t *vfu_ctx;
37
};
38
39
+static void vfu_object_init_ctx(VfuObject *o, Error **errp);
40
+
41
static bool vfu_object_auto_shutdown(void)
42
{
43
bool auto_shutdown = true;
44
@@ -XXX,XX +XXX,XX @@ static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name,
45
{
46
VfuObject *o = VFU_OBJECT(obj);
47
48
+ if (o->vfu_ctx) {
49
+ error_setg(errp, "vfu: Unable to set socket property - server busy");
50
+ return;
51
+ }
52
+
53
qapi_free_SocketAddress(o->socket);
54
55
o->socket = NULL;
56
@@ -XXX,XX +XXX,XX @@ static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name,
57
}
58
59
trace_vfu_prop("socket", o->socket->u.q_unix.path);
60
+
61
+ vfu_object_init_ctx(o, errp);
81
}
62
}
82
63
83
+/*
64
static void vfu_object_set_device(Object *obj, const char *str, Error **errp)
84
+ * Help alignment probing by allocating the first block.
65
{
85
+ *
66
VfuObject *o = VFU_OBJECT(obj);
86
+ * When reading with direct I/O from unallocated area on Gluster backed by XFS,
67
87
+ * reading succeeds regardless of request length. In this case we fallback to
68
+ if (o->vfu_ctx) {
88
+ * safe alignment which is not optimal. Allocating the first block avoids this
69
+ error_setg(errp, "vfu: Unable to set device property - server busy");
89
+ * fallback.
70
+ return;
90
+ *
71
+ }
91
+ * fd may be opened with O_DIRECT, but we don't know the buffer alignment or
92
+ * request alignment, so we use safe values.
93
+ *
94
+ * Returns: 0 on success, -errno on failure. Since this is an optimization,
95
+ * caller may ignore failures.
96
+ */
97
+static int allocate_first_block(int fd, size_t max_size)
98
+{
99
+ size_t write_size = (max_size < MAX_BLOCKSIZE)
100
+ ? BDRV_SECTOR_SIZE
101
+ : MAX_BLOCKSIZE;
102
+ size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
103
+ void *buf;
104
+ ssize_t n;
105
+ int ret;
106
+
72
+
107
+ buf = qemu_memalign(max_align, write_size);
73
g_free(o->device);
108
+ memset(buf, 0, write_size);
74
75
o->device = g_strdup(str);
76
77
trace_vfu_prop("device", str);
109
+
78
+
110
+ do {
79
+ vfu_object_init_ctx(o, errp);
111
+ n = pwrite(fd, buf, write_size, 0);
112
+ } while (n == -1 && errno == EINTR);
113
+
114
+ ret = (n == -1) ? -errno : 0;
115
+
116
+ qemu_vfree(buf);
117
+ return ret;
118
+}
80
+}
119
+
81
+
120
static int handle_aiocb_truncate(void *opaque)
82
+/*
121
{
83
+ * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
122
RawPosixAIOData *aiocb = opaque;
84
+ * properties. It also depends on devices instantiated in QEMU. These
123
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque)
85
+ * dependencies are not available during the instance_init phase of this
124
/* posix_fallocate() doesn't set errno. */
86
+ * object's life-cycle. As such, the server is initialized after the
125
error_setg_errno(errp, -result,
87
+ * machine is setup. machine_init_done_notifier notifies TYPE_VFU_OBJECT
126
"Could not preallocate new data");
88
+ * when the machine is setup, and the dependencies are available.
127
+ } else if (current_length == 0) {
89
+ */
128
+ /*
90
+static void vfu_object_machine_done(Notifier *notifier, void *data)
129
+ * posix_fallocate() uses fallocate() if the filesystem
91
+{
130
+ * supports it, or fallback to manually writing zeroes. If
92
+ VfuObject *o = container_of(notifier, VfuObject, machine_done);
131
+ * fallocate() was used, unaligned reads from the fallocated
93
+ Error *err = NULL;
132
+ * area in raw_probe_alignment() will succeed, hence we need to
133
+ * allocate the first block.
134
+ *
135
+ * Optimize future alignment probing; ignore failures.
136
+ */
137
+ allocate_first_block(fd, offset);
138
}
139
} else {
140
result = 0;
141
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque)
142
if (ftruncate(fd, offset) != 0) {
143
result = -errno;
144
error_setg_errno(errp, -result, "Could not resize file");
145
+ } else if (current_length == 0 && offset > current_length) {
146
+ /* Optimize future alignment probing; ignore failures. */
147
+ allocate_first_block(fd, offset);
148
}
149
return result;
150
default:
151
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
152
index XXXXXXX..XXXXXXX 100644
153
--- a/tests/qemu-iotests/059.out
154
+++ b/tests/qemu-iotests/059.out
155
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMax
156
image: TEST_DIR/t.vmdk
157
file format: vmdk
158
virtual size: 0.977 TiB (1073741824000 bytes)
159
-disk size: 16 KiB
160
+disk size: 1.97 MiB
161
Format specific information:
162
cid: XXXXXXXX
163
parent cid: XXXXXXXX
164
diff --git a/tests/qemu-iotests/150.out b/tests/qemu-iotests/150.out.qcow2
165
similarity index 100%
166
rename from tests/qemu-iotests/150.out
167
rename to tests/qemu-iotests/150.out.qcow2
168
diff --git a/tests/qemu-iotests/150.out.raw b/tests/qemu-iotests/150.out.raw
169
new file mode 100644
170
index XXXXXXX..XXXXXXX
171
--- /dev/null
172
+++ b/tests/qemu-iotests/150.out.raw
173
@@ -XXX,XX +XXX,XX @@
174
+QA output created by 150
175
+
94
+
176
+=== Mapping sparse conversion ===
95
+ vfu_object_init_ctx(o, &err);
177
+
96
+
178
+Offset Length File
97
+ if (err) {
179
+0 0x1000 TEST_DIR/t.IMGFMT
98
+ error_propagate(&error_abort, err);
99
+ }
100
+}
180
+
101
+
181
+=== Mapping non-sparse conversion ===
102
+static void vfu_object_init_ctx(VfuObject *o, Error **errp)
103
+{
104
+ ERRP_GUARD();
182
+
105
+
183
+Offset Length File
106
+ if (o->vfu_ctx || !o->socket || !o->device ||
184
+0 0x100000 TEST_DIR/t.IMGFMT
107
+ !phase_check(PHASE_MACHINE_READY)) {
185
+*** done
108
+ return;
186
diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175
109
+ }
187
index XXXXXXX..XXXXXXX 100755
110
+
188
--- a/tests/qemu-iotests/175
111
+ if (o->err) {
189
+++ b/tests/qemu-iotests/175
112
+ error_propagate(errp, o->err);
190
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
113
+ o->err = NULL;
191
# the file size. This function hides the resulting difference in the
114
+ return;
192
# stat -c '%b' output.
115
+ }
193
# Parameter 1: Number of blocks an empty file occupies
116
+
194
-# Parameter 2: Image size in bytes
117
+ o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0,
195
+# Parameter 2: Minimal number of blocks in an image
118
+ o, VFU_DEV_TYPE_PCI);
196
+# Parameter 3: Image size in bytes
119
+ if (o->vfu_ctx == NULL) {
197
_filter_blocks()
120
+ error_setg(errp, "vfu: Failed to create context - %s", strerror(errno));
198
{
121
+ return;
199
extra_blocks=$1
122
+ }
200
- img_size=$2
201
+ min_blocks=$2
202
+ img_size=$3
203
204
- sed -e "s/blocks=$extra_blocks\\(\$\\|[^0-9]\\)/nothing allocated/" \
205
- -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/everything allocated/"
206
+ sed -e "s/blocks=$min_blocks\\(\$\\|[^0-9]\\)/min allocation/" \
207
+ -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/"
208
}
123
}
209
124
210
# get standard environment, filters and checks
125
static void vfu_object_init(Object *obj)
211
@@ -XXX,XX +XXX,XX @@ size=$((1 * 1024 * 1024))
126
@@ -XXX,XX +XXX,XX @@ static void vfu_object_init(Object *obj)
212
touch "$TEST_DIR/empty"
127
TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE);
213
extra_blocks=$(stat -c '%b' "$TEST_DIR/empty")
128
return;
214
129
}
215
+# We always write the first byte; check how many blocks this filesystem
216
+# allocates to match empty image alloation.
217
+printf "\0" > "$TEST_DIR/empty"
218
+min_blocks=$(stat -c '%b' "$TEST_DIR/empty")
219
+
130
+
220
echo
131
+ if (!phase_check(PHASE_MACHINE_READY)) {
221
echo "== creating image with default preallocation =="
132
+ o->machine_done.notify = vfu_object_machine_done;
222
_make_test_img $size | _filter_imgfmt
133
+ qemu_add_machine_init_done_notifier(&o->machine_done);
223
-stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size
134
+ }
224
+stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size
135
+
225
226
for mode in off full falloc; do
227
echo
228
echo "== creating image with preallocation $mode =="
229
IMGOPTS=preallocation=$mode _make_test_img $size | _filter_imgfmt
230
- stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size
231
+ stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size
232
done
233
234
# success, all done
235
diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out
236
index XXXXXXX..XXXXXXX 100644
237
--- a/tests/qemu-iotests/175.out
238
+++ b/tests/qemu-iotests/175.out
239
@@ -XXX,XX +XXX,XX @@ QA output created by 175
240
241
== creating image with default preallocation ==
242
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
243
-size=1048576, nothing allocated
244
+size=1048576, min allocation
245
246
== creating image with preallocation off ==
247
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=off
248
-size=1048576, nothing allocated
249
+size=1048576, min allocation
250
251
== creating image with preallocation full ==
252
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=full
253
-size=1048576, everything allocated
254
+size=1048576, max allocation
255
256
== creating image with preallocation falloc ==
257
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc
258
-size=1048576, everything allocated
259
+size=1048576, max allocation
260
*** done
261
diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.qcow2
262
index XXXXXXX..XXXXXXX 100644
263
--- a/tests/qemu-iotests/178.out.qcow2
264
+++ b/tests/qemu-iotests/178.out.qcow2
265
@@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608
266
== raw input image with data (human) ==
267
268
Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824
269
-required size: 393216
270
+required size: 458752
271
fully allocated size: 1074135040
272
wrote 512/512 bytes at offset 512
273
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
274
@@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608
275
276
Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824
277
{
278
- "required": 393216,
279
+ "required": 458752,
280
"fully-allocated": 1074135040
281
}
136
}
282
wrote 512/512 bytes at offset 512
137
283
diff --git a/tests/qemu-iotests/221.out b/tests/qemu-iotests/221.out
138
static void vfu_object_finalize(Object *obj)
284
index XXXXXXX..XXXXXXX 100644
139
@@ -XXX,XX +XXX,XX @@ static void vfu_object_finalize(Object *obj)
285
--- a/tests/qemu-iotests/221.out
140
286
+++ b/tests/qemu-iotests/221.out
141
o->socket = NULL;
287
@@ -XXX,XX +XXX,XX @@ QA output created by 221
142
288
=== Check mapping of unaligned raw image ===
143
+ if (o->vfu_ctx) {
289
144
+ vfu_destroy_ctx(o->vfu_ctx);
290
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65537
145
+ o->vfu_ctx = NULL;
291
-[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
146
+ }
292
-[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
147
+
293
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
148
g_free(o->device);
294
+{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
149
295
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
150
o->device = NULL;
296
+{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
151
@@ -XXX,XX +XXX,XX @@ static void vfu_object_finalize(Object *obj)
297
wrote 1/1 bytes at offset 65536
152
if (!k->nr_devs && vfu_object_auto_shutdown()) {
298
1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
153
qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
299
-[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
154
}
300
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
155
+
301
+{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
156
+ if (o->machine_done.notify) {
302
{ "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
157
+ qemu_remove_machine_init_done_notifier(&o->machine_done);
303
{ "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
158
+ o->machine_done.notify = NULL;
304
-[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
159
+ }
305
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
160
}
306
+{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
161
307
{ "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
162
static void vfu_object_class_init(ObjectClass *klass, void *data)
308
{ "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
309
*** done
310
diff --git a/tests/qemu-iotests/253.out b/tests/qemu-iotests/253.out
311
index XXXXXXX..XXXXXXX 100644
312
--- a/tests/qemu-iotests/253.out
313
+++ b/tests/qemu-iotests/253.out
314
@@ -XXX,XX +XXX,XX @@ QA output created by 253
315
=== Check mapping of unaligned raw image ===
316
317
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048575
318
-[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
319
-[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
320
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
321
+{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
322
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
323
+{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
324
wrote 65535/65535 bytes at offset 983040
325
63.999 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
326
-[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
327
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
328
+{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
329
{ "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
330
-[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
331
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
332
+{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
333
{ "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
334
*** done
335
--
163
--
336
2.21.0
164
2.36.1
337
338
diff view generated by jsdifflib
1
From: Denis Plotnikov <dplotnikov@virtuozzo.com>
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
2
3
The patch allows to provide a pattern file for write
3
Find the PCI device with specified id. Initialize the device context
4
command. There was no similar ability before.
4
with the QEMU PCI device
5
5
6
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
6
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
7
Message-id: 20190820164616.4072-1-dplotnikov@virtuozzo.com
7
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
8
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
9
[mreitz: Keep optstring in alphabetical order]
9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Message-id: 7798dbd730099b33fdd00c4c202cfe79e5c5c151.1655151679.git.jag.raman@oracle.com
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
12
---
12
qemu-io-cmds.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++---
13
hw/remote/vfio-user-obj.c | 67 +++++++++++++++++++++++++++++++++++++++
13
1 file changed, 93 insertions(+), 6 deletions(-)
14
1 file changed, 67 insertions(+)
14
15
15
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
16
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
16
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
17
--- a/qemu-io-cmds.c
18
--- a/hw/remote/vfio-user-obj.c
18
+++ b/qemu-io-cmds.c
19
+++ b/hw/remote/vfio-user-obj.c
19
@@ -XXX,XX +XXX,XX @@ static void qemu_io_free(void *p)
20
@@ -XXX,XX +XXX,XX @@
20
qemu_vfree(p);
21
#include "qemu/notify.h"
21
}
22
#include "sysemu/sysemu.h"
22
23
#include "libvfio-user.h"
23
+/*
24
+#include "hw/qdev-core.h"
24
+ * qemu_io_alloc_from_file()
25
+#include "hw/pci/pci.h"
25
+ *
26
26
+ * Allocates the buffer and populates it with the content of the given file
27
#define TYPE_VFU_OBJECT "x-vfio-user-server"
27
+ * up to @len bytes. If the file length is less than @len, then the buffer
28
OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
28
+ * is populated with the file content cyclically.
29
@@ -XXX,XX +XXX,XX @@ struct VfuObject {
29
+ *
30
Notifier machine_done;
30
+ * @blk - the block backend where the buffer content is going to be written to
31
31
+ * @len - the buffer length
32
vfu_ctx_t *vfu_ctx;
32
+ * @file_name - the file to read the content from
33
+ *
34
+ * Returns: the buffer pointer on success
35
+ * NULL on error
36
+ */
37
+static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
38
+ const char *file_name)
39
+{
40
+ char *buf, *buf_origin;
41
+ FILE *f = fopen(file_name, "r");
42
+ int pattern_len;
43
+
33
+
44
+ if (!f) {
34
+ PCIDevice *pci_dev;
45
+ perror(file_name);
35
+
46
+ return NULL;
36
+ Error *unplug_blocker;
37
};
38
39
static void vfu_object_init_ctx(VfuObject *o, Error **errp);
40
@@ -XXX,XX +XXX,XX @@ static void vfu_object_machine_done(Notifier *notifier, void *data)
41
static void vfu_object_init_ctx(VfuObject *o, Error **errp)
42
{
43
ERRP_GUARD();
44
+ DeviceState *dev = NULL;
45
+ vfu_pci_type_t pci_type = VFU_PCI_TYPE_CONVENTIONAL;
46
+ int ret;
47
48
if (o->vfu_ctx || !o->socket || !o->device ||
49
!phase_check(PHASE_MACHINE_READY)) {
50
@@ -XXX,XX +XXX,XX @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
51
error_setg(errp, "vfu: Failed to create context - %s", strerror(errno));
52
return;
53
}
54
+
55
+ dev = qdev_find_recursive(sysbus_get_default(), o->device);
56
+ if (dev == NULL) {
57
+ error_setg(errp, "vfu: Device %s not found", o->device);
58
+ goto fail;
47
+ }
59
+ }
48
+
60
+
49
+ if (qemuio_misalign) {
61
+ if (!object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
50
+ len += MISALIGN_OFFSET;
62
+ error_setg(errp, "vfu: %s not a PCI device", o->device);
63
+ goto fail;
51
+ }
64
+ }
52
+
65
+
53
+ buf_origin = buf = blk_blockalign(blk, len);
66
+ o->pci_dev = PCI_DEVICE(dev);
54
+
67
+
55
+ if (qemuio_misalign) {
68
+ object_ref(OBJECT(o->pci_dev));
56
+ buf_origin += MISALIGN_OFFSET;
69
+
57
+ buf += MISALIGN_OFFSET;
70
+ if (pci_is_express(o->pci_dev)) {
58
+ len -= MISALIGN_OFFSET;
71
+ pci_type = VFU_PCI_TYPE_EXPRESS;
59
+ }
72
+ }
60
+
73
+
61
+ pattern_len = fread(buf_origin, 1, len, f);
74
+ ret = vfu_pci_init(o->vfu_ctx, pci_type, PCI_HEADER_TYPE_NORMAL, 0);
62
+
75
+ if (ret < 0) {
63
+ if (ferror(f)) {
76
+ error_setg(errp,
64
+ perror(file_name);
77
+ "vfu: Failed to attach PCI device %s to context - %s",
65
+ goto error;
78
+ o->device, strerror(errno));
79
+ goto fail;
66
+ }
80
+ }
67
+
81
+
68
+ if (pattern_len == 0) {
82
+ error_setg(&o->unplug_blocker,
69
+ fprintf(stderr, "%s: file is empty\n", file_name);
83
+ "vfu: %s for %s must be deleted before unplugging",
70
+ goto error;
84
+ TYPE_VFU_OBJECT, o->device);
85
+ qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
86
+
87
+ return;
88
+
89
+fail:
90
+ vfu_destroy_ctx(o->vfu_ctx);
91
+ if (o->unplug_blocker && o->pci_dev) {
92
+ qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
93
+ error_free(o->unplug_blocker);
94
+ o->unplug_blocker = NULL;
95
+ }
96
+ if (o->pci_dev) {
97
+ object_unref(OBJECT(o->pci_dev));
98
+ o->pci_dev = NULL;
99
+ }
100
+ o->vfu_ctx = NULL;
101
}
102
103
static void vfu_object_init(Object *obj)
104
@@ -XXX,XX +XXX,XX @@ static void vfu_object_finalize(Object *obj)
105
106
o->device = NULL;
107
108
+ if (o->unplug_blocker && o->pci_dev) {
109
+ qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
110
+ error_free(o->unplug_blocker);
111
+ o->unplug_blocker = NULL;
71
+ }
112
+ }
72
+
113
+
73
+ fclose(f);
114
+ if (o->pci_dev) {
74
+
115
+ object_unref(OBJECT(o->pci_dev));
75
+ if (len > pattern_len) {
116
+ o->pci_dev = NULL;
76
+ len -= pattern_len;
77
+ buf += pattern_len;
78
+
79
+ while (len > 0) {
80
+ size_t len_to_copy = MIN(pattern_len, len);
81
+
82
+ memcpy(buf, buf_origin, len_to_copy);
83
+
84
+ len -= len_to_copy;
85
+ buf += len_to_copy;
86
+ }
87
+ }
117
+ }
88
+
118
+
89
+ return buf_origin;
119
if (!k->nr_devs && vfu_object_auto_shutdown()) {
90
+
120
qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
91
+error:
92
+ qemu_io_free(buf_origin);
93
+ return NULL;
94
+}
95
+
96
static void dump_buffer(const void *buffer, int64_t offset, int64_t len)
97
{
98
uint64_t i;
99
@@ -XXX,XX +XXX,XX @@ static void write_help(void)
100
" -n, -- with -z, don't allow slow fallback\n"
101
" -p, -- ignored for backwards compatibility\n"
102
" -P, -- use different pattern to fill file\n"
103
+" -s, -- use a pattern file to fill the write buffer\n"
104
" -C, -- report statistics in a machine parsable format\n"
105
" -q, -- quiet mode, do not show I/O statistics\n"
106
" -u, -- with -z, allow unmapping\n"
107
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t write_cmd = {
108
.perm = BLK_PERM_WRITE,
109
.argmin = 2,
110
.argmax = -1,
111
- .args = "[-bcCfnquz] [-P pattern] off len",
112
+ .args = "[-bcCfnquz] [-P pattern | -s source_file] off len",
113
.oneline = "writes a number of bytes at a specified offset",
114
.help = write_help,
115
};
116
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
117
{
118
struct timespec t1, t2;
119
bool Cflag = false, qflag = false, bflag = false;
120
- bool Pflag = false, zflag = false, cflag = false;
121
+ bool Pflag = false, zflag = false, cflag = false, sflag = false;
122
int flags = 0;
123
int c, cnt, ret;
124
char *buf = NULL;
125
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
126
/* Some compilers get confused and warn if this is not initialized. */
127
int64_t total = 0;
128
int pattern = 0xcd;
129
+ const char *file_name = NULL;
130
131
- while ((c = getopt(argc, argv, "bcCfnpP:quz")) != -1) {
132
+ while ((c = getopt(argc, argv, "bcCfnpP:qs:uz")) != -1) {
133
switch (c) {
134
case 'b':
135
bflag = true;
136
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
137
case 'q':
138
qflag = true;
139
break;
140
+ case 's':
141
+ sflag = true;
142
+ file_name = optarg;
143
+ break;
144
case 'u':
145
flags |= BDRV_REQ_MAY_UNMAP;
146
break;
147
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
148
return -EINVAL;
149
}
121
}
150
151
- if (zflag && Pflag) {
152
- printf("-z and -P cannot be specified at the same time\n");
153
+ if (zflag + Pflag + sflag > 1) {
154
+ printf("Only one of -z, -P, and -s "
155
+ "can be specified at the same time\n");
156
return -EINVAL;
157
}
158
159
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
160
}
161
162
if (!zflag) {
163
- buf = qemu_io_alloc(blk, count, pattern);
164
+ if (sflag) {
165
+ buf = qemu_io_alloc_from_file(blk, count, file_name);
166
+ if (!buf) {
167
+ return -EINVAL;
168
+ }
169
+ } else {
170
+ buf = qemu_io_alloc(blk, count, pattern);
171
+ }
172
}
173
174
clock_gettime(CLOCK_MONOTONIC, &t1);
175
--
122
--
176
2.21.0
123
2.36.1
177
178
diff view generated by jsdifflib
1
This makes iotest 033 pass with e.g. subformat=monolithicFlat. It also
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
turns a former error in 059 into success.
3
2
4
Signed-off-by: Max Reitz <mreitz@redhat.com>
3
Setup a handler to run vfio-user context. The context is driven by
5
Message-id: 20190815153638.4600-3-mreitz@redhat.com
4
messages to the file descriptor associated with it - get the fd for
6
Reviewed-by: John Snow <jsnow@redhat.com>
5
the context and hook up the handler with it
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
6
7
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
8
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
9
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
10
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Message-id: e934b0090529d448b6a7972b21dfc3d7421ce494.1655151679.git.jag.raman@oracle.com
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
8
---
13
---
9
block/vmdk.c | 54 ++++++++++++++++++++++++--------------
14
qapi/misc.json | 31 ++++++++++
10
tests/qemu-iotests/059 | 7 +++--
15
hw/remote/vfio-user-obj.c | 118 +++++++++++++++++++++++++++++++++++++-
11
tests/qemu-iotests/059.out | 4 ++-
16
2 files changed, 148 insertions(+), 1 deletion(-)
12
3 files changed, 42 insertions(+), 23 deletions(-)
13
17
14
diff --git a/block/vmdk.c b/block/vmdk.c
18
diff --git a/qapi/misc.json b/qapi/misc.json
15
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
16
--- a/block/vmdk.c
20
--- a/qapi/misc.json
17
+++ b/block/vmdk.c
21
+++ b/qapi/misc.json
18
@@ -XXX,XX +XXX,XX @@ static const char *next_line(const char *s)
22
@@ -XXX,XX +XXX,XX @@
23
##
24
{ 'event': 'RTC_CHANGE',
25
'data': { 'offset': 'int', 'qom-path': 'str' } }
26
+
27
+##
28
+# @VFU_CLIENT_HANGUP:
29
+#
30
+# Emitted when the client of a TYPE_VFIO_USER_SERVER closes the
31
+# communication channel
32
+#
33
+# @vfu-id: ID of the TYPE_VFIO_USER_SERVER object. It is the last component
34
+# of @vfu-qom-path referenced below
35
+#
36
+# @vfu-qom-path: path to the TYPE_VFIO_USER_SERVER object in the QOM tree
37
+#
38
+# @dev-id: ID of attached PCI device
39
+#
40
+# @dev-qom-path: path to attached PCI device in the QOM tree
41
+#
42
+# Since: 7.1
43
+#
44
+# Example:
45
+#
46
+# <- { "event": "VFU_CLIENT_HANGUP",
47
+# "data": { "vfu-id": "vfu1",
48
+# "vfu-qom-path": "/objects/vfu1",
49
+# "dev-id": "sas1",
50
+# "dev-qom-path": "/machine/peripheral/sas1" },
51
+# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
52
+#
53
+##
54
+{ 'event': 'VFU_CLIENT_HANGUP',
55
+ 'data': { 'vfu-id': 'str', 'vfu-qom-path': 'str',
56
+ 'dev-id': 'str', 'dev-qom-path': 'str' } }
57
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
58
index XXXXXXX..XXXXXXX 100644
59
--- a/hw/remote/vfio-user-obj.c
60
+++ b/hw/remote/vfio-user-obj.c
61
@@ -XXX,XX +XXX,XX @@
62
*
63
* device - id of a device on the server, a required option. PCI devices
64
* alone are supported presently.
65
+ *
66
+ * notes - x-vfio-user-server could block IO and monitor during the
67
+ * initialization phase.
68
*/
69
70
#include "qemu/osdep.h"
71
@@ -XXX,XX +XXX,XX @@
72
#include "hw/remote/machine.h"
73
#include "qapi/error.h"
74
#include "qapi/qapi-visit-sockets.h"
75
+#include "qapi/qapi-events-misc.h"
76
#include "qemu/notify.h"
77
+#include "qemu/thread.h"
78
#include "sysemu/sysemu.h"
79
#include "libvfio-user.h"
80
#include "hw/qdev-core.h"
81
#include "hw/pci/pci.h"
82
+#include "qemu/timer.h"
83
84
#define TYPE_VFU_OBJECT "x-vfio-user-server"
85
OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
86
@@ -XXX,XX +XXX,XX @@ struct VfuObject {
87
PCIDevice *pci_dev;
88
89
Error *unplug_blocker;
90
+
91
+ int vfu_poll_fd;
92
};
93
94
static void vfu_object_init_ctx(VfuObject *o, Error **errp);
95
@@ -XXX,XX +XXX,XX @@ static void vfu_object_set_device(Object *obj, const char *str, Error **errp)
96
vfu_object_init_ctx(o, errp);
19
}
97
}
20
98
21
static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
99
+static void vfu_object_ctx_run(void *opaque)
22
- const char *desc_file_path, QDict *options,
100
+{
23
- Error **errp)
101
+ VfuObject *o = opaque;
24
+ QDict *options, Error **errp)
102
+ const char *vfu_id;
103
+ char *vfu_path, *pci_dev_path;
104
+ int ret = -1;
105
+
106
+ while (ret != 0) {
107
+ ret = vfu_run_ctx(o->vfu_ctx);
108
+ if (ret < 0) {
109
+ if (errno == EINTR) {
110
+ continue;
111
+ } else if (errno == ENOTCONN) {
112
+ vfu_id = object_get_canonical_path_component(OBJECT(o));
113
+ vfu_path = object_get_canonical_path(OBJECT(o));
114
+ g_assert(o->pci_dev);
115
+ pci_dev_path = object_get_canonical_path(OBJECT(o->pci_dev));
116
+ /* o->device is a required property and is non-NULL here */
117
+ g_assert(o->device);
118
+ qapi_event_send_vfu_client_hangup(vfu_id, vfu_path,
119
+ o->device, pci_dev_path);
120
+ qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL);
121
+ o->vfu_poll_fd = -1;
122
+ object_unparent(OBJECT(o));
123
+ g_free(vfu_path);
124
+ g_free(pci_dev_path);
125
+ break;
126
+ } else {
127
+ VFU_OBJECT_ERROR(o, "vfu: Failed to run device %s - %s",
128
+ o->device, strerror(errno));
129
+ break;
130
+ }
131
+ }
132
+ }
133
+}
134
+
135
+static void vfu_object_attach_ctx(void *opaque)
136
+{
137
+ VfuObject *o = opaque;
138
+ GPollFD pfds[1];
139
+ int ret;
140
+
141
+ qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL);
142
+
143
+ pfds[0].fd = o->vfu_poll_fd;
144
+ pfds[0].events = G_IO_IN | G_IO_HUP | G_IO_ERR;
145
+
146
+retry_attach:
147
+ ret = vfu_attach_ctx(o->vfu_ctx);
148
+ if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
149
+ /**
150
+ * vfu_object_attach_ctx can block QEMU's main loop
151
+ * during attach - the monitor and other IO
152
+ * could be unresponsive during this time.
153
+ */
154
+ (void)qemu_poll_ns(pfds, 1, 500 * (int64_t)SCALE_MS);
155
+ goto retry_attach;
156
+ } else if (ret < 0) {
157
+ VFU_OBJECT_ERROR(o, "vfu: Failed to attach device %s to context - %s",
158
+ o->device, strerror(errno));
159
+ return;
160
+ }
161
+
162
+ o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx);
163
+ if (o->vfu_poll_fd < 0) {
164
+ VFU_OBJECT_ERROR(o, "vfu: Failed to get poll fd %s", o->device);
165
+ return;
166
+ }
167
+
168
+ qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o);
169
+}
170
+
171
/*
172
* TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
173
* properties. It also depends on devices instantiated in QEMU. These
174
@@ -XXX,XX +XXX,XX @@ static void vfu_object_machine_done(Notifier *notifier, void *data)
175
}
176
}
177
178
+/**
179
+ * vfu_object_init_ctx: Create and initialize libvfio-user context. Add
180
+ * an unplug blocker for the associated PCI device. Setup a FD handler
181
+ * to process incoming messages in the context's socket.
182
+ *
183
+ * The socket and device properties are mandatory, and this function
184
+ * will not create the context without them - the setters for these
185
+ * properties should call this function when the property is set. The
186
+ * machine should also be ready when this function is invoked - it is
187
+ * because QEMU objects are initialized before devices, and the
188
+ * associated PCI device wouldn't be available at the object
189
+ * initialization time. Until these conditions are satisfied, this
190
+ * function would return early without performing any task.
191
+ */
192
static void vfu_object_init_ctx(VfuObject *o, Error **errp)
25
{
193
{
26
int ret;
194
ERRP_GUARD();
27
int matches;
195
@@ -XXX,XX +XXX,XX @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
28
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
196
return;
29
const char *p, *np;
30
int64_t sectors = 0;
31
int64_t flat_offset;
32
+ char *desc_file_dir = NULL;
33
char *extent_path;
34
BdrvChild *extent_file;
35
BDRVVmdkState *s = bs->opaque;
36
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
37
continue;
38
}
39
40
- if (!path_is_absolute(fname) && !path_has_protocol(fname) &&
41
- !desc_file_path[0])
42
- {
43
- bdrv_refresh_filename(bs->file->bs);
44
- error_setg(errp, "Cannot use relative extent paths with VMDK "
45
- "descriptor file '%s'", bs->file->bs->filename);
46
- return -EINVAL;
47
- }
48
+ if (path_is_absolute(fname)) {
49
+ extent_path = g_strdup(fname);
50
+ } else {
51
+ if (!desc_file_dir) {
52
+ desc_file_dir = bdrv_dirname(bs->file->bs, errp);
53
+ if (!desc_file_dir) {
54
+ bdrv_refresh_filename(bs->file->bs);
55
+ error_prepend(errp, "Cannot use relative paths with VMDK "
56
+ "descriptor file '%s': ",
57
+ bs->file->bs->filename);
58
+ ret = -EINVAL;
59
+ goto out;
60
+ }
61
+ }
62
63
- extent_path = path_combine(desc_file_path, fname);
64
+ extent_path = g_strconcat(desc_file_dir, fname, NULL);
65
+ }
66
67
ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents);
68
assert(ret < 32);
69
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
70
g_free(extent_path);
71
if (local_err) {
72
error_propagate(errp, local_err);
73
- return -EINVAL;
74
+ ret = -EINVAL;
75
+ goto out;
76
}
77
78
/* save to extents array */
79
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
80
0, 0, 0, 0, 0, &extent, errp);
81
if (ret < 0) {
82
bdrv_unref_child(bs, extent_file);
83
- return ret;
84
+ goto out;
85
}
86
extent->flat_start_offset = flat_offset << 9;
87
} else if (!strcmp(type, "SPARSE") || !strcmp(type, "VMFSSPARSE")) {
88
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
89
g_free(buf);
90
if (ret) {
91
bdrv_unref_child(bs, extent_file);
92
- return ret;
93
+ goto out;
94
}
95
extent = &s->extents[s->num_extents - 1];
96
} else if (!strcmp(type, "SESPARSE")) {
97
ret = vmdk_open_se_sparse(bs, extent_file, bs->open_flags, errp);
98
if (ret) {
99
bdrv_unref_child(bs, extent_file);
100
- return ret;
101
+ goto out;
102
}
103
extent = &s->extents[s->num_extents - 1];
104
} else {
105
error_setg(errp, "Unsupported extent type '%s'", type);
106
bdrv_unref_child(bs, extent_file);
107
- return -ENOTSUP;
108
+ ret = -ENOTSUP;
109
+ goto out;
110
}
111
extent->type = g_strdup(type);
112
}
197
}
113
- return 0;
198
114
+
199
- o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0,
115
+ ret = 0;
200
+ o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path,
116
+ goto out;
201
+ LIBVFIO_USER_FLAG_ATTACH_NB,
117
202
o, VFU_DEV_TYPE_PCI);
118
invalid:
203
if (o->vfu_ctx == NULL) {
119
np = next_line(p);
204
error_setg(errp, "vfu: Failed to create context - %s", strerror(errno));
120
@@ -XXX,XX +XXX,XX @@ invalid:
205
@@ -XXX,XX +XXX,XX @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
121
np--;
206
TYPE_VFU_OBJECT, o->device);
207
qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
208
209
+ ret = vfu_realize_ctx(o->vfu_ctx);
210
+ if (ret < 0) {
211
+ error_setg(errp, "vfu: Failed to realize device %s- %s",
212
+ o->device, strerror(errno));
213
+ goto fail;
214
+ }
215
+
216
+ o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx);
217
+ if (o->vfu_poll_fd < 0) {
218
+ error_setg(errp, "vfu: Failed to get poll fd %s", o->device);
219
+ goto fail;
220
+ }
221
+
222
+ qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_attach_ctx, NULL, o);
223
+
224
return;
225
226
fail:
227
@@ -XXX,XX +XXX,XX @@ static void vfu_object_init(Object *obj)
228
qemu_add_machine_init_done_notifier(&o->machine_done);
122
}
229
}
123
error_setg(errp, "Invalid extent line: %.*s", (int)(np - p), p);
230
124
- return -EINVAL;
231
+ o->vfu_poll_fd = -1;
125
+ ret = -EINVAL;
126
+
127
+out:
128
+ g_free(desc_file_dir);
129
+ return ret;
130
}
232
}
131
233
132
static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
234
static void vfu_object_finalize(Object *obj)
133
@@ -XXX,XX +XXX,XX @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
235
@@ -XXX,XX +XXX,XX @@ static void vfu_object_finalize(Object *obj)
134
}
236
135
s->create_type = g_strdup(ct);
237
o->socket = NULL;
136
s->desc_offset = 0;
238
137
- ret = vmdk_parse_extents(buf, bs, bs->file->bs->exact_filename, options,
239
+ if (o->vfu_poll_fd != -1) {
138
- errp);
240
+ qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL);
139
+ ret = vmdk_parse_extents(buf, bs, options, errp);
241
+ o->vfu_poll_fd = -1;
140
exit:
242
+ }
141
return ret;
243
+
142
}
244
if (o->vfu_ctx) {
143
diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059
245
vfu_destroy_ctx(o->vfu_ctx);
144
index XXXXXXX..XXXXXXX 100755
246
o->vfu_ctx = NULL;
145
--- a/tests/qemu-iotests/059
146
+++ b/tests/qemu-iotests/059
147
@@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2
148
149
echo
150
echo "=== Testing monolithicFlat with internally generated JSON file name ==="
151
+# Should work, because bdrv_dirname() works fine with blkdebug
152
IMGOPTS="subformat=monolithicFlat" _make_test_img 64M
153
-$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" 2>&1 \
154
- | _filter_testdir | _filter_imgfmt
155
+$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \
156
+ -c info \
157
+ 2>&1 \
158
+ | _filter_testdir | _filter_imgfmt | _filter_img_info
159
_cleanup_test_img
160
161
echo
162
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
163
index XXXXXXX..XXXXXXX 100644
164
--- a/tests/qemu-iotests/059.out
165
+++ b/tests/qemu-iotests/059.out
166
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240
167
168
=== Testing monolithicFlat with internally generated JSON file name ===
169
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
170
-qemu-io: can't open: Cannot use relative extent paths with VMDK descriptor file 'json:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "read_aio"}'
171
+format name: IMGFMT
172
+cluster size: 0 bytes
173
+vm state offset: 0 bytes
174
175
=== Testing version 3 ===
176
image: TEST_DIR/iotest-version3.IMGFMT
177
--
247
--
178
2.21.0
248
2.36.1
179
180
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
2
3
It is possible to enable only a subset of the block drivers with the
3
Define and register handlers for PCI config space accesses
4
"--block-drv-rw-whitelist" option of the "configure" script. All other
5
drivers are marked as unusable (or only included as read-only with the
6
"--block-drv-ro-whitelist" option). If an iotest is now using such a
7
disabled block driver, it is failing - which is bad, since at least the
8
tests in the "auto" group should be able to deal with this situation.
9
Thus let's introduce a "_require_drivers" function that can be used by
10
the shell tests to check for the availability of certain drivers first,
11
and marks the test as "not run" if one of the drivers is missing.
12
4
13
This patch mainly targets the test in the "auto" group which should
5
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
14
never fail in such a case, but also improves some of the other tests
6
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
15
along the way. Note that we also assume that the "qcow2" and "file"
7
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
16
drivers are always available - otherwise it does not make sense to
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
17
run "make check-block" at all (which only tests with qcow2 by default).
9
Message-id: be9d2ccf9b1d24e50dcd9c23404dbf284142cec7.1655151679.git.jag.raman@oracle.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
12
hw/remote/vfio-user-obj.c | 51 +++++++++++++++++++++++++++++++++++++++
13
hw/remote/trace-events | 2 ++
14
2 files changed, 53 insertions(+)
18
15
19
Signed-off-by: Thomas Huth <thuth@redhat.com>
16
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
20
Message-id: 20190823133552.11680-1-thuth@redhat.com
17
index XXXXXXX..XXXXXXX 100644
21
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
--- a/hw/remote/vfio-user-obj.c
22
---
19
+++ b/hw/remote/vfio-user-obj.c
23
tests/qemu-iotests/071 | 1 +
20
@@ -XXX,XX +XXX,XX @@
24
tests/qemu-iotests/081 | 4 +---
21
#include "qapi/qapi-events-misc.h"
25
tests/qemu-iotests/099 | 1 +
22
#include "qemu/notify.h"
26
tests/qemu-iotests/120 | 1 +
23
#include "qemu/thread.h"
27
tests/qemu-iotests/162 | 4 +---
24
+#include "qemu/main-loop.h"
28
tests/qemu-iotests/184 | 1 +
25
#include "sysemu/sysemu.h"
29
tests/qemu-iotests/186 | 1 +
26
#include "libvfio-user.h"
30
tests/qemu-iotests/common.rc | 14 ++++++++++++++
27
#include "hw/qdev-core.h"
31
8 files changed, 21 insertions(+), 6 deletions(-)
28
@@ -XXX,XX +XXX,XX @@ retry_attach:
32
29
qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o);
33
diff --git a/tests/qemu-iotests/071 b/tests/qemu-iotests/071
34
index XXXXXXX..XXXXXXX 100755
35
--- a/tests/qemu-iotests/071
36
+++ b/tests/qemu-iotests/071
37
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
38
39
_supported_fmt qcow2
40
_supported_proto file
41
+_require_drivers blkdebug blkverify
42
43
do_run_qemu()
44
{
45
diff --git a/tests/qemu-iotests/081 b/tests/qemu-iotests/081
46
index XXXXXXX..XXXXXXX 100755
47
--- a/tests/qemu-iotests/081
48
+++ b/tests/qemu-iotests/081
49
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
50
_supported_fmt raw
51
_supported_proto file
52
_supported_os Linux
53
+_require_drivers quorum
54
55
do_run_qemu()
56
{
57
@@ -XXX,XX +XXX,XX @@ run_qemu()
58
| _filter_qemu_io | _filter_generated_node_ids
59
}
30
}
60
31
61
-test_quorum=$($QEMU_IMG --help|grep quorum)
32
+static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf,
62
-[ "$test_quorum" = "" ] && _supported_fmt quorum
33
+ size_t count, loff_t offset,
63
-
34
+ const bool is_write)
64
quorum="driver=raw,file.driver=quorum,file.vote-threshold=2"
65
quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
66
quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
67
diff --git a/tests/qemu-iotests/099 b/tests/qemu-iotests/099
68
index XXXXXXX..XXXXXXX 100755
69
--- a/tests/qemu-iotests/099
70
+++ b/tests/qemu-iotests/099
71
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
72
_supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc
73
_supported_proto file
74
_supported_os Linux
75
+_require_drivers blkdebug blkverify
76
_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
77
"subformat=twoGbMaxExtentSparse"
78
79
diff --git a/tests/qemu-iotests/120 b/tests/qemu-iotests/120
80
index XXXXXXX..XXXXXXX 100755
81
--- a/tests/qemu-iotests/120
82
+++ b/tests/qemu-iotests/120
83
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
84
_supported_fmt generic
85
_supported_proto file
86
_unsupported_fmt luks
87
+_require_drivers raw
88
89
_make_test_img 64M
90
91
diff --git a/tests/qemu-iotests/162 b/tests/qemu-iotests/162
92
index XXXXXXX..XXXXXXX 100755
93
--- a/tests/qemu-iotests/162
94
+++ b/tests/qemu-iotests/162
95
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
96
. ./common.filter
97
98
_supported_fmt generic
99
-
100
-test_ssh=$($QEMU_IMG --help | grep '^Supported formats:.* ssh\( \|$\)')
101
-[ "$test_ssh" = "" ] && _notrun "ssh support required"
102
+_require_drivers ssh
103
104
echo
105
echo '=== NBD ==='
106
diff --git a/tests/qemu-iotests/184 b/tests/qemu-iotests/184
107
index XXXXXXX..XXXXXXX 100755
108
--- a/tests/qemu-iotests/184
109
+++ b/tests/qemu-iotests/184
110
@@ -XXX,XX +XXX,XX @@ trap "exit \$status" 0 1 2 3 15
111
. ./common.filter
112
113
_supported_os Linux
114
+_require_drivers throttle
115
116
do_run_qemu()
117
{
118
diff --git a/tests/qemu-iotests/186 b/tests/qemu-iotests/186
119
index XXXXXXX..XXXXXXX 100755
120
--- a/tests/qemu-iotests/186
121
+++ b/tests/qemu-iotests/186
122
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
123
124
_supported_fmt qcow2
125
_supported_proto file
126
+_require_drivers null-co
127
128
if [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then
129
_notrun "Requires a PC machine"
130
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
131
index XXXXXXX..XXXXXXX 100644
132
--- a/tests/qemu-iotests/common.rc
133
+++ b/tests/qemu-iotests/common.rc
134
@@ -XXX,XX +XXX,XX @@ _require_command()
135
[ -x "$c" ] || _notrun "$1 utility required, skipped this test"
136
}
137
138
+# Check that a set of drivers has been whitelisted in the QEMU binary
139
+#
140
+_require_drivers()
141
+{
35
+{
142
+ available=$($QEMU -drive format=help | \
36
+ VfuObject *o = vfu_get_private(vfu_ctx);
143
+ sed -e '/Supported formats:/!d' -e 's/Supported formats://')
37
+ uint32_t pci_access_width = sizeof(uint32_t);
144
+ for driver
38
+ size_t bytes = count;
145
+ do
39
+ uint32_t val = 0;
146
+ if ! echo "$available" | grep -q " $driver\( \|$\)"; then
40
+ char *ptr = buf;
147
+ _notrun "$driver not available"
41
+ int len;
148
+ fi
42
+
149
+ done
43
+ /*
44
+ * Writes to the BAR registers would trigger an update to the
45
+ * global Memory and IO AddressSpaces. But the remote device
46
+ * never uses the global AddressSpaces, therefore overlapping
47
+ * memory regions are not a problem
48
+ */
49
+ while (bytes > 0) {
50
+ len = (bytes > pci_access_width) ? pci_access_width : bytes;
51
+ if (is_write) {
52
+ memcpy(&val, ptr, len);
53
+ pci_host_config_write_common(o->pci_dev, offset,
54
+ pci_config_size(o->pci_dev),
55
+ val, len);
56
+ trace_vfu_cfg_write(offset, val);
57
+ } else {
58
+ val = pci_host_config_read_common(o->pci_dev, offset,
59
+ pci_config_size(o->pci_dev), len);
60
+ memcpy(ptr, &val, len);
61
+ trace_vfu_cfg_read(offset, val);
62
+ }
63
+ offset += len;
64
+ ptr += len;
65
+ bytes -= len;
66
+ }
67
+
68
+ return count;
150
+}
69
+}
151
+
70
+
152
# make sure this script returns success
71
/*
153
true
72
* TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
73
* properties. It also depends on devices instantiated in QEMU. These
74
@@ -XXX,XX +XXX,XX @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
75
TYPE_VFU_OBJECT, o->device);
76
qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
77
78
+ ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_CFG_REGION_IDX,
79
+ pci_config_size(o->pci_dev), &vfu_object_cfg_access,
80
+ VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB,
81
+ NULL, 0, -1, 0);
82
+ if (ret < 0) {
83
+ error_setg(errp,
84
+ "vfu: Failed to setup config space handlers for %s- %s",
85
+ o->device, strerror(errno));
86
+ goto fail;
87
+ }
88
+
89
ret = vfu_realize_ctx(o->vfu_ctx);
90
if (ret < 0) {
91
error_setg(errp, "vfu: Failed to realize device %s- %s",
92
diff --git a/hw/remote/trace-events b/hw/remote/trace-events
93
index XXXXXXX..XXXXXXX 100644
94
--- a/hw/remote/trace-events
95
+++ b/hw/remote/trace-events
96
@@ -XXX,XX +XXX,XX @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d,
97
98
# vfio-user-obj.c
99
vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s"
100
+vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x"
101
+vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x"
154
--
102
--
155
2.21.0
103
2.36.1
156
157
diff view generated by jsdifflib
1
iotest 126 requires backing file support, which flat vmdks cannot offer.
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
Skip this test for such subformats.
2
3
3
Assign separate address space for each device in the remote processes.
4
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
5
Message-id: 20190815153638.4600-8-mreitz@redhat.com
5
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
6
Reviewed-by: John Snow <jsnow@redhat.com>
6
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Message-id: afe0b0a97582cdad42b5b25636a29c523265a10a.1655151679.git.jag.raman@oracle.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
8
---
11
---
9
tests/qemu-iotests/126 | 2 ++
12
MAINTAINERS | 2 +
10
1 file changed, 2 insertions(+)
13
include/hw/remote/iommu.h | 40 ++++++++++++
11
14
hw/remote/iommu.c | 131 ++++++++++++++++++++++++++++++++++++++
12
diff --git a/tests/qemu-iotests/126 b/tests/qemu-iotests/126
15
hw/remote/machine.c | 13 +++-
13
index XXXXXXX..XXXXXXX 100755
16
hw/remote/meson.build | 1 +
14
--- a/tests/qemu-iotests/126
17
5 files changed, 186 insertions(+), 1 deletion(-)
15
+++ b/tests/qemu-iotests/126
18
create mode 100644 include/hw/remote/iommu.h
16
@@ -XXX,XX +XXX,XX @@ status=1    # failure is the default!
19
create mode 100644 hw/remote/iommu.c
17
20
18
# Needs backing file support
21
diff --git a/MAINTAINERS b/MAINTAINERS
19
_supported_fmt qcow qcow2 qed vmdk
22
index XXXXXXX..XXXXXXX 100644
20
+_unsupported_imgopts "subformat=monolithicFlat" \
23
--- a/MAINTAINERS
21
+ "subformat=twoGbMaxExtentFlat"
24
+++ b/MAINTAINERS
22
# This is the default protocol (and we want to test the difference between
25
@@ -XXX,XX +XXX,XX @@ F: hw/remote/iohub.c
23
# colons which separate a protocol prefix from the rest and colons which are
26
F: include/hw/remote/iohub.h
24
# just part of the filename, so we cannot test protocols which require a prefix)
27
F: subprojects/libvfio-user
28
F: hw/remote/vfio-user-obj.c
29
+F: hw/remote/iommu.c
30
+F: include/hw/remote/iommu.h
31
32
EBPF:
33
M: Jason Wang <jasowang@redhat.com>
34
diff --git a/include/hw/remote/iommu.h b/include/hw/remote/iommu.h
35
new file mode 100644
36
index XXXXXXX..XXXXXXX
37
--- /dev/null
38
+++ b/include/hw/remote/iommu.h
39
@@ -XXX,XX +XXX,XX @@
40
+/**
41
+ * Copyright © 2022 Oracle and/or its affiliates.
42
+ *
43
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
44
+ * See the COPYING file in the top-level directory.
45
+ *
46
+ */
47
+
48
+#ifndef REMOTE_IOMMU_H
49
+#define REMOTE_IOMMU_H
50
+
51
+#include "hw/pci/pci_bus.h"
52
+#include "hw/pci/pci.h"
53
+
54
+#ifndef INT2VOIDP
55
+#define INT2VOIDP(i) (void *)(uintptr_t)(i)
56
+#endif
57
+
58
+typedef struct RemoteIommuElem {
59
+ MemoryRegion *mr;
60
+
61
+ AddressSpace as;
62
+} RemoteIommuElem;
63
+
64
+#define TYPE_REMOTE_IOMMU "x-remote-iommu"
65
+OBJECT_DECLARE_SIMPLE_TYPE(RemoteIommu, REMOTE_IOMMU)
66
+
67
+struct RemoteIommu {
68
+ Object parent;
69
+
70
+ GHashTable *elem_by_devfn;
71
+
72
+ QemuMutex lock;
73
+};
74
+
75
+void remote_iommu_setup(PCIBus *pci_bus);
76
+
77
+void remote_iommu_unplug_dev(PCIDevice *pci_dev);
78
+
79
+#endif
80
diff --git a/hw/remote/iommu.c b/hw/remote/iommu.c
81
new file mode 100644
82
index XXXXXXX..XXXXXXX
83
--- /dev/null
84
+++ b/hw/remote/iommu.c
85
@@ -XXX,XX +XXX,XX @@
86
+/**
87
+ * IOMMU for remote device
88
+ *
89
+ * Copyright © 2022 Oracle and/or its affiliates.
90
+ *
91
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
92
+ * See the COPYING file in the top-level directory.
93
+ *
94
+ */
95
+
96
+#include "qemu/osdep.h"
97
+
98
+#include "hw/remote/iommu.h"
99
+#include "hw/pci/pci_bus.h"
100
+#include "hw/pci/pci.h"
101
+#include "exec/memory.h"
102
+#include "exec/address-spaces.h"
103
+#include "trace.h"
104
+
105
+/**
106
+ * IOMMU for TYPE_REMOTE_MACHINE - manages DMA address space isolation
107
+ * for remote machine. It is used by TYPE_VFIO_USER_SERVER.
108
+ *
109
+ * - Each TYPE_VFIO_USER_SERVER instance handles one PCIDevice on a PCIBus.
110
+ * There is one RemoteIommu per PCIBus, so the RemoteIommu tracks multiple
111
+ * PCIDevices by maintaining a ->elem_by_devfn mapping.
112
+ *
113
+ * - memory_region_init_iommu() is not used because vfio-user MemoryRegions
114
+ * will be added to the elem->mr container instead. This is more natural
115
+ * than implementing the IOMMUMemoryRegionClass APIs since vfio-user
116
+ * provides something that is close to a full-fledged MemoryRegion and
117
+ * not like an IOMMU mapping.
118
+ *
119
+ * - When a device is hot unplugged, the elem->mr reference is dropped so
120
+ * all vfio-user MemoryRegions associated with this vfio-user server are
121
+ * destroyed.
122
+ */
123
+
124
+static AddressSpace *remote_iommu_find_add_as(PCIBus *pci_bus,
125
+ void *opaque, int devfn)
126
+{
127
+ RemoteIommu *iommu = opaque;
128
+ RemoteIommuElem *elem = NULL;
129
+
130
+ qemu_mutex_lock(&iommu->lock);
131
+
132
+ elem = g_hash_table_lookup(iommu->elem_by_devfn, INT2VOIDP(devfn));
133
+
134
+ if (!elem) {
135
+ elem = g_malloc0(sizeof(RemoteIommuElem));
136
+ g_hash_table_insert(iommu->elem_by_devfn, INT2VOIDP(devfn), elem);
137
+ }
138
+
139
+ if (!elem->mr) {
140
+ elem->mr = MEMORY_REGION(object_new(TYPE_MEMORY_REGION));
141
+ memory_region_set_size(elem->mr, UINT64_MAX);
142
+ address_space_init(&elem->as, elem->mr, NULL);
143
+ }
144
+
145
+ qemu_mutex_unlock(&iommu->lock);
146
+
147
+ return &elem->as;
148
+}
149
+
150
+void remote_iommu_unplug_dev(PCIDevice *pci_dev)
151
+{
152
+ AddressSpace *as = pci_device_iommu_address_space(pci_dev);
153
+ RemoteIommuElem *elem = NULL;
154
+
155
+ if (as == &address_space_memory) {
156
+ return;
157
+ }
158
+
159
+ elem = container_of(as, RemoteIommuElem, as);
160
+
161
+ address_space_destroy(&elem->as);
162
+
163
+ object_unref(elem->mr);
164
+
165
+ elem->mr = NULL;
166
+}
167
+
168
+static void remote_iommu_init(Object *obj)
169
+{
170
+ RemoteIommu *iommu = REMOTE_IOMMU(obj);
171
+
172
+ iommu->elem_by_devfn = g_hash_table_new_full(NULL, NULL, NULL, g_free);
173
+
174
+ qemu_mutex_init(&iommu->lock);
175
+}
176
+
177
+static void remote_iommu_finalize(Object *obj)
178
+{
179
+ RemoteIommu *iommu = REMOTE_IOMMU(obj);
180
+
181
+ qemu_mutex_destroy(&iommu->lock);
182
+
183
+ g_hash_table_destroy(iommu->elem_by_devfn);
184
+
185
+ iommu->elem_by_devfn = NULL;
186
+}
187
+
188
+void remote_iommu_setup(PCIBus *pci_bus)
189
+{
190
+ RemoteIommu *iommu = NULL;
191
+
192
+ g_assert(pci_bus);
193
+
194
+ iommu = REMOTE_IOMMU(object_new(TYPE_REMOTE_IOMMU));
195
+
196
+ pci_setup_iommu(pci_bus, remote_iommu_find_add_as, iommu);
197
+
198
+ object_property_add_child(OBJECT(pci_bus), "remote-iommu", OBJECT(iommu));
199
+
200
+ object_unref(OBJECT(iommu));
201
+}
202
+
203
+static const TypeInfo remote_iommu_info = {
204
+ .name = TYPE_REMOTE_IOMMU,
205
+ .parent = TYPE_OBJECT,
206
+ .instance_size = sizeof(RemoteIommu),
207
+ .instance_init = remote_iommu_init,
208
+ .instance_finalize = remote_iommu_finalize,
209
+};
210
+
211
+static void remote_iommu_register_types(void)
212
+{
213
+ type_register_static(&remote_iommu_info);
214
+}
215
+
216
+type_init(remote_iommu_register_types)
217
diff --git a/hw/remote/machine.c b/hw/remote/machine.c
218
index XXXXXXX..XXXXXXX 100644
219
--- a/hw/remote/machine.c
220
+++ b/hw/remote/machine.c
221
@@ -XXX,XX +XXX,XX @@
222
#include "qapi/error.h"
223
#include "hw/pci/pci_host.h"
224
#include "hw/remote/iohub.h"
225
+#include "hw/remote/iommu.h"
226
#include "hw/qdev-core.h"
227
228
static void remote_machine_init(MachineState *machine)
229
@@ -XXX,XX +XXX,XX @@ static void remote_machine_instance_init(Object *obj)
230
s->auto_shutdown = true;
231
}
232
233
+static void remote_machine_dev_unplug_cb(HotplugHandler *hotplug_dev,
234
+ DeviceState *dev, Error **errp)
235
+{
236
+ qdev_unrealize(dev);
237
+
238
+ if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
239
+ remote_iommu_unplug_dev(PCI_DEVICE(dev));
240
+ }
241
+}
242
+
243
static void remote_machine_class_init(ObjectClass *oc, void *data)
244
{
245
MachineClass *mc = MACHINE_CLASS(oc);
246
@@ -XXX,XX +XXX,XX @@ static void remote_machine_class_init(ObjectClass *oc, void *data)
247
mc->init = remote_machine_init;
248
mc->desc = "Experimental remote machine";
249
250
- hc->unplug = qdev_simple_device_unplug_cb;
251
+ hc->unplug = remote_machine_dev_unplug_cb;
252
253
object_class_property_add_bool(oc, "vfio-user",
254
remote_machine_get_vfio_user,
255
diff --git a/hw/remote/meson.build b/hw/remote/meson.build
256
index XXXXXXX..XXXXXXX 100644
257
--- a/hw/remote/meson.build
258
+++ b/hw/remote/meson.build
259
@@ -XXX,XX +XXX,XX @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c'))
260
remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c'))
261
remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c'))
262
remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c'))
263
+remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iommu.c'))
264
remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: files('vfio-user-obj.c'))
265
266
remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: libvfio_user_dep)
25
--
267
--
26
2.21.0
268
2.36.1
27
269
28
270
diff view generated by jsdifflib
1
The error message for the test case where we have a quorum node for
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
which no directory name can be generated is different: For
3
twoGbMaxExtentSparse, it complains that it cannot open the extent file.
4
For other (sub)formats, it just notes that it cannot determine the
5
backing file path. Both are fine, but just disable twoGbMaxExtentSparse
6
for simplicity's sake.
7
2
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
3
Define and register callbacks to manage the RAM regions used for
9
Reviewed-by: John Snow <jsnow@redhat.com>
4
device DMA
10
Message-id: 20190815153638.4600-7-mreitz@redhat.com
5
11
Reviewed-by: John Snow <jsnow@redhat.com>
6
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
8
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
10
Message-id: faacbcd45c4d02c591f0dbfdc19041fbb3eae7eb.1655151679.git.jag.raman@oracle.com
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
---
12
---
14
tests/qemu-iotests/110 | 3 ++-
13
hw/remote/machine.c | 5 ++++
15
1 file changed, 2 insertions(+), 1 deletion(-)
14
hw/remote/vfio-user-obj.c | 55 +++++++++++++++++++++++++++++++++++++++
15
hw/remote/trace-events | 2 ++
16
3 files changed, 62 insertions(+)
16
17
17
diff --git a/tests/qemu-iotests/110 b/tests/qemu-iotests/110
18
diff --git a/hw/remote/machine.c b/hw/remote/machine.c
18
index XXXXXXX..XXXXXXX 100755
19
index XXXXXXX..XXXXXXX 100644
19
--- a/tests/qemu-iotests/110
20
--- a/hw/remote/machine.c
20
+++ b/tests/qemu-iotests/110
21
+++ b/hw/remote/machine.c
21
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
22
@@ -XXX,XX +XXX,XX @@
22
# Any format supporting backing files
23
#include "hw/remote/iohub.h"
23
_supported_fmt qed qcow qcow2 vmdk
24
#include "hw/remote/iommu.h"
24
_supported_proto file
25
#include "hw/qdev-core.h"
25
-_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
26
+#include "hw/remote/iommu.h"
26
+_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
27
27
+ "subformat=twoGbMaxExtentSparse"
28
static void remote_machine_init(MachineState *machine)
28
29
{
29
TEST_IMG_REL=$(basename "$TEST_IMG")
30
@@ -XXX,XX +XXX,XX @@ static void remote_machine_init(MachineState *machine)
30
31
32
pci_host = PCI_HOST_BRIDGE(rem_host);
33
34
+ if (s->vfio_user) {
35
+ remote_iommu_setup(pci_host->bus);
36
+ }
37
+
38
remote_iohub_init(&s->iohub);
39
40
pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq,
41
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/hw/remote/vfio-user-obj.c
44
+++ b/hw/remote/vfio-user-obj.c
45
@@ -XXX,XX +XXX,XX @@ static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf,
46
return count;
47
}
48
49
+static void dma_register(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info)
50
+{
51
+ VfuObject *o = vfu_get_private(vfu_ctx);
52
+ AddressSpace *dma_as = NULL;
53
+ MemoryRegion *subregion = NULL;
54
+ g_autofree char *name = NULL;
55
+ struct iovec *iov = &info->iova;
56
+
57
+ if (!info->vaddr) {
58
+ return;
59
+ }
60
+
61
+ name = g_strdup_printf("mem-%s-%"PRIx64"", o->device,
62
+ (uint64_t)info->vaddr);
63
+
64
+ subregion = g_new0(MemoryRegion, 1);
65
+
66
+ memory_region_init_ram_ptr(subregion, NULL, name,
67
+ iov->iov_len, info->vaddr);
68
+
69
+ dma_as = pci_device_iommu_address_space(o->pci_dev);
70
+
71
+ memory_region_add_subregion(dma_as->root, (hwaddr)iov->iov_base, subregion);
72
+
73
+ trace_vfu_dma_register((uint64_t)iov->iov_base, iov->iov_len);
74
+}
75
+
76
+static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info)
77
+{
78
+ VfuObject *o = vfu_get_private(vfu_ctx);
79
+ AddressSpace *dma_as = NULL;
80
+ MemoryRegion *mr = NULL;
81
+ ram_addr_t offset;
82
+
83
+ mr = memory_region_from_host(info->vaddr, &offset);
84
+ if (!mr) {
85
+ return;
86
+ }
87
+
88
+ dma_as = pci_device_iommu_address_space(o->pci_dev);
89
+
90
+ memory_region_del_subregion(dma_as->root, mr);
91
+
92
+ object_unparent((OBJECT(mr)));
93
+
94
+ trace_vfu_dma_unregister((uint64_t)info->iova.iov_base);
95
+}
96
+
97
/*
98
* TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
99
* properties. It also depends on devices instantiated in QEMU. These
100
@@ -XXX,XX +XXX,XX @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
101
goto fail;
102
}
103
104
+ ret = vfu_setup_device_dma(o->vfu_ctx, &dma_register, &dma_unregister);
105
+ if (ret < 0) {
106
+ error_setg(errp, "vfu: Failed to setup DMA handlers for %s",
107
+ o->device);
108
+ goto fail;
109
+ }
110
+
111
ret = vfu_realize_ctx(o->vfu_ctx);
112
if (ret < 0) {
113
error_setg(errp, "vfu: Failed to realize device %s- %s",
114
diff --git a/hw/remote/trace-events b/hw/remote/trace-events
115
index XXXXXXX..XXXXXXX 100644
116
--- a/hw/remote/trace-events
117
+++ b/hw/remote/trace-events
118
@@ -XXX,XX +XXX,XX @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d,
119
vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s"
120
vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x"
121
vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x"
122
+vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %zu bytes"
123
+vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64""
31
--
124
--
32
2.21.0
125
2.36.1
33
34
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
2
3
It's wrong to OR shared permissions. It may lead to crash on further
3
Determine the BARs used by the PCI device and register handlers to
4
permission updates.
4
manage the access to the same.
5
Also, no needs to consider previously calculated permissions, as at
6
this point we already bind all new parents and bdrv_get_cumulative_perm
7
result is enough. So fix the bug by just set permissions by
8
bdrv_get_cumulative_perm result.
9
5
10
Bug was introduced in long ago 234ac1a9025, in 2.9.
6
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
7
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
8
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
10
Message-id: 3373e10b5be5f42846f0632d4382466e1698c505.1655151679.git.jag.raman@oracle.com
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
---
13
include/exec/memory.h | 3 +
14
hw/remote/vfio-user-obj.c | 190 ++++++++++++++++++++++++++++++++
15
softmmu/physmem.c | 4 +-
16
tests/qtest/fuzz/generic_fuzz.c | 9 +-
17
hw/remote/trace-events | 3 +
18
5 files changed, 203 insertions(+), 6 deletions(-)
11
19
12
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
20
diff --git a/include/exec/memory.h b/include/exec/memory.h
13
Message-id: 20190824100740.61635-1-vsementsov@virtuozzo.com
21
index XXXXXXX..XXXXXXX 100644
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
22
--- a/include/exec/memory.h
15
---
23
+++ b/include/exec/memory.h
16
block.c | 5 ++---
24
@@ -XXX,XX +XXX,XX @@ MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache,
17
1 file changed, 2 insertions(+), 3 deletions(-)
25
hwaddr addr, const void *buf,
18
26
hwaddr len);
19
diff --git a/block.c b/block.c
27
20
index XXXXXXX..XXXXXXX 100644
28
+int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr);
21
--- a/block.c
29
+bool prepare_mmio_access(MemoryRegion *mr);
22
+++ b/block.c
30
+
23
@@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
31
static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
24
{
32
{
25
BdrvChild *c, *next;
33
if (is_write) {
26
GSList *list = NULL, *p;
34
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
27
- uint64_t old_perm, old_shared;
35
index XXXXXXX..XXXXXXX 100644
28
uint64_t perm = 0, shared = BLK_PERM_ALL;
36
--- a/hw/remote/vfio-user-obj.c
29
int ret;
37
+++ b/hw/remote/vfio-user-obj.c
30
38
@@ -XXX,XX +XXX,XX @@
31
@@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
39
#include "hw/qdev-core.h"
32
bdrv_unref(from);
40
#include "hw/pci/pci.h"
41
#include "qemu/timer.h"
42
+#include "exec/memory.h"
43
44
#define TYPE_VFU_OBJECT "x-vfio-user-server"
45
OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
46
@@ -XXX,XX +XXX,XX @@ static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info)
47
trace_vfu_dma_unregister((uint64_t)info->iova.iov_base);
48
}
49
50
+static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *buf, hwaddr offset,
51
+ hwaddr size, const bool is_write)
52
+{
53
+ uint8_t *ptr = buf;
54
+ bool release_lock = false;
55
+ uint8_t *ram_ptr = NULL;
56
+ MemTxResult result;
57
+ int access_size;
58
+ uint64_t val;
59
+
60
+ if (memory_access_is_direct(mr, is_write)) {
61
+ /**
62
+ * Some devices expose a PCI expansion ROM, which could be buffer
63
+ * based as compared to other regions which are primarily based on
64
+ * MemoryRegionOps. memory_region_find() would already check
65
+ * for buffer overflow, we don't need to repeat it here.
66
+ */
67
+ ram_ptr = memory_region_get_ram_ptr(mr);
68
+
69
+ if (is_write) {
70
+ memcpy((ram_ptr + offset), buf, size);
71
+ } else {
72
+ memcpy(buf, (ram_ptr + offset), size);
73
+ }
74
+
75
+ return 0;
76
+ }
77
+
78
+ while (size) {
79
+ /**
80
+ * The read/write logic used below is similar to the ones in
81
+ * flatview_read/write_continue()
82
+ */
83
+ release_lock = prepare_mmio_access(mr);
84
+
85
+ access_size = memory_access_size(mr, size, offset);
86
+
87
+ if (is_write) {
88
+ val = ldn_he_p(ptr, access_size);
89
+
90
+ result = memory_region_dispatch_write(mr, offset, val,
91
+ size_memop(access_size),
92
+ MEMTXATTRS_UNSPECIFIED);
93
+ } else {
94
+ result = memory_region_dispatch_read(mr, offset, &val,
95
+ size_memop(access_size),
96
+ MEMTXATTRS_UNSPECIFIED);
97
+
98
+ stn_he_p(ptr, access_size, val);
99
+ }
100
+
101
+ if (release_lock) {
102
+ qemu_mutex_unlock_iothread();
103
+ release_lock = false;
104
+ }
105
+
106
+ if (result != MEMTX_OK) {
107
+ return -1;
108
+ }
109
+
110
+ size -= access_size;
111
+ ptr += access_size;
112
+ offset += access_size;
113
+ }
114
+
115
+ return 0;
116
+}
117
+
118
+static size_t vfu_object_bar_rw(PCIDevice *pci_dev, int pci_bar,
119
+ hwaddr bar_offset, char * const buf,
120
+ hwaddr len, const bool is_write)
121
+{
122
+ MemoryRegionSection section = { 0 };
123
+ uint8_t *ptr = (uint8_t *)buf;
124
+ MemoryRegion *section_mr = NULL;
125
+ uint64_t section_size;
126
+ hwaddr section_offset;
127
+ hwaddr size = 0;
128
+
129
+ while (len) {
130
+ section = memory_region_find(pci_dev->io_regions[pci_bar].memory,
131
+ bar_offset, len);
132
+
133
+ if (!section.mr) {
134
+ warn_report("vfu: invalid address 0x%"PRIx64"", bar_offset);
135
+ return size;
136
+ }
137
+
138
+ section_mr = section.mr;
139
+ section_offset = section.offset_within_region;
140
+ section_size = int128_get64(section.size);
141
+
142
+ if (is_write && section_mr->readonly) {
143
+ warn_report("vfu: attempting to write to readonly region in "
144
+ "bar %d - [0x%"PRIx64" - 0x%"PRIx64"]",
145
+ pci_bar, bar_offset,
146
+ (bar_offset + section_size));
147
+ memory_region_unref(section_mr);
148
+ return size;
149
+ }
150
+
151
+ if (vfu_object_mr_rw(section_mr, ptr, section_offset,
152
+ section_size, is_write)) {
153
+ warn_report("vfu: failed to %s "
154
+ "[0x%"PRIx64" - 0x%"PRIx64"] in bar %d",
155
+ is_write ? "write to" : "read from", bar_offset,
156
+ (bar_offset + section_size), pci_bar);
157
+ memory_region_unref(section_mr);
158
+ return size;
159
+ }
160
+
161
+ size += section_size;
162
+ bar_offset += section_size;
163
+ ptr += section_size;
164
+ len -= section_size;
165
+
166
+ memory_region_unref(section_mr);
167
+ }
168
+
169
+ return size;
170
+}
171
+
172
+/**
173
+ * VFU_OBJECT_BAR_HANDLER - macro for defining handlers for PCI BARs.
174
+ *
175
+ * To create handler for BAR number 2, VFU_OBJECT_BAR_HANDLER(2) would
176
+ * define vfu_object_bar2_handler
177
+ */
178
+#define VFU_OBJECT_BAR_HANDLER(BAR_NO) \
179
+ static ssize_t vfu_object_bar##BAR_NO##_handler(vfu_ctx_t *vfu_ctx, \
180
+ char * const buf, size_t count, \
181
+ loff_t offset, const bool is_write) \
182
+ { \
183
+ VfuObject *o = vfu_get_private(vfu_ctx); \
184
+ PCIDevice *pci_dev = o->pci_dev; \
185
+ \
186
+ return vfu_object_bar_rw(pci_dev, BAR_NO, offset, \
187
+ buf, count, is_write); \
188
+ } \
189
+
190
+VFU_OBJECT_BAR_HANDLER(0)
191
+VFU_OBJECT_BAR_HANDLER(1)
192
+VFU_OBJECT_BAR_HANDLER(2)
193
+VFU_OBJECT_BAR_HANDLER(3)
194
+VFU_OBJECT_BAR_HANDLER(4)
195
+VFU_OBJECT_BAR_HANDLER(5)
196
+VFU_OBJECT_BAR_HANDLER(6)
197
+
198
+static vfu_region_access_cb_t *vfu_object_bar_handlers[PCI_NUM_REGIONS] = {
199
+ &vfu_object_bar0_handler,
200
+ &vfu_object_bar1_handler,
201
+ &vfu_object_bar2_handler,
202
+ &vfu_object_bar3_handler,
203
+ &vfu_object_bar4_handler,
204
+ &vfu_object_bar5_handler,
205
+ &vfu_object_bar6_handler,
206
+};
207
+
208
+/**
209
+ * vfu_object_register_bars - Identify active BAR regions of pdev and setup
210
+ * callbacks to handle read/write accesses
211
+ */
212
+static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev)
213
+{
214
+ int flags = VFU_REGION_FLAG_RW;
215
+ int i;
216
+
217
+ for (i = 0; i < PCI_NUM_REGIONS; i++) {
218
+ if (!pdev->io_regions[i].size) {
219
+ continue;
220
+ }
221
+
222
+ if ((i == VFU_PCI_DEV_ROM_REGION_IDX) ||
223
+ pdev->io_regions[i].memory->readonly) {
224
+ flags &= ~VFU_REGION_FLAG_WRITE;
225
+ }
226
+
227
+ vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR0_REGION_IDX + i,
228
+ (size_t)pdev->io_regions[i].size,
229
+ vfu_object_bar_handlers[i],
230
+ flags, NULL, 0, -1, 0);
231
+
232
+ trace_vfu_bar_register(i, pdev->io_regions[i].addr,
233
+ pdev->io_regions[i].size);
234
+ }
235
+}
236
+
237
/*
238
* TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
239
* properties. It also depends on devices instantiated in QEMU. These
240
@@ -XXX,XX +XXX,XX @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
241
goto fail;
33
}
242
}
34
243
35
- bdrv_get_cumulative_perm(to, &old_perm, &old_shared);
244
+ vfu_object_register_bars(o->vfu_ctx, o->pci_dev);
36
- bdrv_set_perm(to, old_perm | perm, old_shared | shared);
245
+
37
+ bdrv_get_cumulative_perm(to, &perm, &shared);
246
ret = vfu_realize_ctx(o->vfu_ctx);
38
+ bdrv_set_perm(to, perm, shared);
247
if (ret < 0) {
39
248
error_setg(errp, "vfu: Failed to realize device %s- %s",
40
out:
249
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
41
g_slist_free(list);
250
index XXXXXXX..XXXXXXX 100644
251
--- a/softmmu/physmem.c
252
+++ b/softmmu/physmem.c
253
@@ -XXX,XX +XXX,XX @@ void memory_region_flush_rom_device(MemoryRegion *mr, hwaddr addr, hwaddr size)
254
invalidate_and_set_dirty(mr, addr, size);
255
}
256
257
-static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
258
+int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
259
{
260
unsigned access_size_max = mr->ops->valid.max_access_size;
261
262
@@ -XXX,XX +XXX,XX @@ static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
263
return l;
264
}
265
266
-static bool prepare_mmio_access(MemoryRegion *mr)
267
+bool prepare_mmio_access(MemoryRegion *mr)
268
{
269
bool release_lock = false;
270
271
diff --git a/tests/qtest/fuzz/generic_fuzz.c b/tests/qtest/fuzz/generic_fuzz.c
272
index XXXXXXX..XXXXXXX 100644
273
--- a/tests/qtest/fuzz/generic_fuzz.c
274
+++ b/tests/qtest/fuzz/generic_fuzz.c
275
@@ -XXX,XX +XXX,XX @@ static void *pattern_alloc(pattern p, size_t len)
276
return buf;
277
}
278
279
-static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
280
+static int fuzz_memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
281
{
282
unsigned access_size_max = mr->ops->valid.max_access_size;
283
284
@@ -XXX,XX +XXX,XX @@ void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr)
285
286
/*
287
* If mr1 isn't RAM, address_space_translate doesn't update l. Use
288
- * memory_access_size to identify the number of bytes that it is safe
289
- * to write without accidentally writing to another MemoryRegion.
290
+ * fuzz_memory_access_size to identify the number of bytes that it
291
+ * is safe to write without accidentally writing to another
292
+ * MemoryRegion.
293
*/
294
if (!memory_region_is_ram(mr1)) {
295
- l = memory_access_size(mr1, l, addr1);
296
+ l = fuzz_memory_access_size(mr1, l, addr1);
297
}
298
if (memory_region_is_ram(mr1) ||
299
memory_region_is_romd(mr1) ||
300
diff --git a/hw/remote/trace-events b/hw/remote/trace-events
301
index XXXXXXX..XXXXXXX 100644
302
--- a/hw/remote/trace-events
303
+++ b/hw/remote/trace-events
304
@@ -XXX,XX +XXX,XX @@ vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x"
305
vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x"
306
vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %zu bytes"
307
vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64""
308
+vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64""
309
+vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64""
310
+vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64""
42
--
311
--
43
2.21.0
312
2.36.1
44
45
diff view generated by jsdifflib
1
streamOptimized does not support writes that do not span exactly one
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
cluster. Furthermore, it cannot rewrite already allocated clusters.
3
As such, many iotests do not work with it. Disable them.
4
2
5
Signed-off-by: Max Reitz <mreitz@redhat.com>
3
Forward remote device's interrupts to the guest
6
Message-id: 20190815153638.4600-6-mreitz@redhat.com
4
7
Reviewed-by: John Snow <jsnow@redhat.com>
5
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
6
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
7
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
8
Message-id: 9523479eaafe050677f4de2af5dd0df18c27cfd9.1655151679.git.jag.raman@oracle.com
9
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
10
---
10
tests/qemu-iotests/002 | 1 +
11
MAINTAINERS | 1 +
11
tests/qemu-iotests/003 | 1 +
12
include/hw/pci/msi.h | 1 +
12
tests/qemu-iotests/005 | 3 ++-
13
include/hw/pci/msix.h | 1 +
13
tests/qemu-iotests/009 | 1 +
14
include/hw/pci/pci.h | 13 +++
14
tests/qemu-iotests/010 | 1 +
15
include/hw/remote/vfio-user-obj.h | 6 ++
15
tests/qemu-iotests/011 | 1 +
16
hw/pci/msi.c | 49 +++++++--
16
tests/qemu-iotests/017 | 3 ++-
17
hw/pci/msix.c | 35 ++++++-
17
tests/qemu-iotests/018 | 3 ++-
18
hw/pci/pci.c | 13 +++
18
tests/qemu-iotests/019 | 3 ++-
19
hw/remote/machine.c | 16 ++-
19
tests/qemu-iotests/020 | 3 ++-
20
hw/remote/vfio-user-obj.c | 167 ++++++++++++++++++++++++++++++
20
tests/qemu-iotests/027 | 1 +
21
stubs/vfio-user-obj.c | 6 ++
21
tests/qemu-iotests/032 | 1 +
22
hw/remote/trace-events | 1 +
22
tests/qemu-iotests/033 | 1 +
23
stubs/meson.build | 1 +
23
tests/qemu-iotests/034 | 3 ++-
24
13 files changed, 298 insertions(+), 12 deletions(-)
24
tests/qemu-iotests/037 | 3 ++-
25
create mode 100644 include/hw/remote/vfio-user-obj.h
25
tests/qemu-iotests/063 | 3 ++-
26
create mode 100644 stubs/vfio-user-obj.c
26
tests/qemu-iotests/072 | 1 +
27
tests/qemu-iotests/105 | 3 ++-
28
tests/qemu-iotests/197 | 1 +
29
tests/qemu-iotests/215 | 1 +
30
tests/qemu-iotests/251 | 1 +
31
21 files changed, 30 insertions(+), 9 deletions(-)
32
27
33
diff --git a/tests/qemu-iotests/002 b/tests/qemu-iotests/002
28
diff --git a/MAINTAINERS b/MAINTAINERS
34
index XXXXXXX..XXXXXXX 100755
29
index XXXXXXX..XXXXXXX 100644
35
--- a/tests/qemu-iotests/002
30
--- a/MAINTAINERS
36
+++ b/tests/qemu-iotests/002
31
+++ b/MAINTAINERS
37
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
32
@@ -XXX,XX +XXX,XX @@ F: hw/remote/iohub.c
38
33
F: include/hw/remote/iohub.h
39
_supported_fmt generic
34
F: subprojects/libvfio-user
40
_supported_proto generic
35
F: hw/remote/vfio-user-obj.c
41
+_unsupported_imgopts "subformat=streamOptimized"
36
+F: include/hw/remote/vfio-user-obj.h
42
37
F: hw/remote/iommu.c
43
38
F: include/hw/remote/iommu.h
44
size=128M
39
45
diff --git a/tests/qemu-iotests/003 b/tests/qemu-iotests/003
40
diff --git a/include/hw/pci/msi.h b/include/hw/pci/msi.h
46
index XXXXXXX..XXXXXXX 100755
41
index XXXXXXX..XXXXXXX 100644
47
--- a/tests/qemu-iotests/003
42
--- a/include/hw/pci/msi.h
48
+++ b/tests/qemu-iotests/003
43
+++ b/include/hw/pci/msi.h
49
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
44
@@ -XXX,XX +XXX,XX @@ void msi_notify(PCIDevice *dev, unsigned int vector);
50
45
void msi_send_message(PCIDevice *dev, MSIMessage msg);
51
_supported_fmt generic
46
void msi_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len);
52
_supported_proto generic
47
unsigned int msi_nr_vectors_allocated(const PCIDevice *dev);
53
+_unsupported_imgopts "subformat=streamOptimized"
48
+void msi_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp);
54
49
55
size=128M
50
static inline bool msi_present(const PCIDevice *dev)
56
offset=67M
51
{
57
diff --git a/tests/qemu-iotests/005 b/tests/qemu-iotests/005
52
diff --git a/include/hw/pci/msix.h b/include/hw/pci/msix.h
58
index XXXXXXX..XXXXXXX 100755
53
index XXXXXXX..XXXXXXX 100644
59
--- a/tests/qemu-iotests/005
54
--- a/include/hw/pci/msix.h
60
+++ b/tests/qemu-iotests/005
55
+++ b/include/hw/pci/msix.h
61
@@ -XXX,XX +XXX,XX @@ _supported_fmt generic
56
@@ -XXX,XX +XXX,XX @@ void msix_clr_pending(PCIDevice *dev, int vector);
62
_supported_proto generic
57
int msix_vector_use(PCIDevice *dev, unsigned vector);
63
_supported_os Linux
58
void msix_vector_unuse(PCIDevice *dev, unsigned vector);
64
_unsupported_imgopts "subformat=twoGbMaxExtentFlat" \
59
void msix_unuse_all_vectors(PCIDevice *dev);
65
- "subformat=twoGbMaxExtentSparse"
60
+void msix_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp);
66
+ "subformat=twoGbMaxExtentSparse" \
61
67
+ "subformat=streamOptimized"
62
void msix_notify(PCIDevice *dev, unsigned vector);
68
63
69
# vpc is limited to 127GB, so we can't test it here
64
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
70
if [ "$IMGFMT" = "vpc" ]; then
65
index XXXXXXX..XXXXXXX 100644
71
diff --git a/tests/qemu-iotests/009 b/tests/qemu-iotests/009
66
--- a/include/hw/pci/pci.h
72
index XXXXXXX..XXXXXXX 100755
67
+++ b/include/hw/pci/pci.h
73
--- a/tests/qemu-iotests/009
68
@@ -XXX,XX +XXX,XX @@ extern bool pci_available;
74
+++ b/tests/qemu-iotests/009
69
#define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f)
75
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
70
#define PCI_FUNC(devfn) ((devfn) & 0x07)
76
71
#define PCI_BUILD_BDF(bus, devfn) ((bus << 8) | (devfn))
77
_supported_fmt generic
72
+#define PCI_BDF_TO_DEVFN(x) ((x) & 0xff)
78
_supported_proto generic
73
#define PCI_BUS_MAX 256
79
+_unsupported_imgopts "subformat=streamOptimized"
74
#define PCI_DEVFN_MAX 256
80
75
#define PCI_SLOT_MAX 32
81
76
@@ -XXX,XX +XXX,XX @@ typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num,
82
size=6G
77
pcibus_t addr, pcibus_t size, int type);
83
diff --git a/tests/qemu-iotests/010 b/tests/qemu-iotests/010
78
typedef void PCIUnregisterFunc(PCIDevice *pci_dev);
84
index XXXXXXX..XXXXXXX 100755
79
85
--- a/tests/qemu-iotests/010
80
+typedef void MSITriggerFunc(PCIDevice *dev, MSIMessage msg);
86
+++ b/tests/qemu-iotests/010
81
+typedef MSIMessage MSIPrepareMessageFunc(PCIDevice *dev, unsigned vector);
87
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
82
+typedef MSIMessage MSIxPrepareMessageFunc(PCIDevice *dev, unsigned vector);
88
83
+
89
_supported_fmt generic
84
typedef struct PCIIORegion {
90
_supported_proto generic
85
pcibus_t addr; /* current PCI mapping address. -1 means not mapped */
91
+_unsupported_imgopts "subformat=streamOptimized"
86
#define PCI_BAR_UNMAPPED (~(pcibus_t)0)
92
87
@@ -XXX,XX +XXX,XX @@ struct PCIDevice {
93
88
/* Space to store MSIX table & pending bit array */
94
size=6G
89
uint8_t *msix_table;
95
diff --git a/tests/qemu-iotests/011 b/tests/qemu-iotests/011
90
uint8_t *msix_pba;
96
index XXXXXXX..XXXXXXX 100755
91
+
97
--- a/tests/qemu-iotests/011
92
+ /* May be used by INTx or MSI during interrupt notification */
98
+++ b/tests/qemu-iotests/011
93
+ void *irq_opaque;
99
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
94
+
100
95
+ MSITriggerFunc *msi_trigger;
101
_supported_fmt generic
96
+ MSIPrepareMessageFunc *msi_prepare_message;
102
_supported_proto generic
97
+ MSIxPrepareMessageFunc *msix_prepare_message;
103
+_unsupported_imgopts "subformat=streamOptimized"
98
+
104
99
/* MemoryRegion container for msix exclusive BAR setup */
105
100
MemoryRegion msix_exclusive_bar;
106
size=6G
101
/* Memory Regions for MSIX table and pending bit entries. */
107
diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017
102
diff --git a/include/hw/remote/vfio-user-obj.h b/include/hw/remote/vfio-user-obj.h
108
index XXXXXXX..XXXXXXX 100755
103
new file mode 100644
109
--- a/tests/qemu-iotests/017
104
index XXXXXXX..XXXXXXX
110
+++ b/tests/qemu-iotests/017
105
--- /dev/null
111
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
106
+++ b/include/hw/remote/vfio-user-obj.h
112
_supported_fmt qcow qcow2 vmdk qed
107
@@ -XXX,XX +XXX,XX @@
113
_supported_proto generic
108
+#ifndef VFIO_USER_OBJ_H
114
_unsupported_proto vxhs
109
+#define VFIO_USER_OBJ_H
115
-_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
110
+
116
+_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
111
+void vfu_object_set_bus_irq(PCIBus *pci_bus);
117
+ "subformat=streamOptimized"
112
+
118
113
+#endif
119
TEST_OFFSETS="0 4294967296"
114
diff --git a/hw/pci/msi.c b/hw/pci/msi.c
120
115
index XXXXXXX..XXXXXXX 100644
121
diff --git a/tests/qemu-iotests/018 b/tests/qemu-iotests/018
116
--- a/hw/pci/msi.c
122
index XXXXXXX..XXXXXXX 100755
117
+++ b/hw/pci/msi.c
123
--- a/tests/qemu-iotests/018
118
@@ -XXX,XX +XXX,XX @@ void msi_set_message(PCIDevice *dev, MSIMessage msg)
124
+++ b/tests/qemu-iotests/018
119
pci_set_word(dev->config + msi_data_off(dev, msi64bit), msg.data);
125
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
120
}
126
_supported_fmt qcow qcow2 vmdk qed
121
127
_supported_proto file
122
-MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector)
128
_supported_os Linux
123
+static MSIMessage msi_prepare_message(PCIDevice *dev, unsigned int vector)
129
-_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
124
{
130
+_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
125
uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev));
131
+ "streamOptimized"
126
bool msi64bit = flags & PCI_MSI_FLAGS_64BIT;
132
127
@@ -XXX,XX +XXX,XX @@ MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector)
133
TEST_OFFSETS="0 4294967296"
128
return msg;
134
129
}
135
diff --git a/tests/qemu-iotests/019 b/tests/qemu-iotests/019
130
136
index XXXXXXX..XXXXXXX 100755
131
+MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector)
137
--- a/tests/qemu-iotests/019
132
+{
138
+++ b/tests/qemu-iotests/019
133
+ return dev->msi_prepare_message(dev, vector);
139
@@ -XXX,XX +XXX,XX @@ _supported_proto file
134
+}
140
_supported_os Linux
135
+
141
_unsupported_imgopts "subformat=monolithicFlat" \
136
bool msi_enabled(const PCIDevice *dev)
142
"subformat=twoGbMaxExtentFlat" \
137
{
143
- "subformat=twoGbMaxExtentSparse"
138
return msi_present(dev) &&
144
+ "subformat=twoGbMaxExtentSparse" \
139
@@ -XXX,XX +XXX,XX @@ int msi_init(struct PCIDevice *dev, uint8_t offset,
145
+ "subformat=streamOptimized"
140
0xffffffff >> (PCI_MSI_VECTORS_MAX - nr_vectors));
146
141
}
147
TEST_OFFSETS="0 4294967296"
142
148
CLUSTER_SIZE=65536
143
+ dev->msi_prepare_message = msi_prepare_message;
149
diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020
144
+
150
index XXXXXXX..XXXXXXX 100755
145
return 0;
151
--- a/tests/qemu-iotests/020
146
}
152
+++ b/tests/qemu-iotests/020
147
153
@@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed
148
@@ -XXX,XX +XXX,XX @@ void msi_uninit(struct PCIDevice *dev)
154
_supported_proto file
149
cap_size = msi_cap_sizeof(flags);
155
_unsupported_imgopts "subformat=monolithicFlat" \
150
pci_del_capability(dev, PCI_CAP_ID_MSI, cap_size);
156
"subformat=twoGbMaxExtentFlat" \
151
dev->cap_present &= ~QEMU_PCI_CAP_MSI;
157
- "subformat=twoGbMaxExtentSparse"
152
+ dev->msi_prepare_message = NULL;
158
+ "subformat=twoGbMaxExtentSparse" \
153
159
+ "subformat=streamOptimized"
154
MSI_DEV_PRINTF(dev, "uninit\n");
160
155
}
161
TEST_OFFSETS="0 4294967296"
156
@@ -XXX,XX +XXX,XX @@ bool msi_is_masked(const PCIDevice *dev, unsigned int vector)
162
157
return mask & (1U << vector);
163
diff --git a/tests/qemu-iotests/027 b/tests/qemu-iotests/027
158
}
164
index XXXXXXX..XXXXXXX 100755
159
165
--- a/tests/qemu-iotests/027
160
+void msi_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp)
166
+++ b/tests/qemu-iotests/027
161
+{
167
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
162
+ ERRP_GUARD();
168
163
+ uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev));
169
_supported_fmt vmdk qcow qcow2 qed
164
+ bool msi64bit = flags & PCI_MSI_FLAGS_64BIT;
170
_supported_proto generic
165
+ uint32_t irq_state, vector_mask, pending;
171
+_unsupported_imgopts "subformat=streamOptimized"
166
+
172
167
+ if (vector > PCI_MSI_VECTORS_MAX) {
173
168
+ error_setg(errp, "msi: vector %d not allocated. max vector is %d",
174
size=128M
169
+ vector, PCI_MSI_VECTORS_MAX);
175
diff --git a/tests/qemu-iotests/032 b/tests/qemu-iotests/032
170
+ return;
176
index XXXXXXX..XXXXXXX 100755
171
+ }
177
--- a/tests/qemu-iotests/032
172
+
178
+++ b/tests/qemu-iotests/032
173
+ vector_mask = (1U << vector);
179
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
174
+
180
# This works for any image format (though unlikely to segfault for raw)
175
+ irq_state = pci_get_long(dev->config + msi_mask_off(dev, msi64bit));
181
_supported_fmt generic
176
+
182
_supported_proto generic
177
+ if (mask) {
183
+_unsupported_imgopts "subformat=streamOptimized"
178
+ irq_state |= vector_mask;
184
179
+ } else {
185
echo
180
+ irq_state &= ~vector_mask;
186
echo === Prepare image ===
181
+ }
187
diff --git a/tests/qemu-iotests/033 b/tests/qemu-iotests/033
182
+
188
index XXXXXXX..XXXXXXX 100755
183
+ pci_set_long(dev->config + msi_mask_off(dev, msi64bit), irq_state);
189
--- a/tests/qemu-iotests/033
184
+
190
+++ b/tests/qemu-iotests/033
185
+ pending = pci_get_long(dev->config + msi_pending_off(dev, msi64bit));
191
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
186
+ if (!mask && (pending & vector_mask)) {
192
187
+ pending &= ~vector_mask;
193
_supported_fmt generic
188
+ pci_set_long(dev->config + msi_pending_off(dev, msi64bit), pending);
194
_supported_proto generic
189
+ msi_notify(dev, vector);
195
+_unsupported_imgopts "subformat=streamOptimized"
190
+ }
196
191
+}
197
192
+
198
size=128M
193
void msi_notify(PCIDevice *dev, unsigned int vector)
199
diff --git a/tests/qemu-iotests/034 b/tests/qemu-iotests/034
194
{
200
index XXXXXXX..XXXXXXX 100755
195
uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev));
201
--- a/tests/qemu-iotests/034
196
@@ -XXX,XX +XXX,XX @@ void msi_notify(PCIDevice *dev, unsigned int vector)
202
+++ b/tests/qemu-iotests/034
197
203
@@ -XXX,XX +XXX,XX @@ _supported_proto file
198
void msi_send_message(PCIDevice *dev, MSIMessage msg)
204
_supported_os Linux
199
{
205
_unsupported_imgopts "subformat=monolithicFlat" \
200
- MemTxAttrs attrs = {};
206
"subformat=twoGbMaxExtentFlat" \
201
-
207
- "subformat=twoGbMaxExtentSparse"
202
- attrs.requester_id = pci_requester_id(dev);
208
+ "subformat=twoGbMaxExtentSparse" \
203
- address_space_stl_le(&dev->bus_master_as, msg.address, msg.data,
209
+ "subformat=streamOptimized"
204
- attrs, NULL);
210
205
+ dev->msi_trigger(dev, msg);
211
CLUSTER_SIZE=4k
206
}
212
size=128M
207
213
diff --git a/tests/qemu-iotests/037 b/tests/qemu-iotests/037
208
/* Normally called by pci_default_write_config(). */
214
index XXXXXXX..XXXXXXX 100755
209
diff --git a/hw/pci/msix.c b/hw/pci/msix.c
215
--- a/tests/qemu-iotests/037
210
index XXXXXXX..XXXXXXX 100644
216
+++ b/tests/qemu-iotests/037
211
--- a/hw/pci/msix.c
217
@@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed
212
+++ b/hw/pci/msix.c
218
_supported_proto file
213
@@ -XXX,XX +XXX,XX @@
219
_unsupported_imgopts "subformat=monolithicFlat" \
214
#define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8)
220
"subformat=twoGbMaxExtentFlat" \
215
#define MSIX_MASKALL_MASK (PCI_MSIX_FLAGS_MASKALL >> 8)
221
- "subformat=twoGbMaxExtentSparse"
216
222
+ "subformat=twoGbMaxExtentSparse" \
217
-MSIMessage msix_get_message(PCIDevice *dev, unsigned vector)
223
+ "subformat=streamOptimized"
218
+static MSIMessage msix_prepare_message(PCIDevice *dev, unsigned vector)
224
219
{
225
CLUSTER_SIZE=4k
220
uint8_t *table_entry = dev->msix_table + vector * PCI_MSIX_ENTRY_SIZE;
226
size=128M
221
MSIMessage msg;
227
diff --git a/tests/qemu-iotests/063 b/tests/qemu-iotests/063
222
@@ -XXX,XX +XXX,XX @@ MSIMessage msix_get_message(PCIDevice *dev, unsigned vector)
228
index XXXXXXX..XXXXXXX 100755
223
return msg;
229
--- a/tests/qemu-iotests/063
224
}
230
+++ b/tests/qemu-iotests/063
225
231
@@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed raw
226
+MSIMessage msix_get_message(PCIDevice *dev, unsigned vector)
232
_supported_proto file
227
+{
233
_unsupported_imgopts "subformat=monolithicFlat" \
228
+ return dev->msix_prepare_message(dev, vector);
234
"subformat=twoGbMaxExtentFlat" \
229
+}
235
- "subformat=twoGbMaxExtentSparse"
230
+
236
+ "subformat=twoGbMaxExtentSparse" \
231
/*
237
+ "subformat=streamOptimized"
232
* Special API for POWER to configure the vectors through
238
233
* a side channel. Should never be used by devices.
239
_make_test_img 4M
234
@@ -XXX,XX +XXX,XX @@ static void msix_handle_mask_update(PCIDevice *dev, int vector, bool was_masked)
240
235
}
241
diff --git a/tests/qemu-iotests/072 b/tests/qemu-iotests/072
236
}
242
index XXXXXXX..XXXXXXX 100755
237
243
--- a/tests/qemu-iotests/072
238
+void msix_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp)
244
+++ b/tests/qemu-iotests/072
239
+{
245
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
240
+ ERRP_GUARD();
246
241
+ unsigned offset;
247
_supported_fmt vpc vmdk vhdx vdi qed qcow2 qcow
242
+ bool was_masked;
248
_supported_proto file
243
+
249
+_unsupported_imgopts "subformat=streamOptimized"
244
+ if (vector > dev->msix_entries_nr) {
250
245
+ error_setg(errp, "msix: vector %d not allocated. max vector is %d",
251
IMG_SIZE=64M
246
+ vector, dev->msix_entries_nr);
252
247
+ return;
253
diff --git a/tests/qemu-iotests/105 b/tests/qemu-iotests/105
248
+ }
254
index XXXXXXX..XXXXXXX 100755
249
+
255
--- a/tests/qemu-iotests/105
250
+ offset = vector * PCI_MSIX_ENTRY_SIZE + PCI_MSIX_ENTRY_VECTOR_CTRL;
256
+++ b/tests/qemu-iotests/105
251
+
257
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
252
+ was_masked = msix_is_masked(dev, vector);
258
_supported_fmt qcow2 vmdk vhdx qed
253
+
259
_supported_proto generic
254
+ if (mask) {
260
_unsupported_imgopts "subformat=twoGbMaxExtentFlat" \
255
+ dev->msix_table[offset] |= PCI_MSIX_ENTRY_CTRL_MASKBIT;
261
- "subformat=twoGbMaxExtentSparse"
256
+ } else {
262
+ "subformat=twoGbMaxExtentSparse" \
257
+ dev->msix_table[offset] &= ~PCI_MSIX_ENTRY_CTRL_MASKBIT;
263
+ "subformat=streamOptimized"
258
+ }
264
259
+
265
echo
260
+ msix_handle_mask_update(dev, vector, was_masked);
266
echo "creating large image"
261
+}
267
diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197
262
+
268
index XXXXXXX..XXXXXXX 100755
263
static bool msix_masked(PCIDevice *dev)
269
--- a/tests/qemu-iotests/197
264
{
270
+++ b/tests/qemu-iotests/197
265
return dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & MSIX_MASKALL_MASK;
271
@@ -XXX,XX +XXX,XX @@ _supported_fmt generic
266
@@ -XXX,XX +XXX,XX @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
272
_supported_proto generic
267
"msix-pba", pba_size);
273
# LUKS support may be possible, but it complicates things.
268
memory_region_add_subregion(pba_bar, pba_offset, &dev->msix_pba_mmio);
274
_unsupported_fmt luks
269
275
+_unsupported_imgopts "subformat=streamOptimized"
270
+ dev->msix_prepare_message = msix_prepare_message;
276
271
+
277
echo
272
return 0;
278
echo '=== Copy-on-read ==='
273
}
279
diff --git a/tests/qemu-iotests/215 b/tests/qemu-iotests/215
274
280
index XXXXXXX..XXXXXXX 100755
275
@@ -XXX,XX +XXX,XX @@ void msix_uninit(PCIDevice *dev, MemoryRegion *table_bar, MemoryRegion *pba_bar)
281
--- a/tests/qemu-iotests/215
276
g_free(dev->msix_entry_used);
282
+++ b/tests/qemu-iotests/215
277
dev->msix_entry_used = NULL;
283
@@ -XXX,XX +XXX,XX @@ _supported_fmt generic
278
dev->cap_present &= ~QEMU_PCI_CAP_MSIX;
284
_supported_proto generic
279
+ dev->msix_prepare_message = NULL;
285
# LUKS support may be possible, but it complicates things.
280
}
286
_unsupported_fmt luks
281
287
+_unsupported_imgopts "subformat=streamOptimized"
282
void msix_uninit_exclusive_bar(PCIDevice *dev)
288
283
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
289
echo
284
index XXXXXXX..XXXXXXX 100644
290
echo '=== Copy-on-read ==='
285
--- a/hw/pci/pci.c
291
diff --git a/tests/qemu-iotests/251 b/tests/qemu-iotests/251
286
+++ b/hw/pci/pci.c
292
index XXXXXXX..XXXXXXX 100755
287
@@ -XXX,XX +XXX,XX @@ void pci_device_deassert_intx(PCIDevice *dev)
293
--- a/tests/qemu-iotests/251
288
}
294
+++ b/tests/qemu-iotests/251
289
}
295
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
290
296
_supported_fmt generic
291
+static void pci_msi_trigger(PCIDevice *dev, MSIMessage msg)
297
_supported_proto file
292
+{
298
_supported_os Linux
293
+ MemTxAttrs attrs = {};
299
+_unsupported_imgopts "subformat=streamOptimized"
294
+
300
295
+ attrs.requester_id = pci_requester_id(dev);
301
if [ "$IMGOPTSSYNTAX" = "true" ]; then
296
+ address_space_stl_le(&dev->bus_master_as, msg.address, msg.data,
302
# We use json:{} filenames here, so we cannot work with additional options.
297
+ attrs, NULL);
298
+}
299
+
300
static void pci_reset_regions(PCIDevice *dev)
301
{
302
int r;
303
@@ -XXX,XX +XXX,XX @@ static void pci_qdev_unrealize(DeviceState *dev)
304
305
pci_device_deassert_intx(pci_dev);
306
do_pci_unregister_device(pci_dev);
307
+
308
+ pci_dev->msi_trigger = NULL;
309
}
310
311
void pci_register_bar(PCIDevice *pci_dev, int region_num,
312
@@ -XXX,XX +XXX,XX @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)
313
}
314
315
pci_set_power(pci_dev, true);
316
+
317
+ pci_dev->msi_trigger = pci_msi_trigger;
318
}
319
320
PCIDevice *pci_new_multifunction(int devfn, bool multifunction,
321
diff --git a/hw/remote/machine.c b/hw/remote/machine.c
322
index XXXXXXX..XXXXXXX 100644
323
--- a/hw/remote/machine.c
324
+++ b/hw/remote/machine.c
325
@@ -XXX,XX +XXX,XX @@
326
#include "hw/remote/iommu.h"
327
#include "hw/qdev-core.h"
328
#include "hw/remote/iommu.h"
329
+#include "hw/remote/vfio-user-obj.h"
330
+#include "hw/pci/msi.h"
331
332
static void remote_machine_init(MachineState *machine)
333
{
334
@@ -XXX,XX +XXX,XX @@ static void remote_machine_init(MachineState *machine)
335
336
if (s->vfio_user) {
337
remote_iommu_setup(pci_host->bus);
338
+
339
+ msi_nonbroken = true;
340
+
341
+ vfu_object_set_bus_irq(pci_host->bus);
342
+ } else {
343
+ remote_iohub_init(&s->iohub);
344
+
345
+ pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq,
346
+ &s->iohub, REMOTE_IOHUB_NB_PIRQS);
347
}
348
349
- remote_iohub_init(&s->iohub);
350
-
351
- pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq,
352
- &s->iohub, REMOTE_IOHUB_NB_PIRQS);
353
-
354
qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s));
355
}
356
357
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
358
index XXXXXXX..XXXXXXX 100644
359
--- a/hw/remote/vfio-user-obj.c
360
+++ b/hw/remote/vfio-user-obj.c
361
@@ -XXX,XX +XXX,XX @@
362
#include "hw/pci/pci.h"
363
#include "qemu/timer.h"
364
#include "exec/memory.h"
365
+#include "hw/pci/msi.h"
366
+#include "hw/pci/msix.h"
367
+#include "hw/remote/vfio-user-obj.h"
368
369
#define TYPE_VFU_OBJECT "x-vfio-user-server"
370
OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
371
@@ -XXX,XX +XXX,XX @@ struct VfuObject {
372
Error *unplug_blocker;
373
374
int vfu_poll_fd;
375
+
376
+ MSITriggerFunc *default_msi_trigger;
377
+ MSIPrepareMessageFunc *default_msi_prepare_message;
378
+ MSIxPrepareMessageFunc *default_msix_prepare_message;
379
};
380
381
static void vfu_object_init_ctx(VfuObject *o, Error **errp);
382
@@ -XXX,XX +XXX,XX @@ static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev)
383
}
384
}
385
386
+static int vfu_object_map_irq(PCIDevice *pci_dev, int intx)
387
+{
388
+ int pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_dev)),
389
+ pci_dev->devfn);
390
+
391
+ return pci_bdf;
392
+}
393
+
394
+static void vfu_object_set_irq(void *opaque, int pirq, int level)
395
+{
396
+ PCIBus *pci_bus = opaque;
397
+ PCIDevice *pci_dev = NULL;
398
+ vfu_ctx_t *vfu_ctx = NULL;
399
+ int pci_bus_num, devfn;
400
+
401
+ if (level) {
402
+ pci_bus_num = PCI_BUS_NUM(pirq);
403
+ devfn = PCI_BDF_TO_DEVFN(pirq);
404
+
405
+ /*
406
+ * pci_find_device() performs at O(1) if the device is attached
407
+ * to the root PCI bus. Whereas, if the device is attached to a
408
+ * secondary PCI bus (such as when a root port is involved),
409
+ * finding the parent PCI bus could take O(n)
410
+ */
411
+ pci_dev = pci_find_device(pci_bus, pci_bus_num, devfn);
412
+
413
+ vfu_ctx = pci_dev->irq_opaque;
414
+
415
+ g_assert(vfu_ctx);
416
+
417
+ vfu_irq_trigger(vfu_ctx, 0);
418
+ }
419
+}
420
+
421
+static MSIMessage vfu_object_msi_prepare_msg(PCIDevice *pci_dev,
422
+ unsigned int vector)
423
+{
424
+ MSIMessage msg;
425
+
426
+ msg.address = 0;
427
+ msg.data = vector;
428
+
429
+ return msg;
430
+}
431
+
432
+static void vfu_object_msi_trigger(PCIDevice *pci_dev, MSIMessage msg)
433
+{
434
+ vfu_ctx_t *vfu_ctx = pci_dev->irq_opaque;
435
+
436
+ vfu_irq_trigger(vfu_ctx, msg.data);
437
+}
438
+
439
+static void vfu_object_setup_msi_cbs(VfuObject *o)
440
+{
441
+ o->default_msi_trigger = o->pci_dev->msi_trigger;
442
+ o->default_msi_prepare_message = o->pci_dev->msi_prepare_message;
443
+ o->default_msix_prepare_message = o->pci_dev->msix_prepare_message;
444
+
445
+ o->pci_dev->msi_trigger = vfu_object_msi_trigger;
446
+ o->pci_dev->msi_prepare_message = vfu_object_msi_prepare_msg;
447
+ o->pci_dev->msix_prepare_message = vfu_object_msi_prepare_msg;
448
+}
449
+
450
+static void vfu_object_restore_msi_cbs(VfuObject *o)
451
+{
452
+ o->pci_dev->msi_trigger = o->default_msi_trigger;
453
+ o->pci_dev->msi_prepare_message = o->default_msi_prepare_message;
454
+ o->pci_dev->msix_prepare_message = o->default_msix_prepare_message;
455
+}
456
+
457
+static void vfu_msix_irq_state(vfu_ctx_t *vfu_ctx, uint32_t start,
458
+ uint32_t count, bool mask)
459
+{
460
+ VfuObject *o = vfu_get_private(vfu_ctx);
461
+ Error *err = NULL;
462
+ uint32_t vector;
463
+
464
+ for (vector = start; vector < count; vector++) {
465
+ msix_set_mask(o->pci_dev, vector, mask, &err);
466
+ if (err) {
467
+ VFU_OBJECT_ERROR(o, "vfu: %s: %s", o->device,
468
+ error_get_pretty(err));
469
+ error_free(err);
470
+ err = NULL;
471
+ }
472
+ }
473
+}
474
+
475
+static void vfu_msi_irq_state(vfu_ctx_t *vfu_ctx, uint32_t start,
476
+ uint32_t count, bool mask)
477
+{
478
+ VfuObject *o = vfu_get_private(vfu_ctx);
479
+ Error *err = NULL;
480
+ uint32_t vector;
481
+
482
+ for (vector = start; vector < count; vector++) {
483
+ msi_set_mask(o->pci_dev, vector, mask, &err);
484
+ if (err) {
485
+ VFU_OBJECT_ERROR(o, "vfu: %s: %s", o->device,
486
+ error_get_pretty(err));
487
+ error_free(err);
488
+ err = NULL;
489
+ }
490
+ }
491
+}
492
+
493
+static int vfu_object_setup_irqs(VfuObject *o, PCIDevice *pci_dev)
494
+{
495
+ vfu_ctx_t *vfu_ctx = o->vfu_ctx;
496
+ int ret;
497
+
498
+ ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_INTX_IRQ, 1);
499
+ if (ret < 0) {
500
+ return ret;
501
+ }
502
+
503
+ if (msix_nr_vectors_allocated(pci_dev)) {
504
+ ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSIX_IRQ,
505
+ msix_nr_vectors_allocated(pci_dev));
506
+ vfu_setup_irq_state_callback(vfu_ctx, VFU_DEV_MSIX_IRQ,
507
+ &vfu_msix_irq_state);
508
+ } else if (msi_nr_vectors_allocated(pci_dev)) {
509
+ ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSI_IRQ,
510
+ msi_nr_vectors_allocated(pci_dev));
511
+ vfu_setup_irq_state_callback(vfu_ctx, VFU_DEV_MSI_IRQ,
512
+ &vfu_msi_irq_state);
513
+ }
514
+
515
+ if (ret < 0) {
516
+ return ret;
517
+ }
518
+
519
+ vfu_object_setup_msi_cbs(o);
520
+
521
+ pci_dev->irq_opaque = vfu_ctx;
522
+
523
+ return 0;
524
+}
525
+
526
+void vfu_object_set_bus_irq(PCIBus *pci_bus)
527
+{
528
+ int bus_num = pci_bus_num(pci_bus);
529
+ int max_bdf = PCI_BUILD_BDF(bus_num, PCI_DEVFN_MAX - 1);
530
+
531
+ pci_bus_irqs(pci_bus, vfu_object_set_irq, vfu_object_map_irq, pci_bus,
532
+ max_bdf);
533
+}
534
+
535
/*
536
* TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
537
* properties. It also depends on devices instantiated in QEMU. These
538
@@ -XXX,XX +XXX,XX @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
539
540
vfu_object_register_bars(o->vfu_ctx, o->pci_dev);
541
542
+ ret = vfu_object_setup_irqs(o, o->pci_dev);
543
+ if (ret < 0) {
544
+ error_setg(errp, "vfu: Failed to setup interrupts for %s",
545
+ o->device);
546
+ goto fail;
547
+ }
548
+
549
ret = vfu_realize_ctx(o->vfu_ctx);
550
if (ret < 0) {
551
error_setg(errp, "vfu: Failed to realize device %s- %s",
552
@@ -XXX,XX +XXX,XX @@ fail:
553
o->unplug_blocker = NULL;
554
}
555
if (o->pci_dev) {
556
+ vfu_object_restore_msi_cbs(o);
557
+ o->pci_dev->irq_opaque = NULL;
558
object_unref(OBJECT(o->pci_dev));
559
o->pci_dev = NULL;
560
}
561
@@ -XXX,XX +XXX,XX @@ static void vfu_object_finalize(Object *obj)
562
}
563
564
if (o->pci_dev) {
565
+ vfu_object_restore_msi_cbs(o);
566
+ o->pci_dev->irq_opaque = NULL;
567
object_unref(OBJECT(o->pci_dev));
568
o->pci_dev = NULL;
569
}
570
diff --git a/stubs/vfio-user-obj.c b/stubs/vfio-user-obj.c
571
new file mode 100644
572
index XXXXXXX..XXXXXXX
573
--- /dev/null
574
+++ b/stubs/vfio-user-obj.c
575
@@ -XXX,XX +XXX,XX @@
576
+#include "qemu/osdep.h"
577
+#include "hw/remote/vfio-user-obj.h"
578
+
579
+void vfu_object_set_bus_irq(PCIBus *pci_bus)
580
+{
581
+}
582
diff --git a/hw/remote/trace-events b/hw/remote/trace-events
583
index XXXXXXX..XXXXXXX 100644
584
--- a/hw/remote/trace-events
585
+++ b/hw/remote/trace-events
586
@@ -XXX,XX +XXX,XX @@ vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64""
587
vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64""
588
vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64""
589
vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64""
590
+vfu_interrupt(int pirq) "vfu: sending interrupt to device - PIRQ %d"
591
diff --git a/stubs/meson.build b/stubs/meson.build
592
index XXXXXXX..XXXXXXX 100644
593
--- a/stubs/meson.build
594
+++ b/stubs/meson.build
595
@@ -XXX,XX +XXX,XX @@ if have_system
596
else
597
stub_ss.add(files('qdev.c'))
598
endif
599
+stub_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_false: files('vfio-user-obj.c'))
303
--
600
--
304
2.21.0
601
2.36.1
305
306
diff view generated by jsdifflib
1
From: Nir Soffer <nirsof@gmail.com>
1
From: Jagannathan Raman <jag.raman@oracle.com>
2
2
3
Using block_resize we can test allocate_first_block() with file
3
Adds handler to reset a remote device
4
descriptor opened with O_DIRECT, ensuring that it works for any size
5
larger than 4096 bytes.
6
4
7
Testing smaller sizes is tricky as the result depends on the filesystem
5
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
8
used for testing. For example on NFS any size will work since O_DIRECT
6
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
9
does not require any alignment.
7
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Message-id: 112eeadf3bc4c6cdb100bc3f9a6fcfc20b467c1b.1655151679.git.jag.raman@oracle.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
12
hw/remote/vfio-user-obj.c | 20 ++++++++++++++++++++
13
1 file changed, 20 insertions(+)
10
14
11
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
15
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
12
Reviewed-by: Max Reitz <mreitz@redhat.com>
16
index XXXXXXX..XXXXXXX 100644
13
Message-id: 20190827010528.8818-3-nsoffer@redhat.com
17
--- a/hw/remote/vfio-user-obj.c
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
+++ b/hw/remote/vfio-user-obj.c
15
---
19
@@ -XXX,XX +XXX,XX @@ void vfu_object_set_bus_irq(PCIBus *pci_bus)
16
tests/qemu-iotests/175 | 28 ++++++++++++++++++++++++++++
20
max_bdf);
17
tests/qemu-iotests/175.out | 8 ++++++++
18
2 files changed, 36 insertions(+)
19
20
diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175
21
index XXXXXXX..XXXXXXX 100755
22
--- a/tests/qemu-iotests/175
23
+++ b/tests/qemu-iotests/175
24
@@ -XXX,XX +XXX,XX @@ _filter_blocks()
25
-e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/"
26
}
21
}
27
22
28
+# Resize image using block_resize.
23
+static int vfu_object_device_reset(vfu_ctx_t *vfu_ctx, vfu_reset_type_t type)
29
+# Parameter 1: image path
30
+# Parameter 2: new size
31
+_block_resize()
32
+{
24
+{
33
+ local path=$1
25
+ VfuObject *o = vfu_get_private(vfu_ctx);
34
+ local size=$2
35
+
26
+
36
+ $QEMU -qmp stdio -nographic -nodefaults \
27
+ /* vfu_object_ctx_run() handles lost connection */
37
+ -blockdev file,node-name=file,filename=$path,cache.direct=on \
28
+ if (type == VFU_RESET_LOST_CONN) {
38
+ <<EOF
29
+ return 0;
39
+{'execute': 'qmp_capabilities'}
30
+ }
40
+{'execute': 'block_resize', 'arguments': {'node-name': 'file', 'size': $size}}
31
+
41
+{'execute': 'quit'}
32
+ qdev_reset_all(DEVICE(o->pci_dev));
42
+EOF
33
+
34
+ return 0;
43
+}
35
+}
44
+
36
+
45
# get standard environment, filters and checks
37
/*
46
. ./common.rc
38
* TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
47
. ./common.filter
39
* properties. It also depends on devices instantiated in QEMU. These
48
@@ -XXX,XX +XXX,XX @@ _supported_fmt raw
40
@@ -XXX,XX +XXX,XX @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
49
_supported_proto file
41
goto fail;
50
_supported_os Linux
42
}
51
43
52
+_default_cache_mode none
44
+ ret = vfu_setup_device_reset_cb(o->vfu_ctx, &vfu_object_device_reset);
53
+_supported_cache_modes none directsync
45
+ if (ret < 0) {
46
+ error_setg(errp, "vfu: Failed to setup reset callback");
47
+ goto fail;
48
+ }
54
+
49
+
55
size=$((1 * 1024 * 1024))
50
ret = vfu_realize_ctx(o->vfu_ctx);
56
51
if (ret < 0) {
57
touch "$TEST_DIR/empty"
52
error_setg(errp, "vfu: Failed to realize device %s- %s",
58
@@ -XXX,XX +XXX,XX @@ for mode in off full falloc; do
59
stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size
60
done
61
62
+for new_size in 4096 1048576; do
63
+ echo
64
+ echo "== resize empty image with block_resize =="
65
+ _make_test_img 0 | _filter_imgfmt
66
+ _block_resize $TEST_IMG $new_size >/dev/null
67
+ stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $new_size
68
+done
69
+
70
# success, all done
71
echo "*** done"
72
rm -f $seq.full
73
diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out
74
index XXXXXXX..XXXXXXX 100644
75
--- a/tests/qemu-iotests/175.out
76
+++ b/tests/qemu-iotests/175.out
77
@@ -XXX,XX +XXX,XX @@ size=1048576, max allocation
78
== creating image with preallocation falloc ==
79
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc
80
size=1048576, max allocation
81
+
82
+== resize empty image with block_resize ==
83
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0
84
+size=4096, min allocation
85
+
86
+== resize empty image with block_resize ==
87
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0
88
+size=1048576, min allocation
89
*** done
90
--
53
--
91
2.21.0
54
2.36.1
92
93
diff view generated by jsdifflib
1
We had a test for a case where relative extent paths did not work, but
1
Every laio_io_plug() call has a matching laio_io_unplug() call. There is
2
unfortunately we just fixed the underlying problem, so it works now.
2
a plugged counter that tracks the number of levels of plugging and
3
This patch adds a new test case that still fails.
3
allows for nesting.
4
4
5
Signed-off-by: Max Reitz <mreitz@redhat.com>
5
The plugged counter must reflect the balance between laio_io_plug() and
6
Reviewed-by: John Snow <jsnow@redhat.com>
6
laio_io_unplug() calls accurately. Otherwise I/O stalls occur since
7
Message-id: 20190815153638.4600-4-mreitz@redhat.com
7
io_submit(2) calls are skipped while plugged.
8
Reviewed-by: John Snow <jsnow@redhat.com>
8
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Reported-by: Nikolay Tenev <nt@storpool.com>
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
12
Message-id: 20220609164712.1539045-2-stefanha@redhat.com
13
Cc: Stefano Garzarella <sgarzare@redhat.com>
14
Fixes: 68d7946648 ("linux-aio: add `dev_max_batch` parameter to laio_io_unplug()")
15
[Stefano Garzarella suggested adding a Fixes tag.
16
--Stefan]
17
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
10
---
18
---
11
tests/qemu-iotests/059 | 27 +++++++++++++++++++++++++++
19
block/linux-aio.c | 4 +++-
12
tests/qemu-iotests/059.out | 4 ++++
20
1 file changed, 3 insertions(+), 1 deletion(-)
13
2 files changed, 31 insertions(+)
14
21
15
diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059
22
diff --git a/block/linux-aio.c b/block/linux-aio.c
16
index XXXXXXX..XXXXXXX 100755
23
index XXXXXXX..XXXXXXX 100644
17
--- a/tests/qemu-iotests/059
24
--- a/block/linux-aio.c
18
+++ b/tests/qemu-iotests/059
25
+++ b/block/linux-aio.c
19
@@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2
26
@@ -XXX,XX +XXX,XX @@ void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s,
20
27
uint64_t dev_max_batch)
21
echo
28
{
22
echo "=== Testing monolithicFlat with internally generated JSON file name ==="
29
assert(s->io_q.plugged);
30
+ s->io_q.plugged--;
23
+
31
+
24
+echo '--- blkdebug ---'
32
if (s->io_q.in_queue >= laio_max_batch(s, dev_max_batch) ||
25
# Should work, because bdrv_dirname() works fine with blkdebug
33
- (--s->io_q.plugged == 0 &&
26
IMGOPTS="subformat=monolithicFlat" _make_test_img 64M
34
+ (!s->io_q.plugged &&
27
$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \
35
!s->io_q.blocked && !QSIMPLEQ_EMPTY(&s->io_q.pending))) {
28
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TE
36
ioq_submit(s);
29
| _filter_testdir | _filter_imgfmt | _filter_img_info
37
}
30
_cleanup_test_img
31
32
+echo '--- quorum ---'
33
+# Should not work, because bdrv_dirname() does not work with quorum
34
+IMGOPTS="subformat=monolithicFlat" _make_test_img 64M
35
+cp "$TEST_IMG" "$TEST_IMG.orig"
36
+
37
+filename="json:{
38
+ \"driver\": \"$IMGFMT\",
39
+ \"file\": {
40
+ \"driver\": \"quorum\",
41
+ \"children\": [ {
42
+ \"driver\": \"file\",
43
+ \"filename\": \"$TEST_IMG\"
44
+ }, {
45
+ \"driver\": \"file\",
46
+ \"filename\": \"$TEST_IMG.orig\"
47
+ } ],
48
+ \"vote-threshold\": 1
49
+ } }"
50
+
51
+filename=$(echo "$filename" | tr '\n' ' ' | sed -e 's/\s\+/ /g')
52
+$QEMU_IMG info "$filename" 2>&1 \
53
+ | sed -e "s/'json:[^']*'/\$QUORUM_FILE/g" \
54
+ | _filter_testdir | _filter_imgfmt | _filter_img_info
55
+
56
+
57
echo
58
echo "=== Testing version 3 ==="
59
_use_sample_img iotest-version3.vmdk.bz2
60
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
61
index XXXXXXX..XXXXXXX 100644
62
--- a/tests/qemu-iotests/059.out
63
+++ b/tests/qemu-iotests/059.out
64
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240
65
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
66
67
=== Testing monolithicFlat with internally generated JSON file name ===
68
+--- blkdebug ---
69
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
70
format name: IMGFMT
71
cluster size: 0 bytes
72
vm state offset: 0 bytes
73
+--- quorum ---
74
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
75
+qemu-img: Could not open $QUORUM_FILE: Cannot use relative paths with VMDK descriptor file $QUORUM_FILE: Cannot generate a base directory for quorum nodes
76
77
=== Testing version 3 ===
78
image: TEST_DIR/iotest-version3.IMGFMT
79
--
38
--
80
2.21.0
39
2.36.1
81
82
diff view generated by jsdifflib
1
fe646693acc changed qemu-img create's output so that it no longer prints
1
It may not be obvious why laio_io_unplug() checks max batch. I discussed
2
single quotes around parameter values. The subformat and adapter_type
2
this with Stefano and have added a comment summarizing the reason.
3
filters in _filter_img_create() have never been adapted to that change.
4
3
5
Fixes: fe646693acc13ac48b98435d14149ab04dc597bc
4
Cc: Stefano Garzarella <sgarzare@redhat.com>
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
5
Cc: Kevin Wolf <kwolf@redhat.com>
7
Reviewed-by: John Snow <jsnow@redhat.com>
6
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Message-id: 20190815153638.4600-2-mreitz@redhat.com
7
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
9
Reviewed-by: John Snow <jsnow@redhat.com>
8
Message-id: 20220609164712.1539045-3-stefanha@redhat.com
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
10
---
12
tests/qemu-iotests/059.out | 16 ++++++++--------
11
block/linux-aio.c | 6 ++++++
13
tests/qemu-iotests/common.filter | 4 ++--
12
1 file changed, 6 insertions(+)
14
2 files changed, 10 insertions(+), 10 deletions(-)
15
13
16
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
14
diff --git a/block/linux-aio.c b/block/linux-aio.c
17
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
18
--- a/tests/qemu-iotests/059.out
16
--- a/block/linux-aio.c
19
+++ b/tests/qemu-iotests/059.out
17
+++ b/block/linux-aio.c
20
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
18
@@ -XXX,XX +XXX,XX @@ void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s,
21
qemu-io: can't open device TEST_DIR/t.vmdk: L1 size too big
19
assert(s->io_q.plugged);
22
20
s->io_q.plugged--;
23
=== Testing monolithicFlat creation and opening ===
21
24
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat
22
+ /*
25
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648
23
+ * Why max batch checking is performed here:
26
image: TEST_DIR/t.IMGFMT
24
+ * Another BDS may have queued requests with a higher dev_max_batch and
27
file format: IMGFMT
25
+ * therefore in_queue could now exceed our dev_max_batch. Re-check the max
28
virtual size: 2 GiB (2147483648 bytes)
26
+ * batch so we can honor our device's dev_max_batch.
29
27
+ */
30
=== Testing monolithicFlat with zeroed_grain ===
28
if (s->io_q.in_queue >= laio_max_batch(s, dev_max_batch) ||
31
qemu-img: TEST_DIR/t.IMGFMT: Flat image can't enable zeroed grain
29
(!s->io_q.plugged &&
32
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat
30
!s->io_q.blocked && !QSIMPLEQ_EMPTY(&s->io_q.pending))) {
33
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648
34
35
=== Testing big twoGbMaxExtentFlat ===
36
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMaxExtentFlat
37
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000
38
image: TEST_DIR/t.vmdk
39
file format: vmdk
40
virtual size: 0.977 TiB (1073741824000 bytes)
41
@@ -XXX,XX +XXX,XX @@ Format specific information:
42
qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Invalid extent line: RW 12582912 VMFS "dummy.IMGFMT" 1
43
44
=== Testing truncated sparse ===
45
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400 subformat=monolithicSparse
46
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400
47
qemu-img: Could not open 'TEST_DIR/t.IMGFMT': File truncated, expecting at least 13172736 bytes
48
49
=== Converting to streamOptimized from image with small cluster size===
50
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240
51
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
52
53
=== Testing monolithicFlat with internally generated JSON file name ===
54
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 subformat=monolithicFlat
55
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
56
qemu-io: can't open: Cannot use relative extent paths with VMDK descriptor file 'json:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "read_aio"}'
57
58
=== Testing version 3 ===
59
@@ -XXX,XX +XXX,XX @@ read 512/512 bytes at offset 64931328
60
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
61
62
=== Testing 4TB monolithicFlat creation and IO ===
63
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4398046511104 subformat=monolithicFlat
64
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4398046511104
65
image: TEST_DIR/t.IMGFMT
66
file format: IMGFMT
67
virtual size: 4 TiB (4398046511104 bytes)
68
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 966367641600
69
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
70
71
=== Testing qemu-img map on extents ===
72
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 subformat=monolithicSparse
73
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544
74
wrote 1024/1024 bytes at offset 65024
75
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
76
wrote 1024/1024 bytes at offset 2147483136
77
@@ -XXX,XX +XXX,XX @@ Offset Length Mapped to File
78
0 0x20000 0x3f0000 TEST_DIR/t.vmdk
79
0x7fff0000 0x20000 0x410000 TEST_DIR/t.vmdk
80
0x140000000 0x10000 0x430000 TEST_DIR/t.vmdk
81
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 subformat=twoGbMaxExtentSparse
82
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544
83
wrote 1024/1024 bytes at offset 65024
84
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
85
wrote 1024/1024 bytes at offset 2147483136
86
diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
87
index XXXXXXX..XXXXXXX 100644
88
--- a/tests/qemu-iotests/common.filter
89
+++ b/tests/qemu-iotests/common.filter
90
@@ -XXX,XX +XXX,XX @@ _filter_img_create()
91
-e "s# compat6=\\(on\\|off\\)##g" \
92
-e "s# static=\\(on\\|off\\)##g" \
93
-e "s# zeroed_grain=\\(on\\|off\\)##g" \
94
- -e "s# subformat='[^']*'##g" \
95
- -e "s# adapter_type='[^']*'##g" \
96
+ -e "s# subformat=[^ ]*##g" \
97
+ -e "s# adapter_type=[^ ]*##g" \
98
-e "s# hwversion=[^ ]*##g" \
99
-e "s# lazy_refcounts=\\(on\\|off\\)##g" \
100
-e "s# block_size=[0-9]\\+##g" \
101
--
31
--
102
2.21.0
32
2.36.1
103
104
diff view generated by jsdifflib