1 | The following changes since commit bfec359afba088aaacc7d316f43302f28c6e642a: | 1 | The following changes since commit 77f3804ab7ed94b471a14acb260e5aeacf26193f: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/armbru/tags/pull-qdev-2017-04-21' into staging (2017-04-21 11:42:03 +0100) | 3 | Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2021-02-02 16:47:51 +0000) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/codyprime/qemu-kvm-jtc.git tags/block-pull-request | 7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 1507631e438930bc07f776f303af127a9cdb4d41: | 9 | for you to fetch changes up to 026362226f1ff6a1168524a326bbd6347ad40e85: |
10 | 10 | ||
11 | qemu-iotests: _cleanup_qemu must be called on exit (2017-04-21 08:32:44 -0400) | 11 | docs: fix Parallels Image "dirty bitmap" section (2021-02-03 16:48:21 +0000) |
12 | |||
13 | ---------------------------------------------------------------- | ||
14 | Pull request | ||
15 | |||
16 | The pull request includes Multi-Process QEMU, GitLab repo URL updates, and even | ||
17 | a block layer patch to fix the Parallels Image format specification! | ||
12 | 18 | ||
13 | ---------------------------------------------------------------- | 19 | ---------------------------------------------------------------- |
14 | 20 | ||
15 | Block patches for 2.10 | 21 | Denis V. Lunev (1): |
22 | docs: fix Parallels Image "dirty bitmap" section | ||
16 | 23 | ||
17 | ---------------------------------------------------------------- | 24 | Elena Ufimtseva (8): |
25 | multi-process: add configure and usage information | ||
26 | io: add qio_channel_writev_full_all helper | ||
27 | io: add qio_channel_readv_full_all_eof & qio_channel_readv_full_all | ||
28 | helpers | ||
29 | multi-process: define MPQemuMsg format and transmission functions | ||
30 | multi-process: introduce proxy object | ||
31 | multi-process: add proxy communication functions | ||
32 | multi-process: Forward PCI config space acceses to the remote process | ||
33 | multi-process: perform device reset in the remote process | ||
18 | 34 | ||
19 | Ashish Mittal (2): | 35 | Jagannathan Raman (11): |
20 | block/vxhs.c: Add support for a new block device type called "vxhs" | 36 | memory: alloc RAM from file at offset |
21 | block/vxhs.c: Add qemu-iotests for new block device type "vxhs" | 37 | multi-process: Add config option for multi-process QEMU |
38 | multi-process: setup PCI host bridge for remote device | ||
39 | multi-process: setup a machine object for remote device process | ||
40 | multi-process: Initialize message handler in remote device | ||
41 | multi-process: Associate fd of a PCIDevice with its object | ||
42 | multi-process: setup memory manager for remote device | ||
43 | multi-process: PCI BAR read/write handling for proxy & remote | ||
44 | endpoints | ||
45 | multi-process: Synchronize remote memory | ||
46 | multi-process: create IOHUB object to handle irq | ||
47 | multi-process: Retrieve PCI info from remote process | ||
22 | 48 | ||
23 | Jeff Cody (10): | 49 | John G Johnson (1): |
24 | qemu-iotests: exclude vxhs from image creation via protocol | 50 | multi-process: add the concept description to |
25 | block: add bdrv_set_read_only() helper function | 51 | docs/devel/qemu-multiprocess |
26 | block: do not set BDS read_only if copy_on_read enabled | ||
27 | block: honor BDRV_O_ALLOW_RDWR when clearing bs->read_only | ||
28 | block: code movement | ||
29 | block: introduce bdrv_can_set_read_only() | ||
30 | block: use bdrv_can_set_read_only() during reopen | ||
31 | block/rbd - update variable names to more apt names | ||
32 | block/rbd: Add support for reopen() | ||
33 | qemu-iotests: _cleanup_qemu must be called on exit | ||
34 | 52 | ||
35 | block.c | 56 +++- | 53 | Stefan Hajnoczi (6): |
36 | block/Makefile.objs | 2 + | 54 | .github: point Repo Lockdown bot to GitLab repo |
37 | block/bochs.c | 5 +- | 55 | gitmodules: use GitLab repos instead of qemu.org |
38 | block/cloop.c | 5 +- | 56 | gitlab-ci: remove redundant GitLab repo URL command |
39 | block/dmg.c | 6 +- | 57 | docs: update README to use GitLab repo URLs |
40 | block/rbd.c | 65 +++-- | 58 | pc-bios: update mirror URLs to GitLab |
41 | block/trace-events | 17 ++ | 59 | get_maintainer: update repo URL to GitLab |
42 | block/vvfat.c | 19 +- | 60 | |
43 | block/vxhs.c | 575 +++++++++++++++++++++++++++++++++++++++ | 61 | MAINTAINERS | 24 + |
44 | configure | 39 +++ | 62 | README.rst | 4 +- |
45 | include/block/block.h | 2 + | 63 | docs/devel/index.rst | 1 + |
46 | qapi/block-core.json | 23 +- | 64 | docs/devel/multi-process.rst | 966 ++++++++++++++++++++++ |
47 | tests/qemu-iotests/017 | 1 + | 65 | docs/system/index.rst | 1 + |
48 | tests/qemu-iotests/020 | 1 + | 66 | docs/system/multi-process.rst | 64 ++ |
49 | tests/qemu-iotests/028 | 1 + | 67 | docs/interop/parallels.txt | 2 +- |
50 | tests/qemu-iotests/029 | 1 + | 68 | configure | 10 + |
51 | tests/qemu-iotests/073 | 1 + | 69 | meson.build | 5 +- |
52 | tests/qemu-iotests/094 | 11 +- | 70 | hw/remote/trace.h | 1 + |
53 | tests/qemu-iotests/102 | 5 +- | 71 | include/exec/memory.h | 2 + |
54 | tests/qemu-iotests/109 | 1 + | 72 | include/exec/ram_addr.h | 2 +- |
55 | tests/qemu-iotests/114 | 1 + | 73 | include/hw/pci-host/remote.h | 30 + |
56 | tests/qemu-iotests/117 | 1 + | 74 | include/hw/pci/pci_ids.h | 3 + |
57 | tests/qemu-iotests/130 | 2 + | 75 | include/hw/remote/iohub.h | 42 + |
58 | tests/qemu-iotests/134 | 1 + | 76 | include/hw/remote/machine.h | 38 + |
59 | tests/qemu-iotests/140 | 1 + | 77 | include/hw/remote/memory.h | 19 + |
60 | tests/qemu-iotests/141 | 1 + | 78 | include/hw/remote/mpqemu-link.h | 99 +++ |
61 | tests/qemu-iotests/143 | 1 + | 79 | include/hw/remote/proxy-memory-listener.h | 28 + |
62 | tests/qemu-iotests/156 | 2 + | 80 | include/hw/remote/proxy.h | 48 ++ |
63 | tests/qemu-iotests/158 | 1 + | 81 | include/io/channel.h | 78 ++ |
64 | tests/qemu-iotests/common | 6 + | 82 | include/qemu/mmap-alloc.h | 4 +- |
65 | tests/qemu-iotests/common.config | 13 + | 83 | include/sysemu/iothread.h | 6 + |
66 | tests/qemu-iotests/common.filter | 1 + | 84 | backends/hostmem-memfd.c | 2 +- |
67 | tests/qemu-iotests/common.rc | 19 ++ | 85 | hw/misc/ivshmem.c | 3 +- |
68 | 33 files changed, 844 insertions(+), 42 deletions(-) | 86 | hw/pci-host/remote.c | 75 ++ |
69 | create mode 100644 block/vxhs.c | 87 | hw/remote/iohub.c | 119 +++ |
88 | hw/remote/machine.c | 80 ++ | ||
89 | hw/remote/memory.c | 65 ++ | ||
90 | hw/remote/message.c | 230 ++++++ | ||
91 | hw/remote/mpqemu-link.c | 267 ++++++ | ||
92 | hw/remote/proxy-memory-listener.c | 227 +++++ | ||
93 | hw/remote/proxy.c | 379 +++++++++ | ||
94 | hw/remote/remote-obj.c | 203 +++++ | ||
95 | io/channel.c | 116 ++- | ||
96 | iothread.c | 6 + | ||
97 | softmmu/memory.c | 3 +- | ||
98 | softmmu/physmem.c | 11 +- | ||
99 | util/mmap-alloc.c | 7 +- | ||
100 | util/oslib-posix.c | 2 +- | ||
101 | .github/lockdown.yml | 8 +- | ||
102 | .gitlab-ci.yml | 1 - | ||
103 | .gitmodules | 44 +- | ||
104 | Kconfig.host | 4 + | ||
105 | hw/Kconfig | 1 + | ||
106 | hw/meson.build | 1 + | ||
107 | hw/pci-host/Kconfig | 3 + | ||
108 | hw/pci-host/meson.build | 1 + | ||
109 | hw/remote/Kconfig | 4 + | ||
110 | hw/remote/meson.build | 13 + | ||
111 | hw/remote/trace-events | 4 + | ||
112 | pc-bios/README | 4 +- | ||
113 | scripts/get_maintainer.pl | 2 +- | ||
114 | 53 files changed, 3294 insertions(+), 68 deletions(-) | ||
115 | create mode 100644 docs/devel/multi-process.rst | ||
116 | create mode 100644 docs/system/multi-process.rst | ||
117 | create mode 100644 hw/remote/trace.h | ||
118 | create mode 100644 include/hw/pci-host/remote.h | ||
119 | create mode 100644 include/hw/remote/iohub.h | ||
120 | create mode 100644 include/hw/remote/machine.h | ||
121 | create mode 100644 include/hw/remote/memory.h | ||
122 | create mode 100644 include/hw/remote/mpqemu-link.h | ||
123 | create mode 100644 include/hw/remote/proxy-memory-listener.h | ||
124 | create mode 100644 include/hw/remote/proxy.h | ||
125 | create mode 100644 hw/pci-host/remote.c | ||
126 | create mode 100644 hw/remote/iohub.c | ||
127 | create mode 100644 hw/remote/machine.c | ||
128 | create mode 100644 hw/remote/memory.c | ||
129 | create mode 100644 hw/remote/message.c | ||
130 | create mode 100644 hw/remote/mpqemu-link.c | ||
131 | create mode 100644 hw/remote/proxy-memory-listener.c | ||
132 | create mode 100644 hw/remote/proxy.c | ||
133 | create mode 100644 hw/remote/remote-obj.c | ||
134 | create mode 100644 hw/remote/Kconfig | ||
135 | create mode 100644 hw/remote/meson.build | ||
136 | create mode 100644 hw/remote/trace-events | ||
70 | 137 | ||
71 | -- | 138 | -- |
72 | 2.9.3 | 139 | 2.29.2 |
73 | 140 | ||
74 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Use the GitLab repo URL as the main repo location in order to reduce | ||
2 | load on qemu.org. | ||
1 | 3 | ||
4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
5 | Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> | ||
6 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
7 | Message-id: 20210111115017.156802-2-stefanha@redhat.com | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | ||
10 | .github/lockdown.yml | 8 ++++---- | ||
11 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
12 | |||
13 | diff --git a/.github/lockdown.yml b/.github/lockdown.yml | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/.github/lockdown.yml | ||
16 | +++ b/.github/lockdown.yml | ||
17 | @@ -XXX,XX +XXX,XX @@ issues: | ||
18 | comment: | | ||
19 | Thank you for your interest in the QEMU project. | ||
20 | |||
21 | - This repository is a read-only mirror of the project's master | ||
22 | - repostories hosted on https://git.qemu.org/git/qemu.git. | ||
23 | + This repository is a read-only mirror of the project's repostories hosted | ||
24 | + at https://gitlab.com/qemu-project/qemu.git. | ||
25 | The project does not process issues filed on GitHub. | ||
26 | |||
27 | The project issues are tracked on Launchpad: | ||
28 | @@ -XXX,XX +XXX,XX @@ pulls: | ||
29 | comment: | | ||
30 | Thank you for your interest in the QEMU project. | ||
31 | |||
32 | - This repository is a read-only mirror of the project's master | ||
33 | - repostories hosted on https://git.qemu.org/git/qemu.git. | ||
34 | + This repository is a read-only mirror of the project's repostories hosted | ||
35 | + on https://gitlab.com/qemu-project/qemu.git. | ||
36 | The project does not process merge requests filed on GitHub. | ||
37 | |||
38 | QEMU welcomes contributions of code (either fixing bugs or adding new | ||
39 | -- | ||
40 | 2.29.2 | ||
41 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | qemu.org is running out of bandwidth and the QEMU project is moving | ||
2 | towards a gating CI on GitLab. Use the GitLab repos instead of qemu.org | ||
3 | (they will become mirrors). | ||
1 | 4 | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> | ||
7 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
9 | Message-id: 20210111115017.156802-3-stefanha@redhat.com | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | --- | ||
12 | .gitmodules | 44 ++++++++++++++++++++++---------------------- | ||
13 | 1 file changed, 22 insertions(+), 22 deletions(-) | ||
14 | |||
15 | diff --git a/.gitmodules b/.gitmodules | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/.gitmodules | ||
18 | +++ b/.gitmodules | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | [submodule "roms/seabios"] | ||
21 | path = roms/seabios | ||
22 | - url = https://git.qemu.org/git/seabios.git/ | ||
23 | + url = https://gitlab.com/qemu-project/seabios.git/ | ||
24 | [submodule "roms/SLOF"] | ||
25 | path = roms/SLOF | ||
26 | - url = https://git.qemu.org/git/SLOF.git | ||
27 | + url = https://gitlab.com/qemu-project/SLOF.git | ||
28 | [submodule "roms/ipxe"] | ||
29 | path = roms/ipxe | ||
30 | - url = https://git.qemu.org/git/ipxe.git | ||
31 | + url = https://gitlab.com/qemu-project/ipxe.git | ||
32 | [submodule "roms/openbios"] | ||
33 | path = roms/openbios | ||
34 | - url = https://git.qemu.org/git/openbios.git | ||
35 | + url = https://gitlab.com/qemu-project/openbios.git | ||
36 | [submodule "roms/qemu-palcode"] | ||
37 | path = roms/qemu-palcode | ||
38 | - url = https://git.qemu.org/git/qemu-palcode.git | ||
39 | + url = https://gitlab.com/qemu-project/qemu-palcode.git | ||
40 | [submodule "roms/sgabios"] | ||
41 | path = roms/sgabios | ||
42 | - url = https://git.qemu.org/git/sgabios.git | ||
43 | + url = https://gitlab.com/qemu-project/sgabios.git | ||
44 | [submodule "dtc"] | ||
45 | path = dtc | ||
46 | - url = https://git.qemu.org/git/dtc.git | ||
47 | + url = https://gitlab.com/qemu-project/dtc.git | ||
48 | [submodule "roms/u-boot"] | ||
49 | path = roms/u-boot | ||
50 | - url = https://git.qemu.org/git/u-boot.git | ||
51 | + url = https://gitlab.com/qemu-project/u-boot.git | ||
52 | [submodule "roms/skiboot"] | ||
53 | path = roms/skiboot | ||
54 | - url = https://git.qemu.org/git/skiboot.git | ||
55 | + url = https://gitlab.com/qemu-project/skiboot.git | ||
56 | [submodule "roms/QemuMacDrivers"] | ||
57 | path = roms/QemuMacDrivers | ||
58 | - url = https://git.qemu.org/git/QemuMacDrivers.git | ||
59 | + url = https://gitlab.com/qemu-project/QemuMacDrivers.git | ||
60 | [submodule "ui/keycodemapdb"] | ||
61 | path = ui/keycodemapdb | ||
62 | - url = https://git.qemu.org/git/keycodemapdb.git | ||
63 | + url = https://gitlab.com/qemu-project/keycodemapdb.git | ||
64 | [submodule "capstone"] | ||
65 | path = capstone | ||
66 | - url = https://git.qemu.org/git/capstone.git | ||
67 | + url = https://gitlab.com/qemu-project/capstone.git | ||
68 | [submodule "roms/seabios-hppa"] | ||
69 | path = roms/seabios-hppa | ||
70 | - url = https://git.qemu.org/git/seabios-hppa.git | ||
71 | + url = https://gitlab.com/qemu-project/seabios-hppa.git | ||
72 | [submodule "roms/u-boot-sam460ex"] | ||
73 | path = roms/u-boot-sam460ex | ||
74 | - url = https://git.qemu.org/git/u-boot-sam460ex.git | ||
75 | + url = https://gitlab.com/qemu-project/u-boot-sam460ex.git | ||
76 | [submodule "tests/fp/berkeley-testfloat-3"] | ||
77 | path = tests/fp/berkeley-testfloat-3 | ||
78 | - url = https://git.qemu.org/git/berkeley-testfloat-3.git | ||
79 | + url = https://gitlab.com/qemu-project/berkeley-testfloat-3.git | ||
80 | [submodule "tests/fp/berkeley-softfloat-3"] | ||
81 | path = tests/fp/berkeley-softfloat-3 | ||
82 | - url = https://git.qemu.org/git/berkeley-softfloat-3.git | ||
83 | + url = https://gitlab.com/qemu-project/berkeley-softfloat-3.git | ||
84 | [submodule "roms/edk2"] | ||
85 | path = roms/edk2 | ||
86 | - url = https://git.qemu.org/git/edk2.git | ||
87 | + url = https://gitlab.com/qemu-project/edk2.git | ||
88 | [submodule "slirp"] | ||
89 | path = slirp | ||
90 | - url = https://git.qemu.org/git/libslirp.git | ||
91 | + url = https://gitlab.com/qemu-project/libslirp.git | ||
92 | [submodule "roms/opensbi"] | ||
93 | path = roms/opensbi | ||
94 | - url = https://git.qemu.org/git/opensbi.git | ||
95 | + url = https://gitlab.com/qemu-project/opensbi.git | ||
96 | [submodule "roms/qboot"] | ||
97 | path = roms/qboot | ||
98 | - url = https://git.qemu.org/git/qboot.git | ||
99 | + url = https://gitlab.com/qemu-project/qboot.git | ||
100 | [submodule "meson"] | ||
101 | path = meson | ||
102 | - url = https://git.qemu.org/git/meson.git | ||
103 | + url = https://gitlab.com/qemu-project/meson.git | ||
104 | [submodule "roms/vbootrom"] | ||
105 | path = roms/vbootrom | ||
106 | - url = https://git.qemu.org/git/vbootrom.git | ||
107 | + url = https://gitlab.com/qemu-project/vbootrom.git | ||
108 | -- | ||
109 | 2.29.2 | ||
110 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | It is no longer necessary to point .gitmodules at GitLab repos when | ||
2 | running in GitLab CI since they are now used all the time. | ||
1 | 3 | ||
4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
5 | Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> | ||
6 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Message-id: 20210111115017.156802-4-stefanha@redhat.com | ||
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | --- | ||
11 | .gitlab-ci.yml | 1 - | ||
12 | 1 file changed, 1 deletion(-) | ||
13 | |||
14 | diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/.gitlab-ci.yml | ||
17 | +++ b/.gitlab-ci.yml | ||
18 | @@ -XXX,XX +XXX,XX @@ include: | ||
19 | image: $CI_REGISTRY_IMAGE/qemu/$IMAGE:latest | ||
20 | before_script: | ||
21 | - JOBS=$(expr $(nproc) + 1) | ||
22 | - - sed -i s,git.qemu.org/git,gitlab.com/qemu-project, .gitmodules | ||
23 | script: | ||
24 | - mkdir build | ||
25 | - cd build | ||
26 | -- | ||
27 | 2.29.2 | ||
28 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | qemu.org is running out of bandwidth and the QEMU project is moving | ||
2 | towards a gating CI on GitLab. Use the GitLab repos instead of qemu.org | ||
3 | (they will become mirrors). | ||
1 | 4 | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> | ||
7 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
9 | Message-id: 20210111115017.156802-5-stefanha@redhat.com | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | --- | ||
12 | README.rst | 4 ++-- | ||
13 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
14 | |||
15 | diff --git a/README.rst b/README.rst | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/README.rst | ||
18 | +++ b/README.rst | ||
19 | @@ -XXX,XX +XXX,XX @@ The QEMU source code is maintained under the GIT version control system. | ||
20 | |||
21 | .. code-block:: shell | ||
22 | |||
23 | - git clone https://git.qemu.org/git/qemu.git | ||
24 | + git clone https://gitlab.com/qemu-project/qemu.git | ||
25 | |||
26 | When submitting patches, one common approach is to use 'git | ||
27 | format-patch' and/or 'git send-email' to format & send the mail to the | ||
28 | @@ -XXX,XX +XXX,XX @@ The QEMU website is also maintained under source control. | ||
29 | |||
30 | .. code-block:: shell | ||
31 | |||
32 | - git clone https://git.qemu.org/git/qemu-web.git | ||
33 | + git clone https://gitlab.com/qemu-project/qemu-web.git | ||
34 | |||
35 | * `<https://www.qemu.org/2017/02/04/the-new-qemu-website-is-up/>`_ | ||
36 | |||
37 | -- | ||
38 | 2.29.2 | ||
39 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | qemu.org is running out of bandwidth and the QEMU project is moving | ||
2 | towards a gating CI on GitLab. Use the GitLab repos instead of qemu.org | ||
3 | (they will become mirrors). | ||
1 | 4 | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> | ||
7 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
9 | Message-id: 20210111115017.156802-6-stefanha@redhat.com | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | --- | ||
12 | pc-bios/README | 4 ++-- | ||
13 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
14 | |||
15 | diff --git a/pc-bios/README b/pc-bios/README | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/pc-bios/README | ||
18 | +++ b/pc-bios/README | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | legacy x86 software to communicate with an attached serial console as | ||
21 | if a video card were attached. The master sources reside in a subversion | ||
22 | repository at http://sgabios.googlecode.com/svn/trunk. A git mirror is | ||
23 | - available at https://git.qemu.org/git/sgabios.git. | ||
24 | + available at https://gitlab.com/qemu-project/sgabios.git. | ||
25 | |||
26 | - The PXE roms come from the iPXE project. Built with BANNER_TIME 0. | ||
27 | Sources available at http://ipxe.org. Vendor:Device ID -> ROM mapping: | ||
28 | @@ -XXX,XX +XXX,XX @@ | ||
29 | |||
30 | - The u-boot binary for e500 comes from the upstream denx u-boot project where | ||
31 | it was compiled using the qemu-ppce500 target. | ||
32 | - A git mirror is available at: https://git.qemu.org/git/u-boot.git | ||
33 | + A git mirror is available at: https://gitlab.com/qemu-project/u-boot.git | ||
34 | The hash used to compile the current version is: 2072e72 | ||
35 | |||
36 | - Skiboot (https://github.com/open-power/skiboot/) is an OPAL | ||
37 | -- | ||
38 | 2.29.2 | ||
39 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | qemu.org is running out of bandwidth and the QEMU project is moving | ||
2 | towards a gating CI on GitLab. Use the GitLab repos instead of qemu.org | ||
3 | (they will become mirrors). | ||
1 | 4 | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> | ||
7 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
9 | Message-id: 20210111115017.156802-7-stefanha@redhat.com | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | --- | ||
12 | scripts/get_maintainer.pl | 2 +- | ||
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl | ||
16 | index XXXXXXX..XXXXXXX 100755 | ||
17 | --- a/scripts/get_maintainer.pl | ||
18 | +++ b/scripts/get_maintainer.pl | ||
19 | @@ -XXX,XX +XXX,XX @@ sub vcs_exists { | ||
20 | warn("$P: No supported VCS found. Add --nogit to options?\n"); | ||
21 | warn("Using a git repository produces better results.\n"); | ||
22 | warn("Try latest git repository using:\n"); | ||
23 | - warn("git clone https://git.qemu.org/git/qemu.git\n"); | ||
24 | + warn("git clone https://gitlab.com/qemu-project/qemu.git\n"); | ||
25 | $printed_novcs = 1; | ||
26 | } | ||
27 | return 0; | ||
28 | -- | ||
29 | 2.29.2 | ||
30 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John G Johnson <john.g.johnson@oracle.com> | ||
1 | 2 | ||
3 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
4 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
5 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | Message-id: 02a68adef99f5df6a380bf8fd7b90948777e411c.1611938319.git.jag.raman@oracle.com | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | ||
10 | MAINTAINERS | 7 + | ||
11 | docs/devel/index.rst | 1 + | ||
12 | docs/devel/multi-process.rst | 966 +++++++++++++++++++++++++++++++++++ | ||
13 | 3 files changed, 974 insertions(+) | ||
14 | create mode 100644 docs/devel/multi-process.rst | ||
15 | |||
16 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/MAINTAINERS | ||
19 | +++ b/MAINTAINERS | ||
20 | @@ -XXX,XX +XXX,XX @@ S: Maintained | ||
21 | F: hw/semihosting/ | ||
22 | F: include/hw/semihosting/ | ||
23 | |||
24 | +Multi-process QEMU | ||
25 | +M: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
26 | +M: Jagannathan Raman <jag.raman@oracle.com> | ||
27 | +M: John G Johnson <john.g.johnson@oracle.com> | ||
28 | +S: Maintained | ||
29 | +F: docs/devel/multi-process.rst | ||
30 | + | ||
31 | Build and test automation | ||
32 | ------------------------- | ||
33 | Build and test automation | ||
34 | diff --git a/docs/devel/index.rst b/docs/devel/index.rst | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/docs/devel/index.rst | ||
37 | +++ b/docs/devel/index.rst | ||
38 | @@ -XXX,XX +XXX,XX @@ Contents: | ||
39 | clocks | ||
40 | qom | ||
41 | block-coroutine-wrapper | ||
42 | + multi-process | ||
43 | diff --git a/docs/devel/multi-process.rst b/docs/devel/multi-process.rst | ||
44 | new file mode 100644 | ||
45 | index XXXXXXX..XXXXXXX | ||
46 | --- /dev/null | ||
47 | +++ b/docs/devel/multi-process.rst | ||
48 | @@ -XXX,XX +XXX,XX @@ | ||
49 | +This is the design document for multi-process QEMU. It does not | ||
50 | +necessarily reflect the status of the current implementation, which | ||
51 | +may lack features or be considerably different from what is described | ||
52 | +in this document. This document is still useful as a description of | ||
53 | +the goals and general direction of this feature. | ||
54 | + | ||
55 | +Please refer to the following wiki for latest details: | ||
56 | +https://wiki.qemu.org/Features/MultiProcessQEMU | ||
57 | + | ||
58 | +Multi-process QEMU | ||
59 | +=================== | ||
60 | + | ||
61 | +QEMU is often used as the hypervisor for virtual machines running in the | ||
62 | +Oracle cloud. Since one of the advantages of cloud computing is the | ||
63 | +ability to run many VMs from different tenants in the same cloud | ||
64 | +infrastructure, a guest that compromised its hypervisor could | ||
65 | +potentially use the hypervisor's access privileges to access data it is | ||
66 | +not authorized for. | ||
67 | + | ||
68 | +QEMU can be susceptible to security attacks because it is a large, | ||
69 | +monolithic program that provides many features to the VMs it services. | ||
70 | +Many of these features can be configured out of QEMU, but even a reduced | ||
71 | +configuration QEMU has a large amount of code a guest can potentially | ||
72 | +attack. Separating QEMU reduces the attack surface by aiding to | ||
73 | +limit each component in the system to only access the resources that | ||
74 | +it needs to perform its job. | ||
75 | + | ||
76 | +QEMU services | ||
77 | +------------- | ||
78 | + | ||
79 | +QEMU can be broadly described as providing three main services. One is a | ||
80 | +VM control point, where VMs can be created, migrated, re-configured, and | ||
81 | +destroyed. A second is to emulate the CPU instructions within the VM, | ||
82 | +often accelerated by HW virtualization features such as Intel's VT | ||
83 | +extensions. Finally, it provides IO services to the VM by emulating HW | ||
84 | +IO devices, such as disk and network devices. | ||
85 | + | ||
86 | +A multi-process QEMU | ||
87 | +~~~~~~~~~~~~~~~~~~~~ | ||
88 | + | ||
89 | +A multi-process QEMU involves separating QEMU services into separate | ||
90 | +host processes. Each of these processes can be given only the privileges | ||
91 | +it needs to provide its service, e.g., a disk service could be given | ||
92 | +access only to the disk images it provides, and not be allowed to | ||
93 | +access other files, or any network devices. An attacker who compromised | ||
94 | +this service would not be able to use this exploit to access files or | ||
95 | +devices beyond what the disk service was given access to. | ||
96 | + | ||
97 | +A QEMU control process would remain, but in multi-process mode, will | ||
98 | +have no direct interfaces to the VM. During VM execution, it would still | ||
99 | +provide the user interface to hot-plug devices or live migrate the VM. | ||
100 | + | ||
101 | +A first step in creating a multi-process QEMU is to separate IO services | ||
102 | +from the main QEMU program, which would continue to provide CPU | ||
103 | +emulation. i.e., the control process would also be the CPU emulation | ||
104 | +process. In a later phase, CPU emulation could be separated from the | ||
105 | +control process. | ||
106 | + | ||
107 | +Separating IO services | ||
108 | +---------------------- | ||
109 | + | ||
110 | +Separating IO services into individual host processes is a good place to | ||
111 | +begin for a couple of reasons. One is the sheer number of IO devices QEMU | ||
112 | +can emulate provides a large surface of interfaces which could potentially | ||
113 | +be exploited, and, indeed, have been a source of exploits in the past. | ||
114 | +Another is the modular nature of QEMU device emulation code provides | ||
115 | +interface points where the QEMU functions that perform device emulation | ||
116 | +can be separated from the QEMU functions that manage the emulation of | ||
117 | +guest CPU instructions. The devices emulated in the separate process are | ||
118 | +referred to as remote devices. | ||
119 | + | ||
120 | +QEMU device emulation | ||
121 | +~~~~~~~~~~~~~~~~~~~~~ | ||
122 | + | ||
123 | +QEMU uses an object oriented SW architecture for device emulation code. | ||
124 | +Configured objects are all compiled into the QEMU binary, then objects | ||
125 | +are instantiated by name when used by the guest VM. For example, the | ||
126 | +code to emulate a device named "foo" is always present in QEMU, but its | ||
127 | +instantiation code is only run when the device is included in the target | ||
128 | +VM. (e.g., via the QEMU command line as *-device foo*) | ||
129 | + | ||
130 | +The object model is hierarchical, so device emulation code names its | ||
131 | +parent object (such as "pci-device" for a PCI device) and QEMU will | ||
132 | +instantiate a parent object before calling the device's instantiation | ||
133 | +code. | ||
134 | + | ||
135 | +Current separation models | ||
136 | +~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
137 | + | ||
138 | +In order to separate the device emulation code from the CPU emulation | ||
139 | +code, the device object code must run in a different process. There are | ||
140 | +a couple of existing QEMU features that can run emulation code | ||
141 | +separately from the main QEMU process. These are examined below. | ||
142 | + | ||
143 | +vhost user model | ||
144 | +^^^^^^^^^^^^^^^^ | ||
145 | + | ||
146 | +Virtio guest device drivers can be connected to vhost user applications | ||
147 | +in order to perform their IO operations. This model uses special virtio | ||
148 | +device drivers in the guest and vhost user device objects in QEMU, but | ||
149 | +once the QEMU vhost user code has configured the vhost user application, | ||
150 | +mission-mode IO is performed by the application. The vhost user | ||
151 | +application is a daemon process that can be contacted via a known UNIX | ||
152 | +domain socket. | ||
153 | + | ||
154 | +vhost socket | ||
155 | +'''''''''''' | ||
156 | + | ||
157 | +As mentioned above, one of the tasks of the vhost device object within | ||
158 | +QEMU is to contact the vhost application and send it configuration | ||
159 | +information about this device instance. As part of the configuration | ||
160 | +process, the application can also be sent other file descriptors over | ||
161 | +the socket, which then can be used by the vhost user application in | ||
162 | +various ways, some of which are described below. | ||
163 | + | ||
164 | +vhost MMIO store acceleration | ||
165 | +''''''''''''''''''''''''''''' | ||
166 | + | ||
167 | +VMs are often run using HW virtualization features via the KVM kernel | ||
168 | +driver. This driver allows QEMU to accelerate the emulation of guest CPU | ||
169 | +instructions by running the guest in a virtual HW mode. When the guest | ||
170 | +executes instructions that cannot be executed by virtual HW mode, | ||
171 | +execution returns to the KVM driver so it can inform QEMU to emulate the | ||
172 | +instructions in SW. | ||
173 | + | ||
174 | +One of the events that can cause a return to QEMU is when a guest device | ||
175 | +driver accesses an IO location. QEMU then dispatches the memory | ||
176 | +operation to the corresponding QEMU device object. In the case of a | ||
177 | +vhost user device, the memory operation would need to be sent over a | ||
178 | +socket to the vhost application. This path is accelerated by the QEMU | ||
179 | +virtio code by setting up an eventfd file descriptor that the vhost | ||
180 | +application can directly receive MMIO store notifications from the KVM | ||
181 | +driver, instead of needing them to be sent to the QEMU process first. | ||
182 | + | ||
183 | +vhost interrupt acceleration | ||
184 | +'''''''''''''''''''''''''''' | ||
185 | + | ||
186 | +Another optimization used by the vhost application is the ability to | ||
187 | +directly inject interrupts into the VM via the KVM driver, again, | ||
188 | +bypassing the need to send the interrupt back to the QEMU process first. | ||
189 | +The QEMU virtio setup code configures the KVM driver with an eventfd | ||
190 | +that triggers the device interrupt in the guest when the eventfd is | ||
191 | +written. This irqfd file descriptor is then passed to the vhost user | ||
192 | +application program. | ||
193 | + | ||
194 | +vhost access to guest memory | ||
195 | +'''''''''''''''''''''''''''' | ||
196 | + | ||
197 | +The vhost application is also allowed to directly access guest memory, | ||
198 | +instead of needing to send the data as messages to QEMU. This is also | ||
199 | +done with file descriptors sent to the vhost user application by QEMU. | ||
200 | +These descriptors can be passed to ``mmap()`` by the vhost application | ||
201 | +to map the guest address space into the vhost application. | ||
202 | + | ||
203 | +IOMMUs introduce another level of complexity, since the address given to | ||
204 | +the guest virtio device to DMA to or from is not a guest physical | ||
205 | +address. This case is handled by having vhost code within QEMU register | ||
206 | +as a listener for IOMMU mapping changes. The vhost application maintains | ||
207 | +a cache of IOMMMU translations: sending translation requests back to | ||
208 | +QEMU on cache misses, and in turn receiving flush requests from QEMU | ||
209 | +when mappings are purged. | ||
210 | + | ||
211 | +applicability to device separation | ||
212 | +'''''''''''''''''''''''''''''''''' | ||
213 | + | ||
214 | +Much of the vhost model can be re-used by separated device emulation. In | ||
215 | +particular, the ideas of using a socket between QEMU and the device | ||
216 | +emulation application, using a file descriptor to inject interrupts into | ||
217 | +the VM via KVM, and allowing the application to ``mmap()`` the guest | ||
218 | +should be re used. | ||
219 | + | ||
220 | +There are, however, some notable differences between how a vhost | ||
221 | +application works and the needs of separated device emulation. The most | ||
222 | +basic is that vhost uses custom virtio device drivers which always | ||
223 | +trigger IO with MMIO stores. A separated device emulation model must | ||
224 | +work with existing IO device models and guest device drivers. MMIO loads | ||
225 | +break vhost store acceleration since they are synchronous - guest | ||
226 | +progress cannot continue until the load has been emulated. By contrast, | ||
227 | +stores are asynchronous, the guest can continue after the store event | ||
228 | +has been sent to the vhost application. | ||
229 | + | ||
230 | +Another difference is that in the vhost user model, a single daemon can | ||
231 | +support multiple QEMU instances. This is contrary to the security regime | ||
232 | +desired, in which the emulation application should only be allowed to | ||
233 | +access the files or devices the VM it's running on behalf of can access. | ||
234 | +#### qemu-io model | ||
235 | + | ||
236 | +Qemu-io is a test harness used to test changes to the QEMU block backend | ||
237 | +object code. (e.g., the code that implements disk images for disk driver | ||
238 | +emulation) Qemu-io is not a device emulation application per se, but it | ||
239 | +does compile the QEMU block objects into a separate binary from the main | ||
240 | +QEMU one. This could be useful for disk device emulation, since its | ||
241 | +emulation applications will need to include the QEMU block objects. | ||
242 | + | ||
243 | +New separation model based on proxy objects | ||
244 | +------------------------------------------- | ||
245 | + | ||
246 | +A different model based on proxy objects in the QEMU program | ||
247 | +communicating with remote emulation programs could provide separation | ||
248 | +while minimizing the changes needed to the device emulation code. The | ||
249 | +rest of this section is a discussion of how a proxy object model would | ||
250 | +work. | ||
251 | + | ||
252 | +Remote emulation processes | ||
253 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
254 | + | ||
255 | +The remote emulation process will run the QEMU object hierarchy without | ||
256 | +modification. The device emulation objects will be also be based on the | ||
257 | +QEMU code, because for anything but the simplest device, it would not be | ||
258 | +a tractable to re-implement both the object model and the many device | ||
259 | +backends that QEMU has. | ||
260 | + | ||
261 | +The processes will communicate with the QEMU process over UNIX domain | ||
262 | +sockets. The processes can be executed either as standalone processes, | ||
263 | +or be executed by QEMU. In both cases, the host backends the emulation | ||
264 | +processes will provide are specified on its command line, as they would | ||
265 | +be for QEMU. For example: | ||
266 | + | ||
267 | +:: | ||
268 | + | ||
269 | + disk-proc -blockdev driver=file,node-name=file0,filename=disk-file0 \ | ||
270 | + -blockdev driver=qcow2,node-name=drive0,file=file0 | ||
271 | + | ||
272 | +would indicate process *disk-proc* uses a qcow2 emulated disk named | ||
273 | +*file0* as its backend. | ||
274 | + | ||
275 | +Emulation processes may emulate more than one guest controller. A common | ||
276 | +configuration might be to put all controllers of the same device class | ||
277 | +(e.g., disk, network, etc.) in a single process, so that all backends of | ||
278 | +the same type can be managed by a single QMP monitor. | ||
279 | + | ||
280 | +communication with QEMU | ||
281 | +^^^^^^^^^^^^^^^^^^^^^^^ | ||
282 | + | ||
283 | +The first argument to the remote emulation process will be a Unix domain | ||
284 | +socket that connects with the Proxy object. This is a required argument. | ||
285 | + | ||
286 | +:: | ||
287 | + | ||
288 | + disk-proc <socket number> <backend list> | ||
289 | + | ||
290 | +remote process QMP monitor | ||
291 | +^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
292 | + | ||
293 | +Remote emulation processes can be monitored via QMP, similar to QEMU | ||
294 | +itself. The QMP monitor socket is specified the same as for a QEMU | ||
295 | +process: | ||
296 | + | ||
297 | +:: | ||
298 | + | ||
299 | + disk-proc -qmp unix:/tmp/disk-mon,server | ||
300 | + | ||
301 | +can be monitored over the UNIX socket path */tmp/disk-mon*. | ||
302 | + | ||
303 | +QEMU command line | ||
304 | +~~~~~~~~~~~~~~~~~ | ||
305 | + | ||
306 | +Each remote device emulated in a remote process on the host is | ||
307 | +represented as a *-device* of type *pci-proxy-dev*. A socket | ||
308 | +sub-option to this option specifies the Unix socket that connects | ||
309 | +to the remote process. An *id* sub-option is required, and it should | ||
310 | +be the same id as used in the remote process. | ||
311 | + | ||
312 | +:: | ||
313 | + | ||
314 | + qemu-system-x86_64 ... -device pci-proxy-dev,id=lsi0,socket=3 | ||
315 | + | ||
316 | +can be used to add a device emulated in a remote process | ||
317 | + | ||
318 | + | ||
319 | +QEMU management of remote processes | ||
320 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
321 | + | ||
322 | +QEMU is not aware of the type of type of the remote PCI device. It is | ||
323 | +a pass through device as far as QEMU is concerned. | ||
324 | + | ||
325 | +communication with emulation process | ||
326 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
327 | + | ||
328 | +primary channel | ||
329 | +''''''''''''''' | ||
330 | + | ||
331 | +The primary channel (referred to as com in the code) is used to bootstrap | ||
332 | +the remote process. It is also used to pass on device-agnostic commands | ||
333 | +like reset. | ||
334 | + | ||
335 | +per-device channels | ||
336 | +''''''''''''''''''' | ||
337 | + | ||
338 | +Each remote device communicates with QEMU using a dedicated communication | ||
339 | +channel. The proxy object sets up this channel using the primary | ||
340 | +channel during its initialization. | ||
341 | + | ||
342 | +QEMU device proxy objects | ||
343 | +~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
344 | + | ||
345 | +QEMU has an object model based on sub-classes inherited from the | ||
346 | +"object" super-class. The sub-classes that are of interest here are the | ||
347 | +"device" and "bus" sub-classes whose child sub-classes make up the | ||
348 | +device tree of a QEMU emulated system. | ||
349 | + | ||
350 | +The proxy object model will use device proxy objects to replace the | ||
351 | +device emulation code within the QEMU process. These objects will live | ||
352 | +in the same place in the object and bus hierarchies as the objects they | ||
353 | +replace. i.e., the proxy object for an LSI SCSI controller will be a | ||
354 | +sub-class of the "pci-device" class, and will have the same PCI bus | ||
355 | +parent and the same SCSI bus child objects as the LSI controller object | ||
356 | +it replaces. | ||
357 | + | ||
358 | +It is worth noting that the same proxy object is used to mediate with | ||
359 | +all types of remote PCI devices. | ||
360 | + | ||
361 | +object initialization | ||
362 | +^^^^^^^^^^^^^^^^^^^^^ | ||
363 | + | ||
364 | +The Proxy device objects are initialized in the exact same manner in | ||
365 | +which any other QEMU device would be initialized. | ||
366 | + | ||
367 | +In addition, the Proxy objects perform the following two tasks: | ||
368 | +- Parses the "socket" sub option and connects to the remote process | ||
369 | +using this channel | ||
370 | +- Uses the "id" sub-option to connect to the emulated device on the | ||
371 | +separate process | ||
372 | + | ||
373 | +class\_init | ||
374 | +''''''''''' | ||
375 | + | ||
376 | +The ``class_init()`` method of a proxy object will, in general behave | ||
377 | +similarly to the object it replaces, including setting any static | ||
378 | +properties and methods needed by the proxy. | ||
379 | + | ||
380 | +instance\_init / realize | ||
381 | +'''''''''''''''''''''''' | ||
382 | + | ||
383 | +The ``instance_init()`` and ``realize()`` functions would only need to | ||
384 | +perform tasks related to being a proxy, such are registering its own | ||
385 | +MMIO handlers, or creating a child bus that other proxy devices can be | ||
386 | +attached to later. | ||
387 | + | ||
388 | +Other tasks will be device-specific. For example, PCI device objects | ||
389 | +will initialize the PCI config space in order to make a valid PCI device | ||
390 | +tree within the QEMU process. | ||
391 | + | ||
392 | +address space registration | ||
393 | +^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
394 | + | ||
395 | +Most devices are driven by guest device driver accesses to IO addresses | ||
396 | +or ports. The QEMU device emulation code uses QEMU's memory region | ||
397 | +function calls (such as ``memory_region_init_io()``) to add callback | ||
398 | +functions that QEMU will invoke when the guest accesses the device's | ||
399 | +areas of the IO address space. When a guest driver does access the | ||
400 | +device, the VM will exit HW virtualization mode and return to QEMU, | ||
401 | +which will then lookup and execute the corresponding callback function. | ||
402 | + | ||
403 | +A proxy object would need to mirror the memory region calls the actual | ||
404 | +device emulator would perform in its initialization code, but with its | ||
405 | +own callbacks. When invoked by QEMU as a result of a guest IO operation, | ||
406 | +they will forward the operation to the device emulation process. | ||
407 | + | ||
408 | +PCI config space | ||
409 | +^^^^^^^^^^^^^^^^ | ||
410 | + | ||
411 | +PCI devices also have a configuration space that can be accessed by the | ||
412 | +guest driver. Guest accesses to this space is not handled by the device | ||
413 | +emulation object, but by its PCI parent object. Much of this space is | ||
414 | +read-only, but certain registers (especially BAR and MSI-related ones) | ||
415 | +need to be propagated to the emulation process. | ||
416 | + | ||
417 | +PCI parent proxy | ||
418 | +'''''''''''''''' | ||
419 | + | ||
420 | +One way to propagate guest PCI config accesses is to create a | ||
421 | +"pci-device-proxy" class that can serve as the parent of a PCI device | ||
422 | +proxy object. This class's parent would be "pci-device" and it would | ||
423 | +override the PCI parent's ``config_read()`` and ``config_write()`` | ||
424 | +methods with ones that forward these operations to the emulation | ||
425 | +program. | ||
426 | + | ||
427 | +interrupt receipt | ||
428 | +^^^^^^^^^^^^^^^^^ | ||
429 | + | ||
430 | +A proxy for a device that generates interrupts will need to create a | ||
431 | +socket to receive interrupt indications from the emulation process. An | ||
432 | +incoming interrupt indication would then be sent up to its bus parent to | ||
433 | +be injected into the guest. For example, a PCI device object may use | ||
434 | +``pci_set_irq()``. | ||
435 | + | ||
436 | +live migration | ||
437 | +^^^^^^^^^^^^^^ | ||
438 | + | ||
439 | +The proxy will register to save and restore any *vmstate* it needs over | ||
440 | +a live migration event. The device proxy does not need to manage the | ||
441 | +remote device's *vmstate*; that will be handled by the remote process | ||
442 | +proxy (see below). | ||
443 | + | ||
444 | +QEMU remote device operation | ||
445 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
446 | + | ||
447 | +Generic device operations, such as DMA, will be performed by the remote | ||
448 | +process proxy by sending messages to the remote process. | ||
449 | + | ||
450 | +DMA operations | ||
451 | +^^^^^^^^^^^^^^ | ||
452 | + | ||
453 | +DMA operations would be handled much like vhost applications do. One of | ||
454 | +the initial messages sent to the emulation process is a guest memory | ||
455 | +table. Each entry in this table consists of a file descriptor and size | ||
456 | +that the emulation process can ``mmap()`` to directly access guest | ||
457 | +memory, similar to ``vhost_user_set_mem_table()``. Note guest memory | ||
458 | +must be backed by file descriptors, such as when QEMU is given the | ||
459 | +*-mem-path* command line option. | ||
460 | + | ||
461 | +IOMMU operations | ||
462 | +^^^^^^^^^^^^^^^^ | ||
463 | + | ||
464 | +When the emulated system includes an IOMMU, the remote process proxy in | ||
465 | +QEMU will need to create a socket for IOMMU requests from the emulation | ||
466 | +process. It will handle those requests with an | ||
467 | +``address_space_get_iotlb_entry()`` call. In order to handle IOMMU | ||
468 | +unmaps, the remote process proxy will also register as a listener on the | ||
469 | +device's DMA address space. When an IOMMU memory region is created | ||
470 | +within the DMA address space, an IOMMU notifier for unmaps will be added | ||
471 | +to the memory region that will forward unmaps to the emulation process | ||
472 | +over the IOMMU socket. | ||
473 | + | ||
474 | +device hot-plug via QMP | ||
475 | +^^^^^^^^^^^^^^^^^^^^^^^ | ||
476 | + | ||
477 | +An QMP "device\_add" command can add a device emulated by a remote | ||
478 | +process. It will also have "rid" option to the command, just as the | ||
479 | +*-device* command line option does. The remote process may either be one | ||
480 | +started at QEMU startup, or be one added by the "add-process" QMP | ||
481 | +command described above. In either case, the remote process proxy will | ||
482 | +forward the new device's JSON description to the corresponding emulation | ||
483 | +process. | ||
484 | + | ||
485 | +live migration | ||
486 | +^^^^^^^^^^^^^^ | ||
487 | + | ||
488 | +The remote process proxy will also register for live migration | ||
489 | +notifications with ``vmstate_register()``. When called to save state, | ||
490 | +the proxy will send the remote process a secondary socket file | ||
491 | +descriptor to save the remote process's device *vmstate* over. The | ||
492 | +incoming byte stream length and data will be saved as the proxy's | ||
493 | +*vmstate*. When the proxy is resumed on its new host, this *vmstate* | ||
494 | +will be extracted, and a secondary socket file descriptor will be sent | ||
495 | +to the new remote process through which it receives the *vmstate* in | ||
496 | +order to restore the devices there. | ||
497 | + | ||
498 | +device emulation in remote process | ||
499 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
500 | + | ||
501 | +The parts of QEMU that the emulation program will need include the | ||
502 | +object model; the memory emulation objects; the device emulation objects | ||
503 | +of the targeted device, and any dependent devices; and, the device's | ||
504 | +backends. It will also need code to setup the machine environment, | ||
505 | +handle requests from the QEMU process, and route machine-level requests | ||
506 | +(such as interrupts or IOMMU mappings) back to the QEMU process. | ||
507 | + | ||
508 | +initialization | ||
509 | +^^^^^^^^^^^^^^ | ||
510 | + | ||
511 | +The process initialization sequence will follow the same sequence | ||
512 | +followed by QEMU. It will first initialize the backend objects, then | ||
513 | +device emulation objects. The JSON descriptions sent by the QEMU process | ||
514 | +will drive which objects need to be created. | ||
515 | + | ||
516 | +- address spaces | ||
517 | + | ||
518 | +Before the device objects are created, the initial address spaces and | ||
519 | +memory regions must be configured with ``memory_map_init()``. This | ||
520 | +creates a RAM memory region object (*system\_memory*) and an IO memory | ||
521 | +region object (*system\_io*). | ||
522 | + | ||
523 | +- RAM | ||
524 | + | ||
525 | +RAM memory region creation will follow how ``pc_memory_init()`` creates | ||
526 | +them, but must use ``memory_region_init_ram_from_fd()`` instead of | ||
527 | +``memory_region_allocate_system_memory()``. The file descriptors needed | ||
528 | +will be supplied by the guest memory table from above. Those RAM regions | ||
529 | +would then be added to the *system\_memory* memory region with | ||
530 | +``memory_region_add_subregion()``. | ||
531 | + | ||
532 | +- PCI | ||
533 | + | ||
534 | +IO initialization will be driven by the JSON descriptions sent from the | ||
535 | +QEMU process. For a PCI device, a PCI bus will need to be created with | ||
536 | +``pci_root_bus_new()``, and a PCI memory region will need to be created | ||
537 | +and added to the *system\_memory* memory region with | ||
538 | +``memory_region_add_subregion_overlap()``. The overlap version is | ||
539 | +required for architectures where PCI memory overlaps with RAM memory. | ||
540 | + | ||
541 | +MMIO handling | ||
542 | +^^^^^^^^^^^^^ | ||
543 | + | ||
544 | +The device emulation objects will use ``memory_region_init_io()`` to | ||
545 | +install their MMIO handlers, and ``pci_register_bar()`` to associate | ||
546 | +those handlers with a PCI BAR, as they do within QEMU currently. | ||
547 | + | ||
548 | +In order to use ``address_space_rw()`` in the emulation process to | ||
549 | +handle MMIO requests from QEMU, the PCI physical addresses must be the | ||
550 | +same in the QEMU process and the device emulation process. In order to | ||
551 | +accomplish that, guest BAR programming must also be forwarded from QEMU | ||
552 | +to the emulation process. | ||
553 | + | ||
554 | +interrupt injection | ||
555 | +^^^^^^^^^^^^^^^^^^^ | ||
556 | + | ||
557 | +When device emulation wants to inject an interrupt into the VM, the | ||
558 | +request climbs the device's bus object hierarchy until the point where a | ||
559 | +bus object knows how to signal the interrupt to the guest. The details | ||
560 | +depend on the type of interrupt being raised. | ||
561 | + | ||
562 | +- PCI pin interrupts | ||
563 | + | ||
564 | +On x86 systems, there is an emulated IOAPIC object attached to the root | ||
565 | +PCI bus object, and the root PCI object forwards interrupt requests to | ||
566 | +it. The IOAPIC object, in turn, calls the KVM driver to inject the | ||
567 | +corresponding interrupt into the VM. The simplest way to handle this in | ||
568 | +an emulation process would be to setup the root PCI bus driver (via | ||
569 | +``pci_bus_irqs()``) to send a interrupt request back to the QEMU | ||
570 | +process, and have the device proxy object reflect it up the PCI tree | ||
571 | +there. | ||
572 | + | ||
573 | +- PCI MSI/X interrupts | ||
574 | + | ||
575 | +PCI MSI/X interrupts are implemented in HW as DMA writes to a | ||
576 | +CPU-specific PCI address. In QEMU on x86, a KVM APIC object receives | ||
577 | +these DMA writes, then calls into the KVM driver to inject the interrupt | ||
578 | +into the VM. A simple emulation process implementation would be to send | ||
579 | +the MSI DMA address from QEMU as a message at initialization, then | ||
580 | +install an address space handler at that address which forwards the MSI | ||
581 | +message back to QEMU. | ||
582 | + | ||
583 | +DMA operations | ||
584 | +^^^^^^^^^^^^^^ | ||
585 | + | ||
586 | +When a emulation object wants to DMA into or out of guest memory, it | ||
587 | +first must use dma\_memory\_map() to convert the DMA address to a local | ||
588 | +virtual address. The emulation process memory region objects setup above | ||
589 | +will be used to translate the DMA address to a local virtual address the | ||
590 | +device emulation code can access. | ||
591 | + | ||
592 | +IOMMU | ||
593 | +^^^^^ | ||
594 | + | ||
595 | +When an IOMMU is in use in QEMU, DMA translation uses IOMMU memory | ||
596 | +regions to translate the DMA address to a guest physical address before | ||
597 | +that physical address can be translated to a local virtual address. The | ||
598 | +emulation process will need similar functionality. | ||
599 | + | ||
600 | +- IOTLB cache | ||
601 | + | ||
602 | +The emulation process will maintain a cache of recent IOMMU translations | ||
603 | +(the IOTLB). When the translate() callback of an IOMMU memory region is | ||
604 | +invoked, the IOTLB cache will be searched for an entry that will map the | ||
605 | +DMA address to a guest PA. On a cache miss, a message will be sent back | ||
606 | +to QEMU requesting the corresponding translation entry, which be both be | ||
607 | +used to return a guest address and be added to the cache. | ||
608 | + | ||
609 | +- IOTLB purge | ||
610 | + | ||
611 | +The IOMMU emulation will also need to act on unmap requests from QEMU. | ||
612 | +These happen when the guest IOMMU driver purges an entry from the | ||
613 | +guest's translation table. | ||
614 | + | ||
615 | +live migration | ||
616 | +^^^^^^^^^^^^^^ | ||
617 | + | ||
618 | +When a remote process receives a live migration indication from QEMU, it | ||
619 | +will set up a channel using the received file descriptor with | ||
620 | +``qio_channel_socket_new_fd()``. This channel will be used to create a | ||
621 | +*QEMUfile* that can be passed to ``qemu_save_device_state()`` to send | ||
622 | +the process's device state back to QEMU. This method will be reversed on | ||
623 | +restore - the channel will be passed to ``qemu_loadvm_state()`` to | ||
624 | +restore the device state. | ||
625 | + | ||
626 | +Accelerating device emulation | ||
627 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
628 | + | ||
629 | +The messages that are required to be sent between QEMU and the emulation | ||
630 | +process can add considerable latency to IO operations. The optimizations | ||
631 | +described below attempt to ameliorate this effect by allowing the | ||
632 | +emulation process to communicate directly with the kernel KVM driver. | ||
633 | +The KVM file descriptors created would be passed to the emulation process | ||
634 | +via initialization messages, much like the guest memory table is done. | ||
635 | +#### MMIO acceleration | ||
636 | + | ||
637 | +Vhost user applications can receive guest virtio driver stores directly | ||
638 | +from KVM. The issue with the eventfd mechanism used by vhost user is | ||
639 | +that it does not pass any data with the event indication, so it cannot | ||
640 | +handle guest loads or guest stores that carry store data. This concept | ||
641 | +could, however, be expanded to cover more cases. | ||
642 | + | ||
643 | +The expanded idea would require a new type of KVM device: | ||
644 | +*KVM\_DEV\_TYPE\_USER*. This device has two file descriptors: a master | ||
645 | +descriptor that QEMU can use for configuration, and a slave descriptor | ||
646 | +that the emulation process can use to receive MMIO notifications. QEMU | ||
647 | +would create both descriptors using the KVM driver, and pass the slave | ||
648 | +descriptor to the emulation process via an initialization message. | ||
649 | + | ||
650 | +data structures | ||
651 | +^^^^^^^^^^^^^^^ | ||
652 | + | ||
653 | +- guest physical range | ||
654 | + | ||
655 | +The guest physical range structure describes the address range that a | ||
656 | +device will respond to. It includes the base and length of the range, as | ||
657 | +well as which bus the range resides on (e.g., on an x86machine, it can | ||
658 | +specify whether the range refers to memory or IO addresses). | ||
659 | + | ||
660 | +A device can have multiple physical address ranges it responds to (e.g., | ||
661 | +a PCI device can have multiple BARs), so the structure will also include | ||
662 | +an enumerated identifier to specify which of the device's ranges is | ||
663 | +being referred to. | ||
664 | + | ||
665 | ++--------+----------------------------+ | ||
666 | +| Name | Description | | ||
667 | ++========+============================+ | ||
668 | +| addr | range base address | | ||
669 | ++--------+----------------------------+ | ||
670 | +| len | range length | | ||
671 | ++--------+----------------------------+ | ||
672 | +| bus | addr type (memory or IO) | | ||
673 | ++--------+----------------------------+ | ||
674 | +| id | range ID (e.g., PCI BAR) | | ||
675 | ++--------+----------------------------+ | ||
676 | + | ||
677 | +- MMIO request structure | ||
678 | + | ||
679 | +This structure describes an MMIO operation. It includes which guest | ||
680 | +physical range the MMIO was within, the offset within that range, the | ||
681 | +MMIO type (e.g., load or store), and its length and data. It also | ||
682 | +includes a sequence number that can be used to reply to the MMIO, and | ||
683 | +the CPU that issued the MMIO. | ||
684 | + | ||
685 | ++----------+------------------------+ | ||
686 | +| Name | Description | | ||
687 | ++==========+========================+ | ||
688 | +| rid | range MMIO is within | | ||
689 | ++----------+------------------------+ | ||
690 | +| offset | offset withing *rid* | | ||
691 | ++----------+------------------------+ | ||
692 | +| type | e.g., load or store | | ||
693 | ++----------+------------------------+ | ||
694 | +| len | MMIO length | | ||
695 | ++----------+------------------------+ | ||
696 | +| data | store data | | ||
697 | ++----------+------------------------+ | ||
698 | +| seq | sequence ID | | ||
699 | ++----------+------------------------+ | ||
700 | + | ||
701 | +- MMIO request queues | ||
702 | + | ||
703 | +MMIO request queues are FIFO arrays of MMIO request structures. There | ||
704 | +are two queues: pending queue is for MMIOs that haven't been read by the | ||
705 | +emulation program, and the sent queue is for MMIOs that haven't been | ||
706 | +acknowledged. The main use of the second queue is to validate MMIO | ||
707 | +replies from the emulation program. | ||
708 | + | ||
709 | +- scoreboard | ||
710 | + | ||
711 | +Each CPU in the VM is emulated in QEMU by a separate thread, so multiple | ||
712 | +MMIOs may be waiting to be consumed by an emulation program and multiple | ||
713 | +threads may be waiting for MMIO replies. The scoreboard would contain a | ||
714 | +wait queue and sequence number for the per-CPU threads, allowing them to | ||
715 | +be individually woken when the MMIO reply is received from the emulation | ||
716 | +program. It also tracks the number of posted MMIO stores to the device | ||
717 | +that haven't been replied to, in order to satisfy the PCI constraint | ||
718 | +that a load to a device will not complete until all previous stores to | ||
719 | +that device have been completed. | ||
720 | + | ||
721 | +- device shadow memory | ||
722 | + | ||
723 | +Some MMIO loads do not have device side-effects. These MMIOs can be | ||
724 | +completed without sending a MMIO request to the emulation program if the | ||
725 | +emulation program shares a shadow image of the device's memory image | ||
726 | +with the KVM driver. | ||
727 | + | ||
728 | +The emulation program will ask the KVM driver to allocate memory for the | ||
729 | +shadow image, and will then use ``mmap()`` to directly access it. The | ||
730 | +emulation program can control KVM access to the shadow image by sending | ||
731 | +KVM an access map telling it which areas of the image have no | ||
732 | +side-effects (and can be completed immediately), and which require a | ||
733 | +MMIO request to the emulation program. The access map can also inform | ||
734 | +the KVM drive which size accesses are allowed to the image. | ||
735 | + | ||
736 | +master descriptor | ||
737 | +^^^^^^^^^^^^^^^^^ | ||
738 | + | ||
739 | +The master descriptor is used by QEMU to configure the new KVM device. | ||
740 | +The descriptor would be returned by the KVM driver when QEMU issues a | ||
741 | +*KVM\_CREATE\_DEVICE* ``ioctl()`` with a *KVM\_DEV\_TYPE\_USER* type. | ||
742 | + | ||
743 | +KVM\_DEV\_TYPE\_USER device ops | ||
744 | + | ||
745 | + | ||
746 | +The *KVM\_DEV\_TYPE\_USER* operations vector will be registered by a | ||
747 | +``kvm_register_device_ops()`` call when the KVM system in initialized by | ||
748 | +``kvm_init()``. These device ops are called by the KVM driver when QEMU | ||
749 | +executes certain ``ioctl()`` operations on its KVM file descriptor. They | ||
750 | +include: | ||
751 | + | ||
752 | +- create | ||
753 | + | ||
754 | +This routine is called when QEMU issues a *KVM\_CREATE\_DEVICE* | ||
755 | +``ioctl()`` on its per-VM file descriptor. It will allocate and | ||
756 | +initialize a KVM user device specific data structure, and assign the | ||
757 | +*kvm\_device* private field to it. | ||
758 | + | ||
759 | +- ioctl | ||
760 | + | ||
761 | +This routine is invoked when QEMU issues an ``ioctl()`` on the master | ||
762 | +descriptor. The ``ioctl()`` commands supported are defined by the KVM | ||
763 | +device type. *KVM\_DEV\_TYPE\_USER* ones will need several commands: | ||
764 | + | ||
765 | +*KVM\_DEV\_USER\_SLAVE\_FD* creates the slave file descriptor that will | ||
766 | +be passed to the device emulation program. Only one slave can be created | ||
767 | +by each master descriptor. The file operations performed by this | ||
768 | +descriptor are described below. | ||
769 | + | ||
770 | +The *KVM\_DEV\_USER\_PA\_RANGE* command configures a guest physical | ||
771 | +address range that the slave descriptor will receive MMIO notifications | ||
772 | +for. The range is specified by a guest physical range structure | ||
773 | +argument. For buses that assign addresses to devices dynamically, this | ||
774 | +command can be executed while the guest is running, such as the case | ||
775 | +when a guest changes a device's PCI BAR registers. | ||
776 | + | ||
777 | +*KVM\_DEV\_USER\_PA\_RANGE* will use ``kvm_io_bus_register_dev()`` to | ||
778 | +register *kvm\_io\_device\_ops* callbacks to be invoked when the guest | ||
779 | +performs a MMIO operation within the range. When a range is changed, | ||
780 | +``kvm_io_bus_unregister_dev()`` is used to remove the previous | ||
781 | +instantiation. | ||
782 | + | ||
783 | +*KVM\_DEV\_USER\_TIMEOUT* will configure a timeout value that specifies | ||
784 | +how long KVM will wait for the emulation process to respond to a MMIO | ||
785 | +indication. | ||
786 | + | ||
787 | +- destroy | ||
788 | + | ||
789 | +This routine is called when the VM instance is destroyed. It will need | ||
790 | +to destroy the slave descriptor; and free any memory allocated by the | ||
791 | +driver, as well as the *kvm\_device* structure itself. | ||
792 | + | ||
793 | +slave descriptor | ||
794 | +^^^^^^^^^^^^^^^^ | ||
795 | + | ||
796 | +The slave descriptor will have its own file operations vector, which | ||
797 | +responds to system calls on the descriptor performed by the device | ||
798 | +emulation program. | ||
799 | + | ||
800 | +- read | ||
801 | + | ||
802 | +A read returns any pending MMIO requests from the KVM driver as MMIO | ||
803 | +request structures. Multiple structures can be returned if there are | ||
804 | +multiple MMIO operations pending. The MMIO requests are moved from the | ||
805 | +pending queue to the sent queue, and if there are threads waiting for | ||
806 | +space in the pending to add new MMIO operations, they will be woken | ||
807 | +here. | ||
808 | + | ||
809 | +- write | ||
810 | + | ||
811 | +A write also consists of a set of MMIO requests. They are compared to | ||
812 | +the MMIO requests in the sent queue. Matches are removed from the sent | ||
813 | +queue, and any threads waiting for the reply are woken. If a store is | ||
814 | +removed, then the number of posted stores in the per-CPU scoreboard is | ||
815 | +decremented. When the number is zero, and a non side-effect load was | ||
816 | +waiting for posted stores to complete, the load is continued. | ||
817 | + | ||
818 | +- ioctl | ||
819 | + | ||
820 | +There are several ioctl()s that can be performed on the slave | ||
821 | +descriptor. | ||
822 | + | ||
823 | +A *KVM\_DEV\_USER\_SHADOW\_SIZE* ``ioctl()`` causes the KVM driver to | ||
824 | +allocate memory for the shadow image. This memory can later be | ||
825 | +``mmap()``\ ed by the emulation process to share the emulation's view of | ||
826 | +device memory with the KVM driver. | ||
827 | + | ||
828 | +A *KVM\_DEV\_USER\_SHADOW\_CTRL* ``ioctl()`` controls access to the | ||
829 | +shadow image. It will send the KVM driver a shadow control map, which | ||
830 | +specifies which areas of the image can complete guest loads without | ||
831 | +sending the load request to the emulation program. It will also specify | ||
832 | +the size of load operations that are allowed. | ||
833 | + | ||
834 | +- poll | ||
835 | + | ||
836 | +An emulation program will use the ``poll()`` call with a *POLLIN* flag | ||
837 | +to determine if there are MMIO requests waiting to be read. It will | ||
838 | +return if the pending MMIO request queue is not empty. | ||
839 | + | ||
840 | +- mmap | ||
841 | + | ||
842 | +This call allows the emulation program to directly access the shadow | ||
843 | +image allocated by the KVM driver. As device emulation updates device | ||
844 | +memory, changes with no side-effects will be reflected in the shadow, | ||
845 | +and the KVM driver can satisfy guest loads from the shadow image without | ||
846 | +needing to wait for the emulation program. | ||
847 | + | ||
848 | +kvm\_io\_device ops | ||
849 | +^^^^^^^^^^^^^^^^^^^ | ||
850 | + | ||
851 | +Each KVM per-CPU thread can handle MMIO operation on behalf of the guest | ||
852 | +VM. KVM will use the MMIO's guest physical address to search for a | ||
853 | +matching *kvm\_io\_device* to see if the MMIO can be handled by the KVM | ||
854 | +driver instead of exiting back to QEMU. If a match is found, the | ||
855 | +corresponding callback will be invoked. | ||
856 | + | ||
857 | +- read | ||
858 | + | ||
859 | +This callback is invoked when the guest performs a load to the device. | ||
860 | +Loads with side-effects must be handled synchronously, with the KVM | ||
861 | +driver putting the QEMU thread to sleep waiting for the emulation | ||
862 | +process reply before re-starting the guest. Loads that do not have | ||
863 | +side-effects may be optimized by satisfying them from the shadow image, | ||
864 | +if there are no outstanding stores to the device by this CPU. PCI memory | ||
865 | +ordering demands that a load cannot complete before all older stores to | ||
866 | +the same device have been completed. | ||
867 | + | ||
868 | +- write | ||
869 | + | ||
870 | +Stores can be handled asynchronously unless the pending MMIO request | ||
871 | +queue is full. In this case, the QEMU thread must sleep waiting for | ||
872 | +space in the queue. Stores will increment the number of posted stores in | ||
873 | +the per-CPU scoreboard, in order to implement the PCI ordering | ||
874 | +constraint above. | ||
875 | + | ||
876 | +interrupt acceleration | ||
877 | +^^^^^^^^^^^^^^^^^^^^^^ | ||
878 | + | ||
879 | +This performance optimization would work much like a vhost user | ||
880 | +application does, where the QEMU process sets up *eventfds* that cause | ||
881 | +the device's corresponding interrupt to be triggered by the KVM driver. | ||
882 | +These irq file descriptors are sent to the emulation process at | ||
883 | +initialization, and are used when the emulation code raises a device | ||
884 | +interrupt. | ||
885 | + | ||
886 | +intx acceleration | ||
887 | +''''''''''''''''' | ||
888 | + | ||
889 | +Traditional PCI pin interrupts are level based, so, in addition to an | ||
890 | +irq file descriptor, a re-sampling file descriptor needs to be sent to | ||
891 | +the emulation program. This second file descriptor allows multiple | ||
892 | +devices sharing an irq to be notified when the interrupt has been | ||
893 | +acknowledged by the guest, so they can re-trigger the interrupt if their | ||
894 | +device has not de-asserted its interrupt. | ||
895 | + | ||
896 | +intx irq descriptor | ||
897 | + | ||
898 | + | ||
899 | +The irq descriptors are created by the proxy object | ||
900 | +``using event_notifier_init()`` to create the irq and re-sampling | ||
901 | +*eventds*, and ``kvm_vm_ioctl(KVM_IRQFD)`` to bind them to an interrupt. | ||
902 | +The interrupt route can be found with | ||
903 | +``pci_device_route_intx_to_irq()``. | ||
904 | + | ||
905 | +intx routing changes | ||
906 | + | ||
907 | + | ||
908 | +Intx routing can be changed when the guest programs the APIC the device | ||
909 | +pin is connected to. The proxy object in QEMU will use | ||
910 | +``pci_device_set_intx_routing_notifier()`` to be informed of any guest | ||
911 | +changes to the route. This handler will broadly follow the VFIO | ||
912 | +interrupt logic to change the route: de-assigning the existing irq | ||
913 | +descriptor from its route, then assigning it the new route. (see | ||
914 | +``vfio_intx_update()``) | ||
915 | + | ||
916 | +MSI/X acceleration | ||
917 | +'''''''''''''''''' | ||
918 | + | ||
919 | +MSI/X interrupts are sent as DMA transactions to the host. The interrupt | ||
920 | +data contains a vector that is programmed by the guest, A device may have | ||
921 | +multiple MSI interrupts associated with it, so multiple irq descriptors | ||
922 | +may need to be sent to the emulation program. | ||
923 | + | ||
924 | +MSI/X irq descriptor | ||
925 | + | ||
926 | + | ||
927 | +This case will also follow the VFIO example. For each MSI/X interrupt, | ||
928 | +an *eventfd* is created, a virtual interrupt is allocated by | ||
929 | +``kvm_irqchip_add_msi_route()``, and the virtual interrupt is bound to | ||
930 | +the eventfd with ``kvm_irqchip_add_irqfd_notifier()``. | ||
931 | + | ||
932 | +MSI/X config space changes | ||
933 | + | ||
934 | + | ||
935 | +The guest may dynamically update several MSI-related tables in the | ||
936 | +device's PCI config space. These include per-MSI interrupt enables and | ||
937 | +vector data. Additionally, MSIX tables exist in device memory space, not | ||
938 | +config space. Much like the BAR case above, the proxy object must look | ||
939 | +at guest config space programming to keep the MSI interrupt state | ||
940 | +consistent between QEMU and the emulation program. | ||
941 | + | ||
942 | +-------------- | ||
943 | + | ||
944 | +Disaggregated CPU emulation | ||
945 | +--------------------------- | ||
946 | + | ||
947 | +After IO services have been disaggregated, a second phase would be to | ||
948 | +separate a process to handle CPU instruction emulation from the main | ||
949 | +QEMU control function. There are no object separation points for this | ||
950 | +code, so the first task would be to create one. | ||
951 | + | ||
952 | +Host access controls | ||
953 | +-------------------- | ||
954 | + | ||
955 | +Separating QEMU relies on the host OS's access restriction mechanisms to | ||
956 | +enforce that the differing processes can only access the objects they | ||
957 | +are entitled to. There are a couple types of mechanisms usually provided | ||
958 | +by general purpose OSs. | ||
959 | + | ||
960 | +Discretionary access control | ||
961 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
962 | + | ||
963 | +Discretionary access control allows each user to control who can access | ||
964 | +their files. In Linux, this type of control is usually too coarse for | ||
965 | +QEMU separation, since it only provides three separate access controls: | ||
966 | +one for the same user ID, the second for users IDs with the same group | ||
967 | +ID, and the third for all other user IDs. Each device instance would | ||
968 | +need a separate user ID to provide access control, which is likely to be | ||
969 | +unwieldy for dynamically created VMs. | ||
970 | + | ||
971 | +Mandatory access control | ||
972 | +~~~~~~~~~~~~~~~~~~~~~~~~ | ||
973 | + | ||
974 | +Mandatory access control allows the OS to add an additional set of | ||
975 | +controls on top of discretionary access for the OS to control. It also | ||
976 | +adds other attributes to processes and files such as types, roles, and | ||
977 | +categories, and can establish rules for how processes and files can | ||
978 | +interact. | ||
979 | + | ||
980 | +Type enforcement | ||
981 | +^^^^^^^^^^^^^^^^ | ||
982 | + | ||
983 | +Type enforcement assigns a *type* attribute to processes and files, and | ||
984 | +allows rules to be written on what operations a process with a given | ||
985 | +type can perform on a file with a given type. QEMU separation could take | ||
986 | +advantage of type enforcement by running the emulation processes with | ||
987 | +different types, both from the main QEMU process, and from the emulation | ||
988 | +processes of different classes of devices. | ||
989 | + | ||
990 | +For example, guest disk images and disk emulation processes could have | ||
991 | +types separate from the main QEMU process and non-disk emulation | ||
992 | +processes, and the type rules could prevent processes other than disk | ||
993 | +emulation ones from accessing guest disk images. Similarly, network | ||
994 | +emulation processes can have a type separate from the main QEMU process | ||
995 | +and non-network emulation process, and only that type can access the | ||
996 | +host tun/tap device used to provide guest networking. | ||
997 | + | ||
998 | +Category enforcement | ||
999 | +^^^^^^^^^^^^^^^^^^^^ | ||
1000 | + | ||
1001 | +Category enforcement assigns a set of numbers within a given range to | ||
1002 | +the process or file. The process is granted access to the file if the | ||
1003 | +process's set is a superset of the file's set. This enforcement can be | ||
1004 | +used to separate multiple instances of devices in the same class. | ||
1005 | + | ||
1006 | +For example, if there are multiple disk devices provides to a guest, | ||
1007 | +each device emulation process could be provisioned with a separate | ||
1008 | +category. The different device emulation processes would not be able to | ||
1009 | +access each other's backing disk images. | ||
1010 | + | ||
1011 | +Alternatively, categories could be used in lieu of the type enforcement | ||
1012 | +scheme described above. In this scenario, different categories would be | ||
1013 | +used to prevent device emulation processes in different classes from | ||
1014 | +accessing resources assigned to other classes. | ||
1015 | -- | ||
1016 | 2.29.2 | ||
1017 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
1 | 2 | ||
3 | Adds documentation explaining the command-line arguments needed | ||
4 | to use multi-process. | ||
5 | |||
6 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
7 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
8 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Message-id: 49f757a84e5dd6fae14b22544897d1124c5fdbad.1611938319.git.jag.raman@oracle.com | ||
11 | |||
12 | [Move orphan docs/multi-process.rst document into docs/system/ and add | ||
13 | it to index.rst to prevent Sphinx "document isn't included in any | ||
14 | toctree" error. | ||
15 | --Stefan] | ||
16 | |||
17 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
18 | --- | ||
19 | MAINTAINERS | 1 + | ||
20 | docs/system/index.rst | 1 + | ||
21 | docs/system/multi-process.rst | 64 +++++++++++++++++++++++++++++++++++ | ||
22 | 3 files changed, 66 insertions(+) | ||
23 | create mode 100644 docs/system/multi-process.rst | ||
24 | |||
25 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/MAINTAINERS | ||
28 | +++ b/MAINTAINERS | ||
29 | @@ -XXX,XX +XXX,XX @@ M: Jagannathan Raman <jag.raman@oracle.com> | ||
30 | M: John G Johnson <john.g.johnson@oracle.com> | ||
31 | S: Maintained | ||
32 | F: docs/devel/multi-process.rst | ||
33 | +F: docs/system/multi-process.rst | ||
34 | |||
35 | Build and test automation | ||
36 | ------------------------- | ||
37 | diff --git a/docs/system/index.rst b/docs/system/index.rst | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/docs/system/index.rst | ||
40 | +++ b/docs/system/index.rst | ||
41 | @@ -XXX,XX +XXX,XX @@ Contents: | ||
42 | pr-manager | ||
43 | targets | ||
44 | security | ||
45 | + multi-process | ||
46 | deprecated | ||
47 | removed-features | ||
48 | build-platforms | ||
49 | diff --git a/docs/system/multi-process.rst b/docs/system/multi-process.rst | ||
50 | new file mode 100644 | ||
51 | index XXXXXXX..XXXXXXX | ||
52 | --- /dev/null | ||
53 | +++ b/docs/system/multi-process.rst | ||
54 | @@ -XXX,XX +XXX,XX @@ | ||
55 | +Multi-process QEMU | ||
56 | +================== | ||
57 | + | ||
58 | +This document describes how to configure and use multi-process qemu. | ||
59 | +For the design document refer to docs/devel/qemu-multiprocess. | ||
60 | + | ||
61 | +1) Configuration | ||
62 | +---------------- | ||
63 | + | ||
64 | +multi-process is enabled by default for targets that enable KVM | ||
65 | + | ||
66 | + | ||
67 | +2) Usage | ||
68 | +-------- | ||
69 | + | ||
70 | +Multi-process QEMU requires an orchestrator to launch. | ||
71 | + | ||
72 | +Following is a description of command-line used to launch mpqemu. | ||
73 | + | ||
74 | +* Orchestrator: | ||
75 | + | ||
76 | + - The Orchestrator creates a unix socketpair | ||
77 | + | ||
78 | + - It launches the remote process and passes one of the | ||
79 | + sockets to it via command-line. | ||
80 | + | ||
81 | + - It then launches QEMU and specifies the other socket as an option | ||
82 | + to the Proxy device object | ||
83 | + | ||
84 | +* Remote Process: | ||
85 | + | ||
86 | + - QEMU can enter remote process mode by using the "remote" machine | ||
87 | + option. | ||
88 | + | ||
89 | + - The orchestrator creates a "remote-object" with details about | ||
90 | + the device and the file descriptor for the device | ||
91 | + | ||
92 | + - The remaining options are no different from how one launches QEMU with | ||
93 | + devices. | ||
94 | + | ||
95 | + - Example command-line for the remote process is as follows: | ||
96 | + | ||
97 | + /usr/bin/qemu-system-x86_64 \ | ||
98 | + -machine x-remote \ | ||
99 | + -device lsi53c895a,id=lsi0 \ | ||
100 | + -drive id=drive_image2,file=/build/ol7-nvme-test-1.qcow2 \ | ||
101 | + -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0 \ | ||
102 | + -object x-remote-object,id=robj1,devid=lsi1,fd=4, | ||
103 | + | ||
104 | +* QEMU: | ||
105 | + | ||
106 | + - Since parts of the RAM are shared between QEMU & remote process, a | ||
107 | + memory-backend-memfd is required to facilitate this, as follows: | ||
108 | + | ||
109 | + -object memory-backend-memfd,id=mem,size=2G | ||
110 | + | ||
111 | + - A "x-pci-proxy-dev" device is created for each of the PCI devices emulated | ||
112 | + in the remote process. A "socket" sub-option specifies the other end of | ||
113 | + unix channel created by orchestrator. The "id" sub-option must be specified | ||
114 | + and should be the same as the "id" specified for the remote PCI device | ||
115 | + | ||
116 | + - Example commandline for QEMU is as follows: | ||
117 | + | ||
118 | + -device x-pci-proxy-dev,id=lsi0,socket=3 | ||
119 | -- | ||
120 | 2.29.2 | ||
121 | diff view generated by jsdifflib |
1 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 1 | From: Jagannathan Raman <jag.raman@oracle.com> |
---|---|---|---|
2 | |||
3 | Allow RAM MemoryRegion to be created from an offset in a file, instead | ||
4 | of allocating at offset of 0 by default. This is needed to synchronize | ||
5 | RAM between QEMU & remote process. | ||
6 | |||
7 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
8 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
9 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
2 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
3 | Reviewed-by: John Snow <jsnow@redhat.com> | 11 | Message-id: 609996697ad8617e3b01df38accc5c208c24d74e.1611938319.git.jag.raman@oracle.com |
4 | Message-id: 00aed7ffdd7be4b9ed9ce1007d50028a72b34ebe.1491597120.git.jcody@redhat.com | 12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
5 | --- | 13 | --- |
6 | block.c | 14 ++++++++------ | 14 | include/exec/memory.h | 2 ++ |
7 | 1 file changed, 8 insertions(+), 6 deletions(-) | 15 | include/exec/ram_addr.h | 2 +- |
8 | 16 | include/qemu/mmap-alloc.h | 4 +++- | |
9 | diff --git a/block.c b/block.c | 17 | backends/hostmem-memfd.c | 2 +- |
10 | index XXXXXXX..XXXXXXX 100644 | 18 | hw/misc/ivshmem.c | 3 ++- |
11 | --- a/block.c | 19 | softmmu/memory.c | 3 ++- |
12 | +++ b/block.c | 20 | softmmu/physmem.c | 11 +++++++---- |
13 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, | 21 | util/mmap-alloc.c | 7 ++++--- |
14 | BlockDriver *drv; | 22 | util/oslib-posix.c | 2 +- |
15 | QemuOpts *opts; | 23 | 9 files changed, 23 insertions(+), 13 deletions(-) |
16 | const char *value; | 24 | |
17 | + bool read_only; | 25 | diff --git a/include/exec/memory.h b/include/exec/memory.h |
18 | 26 | index XXXXXXX..XXXXXXX 100644 | |
19 | assert(reopen_state != NULL); | 27 | --- a/include/exec/memory.h |
20 | assert(reopen_state->bs->drv != NULL); | 28 | +++ b/include/exec/memory.h |
21 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, | 29 | @@ -XXX,XX +XXX,XX @@ void memory_region_init_ram_from_file(MemoryRegion *mr, |
22 | qdict_put(reopen_state->options, "driver", qstring_from_str(value)); | 30 | * @size: size of the region. |
31 | * @share: %true if memory must be mmaped with the MAP_SHARED flag | ||
32 | * @fd: the fd to mmap. | ||
33 | + * @offset: offset within the file referenced by fd | ||
34 | * @errp: pointer to Error*, to store an error if it happens. | ||
35 | * | ||
36 | * Note that this function does not do anything to cause the data in the | ||
37 | @@ -XXX,XX +XXX,XX @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, | ||
38 | uint64_t size, | ||
39 | bool share, | ||
40 | int fd, | ||
41 | + ram_addr_t offset, | ||
42 | Error **errp); | ||
43 | #endif | ||
44 | |||
45 | diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/include/exec/ram_addr.h | ||
48 | +++ b/include/exec/ram_addr.h | ||
49 | @@ -XXX,XX +XXX,XX @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, | ||
50 | Error **errp); | ||
51 | RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, | ||
52 | uint32_t ram_flags, int fd, | ||
53 | - Error **errp); | ||
54 | + off_t offset, Error **errp); | ||
55 | |||
56 | RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, | ||
57 | MemoryRegion *mr, Error **errp); | ||
58 | diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/include/qemu/mmap-alloc.h | ||
61 | +++ b/include/qemu/mmap-alloc.h | ||
62 | @@ -XXX,XX +XXX,XX @@ size_t qemu_mempath_getpagesize(const char *mem_path); | ||
63 | * otherwise, the alignment in use will be determined by QEMU. | ||
64 | * @shared: map has RAM_SHARED flag. | ||
65 | * @is_pmem: map has RAM_PMEM flag. | ||
66 | + * @map_offset: map starts at offset of map_offset from the start of fd | ||
67 | * | ||
68 | * Return: | ||
69 | * On success, return a pointer to the mapped area. | ||
70 | @@ -XXX,XX +XXX,XX @@ void *qemu_ram_mmap(int fd, | ||
71 | size_t size, | ||
72 | size_t align, | ||
73 | bool shared, | ||
74 | - bool is_pmem); | ||
75 | + bool is_pmem, | ||
76 | + off_t map_offset); | ||
77 | |||
78 | void qemu_ram_munmap(int fd, void *ptr, size_t size); | ||
79 | |||
80 | diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/backends/hostmem-memfd.c | ||
83 | +++ b/backends/hostmem-memfd.c | ||
84 | @@ -XXX,XX +XXX,XX @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) | ||
85 | name = host_memory_backend_get_name(backend); | ||
86 | memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), | ||
87 | name, backend->size, | ||
88 | - backend->share, fd, errp); | ||
89 | + backend->share, fd, 0, errp); | ||
90 | g_free(name); | ||
91 | } | ||
92 | |||
93 | diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c | ||
94 | index XXXXXXX..XXXXXXX 100644 | ||
95 | --- a/hw/misc/ivshmem.c | ||
96 | +++ b/hw/misc/ivshmem.c | ||
97 | @@ -XXX,XX +XXX,XX @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) | ||
98 | |||
99 | /* mmap the region and map into the BAR2 */ | ||
100 | memory_region_init_ram_from_fd(&s->server_bar2, OBJECT(s), | ||
101 | - "ivshmem.bar2", size, true, fd, &local_err); | ||
102 | + "ivshmem.bar2", size, true, fd, 0, | ||
103 | + &local_err); | ||
104 | if (local_err) { | ||
105 | error_propagate(errp, local_err); | ||
106 | return; | ||
107 | diff --git a/softmmu/memory.c b/softmmu/memory.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/softmmu/memory.c | ||
110 | +++ b/softmmu/memory.c | ||
111 | @@ -XXX,XX +XXX,XX @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, | ||
112 | uint64_t size, | ||
113 | bool share, | ||
114 | int fd, | ||
115 | + ram_addr_t offset, | ||
116 | Error **errp) | ||
117 | { | ||
118 | Error *err = NULL; | ||
119 | @@ -XXX,XX +XXX,XX @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, | ||
120 | mr->destructor = memory_region_destructor_ram; | ||
121 | mr->ram_block = qemu_ram_alloc_from_fd(size, mr, | ||
122 | share ? RAM_SHARED : 0, | ||
123 | - fd, &err); | ||
124 | + fd, offset, &err); | ||
125 | if (err) { | ||
126 | mr->size = int128_zero(); | ||
127 | object_unparent(OBJECT(mr)); | ||
128 | diff --git a/softmmu/physmem.c b/softmmu/physmem.c | ||
129 | index XXXXXXX..XXXXXXX 100644 | ||
130 | --- a/softmmu/physmem.c | ||
131 | +++ b/softmmu/physmem.c | ||
132 | @@ -XXX,XX +XXX,XX @@ static void *file_ram_alloc(RAMBlock *block, | ||
133 | ram_addr_t memory, | ||
134 | int fd, | ||
135 | bool truncate, | ||
136 | + off_t offset, | ||
137 | Error **errp) | ||
138 | { | ||
139 | void *area; | ||
140 | @@ -XXX,XX +XXX,XX @@ static void *file_ram_alloc(RAMBlock *block, | ||
23 | } | 141 | } |
24 | 142 | ||
25 | - /* if we are to stay read-only, do not allow permission change | 143 | area = qemu_ram_mmap(fd, memory, block->mr->align, |
26 | - * to r/w */ | 144 | - block->flags & RAM_SHARED, block->flags & RAM_PMEM); |
27 | - if (!(reopen_state->bs->open_flags & BDRV_O_ALLOW_RDWR) && | 145 | + block->flags & RAM_SHARED, block->flags & RAM_PMEM, |
28 | - reopen_state->flags & BDRV_O_RDWR) { | 146 | + offset); |
29 | - error_setg(errp, "Node '%s' is read only", | 147 | if (area == MAP_FAILED) { |
30 | - bdrv_get_device_or_node_name(reopen_state->bs)); | 148 | error_setg_errno(errp, errno, |
31 | + /* If we are to stay read-only, do not allow permission change | 149 | "unable to map backing store for guest RAM"); |
32 | + * to r/w. Attempting to set to r/w may fail if either BDRV_O_ALLOW_RDWR is | 150 | @@ -XXX,XX +XXX,XX @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) |
33 | + * not set, or if the BDS still has copy_on_read enabled */ | 151 | #ifdef CONFIG_POSIX |
34 | + read_only = !(reopen_state->flags & BDRV_O_RDWR); | 152 | RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, |
35 | + ret = bdrv_can_set_read_only(reopen_state->bs, read_only, &local_err); | 153 | uint32_t ram_flags, int fd, |
36 | + if (local_err) { | 154 | - Error **errp) |
37 | + error_propagate(errp, local_err); | 155 | + off_t offset, Error **errp) |
38 | goto error; | 156 | { |
157 | RAMBlock *new_block; | ||
158 | Error *local_err = NULL; | ||
159 | @@ -XXX,XX +XXX,XX @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, | ||
160 | new_block->used_length = size; | ||
161 | new_block->max_length = size; | ||
162 | new_block->flags = ram_flags; | ||
163 | - new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp); | ||
164 | + new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset, | ||
165 | + errp); | ||
166 | if (!new_block->host) { | ||
167 | g_free(new_block); | ||
168 | return NULL; | ||
169 | @@ -XXX,XX +XXX,XX @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, | ||
170 | return NULL; | ||
39 | } | 171 | } |
40 | 172 | ||
173 | - block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp); | ||
174 | + block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp); | ||
175 | if (!block) { | ||
176 | if (created) { | ||
177 | unlink(mem_path); | ||
178 | diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c | ||
179 | index XXXXXXX..XXXXXXX 100644 | ||
180 | --- a/util/mmap-alloc.c | ||
181 | +++ b/util/mmap-alloc.c | ||
182 | @@ -XXX,XX +XXX,XX @@ void *qemu_ram_mmap(int fd, | ||
183 | size_t size, | ||
184 | size_t align, | ||
185 | bool shared, | ||
186 | - bool is_pmem) | ||
187 | + bool is_pmem, | ||
188 | + off_t map_offset) | ||
189 | { | ||
190 | int flags; | ||
191 | int map_sync_flags = 0; | ||
192 | @@ -XXX,XX +XXX,XX @@ void *qemu_ram_mmap(int fd, | ||
193 | offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; | ||
194 | |||
195 | ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, | ||
196 | - flags | map_sync_flags, fd, 0); | ||
197 | + flags | map_sync_flags, fd, map_offset); | ||
198 | |||
199 | if (ptr == MAP_FAILED && map_sync_flags) { | ||
200 | if (errno == ENOTSUP) { | ||
201 | @@ -XXX,XX +XXX,XX @@ void *qemu_ram_mmap(int fd, | ||
202 | * we will remove these flags to handle compatibility. | ||
203 | */ | ||
204 | ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, | ||
205 | - flags, fd, 0); | ||
206 | + flags, fd, map_offset); | ||
207 | } | ||
208 | |||
209 | if (ptr == MAP_FAILED) { | ||
210 | diff --git a/util/oslib-posix.c b/util/oslib-posix.c | ||
211 | index XXXXXXX..XXXXXXX 100644 | ||
212 | --- a/util/oslib-posix.c | ||
213 | +++ b/util/oslib-posix.c | ||
214 | @@ -XXX,XX +XXX,XX @@ void *qemu_memalign(size_t alignment, size_t size) | ||
215 | void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) | ||
216 | { | ||
217 | size_t align = QEMU_VMALLOC_ALIGN; | ||
218 | - void *ptr = qemu_ram_mmap(-1, size, align, shared, false); | ||
219 | + void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0); | ||
220 | |||
221 | if (ptr == MAP_FAILED) { | ||
222 | return NULL; | ||
41 | -- | 223 | -- |
42 | 2.9.3 | 224 | 2.29.2 |
43 | 225 | ||
44 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jagannathan Raman <jag.raman@oracle.com> | ||
1 | 2 | ||
3 | Add configuration options to enable or disable multiprocess QEMU code | ||
4 | |||
5 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
6 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
7 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Message-id: 6cc37253e35418ebd7b675a31a3df6e3c7a12dc1.1611938319.git.jag.raman@oracle.com | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | --- | ||
12 | configure | 10 ++++++++++ | ||
13 | meson.build | 4 +++- | ||
14 | Kconfig.host | 4 ++++ | ||
15 | hw/Kconfig | 1 + | ||
16 | hw/remote/Kconfig | 3 +++ | ||
17 | 5 files changed, 21 insertions(+), 1 deletion(-) | ||
18 | create mode 100644 hw/remote/Kconfig | ||
19 | |||
20 | diff --git a/configure b/configure | ||
21 | index XXXXXXX..XXXXXXX 100755 | ||
22 | --- a/configure | ||
23 | +++ b/configure | ||
24 | @@ -XXX,XX +XXX,XX @@ skip_meson=no | ||
25 | gettext="auto" | ||
26 | fuse="auto" | ||
27 | fuse_lseek="auto" | ||
28 | +multiprocess="no" | ||
29 | |||
30 | malloc_trim="auto" | ||
31 | |||
32 | @@ -XXX,XX +XXX,XX @@ Linux) | ||
33 | linux="yes" | ||
34 | linux_user="yes" | ||
35 | vhost_user=${default_feature:-yes} | ||
36 | + multiprocess=${default_feature:-yes} | ||
37 | ;; | ||
38 | esac | ||
39 | |||
40 | @@ -XXX,XX +XXX,XX @@ for opt do | ||
41 | ;; | ||
42 | --disable-fuse-lseek) fuse_lseek="disabled" | ||
43 | ;; | ||
44 | + --enable-multiprocess) multiprocess="yes" | ||
45 | + ;; | ||
46 | + --disable-multiprocess) multiprocess="no" | ||
47 | + ;; | ||
48 | *) | ||
49 | echo "ERROR: unknown option $opt" | ||
50 | echo "Try '$0 --help' for more information" | ||
51 | @@ -XXX,XX +XXX,XX @@ disabled with --disable-FEATURE, default is enabled if available | ||
52 | libdaxctl libdaxctl support | ||
53 | fuse FUSE block device export | ||
54 | fuse-lseek SEEK_HOLE/SEEK_DATA support for FUSE exports | ||
55 | + multiprocess Multiprocess QEMU support | ||
56 | |||
57 | NOTE: The object files are built at the place where configure is launched | ||
58 | EOF | ||
59 | @@ -XXX,XX +XXX,XX @@ fi | ||
60 | if test "$have_mlockall" = "yes" ; then | ||
61 | echo "HAVE_MLOCKALL=y" >> $config_host_mak | ||
62 | fi | ||
63 | +if test "$multiprocess" = "yes" ; then | ||
64 | + echo "CONFIG_MULTIPROCESS_ALLOWED=y" >> $config_host_mak | ||
65 | +fi | ||
66 | if test "$fuzzing" = "yes" ; then | ||
67 | # If LIB_FUZZING_ENGINE is set, assume we are running on OSS-Fuzz, and the | ||
68 | # needed CFLAGS have already been provided | ||
69 | diff --git a/meson.build b/meson.build | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/meson.build | ||
72 | +++ b/meson.build | ||
73 | @@ -XXX,XX +XXX,XX @@ host_kconfig = \ | ||
74 | ('CONFIG_VHOST_KERNEL' in config_host ? ['CONFIG_VHOST_KERNEL=y'] : []) + \ | ||
75 | (have_virtfs ? ['CONFIG_VIRTFS=y'] : []) + \ | ||
76 | ('CONFIG_LINUX' in config_host ? ['CONFIG_LINUX=y'] : []) + \ | ||
77 | - ('CONFIG_PVRDMA' in config_host ? ['CONFIG_PVRDMA=y'] : []) | ||
78 | + ('CONFIG_PVRDMA' in config_host ? ['CONFIG_PVRDMA=y'] : []) + \ | ||
79 | + ('CONFIG_MULTIPROCESS_ALLOWED' in config_host ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) | ||
80 | |||
81 | ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ] | ||
82 | |||
83 | @@ -XXX,XX +XXX,XX @@ summary_info += {'libpmem support': config_host.has_key('CONFIG_LIBPMEM')} | ||
84 | summary_info += {'libdaxctl support': config_host.has_key('CONFIG_LIBDAXCTL')} | ||
85 | summary_info += {'libudev': libudev.found()} | ||
86 | summary_info += {'FUSE lseek': fuse_lseek.found()} | ||
87 | +summary_info += {'Multiprocess QEMU': config_host.has_key('CONFIG_MULTIPROCESS_ALLOWED')} | ||
88 | summary(summary_info, bool_yn: true, section: 'Dependencies') | ||
89 | |||
90 | if not supported_cpus.contains(cpu) | ||
91 | diff --git a/Kconfig.host b/Kconfig.host | ||
92 | index XXXXXXX..XXXXXXX 100644 | ||
93 | --- a/Kconfig.host | ||
94 | +++ b/Kconfig.host | ||
95 | @@ -XXX,XX +XXX,XX @@ config VIRTFS | ||
96 | |||
97 | config PVRDMA | ||
98 | bool | ||
99 | + | ||
100 | +config MULTIPROCESS_ALLOWED | ||
101 | + bool | ||
102 | + imply MULTIPROCESS | ||
103 | diff --git a/hw/Kconfig b/hw/Kconfig | ||
104 | index XXXXXXX..XXXXXXX 100644 | ||
105 | --- a/hw/Kconfig | ||
106 | +++ b/hw/Kconfig | ||
107 | @@ -XXX,XX +XXX,XX @@ source pci-host/Kconfig | ||
108 | source pcmcia/Kconfig | ||
109 | source pci/Kconfig | ||
110 | source rdma/Kconfig | ||
111 | +source remote/Kconfig | ||
112 | source rtc/Kconfig | ||
113 | source scsi/Kconfig | ||
114 | source sd/Kconfig | ||
115 | diff --git a/hw/remote/Kconfig b/hw/remote/Kconfig | ||
116 | new file mode 100644 | ||
117 | index XXXXXXX..XXXXXXX | ||
118 | --- /dev/null | ||
119 | +++ b/hw/remote/Kconfig | ||
120 | @@ -XXX,XX +XXX,XX @@ | ||
121 | +config MULTIPROCESS | ||
122 | + bool | ||
123 | + depends on PCI && KVM | ||
124 | -- | ||
125 | 2.29.2 | ||
126 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jagannathan Raman <jag.raman@oracle.com> | ||
1 | 2 | ||
3 | PCI host bridge is setup for the remote device process. It is | ||
4 | implemented using remote-pcihost object. It is an extension of the PCI | ||
5 | host bridge setup by QEMU. | ||
6 | Remote-pcihost configures a PCI bus which could be used by the remote | ||
7 | PCI device to latch on to. | ||
8 | |||
9 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
10 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
11 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
12 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Message-id: 0871ba857abb2eafacde07e7fe66a3f12415bfb2.1611938319.git.jag.raman@oracle.com | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | --- | ||
16 | MAINTAINERS | 2 + | ||
17 | include/hw/pci-host/remote.h | 29 ++++++++++++++ | ||
18 | hw/pci-host/remote.c | 75 ++++++++++++++++++++++++++++++++++++ | ||
19 | hw/pci-host/Kconfig | 3 ++ | ||
20 | hw/pci-host/meson.build | 1 + | ||
21 | hw/remote/Kconfig | 1 + | ||
22 | 6 files changed, 111 insertions(+) | ||
23 | create mode 100644 include/hw/pci-host/remote.h | ||
24 | create mode 100644 hw/pci-host/remote.c | ||
25 | |||
26 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/MAINTAINERS | ||
29 | +++ b/MAINTAINERS | ||
30 | @@ -XXX,XX +XXX,XX @@ M: John G Johnson <john.g.johnson@oracle.com> | ||
31 | S: Maintained | ||
32 | F: docs/devel/multi-process.rst | ||
33 | F: docs/system/multi-process.rst | ||
34 | +F: hw/pci-host/remote.c | ||
35 | +F: include/hw/pci-host/remote.h | ||
36 | |||
37 | Build and test automation | ||
38 | ------------------------- | ||
39 | diff --git a/include/hw/pci-host/remote.h b/include/hw/pci-host/remote.h | ||
40 | new file mode 100644 | ||
41 | index XXXXXXX..XXXXXXX | ||
42 | --- /dev/null | ||
43 | +++ b/include/hw/pci-host/remote.h | ||
44 | @@ -XXX,XX +XXX,XX @@ | ||
45 | +/* | ||
46 | + * PCI Host for remote device | ||
47 | + * | ||
48 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | ||
49 | + * | ||
50 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
51 | + * See the COPYING file in the top-level directory. | ||
52 | + * | ||
53 | + */ | ||
54 | + | ||
55 | +#ifndef REMOTE_PCIHOST_H | ||
56 | +#define REMOTE_PCIHOST_H | ||
57 | + | ||
58 | +#include "exec/memory.h" | ||
59 | +#include "hw/pci/pcie_host.h" | ||
60 | + | ||
61 | +#define TYPE_REMOTE_PCIHOST "remote-pcihost" | ||
62 | +OBJECT_DECLARE_SIMPLE_TYPE(RemotePCIHost, REMOTE_PCIHOST) | ||
63 | + | ||
64 | +struct RemotePCIHost { | ||
65 | + /*< private >*/ | ||
66 | + PCIExpressHost parent_obj; | ||
67 | + /*< public >*/ | ||
68 | + | ||
69 | + MemoryRegion *mr_pci_mem; | ||
70 | + MemoryRegion *mr_sys_io; | ||
71 | +}; | ||
72 | + | ||
73 | +#endif | ||
74 | diff --git a/hw/pci-host/remote.c b/hw/pci-host/remote.c | ||
75 | new file mode 100644 | ||
76 | index XXXXXXX..XXXXXXX | ||
77 | --- /dev/null | ||
78 | +++ b/hw/pci-host/remote.c | ||
79 | @@ -XXX,XX +XXX,XX @@ | ||
80 | +/* | ||
81 | + * Remote PCI host device | ||
82 | + * | ||
83 | + * Unlike PCI host devices that model physical hardware, the purpose | ||
84 | + * of this PCI host is to host multi-process QEMU devices. | ||
85 | + * | ||
86 | + * Multi-process QEMU extends the PCI host of a QEMU machine into a | ||
87 | + * remote process. Any PCI device attached to the remote process is | ||
88 | + * visible in the QEMU guest. This allows existing QEMU device models | ||
89 | + * to be reused in the remote process. | ||
90 | + * | ||
91 | + * This PCI host is purely a container for PCI devices. It's fake in the | ||
92 | + * sense that the guest never sees this PCI host and has no way of | ||
93 | + * accessing it. Its job is just to provide the environment that QEMU | ||
94 | + * PCI device models need when running in a remote process. | ||
95 | + * | ||
96 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | ||
97 | + * | ||
98 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
99 | + * See the COPYING file in the top-level directory. | ||
100 | + * | ||
101 | + */ | ||
102 | + | ||
103 | +#include "qemu/osdep.h" | ||
104 | +#include "qemu-common.h" | ||
105 | + | ||
106 | +#include "hw/pci/pci.h" | ||
107 | +#include "hw/pci/pci_host.h" | ||
108 | +#include "hw/pci/pcie_host.h" | ||
109 | +#include "hw/qdev-properties.h" | ||
110 | +#include "hw/pci-host/remote.h" | ||
111 | +#include "exec/memory.h" | ||
112 | + | ||
113 | +static const char *remote_pcihost_root_bus_path(PCIHostState *host_bridge, | ||
114 | + PCIBus *rootbus) | ||
115 | +{ | ||
116 | + return "0000:00"; | ||
117 | +} | ||
118 | + | ||
119 | +static void remote_pcihost_realize(DeviceState *dev, Error **errp) | ||
120 | +{ | ||
121 | + PCIHostState *pci = PCI_HOST_BRIDGE(dev); | ||
122 | + RemotePCIHost *s = REMOTE_PCIHOST(dev); | ||
123 | + | ||
124 | + pci->bus = pci_root_bus_new(DEVICE(s), "remote-pci", | ||
125 | + s->mr_pci_mem, s->mr_sys_io, | ||
126 | + 0, TYPE_PCIE_BUS); | ||
127 | +} | ||
128 | + | ||
129 | +static void remote_pcihost_class_init(ObjectClass *klass, void *data) | ||
130 | +{ | ||
131 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
132 | + PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass); | ||
133 | + | ||
134 | + hc->root_bus_path = remote_pcihost_root_bus_path; | ||
135 | + dc->realize = remote_pcihost_realize; | ||
136 | + | ||
137 | + dc->user_creatable = false; | ||
138 | + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); | ||
139 | + dc->fw_name = "pci"; | ||
140 | +} | ||
141 | + | ||
142 | +static const TypeInfo remote_pcihost_info = { | ||
143 | + .name = TYPE_REMOTE_PCIHOST, | ||
144 | + .parent = TYPE_PCIE_HOST_BRIDGE, | ||
145 | + .instance_size = sizeof(RemotePCIHost), | ||
146 | + .class_init = remote_pcihost_class_init, | ||
147 | +}; | ||
148 | + | ||
149 | +static void remote_pcihost_register(void) | ||
150 | +{ | ||
151 | + type_register_static(&remote_pcihost_info); | ||
152 | +} | ||
153 | + | ||
154 | +type_init(remote_pcihost_register) | ||
155 | diff --git a/hw/pci-host/Kconfig b/hw/pci-host/Kconfig | ||
156 | index XXXXXXX..XXXXXXX 100644 | ||
157 | --- a/hw/pci-host/Kconfig | ||
158 | +++ b/hw/pci-host/Kconfig | ||
159 | @@ -XXX,XX +XXX,XX @@ config PCI_POWERNV | ||
160 | select PCI_EXPRESS | ||
161 | select MSI_NONBROKEN | ||
162 | select PCIE_PORT | ||
163 | + | ||
164 | +config REMOTE_PCIHOST | ||
165 | + bool | ||
166 | diff --git a/hw/pci-host/meson.build b/hw/pci-host/meson.build | ||
167 | index XXXXXXX..XXXXXXX 100644 | ||
168 | --- a/hw/pci-host/meson.build | ||
169 | +++ b/hw/pci-host/meson.build | ||
170 | @@ -XXX,XX +XXX,XX @@ pci_ss.add(when: 'CONFIG_PCI_EXPRESS_XILINX', if_true: files('xilinx-pcie.c')) | ||
171 | pci_ss.add(when: 'CONFIG_PCI_I440FX', if_true: files('i440fx.c')) | ||
172 | pci_ss.add(when: 'CONFIG_PCI_SABRE', if_true: files('sabre.c')) | ||
173 | pci_ss.add(when: 'CONFIG_XEN_IGD_PASSTHROUGH', if_true: files('xen_igd_pt.c')) | ||
174 | +pci_ss.add(when: 'CONFIG_REMOTE_PCIHOST', if_true: files('remote.c')) | ||
175 | |||
176 | # PPC devices | ||
177 | pci_ss.add(when: 'CONFIG_PREP_PCI', if_true: files('prep.c')) | ||
178 | diff --git a/hw/remote/Kconfig b/hw/remote/Kconfig | ||
179 | index XXXXXXX..XXXXXXX 100644 | ||
180 | --- a/hw/remote/Kconfig | ||
181 | +++ b/hw/remote/Kconfig | ||
182 | @@ -XXX,XX +XXX,XX @@ | ||
183 | config MULTIPROCESS | ||
184 | bool | ||
185 | depends on PCI && KVM | ||
186 | + select REMOTE_PCIHOST | ||
187 | -- | ||
188 | 2.29.2 | ||
189 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jagannathan Raman <jag.raman@oracle.com> | ||
1 | 2 | ||
3 | x-remote-machine object sets up various subsystems of the remote | ||
4 | device process. Instantiate PCI host bridge object and initialize RAM, IO & | ||
5 | PCI memory regions. | ||
6 | |||
7 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
8 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
9 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | Message-id: c537f38d17f90453ca610c6b70cf3480274e0ba1.1611938319.git.jag.raman@oracle.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | --- | ||
14 | MAINTAINERS | 2 ++ | ||
15 | include/hw/pci-host/remote.h | 1 + | ||
16 | include/hw/remote/machine.h | 27 ++++++++++++++ | ||
17 | hw/remote/machine.c | 70 ++++++++++++++++++++++++++++++++++++ | ||
18 | hw/meson.build | 1 + | ||
19 | hw/remote/meson.build | 5 +++ | ||
20 | 6 files changed, 106 insertions(+) | ||
21 | create mode 100644 include/hw/remote/machine.h | ||
22 | create mode 100644 hw/remote/machine.c | ||
23 | create mode 100644 hw/remote/meson.build | ||
24 | |||
25 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/MAINTAINERS | ||
28 | +++ b/MAINTAINERS | ||
29 | @@ -XXX,XX +XXX,XX @@ F: docs/devel/multi-process.rst | ||
30 | F: docs/system/multi-process.rst | ||
31 | F: hw/pci-host/remote.c | ||
32 | F: include/hw/pci-host/remote.h | ||
33 | +F: hw/remote/machine.c | ||
34 | +F: include/hw/remote/machine.h | ||
35 | |||
36 | Build and test automation | ||
37 | ------------------------- | ||
38 | diff --git a/include/hw/pci-host/remote.h b/include/hw/pci-host/remote.h | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/include/hw/pci-host/remote.h | ||
41 | +++ b/include/hw/pci-host/remote.h | ||
42 | @@ -XXX,XX +XXX,XX @@ struct RemotePCIHost { | ||
43 | |||
44 | MemoryRegion *mr_pci_mem; | ||
45 | MemoryRegion *mr_sys_io; | ||
46 | + MemoryRegion *mr_sys_mem; | ||
47 | }; | ||
48 | |||
49 | #endif | ||
50 | diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h | ||
51 | new file mode 100644 | ||
52 | index XXXXXXX..XXXXXXX | ||
53 | --- /dev/null | ||
54 | +++ b/include/hw/remote/machine.h | ||
55 | @@ -XXX,XX +XXX,XX @@ | ||
56 | +/* | ||
57 | + * Remote machine configuration | ||
58 | + * | ||
59 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | ||
60 | + * | ||
61 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
62 | + * See the COPYING file in the top-level directory. | ||
63 | + * | ||
64 | + */ | ||
65 | + | ||
66 | +#ifndef REMOTE_MACHINE_H | ||
67 | +#define REMOTE_MACHINE_H | ||
68 | + | ||
69 | +#include "qom/object.h" | ||
70 | +#include "hw/boards.h" | ||
71 | +#include "hw/pci-host/remote.h" | ||
72 | + | ||
73 | +struct RemoteMachineState { | ||
74 | + MachineState parent_obj; | ||
75 | + | ||
76 | + RemotePCIHost *host; | ||
77 | +}; | ||
78 | + | ||
79 | +#define TYPE_REMOTE_MACHINE "x-remote-machine" | ||
80 | +OBJECT_DECLARE_SIMPLE_TYPE(RemoteMachineState, REMOTE_MACHINE) | ||
81 | + | ||
82 | +#endif | ||
83 | diff --git a/hw/remote/machine.c b/hw/remote/machine.c | ||
84 | new file mode 100644 | ||
85 | index XXXXXXX..XXXXXXX | ||
86 | --- /dev/null | ||
87 | +++ b/hw/remote/machine.c | ||
88 | @@ -XXX,XX +XXX,XX @@ | ||
89 | +/* | ||
90 | + * Machine for remote device | ||
91 | + * | ||
92 | + * This machine type is used by the remote device process in multi-process | ||
93 | + * QEMU. QEMU device models depend on parent busses, interrupt controllers, | ||
94 | + * memory regions, etc. The remote machine type offers this environment so | ||
95 | + * that QEMU device models can be used as remote devices. | ||
96 | + * | ||
97 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | ||
98 | + * | ||
99 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
100 | + * See the COPYING file in the top-level directory. | ||
101 | + * | ||
102 | + */ | ||
103 | + | ||
104 | +#include "qemu/osdep.h" | ||
105 | +#include "qemu-common.h" | ||
106 | + | ||
107 | +#include "hw/remote/machine.h" | ||
108 | +#include "exec/address-spaces.h" | ||
109 | +#include "exec/memory.h" | ||
110 | +#include "qapi/error.h" | ||
111 | + | ||
112 | +static void remote_machine_init(MachineState *machine) | ||
113 | +{ | ||
114 | + MemoryRegion *system_memory, *system_io, *pci_memory; | ||
115 | + RemoteMachineState *s = REMOTE_MACHINE(machine); | ||
116 | + RemotePCIHost *rem_host; | ||
117 | + | ||
118 | + system_memory = get_system_memory(); | ||
119 | + system_io = get_system_io(); | ||
120 | + | ||
121 | + pci_memory = g_new(MemoryRegion, 1); | ||
122 | + memory_region_init(pci_memory, NULL, "pci", UINT64_MAX); | ||
123 | + | ||
124 | + rem_host = REMOTE_PCIHOST(qdev_new(TYPE_REMOTE_PCIHOST)); | ||
125 | + | ||
126 | + rem_host->mr_pci_mem = pci_memory; | ||
127 | + rem_host->mr_sys_mem = system_memory; | ||
128 | + rem_host->mr_sys_io = system_io; | ||
129 | + | ||
130 | + s->host = rem_host; | ||
131 | + | ||
132 | + object_property_add_child(OBJECT(s), "remote-pcihost", OBJECT(rem_host)); | ||
133 | + memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1); | ||
134 | + | ||
135 | + qdev_realize(DEVICE(rem_host), sysbus_get_default(), &error_fatal); | ||
136 | +} | ||
137 | + | ||
138 | +static void remote_machine_class_init(ObjectClass *oc, void *data) | ||
139 | +{ | ||
140 | + MachineClass *mc = MACHINE_CLASS(oc); | ||
141 | + | ||
142 | + mc->init = remote_machine_init; | ||
143 | + mc->desc = "Experimental remote machine"; | ||
144 | +} | ||
145 | + | ||
146 | +static const TypeInfo remote_machine = { | ||
147 | + .name = TYPE_REMOTE_MACHINE, | ||
148 | + .parent = TYPE_MACHINE, | ||
149 | + .instance_size = sizeof(RemoteMachineState), | ||
150 | + .class_init = remote_machine_class_init, | ||
151 | +}; | ||
152 | + | ||
153 | +static void remote_machine_register_types(void) | ||
154 | +{ | ||
155 | + type_register_static(&remote_machine); | ||
156 | +} | ||
157 | + | ||
158 | +type_init(remote_machine_register_types); | ||
159 | diff --git a/hw/meson.build b/hw/meson.build | ||
160 | index XXXXXXX..XXXXXXX 100644 | ||
161 | --- a/hw/meson.build | ||
162 | +++ b/hw/meson.build | ||
163 | @@ -XXX,XX +XXX,XX @@ subdir('moxie') | ||
164 | subdir('nios2') | ||
165 | subdir('openrisc') | ||
166 | subdir('ppc') | ||
167 | +subdir('remote') | ||
168 | subdir('riscv') | ||
169 | subdir('rx') | ||
170 | subdir('s390x') | ||
171 | diff --git a/hw/remote/meson.build b/hw/remote/meson.build | ||
172 | new file mode 100644 | ||
173 | index XXXXXXX..XXXXXXX | ||
174 | --- /dev/null | ||
175 | +++ b/hw/remote/meson.build | ||
176 | @@ -XXX,XX +XXX,XX @@ | ||
177 | +remote_ss = ss.source_set() | ||
178 | + | ||
179 | +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('machine.c')) | ||
180 | + | ||
181 | +softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) | ||
182 | -- | ||
183 | 2.29.2 | ||
184 | diff view generated by jsdifflib |
1 | For the tests that use the common.qemu functions for running a QEMU | 1 | From: Elena Ufimtseva <elena.ufimtseva@oracle.com> |
---|---|---|---|
2 | process, _cleanup_qemu must be called in the exit function. | ||
3 | 2 | ||
4 | If it is not, if the qemu process aborts, then not all of the droppings | 3 | Adds qio_channel_writev_full_all() to transmit both data and FDs. |
5 | are cleaned up (e.g. pidfile, fifos). | 4 | Refactors existing code to use this helper. |
6 | 5 | ||
7 | This updates those tests that did not have a cleanup in qemu-iotests. | 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 | Acked-by: Daniel P. Berrangé <berrange@redhat.com> | ||
11 | Message-id: 480fbf1fe4152495d60596c9b665124549b426a5.1611938319.git.jag.raman@oracle.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | --- | ||
14 | include/io/channel.h | 25 +++++++++++++++++++++++++ | ||
15 | io/channel.c | 15 ++++++++++++++- | ||
16 | 2 files changed, 39 insertions(+), 1 deletion(-) | ||
8 | 17 | ||
9 | (I swapped spaces for tabs in test 102 as well) | 18 | diff --git a/include/io/channel.h b/include/io/channel.h |
10 | 19 | index XXXXXXX..XXXXXXX 100644 | |
11 | Reported-by: Eric Blake <eblake@redhat.com> | 20 | --- a/include/io/channel.h |
12 | Reviewed-by: Eric Blake <eblake@redhat.com> | 21 | +++ b/include/io/channel.h |
13 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 22 | @@ -XXX,XX +XXX,XX @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, |
14 | Message-id: d59c2f6ad6c1da8b9b3c7f357c94a7122ccfc55a.1492544096.git.jcody@redhat.com | 23 | IOHandler *io_write, |
15 | --- | 24 | void *opaque); |
16 | tests/qemu-iotests/028 | 1 + | 25 | |
17 | tests/qemu-iotests/094 | 11 ++++++++--- | 26 | +/** |
18 | tests/qemu-iotests/102 | 5 +++-- | 27 | + * qio_channel_writev_full_all: |
19 | tests/qemu-iotests/109 | 1 + | 28 | + * @ioc: the channel object |
20 | tests/qemu-iotests/117 | 1 + | 29 | + * @iov: the array of memory regions to write data from |
21 | tests/qemu-iotests/130 | 1 + | 30 | + * @niov: the length of the @iov array |
22 | tests/qemu-iotests/140 | 1 + | 31 | + * @fds: an array of file handles to send |
23 | tests/qemu-iotests/141 | 1 + | 32 | + * @nfds: number of file handles in @fds |
24 | tests/qemu-iotests/143 | 1 + | 33 | + * @errp: pointer to a NULL-initialized error object |
25 | tests/qemu-iotests/156 | 1 + | 34 | + * |
26 | 10 files changed, 19 insertions(+), 5 deletions(-) | 35 | + * |
27 | 36 | + * Behaves like qio_channel_writev_full but will attempt | |
28 | diff --git a/tests/qemu-iotests/028 b/tests/qemu-iotests/028 | 37 | + * to send all data passed (file handles and memory regions). |
29 | index XXXXXXX..XXXXXXX 100755 | 38 | + * The function will wait for all requested data |
30 | --- a/tests/qemu-iotests/028 | 39 | + * to be written, yielding from the current coroutine |
31 | +++ b/tests/qemu-iotests/028 | 40 | + * if required. |
32 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | 41 | + * |
33 | 42 | + * Returns: 0 if all bytes were written, or -1 on error | |
34 | _cleanup() | 43 | + */ |
35 | { | 44 | + |
36 | + _cleanup_qemu | 45 | +int qio_channel_writev_full_all(QIOChannel *ioc, |
37 | rm -f "${TEST_IMG}.copy" | 46 | + const struct iovec *iov, |
38 | _cleanup_test_img | 47 | + size_t niov, |
39 | } | 48 | + int *fds, size_t nfds, |
40 | diff --git a/tests/qemu-iotests/094 b/tests/qemu-iotests/094 | 49 | + Error **errp); |
41 | index XXXXXXX..XXXXXXX 100755 | 50 | + |
42 | --- a/tests/qemu-iotests/094 | 51 | #endif /* QIO_CHANNEL_H */ |
43 | +++ b/tests/qemu-iotests/094 | 52 | diff --git a/io/channel.c b/io/channel.c |
44 | @@ -XXX,XX +XXX,XX @@ echo "QA output created by $seq" | 53 | index XXXXXXX..XXXXXXX 100644 |
45 | here="$PWD" | 54 | --- a/io/channel.c |
46 | status=1 # failure is the default! | 55 | +++ b/io/channel.c |
47 | 56 | @@ -XXX,XX +XXX,XX @@ int qio_channel_writev_all(QIOChannel *ioc, | |
48 | -trap "exit \$status" 0 1 2 3 15 | 57 | const struct iovec *iov, |
49 | +_cleanup() | 58 | size_t niov, |
59 | Error **errp) | ||
50 | +{ | 60 | +{ |
51 | + _cleanup_qemu | 61 | + return qio_channel_writev_full_all(ioc, iov, niov, NULL, 0, errp); |
52 | + _cleanup_test_img | ||
53 | + rm -f "$TEST_DIR/source.$IMGFMT" | ||
54 | +} | 62 | +} |
55 | + | 63 | + |
56 | +trap "_cleanup; exit \$status" 0 1 2 3 15 | 64 | +int qio_channel_writev_full_all(QIOChannel *ioc, |
57 | 65 | + const struct iovec *iov, | |
58 | # get standard environment, filters and checks | 66 | + size_t niov, |
59 | . ./common.rc | 67 | + int *fds, size_t nfds, |
60 | @@ -XXX,XX +XXX,XX @@ _send_qemu_cmd $QEMU_HANDLE \ | 68 | + Error **errp) |
61 | |||
62 | wait=1 _cleanup_qemu | ||
63 | |||
64 | -_cleanup_test_img | ||
65 | -rm -f "$TEST_DIR/source.$IMGFMT" | ||
66 | |||
67 | # success, all done | ||
68 | echo '*** done' | ||
69 | diff --git a/tests/qemu-iotests/102 b/tests/qemu-iotests/102 | ||
70 | index XXXXXXX..XXXXXXX 100755 | ||
71 | --- a/tests/qemu-iotests/102 | ||
72 | +++ b/tests/qemu-iotests/102 | ||
73 | @@ -XXX,XX +XXX,XX @@ seq=$(basename $0) | ||
74 | echo "QA output created by $seq" | ||
75 | |||
76 | here=$PWD | ||
77 | -status=1 # failure is the default! | ||
78 | +status=1 # failure is the default! | ||
79 | |||
80 | _cleanup() | ||
81 | { | 69 | { |
82 | - _cleanup_test_img | 70 | int ret = -1; |
83 | + _cleanup_qemu | 71 | struct iovec *local_iov = g_new(struct iovec, niov); |
84 | + _cleanup_test_img | 72 | @@ -XXX,XX +XXX,XX @@ int qio_channel_writev_all(QIOChannel *ioc, |
85 | } | 73 | |
86 | trap "_cleanup; exit \$status" 0 1 2 3 15 | 74 | while (nlocal_iov > 0) { |
87 | 75 | ssize_t len; | |
88 | diff --git a/tests/qemu-iotests/109 b/tests/qemu-iotests/109 | 76 | - len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp); |
89 | index XXXXXXX..XXXXXXX 100755 | 77 | + len = qio_channel_writev_full(ioc, local_iov, nlocal_iov, fds, nfds, |
90 | --- a/tests/qemu-iotests/109 | 78 | + errp); |
91 | +++ b/tests/qemu-iotests/109 | 79 | if (len == QIO_CHANNEL_ERR_BLOCK) { |
92 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | 80 | if (qemu_in_coroutine()) { |
93 | 81 | qio_channel_yield(ioc, G_IO_OUT); | |
94 | _cleanup() | 82 | @@ -XXX,XX +XXX,XX @@ int qio_channel_writev_all(QIOChannel *ioc, |
95 | { | 83 | } |
96 | + _cleanup_qemu | 84 | |
97 | rm -f $TEST_IMG.src | 85 | iov_discard_front(&local_iov, &nlocal_iov, len); |
98 | _cleanup_test_img | 86 | + |
99 | } | 87 | + fds = NULL; |
100 | diff --git a/tests/qemu-iotests/117 b/tests/qemu-iotests/117 | 88 | + nfds = 0; |
101 | index XXXXXXX..XXXXXXX 100755 | 89 | } |
102 | --- a/tests/qemu-iotests/117 | 90 | |
103 | +++ b/tests/qemu-iotests/117 | 91 | ret = 0; |
104 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
105 | |||
106 | _cleanup() | ||
107 | { | ||
108 | + _cleanup_qemu | ||
109 | _cleanup_test_img | ||
110 | } | ||
111 | trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
112 | diff --git a/tests/qemu-iotests/130 b/tests/qemu-iotests/130 | ||
113 | index XXXXXXX..XXXXXXX 100755 | ||
114 | --- a/tests/qemu-iotests/130 | ||
115 | +++ b/tests/qemu-iotests/130 | ||
116 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
117 | |||
118 | _cleanup() | ||
119 | { | ||
120 | + _cleanup_qemu | ||
121 | _cleanup_test_img | ||
122 | } | ||
123 | trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
124 | diff --git a/tests/qemu-iotests/140 b/tests/qemu-iotests/140 | ||
125 | index XXXXXXX..XXXXXXX 100755 | ||
126 | --- a/tests/qemu-iotests/140 | ||
127 | +++ b/tests/qemu-iotests/140 | ||
128 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
129 | |||
130 | _cleanup() | ||
131 | { | ||
132 | + _cleanup_qemu | ||
133 | _cleanup_test_img | ||
134 | rm -f "$TEST_DIR/nbd" | ||
135 | } | ||
136 | diff --git a/tests/qemu-iotests/141 b/tests/qemu-iotests/141 | ||
137 | index XXXXXXX..XXXXXXX 100755 | ||
138 | --- a/tests/qemu-iotests/141 | ||
139 | +++ b/tests/qemu-iotests/141 | ||
140 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
141 | |||
142 | _cleanup() | ||
143 | { | ||
144 | + _cleanup_qemu | ||
145 | _cleanup_test_img | ||
146 | rm -f "$TEST_DIR/{b,m,o}.$IMGFMT" | ||
147 | } | ||
148 | diff --git a/tests/qemu-iotests/143 b/tests/qemu-iotests/143 | ||
149 | index XXXXXXX..XXXXXXX 100755 | ||
150 | --- a/tests/qemu-iotests/143 | ||
151 | +++ b/tests/qemu-iotests/143 | ||
152 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
153 | |||
154 | _cleanup() | ||
155 | { | ||
156 | + _cleanup_qemu | ||
157 | rm -f "$TEST_DIR/nbd" | ||
158 | } | ||
159 | trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
160 | diff --git a/tests/qemu-iotests/156 b/tests/qemu-iotests/156 | ||
161 | index XXXXXXX..XXXXXXX 100755 | ||
162 | --- a/tests/qemu-iotests/156 | ||
163 | +++ b/tests/qemu-iotests/156 | ||
164 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
165 | |||
166 | _cleanup() | ||
167 | { | ||
168 | + _cleanup_qemu | ||
169 | rm -f "$TEST_IMG{,.target}{,.backing,.overlay}" | ||
170 | } | ||
171 | trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
172 | -- | 92 | -- |
173 | 2.9.3 | 93 | 2.29.2 |
174 | 94 | ||
175 | diff view generated by jsdifflib |
1 | Update 'clientname' to be 'user', which tracks better with both | 1 | From: Elena Ufimtseva <elena.ufimtseva@oracle.com> |
---|---|---|---|
2 | the QAPI and rados variable naming. | 2 | |
3 | 3 | Adds qio_channel_readv_full_all_eof() and qio_channel_readv_full_all() | |
4 | Update 'name' to be 'image_name', as it indicates the rbd image. | 4 | to read both data and FDs. Refactors existing code to use these helpers. |
5 | Naming it 'image' would have been ideal, but we are using that for | 5 | |
6 | the rados_image_t value returned by rbd_open(). | 6 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> |
7 | 7 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | |
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 8 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> |
9 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 9 | Acked-by: Daniel P. Berrangé <berrange@redhat.com> |
10 | Reviewed-by: John Snow <jsnow@redhat.com> | 10 | Message-id: b059c4cc0fb741e794d644c144cc21372cad877d.1611938319.git.jag.raman@oracle.com |
11 | Message-id: b7ec1fb2e1cf36f9b6911631447a5b0422590b7d.1491597120.git.jcody@redhat.com | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 12 | --- |
13 | block/rbd.c | 33 +++++++++++++++++---------------- | 13 | include/io/channel.h | 53 +++++++++++++++++++++++ |
14 | 1 file changed, 17 insertions(+), 16 deletions(-) | 14 | io/channel.c | 101 ++++++++++++++++++++++++++++++++++--------- |
15 | 15 | 2 files changed, 134 insertions(+), 20 deletions(-) | |
16 | diff --git a/block/rbd.c b/block/rbd.c | 16 | |
17 | diff --git a/include/io/channel.h b/include/io/channel.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/block/rbd.c | 19 | --- a/include/io/channel.h |
19 | +++ b/block/rbd.c | 20 | +++ b/include/io/channel.h |
20 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVRBDState { | 21 | @@ -XXX,XX +XXX,XX @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, |
21 | rados_t cluster; | 22 | IOHandler *io_write, |
22 | rados_ioctx_t io_ctx; | 23 | void *opaque); |
23 | rbd_image_t image; | 24 | |
24 | - char *name; | 25 | +/** |
25 | + char *image_name; | 26 | + * qio_channel_readv_full_all_eof: |
26 | char *snap; | 27 | + * @ioc: the channel object |
27 | } BDRVRBDState; | 28 | + * @iov: the array of memory regions to read data to |
28 | 29 | + * @niov: the length of the @iov array | |
29 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp) | 30 | + * @fds: an array of file handles to read |
30 | int64_t bytes = 0; | 31 | + * @nfds: number of file handles in @fds |
31 | int64_t objsize; | 32 | + * @errp: pointer to a NULL-initialized error object |
32 | int obj_order = 0; | 33 | + * |
33 | - const char *pool, *name, *conf, *clientname, *keypairs; | 34 | + * |
34 | + const char *pool, *image_name, *conf, *user, *keypairs; | 35 | + * Performs same function as qio_channel_readv_all_eof. |
35 | const char *secretid; | 36 | + * Additionally, attempts to read file descriptors shared |
36 | rados_t cluster; | 37 | + * over the channel. The function will wait for all |
37 | rados_ioctx_t io_ctx; | 38 | + * requested data to be read, yielding from the current |
38 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp) | 39 | + * coroutine if required. data refers to both file |
39 | */ | 40 | + * descriptors and the iovs. |
40 | pool = qdict_get_try_str(options, "pool"); | 41 | + * |
41 | conf = qdict_get_try_str(options, "conf"); | 42 | + * Returns: 1 if all bytes were read, 0 if end-of-file |
42 | - clientname = qdict_get_try_str(options, "user"); | 43 | + * occurs without data, or -1 on error |
43 | - name = qdict_get_try_str(options, "image"); | 44 | + */ |
44 | + user = qdict_get_try_str(options, "user"); | 45 | + |
45 | + image_name = qdict_get_try_str(options, "image"); | 46 | +int qio_channel_readv_full_all_eof(QIOChannel *ioc, |
46 | keypairs = qdict_get_try_str(options, "=keyvalue-pairs"); | 47 | + const struct iovec *iov, |
47 | 48 | + size_t niov, | |
48 | - ret = rados_create(&cluster, clientname); | 49 | + int **fds, size_t *nfds, |
49 | + ret = rados_create(&cluster, user); | 50 | + Error **errp); |
50 | if (ret < 0) { | 51 | + |
51 | error_setg_errno(errp, -ret, "error initializing"); | 52 | +/** |
52 | goto exit; | 53 | + * qio_channel_readv_full_all: |
53 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp) | 54 | + * @ioc: the channel object |
54 | goto shutdown; | 55 | + * @iov: the array of memory regions to read data to |
56 | + * @niov: the length of the @iov array | ||
57 | + * @fds: an array of file handles to read | ||
58 | + * @nfds: number of file handles in @fds | ||
59 | + * @errp: pointer to a NULL-initialized error object | ||
60 | + * | ||
61 | + * | ||
62 | + * Performs same function as qio_channel_readv_all_eof. | ||
63 | + * Additionally, attempts to read file descriptors shared | ||
64 | + * over the channel. The function will wait for all | ||
65 | + * requested data to be read, yielding from the current | ||
66 | + * coroutine if required. data refers to both file | ||
67 | + * descriptors and the iovs. | ||
68 | + * | ||
69 | + * Returns: 0 if all bytes were read, or -1 on error | ||
70 | + */ | ||
71 | + | ||
72 | +int qio_channel_readv_full_all(QIOChannel *ioc, | ||
73 | + const struct iovec *iov, | ||
74 | + size_t niov, | ||
75 | + int **fds, size_t *nfds, | ||
76 | + Error **errp); | ||
77 | + | ||
78 | /** | ||
79 | * qio_channel_writev_full_all: | ||
80 | * @ioc: the channel object | ||
81 | diff --git a/io/channel.c b/io/channel.c | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/io/channel.c | ||
84 | +++ b/io/channel.c | ||
85 | @@ -XXX,XX +XXX,XX @@ int qio_channel_readv_all_eof(QIOChannel *ioc, | ||
86 | const struct iovec *iov, | ||
87 | size_t niov, | ||
88 | Error **errp) | ||
89 | +{ | ||
90 | + return qio_channel_readv_full_all_eof(ioc, iov, niov, NULL, NULL, errp); | ||
91 | +} | ||
92 | + | ||
93 | +int qio_channel_readv_all(QIOChannel *ioc, | ||
94 | + const struct iovec *iov, | ||
95 | + size_t niov, | ||
96 | + Error **errp) | ||
97 | +{ | ||
98 | + return qio_channel_readv_full_all(ioc, iov, niov, NULL, NULL, errp); | ||
99 | +} | ||
100 | + | ||
101 | +int qio_channel_readv_full_all_eof(QIOChannel *ioc, | ||
102 | + const struct iovec *iov, | ||
103 | + size_t niov, | ||
104 | + int **fds, size_t *nfds, | ||
105 | + Error **errp) | ||
106 | { | ||
107 | int ret = -1; | ||
108 | struct iovec *local_iov = g_new(struct iovec, niov); | ||
109 | struct iovec *local_iov_head = local_iov; | ||
110 | unsigned int nlocal_iov = niov; | ||
111 | + int **local_fds = fds; | ||
112 | + size_t *local_nfds = nfds; | ||
113 | bool partial = false; | ||
114 | |||
115 | + if (nfds) { | ||
116 | + *nfds = 0; | ||
117 | + } | ||
118 | + | ||
119 | + if (fds) { | ||
120 | + *fds = NULL; | ||
121 | + } | ||
122 | + | ||
123 | nlocal_iov = iov_copy(local_iov, nlocal_iov, | ||
124 | iov, niov, | ||
125 | 0, iov_size(iov, niov)); | ||
126 | |||
127 | - while (nlocal_iov > 0) { | ||
128 | + while ((nlocal_iov > 0) || local_fds) { | ||
129 | ssize_t len; | ||
130 | - len = qio_channel_readv(ioc, local_iov, nlocal_iov, errp); | ||
131 | + len = qio_channel_readv_full(ioc, local_iov, nlocal_iov, local_fds, | ||
132 | + local_nfds, errp); | ||
133 | if (len == QIO_CHANNEL_ERR_BLOCK) { | ||
134 | if (qemu_in_coroutine()) { | ||
135 | qio_channel_yield(ioc, G_IO_IN); | ||
136 | @@ -XXX,XX +XXX,XX @@ int qio_channel_readv_all_eof(QIOChannel *ioc, | ||
137 | qio_channel_wait(ioc, G_IO_IN); | ||
138 | } | ||
139 | continue; | ||
140 | - } else if (len < 0) { | ||
141 | - goto cleanup; | ||
142 | - } else if (len == 0) { | ||
143 | - if (partial) { | ||
144 | - error_setg(errp, | ||
145 | - "Unexpected end-of-file before all bytes were read"); | ||
146 | - } else { | ||
147 | + } | ||
148 | + | ||
149 | + if (len == 0) { | ||
150 | + if (local_nfds && *local_nfds) { | ||
151 | + /* | ||
152 | + * Got some FDs, but no data yet. This isn't an EOF | ||
153 | + * scenario (yet), so carry on to try to read data | ||
154 | + * on next loop iteration | ||
155 | + */ | ||
156 | + goto next_iter; | ||
157 | + } else if (!partial) { | ||
158 | + /* No fds and no data - EOF before any data read */ | ||
159 | ret = 0; | ||
160 | + goto cleanup; | ||
161 | + } else { | ||
162 | + len = -1; | ||
163 | + error_setg(errp, | ||
164 | + "Unexpected end-of-file before all data were read"); | ||
165 | + /* Fallthrough into len < 0 handling */ | ||
166 | + } | ||
167 | + } | ||
168 | + | ||
169 | + if (len < 0) { | ||
170 | + /* Close any FDs we previously received */ | ||
171 | + if (nfds && fds) { | ||
172 | + size_t i; | ||
173 | + for (i = 0; i < (*nfds); i++) { | ||
174 | + close((*fds)[i]); | ||
175 | + } | ||
176 | + g_free(*fds); | ||
177 | + *fds = NULL; | ||
178 | + *nfds = 0; | ||
179 | } | ||
180 | goto cleanup; | ||
181 | } | ||
182 | |||
183 | + if (nlocal_iov) { | ||
184 | + iov_discard_front(&local_iov, &nlocal_iov, len); | ||
185 | + } | ||
186 | + | ||
187 | +next_iter: | ||
188 | partial = true; | ||
189 | - iov_discard_front(&local_iov, &nlocal_iov, len); | ||
190 | + local_fds = NULL; | ||
191 | + local_nfds = NULL; | ||
55 | } | 192 | } |
56 | 193 | ||
57 | - ret = rbd_create(io_ctx, name, bytes, &obj_order); | 194 | ret = 1; |
58 | + ret = rbd_create(io_ctx, image_name, bytes, &obj_order); | 195 | @@ -XXX,XX +XXX,XX @@ int qio_channel_readv_all_eof(QIOChannel *ioc, |
59 | if (ret < 0) { | 196 | return ret; |
60 | error_setg_errno(errp, -ret, "error rbd create"); | 197 | } |
198 | |||
199 | -int qio_channel_readv_all(QIOChannel *ioc, | ||
200 | - const struct iovec *iov, | ||
201 | - size_t niov, | ||
202 | - Error **errp) | ||
203 | +int qio_channel_readv_full_all(QIOChannel *ioc, | ||
204 | + const struct iovec *iov, | ||
205 | + size_t niov, | ||
206 | + int **fds, size_t *nfds, | ||
207 | + Error **errp) | ||
208 | { | ||
209 | - int ret = qio_channel_readv_all_eof(ioc, iov, niov, errp); | ||
210 | + int ret = qio_channel_readv_full_all_eof(ioc, iov, niov, fds, nfds, errp); | ||
211 | |||
212 | if (ret == 0) { | ||
213 | - ret = -1; | ||
214 | - error_setg(errp, | ||
215 | - "Unexpected end-of-file before all bytes were read"); | ||
216 | - } else if (ret == 1) { | ||
217 | - ret = 0; | ||
218 | + error_prepend(errp, | ||
219 | + "Unexpected end-of-file before all data were read."); | ||
220 | + return -1; | ||
61 | } | 221 | } |
62 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | 222 | + if (ret == 1) { |
63 | Error **errp) | 223 | + return 0; |
64 | { | 224 | + } |
65 | BDRVRBDState *s = bs->opaque; | 225 | + |
66 | - const char *pool, *snap, *conf, *clientname, *name, *keypairs; | 226 | return ret; |
67 | + const char *pool, *snap, *conf, *user, *image_name, *keypairs; | ||
68 | const char *secretid; | ||
69 | QemuOpts *opts; | ||
70 | Error *local_err = NULL; | ||
71 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | ||
72 | pool = qemu_opt_get(opts, "pool"); | ||
73 | conf = qemu_opt_get(opts, "conf"); | ||
74 | snap = qemu_opt_get(opts, "snapshot"); | ||
75 | - clientname = qemu_opt_get(opts, "user"); | ||
76 | - name = qemu_opt_get(opts, "image"); | ||
77 | + user = qemu_opt_get(opts, "user"); | ||
78 | + image_name = qemu_opt_get(opts, "image"); | ||
79 | keypairs = qemu_opt_get(opts, "=keyvalue-pairs"); | ||
80 | |||
81 | - if (!pool || !name) { | ||
82 | + if (!pool || !image_name) { | ||
83 | error_setg(errp, "Parameters 'pool' and 'image' are required"); | ||
84 | r = -EINVAL; | ||
85 | goto failed_opts; | ||
86 | } | ||
87 | |||
88 | - r = rados_create(&s->cluster, clientname); | ||
89 | + r = rados_create(&s->cluster, user); | ||
90 | if (r < 0) { | ||
91 | error_setg_errno(errp, -r, "error initializing"); | ||
92 | goto failed_opts; | ||
93 | } | ||
94 | |||
95 | s->snap = g_strdup(snap); | ||
96 | - s->name = g_strdup(name); | ||
97 | + s->image_name = g_strdup(image_name); | ||
98 | |||
99 | /* try default location when conf=NULL, but ignore failure */ | ||
100 | r = rados_conf_read_file(s->cluster, conf); | ||
101 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | ||
102 | } | ||
103 | |||
104 | /* rbd_open is always r/w */ | ||
105 | - r = rbd_open(s->io_ctx, s->name, &s->image, s->snap); | ||
106 | + r = rbd_open(s->io_ctx, s->image_name, &s->image, s->snap); | ||
107 | if (r < 0) { | ||
108 | - error_setg_errno(errp, -r, "error reading header from %s", s->name); | ||
109 | + error_setg_errno(errp, -r, "error reading header from %s", | ||
110 | + s->image_name); | ||
111 | goto failed_open; | ||
112 | } | ||
113 | |||
114 | @@ -XXX,XX +XXX,XX @@ failed_open: | ||
115 | failed_shutdown: | ||
116 | rados_shutdown(s->cluster); | ||
117 | g_free(s->snap); | ||
118 | - g_free(s->name); | ||
119 | + g_free(s->image_name); | ||
120 | failed_opts: | ||
121 | qemu_opts_del(opts); | ||
122 | g_free(mon_host); | ||
123 | @@ -XXX,XX +XXX,XX @@ static void qemu_rbd_close(BlockDriverState *bs) | ||
124 | rbd_close(s->image); | ||
125 | rados_ioctx_destroy(s->io_ctx); | ||
126 | g_free(s->snap); | ||
127 | - g_free(s->name); | ||
128 | + g_free(s->image_name); | ||
129 | rados_shutdown(s->cluster); | ||
130 | } | 227 | } |
131 | 228 | ||
132 | -- | 229 | -- |
133 | 2.9.3 | 230 | 2.29.2 |
134 | 231 | ||
135 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
1 | 2 | ||
3 | Defines MPQemuMsg, which is the message that is sent to the remote | ||
4 | process. This message is sent over QIOChannel and is used to | ||
5 | command the remote process to perform various tasks. | ||
6 | Define transmission functions used by proxy and by remote. | ||
7 | |||
8 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
9 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
10 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
11 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Message-id: 56ca8bcf95195b2b195b08f6b9565b6d7410bce5.1611938319.git.jag.raman@oracle.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | --- | ||
15 | MAINTAINERS | 2 + | ||
16 | meson.build | 1 + | ||
17 | hw/remote/trace.h | 1 + | ||
18 | include/hw/remote/mpqemu-link.h | 63 ++++++++++ | ||
19 | include/sysemu/iothread.h | 6 + | ||
20 | hw/remote/mpqemu-link.c | 205 ++++++++++++++++++++++++++++++++ | ||
21 | iothread.c | 6 + | ||
22 | hw/remote/meson.build | 1 + | ||
23 | hw/remote/trace-events | 4 + | ||
24 | 9 files changed, 289 insertions(+) | ||
25 | create mode 100644 hw/remote/trace.h | ||
26 | create mode 100644 include/hw/remote/mpqemu-link.h | ||
27 | create mode 100644 hw/remote/mpqemu-link.c | ||
28 | create mode 100644 hw/remote/trace-events | ||
29 | |||
30 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/MAINTAINERS | ||
33 | +++ b/MAINTAINERS | ||
34 | @@ -XXX,XX +XXX,XX @@ F: hw/pci-host/remote.c | ||
35 | F: include/hw/pci-host/remote.h | ||
36 | F: hw/remote/machine.c | ||
37 | F: include/hw/remote/machine.h | ||
38 | +F: hw/remote/mpqemu-link.c | ||
39 | +F: include/hw/remote/mpqemu-link.h | ||
40 | |||
41 | Build and test automation | ||
42 | ------------------------- | ||
43 | diff --git a/meson.build b/meson.build | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/meson.build | ||
46 | +++ b/meson.build | ||
47 | @@ -XXX,XX +XXX,XX @@ if have_system | ||
48 | 'net', | ||
49 | 'softmmu', | ||
50 | 'ui', | ||
51 | + 'hw/remote', | ||
52 | ] | ||
53 | endif | ||
54 | trace_events_subdirs += [ | ||
55 | diff --git a/hw/remote/trace.h b/hw/remote/trace.h | ||
56 | new file mode 100644 | ||
57 | index XXXXXXX..XXXXXXX | ||
58 | --- /dev/null | ||
59 | +++ b/hw/remote/trace.h | ||
60 | @@ -0,0 +1 @@ | ||
61 | +#include "trace/trace-hw_remote.h" | ||
62 | diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h | ||
63 | new file mode 100644 | ||
64 | index XXXXXXX..XXXXXXX | ||
65 | --- /dev/null | ||
66 | +++ b/include/hw/remote/mpqemu-link.h | ||
67 | @@ -XXX,XX +XXX,XX @@ | ||
68 | +/* | ||
69 | + * Communication channel between QEMU and remote device process | ||
70 | + * | ||
71 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | ||
72 | + * | ||
73 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
74 | + * See the COPYING file in the top-level directory. | ||
75 | + * | ||
76 | + */ | ||
77 | + | ||
78 | +#ifndef MPQEMU_LINK_H | ||
79 | +#define MPQEMU_LINK_H | ||
80 | + | ||
81 | +#include "qom/object.h" | ||
82 | +#include "qemu/thread.h" | ||
83 | +#include "io/channel.h" | ||
84 | + | ||
85 | +#define REMOTE_MAX_FDS 8 | ||
86 | + | ||
87 | +#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data.u64) | ||
88 | + | ||
89 | +/** | ||
90 | + * MPQemuCmd: | ||
91 | + * | ||
92 | + * MPQemuCmd enum type to specify the command to be executed on the remote | ||
93 | + * device. | ||
94 | + * | ||
95 | + * This uses a private protocol between QEMU and the remote process. vfio-user | ||
96 | + * protocol would supersede this in the future. | ||
97 | + * | ||
98 | + */ | ||
99 | +typedef enum { | ||
100 | + MPQEMU_CMD_MAX, | ||
101 | +} MPQemuCmd; | ||
102 | + | ||
103 | +/** | ||
104 | + * MPQemuMsg: | ||
105 | + * @cmd: The remote command | ||
106 | + * @size: Size of the data to be shared | ||
107 | + * @data: Structured data | ||
108 | + * @fds: File descriptors to be shared with remote device | ||
109 | + * | ||
110 | + * MPQemuMsg Format of the message sent to the remote device from QEMU. | ||
111 | + * | ||
112 | + */ | ||
113 | +typedef struct { | ||
114 | + int cmd; | ||
115 | + size_t size; | ||
116 | + | ||
117 | + union { | ||
118 | + uint64_t u64; | ||
119 | + } data; | ||
120 | + | ||
121 | + int fds[REMOTE_MAX_FDS]; | ||
122 | + int num_fds; | ||
123 | +} MPQemuMsg; | ||
124 | + | ||
125 | +bool mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc, Error **errp); | ||
126 | +bool mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc, Error **errp); | ||
127 | + | ||
128 | +bool mpqemu_msg_valid(MPQemuMsg *msg); | ||
129 | + | ||
130 | +#endif | ||
131 | diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h | ||
132 | index XXXXXXX..XXXXXXX 100644 | ||
133 | --- a/include/sysemu/iothread.h | ||
134 | +++ b/include/sysemu/iothread.h | ||
135 | @@ -XXX,XX +XXX,XX @@ IOThread *iothread_create(const char *id, Error **errp); | ||
136 | void iothread_stop(IOThread *iothread); | ||
137 | void iothread_destroy(IOThread *iothread); | ||
138 | |||
139 | +/* | ||
140 | + * Returns true if executing withing IOThread context, | ||
141 | + * false otherwise. | ||
142 | + */ | ||
143 | +bool qemu_in_iothread(void); | ||
144 | + | ||
145 | #endif /* IOTHREAD_H */ | ||
146 | diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c | ||
147 | new file mode 100644 | ||
148 | index XXXXXXX..XXXXXXX | ||
149 | --- /dev/null | ||
150 | +++ b/hw/remote/mpqemu-link.c | ||
151 | @@ -XXX,XX +XXX,XX @@ | ||
152 | +/* | ||
153 | + * Communication channel between QEMU and remote device process | ||
154 | + * | ||
155 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | ||
156 | + * | ||
157 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
158 | + * See the COPYING file in the top-level directory. | ||
159 | + * | ||
160 | + */ | ||
161 | + | ||
162 | +#include "qemu/osdep.h" | ||
163 | +#include "qemu-common.h" | ||
164 | + | ||
165 | +#include "qemu/module.h" | ||
166 | +#include "hw/remote/mpqemu-link.h" | ||
167 | +#include "qapi/error.h" | ||
168 | +#include "qemu/iov.h" | ||
169 | +#include "qemu/error-report.h" | ||
170 | +#include "qemu/main-loop.h" | ||
171 | +#include "io/channel.h" | ||
172 | +#include "sysemu/iothread.h" | ||
173 | +#include "trace.h" | ||
174 | + | ||
175 | +/* | ||
176 | + * Send message over the ioc QIOChannel. | ||
177 | + * This function is safe to call from: | ||
178 | + * - main loop in co-routine context. Will block the main loop if not in | ||
179 | + * co-routine context; | ||
180 | + * - vCPU thread with no co-routine context and if the channel is not part | ||
181 | + * of the main loop handling; | ||
182 | + * - IOThread within co-routine context, outside of co-routine context | ||
183 | + * will block IOThread; | ||
184 | + * Returns true if no errors were encountered, false otherwise. | ||
185 | + */ | ||
186 | +bool mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc, Error **errp) | ||
187 | +{ | ||
188 | + ERRP_GUARD(); | ||
189 | + bool iolock = qemu_mutex_iothread_locked(); | ||
190 | + bool iothread = qemu_in_iothread(); | ||
191 | + struct iovec send[2] = {0}; | ||
192 | + int *fds = NULL; | ||
193 | + size_t nfds = 0; | ||
194 | + bool ret = false; | ||
195 | + | ||
196 | + send[0].iov_base = msg; | ||
197 | + send[0].iov_len = MPQEMU_MSG_HDR_SIZE; | ||
198 | + | ||
199 | + send[1].iov_base = (void *)&msg->data; | ||
200 | + send[1].iov_len = msg->size; | ||
201 | + | ||
202 | + if (msg->num_fds) { | ||
203 | + nfds = msg->num_fds; | ||
204 | + fds = msg->fds; | ||
205 | + } | ||
206 | + | ||
207 | + /* | ||
208 | + * Dont use in IOThread out of co-routine context as | ||
209 | + * it will block IOThread. | ||
210 | + */ | ||
211 | + assert(qemu_in_coroutine() || !iothread); | ||
212 | + | ||
213 | + /* | ||
214 | + * Skip unlocking/locking iothread lock when the IOThread is running | ||
215 | + * in co-routine context. Co-routine context is asserted above | ||
216 | + * for IOThread case. | ||
217 | + * Also skip lock handling while in a co-routine in the main context. | ||
218 | + */ | ||
219 | + if (iolock && !iothread && !qemu_in_coroutine()) { | ||
220 | + qemu_mutex_unlock_iothread(); | ||
221 | + } | ||
222 | + | ||
223 | + if (!qio_channel_writev_full_all(ioc, send, G_N_ELEMENTS(send), | ||
224 | + fds, nfds, errp)) { | ||
225 | + ret = true; | ||
226 | + } else { | ||
227 | + trace_mpqemu_send_io_error(msg->cmd, msg->size, nfds); | ||
228 | + } | ||
229 | + | ||
230 | + if (iolock && !iothread && !qemu_in_coroutine()) { | ||
231 | + /* See above comment why skip locking here. */ | ||
232 | + qemu_mutex_lock_iothread(); | ||
233 | + } | ||
234 | + | ||
235 | + return ret; | ||
236 | +} | ||
237 | + | ||
238 | +/* | ||
239 | + * Read message from the ioc QIOChannel. | ||
240 | + * This function is safe to call from: | ||
241 | + * - From main loop in co-routine context. Will block the main loop if not in | ||
242 | + * co-routine context; | ||
243 | + * - From vCPU thread with no co-routine context and if the channel is not part | ||
244 | + * of the main loop handling; | ||
245 | + * - From IOThread within co-routine context, outside of co-routine context | ||
246 | + * will block IOThread; | ||
247 | + */ | ||
248 | +static ssize_t mpqemu_read(QIOChannel *ioc, void *buf, size_t len, int **fds, | ||
249 | + size_t *nfds, Error **errp) | ||
250 | +{ | ||
251 | + ERRP_GUARD(); | ||
252 | + struct iovec iov = { .iov_base = buf, .iov_len = len }; | ||
253 | + bool iolock = qemu_mutex_iothread_locked(); | ||
254 | + bool iothread = qemu_in_iothread(); | ||
255 | + int ret = -1; | ||
256 | + | ||
257 | + /* | ||
258 | + * Dont use in IOThread out of co-routine context as | ||
259 | + * it will block IOThread. | ||
260 | + */ | ||
261 | + assert(qemu_in_coroutine() || !iothread); | ||
262 | + | ||
263 | + if (iolock && !iothread && !qemu_in_coroutine()) { | ||
264 | + qemu_mutex_unlock_iothread(); | ||
265 | + } | ||
266 | + | ||
267 | + ret = qio_channel_readv_full_all_eof(ioc, &iov, 1, fds, nfds, errp); | ||
268 | + | ||
269 | + if (iolock && !iothread && !qemu_in_coroutine()) { | ||
270 | + qemu_mutex_lock_iothread(); | ||
271 | + } | ||
272 | + | ||
273 | + return (ret <= 0) ? ret : iov.iov_len; | ||
274 | +} | ||
275 | + | ||
276 | +bool mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc, Error **errp) | ||
277 | +{ | ||
278 | + ERRP_GUARD(); | ||
279 | + g_autofree int *fds = NULL; | ||
280 | + size_t nfds = 0; | ||
281 | + ssize_t len; | ||
282 | + bool ret = false; | ||
283 | + | ||
284 | + len = mpqemu_read(ioc, msg, MPQEMU_MSG_HDR_SIZE, &fds, &nfds, errp); | ||
285 | + if (len <= 0) { | ||
286 | + goto fail; | ||
287 | + } else if (len != MPQEMU_MSG_HDR_SIZE) { | ||
288 | + error_setg(errp, "Message header corrupted"); | ||
289 | + goto fail; | ||
290 | + } | ||
291 | + | ||
292 | + if (msg->size > sizeof(msg->data)) { | ||
293 | + error_setg(errp, "Invalid size for message"); | ||
294 | + goto fail; | ||
295 | + } | ||
296 | + | ||
297 | + if (!msg->size) { | ||
298 | + goto copy_fds; | ||
299 | + } | ||
300 | + | ||
301 | + len = mpqemu_read(ioc, &msg->data, msg->size, NULL, NULL, errp); | ||
302 | + if (len <= 0) { | ||
303 | + goto fail; | ||
304 | + } | ||
305 | + if (len != msg->size) { | ||
306 | + error_setg(errp, "Unable to read full message"); | ||
307 | + goto fail; | ||
308 | + } | ||
309 | + | ||
310 | +copy_fds: | ||
311 | + msg->num_fds = nfds; | ||
312 | + if (nfds > G_N_ELEMENTS(msg->fds)) { | ||
313 | + error_setg(errp, | ||
314 | + "Overflow error: received %zu fds, more than max of %d fds", | ||
315 | + nfds, REMOTE_MAX_FDS); | ||
316 | + goto fail; | ||
317 | + } | ||
318 | + if (nfds) { | ||
319 | + memcpy(msg->fds, fds, nfds * sizeof(int)); | ||
320 | + } | ||
321 | + | ||
322 | + ret = true; | ||
323 | + | ||
324 | +fail: | ||
325 | + if (*errp) { | ||
326 | + trace_mpqemu_recv_io_error(msg->cmd, msg->size, nfds); | ||
327 | + } | ||
328 | + while (*errp && nfds) { | ||
329 | + close(fds[nfds - 1]); | ||
330 | + nfds--; | ||
331 | + } | ||
332 | + | ||
333 | + return ret; | ||
334 | +} | ||
335 | + | ||
336 | +bool mpqemu_msg_valid(MPQemuMsg *msg) | ||
337 | +{ | ||
338 | + if (msg->cmd >= MPQEMU_CMD_MAX && msg->cmd < 0) { | ||
339 | + return false; | ||
340 | + } | ||
341 | + | ||
342 | + /* Verify FDs. */ | ||
343 | + if (msg->num_fds >= REMOTE_MAX_FDS) { | ||
344 | + return false; | ||
345 | + } | ||
346 | + | ||
347 | + if (msg->num_fds > 0) { | ||
348 | + for (int i = 0; i < msg->num_fds; i++) { | ||
349 | + if (fcntl(msg->fds[i], F_GETFL) == -1) { | ||
350 | + return false; | ||
351 | + } | ||
352 | + } | ||
353 | + } | ||
354 | + | ||
355 | + return true; | ||
356 | +} | ||
357 | diff --git a/iothread.c b/iothread.c | ||
358 | index XXXXXXX..XXXXXXX 100644 | ||
359 | --- a/iothread.c | ||
360 | +++ b/iothread.c | ||
361 | @@ -XXX,XX +XXX,XX @@ IOThread *iothread_by_id(const char *id) | ||
362 | { | ||
363 | return IOTHREAD(object_resolve_path_type(id, TYPE_IOTHREAD, NULL)); | ||
364 | } | ||
365 | + | ||
366 | +bool qemu_in_iothread(void) | ||
367 | +{ | ||
368 | + return qemu_get_current_aio_context() == qemu_get_aio_context() ? | ||
369 | + false : true; | ||
370 | +} | ||
371 | diff --git a/hw/remote/meson.build b/hw/remote/meson.build | ||
372 | index XXXXXXX..XXXXXXX 100644 | ||
373 | --- a/hw/remote/meson.build | ||
374 | +++ b/hw/remote/meson.build | ||
375 | @@ -XXX,XX +XXX,XX @@ | ||
376 | remote_ss = ss.source_set() | ||
377 | |||
378 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('machine.c')) | ||
379 | +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) | ||
380 | |||
381 | softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) | ||
382 | diff --git a/hw/remote/trace-events b/hw/remote/trace-events | ||
383 | new file mode 100644 | ||
384 | index XXXXXXX..XXXXXXX | ||
385 | --- /dev/null | ||
386 | +++ b/hw/remote/trace-events | ||
387 | @@ -XXX,XX +XXX,XX @@ | ||
388 | +# multi-process trace events | ||
389 | + | ||
390 | +mpqemu_send_io_error(int cmd, int size, int nfds) "send command %d size %d, %d file descriptors to remote process" | ||
391 | +mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, %d file descriptors to remote process" | ||
392 | -- | ||
393 | 2.29.2 | ||
394 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jagannathan Raman <jag.raman@oracle.com> | ||
1 | 2 | ||
3 | Initializes the message handler function in the remote process. It is | ||
4 | called whenever there's an event pending on QIOChannel that registers | ||
5 | this function. | ||
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: 99d38d8b93753a6409ac2340e858858cda59ab1b.1611938319.git.jag.raman@oracle.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | --- | ||
14 | MAINTAINERS | 1 + | ||
15 | include/hw/remote/machine.h | 9 ++++++ | ||
16 | hw/remote/message.c | 57 +++++++++++++++++++++++++++++++++++++ | ||
17 | hw/remote/meson.build | 1 + | ||
18 | 4 files changed, 68 insertions(+) | ||
19 | create mode 100644 hw/remote/message.c | ||
20 | |||
21 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/MAINTAINERS | ||
24 | +++ b/MAINTAINERS | ||
25 | @@ -XXX,XX +XXX,XX @@ F: hw/remote/machine.c | ||
26 | F: include/hw/remote/machine.h | ||
27 | F: hw/remote/mpqemu-link.c | ||
28 | F: include/hw/remote/mpqemu-link.h | ||
29 | +F: hw/remote/message.c | ||
30 | |||
31 | Build and test automation | ||
32 | ------------------------- | ||
33 | diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/include/hw/remote/machine.h | ||
36 | +++ b/include/hw/remote/machine.h | ||
37 | @@ -XXX,XX +XXX,XX @@ | ||
38 | #include "qom/object.h" | ||
39 | #include "hw/boards.h" | ||
40 | #include "hw/pci-host/remote.h" | ||
41 | +#include "io/channel.h" | ||
42 | |||
43 | struct RemoteMachineState { | ||
44 | MachineState parent_obj; | ||
45 | @@ -XXX,XX +XXX,XX @@ struct RemoteMachineState { | ||
46 | RemotePCIHost *host; | ||
47 | }; | ||
48 | |||
49 | +/* Used to pass to co-routine device and ioc. */ | ||
50 | +typedef struct RemoteCommDev { | ||
51 | + PCIDevice *dev; | ||
52 | + QIOChannel *ioc; | ||
53 | +} RemoteCommDev; | ||
54 | + | ||
55 | #define TYPE_REMOTE_MACHINE "x-remote-machine" | ||
56 | OBJECT_DECLARE_SIMPLE_TYPE(RemoteMachineState, REMOTE_MACHINE) | ||
57 | |||
58 | +void coroutine_fn mpqemu_remote_msg_loop_co(void *data); | ||
59 | + | ||
60 | #endif | ||
61 | diff --git a/hw/remote/message.c b/hw/remote/message.c | ||
62 | new file mode 100644 | ||
63 | index XXXXXXX..XXXXXXX | ||
64 | --- /dev/null | ||
65 | +++ b/hw/remote/message.c | ||
66 | @@ -XXX,XX +XXX,XX @@ | ||
67 | +/* | ||
68 | + * Copyright © 2020, 2021 Oracle and/or its affiliates. | ||
69 | + * | ||
70 | + * This work is licensed under the terms of the GNU GPL-v2, version 2 or later. | ||
71 | + * | ||
72 | + * See the COPYING file in the top-level directory. | ||
73 | + * | ||
74 | + */ | ||
75 | + | ||
76 | +#include "qemu/osdep.h" | ||
77 | +#include "qemu-common.h" | ||
78 | + | ||
79 | +#include "hw/remote/machine.h" | ||
80 | +#include "io/channel.h" | ||
81 | +#include "hw/remote/mpqemu-link.h" | ||
82 | +#include "qapi/error.h" | ||
83 | +#include "sysemu/runstate.h" | ||
84 | + | ||
85 | +void coroutine_fn mpqemu_remote_msg_loop_co(void *data) | ||
86 | +{ | ||
87 | + g_autofree RemoteCommDev *com = (RemoteCommDev *)data; | ||
88 | + PCIDevice *pci_dev = NULL; | ||
89 | + Error *local_err = NULL; | ||
90 | + | ||
91 | + assert(com->ioc); | ||
92 | + | ||
93 | + pci_dev = com->dev; | ||
94 | + for (; !local_err;) { | ||
95 | + MPQemuMsg msg = {0}; | ||
96 | + | ||
97 | + if (!mpqemu_msg_recv(&msg, com->ioc, &local_err)) { | ||
98 | + break; | ||
99 | + } | ||
100 | + | ||
101 | + if (!mpqemu_msg_valid(&msg)) { | ||
102 | + error_setg(&local_err, "Received invalid message from proxy" | ||
103 | + "in remote process pid="FMT_pid"", | ||
104 | + getpid()); | ||
105 | + break; | ||
106 | + } | ||
107 | + | ||
108 | + switch (msg.cmd) { | ||
109 | + default: | ||
110 | + error_setg(&local_err, | ||
111 | + "Unknown command (%d) received for device %s" | ||
112 | + " (pid="FMT_pid")", | ||
113 | + msg.cmd, DEVICE(pci_dev)->id, getpid()); | ||
114 | + } | ||
115 | + } | ||
116 | + | ||
117 | + if (local_err) { | ||
118 | + error_report_err(local_err); | ||
119 | + qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_ERROR); | ||
120 | + } else { | ||
121 | + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); | ||
122 | + } | ||
123 | +} | ||
124 | diff --git a/hw/remote/meson.build b/hw/remote/meson.build | ||
125 | index XXXXXXX..XXXXXXX 100644 | ||
126 | --- a/hw/remote/meson.build | ||
127 | +++ b/hw/remote/meson.build | ||
128 | @@ -XXX,XX +XXX,XX @@ remote_ss = ss.source_set() | ||
129 | |||
130 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('machine.c')) | ||
131 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) | ||
132 | +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) | ||
133 | |||
134 | softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) | ||
135 | -- | ||
136 | 2.29.2 | ||
137 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Jagannathan Raman <jag.raman@oracle.com> | |
2 | |||
3 | Associate the file descriptor for a PCIDevice in remote process with | ||
4 | DeviceState object. | ||
5 | |||
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: f405a2ed5d7518b87bea7c59cfdf334d67e5ee51.1611938319.git.jag.raman@oracle.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | --- | ||
13 | MAINTAINERS | 1 + | ||
14 | hw/remote/remote-obj.c | 203 +++++++++++++++++++++++++++++++++++++++++ | ||
15 | hw/remote/meson.build | 1 + | ||
16 | 3 files changed, 205 insertions(+) | ||
17 | create mode 100644 hw/remote/remote-obj.c | ||
18 | |||
19 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/MAINTAINERS | ||
22 | +++ b/MAINTAINERS | ||
23 | @@ -XXX,XX +XXX,XX @@ F: include/hw/remote/machine.h | ||
24 | F: hw/remote/mpqemu-link.c | ||
25 | F: include/hw/remote/mpqemu-link.h | ||
26 | F: hw/remote/message.c | ||
27 | +F: hw/remote/remote-obj.c | ||
28 | |||
29 | Build and test automation | ||
30 | ------------------------- | ||
31 | diff --git a/hw/remote/remote-obj.c b/hw/remote/remote-obj.c | ||
32 | new file mode 100644 | ||
33 | index XXXXXXX..XXXXXXX | ||
34 | --- /dev/null | ||
35 | +++ b/hw/remote/remote-obj.c | ||
36 | @@ -XXX,XX +XXX,XX @@ | ||
37 | +/* | ||
38 | + * Copyright © 2020, 2021 Oracle and/or its affiliates. | ||
39 | + * | ||
40 | + * This work is licensed under the terms of the GNU GPL-v2, version 2 or later. | ||
41 | + * | ||
42 | + * See the COPYING file in the top-level directory. | ||
43 | + * | ||
44 | + */ | ||
45 | + | ||
46 | +#include "qemu/osdep.h" | ||
47 | +#include "qemu-common.h" | ||
48 | + | ||
49 | +#include "qemu/error-report.h" | ||
50 | +#include "qemu/notify.h" | ||
51 | +#include "qom/object_interfaces.h" | ||
52 | +#include "hw/qdev-core.h" | ||
53 | +#include "io/channel.h" | ||
54 | +#include "hw/qdev-core.h" | ||
55 | +#include "hw/remote/machine.h" | ||
56 | +#include "io/channel-util.h" | ||
57 | +#include "qapi/error.h" | ||
58 | +#include "sysemu/sysemu.h" | ||
59 | +#include "hw/pci/pci.h" | ||
60 | +#include "qemu/sockets.h" | ||
61 | +#include "monitor/monitor.h" | ||
62 | + | ||
63 | +#define TYPE_REMOTE_OBJECT "x-remote-object" | ||
64 | +OBJECT_DECLARE_TYPE(RemoteObject, RemoteObjectClass, REMOTE_OBJECT) | ||
65 | + | ||
66 | +struct RemoteObjectClass { | ||
67 | + ObjectClass parent_class; | ||
68 | + | ||
69 | + unsigned int nr_devs; | ||
70 | + unsigned int max_devs; | ||
71 | +}; | ||
72 | + | ||
73 | +struct RemoteObject { | ||
74 | + /* private */ | ||
75 | + Object parent; | ||
76 | + | ||
77 | + Notifier machine_done; | ||
78 | + | ||
79 | + int32_t fd; | ||
80 | + char *devid; | ||
81 | + | ||
82 | + QIOChannel *ioc; | ||
83 | + | ||
84 | + DeviceState *dev; | ||
85 | + DeviceListener listener; | ||
86 | +}; | ||
87 | + | ||
88 | +static void remote_object_set_fd(Object *obj, const char *str, Error **errp) | ||
89 | +{ | ||
90 | + RemoteObject *o = REMOTE_OBJECT(obj); | ||
91 | + int fd = -1; | ||
92 | + | ||
93 | + fd = monitor_fd_param(monitor_cur(), str, errp); | ||
94 | + if (fd == -1) { | ||
95 | + error_prepend(errp, "Could not parse remote object fd %s:", str); | ||
96 | + return; | ||
97 | + } | ||
98 | + | ||
99 | + if (!fd_is_socket(fd)) { | ||
100 | + error_setg(errp, "File descriptor '%s' is not a socket", str); | ||
101 | + close(fd); | ||
102 | + return; | ||
103 | + } | ||
104 | + | ||
105 | + o->fd = fd; | ||
106 | +} | ||
107 | + | ||
108 | +static void remote_object_set_devid(Object *obj, const char *str, Error **errp) | ||
109 | +{ | ||
110 | + RemoteObject *o = REMOTE_OBJECT(obj); | ||
111 | + | ||
112 | + g_free(o->devid); | ||
113 | + | ||
114 | + o->devid = g_strdup(str); | ||
115 | +} | ||
116 | + | ||
117 | +static void remote_object_unrealize_listener(DeviceListener *listener, | ||
118 | + DeviceState *dev) | ||
119 | +{ | ||
120 | + RemoteObject *o = container_of(listener, RemoteObject, listener); | ||
121 | + | ||
122 | + if (o->dev == dev) { | ||
123 | + object_unref(OBJECT(o)); | ||
124 | + } | ||
125 | +} | ||
126 | + | ||
127 | +static void remote_object_machine_done(Notifier *notifier, void *data) | ||
128 | +{ | ||
129 | + RemoteObject *o = container_of(notifier, RemoteObject, machine_done); | ||
130 | + DeviceState *dev = NULL; | ||
131 | + QIOChannel *ioc = NULL; | ||
132 | + Coroutine *co = NULL; | ||
133 | + RemoteCommDev *comdev = NULL; | ||
134 | + Error *err = NULL; | ||
135 | + | ||
136 | + dev = qdev_find_recursive(sysbus_get_default(), o->devid); | ||
137 | + if (!dev || !object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { | ||
138 | + error_report("%s is not a PCI device", o->devid); | ||
139 | + return; | ||
140 | + } | ||
141 | + | ||
142 | + ioc = qio_channel_new_fd(o->fd, &err); | ||
143 | + if (!ioc) { | ||
144 | + error_report_err(err); | ||
145 | + return; | ||
146 | + } | ||
147 | + qio_channel_set_blocking(ioc, false, NULL); | ||
148 | + | ||
149 | + o->dev = dev; | ||
150 | + | ||
151 | + o->listener.unrealize = remote_object_unrealize_listener; | ||
152 | + device_listener_register(&o->listener); | ||
153 | + | ||
154 | + /* co-routine should free this. */ | ||
155 | + comdev = g_new0(RemoteCommDev, 1); | ||
156 | + *comdev = (RemoteCommDev) { | ||
157 | + .ioc = ioc, | ||
158 | + .dev = PCI_DEVICE(dev), | ||
159 | + }; | ||
160 | + | ||
161 | + co = qemu_coroutine_create(mpqemu_remote_msg_loop_co, comdev); | ||
162 | + qemu_coroutine_enter(co); | ||
163 | +} | ||
164 | + | ||
165 | +static void remote_object_init(Object *obj) | ||
166 | +{ | ||
167 | + RemoteObjectClass *k = REMOTE_OBJECT_GET_CLASS(obj); | ||
168 | + RemoteObject *o = REMOTE_OBJECT(obj); | ||
169 | + | ||
170 | + if (k->nr_devs >= k->max_devs) { | ||
171 | + error_report("Reached maximum number of devices: %u", k->max_devs); | ||
172 | + return; | ||
173 | + } | ||
174 | + | ||
175 | + o->ioc = NULL; | ||
176 | + o->fd = -1; | ||
177 | + o->devid = NULL; | ||
178 | + | ||
179 | + k->nr_devs++; | ||
180 | + | ||
181 | + o->machine_done.notify = remote_object_machine_done; | ||
182 | + qemu_add_machine_init_done_notifier(&o->machine_done); | ||
183 | +} | ||
184 | + | ||
185 | +static void remote_object_finalize(Object *obj) | ||
186 | +{ | ||
187 | + RemoteObjectClass *k = REMOTE_OBJECT_GET_CLASS(obj); | ||
188 | + RemoteObject *o = REMOTE_OBJECT(obj); | ||
189 | + | ||
190 | + device_listener_unregister(&o->listener); | ||
191 | + | ||
192 | + if (o->ioc) { | ||
193 | + qio_channel_shutdown(o->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); | ||
194 | + qio_channel_close(o->ioc, NULL); | ||
195 | + } | ||
196 | + | ||
197 | + object_unref(OBJECT(o->ioc)); | ||
198 | + | ||
199 | + k->nr_devs--; | ||
200 | + g_free(o->devid); | ||
201 | +} | ||
202 | + | ||
203 | +static void remote_object_class_init(ObjectClass *klass, void *data) | ||
204 | +{ | ||
205 | + RemoteObjectClass *k = REMOTE_OBJECT_CLASS(klass); | ||
206 | + | ||
207 | + /* | ||
208 | + * Limit number of supported devices to 1. This is done to avoid devices | ||
209 | + * from one VM accessing the RAM of another VM. This is done until we | ||
210 | + * start using separate address spaces for individual devices. | ||
211 | + */ | ||
212 | + k->max_devs = 1; | ||
213 | + k->nr_devs = 0; | ||
214 | + | ||
215 | + object_class_property_add_str(klass, "fd", NULL, remote_object_set_fd); | ||
216 | + object_class_property_add_str(klass, "devid", NULL, | ||
217 | + remote_object_set_devid); | ||
218 | +} | ||
219 | + | ||
220 | +static const TypeInfo remote_object_info = { | ||
221 | + .name = TYPE_REMOTE_OBJECT, | ||
222 | + .parent = TYPE_OBJECT, | ||
223 | + .instance_size = sizeof(RemoteObject), | ||
224 | + .instance_init = remote_object_init, | ||
225 | + .instance_finalize = remote_object_finalize, | ||
226 | + .class_size = sizeof(RemoteObjectClass), | ||
227 | + .class_init = remote_object_class_init, | ||
228 | + .interfaces = (InterfaceInfo[]) { | ||
229 | + { TYPE_USER_CREATABLE }, | ||
230 | + { } | ||
231 | + } | ||
232 | +}; | ||
233 | + | ||
234 | +static void register_types(void) | ||
235 | +{ | ||
236 | + type_register_static(&remote_object_info); | ||
237 | +} | ||
238 | + | ||
239 | +type_init(register_types); | ||
240 | diff --git a/hw/remote/meson.build b/hw/remote/meson.build | ||
241 | index XXXXXXX..XXXXXXX 100644 | ||
242 | --- a/hw/remote/meson.build | ||
243 | +++ b/hw/remote/meson.build | ||
244 | @@ -XXX,XX +XXX,XX @@ remote_ss = ss.source_set() | ||
245 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('machine.c')) | ||
246 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) | ||
247 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) | ||
248 | +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) | ||
249 | |||
250 | softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) | ||
251 | -- | ||
252 | 2.29.2 | ||
253 | diff view generated by jsdifflib |
1 | The BDRV_O_ALLOW_RDWR flag allows / prohibits the changing of | 1 | From: Jagannathan Raman <jag.raman@oracle.com> |
---|---|---|---|
2 | the BDS 'read_only' state, but there are a few places where it | 2 | |
3 | is ignored. In the bdrv_set_read_only() helper, make sure to | 3 | SyncSysMemMsg message format is defined. It is used to send |
4 | honor the flag. | 4 | file descriptors of the RAM regions to remote device. |
5 | 5 | RAM on the remote device is configured with a set of file descriptors. | |
6 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 6 | Old RAM regions are deleted and new regions, each with an fd, is |
7 | added to the RAM. | ||
8 | |||
9 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
10 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
11 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 12 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | Reviewed-by: John Snow <jsnow@redhat.com> | 13 | Message-id: 7d2d1831d812e85f681e7a8ab99e032cf4704689.1611938319.git.jag.raman@oracle.com |
9 | Message-id: be2e5fb2d285cbece2b6d06bed54a6f56520d251.1491597120.git.jcody@redhat.com | 14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
10 | --- | 15 | --- |
11 | block.c | 7 +++++++ | 16 | MAINTAINERS | 2 + |
12 | 1 file changed, 7 insertions(+) | 17 | include/hw/remote/memory.h | 19 ++++++++++ |
13 | 18 | include/hw/remote/mpqemu-link.h | 10 +++++ | |
14 | diff --git a/block.c b/block.c | 19 | hw/remote/memory.c | 65 +++++++++++++++++++++++++++++++++ |
15 | index XXXXXXX..XXXXXXX 100644 | 20 | hw/remote/mpqemu-link.c | 11 ++++++ |
16 | --- a/block.c | 21 | hw/remote/meson.build | 2 + |
17 | +++ b/block.c | 22 | 6 files changed, 109 insertions(+) |
18 | @@ -XXX,XX +XXX,XX @@ int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 23 | create mode 100644 include/hw/remote/memory.h |
19 | return -EINVAL; | 24 | create mode 100644 hw/remote/memory.c |
25 | |||
26 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/MAINTAINERS | ||
29 | +++ b/MAINTAINERS | ||
30 | @@ -XXX,XX +XXX,XX @@ F: hw/remote/mpqemu-link.c | ||
31 | F: include/hw/remote/mpqemu-link.h | ||
32 | F: hw/remote/message.c | ||
33 | F: hw/remote/remote-obj.c | ||
34 | +F: include/hw/remote/memory.h | ||
35 | +F: hw/remote/memory.c | ||
36 | |||
37 | Build and test automation | ||
38 | ------------------------- | ||
39 | diff --git a/include/hw/remote/memory.h b/include/hw/remote/memory.h | ||
40 | new file mode 100644 | ||
41 | index XXXXXXX..XXXXXXX | ||
42 | --- /dev/null | ||
43 | +++ b/include/hw/remote/memory.h | ||
44 | @@ -XXX,XX +XXX,XX @@ | ||
45 | +/* | ||
46 | + * Memory manager for remote device | ||
47 | + * | ||
48 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | ||
49 | + * | ||
50 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
51 | + * See the COPYING file in the top-level directory. | ||
52 | + * | ||
53 | + */ | ||
54 | + | ||
55 | +#ifndef REMOTE_MEMORY_H | ||
56 | +#define REMOTE_MEMORY_H | ||
57 | + | ||
58 | +#include "exec/hwaddr.h" | ||
59 | +#include "hw/remote/mpqemu-link.h" | ||
60 | + | ||
61 | +void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp); | ||
62 | + | ||
63 | +#endif | ||
64 | diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/include/hw/remote/mpqemu-link.h | ||
67 | +++ b/include/hw/remote/mpqemu-link.h | ||
68 | @@ -XXX,XX +XXX,XX @@ | ||
69 | #include "qom/object.h" | ||
70 | #include "qemu/thread.h" | ||
71 | #include "io/channel.h" | ||
72 | +#include "exec/hwaddr.h" | ||
73 | |||
74 | #define REMOTE_MAX_FDS 8 | ||
75 | |||
76 | @@ -XXX,XX +XXX,XX @@ | ||
77 | * | ||
78 | */ | ||
79 | typedef enum { | ||
80 | + MPQEMU_CMD_SYNC_SYSMEM, | ||
81 | MPQEMU_CMD_MAX, | ||
82 | } MPQemuCmd; | ||
83 | |||
84 | +typedef struct { | ||
85 | + hwaddr gpas[REMOTE_MAX_FDS]; | ||
86 | + uint64_t sizes[REMOTE_MAX_FDS]; | ||
87 | + off_t offsets[REMOTE_MAX_FDS]; | ||
88 | +} SyncSysmemMsg; | ||
89 | + | ||
90 | /** | ||
91 | * MPQemuMsg: | ||
92 | * @cmd: The remote command | ||
93 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
94 | * MPQemuMsg Format of the message sent to the remote device from QEMU. | ||
95 | * | ||
96 | */ | ||
97 | + | ||
98 | typedef struct { | ||
99 | int cmd; | ||
100 | size_t size; | ||
101 | |||
102 | union { | ||
103 | uint64_t u64; | ||
104 | + SyncSysmemMsg sync_sysmem; | ||
105 | } data; | ||
106 | |||
107 | int fds[REMOTE_MAX_FDS]; | ||
108 | diff --git a/hw/remote/memory.c b/hw/remote/memory.c | ||
109 | new file mode 100644 | ||
110 | index XXXXXXX..XXXXXXX | ||
111 | --- /dev/null | ||
112 | +++ b/hw/remote/memory.c | ||
113 | @@ -XXX,XX +XXX,XX @@ | ||
114 | +/* | ||
115 | + * Memory manager for remote device | ||
116 | + * | ||
117 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | ||
118 | + * | ||
119 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
120 | + * See the COPYING file in the top-level directory. | ||
121 | + * | ||
122 | + */ | ||
123 | + | ||
124 | +#include "qemu/osdep.h" | ||
125 | +#include "qemu-common.h" | ||
126 | + | ||
127 | +#include "hw/remote/memory.h" | ||
128 | +#include "exec/address-spaces.h" | ||
129 | +#include "exec/ram_addr.h" | ||
130 | +#include "qapi/error.h" | ||
131 | + | ||
132 | +static void remote_sysmem_reset(void) | ||
133 | +{ | ||
134 | + MemoryRegion *sysmem, *subregion, *next; | ||
135 | + | ||
136 | + sysmem = get_system_memory(); | ||
137 | + | ||
138 | + QTAILQ_FOREACH_SAFE(subregion, &sysmem->subregions, subregions_link, next) { | ||
139 | + if (subregion->ram) { | ||
140 | + memory_region_del_subregion(sysmem, subregion); | ||
141 | + object_unparent(OBJECT(subregion)); | ||
142 | + } | ||
143 | + } | ||
144 | +} | ||
145 | + | ||
146 | +void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp) | ||
147 | +{ | ||
148 | + ERRP_GUARD(); | ||
149 | + SyncSysmemMsg *sysmem_info = &msg->data.sync_sysmem; | ||
150 | + MemoryRegion *sysmem, *subregion; | ||
151 | + static unsigned int suffix; | ||
152 | + int region; | ||
153 | + | ||
154 | + sysmem = get_system_memory(); | ||
155 | + | ||
156 | + remote_sysmem_reset(); | ||
157 | + | ||
158 | + for (region = 0; region < msg->num_fds; region++) { | ||
159 | + g_autofree char *name; | ||
160 | + subregion = g_new(MemoryRegion, 1); | ||
161 | + name = g_strdup_printf("remote-mem-%u", suffix++); | ||
162 | + memory_region_init_ram_from_fd(subregion, NULL, | ||
163 | + name, sysmem_info->sizes[region], | ||
164 | + true, msg->fds[region], | ||
165 | + sysmem_info->offsets[region], | ||
166 | + errp); | ||
167 | + | ||
168 | + if (*errp) { | ||
169 | + g_free(subregion); | ||
170 | + remote_sysmem_reset(); | ||
171 | + return; | ||
172 | + } | ||
173 | + | ||
174 | + memory_region_add_subregion(sysmem, sysmem_info->gpas[region], | ||
175 | + subregion); | ||
176 | + | ||
177 | + } | ||
178 | +} | ||
179 | diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c | ||
180 | index XXXXXXX..XXXXXXX 100644 | ||
181 | --- a/hw/remote/mpqemu-link.c | ||
182 | +++ b/hw/remote/mpqemu-link.c | ||
183 | @@ -XXX,XX +XXX,XX @@ bool mpqemu_msg_valid(MPQemuMsg *msg) | ||
184 | } | ||
20 | } | 185 | } |
21 | 186 | ||
22 | + /* Do not clear read_only if it is prohibited */ | 187 | + /* Verify message specific fields. */ |
23 | + if (!read_only && !(bs->open_flags & BDRV_O_ALLOW_RDWR)) { | 188 | + switch (msg->cmd) { |
24 | + error_setg(errp, "Node '%s' is read only", | 189 | + case MPQEMU_CMD_SYNC_SYSMEM: |
25 | + bdrv_get_device_or_node_name(bs)); | 190 | + if (msg->num_fds == 0 || msg->size != sizeof(SyncSysmemMsg)) { |
26 | + return -EPERM; | 191 | + return false; |
192 | + } | ||
193 | + break; | ||
194 | + default: | ||
195 | + break; | ||
27 | + } | 196 | + } |
28 | + | 197 | + |
29 | bs->read_only = read_only; | 198 | return true; |
30 | return 0; | ||
31 | } | 199 | } |
200 | diff --git a/hw/remote/meson.build b/hw/remote/meson.build | ||
201 | index XXXXXXX..XXXXXXX 100644 | ||
202 | --- a/hw/remote/meson.build | ||
203 | +++ b/hw/remote/meson.build | ||
204 | @@ -XXX,XX +XXX,XX @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) | ||
205 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) | ||
206 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) | ||
207 | |||
208 | +specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) | ||
209 | + | ||
210 | softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) | ||
32 | -- | 211 | -- |
33 | 2.9.3 | 212 | 2.29.2 |
34 | 213 | ||
35 | diff view generated by jsdifflib |
1 | The protocol VXHS does not support image creation. Some tests expect | 1 | From: Elena Ufimtseva <elena.ufimtseva@oracle.com> |
---|---|---|---|
2 | to be able to create images through the protocol. Exclude VXHS from | ||
3 | these tests. | ||
4 | 2 | ||
5 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 3 | Defines a PCI Device proxy object as a child of TYPE_PCI_DEVICE. |
4 | |||
5 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
6 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
7 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Message-id: b5186ebfedf8e557044d09a768846c59230ad3a7.1611938319.git.jag.raman@oracle.com | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | --- | 11 | --- |
7 | tests/qemu-iotests/017 | 1 + | 12 | MAINTAINERS | 2 + |
8 | tests/qemu-iotests/020 | 1 + | 13 | include/hw/remote/proxy.h | 33 +++++++++++++ |
9 | tests/qemu-iotests/029 | 1 + | 14 | hw/remote/proxy.c | 99 +++++++++++++++++++++++++++++++++++++++ |
10 | tests/qemu-iotests/073 | 1 + | 15 | hw/remote/meson.build | 1 + |
11 | tests/qemu-iotests/114 | 1 + | 16 | 4 files changed, 135 insertions(+) |
12 | tests/qemu-iotests/130 | 1 + | 17 | create mode 100644 include/hw/remote/proxy.h |
13 | tests/qemu-iotests/134 | 1 + | 18 | create mode 100644 hw/remote/proxy.c |
14 | tests/qemu-iotests/156 | 1 + | ||
15 | tests/qemu-iotests/158 | 1 + | ||
16 | 9 files changed, 9 insertions(+) | ||
17 | 19 | ||
18 | diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017 | 20 | diff --git a/MAINTAINERS b/MAINTAINERS |
19 | index XXXXXXX..XXXXXXX 100755 | 21 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/tests/qemu-iotests/017 | 22 | --- a/MAINTAINERS |
21 | +++ b/tests/qemu-iotests/017 | 23 | +++ b/MAINTAINERS |
22 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 24 | @@ -XXX,XX +XXX,XX @@ F: hw/remote/message.c |
23 | # Any format supporting backing files | 25 | F: hw/remote/remote-obj.c |
24 | _supported_fmt qcow qcow2 vmdk qed | 26 | F: include/hw/remote/memory.h |
25 | _supported_proto generic | 27 | F: hw/remote/memory.c |
26 | +_unsupported_proto vxhs | 28 | +F: hw/remote/proxy.c |
27 | _supported_os Linux | 29 | +F: include/hw/remote/proxy.h |
28 | _unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | 30 | |
29 | 31 | Build and test automation | |
30 | diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020 | 32 | ------------------------- |
31 | index XXXXXXX..XXXXXXX 100755 | 33 | diff --git a/include/hw/remote/proxy.h b/include/hw/remote/proxy.h |
32 | --- a/tests/qemu-iotests/020 | 34 | new file mode 100644 |
33 | +++ b/tests/qemu-iotests/020 | 35 | index XXXXXXX..XXXXXXX |
34 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 36 | --- /dev/null |
35 | # Any format supporting backing files | 37 | +++ b/include/hw/remote/proxy.h |
36 | _supported_fmt qcow qcow2 vmdk qed | 38 | @@ -XXX,XX +XXX,XX @@ |
37 | _supported_proto generic | 39 | +/* |
38 | +_unsupported_proto vxhs | 40 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. |
39 | _supported_os Linux | 41 | + * |
40 | _unsupported_imgopts "subformat=monolithicFlat" \ | 42 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
41 | "subformat=twoGbMaxExtentFlat" \ | 43 | + * See the COPYING file in the top-level directory. |
42 | diff --git a/tests/qemu-iotests/029 b/tests/qemu-iotests/029 | 44 | + * |
43 | index XXXXXXX..XXXXXXX 100755 | 45 | + */ |
44 | --- a/tests/qemu-iotests/029 | 46 | + |
45 | +++ b/tests/qemu-iotests/029 | 47 | +#ifndef PROXY_H |
46 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 48 | +#define PROXY_H |
47 | # Any format supporting intenal snapshots | 49 | + |
48 | _supported_fmt qcow2 | 50 | +#include "hw/pci/pci.h" |
49 | _supported_proto generic | 51 | +#include "io/channel.h" |
50 | +_unsupported_proto vxhs | 52 | + |
51 | _supported_os Linux | 53 | +#define TYPE_PCI_PROXY_DEV "x-pci-proxy-dev" |
52 | # Internal snapshots are (currently) impossible with refcount_bits=1 | 54 | +OBJECT_DECLARE_SIMPLE_TYPE(PCIProxyDev, PCI_PROXY_DEV) |
53 | _unsupported_imgopts 'refcount_bits=1[^0-9]' | 55 | + |
54 | diff --git a/tests/qemu-iotests/073 b/tests/qemu-iotests/073 | 56 | +struct PCIProxyDev { |
55 | index XXXXXXX..XXXXXXX 100755 | 57 | + PCIDevice parent_dev; |
56 | --- a/tests/qemu-iotests/073 | 58 | + char *fd; |
57 | +++ b/tests/qemu-iotests/073 | 59 | + |
58 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 60 | + /* |
59 | 61 | + * Mutex used to protect the QIOChannel fd from | |
60 | _supported_fmt qcow2 | 62 | + * the concurrent access by the VCPUs since proxy |
61 | _supported_proto generic | 63 | + * blocks while awaiting for the replies from the |
62 | +_unsupported_proto vxhs | 64 | + * process remote. |
63 | _supported_os Linux | 65 | + */ |
64 | 66 | + QemuMutex io_mutex; | |
65 | CLUSTER_SIZE=64k | 67 | + QIOChannel *ioc; |
66 | diff --git a/tests/qemu-iotests/114 b/tests/qemu-iotests/114 | 68 | + Error *migration_blocker; |
67 | index XXXXXXX..XXXXXXX 100755 | 69 | +}; |
68 | --- a/tests/qemu-iotests/114 | 70 | + |
69 | +++ b/tests/qemu-iotests/114 | 71 | +#endif /* PROXY_H */ |
70 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 72 | diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c |
71 | 73 | new file mode 100644 | |
72 | _supported_fmt qcow2 | 74 | index XXXXXXX..XXXXXXX |
73 | _supported_proto generic | 75 | --- /dev/null |
74 | +_unsupported_proto vxhs | 76 | +++ b/hw/remote/proxy.c |
75 | _supported_os Linux | 77 | @@ -XXX,XX +XXX,XX @@ |
76 | 78 | +/* | |
77 | 79 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | |
78 | diff --git a/tests/qemu-iotests/130 b/tests/qemu-iotests/130 | 80 | + * |
79 | index XXXXXXX..XXXXXXX 100755 | 81 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
80 | --- a/tests/qemu-iotests/130 | 82 | + * See the COPYING file in the top-level directory. |
81 | +++ b/tests/qemu-iotests/130 | 83 | + * |
82 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 84 | + */ |
83 | 85 | + | |
84 | _supported_fmt qcow2 | 86 | +#include "qemu/osdep.h" |
85 | _supported_proto generic | 87 | +#include "qemu-common.h" |
86 | +_unsupported_proto vxhs | 88 | + |
87 | _supported_os Linux | 89 | +#include "hw/remote/proxy.h" |
88 | 90 | +#include "hw/pci/pci.h" | |
89 | qemu_comm_method="monitor" | 91 | +#include "qapi/error.h" |
90 | diff --git a/tests/qemu-iotests/134 b/tests/qemu-iotests/134 | 92 | +#include "io/channel-util.h" |
91 | index XXXXXXX..XXXXXXX 100755 | 93 | +#include "hw/qdev-properties.h" |
92 | --- a/tests/qemu-iotests/134 | 94 | +#include "monitor/monitor.h" |
93 | +++ b/tests/qemu-iotests/134 | 95 | +#include "migration/blocker.h" |
94 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 96 | +#include "qemu/sockets.h" |
95 | 97 | + | |
96 | _supported_fmt qcow2 | 98 | +static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) |
97 | _supported_proto generic | 99 | +{ |
98 | +_unsupported_proto vxhs | 100 | + ERRP_GUARD(); |
99 | _supported_os Linux | 101 | + PCIProxyDev *dev = PCI_PROXY_DEV(device); |
100 | 102 | + int fd; | |
101 | 103 | + | |
102 | diff --git a/tests/qemu-iotests/156 b/tests/qemu-iotests/156 | 104 | + if (!dev->fd) { |
103 | index XXXXXXX..XXXXXXX 100755 | 105 | + error_setg(errp, "fd parameter not specified for %s", |
104 | --- a/tests/qemu-iotests/156 | 106 | + DEVICE(device)->id); |
105 | +++ b/tests/qemu-iotests/156 | 107 | + return; |
106 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 108 | + } |
107 | 109 | + | |
108 | _supported_fmt qcow2 qed | 110 | + fd = monitor_fd_param(monitor_cur(), dev->fd, errp); |
109 | _supported_proto generic | 111 | + if (fd == -1) { |
110 | +_unsupported_proto vxhs | 112 | + error_prepend(errp, "proxy: unable to parse fd %s: ", dev->fd); |
111 | _supported_os Linux | 113 | + return; |
112 | 114 | + } | |
113 | # Create source disk | 115 | + |
114 | diff --git a/tests/qemu-iotests/158 b/tests/qemu-iotests/158 | 116 | + if (!fd_is_socket(fd)) { |
115 | index XXXXXXX..XXXXXXX 100755 | 117 | + error_setg(errp, "proxy: fd %d is not a socket", fd); |
116 | --- a/tests/qemu-iotests/158 | 118 | + close(fd); |
117 | +++ b/tests/qemu-iotests/158 | 119 | + return; |
118 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 120 | + } |
119 | 121 | + | |
120 | _supported_fmt qcow2 | 122 | + dev->ioc = qio_channel_new_fd(fd, errp); |
121 | _supported_proto generic | 123 | + |
122 | +_unsupported_proto vxhs | 124 | + error_setg(&dev->migration_blocker, "%s does not support migration", |
123 | _supported_os Linux | 125 | + TYPE_PCI_PROXY_DEV); |
124 | 126 | + migrate_add_blocker(dev->migration_blocker, errp); | |
127 | + | ||
128 | + qemu_mutex_init(&dev->io_mutex); | ||
129 | + qio_channel_set_blocking(dev->ioc, true, NULL); | ||
130 | +} | ||
131 | + | ||
132 | +static void pci_proxy_dev_exit(PCIDevice *pdev) | ||
133 | +{ | ||
134 | + PCIProxyDev *dev = PCI_PROXY_DEV(pdev); | ||
135 | + | ||
136 | + if (dev->ioc) { | ||
137 | + qio_channel_close(dev->ioc, NULL); | ||
138 | + } | ||
139 | + | ||
140 | + migrate_del_blocker(dev->migration_blocker); | ||
141 | + | ||
142 | + error_free(dev->migration_blocker); | ||
143 | +} | ||
144 | + | ||
145 | +static Property proxy_properties[] = { | ||
146 | + DEFINE_PROP_STRING("fd", PCIProxyDev, fd), | ||
147 | + DEFINE_PROP_END_OF_LIST(), | ||
148 | +}; | ||
149 | + | ||
150 | +static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) | ||
151 | +{ | ||
152 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
153 | + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); | ||
154 | + | ||
155 | + k->realize = pci_proxy_dev_realize; | ||
156 | + k->exit = pci_proxy_dev_exit; | ||
157 | + device_class_set_props(dc, proxy_properties); | ||
158 | +} | ||
159 | + | ||
160 | +static const TypeInfo pci_proxy_dev_type_info = { | ||
161 | + .name = TYPE_PCI_PROXY_DEV, | ||
162 | + .parent = TYPE_PCI_DEVICE, | ||
163 | + .instance_size = sizeof(PCIProxyDev), | ||
164 | + .class_init = pci_proxy_dev_class_init, | ||
165 | + .interfaces = (InterfaceInfo[]) { | ||
166 | + { INTERFACE_CONVENTIONAL_PCI_DEVICE }, | ||
167 | + { }, | ||
168 | + }, | ||
169 | +}; | ||
170 | + | ||
171 | +static void pci_proxy_dev_register_types(void) | ||
172 | +{ | ||
173 | + type_register_static(&pci_proxy_dev_type_info); | ||
174 | +} | ||
175 | + | ||
176 | +type_init(pci_proxy_dev_register_types) | ||
177 | diff --git a/hw/remote/meson.build b/hw/remote/meson.build | ||
178 | index XXXXXXX..XXXXXXX 100644 | ||
179 | --- a/hw/remote/meson.build | ||
180 | +++ b/hw/remote/meson.build | ||
181 | @@ -XXX,XX +XXX,XX @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('machine.c')) | ||
182 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) | ||
183 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) | ||
184 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) | ||
185 | +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) | ||
186 | |||
187 | specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) | ||
125 | 188 | ||
126 | -- | 189 | -- |
127 | 2.9.3 | 190 | 2.29.2 |
128 | 191 | ||
129 | diff view generated by jsdifflib |
1 | This adds support for reopen in rbd, for changing between r/w and r/o. | 1 | From: Elena Ufimtseva <elena.ufimtseva@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | Note, that this is only a flag change, but we will block a change from | 3 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> |
4 | r/o to r/w if we are using an RBD internal snapshot. | 4 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> |
5 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | Message-id: d54edb4176361eed86b903e8f27058363b6c83b3.1611938319.git.jag.raman@oracle.com | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | ||
10 | include/hw/remote/mpqemu-link.h | 4 ++++ | ||
11 | hw/remote/mpqemu-link.c | 34 +++++++++++++++++++++++++++++++++ | ||
12 | 2 files changed, 38 insertions(+) | ||
5 | 13 | ||
6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 14 | diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h |
7 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
8 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
9 | Message-id: d4e87539167ec6527d44c97b164eabcccf96e4f3.1491597120.git.jcody@redhat.com | ||
10 | --- | ||
11 | block/rbd.c | 21 +++++++++++++++++++++ | ||
12 | 1 file changed, 21 insertions(+) | ||
13 | |||
14 | diff --git a/block/rbd.c b/block/rbd.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/block/rbd.c | 16 | --- a/include/hw/remote/mpqemu-link.h |
17 | +++ b/block/rbd.c | 17 | +++ b/include/hw/remote/mpqemu-link.h |
18 | @@ -XXX,XX +XXX,XX @@ failed_opts: | 18 | @@ -XXX,XX +XXX,XX @@ |
19 | return r; | 19 | #include "qemu/thread.h" |
20 | #include "io/channel.h" | ||
21 | #include "exec/hwaddr.h" | ||
22 | +#include "io/channel-socket.h" | ||
23 | +#include "hw/remote/proxy.h" | ||
24 | |||
25 | #define REMOTE_MAX_FDS 8 | ||
26 | |||
27 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
28 | bool mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc, Error **errp); | ||
29 | bool mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc, Error **errp); | ||
30 | |||
31 | +uint64_t mpqemu_msg_send_and_await_reply(MPQemuMsg *msg, PCIProxyDev *pdev, | ||
32 | + Error **errp); | ||
33 | bool mpqemu_msg_valid(MPQemuMsg *msg); | ||
34 | |||
35 | #endif | ||
36 | diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/hw/remote/mpqemu-link.c | ||
39 | +++ b/hw/remote/mpqemu-link.c | ||
40 | @@ -XXX,XX +XXX,XX @@ fail: | ||
41 | return ret; | ||
20 | } | 42 | } |
21 | 43 | ||
44 | +/* | ||
45 | + * Send msg and wait for a reply with command code RET_MSG. | ||
46 | + * Returns the message received of size u64 or UINT64_MAX | ||
47 | + * on error. | ||
48 | + * Called from VCPU thread in non-coroutine context. | ||
49 | + * Used by the Proxy object to communicate to remote processes. | ||
50 | + */ | ||
51 | +uint64_t mpqemu_msg_send_and_await_reply(MPQemuMsg *msg, PCIProxyDev *pdev, | ||
52 | + Error **errp) | ||
53 | +{ | ||
54 | + ERRP_GUARD(); | ||
55 | + MPQemuMsg msg_reply = {0}; | ||
56 | + uint64_t ret = UINT64_MAX; | ||
22 | + | 57 | + |
23 | +/* Since RBD is currently always opened R/W via the API, | 58 | + assert(!qemu_in_coroutine()); |
24 | + * we just need to check if we are using a snapshot or not, in | ||
25 | + * order to determine if we will allow it to be R/W */ | ||
26 | +static int qemu_rbd_reopen_prepare(BDRVReopenState *state, | ||
27 | + BlockReopenQueue *queue, Error **errp) | ||
28 | +{ | ||
29 | + BDRVRBDState *s = state->bs->opaque; | ||
30 | + int ret = 0; | ||
31 | + | 59 | + |
32 | + if (s->snap && state->flags & BDRV_O_RDWR) { | 60 | + QEMU_LOCK_GUARD(&pdev->io_mutex); |
33 | + error_setg(errp, | 61 | + if (!mpqemu_msg_send(msg, pdev->ioc, errp)) { |
34 | + "Cannot change node '%s' to r/w when using RBD snapshot", | 62 | + return ret; |
35 | + bdrv_get_device_or_node_name(state->bs)); | ||
36 | + ret = -EINVAL; | ||
37 | + } | 63 | + } |
38 | + | 64 | + |
39 | + return ret; | 65 | + if (!mpqemu_msg_recv(&msg_reply, pdev->ioc, errp)) { |
66 | + return ret; | ||
67 | + } | ||
68 | + | ||
69 | + if (!mpqemu_msg_valid(&msg_reply)) { | ||
70 | + error_setg(errp, "ERROR: Invalid reply received for command %d", | ||
71 | + msg->cmd); | ||
72 | + return ret; | ||
73 | + } | ||
74 | + | ||
75 | + return msg_reply.data.u64; | ||
40 | +} | 76 | +} |
41 | + | 77 | + |
42 | static void qemu_rbd_close(BlockDriverState *bs) | 78 | bool mpqemu_msg_valid(MPQemuMsg *msg) |
43 | { | 79 | { |
44 | BDRVRBDState *s = bs->opaque; | 80 | if (msg->cmd >= MPQEMU_CMD_MAX && msg->cmd < 0) { |
45 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_rbd = { | ||
46 | .bdrv_parse_filename = qemu_rbd_parse_filename, | ||
47 | .bdrv_file_open = qemu_rbd_open, | ||
48 | .bdrv_close = qemu_rbd_close, | ||
49 | + .bdrv_reopen_prepare = qemu_rbd_reopen_prepare, | ||
50 | .bdrv_create = qemu_rbd_create, | ||
51 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
52 | .bdrv_get_info = qemu_rbd_getinfo, | ||
53 | -- | 81 | -- |
54 | 2.9.3 | 82 | 2.29.2 |
55 | 83 | ||
56 | diff view generated by jsdifflib |
1 | We have a helper wrapper for checking for the BDS read_only flag, | 1 | From: Elena Ufimtseva <elena.ufimtseva@oracle.com> |
---|---|---|---|
2 | add a helper wrapper to set the read_only flag as well. | 2 | |
3 | 3 | The Proxy Object sends the PCI config space accesses as messages | |
4 | to the remote process over the communication channel | ||
5 | |||
6 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
7 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
8 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
4 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
5 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 10 | Message-id: d3c94f4618813234655356c60e6f0d0362ff42d6.1611938319.git.jag.raman@oracle.com |
6 | Reviewed-by: John Snow <jsnow@redhat.com> | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
7 | Message-id: 9b18972d05f5fa2ac16c014f0af98d680553048d.1491597120.git.jcody@redhat.com | ||
8 | --- | 12 | --- |
9 | block.c | 5 +++++ | 13 | include/hw/remote/mpqemu-link.h | 10 ++++++ |
10 | block/bochs.c | 2 +- | 14 | hw/remote/message.c | 60 +++++++++++++++++++++++++++++++++ |
11 | block/cloop.c | 2 +- | 15 | hw/remote/mpqemu-link.c | 8 ++++- |
12 | block/dmg.c | 2 +- | 16 | hw/remote/proxy.c | 55 ++++++++++++++++++++++++++++++ |
13 | block/rbd.c | 2 +- | 17 | 4 files changed, 132 insertions(+), 1 deletion(-) |
14 | block/vvfat.c | 4 ++-- | 18 | |
15 | include/block/block.h | 1 + | 19 | diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h |
16 | 7 files changed, 12 insertions(+), 6 deletions(-) | 20 | index XXXXXXX..XXXXXXX 100644 |
17 | 21 | --- a/include/hw/remote/mpqemu-link.h | |
18 | diff --git a/block.c b/block.c | 22 | +++ b/include/hw/remote/mpqemu-link.h |
19 | index XXXXXXX..XXXXXXX 100644 | 23 | @@ -XXX,XX +XXX,XX @@ |
20 | --- a/block.c | 24 | */ |
21 | +++ b/block.c | 25 | typedef enum { |
22 | @@ -XXX,XX +XXX,XX @@ void path_combine(char *dest, int dest_size, | 26 | MPQEMU_CMD_SYNC_SYSMEM, |
27 | + MPQEMU_CMD_RET, | ||
28 | + MPQEMU_CMD_PCI_CFGWRITE, | ||
29 | + MPQEMU_CMD_PCI_CFGREAD, | ||
30 | MPQEMU_CMD_MAX, | ||
31 | } MPQemuCmd; | ||
32 | |||
33 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
34 | off_t offsets[REMOTE_MAX_FDS]; | ||
35 | } SyncSysmemMsg; | ||
36 | |||
37 | +typedef struct { | ||
38 | + uint32_t addr; | ||
39 | + uint32_t val; | ||
40 | + int len; | ||
41 | +} PciConfDataMsg; | ||
42 | + | ||
43 | /** | ||
44 | * MPQemuMsg: | ||
45 | * @cmd: The remote command | ||
46 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
47 | |||
48 | union { | ||
49 | uint64_t u64; | ||
50 | + PciConfDataMsg pci_conf_data; | ||
51 | SyncSysmemMsg sync_sysmem; | ||
52 | } data; | ||
53 | |||
54 | diff --git a/hw/remote/message.c b/hw/remote/message.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/hw/remote/message.c | ||
57 | +++ b/hw/remote/message.c | ||
58 | @@ -XXX,XX +XXX,XX @@ | ||
59 | #include "hw/remote/mpqemu-link.h" | ||
60 | #include "qapi/error.h" | ||
61 | #include "sysemu/runstate.h" | ||
62 | +#include "hw/pci/pci.h" | ||
63 | + | ||
64 | +static void process_config_write(QIOChannel *ioc, PCIDevice *dev, | ||
65 | + MPQemuMsg *msg, Error **errp); | ||
66 | +static void process_config_read(QIOChannel *ioc, PCIDevice *dev, | ||
67 | + MPQemuMsg *msg, Error **errp); | ||
68 | |||
69 | void coroutine_fn mpqemu_remote_msg_loop_co(void *data) | ||
70 | { | ||
71 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) | ||
72 | } | ||
73 | |||
74 | switch (msg.cmd) { | ||
75 | + case MPQEMU_CMD_PCI_CFGWRITE: | ||
76 | + process_config_write(com->ioc, pci_dev, &msg, &local_err); | ||
77 | + break; | ||
78 | + case MPQEMU_CMD_PCI_CFGREAD: | ||
79 | + process_config_read(com->ioc, pci_dev, &msg, &local_err); | ||
80 | + break; | ||
81 | default: | ||
82 | error_setg(&local_err, | ||
83 | "Unknown command (%d) received for device %s" | ||
84 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) | ||
85 | qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); | ||
23 | } | 86 | } |
24 | } | 87 | } |
25 | 88 | + | |
26 | +void bdrv_set_read_only(BlockDriverState *bs, bool read_only) | 89 | +static void process_config_write(QIOChannel *ioc, PCIDevice *dev, |
27 | +{ | 90 | + MPQemuMsg *msg, Error **errp) |
28 | + bs->read_only = read_only; | 91 | +{ |
29 | +} | 92 | + ERRP_GUARD(); |
30 | + | 93 | + PciConfDataMsg *conf = (PciConfDataMsg *)&msg->data.pci_conf_data; |
31 | void bdrv_get_full_backing_filename_from_filename(const char *backed, | 94 | + MPQemuMsg ret = { 0 }; |
32 | const char *backing, | 95 | + |
33 | char *dest, size_t sz, | 96 | + if ((conf->addr + sizeof(conf->val)) > pci_config_size(dev)) { |
34 | diff --git a/block/bochs.c b/block/bochs.c | 97 | + error_setg(errp, "Bad address for PCI config write, pid "FMT_pid".", |
35 | index XXXXXXX..XXXXXXX 100644 | 98 | + getpid()); |
36 | --- a/block/bochs.c | 99 | + ret.data.u64 = UINT64_MAX; |
37 | +++ b/block/bochs.c | 100 | + } else { |
38 | @@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, | 101 | + pci_default_write_config(dev, conf->addr, conf->val, conf->len); |
39 | return -EINVAL; | 102 | + } |
103 | + | ||
104 | + ret.cmd = MPQEMU_CMD_RET; | ||
105 | + ret.size = sizeof(ret.data.u64); | ||
106 | + | ||
107 | + if (!mpqemu_msg_send(&ret, ioc, NULL)) { | ||
108 | + error_prepend(errp, "Error returning code to proxy, pid "FMT_pid": ", | ||
109 | + getpid()); | ||
110 | + } | ||
111 | +} | ||
112 | + | ||
113 | +static void process_config_read(QIOChannel *ioc, PCIDevice *dev, | ||
114 | + MPQemuMsg *msg, Error **errp) | ||
115 | +{ | ||
116 | + ERRP_GUARD(); | ||
117 | + PciConfDataMsg *conf = (PciConfDataMsg *)&msg->data.pci_conf_data; | ||
118 | + MPQemuMsg ret = { 0 }; | ||
119 | + | ||
120 | + if ((conf->addr + sizeof(conf->val)) > pci_config_size(dev)) { | ||
121 | + error_setg(errp, "Bad address for PCI config read, pid "FMT_pid".", | ||
122 | + getpid()); | ||
123 | + ret.data.u64 = UINT64_MAX; | ||
124 | + } else { | ||
125 | + ret.data.u64 = pci_default_read_config(dev, conf->addr, conf->len); | ||
126 | + } | ||
127 | + | ||
128 | + ret.cmd = MPQEMU_CMD_RET; | ||
129 | + ret.size = sizeof(ret.data.u64); | ||
130 | + | ||
131 | + if (!mpqemu_msg_send(&ret, ioc, NULL)) { | ||
132 | + error_prepend(errp, "Error returning code to proxy, pid "FMT_pid": ", | ||
133 | + getpid()); | ||
134 | + } | ||
135 | +} | ||
136 | diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c | ||
137 | index XXXXXXX..XXXXXXX 100644 | ||
138 | --- a/hw/remote/mpqemu-link.c | ||
139 | +++ b/hw/remote/mpqemu-link.c | ||
140 | @@ -XXX,XX +XXX,XX @@ uint64_t mpqemu_msg_send_and_await_reply(MPQemuMsg *msg, PCIProxyDev *pdev, | ||
141 | return ret; | ||
40 | } | 142 | } |
41 | 143 | ||
42 | - bs->read_only = true; /* no write support yet */ | 144 | - if (!mpqemu_msg_valid(&msg_reply)) { |
43 | + bdrv_set_read_only(bs, true); /* no write support yet */ | 145 | + if (!mpqemu_msg_valid(&msg_reply) || msg_reply.cmd != MPQEMU_CMD_RET) { |
44 | 146 | error_setg(errp, "ERROR: Invalid reply received for command %d", | |
45 | ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); | 147 | msg->cmd); |
46 | if (ret < 0) { | 148 | return ret; |
47 | diff --git a/block/cloop.c b/block/cloop.c | 149 | @@ -XXX,XX +XXX,XX @@ bool mpqemu_msg_valid(MPQemuMsg *msg) |
48 | index XXXXXXX..XXXXXXX 100644 | 150 | return false; |
49 | --- a/block/cloop.c | 151 | } |
50 | +++ b/block/cloop.c | 152 | break; |
51 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | 153 | + case MPQEMU_CMD_PCI_CFGWRITE: |
52 | return -EINVAL; | 154 | + case MPQEMU_CMD_PCI_CFGREAD: |
155 | + if (msg->size != sizeof(PciConfDataMsg)) { | ||
156 | + return false; | ||
157 | + } | ||
158 | + break; | ||
159 | default: | ||
160 | break; | ||
53 | } | 161 | } |
54 | 162 | diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c | |
55 | - bs->read_only = true; | 163 | index XXXXXXX..XXXXXXX 100644 |
56 | + bdrv_set_read_only(bs, true); | 164 | --- a/hw/remote/proxy.c |
57 | 165 | +++ b/hw/remote/proxy.c | |
58 | /* read header */ | 166 | @@ -XXX,XX +XXX,XX @@ |
59 | ret = bdrv_pread(bs->file, 128, &s->block_size, 4); | 167 | #include "monitor/monitor.h" |
60 | diff --git a/block/dmg.c b/block/dmg.c | 168 | #include "migration/blocker.h" |
61 | index XXXXXXX..XXXXXXX 100644 | 169 | #include "qemu/sockets.h" |
62 | --- a/block/dmg.c | 170 | +#include "hw/remote/mpqemu-link.h" |
63 | +++ b/block/dmg.c | 171 | +#include "qemu/error-report.h" |
64 | @@ -XXX,XX +XXX,XX @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, | 172 | |
65 | } | 173 | static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) |
66 | 174 | { | |
67 | block_module_load_one("dmg-bz2"); | 175 | @@ -XXX,XX +XXX,XX @@ static void pci_proxy_dev_exit(PCIDevice *pdev) |
68 | - bs->read_only = true; | 176 | error_free(dev->migration_blocker); |
69 | + bdrv_set_read_only(bs, true); | 177 | } |
70 | 178 | ||
71 | s->n_chunks = 0; | 179 | +static void config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, |
72 | s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; | 180 | + int len, unsigned int op) |
73 | diff --git a/block/rbd.c b/block/rbd.c | 181 | +{ |
74 | index XXXXXXX..XXXXXXX 100644 | 182 | + MPQemuMsg msg = { 0 }; |
75 | --- a/block/rbd.c | 183 | + uint64_t ret = -EINVAL; |
76 | +++ b/block/rbd.c | 184 | + Error *local_err = NULL; |
77 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | 185 | + |
78 | goto failed_open; | 186 | + msg.cmd = op; |
79 | } | 187 | + msg.data.pci_conf_data.addr = addr; |
80 | 188 | + msg.data.pci_conf_data.val = (op == MPQEMU_CMD_PCI_CFGWRITE) ? *val : 0; | |
81 | - bs->read_only = (s->snap != NULL); | 189 | + msg.data.pci_conf_data.len = len; |
82 | + bdrv_set_read_only(bs, (s->snap != NULL)); | 190 | + msg.size = sizeof(PciConfDataMsg); |
83 | 191 | + | |
84 | qemu_opts_del(opts); | 192 | + ret = mpqemu_msg_send_and_await_reply(&msg, pdev, &local_err); |
85 | return 0; | 193 | + if (local_err) { |
86 | diff --git a/block/vvfat.c b/block/vvfat.c | 194 | + error_report_err(local_err); |
87 | index XXXXXXX..XXXXXXX 100644 | 195 | + } |
88 | --- a/block/vvfat.c | 196 | + |
89 | +++ b/block/vvfat.c | 197 | + if (ret == UINT64_MAX) { |
90 | @@ -XXX,XX +XXX,XX @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, | 198 | + error_report("Failed to perform PCI config %s operation", |
91 | s->current_cluster=0xffffffff; | 199 | + (op == MPQEMU_CMD_PCI_CFGREAD) ? "READ" : "WRITE"); |
92 | 200 | + } | |
93 | /* read only is the default for safety */ | 201 | + |
94 | - bs->read_only = true; | 202 | + if (op == MPQEMU_CMD_PCI_CFGREAD) { |
95 | + bdrv_set_read_only(bs, true); | 203 | + *val = (uint32_t)ret; |
96 | s->qcow = NULL; | 204 | + } |
97 | s->qcow_filename = NULL; | 205 | +} |
98 | s->fat2 = NULL; | 206 | + |
99 | @@ -XXX,XX +XXX,XX @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, | 207 | +static uint32_t pci_proxy_read_config(PCIDevice *d, uint32_t addr, int len) |
100 | if (ret < 0) { | 208 | +{ |
101 | goto fail; | 209 | + uint32_t val; |
102 | } | 210 | + |
103 | - bs->read_only = false; | 211 | + config_op_send(PCI_PROXY_DEV(d), addr, &val, len, MPQEMU_CMD_PCI_CFGREAD); |
104 | + bdrv_set_read_only(bs, false); | 212 | + |
105 | } | 213 | + return val; |
106 | 214 | +} | |
107 | bs->total_sectors = cyls * heads * secs; | 215 | + |
108 | diff --git a/include/block/block.h b/include/block/block.h | 216 | +static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val, |
109 | index XXXXXXX..XXXXXXX 100644 | 217 | + int len) |
110 | --- a/include/block/block.h | 218 | +{ |
111 | +++ b/include/block/block.h | 219 | + /* |
112 | @@ -XXX,XX +XXX,XX @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, | 220 | + * Some of the functions access the copy of remote device's PCI config |
113 | int64_t sector_num, int nb_sectors, int *pnum); | 221 | + * space which is cached in the proxy device. Therefore, maintain |
114 | 222 | + * it updated. | |
115 | bool bdrv_is_read_only(BlockDriverState *bs); | 223 | + */ |
116 | +void bdrv_set_read_only(BlockDriverState *bs, bool read_only); | 224 | + pci_default_write_config(d, addr, val, len); |
117 | bool bdrv_is_sg(BlockDriverState *bs); | 225 | + |
118 | bool bdrv_is_inserted(BlockDriverState *bs); | 226 | + config_op_send(PCI_PROXY_DEV(d), addr, &val, len, MPQEMU_CMD_PCI_CFGWRITE); |
119 | int bdrv_media_changed(BlockDriverState *bs); | 227 | +} |
228 | + | ||
229 | static Property proxy_properties[] = { | ||
230 | DEFINE_PROP_STRING("fd", PCIProxyDev, fd), | ||
231 | DEFINE_PROP_END_OF_LIST(), | ||
232 | @@ -XXX,XX +XXX,XX @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) | ||
233 | |||
234 | k->realize = pci_proxy_dev_realize; | ||
235 | k->exit = pci_proxy_dev_exit; | ||
236 | + k->config_read = pci_proxy_read_config; | ||
237 | + k->config_write = pci_proxy_write_config; | ||
238 | + | ||
239 | device_class_set_props(dc, proxy_properties); | ||
240 | } | ||
241 | |||
120 | -- | 242 | -- |
121 | 2.9.3 | 243 | 2.29.2 |
122 | 244 | ||
123 | diff view generated by jsdifflib |
1 | Move bdrv_is_read_only() up with its friends. | 1 | From: Jagannathan Raman <jag.raman@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | Proxy device object implements handler for PCI BAR writes and reads. | ||
4 | The handler uses BAR_WRITE/BAR_READ message to communicate to the | ||
5 | remote process with the BAR address and value to be written/read. | ||
6 | The remote process implements handler for BAR_WRITE/BAR_READ | ||
7 | message. | ||
8 | |||
9 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
10 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
11 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> | ||
3 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 12 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | Reviewed-by: John Snow <jsnow@redhat.com> | 13 | Message-id: a8b76714a9688be5552c4c92d089bc9e8a4707ff.1611938319.git.jag.raman@oracle.com |
5 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
6 | Message-id: 73b2399459760c32506f9407efb9dddb3a2789de.1491597120.git.jcody@redhat.com | ||
7 | --- | 15 | --- |
8 | block.c | 10 +++++----- | 16 | include/hw/remote/mpqemu-link.h | 10 ++++ |
9 | 1 file changed, 5 insertions(+), 5 deletions(-) | 17 | include/hw/remote/proxy.h | 9 ++++ |
10 | 18 | hw/remote/message.c | 83 +++++++++++++++++++++++++++++++++ | |
11 | diff --git a/block.c b/block.c | 19 | hw/remote/mpqemu-link.c | 6 +++ |
12 | index XXXXXXX..XXXXXXX 100644 | 20 | hw/remote/proxy.c | 60 ++++++++++++++++++++++++ |
13 | --- a/block.c | 21 | 5 files changed, 168 insertions(+) |
14 | +++ b/block.c | 22 | |
15 | @@ -XXX,XX +XXX,XX @@ void path_combine(char *dest, int dest_size, | 23 | diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h |
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/include/hw/remote/mpqemu-link.h | ||
26 | +++ b/include/hw/remote/mpqemu-link.h | ||
27 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
28 | MPQEMU_CMD_RET, | ||
29 | MPQEMU_CMD_PCI_CFGWRITE, | ||
30 | MPQEMU_CMD_PCI_CFGREAD, | ||
31 | + MPQEMU_CMD_BAR_WRITE, | ||
32 | + MPQEMU_CMD_BAR_READ, | ||
33 | MPQEMU_CMD_MAX, | ||
34 | } MPQemuCmd; | ||
35 | |||
36 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
37 | int len; | ||
38 | } PciConfDataMsg; | ||
39 | |||
40 | +typedef struct { | ||
41 | + hwaddr addr; | ||
42 | + uint64_t val; | ||
43 | + unsigned size; | ||
44 | + bool memory; | ||
45 | +} BarAccessMsg; | ||
46 | + | ||
47 | /** | ||
48 | * MPQemuMsg: | ||
49 | * @cmd: The remote command | ||
50 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
51 | uint64_t u64; | ||
52 | PciConfDataMsg pci_conf_data; | ||
53 | SyncSysmemMsg sync_sysmem; | ||
54 | + BarAccessMsg bar_access; | ||
55 | } data; | ||
56 | |||
57 | int fds[REMOTE_MAX_FDS]; | ||
58 | diff --git a/include/hw/remote/proxy.h b/include/hw/remote/proxy.h | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/include/hw/remote/proxy.h | ||
61 | +++ b/include/hw/remote/proxy.h | ||
62 | @@ -XXX,XX +XXX,XX @@ | ||
63 | #define TYPE_PCI_PROXY_DEV "x-pci-proxy-dev" | ||
64 | OBJECT_DECLARE_SIMPLE_TYPE(PCIProxyDev, PCI_PROXY_DEV) | ||
65 | |||
66 | +typedef struct ProxyMemoryRegion { | ||
67 | + PCIProxyDev *dev; | ||
68 | + MemoryRegion mr; | ||
69 | + bool memory; | ||
70 | + bool present; | ||
71 | + uint8_t type; | ||
72 | +} ProxyMemoryRegion; | ||
73 | + | ||
74 | struct PCIProxyDev { | ||
75 | PCIDevice parent_dev; | ||
76 | char *fd; | ||
77 | @@ -XXX,XX +XXX,XX @@ struct PCIProxyDev { | ||
78 | QemuMutex io_mutex; | ||
79 | QIOChannel *ioc; | ||
80 | Error *migration_blocker; | ||
81 | + ProxyMemoryRegion region[PCI_NUM_REGIONS]; | ||
82 | }; | ||
83 | |||
84 | #endif /* PROXY_H */ | ||
85 | diff --git a/hw/remote/message.c b/hw/remote/message.c | ||
86 | index XXXXXXX..XXXXXXX 100644 | ||
87 | --- a/hw/remote/message.c | ||
88 | +++ b/hw/remote/message.c | ||
89 | @@ -XXX,XX +XXX,XX @@ | ||
90 | #include "qapi/error.h" | ||
91 | #include "sysemu/runstate.h" | ||
92 | #include "hw/pci/pci.h" | ||
93 | +#include "exec/memattrs.h" | ||
94 | |||
95 | static void process_config_write(QIOChannel *ioc, PCIDevice *dev, | ||
96 | MPQemuMsg *msg, Error **errp); | ||
97 | static void process_config_read(QIOChannel *ioc, PCIDevice *dev, | ||
98 | MPQemuMsg *msg, Error **errp); | ||
99 | +static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **errp); | ||
100 | +static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp); | ||
101 | |||
102 | void coroutine_fn mpqemu_remote_msg_loop_co(void *data) | ||
103 | { | ||
104 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) | ||
105 | case MPQEMU_CMD_PCI_CFGREAD: | ||
106 | process_config_read(com->ioc, pci_dev, &msg, &local_err); | ||
107 | break; | ||
108 | + case MPQEMU_CMD_BAR_WRITE: | ||
109 | + process_bar_write(com->ioc, &msg, &local_err); | ||
110 | + break; | ||
111 | + case MPQEMU_CMD_BAR_READ: | ||
112 | + process_bar_read(com->ioc, &msg, &local_err); | ||
113 | + break; | ||
114 | default: | ||
115 | error_setg(&local_err, | ||
116 | "Unknown command (%d) received for device %s" | ||
117 | @@ -XXX,XX +XXX,XX @@ static void process_config_read(QIOChannel *ioc, PCIDevice *dev, | ||
118 | getpid()); | ||
16 | } | 119 | } |
17 | } | 120 | } |
18 | 121 | + | |
19 | +bool bdrv_is_read_only(BlockDriverState *bs) | 122 | +static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **errp) |
20 | +{ | 123 | +{ |
21 | + return bs->read_only; | 124 | + ERRP_GUARD(); |
22 | +} | 125 | + BarAccessMsg *bar_access = &msg->data.bar_access; |
23 | + | 126 | + AddressSpace *as = |
24 | int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 127 | + bar_access->memory ? &address_space_memory : &address_space_io; |
25 | { | 128 | + MPQemuMsg ret = { 0 }; |
26 | /* Do not set read_only if copy_on_read is enabled */ | 129 | + MemTxResult res; |
27 | @@ -XXX,XX +XXX,XX @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr) | 130 | + uint64_t val; |
28 | *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors; | 131 | + |
132 | + if (!is_power_of_2(bar_access->size) || | ||
133 | + (bar_access->size > sizeof(uint64_t))) { | ||
134 | + ret.data.u64 = UINT64_MAX; | ||
135 | + goto fail; | ||
136 | + } | ||
137 | + | ||
138 | + val = cpu_to_le64(bar_access->val); | ||
139 | + | ||
140 | + res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, | ||
141 | + (void *)&val, bar_access->size, true); | ||
142 | + | ||
143 | + if (res != MEMTX_OK) { | ||
144 | + error_setg(errp, "Bad address %"PRIx64" for mem write, pid "FMT_pid".", | ||
145 | + bar_access->addr, getpid()); | ||
146 | + ret.data.u64 = -1; | ||
147 | + } | ||
148 | + | ||
149 | +fail: | ||
150 | + ret.cmd = MPQEMU_CMD_RET; | ||
151 | + ret.size = sizeof(ret.data.u64); | ||
152 | + | ||
153 | + if (!mpqemu_msg_send(&ret, ioc, NULL)) { | ||
154 | + error_prepend(errp, "Error returning code to proxy, pid "FMT_pid": ", | ||
155 | + getpid()); | ||
156 | + } | ||
157 | +} | ||
158 | + | ||
159 | +static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp) | ||
160 | +{ | ||
161 | + ERRP_GUARD(); | ||
162 | + BarAccessMsg *bar_access = &msg->data.bar_access; | ||
163 | + MPQemuMsg ret = { 0 }; | ||
164 | + AddressSpace *as; | ||
165 | + MemTxResult res; | ||
166 | + uint64_t val = 0; | ||
167 | + | ||
168 | + as = bar_access->memory ? &address_space_memory : &address_space_io; | ||
169 | + | ||
170 | + if (!is_power_of_2(bar_access->size) || | ||
171 | + (bar_access->size > sizeof(uint64_t))) { | ||
172 | + val = UINT64_MAX; | ||
173 | + goto fail; | ||
174 | + } | ||
175 | + | ||
176 | + res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, | ||
177 | + (void *)&val, bar_access->size, false); | ||
178 | + | ||
179 | + if (res != MEMTX_OK) { | ||
180 | + error_setg(errp, "Bad address %"PRIx64" for mem read, pid "FMT_pid".", | ||
181 | + bar_access->addr, getpid()); | ||
182 | + val = UINT64_MAX; | ||
183 | + } | ||
184 | + | ||
185 | +fail: | ||
186 | + ret.cmd = MPQEMU_CMD_RET; | ||
187 | + ret.data.u64 = le64_to_cpu(val); | ||
188 | + ret.size = sizeof(ret.data.u64); | ||
189 | + | ||
190 | + if (!mpqemu_msg_send(&ret, ioc, NULL)) { | ||
191 | + error_prepend(errp, "Error returning code to proxy, pid "FMT_pid": ", | ||
192 | + getpid()); | ||
193 | + } | ||
194 | +} | ||
195 | diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c | ||
196 | index XXXXXXX..XXXXXXX 100644 | ||
197 | --- a/hw/remote/mpqemu-link.c | ||
198 | +++ b/hw/remote/mpqemu-link.c | ||
199 | @@ -XXX,XX +XXX,XX @@ bool mpqemu_msg_valid(MPQemuMsg *msg) | ||
200 | return false; | ||
201 | } | ||
202 | break; | ||
203 | + case MPQEMU_CMD_BAR_WRITE: | ||
204 | + case MPQEMU_CMD_BAR_READ: | ||
205 | + if ((msg->size != sizeof(BarAccessMsg)) || (msg->num_fds != 0)) { | ||
206 | + return false; | ||
207 | + } | ||
208 | + break; | ||
209 | default: | ||
210 | break; | ||
211 | } | ||
212 | diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c | ||
213 | index XXXXXXX..XXXXXXX 100644 | ||
214 | --- a/hw/remote/proxy.c | ||
215 | +++ b/hw/remote/proxy.c | ||
216 | @@ -XXX,XX +XXX,XX @@ static void pci_proxy_dev_register_types(void) | ||
29 | } | 217 | } |
30 | 218 | ||
31 | -bool bdrv_is_read_only(BlockDriverState *bs) | 219 | type_init(pci_proxy_dev_register_types) |
32 | -{ | 220 | + |
33 | - return bs->read_only; | 221 | +static void send_bar_access_msg(PCIProxyDev *pdev, MemoryRegion *mr, |
34 | -} | 222 | + bool write, hwaddr addr, uint64_t *val, |
35 | - | 223 | + unsigned size, bool memory) |
36 | bool bdrv_is_sg(BlockDriverState *bs) | 224 | +{ |
37 | { | 225 | + MPQemuMsg msg = { 0 }; |
38 | return bs->sg; | 226 | + long ret = -EINVAL; |
227 | + Error *local_err = NULL; | ||
228 | + | ||
229 | + msg.size = sizeof(BarAccessMsg); | ||
230 | + msg.data.bar_access.addr = mr->addr + addr; | ||
231 | + msg.data.bar_access.size = size; | ||
232 | + msg.data.bar_access.memory = memory; | ||
233 | + | ||
234 | + if (write) { | ||
235 | + msg.cmd = MPQEMU_CMD_BAR_WRITE; | ||
236 | + msg.data.bar_access.val = *val; | ||
237 | + } else { | ||
238 | + msg.cmd = MPQEMU_CMD_BAR_READ; | ||
239 | + } | ||
240 | + | ||
241 | + ret = mpqemu_msg_send_and_await_reply(&msg, pdev, &local_err); | ||
242 | + if (local_err) { | ||
243 | + error_report_err(local_err); | ||
244 | + } | ||
245 | + | ||
246 | + if (!write) { | ||
247 | + *val = ret; | ||
248 | + } | ||
249 | +} | ||
250 | + | ||
251 | +static void proxy_bar_write(void *opaque, hwaddr addr, uint64_t val, | ||
252 | + unsigned size) | ||
253 | +{ | ||
254 | + ProxyMemoryRegion *pmr = opaque; | ||
255 | + | ||
256 | + send_bar_access_msg(pmr->dev, &pmr->mr, true, addr, &val, size, | ||
257 | + pmr->memory); | ||
258 | +} | ||
259 | + | ||
260 | +static uint64_t proxy_bar_read(void *opaque, hwaddr addr, unsigned size) | ||
261 | +{ | ||
262 | + ProxyMemoryRegion *pmr = opaque; | ||
263 | + uint64_t val; | ||
264 | + | ||
265 | + send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size, | ||
266 | + pmr->memory); | ||
267 | + | ||
268 | + return val; | ||
269 | +} | ||
270 | + | ||
271 | +const MemoryRegionOps proxy_mr_ops = { | ||
272 | + .read = proxy_bar_read, | ||
273 | + .write = proxy_bar_write, | ||
274 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
275 | + .impl = { | ||
276 | + .min_access_size = 1, | ||
277 | + .max_access_size = 8, | ||
278 | + }, | ||
279 | +}; | ||
39 | -- | 280 | -- |
40 | 2.9.3 | 281 | 2.29.2 |
41 | 282 | ||
42 | diff view generated by jsdifflib |
1 | From: Ashish Mittal <ashmit602@gmail.com> | 1 | From: Jagannathan Raman <jag.raman@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | Source code for the qnio library that this code loads can be downloaded from: | 3 | Add ProxyMemoryListener object which is used to keep the view of the RAM |
4 | https://github.com/VeritasHyperScale/libqnio.git | 4 | in sync between QEMU and remote process. |
5 | A MemoryListener is registered for system-memory AddressSpace. The | ||
6 | listener sends SYNC_SYSMEM message to the remote process when memory | ||
7 | listener commits the changes to memory, the remote process receives | ||
8 | the message and processes it in the handler for SYNC_SYSMEM message. | ||
5 | 9 | ||
6 | Sample command line using JSON syntax: | 10 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> |
7 | ./x86_64-softmmu/qemu-system-x86_64 -name instance-00000008 -S -vnc 0.0.0.0:0 | 11 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> |
8 | -k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 | 12 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> |
9 | -msg timestamp=on | 13 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
10 | 'json:{"driver":"vxhs","vdisk-id":"c3e9095a-a5ee-4dce-afeb-2a59fb387410", | 14 | Message-id: 04fe4e6a9ca90d4f11ab6f59be7652f5b086a071.1611938319.git.jag.raman@oracle.com |
11 | "server":{"host":"172.172.17.4","port":"9999"}}' | 15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
16 | --- | ||
17 | MAINTAINERS | 2 + | ||
18 | include/hw/remote/proxy-memory-listener.h | 28 +++ | ||
19 | include/hw/remote/proxy.h | 2 + | ||
20 | hw/remote/message.c | 4 + | ||
21 | hw/remote/proxy-memory-listener.c | 227 ++++++++++++++++++++++ | ||
22 | hw/remote/proxy.c | 6 + | ||
23 | hw/remote/meson.build | 1 + | ||
24 | 7 files changed, 270 insertions(+) | ||
25 | create mode 100644 include/hw/remote/proxy-memory-listener.h | ||
26 | create mode 100644 hw/remote/proxy-memory-listener.c | ||
12 | 27 | ||
13 | Sample command line using URI syntax: | 28 | diff --git a/MAINTAINERS b/MAINTAINERS |
14 | qemu-img convert -f raw -O raw -n | 29 | index XXXXXXX..XXXXXXX 100644 |
15 | /var/lib/nova/instances/_base/0c5eacd5ebea5ed914b6a3e7b18f1ce734c386ad | 30 | --- a/MAINTAINERS |
16 | vxhs://192.168.0.1:9999/c6718f6b-0401-441d-a8c3-1f0064d75ee0 | 31 | +++ b/MAINTAINERS |
17 | 32 | @@ -XXX,XX +XXX,XX @@ F: include/hw/remote/memory.h | |
18 | Sample command line using TLS credentials (run in secure mode): | 33 | F: hw/remote/memory.c |
19 | ./qemu-io --object | 34 | F: hw/remote/proxy.c |
20 | tls-creds-x509,id=tls0,dir=/etc/pki/qemu/vxhs,endpoint=client -c 'read | 35 | F: include/hw/remote/proxy.h |
21 | -v 66000 2.5k' 'json:{"server.host": "127.0.0.1", "server.port": "9999", | 36 | +F: hw/remote/proxy-memory-listener.c |
22 | "vdisk-id": "/test.raw", "driver": "vxhs", "tls-creds":"tls0"}' | 37 | +F: include/hw/remote/proxy-memory-listener.h |
23 | 38 | ||
24 | Signed-off-by: Ashish Mittal <Ashish.Mittal@veritas.com> | 39 | Build and test automation |
25 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 40 | ------------------------- |
26 | Reviewed-by: Jeff Cody <jcody@redhat.com> | 41 | diff --git a/include/hw/remote/proxy-memory-listener.h b/include/hw/remote/proxy-memory-listener.h |
27 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
28 | Message-id: 1491277689-24949-2-git-send-email-Ashish.Mittal@veritas.com | ||
29 | --- | ||
30 | block/Makefile.objs | 2 + | ||
31 | block/trace-events | 17 ++ | ||
32 | block/vxhs.c | 575 +++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
33 | configure | 39 ++++ | ||
34 | qapi/block-core.json | 23 ++- | ||
35 | 5 files changed, 654 insertions(+), 2 deletions(-) | ||
36 | create mode 100644 block/vxhs.c | ||
37 | |||
38 | diff --git a/block/Makefile.objs b/block/Makefile.objs | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/block/Makefile.objs | ||
41 | +++ b/block/Makefile.objs | ||
42 | @@ -XXX,XX +XXX,XX @@ block-obj-$(CONFIG_LIBNFS) += nfs.o | ||
43 | block-obj-$(CONFIG_CURL) += curl.o | ||
44 | block-obj-$(CONFIG_RBD) += rbd.o | ||
45 | block-obj-$(CONFIG_GLUSTERFS) += gluster.o | ||
46 | +block-obj-$(CONFIG_VXHS) += vxhs.o | ||
47 | block-obj-$(CONFIG_LIBSSH2) += ssh.o | ||
48 | block-obj-y += accounting.o dirty-bitmap.o | ||
49 | block-obj-y += write-threshold.o | ||
50 | @@ -XXX,XX +XXX,XX @@ rbd.o-cflags := $(RBD_CFLAGS) | ||
51 | rbd.o-libs := $(RBD_LIBS) | ||
52 | gluster.o-cflags := $(GLUSTERFS_CFLAGS) | ||
53 | gluster.o-libs := $(GLUSTERFS_LIBS) | ||
54 | +vxhs.o-libs := $(VXHS_LIBS) | ||
55 | ssh.o-cflags := $(LIBSSH2_CFLAGS) | ||
56 | ssh.o-libs := $(LIBSSH2_LIBS) | ||
57 | block-obj-$(if $(CONFIG_BZIP2),m,n) += dmg-bz2.o | ||
58 | diff --git a/block/trace-events b/block/trace-events | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/block/trace-events | ||
61 | +++ b/block/trace-events | ||
62 | @@ -XXX,XX +XXX,XX @@ qed_aio_write_data(void *s, void *acb, int ret, uint64_t offset, size_t len) "s | ||
63 | qed_aio_write_prefill(void *s, void *acb, uint64_t start, size_t len, uint64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64 | ||
64 | qed_aio_write_postfill(void *s, void *acb, uint64_t start, size_t len, uint64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64 | ||
65 | qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu" | ||
66 | + | ||
67 | +# block/vxhs.c | ||
68 | +vxhs_iio_callback(int error) "ctx is NULL: error %d" | ||
69 | +vxhs_iio_callback_chnfail(int err, int error) "QNIO channel failed, no i/o %d, %d" | ||
70 | +vxhs_iio_callback_unknwn(int opcode, int err) "unexpected opcode %d, errno %d" | ||
71 | +vxhs_aio_rw_invalid(int req) "Invalid I/O request iodir %d" | ||
72 | +vxhs_aio_rw_ioerr(char *guid, int iodir, uint64_t size, uint64_t off, void *acb, int ret, int err) "IO ERROR (vDisk %s) FOR : Read/Write = %d size = %lu offset = %lu ACB = %p. Error = %d, errno = %d" | ||
73 | +vxhs_get_vdisk_stat_err(char *guid, int ret, int err) "vDisk (%s) stat ioctl failed, ret = %d, errno = %d" | ||
74 | +vxhs_get_vdisk_stat(char *vdisk_guid, uint64_t vdisk_size) "vDisk %s stat ioctl returned size %lu" | ||
75 | +vxhs_complete_aio(void *acb, uint64_t ret) "aio failed acb %p ret %ld" | ||
76 | +vxhs_parse_uri_filename(const char *filename) "URI passed via bdrv_parse_filename %s" | ||
77 | +vxhs_open_vdiskid(const char *vdisk_id) "Opening vdisk-id %s" | ||
78 | +vxhs_open_hostinfo(char *of_vsa_addr, int port) "Adding host %s:%d to BDRVVXHSState" | ||
79 | +vxhs_open_iio_open(const char *host) "Failed to connect to storage agent on host %s" | ||
80 | +vxhs_parse_uri_hostinfo(char *host, int port) "Host: IP %s, Port %d" | ||
81 | +vxhs_close(char *vdisk_guid) "Closing vdisk %s" | ||
82 | +vxhs_get_creds(const char *cacert, const char *client_key, const char *client_cert) "cacert %s, client_key %s, client_cert %s" | ||
83 | diff --git a/block/vxhs.c b/block/vxhs.c | ||
84 | new file mode 100644 | 42 | new file mode 100644 |
85 | index XXXXXXX..XXXXXXX | 43 | index XXXXXXX..XXXXXXX |
86 | --- /dev/null | 44 | --- /dev/null |
87 | +++ b/block/vxhs.c | 45 | +++ b/include/hw/remote/proxy-memory-listener.h |
88 | @@ -XXX,XX +XXX,XX @@ | 46 | @@ -XXX,XX +XXX,XX @@ |
89 | +/* | 47 | +/* |
90 | + * QEMU Block driver for Veritas HyperScale (VxHS) | 48 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. |
91 | + * | ||
92 | + * Copyright (c) 2017 Veritas Technologies LLC. | ||
93 | + * | 49 | + * |
94 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 50 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
95 | + * See the COPYING file in the top-level directory. | 51 | + * See the COPYING file in the top-level directory. |
96 | + * | 52 | + * |
97 | + */ | 53 | + */ |
98 | + | 54 | + |
55 | +#ifndef PROXY_MEMORY_LISTENER_H | ||
56 | +#define PROXY_MEMORY_LISTENER_H | ||
57 | + | ||
58 | +#include "exec/memory.h" | ||
59 | +#include "io/channel.h" | ||
60 | + | ||
61 | +typedef struct ProxyMemoryListener { | ||
62 | + MemoryListener listener; | ||
63 | + | ||
64 | + int n_mr_sections; | ||
65 | + MemoryRegionSection *mr_sections; | ||
66 | + | ||
67 | + QIOChannel *ioc; | ||
68 | +} ProxyMemoryListener; | ||
69 | + | ||
70 | +void proxy_memory_listener_configure(ProxyMemoryListener *proxy_listener, | ||
71 | + QIOChannel *ioc); | ||
72 | +void proxy_memory_listener_deconfigure(ProxyMemoryListener *proxy_listener); | ||
73 | + | ||
74 | +#endif | ||
75 | diff --git a/include/hw/remote/proxy.h b/include/hw/remote/proxy.h | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/include/hw/remote/proxy.h | ||
78 | +++ b/include/hw/remote/proxy.h | ||
79 | @@ -XXX,XX +XXX,XX @@ | ||
80 | |||
81 | #include "hw/pci/pci.h" | ||
82 | #include "io/channel.h" | ||
83 | +#include "hw/remote/proxy-memory-listener.h" | ||
84 | |||
85 | #define TYPE_PCI_PROXY_DEV "x-pci-proxy-dev" | ||
86 | OBJECT_DECLARE_SIMPLE_TYPE(PCIProxyDev, PCI_PROXY_DEV) | ||
87 | @@ -XXX,XX +XXX,XX @@ struct PCIProxyDev { | ||
88 | QemuMutex io_mutex; | ||
89 | QIOChannel *ioc; | ||
90 | Error *migration_blocker; | ||
91 | + ProxyMemoryListener proxy_listener; | ||
92 | ProxyMemoryRegion region[PCI_NUM_REGIONS]; | ||
93 | }; | ||
94 | |||
95 | diff --git a/hw/remote/message.c b/hw/remote/message.c | ||
96 | index XXXXXXX..XXXXXXX 100644 | ||
97 | --- a/hw/remote/message.c | ||
98 | +++ b/hw/remote/message.c | ||
99 | @@ -XXX,XX +XXX,XX @@ | ||
100 | #include "sysemu/runstate.h" | ||
101 | #include "hw/pci/pci.h" | ||
102 | #include "exec/memattrs.h" | ||
103 | +#include "hw/remote/memory.h" | ||
104 | |||
105 | static void process_config_write(QIOChannel *ioc, PCIDevice *dev, | ||
106 | MPQemuMsg *msg, Error **errp); | ||
107 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) | ||
108 | case MPQEMU_CMD_BAR_READ: | ||
109 | process_bar_read(com->ioc, &msg, &local_err); | ||
110 | break; | ||
111 | + case MPQEMU_CMD_SYNC_SYSMEM: | ||
112 | + remote_sysmem_reconfig(&msg, &local_err); | ||
113 | + break; | ||
114 | default: | ||
115 | error_setg(&local_err, | ||
116 | "Unknown command (%d) received for device %s" | ||
117 | diff --git a/hw/remote/proxy-memory-listener.c b/hw/remote/proxy-memory-listener.c | ||
118 | new file mode 100644 | ||
119 | index XXXXXXX..XXXXXXX | ||
120 | --- /dev/null | ||
121 | +++ b/hw/remote/proxy-memory-listener.c | ||
122 | @@ -XXX,XX +XXX,XX @@ | ||
123 | +/* | ||
124 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | ||
125 | + * | ||
126 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
127 | + * See the COPYING file in the top-level directory. | ||
128 | + * | ||
129 | + */ | ||
130 | + | ||
99 | +#include "qemu/osdep.h" | 131 | +#include "qemu/osdep.h" |
100 | +#include <qnio/qnio_api.h> | 132 | +#include "qemu-common.h" |
101 | +#include <sys/param.h> | 133 | + |
102 | +#include "block/block_int.h" | 134 | +#include "qemu/compiler.h" |
103 | +#include "qapi/qmp/qerror.h" | 135 | +#include "qemu/int128.h" |
104 | +#include "qapi/qmp/qdict.h" | 136 | +#include "qemu/range.h" |
105 | +#include "qapi/qmp/qstring.h" | 137 | +#include "exec/memory.h" |
106 | +#include "trace.h" | 138 | +#include "exec/cpu-common.h" |
107 | +#include "qemu/uri.h" | 139 | +#include "cpu.h" |
140 | +#include "exec/ram_addr.h" | ||
141 | +#include "exec/address-spaces.h" | ||
108 | +#include "qapi/error.h" | 142 | +#include "qapi/error.h" |
109 | +#include "qemu/uuid.h" | 143 | +#include "hw/remote/mpqemu-link.h" |
110 | +#include "crypto/tlscredsx509.h" | 144 | +#include "hw/remote/proxy-memory-listener.h" |
111 | + | ||
112 | +#define VXHS_OPT_FILENAME "filename" | ||
113 | +#define VXHS_OPT_VDISK_ID "vdisk-id" | ||
114 | +#define VXHS_OPT_SERVER "server" | ||
115 | +#define VXHS_OPT_HOST "host" | ||
116 | +#define VXHS_OPT_PORT "port" | ||
117 | + | ||
118 | +/* Only accessed under QEMU global mutex */ | ||
119 | +static uint32_t vxhs_ref; | ||
120 | + | ||
121 | +typedef enum { | ||
122 | + VDISK_AIO_READ, | ||
123 | + VDISK_AIO_WRITE, | ||
124 | +} VDISKAIOCmd; | ||
125 | + | 145 | + |
126 | +/* | 146 | +/* |
127 | + * HyperScale AIO callbacks structure | 147 | + * TODO: get_fd_from_hostaddr(), proxy_mrs_can_merge() and |
148 | + * proxy_memory_listener_commit() defined below perform tasks similar to the | ||
149 | + * functions defined in vhost-user.c. These functions are good candidates | ||
150 | + * for refactoring. | ||
151 | + * | ||
128 | + */ | 152 | + */ |
129 | +typedef struct VXHSAIOCB { | 153 | + |
130 | + BlockAIOCB common; | 154 | +static void proxy_memory_listener_reset(MemoryListener *listener) |
131 | + int err; | 155 | +{ |
132 | +} VXHSAIOCB; | 156 | + ProxyMemoryListener *proxy_listener = container_of(listener, |
133 | + | 157 | + ProxyMemoryListener, |
134 | +typedef struct VXHSvDiskHostsInfo { | 158 | + listener); |
135 | + void *dev_handle; /* Device handle */ | 159 | + int mrs; |
136 | + char *host; /* Host name or IP */ | 160 | + |
137 | + int port; /* Host's port number */ | 161 | + for (mrs = 0; mrs < proxy_listener->n_mr_sections; mrs++) { |
138 | +} VXHSvDiskHostsInfo; | 162 | + memory_region_unref(proxy_listener->mr_sections[mrs].mr); |
139 | + | 163 | + } |
140 | +/* | 164 | + |
141 | + * Structure per vDisk maintained for state | 165 | + g_free(proxy_listener->mr_sections); |
142 | + */ | 166 | + proxy_listener->mr_sections = NULL; |
143 | +typedef struct BDRVVXHSState { | 167 | + proxy_listener->n_mr_sections = 0; |
144 | + VXHSvDiskHostsInfo vdisk_hostinfo; /* Per host info */ | 168 | +} |
145 | + char *vdisk_guid; | 169 | + |
146 | + char *tlscredsid; /* tlscredsid */ | 170 | +static int get_fd_from_hostaddr(uint64_t host, ram_addr_t *offset) |
147 | +} BDRVVXHSState; | 171 | +{ |
148 | + | 172 | + MemoryRegion *mr; |
149 | +static void vxhs_complete_aio_bh(void *opaque) | 173 | + ram_addr_t off; |
150 | +{ | 174 | + |
151 | + VXHSAIOCB *acb = opaque; | 175 | + /** |
152 | + BlockCompletionFunc *cb = acb->common.cb; | 176 | + * Assumes that the host address is a valid address as it's |
153 | + void *cb_opaque = acb->common.opaque; | 177 | + * coming from the MemoryListener system. In the case host |
154 | + int ret = 0; | 178 | + * address is not valid, the following call would return |
155 | + | 179 | + * the default subregion of "system_memory" region, and |
156 | + if (acb->err != 0) { | 180 | + * not NULL. So it's not possible to check for NULL here. |
157 | + trace_vxhs_complete_aio(acb, acb->err); | 181 | + */ |
158 | + ret = (-EIO); | 182 | + mr = memory_region_from_host((void *)(uintptr_t)host, &off); |
159 | + } | 183 | + |
160 | + | 184 | + if (offset) { |
161 | + qemu_aio_unref(acb); | 185 | + *offset = off; |
162 | + cb(cb_opaque, ret); | 186 | + } |
163 | +} | 187 | + |
164 | + | 188 | + return memory_region_get_fd(mr); |
165 | +/* | 189 | +} |
166 | + * Called from a libqnio thread | 190 | + |
167 | + */ | 191 | +static bool proxy_mrs_can_merge(uint64_t host, uint64_t prev_host, size_t size) |
168 | +static void vxhs_iio_callback(void *ctx, uint32_t opcode, uint32_t error) | 192 | +{ |
169 | +{ | 193 | + if (((prev_host + size) != host)) { |
170 | + VXHSAIOCB *acb = NULL; | 194 | + return false; |
171 | + | 195 | + } |
172 | + switch (opcode) { | 196 | + |
173 | + case IRP_READ_REQUEST: | 197 | + if (get_fd_from_hostaddr(host, NULL) != |
174 | + case IRP_WRITE_REQUEST: | 198 | + get_fd_from_hostaddr(prev_host, NULL)) { |
175 | + | 199 | + return false; |
176 | + /* | 200 | + } |
177 | + * ctx is VXHSAIOCB* | 201 | + |
178 | + * ctx is NULL if error is QNIOERROR_CHANNEL_HUP | 202 | + return true; |
179 | + */ | 203 | +} |
180 | + if (ctx) { | 204 | + |
181 | + acb = ctx; | 205 | +static bool try_merge(ProxyMemoryListener *proxy_listener, |
182 | + } else { | 206 | + MemoryRegionSection *section) |
183 | + trace_vxhs_iio_callback(error); | 207 | +{ |
184 | + goto out; | 208 | + uint64_t mrs_size, mrs_gpa, mrs_page; |
209 | + MemoryRegionSection *prev_sec; | ||
210 | + bool merged = false; | ||
211 | + uintptr_t mrs_host; | ||
212 | + RAMBlock *mrs_rb; | ||
213 | + | ||
214 | + if (!proxy_listener->n_mr_sections) { | ||
215 | + return false; | ||
216 | + } | ||
217 | + | ||
218 | + mrs_rb = section->mr->ram_block; | ||
219 | + mrs_page = (uint64_t)qemu_ram_pagesize(mrs_rb); | ||
220 | + mrs_size = int128_get64(section->size); | ||
221 | + mrs_gpa = section->offset_within_address_space; | ||
222 | + mrs_host = (uintptr_t)memory_region_get_ram_ptr(section->mr) + | ||
223 | + section->offset_within_region; | ||
224 | + | ||
225 | + if (get_fd_from_hostaddr(mrs_host, NULL) < 0) { | ||
226 | + return true; | ||
227 | + } | ||
228 | + | ||
229 | + mrs_host = mrs_host & ~(mrs_page - 1); | ||
230 | + mrs_gpa = mrs_gpa & ~(mrs_page - 1); | ||
231 | + mrs_size = ROUND_UP(mrs_size, mrs_page); | ||
232 | + | ||
233 | + prev_sec = proxy_listener->mr_sections + | ||
234 | + (proxy_listener->n_mr_sections - 1); | ||
235 | + uint64_t prev_gpa_start = prev_sec->offset_within_address_space; | ||
236 | + uint64_t prev_size = int128_get64(prev_sec->size); | ||
237 | + uint64_t prev_gpa_end = range_get_last(prev_gpa_start, prev_size); | ||
238 | + uint64_t prev_host_start = | ||
239 | + (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) + | ||
240 | + prev_sec->offset_within_region; | ||
241 | + uint64_t prev_host_end = range_get_last(prev_host_start, prev_size); | ||
242 | + | ||
243 | + if (mrs_gpa <= (prev_gpa_end + 1)) { | ||
244 | + g_assert(mrs_gpa > prev_gpa_start); | ||
245 | + | ||
246 | + if ((section->mr == prev_sec->mr) && | ||
247 | + proxy_mrs_can_merge(mrs_host, prev_host_start, | ||
248 | + (mrs_gpa - prev_gpa_start))) { | ||
249 | + uint64_t max_end = MAX(prev_host_end, mrs_host + mrs_size); | ||
250 | + merged = true; | ||
251 | + prev_sec->offset_within_address_space = | ||
252 | + MIN(prev_gpa_start, mrs_gpa); | ||
253 | + prev_sec->offset_within_region = | ||
254 | + MIN(prev_host_start, mrs_host) - | ||
255 | + (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr); | ||
256 | + prev_sec->size = int128_make64(max_end - MIN(prev_host_start, | ||
257 | + mrs_host)); | ||
185 | + } | 258 | + } |
186 | + | 259 | + } |
187 | + if (error) { | 260 | + |
188 | + if (!acb->err) { | 261 | + return merged; |
189 | + acb->err = error; | 262 | +} |
190 | + } | 263 | + |
191 | + trace_vxhs_iio_callback(error); | 264 | +static void proxy_memory_listener_region_addnop(MemoryListener *listener, |
192 | + } | 265 | + MemoryRegionSection *section) |
193 | + | 266 | +{ |
194 | + aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs), | 267 | + ProxyMemoryListener *proxy_listener = container_of(listener, |
195 | + vxhs_complete_aio_bh, acb); | 268 | + ProxyMemoryListener, |
196 | + break; | 269 | + listener); |
197 | + | 270 | + |
198 | + default: | 271 | + if (!memory_region_is_ram(section->mr) || |
199 | + if (error == QNIOERROR_HUP) { | 272 | + memory_region_is_rom(section->mr)) { |
200 | + /* | ||
201 | + * Channel failed, spontaneous notification, | ||
202 | + * not in response to I/O | ||
203 | + */ | ||
204 | + trace_vxhs_iio_callback_chnfail(error, errno); | ||
205 | + } else { | ||
206 | + trace_vxhs_iio_callback_unknwn(opcode, error); | ||
207 | + } | ||
208 | + break; | ||
209 | + } | ||
210 | +out: | ||
211 | + return; | ||
212 | +} | ||
213 | + | ||
214 | +static QemuOptsList runtime_opts = { | ||
215 | + .name = "vxhs", | ||
216 | + .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), | ||
217 | + .desc = { | ||
218 | + { | ||
219 | + .name = VXHS_OPT_FILENAME, | ||
220 | + .type = QEMU_OPT_STRING, | ||
221 | + .help = "URI to the Veritas HyperScale image", | ||
222 | + }, | ||
223 | + { | ||
224 | + .name = VXHS_OPT_VDISK_ID, | ||
225 | + .type = QEMU_OPT_STRING, | ||
226 | + .help = "UUID of the VxHS vdisk", | ||
227 | + }, | ||
228 | + { | ||
229 | + .name = "tls-creds", | ||
230 | + .type = QEMU_OPT_STRING, | ||
231 | + .help = "ID of the TLS/SSL credentials to use", | ||
232 | + }, | ||
233 | + { /* end of list */ } | ||
234 | + }, | ||
235 | +}; | ||
236 | + | ||
237 | +static QemuOptsList runtime_tcp_opts = { | ||
238 | + .name = "vxhs_tcp", | ||
239 | + .head = QTAILQ_HEAD_INITIALIZER(runtime_tcp_opts.head), | ||
240 | + .desc = { | ||
241 | + { | ||
242 | + .name = VXHS_OPT_HOST, | ||
243 | + .type = QEMU_OPT_STRING, | ||
244 | + .help = "host address (ipv4 addresses)", | ||
245 | + }, | ||
246 | + { | ||
247 | + .name = VXHS_OPT_PORT, | ||
248 | + .type = QEMU_OPT_NUMBER, | ||
249 | + .help = "port number on which VxHSD is listening (default 9999)", | ||
250 | + .def_value_str = "9999" | ||
251 | + }, | ||
252 | + { /* end of list */ } | ||
253 | + }, | ||
254 | +}; | ||
255 | + | ||
256 | +/* | ||
257 | + * Parse incoming URI and populate *options with the host | ||
258 | + * and device information | ||
259 | + */ | ||
260 | +static int vxhs_parse_uri(const char *filename, QDict *options) | ||
261 | +{ | ||
262 | + URI *uri = NULL; | ||
263 | + char *port; | ||
264 | + int ret = 0; | ||
265 | + | ||
266 | + trace_vxhs_parse_uri_filename(filename); | ||
267 | + uri = uri_parse(filename); | ||
268 | + if (!uri || !uri->server || !uri->path) { | ||
269 | + uri_free(uri); | ||
270 | + return -EINVAL; | ||
271 | + } | ||
272 | + | ||
273 | + qdict_put(options, VXHS_OPT_SERVER".host", qstring_from_str(uri->server)); | ||
274 | + | ||
275 | + if (uri->port) { | ||
276 | + port = g_strdup_printf("%d", uri->port); | ||
277 | + qdict_put(options, VXHS_OPT_SERVER".port", qstring_from_str(port)); | ||
278 | + g_free(port); | ||
279 | + } | ||
280 | + | ||
281 | + qdict_put(options, "vdisk-id", qstring_from_str(uri->path)); | ||
282 | + | ||
283 | + trace_vxhs_parse_uri_hostinfo(uri->server, uri->port); | ||
284 | + uri_free(uri); | ||
285 | + | ||
286 | + return ret; | ||
287 | +} | ||
288 | + | ||
289 | +static void vxhs_parse_filename(const char *filename, QDict *options, | ||
290 | + Error **errp) | ||
291 | +{ | ||
292 | + if (qdict_haskey(options, "vdisk-id") || qdict_haskey(options, "server")) { | ||
293 | + error_setg(errp, "vdisk-id/server and a file name may not be specified " | ||
294 | + "at the same time"); | ||
295 | + return; | 273 | + return; |
296 | + } | 274 | + } |
297 | + | 275 | + |
298 | + if (strstr(filename, "://")) { | 276 | + if (try_merge(proxy_listener, section)) { |
299 | + int ret = vxhs_parse_uri(filename, options); | ||
300 | + if (ret < 0) { | ||
301 | + error_setg(errp, "Invalid URI. URI should be of the form " | ||
302 | + " vxhs://<host_ip>:<port>/<vdisk-id>"); | ||
303 | + } | ||
304 | + } | ||
305 | +} | ||
306 | + | ||
307 | +static int vxhs_init_and_ref(void) | ||
308 | +{ | ||
309 | + if (vxhs_ref++ == 0) { | ||
310 | + if (iio_init(QNIO_VERSION, vxhs_iio_callback)) { | ||
311 | + return -ENODEV; | ||
312 | + } | ||
313 | + } | ||
314 | + return 0; | ||
315 | +} | ||
316 | + | ||
317 | +static void vxhs_unref(void) | ||
318 | +{ | ||
319 | + if (--vxhs_ref == 0) { | ||
320 | + iio_fini(); | ||
321 | + } | ||
322 | +} | ||
323 | + | ||
324 | +static void vxhs_get_tls_creds(const char *id, char **cacert, | ||
325 | + char **key, char **cert, Error **errp) | ||
326 | +{ | ||
327 | + Object *obj; | ||
328 | + QCryptoTLSCreds *creds; | ||
329 | + QCryptoTLSCredsX509 *creds_x509; | ||
330 | + | ||
331 | + obj = object_resolve_path_component( | ||
332 | + object_get_objects_root(), id); | ||
333 | + | ||
334 | + if (!obj) { | ||
335 | + error_setg(errp, "No TLS credentials with id '%s'", | ||
336 | + id); | ||
337 | + return; | 277 | + return; |
338 | + } | 278 | + } |
339 | + | 279 | + |
340 | + creds_x509 = (QCryptoTLSCredsX509 *) | 280 | + ++proxy_listener->n_mr_sections; |
341 | + object_dynamic_cast(obj, TYPE_QCRYPTO_TLS_CREDS_X509); | 281 | + proxy_listener->mr_sections = g_renew(MemoryRegionSection, |
342 | + | 282 | + proxy_listener->mr_sections, |
343 | + if (!creds_x509) { | 283 | + proxy_listener->n_mr_sections); |
344 | + error_setg(errp, "Object with id '%s' is not TLS credentials", | 284 | + proxy_listener->mr_sections[proxy_listener->n_mr_sections - 1] = *section; |
345 | + id); | 285 | + proxy_listener->mr_sections[proxy_listener->n_mr_sections - 1].fv = NULL; |
286 | + memory_region_ref(section->mr); | ||
287 | +} | ||
288 | + | ||
289 | +static void proxy_memory_listener_commit(MemoryListener *listener) | ||
290 | +{ | ||
291 | + ProxyMemoryListener *proxy_listener = container_of(listener, | ||
292 | + ProxyMemoryListener, | ||
293 | + listener); | ||
294 | + MPQemuMsg msg; | ||
295 | + MemoryRegionSection *section; | ||
296 | + ram_addr_t offset; | ||
297 | + uintptr_t host_addr; | ||
298 | + int region; | ||
299 | + Error *local_err = NULL; | ||
300 | + | ||
301 | + memset(&msg, 0, sizeof(MPQemuMsg)); | ||
302 | + | ||
303 | + msg.cmd = MPQEMU_CMD_SYNC_SYSMEM; | ||
304 | + msg.num_fds = proxy_listener->n_mr_sections; | ||
305 | + msg.size = sizeof(SyncSysmemMsg); | ||
306 | + if (msg.num_fds > REMOTE_MAX_FDS) { | ||
307 | + error_report("Number of fds is more than %d", REMOTE_MAX_FDS); | ||
346 | + return; | 308 | + return; |
347 | + } | 309 | + } |
348 | + | 310 | + |
349 | + creds = &creds_x509->parent_obj; | 311 | + for (region = 0; region < proxy_listener->n_mr_sections; region++) { |
350 | + | 312 | + section = &proxy_listener->mr_sections[region]; |
351 | + if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) { | 313 | + msg.data.sync_sysmem.gpas[region] = |
352 | + error_setg(errp, | 314 | + section->offset_within_address_space; |
353 | + "Expecting TLS credentials with a client endpoint"); | 315 | + msg.data.sync_sysmem.sizes[region] = int128_get64(section->size); |
354 | + return; | 316 | + host_addr = (uintptr_t)memory_region_get_ram_ptr(section->mr) + |
355 | + } | 317 | + section->offset_within_region; |
356 | + | 318 | + msg.fds[region] = get_fd_from_hostaddr(host_addr, &offset); |
357 | + /* | 319 | + msg.data.sync_sysmem.offsets[region] = offset; |
358 | + * Get the cacert, client_cert and client_key file names. | 320 | + } |
359 | + */ | 321 | + if (!mpqemu_msg_send(&msg, proxy_listener->ioc, &local_err)) { |
360 | + if (!creds->dir) { | 322 | + error_report_err(local_err); |
361 | + error_setg(errp, "TLS object missing 'dir' property value"); | 323 | + } |
362 | + return; | 324 | +} |
363 | + } | 325 | + |
364 | + | 326 | +void proxy_memory_listener_deconfigure(ProxyMemoryListener *proxy_listener) |
365 | + *cacert = g_strdup_printf("%s/%s", creds->dir, | 327 | +{ |
366 | + QCRYPTO_TLS_CREDS_X509_CA_CERT); | 328 | + memory_listener_unregister(&proxy_listener->listener); |
367 | + *cert = g_strdup_printf("%s/%s", creds->dir, | 329 | + |
368 | + QCRYPTO_TLS_CREDS_X509_CLIENT_CERT); | 330 | + proxy_memory_listener_reset(&proxy_listener->listener); |
369 | + *key = g_strdup_printf("%s/%s", creds->dir, | 331 | +} |
370 | + QCRYPTO_TLS_CREDS_X509_CLIENT_KEY); | 332 | + |
371 | +} | 333 | +void proxy_memory_listener_configure(ProxyMemoryListener *proxy_listener, |
372 | + | 334 | + QIOChannel *ioc) |
373 | +static int vxhs_open(BlockDriverState *bs, QDict *options, | 335 | +{ |
374 | + int bdrv_flags, Error **errp) | 336 | + proxy_listener->n_mr_sections = 0; |
375 | +{ | 337 | + proxy_listener->mr_sections = NULL; |
376 | + BDRVVXHSState *s = bs->opaque; | 338 | + |
377 | + void *dev_handlep; | 339 | + proxy_listener->ioc = ioc; |
378 | + QDict *backing_options = NULL; | 340 | + |
379 | + QemuOpts *opts = NULL; | 341 | + proxy_listener->listener.begin = proxy_memory_listener_reset; |
380 | + QemuOpts *tcp_opts = NULL; | 342 | + proxy_listener->listener.commit = proxy_memory_listener_commit; |
381 | + char *of_vsa_addr = NULL; | 343 | + proxy_listener->listener.region_add = proxy_memory_listener_region_addnop; |
382 | + Error *local_err = NULL; | 344 | + proxy_listener->listener.region_nop = proxy_memory_listener_region_addnop; |
383 | + const char *vdisk_id_opt; | 345 | + proxy_listener->listener.priority = 10; |
384 | + const char *server_host_opt; | 346 | + |
385 | + int ret = 0; | 347 | + memory_listener_register(&proxy_listener->listener, |
386 | + char *cacert = NULL; | 348 | + &address_space_memory); |
387 | + char *client_key = NULL; | 349 | +} |
388 | + char *client_cert = NULL; | 350 | diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c |
389 | + | 351 | index XXXXXXX..XXXXXXX 100644 |
390 | + ret = vxhs_init_and_ref(); | 352 | --- a/hw/remote/proxy.c |
391 | + if (ret < 0) { | 353 | +++ b/hw/remote/proxy.c |
392 | + ret = -EINVAL; | 354 | @@ -XXX,XX +XXX,XX @@ |
393 | + goto out; | 355 | #include "qemu/sockets.h" |
394 | + } | 356 | #include "hw/remote/mpqemu-link.h" |
395 | + | 357 | #include "qemu/error-report.h" |
396 | + /* Create opts info from runtime_opts and runtime_tcp_opts list */ | 358 | +#include "hw/remote/proxy-memory-listener.h" |
397 | + opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); | 359 | +#include "qom/object.h" |
398 | + tcp_opts = qemu_opts_create(&runtime_tcp_opts, NULL, 0, &error_abort); | 360 | |
399 | + | 361 | static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) |
400 | + qemu_opts_absorb_qdict(opts, options, &local_err); | 362 | { |
401 | + if (local_err) { | 363 | @@ -XXX,XX +XXX,XX @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) |
402 | + ret = -EINVAL; | 364 | |
403 | + goto out; | 365 | qemu_mutex_init(&dev->io_mutex); |
404 | + } | 366 | qio_channel_set_blocking(dev->ioc, true, NULL); |
405 | + | 367 | + |
406 | + /* vdisk-id is the disk UUID */ | 368 | + proxy_memory_listener_configure(&dev->proxy_listener, dev->ioc); |
407 | + vdisk_id_opt = qemu_opt_get(opts, VXHS_OPT_VDISK_ID); | 369 | } |
408 | + if (!vdisk_id_opt) { | 370 | |
409 | + error_setg(&local_err, QERR_MISSING_PARAMETER, VXHS_OPT_VDISK_ID); | 371 | static void pci_proxy_dev_exit(PCIDevice *pdev) |
410 | + ret = -EINVAL; | 372 | @@ -XXX,XX +XXX,XX @@ static void pci_proxy_dev_exit(PCIDevice *pdev) |
411 | + goto out; | 373 | migrate_del_blocker(dev->migration_blocker); |
412 | + } | 374 | |
413 | + | 375 | error_free(dev->migration_blocker); |
414 | + /* vdisk-id may contain a leading '/' */ | 376 | + |
415 | + if (strlen(vdisk_id_opt) > UUID_FMT_LEN + 1) { | 377 | + proxy_memory_listener_deconfigure(&dev->proxy_listener); |
416 | + error_setg(&local_err, "vdisk-id cannot be more than %d characters", | 378 | } |
417 | + UUID_FMT_LEN); | 379 | |
418 | + ret = -EINVAL; | 380 | static void config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, |
419 | + goto out; | 381 | diff --git a/hw/remote/meson.build b/hw/remote/meson.build |
420 | + } | 382 | index XXXXXXX..XXXXXXX 100644 |
421 | + | 383 | --- a/hw/remote/meson.build |
422 | + s->vdisk_guid = g_strdup(vdisk_id_opt); | 384 | +++ b/hw/remote/meson.build |
423 | + trace_vxhs_open_vdiskid(vdisk_id_opt); | 385 | @@ -XXX,XX +XXX,XX @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) |
424 | + | 386 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) |
425 | + /* get the 'server.' arguments */ | 387 | |
426 | + qdict_extract_subqdict(options, &backing_options, VXHS_OPT_SERVER"."); | 388 | specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) |
427 | + | 389 | +specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy-memory-listener.c')) |
428 | + qemu_opts_absorb_qdict(tcp_opts, backing_options, &local_err); | 390 | |
429 | + if (local_err != NULL) { | 391 | softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) |
430 | + ret = -EINVAL; | ||
431 | + goto out; | ||
432 | + } | ||
433 | + | ||
434 | + server_host_opt = qemu_opt_get(tcp_opts, VXHS_OPT_HOST); | ||
435 | + if (!server_host_opt) { | ||
436 | + error_setg(&local_err, QERR_MISSING_PARAMETER, | ||
437 | + VXHS_OPT_SERVER"."VXHS_OPT_HOST); | ||
438 | + ret = -EINVAL; | ||
439 | + goto out; | ||
440 | + } | ||
441 | + | ||
442 | + if (strlen(server_host_opt) > MAXHOSTNAMELEN) { | ||
443 | + error_setg(&local_err, "server.host cannot be more than %d characters", | ||
444 | + MAXHOSTNAMELEN); | ||
445 | + ret = -EINVAL; | ||
446 | + goto out; | ||
447 | + } | ||
448 | + | ||
449 | + /* check if we got tls-creds via the --object argument */ | ||
450 | + s->tlscredsid = g_strdup(qemu_opt_get(opts, "tls-creds")); | ||
451 | + if (s->tlscredsid) { | ||
452 | + vxhs_get_tls_creds(s->tlscredsid, &cacert, &client_key, | ||
453 | + &client_cert, &local_err); | ||
454 | + if (local_err != NULL) { | ||
455 | + ret = -EINVAL; | ||
456 | + goto out; | ||
457 | + } | ||
458 | + trace_vxhs_get_creds(cacert, client_key, client_cert); | ||
459 | + } | ||
460 | + | ||
461 | + s->vdisk_hostinfo.host = g_strdup(server_host_opt); | ||
462 | + s->vdisk_hostinfo.port = g_ascii_strtoll(qemu_opt_get(tcp_opts, | ||
463 | + VXHS_OPT_PORT), | ||
464 | + NULL, 0); | ||
465 | + | ||
466 | + trace_vxhs_open_hostinfo(s->vdisk_hostinfo.host, | ||
467 | + s->vdisk_hostinfo.port); | ||
468 | + | ||
469 | + of_vsa_addr = g_strdup_printf("of://%s:%d", | ||
470 | + s->vdisk_hostinfo.host, | ||
471 | + s->vdisk_hostinfo.port); | ||
472 | + | ||
473 | + /* | ||
474 | + * Open qnio channel to storage agent if not opened before | ||
475 | + */ | ||
476 | + dev_handlep = iio_open(of_vsa_addr, s->vdisk_guid, 0, | ||
477 | + cacert, client_key, client_cert); | ||
478 | + if (dev_handlep == NULL) { | ||
479 | + trace_vxhs_open_iio_open(of_vsa_addr); | ||
480 | + ret = -ENODEV; | ||
481 | + goto out; | ||
482 | + } | ||
483 | + s->vdisk_hostinfo.dev_handle = dev_handlep; | ||
484 | + | ||
485 | +out: | ||
486 | + g_free(of_vsa_addr); | ||
487 | + QDECREF(backing_options); | ||
488 | + qemu_opts_del(tcp_opts); | ||
489 | + qemu_opts_del(opts); | ||
490 | + g_free(cacert); | ||
491 | + g_free(client_key); | ||
492 | + g_free(client_cert); | ||
493 | + | ||
494 | + if (ret < 0) { | ||
495 | + vxhs_unref(); | ||
496 | + error_propagate(errp, local_err); | ||
497 | + g_free(s->vdisk_hostinfo.host); | ||
498 | + g_free(s->vdisk_guid); | ||
499 | + g_free(s->tlscredsid); | ||
500 | + s->vdisk_guid = NULL; | ||
501 | + } | ||
502 | + | ||
503 | + return ret; | ||
504 | +} | ||
505 | + | ||
506 | +static const AIOCBInfo vxhs_aiocb_info = { | ||
507 | + .aiocb_size = sizeof(VXHSAIOCB) | ||
508 | +}; | ||
509 | + | ||
510 | +/* | ||
511 | + * This allocates QEMU-VXHS callback for each IO | ||
512 | + * and is passed to QNIO. When QNIO completes the work, | ||
513 | + * it will be passed back through the callback. | ||
514 | + */ | ||
515 | +static BlockAIOCB *vxhs_aio_rw(BlockDriverState *bs, int64_t sector_num, | ||
516 | + QEMUIOVector *qiov, int nb_sectors, | ||
517 | + BlockCompletionFunc *cb, void *opaque, | ||
518 | + VDISKAIOCmd iodir) | ||
519 | +{ | ||
520 | + VXHSAIOCB *acb = NULL; | ||
521 | + BDRVVXHSState *s = bs->opaque; | ||
522 | + size_t size; | ||
523 | + uint64_t offset; | ||
524 | + int iio_flags = 0; | ||
525 | + int ret = 0; | ||
526 | + void *dev_handle = s->vdisk_hostinfo.dev_handle; | ||
527 | + | ||
528 | + offset = sector_num * BDRV_SECTOR_SIZE; | ||
529 | + size = nb_sectors * BDRV_SECTOR_SIZE; | ||
530 | + acb = qemu_aio_get(&vxhs_aiocb_info, bs, cb, opaque); | ||
531 | + | ||
532 | + /* | ||
533 | + * Initialize VXHSAIOCB. | ||
534 | + */ | ||
535 | + acb->err = 0; | ||
536 | + | ||
537 | + iio_flags = IIO_FLAG_ASYNC; | ||
538 | + | ||
539 | + switch (iodir) { | ||
540 | + case VDISK_AIO_WRITE: | ||
541 | + ret = iio_writev(dev_handle, acb, qiov->iov, qiov->niov, | ||
542 | + offset, (uint64_t)size, iio_flags); | ||
543 | + break; | ||
544 | + case VDISK_AIO_READ: | ||
545 | + ret = iio_readv(dev_handle, acb, qiov->iov, qiov->niov, | ||
546 | + offset, (uint64_t)size, iio_flags); | ||
547 | + break; | ||
548 | + default: | ||
549 | + trace_vxhs_aio_rw_invalid(iodir); | ||
550 | + goto errout; | ||
551 | + } | ||
552 | + | ||
553 | + if (ret != 0) { | ||
554 | + trace_vxhs_aio_rw_ioerr(s->vdisk_guid, iodir, size, offset, | ||
555 | + acb, ret, errno); | ||
556 | + goto errout; | ||
557 | + } | ||
558 | + return &acb->common; | ||
559 | + | ||
560 | +errout: | ||
561 | + qemu_aio_unref(acb); | ||
562 | + return NULL; | ||
563 | +} | ||
564 | + | ||
565 | +static BlockAIOCB *vxhs_aio_readv(BlockDriverState *bs, | ||
566 | + int64_t sector_num, QEMUIOVector *qiov, | ||
567 | + int nb_sectors, | ||
568 | + BlockCompletionFunc *cb, void *opaque) | ||
569 | +{ | ||
570 | + return vxhs_aio_rw(bs, sector_num, qiov, nb_sectors, cb, | ||
571 | + opaque, VDISK_AIO_READ); | ||
572 | +} | ||
573 | + | ||
574 | +static BlockAIOCB *vxhs_aio_writev(BlockDriverState *bs, | ||
575 | + int64_t sector_num, QEMUIOVector *qiov, | ||
576 | + int nb_sectors, | ||
577 | + BlockCompletionFunc *cb, void *opaque) | ||
578 | +{ | ||
579 | + return vxhs_aio_rw(bs, sector_num, qiov, nb_sectors, | ||
580 | + cb, opaque, VDISK_AIO_WRITE); | ||
581 | +} | ||
582 | + | ||
583 | +static void vxhs_close(BlockDriverState *bs) | ||
584 | +{ | ||
585 | + BDRVVXHSState *s = bs->opaque; | ||
586 | + | ||
587 | + trace_vxhs_close(s->vdisk_guid); | ||
588 | + | ||
589 | + g_free(s->vdisk_guid); | ||
590 | + s->vdisk_guid = NULL; | ||
591 | + | ||
592 | + /* | ||
593 | + * Close vDisk device | ||
594 | + */ | ||
595 | + if (s->vdisk_hostinfo.dev_handle) { | ||
596 | + iio_close(s->vdisk_hostinfo.dev_handle); | ||
597 | + s->vdisk_hostinfo.dev_handle = NULL; | ||
598 | + } | ||
599 | + | ||
600 | + vxhs_unref(); | ||
601 | + | ||
602 | + /* | ||
603 | + * Free the dynamically allocated host string etc | ||
604 | + */ | ||
605 | + g_free(s->vdisk_hostinfo.host); | ||
606 | + g_free(s->tlscredsid); | ||
607 | + s->tlscredsid = NULL; | ||
608 | + s->vdisk_hostinfo.host = NULL; | ||
609 | + s->vdisk_hostinfo.port = 0; | ||
610 | +} | ||
611 | + | ||
612 | +static int64_t vxhs_get_vdisk_stat(BDRVVXHSState *s) | ||
613 | +{ | ||
614 | + int64_t vdisk_size = -1; | ||
615 | + int ret = 0; | ||
616 | + void *dev_handle = s->vdisk_hostinfo.dev_handle; | ||
617 | + | ||
618 | + ret = iio_ioctl(dev_handle, IOR_VDISK_STAT, &vdisk_size, 0); | ||
619 | + if (ret < 0) { | ||
620 | + trace_vxhs_get_vdisk_stat_err(s->vdisk_guid, ret, errno); | ||
621 | + return -EIO; | ||
622 | + } | ||
623 | + | ||
624 | + trace_vxhs_get_vdisk_stat(s->vdisk_guid, vdisk_size); | ||
625 | + return vdisk_size; | ||
626 | +} | ||
627 | + | ||
628 | +/* | ||
629 | + * Returns the size of vDisk in bytes. This is required | ||
630 | + * by QEMU block upper block layer so that it is visible | ||
631 | + * to guest. | ||
632 | + */ | ||
633 | +static int64_t vxhs_getlength(BlockDriverState *bs) | ||
634 | +{ | ||
635 | + BDRVVXHSState *s = bs->opaque; | ||
636 | + int64_t vdisk_size; | ||
637 | + | ||
638 | + vdisk_size = vxhs_get_vdisk_stat(s); | ||
639 | + if (vdisk_size < 0) { | ||
640 | + return -EIO; | ||
641 | + } | ||
642 | + | ||
643 | + return vdisk_size; | ||
644 | +} | ||
645 | + | ||
646 | +static BlockDriver bdrv_vxhs = { | ||
647 | + .format_name = "vxhs", | ||
648 | + .protocol_name = "vxhs", | ||
649 | + .instance_size = sizeof(BDRVVXHSState), | ||
650 | + .bdrv_file_open = vxhs_open, | ||
651 | + .bdrv_parse_filename = vxhs_parse_filename, | ||
652 | + .bdrv_close = vxhs_close, | ||
653 | + .bdrv_getlength = vxhs_getlength, | ||
654 | + .bdrv_aio_readv = vxhs_aio_readv, | ||
655 | + .bdrv_aio_writev = vxhs_aio_writev, | ||
656 | +}; | ||
657 | + | ||
658 | +static void bdrv_vxhs_init(void) | ||
659 | +{ | ||
660 | + bdrv_register(&bdrv_vxhs); | ||
661 | +} | ||
662 | + | ||
663 | +block_init(bdrv_vxhs_init); | ||
664 | diff --git a/configure b/configure | ||
665 | index XXXXXXX..XXXXXXX 100755 | ||
666 | --- a/configure | ||
667 | +++ b/configure | ||
668 | @@ -XXX,XX +XXX,XX @@ numa="" | ||
669 | tcmalloc="no" | ||
670 | jemalloc="no" | ||
671 | replication="yes" | ||
672 | +vxhs="" | ||
673 | |||
674 | supported_cpu="no" | ||
675 | supported_os="no" | ||
676 | @@ -XXX,XX +XXX,XX @@ for opt do | ||
677 | ;; | ||
678 | --enable-replication) replication="yes" | ||
679 | ;; | ||
680 | + --disable-vxhs) vxhs="no" | ||
681 | + ;; | ||
682 | + --enable-vxhs) vxhs="yes" | ||
683 | + ;; | ||
684 | *) | ||
685 | echo "ERROR: unknown option $opt" | ||
686 | echo "Try '$0 --help' for more information" | ||
687 | @@ -XXX,XX +XXX,XX @@ disabled with --disable-FEATURE, default is enabled if available: | ||
688 | xfsctl xfsctl support | ||
689 | qom-cast-debug cast debugging support | ||
690 | tools build qemu-io, qemu-nbd and qemu-image tools | ||
691 | + vxhs Veritas HyperScale vDisk backend support | ||
692 | |||
693 | NOTE: The object files are built at the place where configure is launched | ||
694 | EOF | ||
695 | @@ -XXX,XX +XXX,XX @@ if compile_prog "" "" ; then | ||
696 | fi | ||
697 | |||
698 | ########################################## | ||
699 | +# Veritas HyperScale block driver VxHS | ||
700 | +# Check if libvxhs is installed | ||
701 | + | ||
702 | +if test "$vxhs" != "no" ; then | ||
703 | + cat > $TMPC <<EOF | ||
704 | +#include <stdint.h> | ||
705 | +#include <qnio/qnio_api.h> | ||
706 | + | ||
707 | +void *vxhs_callback; | ||
708 | + | ||
709 | +int main(void) { | ||
710 | + iio_init(QNIO_VERSION, vxhs_callback); | ||
711 | + return 0; | ||
712 | +} | ||
713 | +EOF | ||
714 | + vxhs_libs="-lvxhs -lssl" | ||
715 | + if compile_prog "" "$vxhs_libs" ; then | ||
716 | + vxhs=yes | ||
717 | + else | ||
718 | + if test "$vxhs" = "yes" ; then | ||
719 | + feature_not_found "vxhs block device" "Install libvxhs See github" | ||
720 | + fi | ||
721 | + vxhs=no | ||
722 | + fi | ||
723 | +fi | ||
724 | + | ||
725 | +########################################## | ||
726 | # End of CC checks | ||
727 | # After here, no more $cc or $ld runs | ||
728 | |||
729 | @@ -XXX,XX +XXX,XX @@ echo "tcmalloc support $tcmalloc" | ||
730 | echo "jemalloc support $jemalloc" | ||
731 | echo "avx2 optimization $avx2_opt" | ||
732 | echo "replication support $replication" | ||
733 | +echo "VxHS block device $vxhs" | ||
734 | |||
735 | if test "$sdl_too_old" = "yes"; then | ||
736 | echo "-> Your SDL version is too old - please upgrade to have SDL support" | ||
737 | @@ -XXX,XX +XXX,XX @@ if test "$pthread_setname_np" = "yes" ; then | ||
738 | echo "CONFIG_PTHREAD_SETNAME_NP=y" >> $config_host_mak | ||
739 | fi | ||
740 | |||
741 | +if test "$vxhs" = "yes" ; then | ||
742 | + echo "CONFIG_VXHS=y" >> $config_host_mak | ||
743 | + echo "VXHS_LIBS=$vxhs_libs" >> $config_host_mak | ||
744 | +fi | ||
745 | + | ||
746 | if test "$tcg_interpreter" = "yes"; then | ||
747 | QEMU_INCLUDES="-I\$(SRC_PATH)/tcg/tci $QEMU_INCLUDES" | ||
748 | elif test "$ARCH" = "sparc64" ; then | ||
749 | diff --git a/qapi/block-core.json b/qapi/block-core.json | ||
750 | index XXXXXXX..XXXXXXX 100644 | ||
751 | --- a/qapi/block-core.json | ||
752 | +++ b/qapi/block-core.json | ||
753 | @@ -XXX,XX +XXX,XX @@ | ||
754 | # | ||
755 | # Drivers that are supported in block device operations. | ||
756 | # | ||
757 | +# @vxhs: Since 2.10 | ||
758 | +# | ||
759 | # Since: 2.9 | ||
760 | ## | ||
761 | { 'enum': 'BlockdevDriver', | ||
762 | @@ -XXX,XX +XXX,XX @@ | ||
763 | 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', | ||
764 | 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', | ||
765 | 'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh', | ||
766 | - 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } | ||
767 | + 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } | ||
768 | |||
769 | ## | ||
770 | # @BlockdevOptionsFile: | ||
771 | @@ -XXX,XX +XXX,XX @@ | ||
772 | 'data': { '*offset': 'int', '*size': 'int' } } | ||
773 | |||
774 | ## | ||
775 | +# @BlockdevOptionsVxHS: | ||
776 | +# | ||
777 | +# Driver specific block device options for VxHS | ||
778 | +# | ||
779 | +# @vdisk-id: UUID of VxHS volume | ||
780 | +# @server: vxhs server IP, port | ||
781 | +# @tls-creds: TLS credentials ID | ||
782 | +# | ||
783 | +# Since: 2.10 | ||
784 | +## | ||
785 | +{ 'struct': 'BlockdevOptionsVxHS', | ||
786 | + 'data': { 'vdisk-id': 'str', | ||
787 | + 'server': 'InetSocketAddressBase', | ||
788 | + '*tls-creds': 'str' } } | ||
789 | + | ||
790 | +## | ||
791 | # @BlockdevOptions: | ||
792 | # | ||
793 | # Options for creating a block device. Many options are available for all | ||
794 | @@ -XXX,XX +XXX,XX @@ | ||
795 | 'vhdx': 'BlockdevOptionsGenericFormat', | ||
796 | 'vmdk': 'BlockdevOptionsGenericCOWFormat', | ||
797 | 'vpc': 'BlockdevOptionsGenericFormat', | ||
798 | - 'vvfat': 'BlockdevOptionsVVFAT' | ||
799 | + 'vvfat': 'BlockdevOptionsVVFAT', | ||
800 | + 'vxhs': 'BlockdevOptionsVxHS' | ||
801 | } } | ||
802 | |||
803 | ## | ||
804 | -- | 392 | -- |
805 | 2.9.3 | 393 | 2.29.2 |
806 | 394 | ||
807 | diff view generated by jsdifflib |
1 | From: Ashish Mittal <ashmit602@gmail.com> | 1 | From: Jagannathan Raman <jag.raman@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | These changes use a vxhs test server that is a part of the following | 3 | IOHUB object is added to manage PCI IRQs. It uses KVM_IRQFD |
4 | repository: | 4 | ioctl to create irqfd to injecting PCI interrupts to the guest. |
5 | https://github.com/VeritasHyperScale/libqnio.git | 5 | IOHUB object forwards the irqfd to the remote process. Remote process |
6 | uses this fd to directly send interrupts to the guest, bypassing QEMU. | ||
6 | 7 | ||
7 | Signed-off-by: Ashish Mittal <Ashish.Mittal@veritas.com> | 8 | Signed-off-by: John G Johnson <john.g.johnson@oracle.com> |
9 | Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> | ||
10 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | Reviewed-by: Jeff Cody <jcody@redhat.com> | 12 | Message-id: 51d5c3d54e28a68b002e3875c59599c9f5a424a1.1611938319.git.jag.raman@oracle.com |
10 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
11 | Message-id: 1491277689-24949-3-git-send-email-Ashish.Mittal@veritas.com | ||
12 | --- | 14 | --- |
13 | tests/qemu-iotests/common | 6 ++++++ | 15 | MAINTAINERS | 2 + |
14 | tests/qemu-iotests/common.config | 13 +++++++++++++ | 16 | include/hw/pci/pci_ids.h | 3 + |
15 | tests/qemu-iotests/common.filter | 1 + | 17 | include/hw/remote/iohub.h | 42 +++++++++++ |
16 | tests/qemu-iotests/common.rc | 19 +++++++++++++++++++ | 18 | include/hw/remote/machine.h | 2 + |
17 | 4 files changed, 39 insertions(+) | 19 | include/hw/remote/mpqemu-link.h | 1 + |
20 | include/hw/remote/proxy.h | 4 ++ | ||
21 | hw/remote/iohub.c | 119 ++++++++++++++++++++++++++++++++ | ||
22 | hw/remote/machine.c | 10 +++ | ||
23 | hw/remote/message.c | 4 ++ | ||
24 | hw/remote/mpqemu-link.c | 5 ++ | ||
25 | hw/remote/proxy.c | 56 +++++++++++++++ | ||
26 | hw/remote/meson.build | 1 + | ||
27 | 12 files changed, 249 insertions(+) | ||
28 | create mode 100644 include/hw/remote/iohub.h | ||
29 | create mode 100644 hw/remote/iohub.c | ||
18 | 30 | ||
19 | diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common | 31 | diff --git a/MAINTAINERS b/MAINTAINERS |
20 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/tests/qemu-iotests/common | 33 | --- a/MAINTAINERS |
22 | +++ b/tests/qemu-iotests/common | 34 | +++ b/MAINTAINERS |
23 | @@ -XXX,XX +XXX,XX @@ check options | 35 | @@ -XXX,XX +XXX,XX @@ F: hw/remote/proxy.c |
24 | -ssh test ssh | 36 | F: include/hw/remote/proxy.h |
25 | -nfs test nfs | 37 | F: hw/remote/proxy-memory-listener.c |
26 | -luks test luks | 38 | F: include/hw/remote/proxy-memory-listener.h |
27 | + -vxhs test vxhs | 39 | +F: hw/remote/iohub.c |
28 | -xdiff graphical mode diff | 40 | +F: include/hw/remote/iohub.h |
29 | -nocache use O_DIRECT on backing file | 41 | |
30 | -misalign misalign memory allocations | 42 | Build and test automation |
31 | @@ -XXX,XX +XXX,XX @@ testlist options | 43 | ------------------------- |
32 | xpand=false | 44 | diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h |
33 | ;; | 45 | index XXXXXXX..XXXXXXX 100644 |
34 | 46 | --- a/include/hw/pci/pci_ids.h | |
35 | + -vxhs) | 47 | +++ b/include/hw/pci/pci_ids.h |
36 | + IMGPROTO=vxhs | 48 | @@ -XXX,XX +XXX,XX @@ |
37 | + xpand=false | 49 | #define PCI_DEVICE_ID_SUN_SIMBA 0x5000 |
38 | + ;; | 50 | #define PCI_DEVICE_ID_SUN_SABRE 0xa000 |
39 | + | 51 | |
40 | -ssh) | 52 | +#define PCI_VENDOR_ID_ORACLE 0x108e |
41 | IMGPROTO=ssh | 53 | +#define PCI_DEVICE_ID_REMOTE_IOHUB 0xb000 |
42 | xpand=false | 54 | + |
43 | diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config | 55 | #define PCI_VENDOR_ID_CMD 0x1095 |
44 | index XXXXXXX..XXXXXXX 100644 | 56 | #define PCI_DEVICE_ID_CMD_646 0x0646 |
45 | --- a/tests/qemu-iotests/common.config | 57 | |
46 | +++ b/tests/qemu-iotests/common.config | 58 | diff --git a/include/hw/remote/iohub.h b/include/hw/remote/iohub.h |
47 | @@ -XXX,XX +XXX,XX @@ if [ -z "$QEMU_NBD_PROG" ]; then | 59 | new file mode 100644 |
48 | export QEMU_NBD_PROG="`set_prog_path qemu-nbd`" | 60 | index XXXXXXX..XXXXXXX |
49 | fi | 61 | --- /dev/null |
50 | 62 | +++ b/include/hw/remote/iohub.h | |
51 | +if [ -z "$QEMU_VXHS_PROG" ]; then | 63 | @@ -XXX,XX +XXX,XX @@ |
52 | + export QEMU_VXHS_PROG="`set_prog_path qnio_server`" | 64 | +/* |
53 | +fi | 65 | + * IO Hub for remote device |
54 | + | 66 | + * |
55 | _qemu_wrapper() | 67 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. |
68 | + * | ||
69 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
70 | + * See the COPYING file in the top-level directory. | ||
71 | + * | ||
72 | + */ | ||
73 | + | ||
74 | +#ifndef REMOTE_IOHUB_H | ||
75 | +#define REMOTE_IOHUB_H | ||
76 | + | ||
77 | +#include "hw/pci/pci.h" | ||
78 | +#include "qemu/event_notifier.h" | ||
79 | +#include "qemu/thread-posix.h" | ||
80 | +#include "hw/remote/mpqemu-link.h" | ||
81 | + | ||
82 | +#define REMOTE_IOHUB_NB_PIRQS PCI_DEVFN_MAX | ||
83 | + | ||
84 | +typedef struct ResampleToken { | ||
85 | + void *iohub; | ||
86 | + int pirq; | ||
87 | +} ResampleToken; | ||
88 | + | ||
89 | +typedef struct RemoteIOHubState { | ||
90 | + PCIDevice d; | ||
91 | + EventNotifier irqfds[REMOTE_IOHUB_NB_PIRQS]; | ||
92 | + EventNotifier resamplefds[REMOTE_IOHUB_NB_PIRQS]; | ||
93 | + unsigned int irq_level[REMOTE_IOHUB_NB_PIRQS]; | ||
94 | + ResampleToken token[REMOTE_IOHUB_NB_PIRQS]; | ||
95 | + QemuMutex irq_level_lock[REMOTE_IOHUB_NB_PIRQS]; | ||
96 | +} RemoteIOHubState; | ||
97 | + | ||
98 | +int remote_iohub_map_irq(PCIDevice *pci_dev, int intx); | ||
99 | +void remote_iohub_set_irq(void *opaque, int pirq, int level); | ||
100 | +void process_set_irqfd_msg(PCIDevice *pci_dev, MPQemuMsg *msg); | ||
101 | + | ||
102 | +void remote_iohub_init(RemoteIOHubState *iohub); | ||
103 | +void remote_iohub_finalize(RemoteIOHubState *iohub); | ||
104 | + | ||
105 | +#endif | ||
106 | diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h | ||
107 | index XXXXXXX..XXXXXXX 100644 | ||
108 | --- a/include/hw/remote/machine.h | ||
109 | +++ b/include/hw/remote/machine.h | ||
110 | @@ -XXX,XX +XXX,XX @@ | ||
111 | #include "hw/boards.h" | ||
112 | #include "hw/pci-host/remote.h" | ||
113 | #include "io/channel.h" | ||
114 | +#include "hw/remote/iohub.h" | ||
115 | |||
116 | struct RemoteMachineState { | ||
117 | MachineState parent_obj; | ||
118 | |||
119 | RemotePCIHost *host; | ||
120 | + RemoteIOHubState iohub; | ||
121 | }; | ||
122 | |||
123 | /* Used to pass to co-routine device and ioc. */ | ||
124 | diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h | ||
125 | index XXXXXXX..XXXXXXX 100644 | ||
126 | --- a/include/hw/remote/mpqemu-link.h | ||
127 | +++ b/include/hw/remote/mpqemu-link.h | ||
128 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
129 | MPQEMU_CMD_PCI_CFGREAD, | ||
130 | MPQEMU_CMD_BAR_WRITE, | ||
131 | MPQEMU_CMD_BAR_READ, | ||
132 | + MPQEMU_CMD_SET_IRQFD, | ||
133 | MPQEMU_CMD_MAX, | ||
134 | } MPQemuCmd; | ||
135 | |||
136 | diff --git a/include/hw/remote/proxy.h b/include/hw/remote/proxy.h | ||
137 | index XXXXXXX..XXXXXXX 100644 | ||
138 | --- a/include/hw/remote/proxy.h | ||
139 | +++ b/include/hw/remote/proxy.h | ||
140 | @@ -XXX,XX +XXX,XX @@ | ||
141 | #include "hw/pci/pci.h" | ||
142 | #include "io/channel.h" | ||
143 | #include "hw/remote/proxy-memory-listener.h" | ||
144 | +#include "qemu/event_notifier.h" | ||
145 | |||
146 | #define TYPE_PCI_PROXY_DEV "x-pci-proxy-dev" | ||
147 | OBJECT_DECLARE_SIMPLE_TYPE(PCIProxyDev, PCI_PROXY_DEV) | ||
148 | @@ -XXX,XX +XXX,XX @@ struct PCIProxyDev { | ||
149 | QIOChannel *ioc; | ||
150 | Error *migration_blocker; | ||
151 | ProxyMemoryListener proxy_listener; | ||
152 | + int virq; | ||
153 | + EventNotifier intr; | ||
154 | + EventNotifier resample; | ||
155 | ProxyMemoryRegion region[PCI_NUM_REGIONS]; | ||
156 | }; | ||
157 | |||
158 | diff --git a/hw/remote/iohub.c b/hw/remote/iohub.c | ||
159 | new file mode 100644 | ||
160 | index XXXXXXX..XXXXXXX | ||
161 | --- /dev/null | ||
162 | +++ b/hw/remote/iohub.c | ||
163 | @@ -XXX,XX +XXX,XX @@ | ||
164 | +/* | ||
165 | + * Remote IO Hub | ||
166 | + * | ||
167 | + * Copyright © 2018, 2021 Oracle and/or its affiliates. | ||
168 | + * | ||
169 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
170 | + * See the COPYING file in the top-level directory. | ||
171 | + * | ||
172 | + */ | ||
173 | + | ||
174 | +#include "qemu/osdep.h" | ||
175 | +#include "qemu-common.h" | ||
176 | + | ||
177 | +#include "hw/pci/pci.h" | ||
178 | +#include "hw/pci/pci_ids.h" | ||
179 | +#include "hw/pci/pci_bus.h" | ||
180 | +#include "qemu/thread.h" | ||
181 | +#include "hw/boards.h" | ||
182 | +#include "hw/remote/machine.h" | ||
183 | +#include "hw/remote/iohub.h" | ||
184 | +#include "qemu/main-loop.h" | ||
185 | + | ||
186 | +void remote_iohub_init(RemoteIOHubState *iohub) | ||
187 | +{ | ||
188 | + int pirq; | ||
189 | + | ||
190 | + memset(&iohub->irqfds, 0, sizeof(iohub->irqfds)); | ||
191 | + memset(&iohub->resamplefds, 0, sizeof(iohub->resamplefds)); | ||
192 | + | ||
193 | + for (pirq = 0; pirq < REMOTE_IOHUB_NB_PIRQS; pirq++) { | ||
194 | + qemu_mutex_init(&iohub->irq_level_lock[pirq]); | ||
195 | + iohub->irq_level[pirq] = 0; | ||
196 | + event_notifier_init_fd(&iohub->irqfds[pirq], -1); | ||
197 | + event_notifier_init_fd(&iohub->resamplefds[pirq], -1); | ||
198 | + } | ||
199 | +} | ||
200 | + | ||
201 | +void remote_iohub_finalize(RemoteIOHubState *iohub) | ||
202 | +{ | ||
203 | + int pirq; | ||
204 | + | ||
205 | + for (pirq = 0; pirq < REMOTE_IOHUB_NB_PIRQS; pirq++) { | ||
206 | + qemu_set_fd_handler(event_notifier_get_fd(&iohub->resamplefds[pirq]), | ||
207 | + NULL, NULL, NULL); | ||
208 | + event_notifier_cleanup(&iohub->irqfds[pirq]); | ||
209 | + event_notifier_cleanup(&iohub->resamplefds[pirq]); | ||
210 | + qemu_mutex_destroy(&iohub->irq_level_lock[pirq]); | ||
211 | + } | ||
212 | +} | ||
213 | + | ||
214 | +int remote_iohub_map_irq(PCIDevice *pci_dev, int intx) | ||
215 | +{ | ||
216 | + return pci_dev->devfn; | ||
217 | +} | ||
218 | + | ||
219 | +void remote_iohub_set_irq(void *opaque, int pirq, int level) | ||
220 | +{ | ||
221 | + RemoteIOHubState *iohub = opaque; | ||
222 | + | ||
223 | + assert(pirq >= 0); | ||
224 | + assert(pirq < PCI_DEVFN_MAX); | ||
225 | + | ||
226 | + QEMU_LOCK_GUARD(&iohub->irq_level_lock[pirq]); | ||
227 | + | ||
228 | + if (level) { | ||
229 | + if (++iohub->irq_level[pirq] == 1) { | ||
230 | + event_notifier_set(&iohub->irqfds[pirq]); | ||
231 | + } | ||
232 | + } else if (iohub->irq_level[pirq] > 0) { | ||
233 | + iohub->irq_level[pirq]--; | ||
234 | + } | ||
235 | +} | ||
236 | + | ||
237 | +static void intr_resample_handler(void *opaque) | ||
238 | +{ | ||
239 | + ResampleToken *token = opaque; | ||
240 | + RemoteIOHubState *iohub = token->iohub; | ||
241 | + int pirq, s; | ||
242 | + | ||
243 | + pirq = token->pirq; | ||
244 | + | ||
245 | + s = event_notifier_test_and_clear(&iohub->resamplefds[pirq]); | ||
246 | + | ||
247 | + assert(s >= 0); | ||
248 | + | ||
249 | + QEMU_LOCK_GUARD(&iohub->irq_level_lock[pirq]); | ||
250 | + | ||
251 | + if (iohub->irq_level[pirq]) { | ||
252 | + event_notifier_set(&iohub->irqfds[pirq]); | ||
253 | + } | ||
254 | +} | ||
255 | + | ||
256 | +void process_set_irqfd_msg(PCIDevice *pci_dev, MPQemuMsg *msg) | ||
257 | +{ | ||
258 | + RemoteMachineState *machine = REMOTE_MACHINE(current_machine); | ||
259 | + RemoteIOHubState *iohub = &machine->iohub; | ||
260 | + int pirq, intx; | ||
261 | + | ||
262 | + intx = pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; | ||
263 | + | ||
264 | + pirq = remote_iohub_map_irq(pci_dev, intx); | ||
265 | + | ||
266 | + if (event_notifier_get_fd(&iohub->irqfds[pirq]) != -1) { | ||
267 | + qemu_set_fd_handler(event_notifier_get_fd(&iohub->resamplefds[pirq]), | ||
268 | + NULL, NULL, NULL); | ||
269 | + event_notifier_cleanup(&iohub->irqfds[pirq]); | ||
270 | + event_notifier_cleanup(&iohub->resamplefds[pirq]); | ||
271 | + memset(&iohub->token[pirq], 0, sizeof(ResampleToken)); | ||
272 | + } | ||
273 | + | ||
274 | + event_notifier_init_fd(&iohub->irqfds[pirq], msg->fds[0]); | ||
275 | + event_notifier_init_fd(&iohub->resamplefds[pirq], msg->fds[1]); | ||
276 | + | ||
277 | + iohub->token[pirq].iohub = iohub; | ||
278 | + iohub->token[pirq].pirq = pirq; | ||
279 | + | ||
280 | + qemu_set_fd_handler(msg->fds[1], intr_resample_handler, NULL, | ||
281 | + &iohub->token[pirq]); | ||
282 | +} | ||
283 | diff --git a/hw/remote/machine.c b/hw/remote/machine.c | ||
284 | index XXXXXXX..XXXXXXX 100644 | ||
285 | --- a/hw/remote/machine.c | ||
286 | +++ b/hw/remote/machine.c | ||
287 | @@ -XXX,XX +XXX,XX @@ | ||
288 | #include "exec/address-spaces.h" | ||
289 | #include "exec/memory.h" | ||
290 | #include "qapi/error.h" | ||
291 | +#include "hw/pci/pci_host.h" | ||
292 | +#include "hw/remote/iohub.h" | ||
293 | |||
294 | static void remote_machine_init(MachineState *machine) | ||
56 | { | 295 | { |
57 | ( | 296 | MemoryRegion *system_memory, *system_io, *pci_memory; |
58 | @@ -XXX,XX +XXX,XX @@ _qemu_nbd_wrapper() | 297 | RemoteMachineState *s = REMOTE_MACHINE(machine); |
59 | ) | 298 | RemotePCIHost *rem_host; |
299 | + PCIHostState *pci_host; | ||
300 | |||
301 | system_memory = get_system_memory(); | ||
302 | system_io = get_system_io(); | ||
303 | @@ -XXX,XX +XXX,XX @@ static void remote_machine_init(MachineState *machine) | ||
304 | memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1); | ||
305 | |||
306 | qdev_realize(DEVICE(rem_host), sysbus_get_default(), &error_fatal); | ||
307 | + | ||
308 | + pci_host = PCI_HOST_BRIDGE(rem_host); | ||
309 | + | ||
310 | + remote_iohub_init(&s->iohub); | ||
311 | + | ||
312 | + pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, | ||
313 | + &s->iohub, REMOTE_IOHUB_NB_PIRQS); | ||
60 | } | 314 | } |
61 | 315 | ||
62 | +_qemu_vxhs_wrapper() | 316 | static void remote_machine_class_init(ObjectClass *oc, void *data) |
63 | +{ | 317 | diff --git a/hw/remote/message.c b/hw/remote/message.c |
64 | + ( | 318 | index XXXXXXX..XXXXXXX 100644 |
65 | + echo $BASHPID > "${TEST_DIR}/qemu-vxhs.pid" | 319 | --- a/hw/remote/message.c |
66 | + exec "$QEMU_VXHS_PROG" $QEMU_VXHS_OPTIONS "$@" | 320 | +++ b/hw/remote/message.c |
67 | + ) | 321 | @@ -XXX,XX +XXX,XX @@ |
68 | +} | 322 | #include "hw/pci/pci.h" |
69 | + | 323 | #include "exec/memattrs.h" |
70 | export QEMU=_qemu_wrapper | 324 | #include "hw/remote/memory.h" |
71 | export QEMU_IMG=_qemu_img_wrapper | 325 | +#include "hw/remote/iohub.h" |
72 | export QEMU_IO=_qemu_io_wrapper | 326 | |
73 | export QEMU_NBD=_qemu_nbd_wrapper | 327 | static void process_config_write(QIOChannel *ioc, PCIDevice *dev, |
74 | +export QEMU_VXHS=_qemu_vxhs_wrapper | 328 | MPQemuMsg *msg, Error **errp); |
75 | 329 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) | |
76 | QEMU_IMG_EXTRA_ARGS= | 330 | case MPQEMU_CMD_SYNC_SYSMEM: |
77 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | 331 | remote_sysmem_reconfig(&msg, &local_err); |
78 | diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter | 332 | break; |
79 | index XXXXXXX..XXXXXXX 100644 | 333 | + case MPQEMU_CMD_SET_IRQFD: |
80 | --- a/tests/qemu-iotests/common.filter | 334 | + process_set_irqfd_msg(pci_dev, &msg); |
81 | +++ b/tests/qemu-iotests/common.filter | 335 | + break; |
82 | @@ -XXX,XX +XXX,XX @@ _filter_img_info() | 336 | default: |
83 | -e "s#$TEST_DIR#TEST_DIR#g" \ | 337 | error_setg(&local_err, |
84 | -e "s#$IMGFMT#IMGFMT#g" \ | 338 | "Unknown command (%d) received for device %s" |
85 | -e 's#nbd://127.0.0.1:10810$#TEST_DIR/t.IMGFMT#g' \ | 339 | diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c |
86 | + -e 's#json.*vdisk-id.*vxhs"}}#TEST_DIR/t.IMGFMT#' \ | 340 | index XXXXXXX..XXXXXXX 100644 |
87 | -e "/encrypted: yes/d" \ | 341 | --- a/hw/remote/mpqemu-link.c |
88 | -e "/cluster_size: [0-9]\\+/d" \ | 342 | +++ b/hw/remote/mpqemu-link.c |
89 | -e "/table_size: [0-9]\\+/d" \ | 343 | @@ -XXX,XX +XXX,XX @@ bool mpqemu_msg_valid(MPQemuMsg *msg) |
90 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | 344 | return false; |
91 | index XXXXXXX..XXXXXXX 100644 | 345 | } |
92 | --- a/tests/qemu-iotests/common.rc | 346 | break; |
93 | +++ b/tests/qemu-iotests/common.rc | 347 | + case MPQEMU_CMD_SET_IRQFD: |
94 | @@ -XXX,XX +XXX,XX @@ else | 348 | + if (msg->size || (msg->num_fds != 2)) { |
95 | elif [ "$IMGPROTO" = "nfs" ]; then | 349 | + return false; |
96 | TEST_DIR="nfs://127.0.0.1/$TEST_DIR" | 350 | + } |
97 | TEST_IMG=$TEST_DIR/t.$IMGFMT | 351 | + break; |
98 | + elif [ "$IMGPROTO" = "vxhs" ]; then | 352 | default: |
99 | + TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT | 353 | break; |
100 | + TEST_IMG="vxhs://127.0.0.1:9999/t.$IMGFMT" | 354 | } |
101 | else | 355 | diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c |
102 | TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT | 356 | index XXXXXXX..XXXXXXX 100644 |
103 | fi | 357 | --- a/hw/remote/proxy.c |
104 | @@ -XXX,XX +XXX,XX @@ _make_test_img() | 358 | +++ b/hw/remote/proxy.c |
105 | eval "$QEMU_NBD -v -t -b 127.0.0.1 -p 10810 -f $IMGFMT $TEST_IMG_FILE >/dev/null &" | 359 | @@ -XXX,XX +XXX,XX @@ |
106 | sleep 1 # FIXME: qemu-nbd needs to be listening before we continue | 360 | #include "qemu/error-report.h" |
107 | fi | 361 | #include "hw/remote/proxy-memory-listener.h" |
108 | + | 362 | #include "qom/object.h" |
109 | + # Start QNIO server on image directory for vxhs protocol | 363 | +#include "qemu/event_notifier.h" |
110 | + if [ $IMGPROTO = "vxhs" ]; then | 364 | +#include "sysemu/kvm.h" |
111 | + eval "$QEMU_VXHS -d $TEST_DIR > /dev/null &" | 365 | +#include "util/event_notifier-posix.c" |
112 | + sleep 1 # Wait for server to come up. | 366 | + |
113 | + fi | 367 | +static void proxy_intx_update(PCIDevice *pci_dev) |
368 | +{ | ||
369 | + PCIProxyDev *dev = PCI_PROXY_DEV(pci_dev); | ||
370 | + PCIINTxRoute route; | ||
371 | + int pin = pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; | ||
372 | + | ||
373 | + if (dev->virq != -1) { | ||
374 | + kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &dev->intr, dev->virq); | ||
375 | + dev->virq = -1; | ||
376 | + } | ||
377 | + | ||
378 | + route = pci_device_route_intx_to_irq(pci_dev, pin); | ||
379 | + | ||
380 | + dev->virq = route.irq; | ||
381 | + | ||
382 | + if (dev->virq != -1) { | ||
383 | + kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, &dev->intr, | ||
384 | + &dev->resample, dev->virq); | ||
385 | + } | ||
386 | +} | ||
387 | + | ||
388 | +static void setup_irqfd(PCIProxyDev *dev) | ||
389 | +{ | ||
390 | + PCIDevice *pci_dev = PCI_DEVICE(dev); | ||
391 | + MPQemuMsg msg; | ||
392 | + Error *local_err = NULL; | ||
393 | + | ||
394 | + event_notifier_init(&dev->intr, 0); | ||
395 | + event_notifier_init(&dev->resample, 0); | ||
396 | + | ||
397 | + memset(&msg, 0, sizeof(MPQemuMsg)); | ||
398 | + msg.cmd = MPQEMU_CMD_SET_IRQFD; | ||
399 | + msg.num_fds = 2; | ||
400 | + msg.fds[0] = event_notifier_get_fd(&dev->intr); | ||
401 | + msg.fds[1] = event_notifier_get_fd(&dev->resample); | ||
402 | + msg.size = 0; | ||
403 | + | ||
404 | + if (!mpqemu_msg_send(&msg, dev->ioc, &local_err)) { | ||
405 | + error_report_err(local_err); | ||
406 | + } | ||
407 | + | ||
408 | + dev->virq = -1; | ||
409 | + | ||
410 | + proxy_intx_update(pci_dev); | ||
411 | + | ||
412 | + pci_device_set_intx_routing_notifier(pci_dev, proxy_intx_update); | ||
413 | +} | ||
414 | |||
415 | static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) | ||
416 | { | ||
417 | @@ -XXX,XX +XXX,XX @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) | ||
418 | qio_channel_set_blocking(dev->ioc, true, NULL); | ||
419 | |||
420 | proxy_memory_listener_configure(&dev->proxy_listener, dev->ioc); | ||
421 | + | ||
422 | + setup_irqfd(dev); | ||
114 | } | 423 | } |
115 | 424 | ||
116 | _rm_test_img() | 425 | static void pci_proxy_dev_exit(PCIDevice *pdev) |
117 | @@ -XXX,XX +XXX,XX @@ _cleanup_test_img() | 426 | @@ -XXX,XX +XXX,XX @@ static void pci_proxy_dev_exit(PCIDevice *pdev) |
118 | fi | 427 | error_free(dev->migration_blocker); |
119 | rm -f "$TEST_IMG_FILE" | 428 | |
120 | ;; | 429 | proxy_memory_listener_deconfigure(&dev->proxy_listener); |
121 | + vxhs) | 430 | + |
122 | + if [ -f "${TEST_DIR}/qemu-vxhs.pid" ]; then | 431 | + event_notifier_cleanup(&dev->intr); |
123 | + local QEMU_VXHS_PID | 432 | + event_notifier_cleanup(&dev->resample); |
124 | + read QEMU_VXHS_PID < "${TEST_DIR}/qemu-vxhs.pid" | 433 | } |
125 | + kill ${QEMU_VXHS_PID} >/dev/null 2>&1 | 434 | |
126 | + rm -f "${TEST_DIR}/qemu-vxhs.pid" | 435 | static void config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, |
127 | + fi | 436 | diff --git a/hw/remote/meson.build b/hw/remote/meson.build |
128 | + rm -f "$TEST_IMG_FILE" | 437 | index XXXXXXX..XXXXXXX 100644 |
129 | + ;; | 438 | --- a/hw/remote/meson.build |
130 | + | 439 | +++ b/hw/remote/meson.build |
131 | file) | 440 | @@ -XXX,XX +XXX,XX @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) |
132 | _rm_test_img "$TEST_DIR/t.$IMGFMT" | 441 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) |
133 | _rm_test_img "$TEST_DIR/t.$IMGFMT.orig" | 442 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) |
443 | remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) | ||
444 | +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c')) | ||
445 | |||
446 | specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) | ||
447 | specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy-memory-listener.c')) | ||
134 | -- | 448 | -- |
135 | 2.9.3 | 449 | 2.29.2 |
136 | 450 | ||
137 | diff view generated by jsdifflib |
1 | Introduce check function for setting read_only flags. Will return < 0 on | 1 | From: Jagannathan Raman <jag.raman@oracle.com> |
---|---|---|---|
2 | error, with appropriate Error value set. Does not alter any flags. | ||
3 | 2 | ||
4 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 3 | Retrieve PCI configuration info about the remote device and |
4 | configure the Proxy PCI object based on the returned information | ||
5 | |||
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> | ||
5 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
6 | Reviewed-by: John Snow <jsnow@redhat.com> | 10 | Message-id: 85ee367bbb993aa23699b44cfedd83b4ea6d5221.1611938319.git.jag.raman@oracle.com |
7 | Message-id: e2bba34ac3bc76a0c42adc390413f358ae0566e8.1491597120.git.jcody@redhat.com | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | --- | 12 | --- |
9 | block.c | 14 +++++++++++++- | 13 | hw/remote/proxy.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++ |
10 | include/block/block.h | 1 + | 14 | 1 file changed, 84 insertions(+) |
11 | 2 files changed, 14 insertions(+), 1 deletion(-) | ||
12 | 15 | ||
13 | diff --git a/block.c b/block.c | 16 | diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c |
14 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/block.c | 18 | --- a/hw/remote/proxy.c |
16 | +++ b/block.c | 19 | +++ b/hw/remote/proxy.c |
17 | @@ -XXX,XX +XXX,XX @@ bool bdrv_is_read_only(BlockDriverState *bs) | 20 | @@ -XXX,XX +XXX,XX @@ |
18 | return bs->read_only; | 21 | #include "sysemu/kvm.h" |
22 | #include "util/event_notifier-posix.c" | ||
23 | |||
24 | +static void probe_pci_info(PCIDevice *dev, Error **errp); | ||
25 | + | ||
26 | static void proxy_intx_update(PCIDevice *pci_dev) | ||
27 | { | ||
28 | PCIProxyDev *dev = PCI_PROXY_DEV(pci_dev); | ||
29 | @@ -XXX,XX +XXX,XX @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) | ||
30 | { | ||
31 | ERRP_GUARD(); | ||
32 | PCIProxyDev *dev = PCI_PROXY_DEV(device); | ||
33 | + uint8_t *pci_conf = device->config; | ||
34 | int fd; | ||
35 | |||
36 | if (!dev->fd) { | ||
37 | @@ -XXX,XX +XXX,XX @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) | ||
38 | qemu_mutex_init(&dev->io_mutex); | ||
39 | qio_channel_set_blocking(dev->ioc, true, NULL); | ||
40 | |||
41 | + pci_conf[PCI_LATENCY_TIMER] = 0xff; | ||
42 | + pci_conf[PCI_INTERRUPT_PIN] = 0x01; | ||
43 | + | ||
44 | proxy_memory_listener_configure(&dev->proxy_listener, dev->ioc); | ||
45 | |||
46 | setup_irqfd(dev); | ||
47 | + | ||
48 | + probe_pci_info(PCI_DEVICE(dev), errp); | ||
19 | } | 49 | } |
20 | 50 | ||
21 | -int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 51 | static void pci_proxy_dev_exit(PCIDevice *pdev) |
22 | +int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 52 | @@ -XXX,XX +XXX,XX @@ const MemoryRegionOps proxy_mr_ops = { |
23 | { | 53 | .max_access_size = 8, |
24 | /* Do not set read_only if copy_on_read is enabled */ | 54 | }, |
25 | if (bs->copy_on_read && read_only) { | 55 | }; |
26 | @@ -XXX,XX +XXX,XX @@ int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | ||
27 | return -EPERM; | ||
28 | } | ||
29 | |||
30 | + return 0; | ||
31 | +} | ||
32 | + | 56 | + |
33 | +int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 57 | +static void probe_pci_info(PCIDevice *dev, Error **errp) |
34 | +{ | 58 | +{ |
35 | + int ret = 0; | 59 | + PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); |
60 | + uint32_t orig_val, new_val, base_class, val; | ||
61 | + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); | ||
62 | + DeviceClass *dc = DEVICE_CLASS(pc); | ||
63 | + uint8_t type; | ||
64 | + int i, size; | ||
36 | + | 65 | + |
37 | + ret = bdrv_can_set_read_only(bs, read_only, errp); | 66 | + config_op_send(pdev, PCI_VENDOR_ID, &val, 2, MPQEMU_CMD_PCI_CFGREAD); |
38 | + if (ret < 0) { | 67 | + pc->vendor_id = (uint16_t)val; |
39 | + return ret; | 68 | + |
69 | + config_op_send(pdev, PCI_DEVICE_ID, &val, 2, MPQEMU_CMD_PCI_CFGREAD); | ||
70 | + pc->device_id = (uint16_t)val; | ||
71 | + | ||
72 | + config_op_send(pdev, PCI_CLASS_DEVICE, &val, 2, MPQEMU_CMD_PCI_CFGREAD); | ||
73 | + pc->class_id = (uint16_t)val; | ||
74 | + | ||
75 | + config_op_send(pdev, PCI_SUBSYSTEM_ID, &val, 2, MPQEMU_CMD_PCI_CFGREAD); | ||
76 | + pc->subsystem_id = (uint16_t)val; | ||
77 | + | ||
78 | + base_class = pc->class_id >> 4; | ||
79 | + switch (base_class) { | ||
80 | + case PCI_BASE_CLASS_BRIDGE: | ||
81 | + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); | ||
82 | + break; | ||
83 | + case PCI_BASE_CLASS_STORAGE: | ||
84 | + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | ||
85 | + break; | ||
86 | + case PCI_BASE_CLASS_NETWORK: | ||
87 | + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); | ||
88 | + break; | ||
89 | + case PCI_BASE_CLASS_INPUT: | ||
90 | + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); | ||
91 | + break; | ||
92 | + case PCI_BASE_CLASS_DISPLAY: | ||
93 | + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); | ||
94 | + break; | ||
95 | + case PCI_BASE_CLASS_PROCESSOR: | ||
96 | + set_bit(DEVICE_CATEGORY_CPU, dc->categories); | ||
97 | + break; | ||
98 | + default: | ||
99 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); | ||
100 | + break; | ||
40 | + } | 101 | + } |
41 | + | 102 | + |
42 | bs->read_only = read_only; | 103 | + for (i = 0; i < PCI_NUM_REGIONS; i++) { |
43 | return 0; | 104 | + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &orig_val, 4, |
44 | } | 105 | + MPQEMU_CMD_PCI_CFGREAD); |
45 | diff --git a/include/block/block.h b/include/block/block.h | 106 | + new_val = 0xffffffff; |
46 | index XXXXXXX..XXXXXXX 100644 | 107 | + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &new_val, 4, |
47 | --- a/include/block/block.h | 108 | + MPQEMU_CMD_PCI_CFGWRITE); |
48 | +++ b/include/block/block.h | 109 | + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &new_val, 4, |
49 | @@ -XXX,XX +XXX,XX @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, | 110 | + MPQEMU_CMD_PCI_CFGREAD); |
50 | int64_t sector_num, int nb_sectors, int *pnum); | 111 | + size = (~(new_val & 0xFFFFFFF0)) + 1; |
51 | 112 | + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &orig_val, 4, | |
52 | bool bdrv_is_read_only(BlockDriverState *bs); | 113 | + MPQEMU_CMD_PCI_CFGWRITE); |
53 | +int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); | 114 | + type = (new_val & 0x1) ? |
54 | int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); | 115 | + PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY; |
55 | bool bdrv_is_sg(BlockDriverState *bs); | 116 | + |
56 | bool bdrv_is_inserted(BlockDriverState *bs); | 117 | + if (size) { |
118 | + g_autofree char *name; | ||
119 | + pdev->region[i].dev = pdev; | ||
120 | + pdev->region[i].present = true; | ||
121 | + if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) { | ||
122 | + pdev->region[i].memory = true; | ||
123 | + } | ||
124 | + name = g_strdup_printf("bar-region-%d", i); | ||
125 | + memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev), | ||
126 | + &proxy_mr_ops, &pdev->region[i], | ||
127 | + name, size); | ||
128 | + pci_register_bar(dev, i, type, &pdev->region[i].mr); | ||
129 | + } | ||
130 | + } | ||
131 | +} | ||
57 | -- | 132 | -- |
58 | 2.9.3 | 133 | 2.29.2 |
59 | 134 | ||
60 | diff view generated by jsdifflib |
1 | A few block drivers will set the BDS read_only flag from their | 1 | From: Elena Ufimtseva <elena.ufimtseva@oracle.com> |
---|---|---|---|
2 | .bdrv_open() function. This means the bs->read_only flag could | ||
3 | be set after we enable copy_on_read, as the BDRV_O_COPY_ON_READ | ||
4 | flag check occurs prior to the call to bdrv->bdrv_open(). | ||
5 | 2 | ||
6 | This adds an error return to bdrv_set_read_only(), and an error will be | 3 | Perform device reset in the remote process when QEMU performs |
7 | return if we try to set the BDS to read_only while copy_on_read is | 4 | device reset. This is required to reset the internal state |
8 | enabled. | 5 | (like registers, etc...) of emulated devices |
9 | 6 | ||
10 | This patch also changes the behavior of vvfat. Before, vvfat could | 7 | Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> |
11 | override the drive 'readonly' flag with its own, internal 'rw' flag. | 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: 7cb220a51f565dc0817bd76e2f540e89c2d2b850.1611938319.git.jag.raman@oracle.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | --- | ||
14 | include/hw/remote/mpqemu-link.h | 1 + | ||
15 | hw/remote/message.c | 22 ++++++++++++++++++++++ | ||
16 | hw/remote/proxy.c | 19 +++++++++++++++++++ | ||
17 | 3 files changed, 42 insertions(+) | ||
12 | 18 | ||
13 | For instance, this -drive parameter would result in a writable image: | 19 | diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h |
14 | |||
15 | "-drive format=vvfat,dir=/tmp/vvfat,rw,if=virtio,readonly=on" | ||
16 | |||
17 | This is not correct. Now, attempting to use the above -drive parameter | ||
18 | will result in an error (i.e., 'rw' is incompatible with 'readonly=on'). | ||
19 | |||
20 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
21 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
22 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
23 | Message-id: 0c5b4c1cc2c651471b131f21376dfd5ea24d2196.1491597120.git.jcody@redhat.com | ||
24 | --- | ||
25 | block.c | 10 +++++++++- | ||
26 | block/bochs.c | 5 ++++- | ||
27 | block/cloop.c | 5 ++++- | ||
28 | block/dmg.c | 6 +++++- | ||
29 | block/rbd.c | 11 ++++++++++- | ||
30 | block/vvfat.c | 19 +++++++++++++++---- | ||
31 | include/block/block.h | 2 +- | ||
32 | 7 files changed, 48 insertions(+), 10 deletions(-) | ||
33 | |||
34 | diff --git a/block.c b/block.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/block.c | 21 | --- a/include/hw/remote/mpqemu-link.h |
37 | +++ b/block.c | 22 | +++ b/include/hw/remote/mpqemu-link.h |
38 | @@ -XXX,XX +XXX,XX @@ void path_combine(char *dest, int dest_size, | 23 | @@ -XXX,XX +XXX,XX @@ typedef enum { |
24 | MPQEMU_CMD_BAR_WRITE, | ||
25 | MPQEMU_CMD_BAR_READ, | ||
26 | MPQEMU_CMD_SET_IRQFD, | ||
27 | + MPQEMU_CMD_DEVICE_RESET, | ||
28 | MPQEMU_CMD_MAX, | ||
29 | } MPQemuCmd; | ||
30 | |||
31 | diff --git a/hw/remote/message.c b/hw/remote/message.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/hw/remote/message.c | ||
34 | +++ b/hw/remote/message.c | ||
35 | @@ -XXX,XX +XXX,XX @@ | ||
36 | #include "exec/memattrs.h" | ||
37 | #include "hw/remote/memory.h" | ||
38 | #include "hw/remote/iohub.h" | ||
39 | +#include "sysemu/reset.h" | ||
40 | |||
41 | static void process_config_write(QIOChannel *ioc, PCIDevice *dev, | ||
42 | MPQemuMsg *msg, Error **errp); | ||
43 | @@ -XXX,XX +XXX,XX @@ static void process_config_read(QIOChannel *ioc, PCIDevice *dev, | ||
44 | MPQemuMsg *msg, Error **errp); | ||
45 | static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **errp); | ||
46 | static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp); | ||
47 | +static void process_device_reset_msg(QIOChannel *ioc, PCIDevice *dev, | ||
48 | + Error **errp); | ||
49 | |||
50 | void coroutine_fn mpqemu_remote_msg_loop_co(void *data) | ||
51 | { | ||
52 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) | ||
53 | case MPQEMU_CMD_SET_IRQFD: | ||
54 | process_set_irqfd_msg(pci_dev, &msg); | ||
55 | break; | ||
56 | + case MPQEMU_CMD_DEVICE_RESET: | ||
57 | + process_device_reset_msg(com->ioc, pci_dev, &local_err); | ||
58 | + break; | ||
59 | default: | ||
60 | error_setg(&local_err, | ||
61 | "Unknown command (%d) received for device %s" | ||
62 | @@ -XXX,XX +XXX,XX @@ fail: | ||
63 | getpid()); | ||
39 | } | 64 | } |
40 | } | 65 | } |
41 | 66 | + | |
42 | -void bdrv_set_read_only(BlockDriverState *bs, bool read_only) | 67 | +static void process_device_reset_msg(QIOChannel *ioc, PCIDevice *dev, |
43 | +int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 68 | + Error **errp) |
44 | { | 69 | +{ |
45 | + /* Do not set read_only if copy_on_read is enabled */ | 70 | + DeviceClass *dc = DEVICE_GET_CLASS(dev); |
46 | + if (bs->copy_on_read && read_only) { | 71 | + DeviceState *s = DEVICE(dev); |
47 | + error_setg(errp, "Can't set node '%s' to r/o with copy-on-read enabled", | 72 | + MPQemuMsg ret = { 0 }; |
48 | + bdrv_get_device_or_node_name(bs)); | 73 | + |
49 | + return -EINVAL; | 74 | + if (dc->reset) { |
75 | + dc->reset(s); | ||
50 | + } | 76 | + } |
51 | + | 77 | + |
52 | bs->read_only = read_only; | 78 | + ret.cmd = MPQEMU_CMD_RET; |
53 | + return 0; | 79 | + |
80 | + mpqemu_msg_send(&ret, ioc, errp); | ||
81 | +} | ||
82 | diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/hw/remote/proxy.c | ||
85 | +++ b/hw/remote/proxy.c | ||
86 | @@ -XXX,XX +XXX,XX @@ | ||
87 | #include "util/event_notifier-posix.c" | ||
88 | |||
89 | static void probe_pci_info(PCIDevice *dev, Error **errp); | ||
90 | +static void proxy_device_reset(DeviceState *dev); | ||
91 | |||
92 | static void proxy_intx_update(PCIDevice *pci_dev) | ||
93 | { | ||
94 | @@ -XXX,XX +XXX,XX @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) | ||
95 | k->config_read = pci_proxy_read_config; | ||
96 | k->config_write = pci_proxy_write_config; | ||
97 | |||
98 | + dc->reset = proxy_device_reset; | ||
99 | + | ||
100 | device_class_set_props(dc, proxy_properties); | ||
54 | } | 101 | } |
55 | 102 | ||
56 | void bdrv_get_full_backing_filename_from_filename(const char *backed, | 103 | @@ -XXX,XX +XXX,XX @@ static void probe_pci_info(PCIDevice *dev, Error **errp) |
57 | diff --git a/block/bochs.c b/block/bochs.c | 104 | } |
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/block/bochs.c | ||
60 | +++ b/block/bochs.c | ||
61 | @@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, | ||
62 | return -EINVAL; | ||
63 | } | 105 | } |
64 | 106 | } | |
65 | - bdrv_set_read_only(bs, true); /* no write support yet */ | 107 | + |
66 | + ret = bdrv_set_read_only(bs, true, errp); /* no write support yet */ | 108 | +static void proxy_device_reset(DeviceState *dev) |
67 | + if (ret < 0) { | 109 | +{ |
68 | + return ret; | 110 | + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); |
69 | + } | 111 | + MPQemuMsg msg = { 0 }; |
70 | 112 | + Error *local_err = NULL; | |
71 | ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); | 113 | + |
72 | if (ret < 0) { | 114 | + msg.cmd = MPQEMU_CMD_DEVICE_RESET; |
73 | diff --git a/block/cloop.c b/block/cloop.c | 115 | + msg.size = 0; |
74 | index XXXXXXX..XXXXXXX 100644 | 116 | + |
75 | --- a/block/cloop.c | 117 | + mpqemu_msg_send_and_await_reply(&msg, pdev, &local_err); |
76 | +++ b/block/cloop.c | 118 | + if (local_err) { |
77 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | 119 | + error_report_err(local_err); |
78 | return -EINVAL; | ||
79 | } | ||
80 | |||
81 | - bdrv_set_read_only(bs, true); | ||
82 | + ret = bdrv_set_read_only(bs, true, errp); | ||
83 | + if (ret < 0) { | ||
84 | + return ret; | ||
85 | + } | ||
86 | |||
87 | /* read header */ | ||
88 | ret = bdrv_pread(bs->file, 128, &s->block_size, 4); | ||
89 | diff --git a/block/dmg.c b/block/dmg.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/block/dmg.c | ||
92 | +++ b/block/dmg.c | ||
93 | @@ -XXX,XX +XXX,XX @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, | ||
94 | return -EINVAL; | ||
95 | } | ||
96 | |||
97 | + ret = bdrv_set_read_only(bs, true, errp); | ||
98 | + if (ret < 0) { | ||
99 | + return ret; | ||
100 | + } | 120 | + } |
101 | + | 121 | + |
102 | block_module_load_one("dmg-bz2"); | 122 | +} |
103 | - bdrv_set_read_only(bs, true); | ||
104 | |||
105 | s->n_chunks = 0; | ||
106 | s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; | ||
107 | diff --git a/block/rbd.c b/block/rbd.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/block/rbd.c | ||
110 | +++ b/block/rbd.c | ||
111 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | ||
112 | goto failed_shutdown; | ||
113 | } | ||
114 | |||
115 | + /* rbd_open is always r/w */ | ||
116 | r = rbd_open(s->io_ctx, s->name, &s->image, s->snap); | ||
117 | if (r < 0) { | ||
118 | error_setg_errno(errp, -r, "error reading header from %s", s->name); | ||
119 | goto failed_open; | ||
120 | } | ||
121 | |||
122 | - bdrv_set_read_only(bs, (s->snap != NULL)); | ||
123 | + /* If we are using an rbd snapshot, we must be r/o, otherwise | ||
124 | + * leave as-is */ | ||
125 | + if (s->snap != NULL) { | ||
126 | + r = bdrv_set_read_only(bs, true, &local_err); | ||
127 | + if (r < 0) { | ||
128 | + error_propagate(errp, local_err); | ||
129 | + goto failed_open; | ||
130 | + } | ||
131 | + } | ||
132 | |||
133 | qemu_opts_del(opts); | ||
134 | return 0; | ||
135 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
136 | index XXXXXXX..XXXXXXX 100644 | ||
137 | --- a/block/vvfat.c | ||
138 | +++ b/block/vvfat.c | ||
139 | @@ -XXX,XX +XXX,XX @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, | ||
140 | |||
141 | s->current_cluster=0xffffffff; | ||
142 | |||
143 | - /* read only is the default for safety */ | ||
144 | - bdrv_set_read_only(bs, true); | ||
145 | s->qcow = NULL; | ||
146 | s->qcow_filename = NULL; | ||
147 | s->fat2 = NULL; | ||
148 | @@ -XXX,XX +XXX,XX @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, | ||
149 | s->sector_count = cyls * heads * secs - (s->first_sectors_number - 1); | ||
150 | |||
151 | if (qemu_opt_get_bool(opts, "rw", false)) { | ||
152 | - ret = enable_write_target(bs, errp); | ||
153 | + if (!bdrv_is_read_only(bs)) { | ||
154 | + ret = enable_write_target(bs, errp); | ||
155 | + if (ret < 0) { | ||
156 | + goto fail; | ||
157 | + } | ||
158 | + } else { | ||
159 | + ret = -EPERM; | ||
160 | + error_setg(errp, | ||
161 | + "Unable to set VVFAT to 'rw' when drive is read-only"); | ||
162 | + goto fail; | ||
163 | + } | ||
164 | + } else { | ||
165 | + /* read only is the default for safety */ | ||
166 | + ret = bdrv_set_read_only(bs, true, &local_err); | ||
167 | if (ret < 0) { | ||
168 | + error_propagate(errp, local_err); | ||
169 | goto fail; | ||
170 | } | ||
171 | - bdrv_set_read_only(bs, false); | ||
172 | } | ||
173 | |||
174 | bs->total_sectors = cyls * heads * secs; | ||
175 | diff --git a/include/block/block.h b/include/block/block.h | ||
176 | index XXXXXXX..XXXXXXX 100644 | ||
177 | --- a/include/block/block.h | ||
178 | +++ b/include/block/block.h | ||
179 | @@ -XXX,XX +XXX,XX @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, | ||
180 | int64_t sector_num, int nb_sectors, int *pnum); | ||
181 | |||
182 | bool bdrv_is_read_only(BlockDriverState *bs); | ||
183 | -void bdrv_set_read_only(BlockDriverState *bs, bool read_only); | ||
184 | +int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); | ||
185 | bool bdrv_is_sg(BlockDriverState *bs); | ||
186 | bool bdrv_is_inserted(BlockDriverState *bs); | ||
187 | int bdrv_media_changed(BlockDriverState *bs); | ||
188 | -- | 123 | -- |
189 | 2.9.3 | 124 | 2.29.2 |
190 | 125 | ||
191 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: "Denis V. Lunev" <den@openvz.org> | ||
1 | 2 | ||
3 | Original specification says that l1 table size if 64 * l1_size, which | ||
4 | is obviously wrong. The size of the l1 entry is 64 _bits_, not bytes. | ||
5 | Thus 64 is to be replaces with 8 as specification says about bytes. | ||
6 | |||
7 | There is also minor tweak, field name is renamed from l1 to l1_table, | ||
8 | which matches with the later text. | ||
9 | |||
10 | Signed-off-by: Denis V. Lunev <den@openvz.org> | ||
11 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
12 | Message-id: 20210128171313.2210947-1-den@openvz.org | ||
13 | CC: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | CC: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
15 | |||
16 | [Replace the original commit message "docs: fix mistake in dirty bitmap | ||
17 | feature description" as suggested by Eric Blake. | ||
18 | --Stefan] | ||
19 | |||
20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
21 | --- | ||
22 | docs/interop/parallels.txt | 2 +- | ||
23 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
24 | |||
25 | diff --git a/docs/interop/parallels.txt b/docs/interop/parallels.txt | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/docs/interop/parallels.txt | ||
28 | +++ b/docs/interop/parallels.txt | ||
29 | @@ -XXX,XX +XXX,XX @@ of its data area are: | ||
30 | 28 - 31: l1_size | ||
31 | The number of entries in the L1 table of the bitmap. | ||
32 | |||
33 | - variable: l1 (64 * l1_size bytes) | ||
34 | + variable: l1_table (8 * l1_size bytes) | ||
35 | L1 offset table (in bytes) | ||
36 | |||
37 | A dirty bitmap is stored using a one-level structure for the mapping to host | ||
38 | -- | ||
39 | 2.29.2 | ||
40 | diff view generated by jsdifflib |