Compare commits

..
Author SHA1 Message Date
Michael Tokarev 161e1f22b8 Update version for 7.2.2 release 2023-04-23 13:06:20 +03:00
Lukas Tschoke 2e0e234272 block/vhdx: fix dynamic VHDX BAT corruption
The corruption occurs when a BAT entry aligned to 4096 bytes is changed.

Specifically, the corruption occurs during the creation of the LOG Data
Descriptor. The incorrect behavior involves copying 4088 bytes from the
original 4096 bytes aligned offset to `tmp[8..4096]` and then copying
the new value for the first BAT entry to the beginning `tmp[0..8]`.
This results in all existing BAT entries inside the 4K region being
incorrectly moved by 8 bytes and the last entry being lost.

This bug did not cause noticeable corruption when only sequentially
writing once to an empty dynamic VHDX (e.g.
using `qemu-img convert -O vhdx -o subformat=dynamic ...`), but it
still resulted in invalid values for the (unused) Sector Bitmap BAT
entries.

Importantly, this corruption would only become noticeable after the
corrupted BAT is re-read from the file.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/727
Cc: [email protected]
Signed-off-by: Lukas Tschoke <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Kevin Wolf <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit 8af037fe4c)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-13 18:31:39 +03:00
Klaus Jensen c221208352 hw/nvme: fix memory leak in nvme_dsm
The iocb (and the allocated memory to hold LBA ranges) leaks if reading
the LBA ranges fails.

Fix this by adding a free and an unref of the iocb.

Reported-by: Coverity (CID 1508281)
Fixes: d7d1474fd8 ("hw/nvme: reimplement dsm to allow cancellation")
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Klaus Jensen <[email protected]>
(cherry picked from commit 4b32319cda)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-13 18:28:32 +03:00
Peter Xu 3218890da4 io: tls: Inherit QIO_CHANNEL_FEATURE_SHUTDOWN on server side
TLS iochannel will inherit io_shutdown() from the master ioc, however we
missed to do that on the server side.

This will e.g. allow qemu_file_shutdown() to work on dest QEMU too for
migration.

Acked-by: Daniel P. Berrangé <[email protected]>
Signed-off-by: Peter Xu <[email protected]>
Reviewed-by: Juan Quintela <[email protected]>
Signed-off-by: Juan Quintela <[email protected]>
(cherry picked from commit 86d063fa83)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-13 18:28:26 +03:00
Richard Henderson dda57509e9 target/arm: Handle m-profile in arm_is_secure
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1421
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
Message-id: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 9094f9551d)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-12 16:57:32 +03:00
Mathis Marion 73a11e3723 linux-user: fix timerfd read endianness conversion
When reading the expiration count from a timerfd, the endianness of the
64bit value read is the one of the host, just as for eventfds.

Signed-off-by: Mathis Marion <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Laurent Vivier <[email protected]>
(cherry picked from commit d759a62b12)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-10 11:38:34 +03:00
Ilya Leoshkevich b6abbe6250 linux-user: Fix unaligned memory access in prlimit64 syscall
target_rlimit64 contains uint64_t fields, so it's 8-byte aligned on
some hosts, while some guests may align their respective type on a
4-byte boundary. This may lead to an unaligned access, which is an UB.

Fix by defining the fields as abi_ullong. This makes the host alignment
match that of the guest, and lets the compiler know that it should emit
code that can deal with the guest alignment.

While at it, also use __get_user() and __put_user() instead of
tswap64().

Fixes: 163a05a839 ("linux-user: Implement prlimit64 syscall")
Reported-by: Richard Henderson <[email protected]>
Signed-off-by: Ilya Leoshkevich <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Laurent Vivier <[email protected]>
(cherry picked from commit 9c1da8b5ee)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-10 11:37:09 +03:00
Mathis Marion b57641e907 linux-user: fix sockaddr_in6 endianness
The sin6_scope_id field uses the host byte order, so there is a
conversion to be made when host and target endianness differ.

Signed-off-by: Mathis Marion <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Laurent Vivier <[email protected]>
(cherry picked from commit 44cf6731d6)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-10 11:34:41 +03:00
Bernhard Beschow d9bb73d8e3 qemu/osdep: Switch position of "extern" and "G_NORETURN"
Fixes the Windows build under msys2 using GCC 12 which fails with the following
error:

  [184/579] Compiling C++ object qga/vss-win32/qga-vss.dll.p/install.cpp.obj
  FAILED: qga/vss-win32/qga-vss.dll.p/install.cpp.obj
  "c++" "-m64" "-mcx16" "-Iqga/vss-win32/qga-vss.dll.p" "-Iqga/vss-win32" "-I../src/qga/vss-win32" "-I." "-Iqapi" "-Itrace" "-Iui" "-Iui/shader" "-IC:/msys64/mingw64/include/glib-2.0" "-IC:/msys64/mingw64/lib/glib-2.0/include" "-fdiagnostics-color=auto" "-Wall" "-Winvalid-pch" "-Wnon-virtual-dtor" "-Werror" "-std=gnu++11" "-g" "-iquote" "." "-iquote" "C:/msys64/home/shentey/Projects/qemu/src" "-iquote" "C:/msys64/home/shentey/Projects/qemu/src/include" "-iquote" "C:/msys64/home/shentey/Projects/qemu/src/tcg/i386" "-D__STDC_LIMIT_MACROS" "-D__STDC_CONSTANT_MACROS" "-D__STDC_FORMAT_MACROS" "-fno-pie" "-no-pie" "-D_GNU_SOURCE" "-D_FILE_OFFSET_BITS=64" "-D_LARGEFILE_SOURCE" "-fno-strict-aliasing" "-fno-common" "-fwrapv" "-Wundef" "-Wwrite-strings" "-Wtype-limits" "-Wformat-security" "-Wformat-y2k" "-Winit-self" "-Wignored-qualifiers" "-Wempty-body" "-Wendif-labels" "-Wexpansion-to-defined" "-Wimplicit-fallthrough=2" "-Wmissing-format-attribute" "-Wno-missing-include-dirs" "-Wno-shift-negative-value" "-Wno-psabi" "-fstack-protector-strong" "-Wno-unknown-pragmas" "-Wno-delete-non-virtual-dtor" "-Wno-non-virtual-dtor" -MD -MQ qga/vss-win32/qga-vss.dll.p/install.cpp.obj -MF "qga/vss-win32/qga-vss.dll.p/install.cpp.obj.d" -o qga/vss-win32/qga-vss.dll.p/install.cpp.obj "-c" ../src/qga/vss-win32/install.cpp
  In file included from C:/msys64/mingw64/lib/glib-2.0/include/glibconfig.h:9,
              from C:/msys64/mingw64/include/glib-2.0/glib/gtypes.h:34,
              from C:/msys64/mingw64/include/glib-2.0/glib/galloca.h:34,
              from C:/msys64/mingw64/include/glib-2.0/glib.h:32,
              from C:/msys64/home/shentey/Projects/qemu/src/include/glib-compat.h:32,
              from C:/msys64/home/shentey/Projects/qemu/src/include/qemu/osdep.h:144,
              from ../src/qga/vss-win32/install.cpp:13:
  C:/msys64/mingw64/include/glib-2.0/glib/gmacros.h:1075:21: error: standard attributes in middle of decl-specifiers
  1075 | # define G_NORETURN [[noreturn]]
        |                     ^
  C:/msys64/home/shentey/Projects/qemu/src/include/qemu/osdep.h:240:8: note: in expansion of macro 'G_NORETURN'
  240 | extern G_NORETURN
        |        ^~~~~~~~~~
  C:/msys64/mingw64/include/glib-2.0/glib/gmacros.h:1075:21: note: standard attributes must precede the decl-specifiers to apply to the declaration, or follow them to apply to the type
  1075 | # define G_NORETURN [[noreturn]]
        |                     ^
  C:/msys64/home/shentey/Projects/qemu/src/include/qemu/osdep.h:240:8: note: in expansion of macro 'G_NORETURN'
  240 | extern G_NORETURN
        |        ^~~~~~~~~~
  C:/msys64/mingw64/include/glib-2.0/glib/gmacros.h:1075:21: error: attribute ignored [-Werror=attributes]
  1075 | # define G_NORETURN [[noreturn]]
        |                     ^
  C:/msys64/home/shentey/Projects/qemu/src/include/qemu/osdep.h:240:8: note: in expansion of macro 'G_NORETURN'
  240 | extern G_NORETURN
        |        ^~~~~~~~~~
  C:/msys64/mingw64/include/glib-2.0/glib/gmacros.h:1075:21: note: an attribute that appertains to a type-specifier is ignored
  1075 | # define G_NORETURN [[noreturn]]
        |                     ^
  C:/msys64/home/shentey/Projects/qemu/src/include/qemu/osdep.h:240:8: note: in expansion of macro 'G_NORETURN'
  240 | extern G_NORETURN
        |        ^~~~~~~~~~
  cc1plus.exe: all warnings being treated as errors

Apparently it also fixes the compilation with Clang 15 (see
https://gitlab.com/qemu-project/qemu/-/issues/1541 ).

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1541
Signed-off-by: Bernhard Beschow <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit 5cb993ff13)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-10 11:24:30 +03:00
Marc-André Lureau c74cba8362 ui: fix crash on serial reset, during init
For ex, when resetting the xlnx-zcu102 machine:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason =
EXC_BAD_ACCESS (code=1, address=0x50)
   * frame #0: 0x10020a740 gd_vc_send_chars(vc=0x000000000) at
gtk.c:1759:41 [opt]
     frame #1: 0x100636264 qemu_chr_fe_accept_input(be=<unavailable>) at
char-fe.c:159:9 [opt]
     frame #2: 0x1000608e0 cadence_uart_reset_hold [inlined]
uart_rx_reset(s=0x10810a960) at cadence_uart.c:158:5 [opt]
     frame #3: 0x1000608d4 cadence_uart_reset_hold(obj=0x10810a960) at
cadence_uart.c:530:5 [opt]
     frame #4: 0x100580ab4 resettable_phase_hold(obj=0x10810a960,
opaque=0x000000000, type=<unavailable>) at resettable.c:0 [opt]
     frame #5: 0x10057d1b0 bus_reset_child_foreach(obj=<unavailable>,
cb=(resettable_phase_hold at resettable.c:162), opaque=0x000000000,
type=RESET_TYPE_COLD) at bus.c:97:13 [opt]
     frame #6: 0x1005809f8 resettable_phase_hold [inlined]
resettable_child_foreach(rc=0x000060000332d2c0, obj=0x0000600002c1c180,
cb=<unavailable>, opaque=0x000000000, type=RESET_TYPE_COLD) at
resettable.c:96:9 [opt]
     frame #7: 0x1005809d8 resettable_phase_hold(obj=0x0000600002c1c180,
opaque=0x000000000, type=RESET_TYPE_COLD) at resettable.c:173:5 [opt]
     frame #8: 0x1005803a0
resettable_assert_reset(obj=0x0000600002c1c180, type=<unavailable>) at
resettable.c:60:5 [opt]
     frame #9: 0x10058027c resettable_reset(obj=0x0000600002c1c180,
type=RESET_TYPE_COLD) at resettable.c:45:5 [opt]

While the chardev is created early, the VirtualConsole is associated
after, during qemu_init_displays().

Signed-off-by: Marc-André Lureau <[email protected]>
Tested-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
(cherry picked from commit 49152ac470)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-10 11:22:21 +03:00
Pierrick Bouvier a3f531cee6 qga/vss-win32: fix warning for clang++-15
Reported when compiling with clang-windows-arm64.

../qga/vss-win32/install.cpp:537:9: error: variable 'hr' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
    if (!(ControlService(service, SERVICE_CONTROL_STOP, NULL))) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../qga/vss-win32/install.cpp:545:12: note: uninitialized use occurs here
    return hr;
           ^~

Signed-off-by: Pierrick Bouvier <[email protected]>
Fixes: 917ebcb170 ("qga-win: Fix QGA VSS Provider service stop failure")
Reviewed-by: Konstantin Kostiuk <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
(cherry picked from commit 0fcd574b02)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-10 11:19:08 +03:00
Cédric Le Goater 5d4218f0b2 target/s390x: Fix float_comp_to_cc() prototype
GCC13 reports an error :

../target/s390x/tcg/fpu_helper.c:123:5: error: conflicting types for ‘float_comp_to_cc’ due to enum/integer mismatch; have ‘int(CPUS390XState *, FloatRelation)’ {aka ‘int(struct CPUArchState *, FloatRelation)’} [-Werror=enum-int-mismatch]

  123 | int float_comp_to_cc(CPUS390XState *env, FloatRelation float_compare)
      |     ^~~~~~~~~~~~~~~~
In file included from ../target/s390x/tcg/fpu_helper.c:23:
../target/s390x/s390x-internal.h:302:5: note: previous declaration of ‘float_comp_to_cc’ with type ‘int(CPUS390XState *, int)’ {aka ‘int(struct CPUArchState *, int)’}
  302 | int float_comp_to_cc(CPUS390XState *env, int float_compare);
      |     ^~~~~~~~~~~~~~~~

Fixes: 71bfd65c5f ("softfloat: Name compare relation enum")
Signed-off-by: Cédric Le Goater <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit f79283fdb8)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-10 11:17:57 +03:00
Stefan Hajnoczi 248aa3deb6 aio-posix: fix race between epoll upgrade and aio_set_fd_handler()
If another thread calls aio_set_fd_handler() while the IOThread event
loop is upgrading from ppoll(2) to epoll(7) then we might miss new
AioHandlers. The epollfd will not monitor the new AioHandler's fd,
resulting in hangs.

Take the AioHandler list lock while upgrading to epoll. This prevents
AioHandlers from changing while epoll is being set up. If we cannot lock
because we're in a nested event loop, then don't upgrade to epoll (it
will happen next time we're not in a nested call).

The downside to taking the lock is that the aio_set_fd_handler() thread
has to wait until the epoll upgrade is finished, which involves many
epoll_ctl(2) system calls. However, this scenario is rare and I couldn't
think of another solution that is still simple.

Reported-by: Qing Wang <[email protected]>
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2090998
Cc: Paolo Bonzini <[email protected]>
Cc: Fam Zheng <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Kevin Wolf <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit e62da98527)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-10 11:16:14 +03:00
Markus Armbruster d8592b05be hw/arm: do not free machine->fdt in arm_load_dtb()
At this moment, arm_load_dtb() can free machine->fdt when
binfo->dtb_filename is NULL. If there's no 'dtb_filename', 'fdt' will be
retrieved by binfo->get_dtb(). If get_dtb() returns machine->fdt, as is
the case of machvirt_dtb() from hw/arm/virt.c, fdt now has a pointer to
machine->fdt. And, in that case, the existing g_free(fdt) at the end of
arm_load_dtb() will make machine->fdt point to an invalid memory region.

Since monitor command 'dumpdtb' was introduced a couple of releases
ago, running it with any ARM machine that uses arm_load_dtb() will
crash QEMU.

Let's enable all arm_load_dtb() callers to use dumpdtb properly. Instead
of freeing 'fdt', assign it back to ms->fdt.

Cc: Peter Maydell <[email protected]>
Cc: [email protected]
Fixes: bf353ad555 ("qmp/hmp, device_tree.c: introduce dumpdtb")
Reported-by: Markus Armbruster <[email protected]>
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Daniel Henrique Barboza <[email protected]>
Message-id: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 12148d442e)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-10 11:06:09 +03:00
Ilya Leoshkevich 5d42bf6c57 target/s390x: Fix EXECUTE of relative long instructions
The code uses the wrong base for relative addressing: it should use the
target instruction address and not the EXECUTE's address.

Fix by storing the target instruction address in the new CPUS390XState
member and loading it from the code generated by gen_ri2().

Reported-by: Nina Schoetterl-Glausch <[email protected]>
Signed-off-by: Ilya Leoshkevich <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit 703d03a4aa)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-30 12:19:04 +03:00
Richard Henderson ad2f459ce0 target/s390x: Split out gen_ri2
Use tcg_constant_i64.  Adjust in2_mri2_* to allocate a new
temporary for the output, using gen_ri2 for the address.

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
(cherry picked from commit bdbc87e323)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-30 12:19:04 +03:00
Nina Schoetterl-Glausch 17b032c659 target/s390x: Fix emulation of C(G)HRL
The second operand of COMPARE HALFWORD RELATIVE LONG is a signed
halfword, it does not have the same size as the first operand.

Fixes: a7e836d5eb ("target-s390: Convert COMPARE, COMPARE LOGICAL")
Signed-off-by: Nina Schoetterl-Glausch <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit 54fce97cfc)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-30 12:19:04 +03:00
Thomas Huth a3c6cd83e3 target/s390x/arch_dump: Fix memory corruption in s390x_write_elf64_notes()
"note_size" can be smaller than sizeof(note), so unconditionally calling
memset(notep, 0, sizeof(note)) could cause a memory corruption here in
case notep has been allocated dynamically, thus let's use note_size as
length argument for memset() instead.

Reported-by: Sebastian Mitterle <[email protected]>
Fixes: 113d8f4e95 ("s390x: pv: Add dump support")
Message-Id: <[email protected]>
Reviewed-by: Janosch Frank <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit eb60026120)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-30 12:19:04 +03:00
Yuval Shaia a2efa1fac4 hw/pvrdma: Protect against buggy or malicious guest driver
Guest driver might execute HW commands when shared buffers are not yet
allocated.
This could happen on purpose (malicious guest) or because of some other
guest/host address mapping error.
We need to protect againts such case.

Fixes: CVE-2022-1050

Reported-by: Raven <[email protected]>
Signed-off-by: Yuval Shaia <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Laurent Vivier <[email protected]>
(cherry picked from commit 31c4b6fb02)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-30 12:19:04 +03:00
Fiona Ebner b209cc4556 hw/net/vmxnet3: allow VMXNET3_MAX_MTU itself as a value
Currently, VMXNET3_MAX_MTU itself (being 9000) is not considered a
valid value for the MTU, but a guest running ESXi 7.0 might try to
set it and fail the assert [0].

In the Linux kernel, dev->max_mtu itself is a valid value for the MTU
and for the vmxnet3 driver it's 9000, so a guest running Linux will
also fail the assert when trying to set an MTU of 9000.

VMXNET3_MAX_MTU and s->mtu don't seem to be used in relation to buffer
allocations/accesses, so allowing the upper limit itself as a value
should be fine.

[0]: https://forum.proxmox.com/threads/114011/

Fixes: d05dcd94ae ("net: vmxnet3: validate configuration values during activate (CVE-2021-20203)")
Signed-off-by: Fiona Ebner <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
(cherry picked from commit 099a638281)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-30 12:19:04 +03:00
Konstantin Kostiuk 5bfbcc3faa qga/win32: Remove change action from MSI installer
Remove the 'change' button from "Programs and Features" because it does
not checks if a user is an admin or not. The installer has no components
to choose from and always installs everything. So the 'change' button is
not obviously needed but can create a security issue.

resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2167423
fixes: CVE-2023-0664 (part 1 of 2)

Signed-off-by: Konstantin Kostiuk <[email protected]>
Reviewed-by: Yan Vugenfirer <[email protected]>
Reported-by: Brian Wiltse <[email protected]>
(cherry picked from commit 88288c2a51)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-30 12:19:04 +03:00
Markus Armbruster 099e8cd9ea qga: Drop dangling reference to QERR_QGA_LOGGING_DISABLED
slog()'s function comment advises to use QERR_QGA_LOGGING_DISABLED.
This macro never existed.  The reference got added in commit
e3d4d25206 "guest agent: add guest agent RPCs/commands" along with
QERR_QGA_LOGGING_FAILED, so maybe that one was meant.  However,
QERR_QGA_LOGGING_FAILED was never actually used, and was removed in
commit d73f0beadb "qerror.h: Remove unused error classes".

Drop the dangling reference.

Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Juan Quintela <[email protected]>
Reviewed-by: Konstantin Kostiuk <[email protected]>
(cherry picked from commit c40233593e)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-30 12:19:04 +03:00
Michael Tokarev 32b8913f72 Update version for 7.2.1 release
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-30 10:12:46 +03:00
Marc-André Lureau e807a1c29f build-sys: fix crlf-ending C code
On msys2, the shader-to-C script produces bad C:
./ui/shader/texture-blit-vert.h:2:5: error: missing terminating " character [-Werror]

Fix it by changing the line ending from crlf to lf, and convert the
script to Python (qemu build seems perl-free after that).

Signed-off-by: Marc-André Lureau <[email protected]>
Acked-by: Thomas Huth <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <[email protected]>
(cherry picked from commit e2c4012bc3)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:05 +03:00
Alex Bennée 9d46d348f6 tests/tcg: fix unused variable in linux-test
The latest hexagon compiler picks up that we never consume wcount.
Given the name of the #define that rcount checks against is WCOUNT_MAX
I figured the check just got missed.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
(cherry picked from commit 2bc6c79417)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:05 +03:00
Anton Johansson 7c8a67ed46 block: Handle curl 7.55.0, 7.85.0 version changes
* 7.55.0 deprecates CURLINFO_CONTENT_LENGTH_DOWNLOAD in favour of a *_T
  version, which returns curl_off_t instead of a double.
* 7.85.0 deprecates CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS in
  favour of *_STR variants, specifying the desired protocols via a
  string.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1440
Signed-off-by: Anton Johansson <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Kevin Wolf <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit e7b8d9d038)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:05 +03:00
Jason Wang b05232a256 intel-iommu: fail DEVIOTLB_UNMAP without dt mode
Without dt mode, device IOTLB notifier won't work since guest won't
send device IOTLB invalidation descriptor in this case. Let's fail
early instead of misbehaving silently.

Reviewed-by: Laurent Vivier <[email protected]>
Tested-by: Laurent Vivier <[email protected]>
Tested-by: Viktor Prutyanov <[email protected]>
Buglink: https://bugzilla.redhat.com/2156876
Signed-off-by: Jason Wang <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Peter Xu <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 09adb0e021)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Jason Wang f6d602d078 intel-iommu: fail MAP notifier without caching mode
Without caching mode, MAP notifier won't work correctly since guest
won't send IOTLB update event when it establishes new mappings in the
I/O page tables. Let's fail the IOMMU notifiers early instead of
misbehaving silently.

Reviewed-by: Eric Auger <[email protected]>
Tested-by: Viktor Prutyanov <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Peter Xu <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit b8d78277c0)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Yajun Wu 2529bbf4a7 chardev/char-socket: set s->listener = NULL in char_socket_finalize
After live migration with virtio block device, qemu crash at:

	#0  0x000055914f46f795 in object_dynamic_cast_assert (obj=0x559151b7b090, typename=0x55914f80fbc4 "qio-channel", file=0x55914f80fb90 "/images/testvfe/sw/qemu.gerrit/include/io/channel.h", line=30, func=0x55914f80fcb8 <__func__.17257> "QIO_CHANNEL") at ../qom/object.c:872
	#1  0x000055914f480d68 in QIO_CHANNEL (obj=0x559151b7b090) at /images/testvfe/sw/qemu.gerrit/include/io/channel.h:29
	#2  0x000055914f4812f8 in qio_net_listener_set_client_func_full (listener=0x559151b7a720, func=0x55914f580b97 <tcp_chr_accept>, data=0x5591519f4ea0, notify=0x0, context=0x0) at ../io/net-listener.c:166
	#3  0x000055914f580059 in tcp_chr_update_read_handler (chr=0x5591519f4ea0) at ../chardev/char-socket.c:637
	#4  0x000055914f583dca in qemu_chr_be_update_read_handlers (s=0x5591519f4ea0, context=0x0) at ../chardev/char.c:226
	#5  0x000055914f57b7c9 in qemu_chr_fe_set_handlers_full (b=0x559152bf23a0, fd_can_read=0x0, fd_read=0x0, fd_event=0x0, be_change=0x0, opaque=0x0, context=0x0, set_open=false, sync_state=true) at ../chardev/char-fe.c:279
	#6  0x000055914f57b86d in qemu_chr_fe_set_handlers (b=0x559152bf23a0, fd_can_read=0x0, fd_read=0x0, fd_event=0x0, be_change=0x0, opaque=0x0, context=0x0, set_open=false) at ../chardev/char-fe.c:304
	#7  0x000055914f378caf in vhost_user_async_close (d=0x559152bf21a0, chardev=0x559152bf23a0, vhost=0x559152bf2420, cb=0x55914f2fb8c1 <vhost_user_blk_disconnect>) at ../hw/virtio/vhost-user.c:2725
	#8  0x000055914f2fba40 in vhost_user_blk_event (opaque=0x559152bf21a0, event=CHR_EVENT_CLOSED) at ../hw/block/vhost-user-blk.c:395
	#9  0x000055914f58388c in chr_be_event (s=0x5591519f4ea0, event=CHR_EVENT_CLOSED) at ../chardev/char.c:61
	#10 0x000055914f583905 in qemu_chr_be_event (s=0x5591519f4ea0, event=CHR_EVENT_CLOSED) at ../chardev/char.c:81
	#11 0x000055914f581275 in char_socket_finalize (obj=0x5591519f4ea0) at ../chardev/char-socket.c:1083
	#12 0x000055914f46f073 in object_deinit (obj=0x5591519f4ea0, type=0x5591519055c0) at ../qom/object.c:680
	#13 0x000055914f46f0e5 in object_finalize (data=0x5591519f4ea0) at ../qom/object.c:694
	#14 0x000055914f46ff06 in object_unref (objptr=0x5591519f4ea0) at ../qom/object.c:1202
	#15 0x000055914f4715a4 in object_finalize_child_property (obj=0x559151b76c50, name=0x559151b7b250 "char3", opaque=0x5591519f4ea0) at ../qom/object.c:1747
	#16 0x000055914f46ee86 in object_property_del_all (obj=0x559151b76c50) at ../qom/object.c:632
	#17 0x000055914f46f0d2 in object_finalize (data=0x559151b76c50) at ../qom/object.c:693
	#18 0x000055914f46ff06 in object_unref (objptr=0x559151b76c50) at ../qom/object.c:1202
	#19 0x000055914f4715a4 in object_finalize_child_property (obj=0x559151b6b560, name=0x559151b76630 "chardevs", opaque=0x559151b76c50) at ../qom/object.c:1747
	#20 0x000055914f46ef67 in object_property_del_child (obj=0x559151b6b560, child=0x559151b76c50) at ../qom/object.c:654
	#21 0x000055914f46f042 in object_unparent (obj=0x559151b76c50) at ../qom/object.c:673
	#22 0x000055914f58632a in qemu_chr_cleanup () at ../chardev/char.c:1189
	#23 0x000055914f16c66c in qemu_cleanup () at ../softmmu/runstate.c:830
	#24 0x000055914eee7b9e in qemu_default_main () at ../softmmu/main.c:38
	#25 0x000055914eee7bcc in main (argc=86, argv=0x7ffc97cb8d88) at ../softmmu/main.c:48

In char_socket_finalize after s->listener freed, event callback function
vhost_user_blk_event will be called to handle CHR_EVENT_CLOSED.
vhost_user_blk_event is calling qio_net_listener_set_client_func_full which
is still using s->listener.

Setting s->listener = NULL after object_unref(OBJECT(s->listener)) can
solve this issue.

Signed-off-by: Yajun Wu <[email protected]>
Acked-by: Jiri Pirko <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit b8a7f51f59)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Carlos López 6cf13d9d01 libvhost-user: check for NULL when allocating a virtqueue element
Check the return value for malloc(), avoiding a NULL pointer
dereference, and propagate error in function callers.

Found with GCC 13 and -fanalyzer:

../subprojects/libvhost-user/libvhost-user.c: In function ‘virtqueue_alloc_element’:
../subprojects/libvhost-user/libvhost-user.c:2556:19: error: dereference of possibly-NULL ‘elem’ [CWE-690] [-Werror=analyzer-possible-null-dereference]
 2556 |     elem->out_num = out_num;
      |     ~~~~~~~~~~~~~~^~~~~~~~~
  ‘virtqueue_alloc_element’: event 1
    |
    | 2554 |     assert(sz >= sizeof(VuVirtqElement));
    |      |     ^~~~~~
    |      |     |
    |      |     (1) following ‘true’ branch (when ‘sz > 31’)...
    |
  ‘virtqueue_alloc_element’: events 2-4
    |
    | 2555 |     elem = malloc(out_sg_end);
    |      |     ^~~~   ~~~~~~~~~~~~~~~~~~
    |      |     |      |
    |      |     |      (3) this call could return NULL
    |      |     (2) ...to here
    | 2556 |     elem->out_num = out_num;
    |      |     ~~~~~~~~~~~~~~~~~~~~~~~
    |      |                   |
    |      |                   (4) ‘elem’ could be NULL: unchecked value from (3)
    |

Signed-off-by: Carlos López <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 9c1916057a)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Carlos López a7485cdca7 vhost: avoid a potential use of an uninitialized variable in vhost_svq_poll()
In vhost_svq_poll(), if vhost_svq_get_buf() fails due to a device
providing invalid descriptors, len is left uninitialized and returned
to the caller, potentally leaking stack data or causing undefined
behavior.

Fix this by initializing len to 0.

Found with GCC 13 and -fanalyzer (abridged):

../hw/virtio/vhost-shadow-virtqueue.c: In function ‘vhost_svq_poll’:
../hw/virtio/vhost-shadow-virtqueue.c:538:12: warning: use of uninitialized value ‘len’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
  538 |     return len;
      |            ^~~
  ‘vhost_svq_poll’: events 1-4
    |
    |  522 | size_t vhost_svq_poll(VhostShadowVirtqueue *svq)
    |      |        ^~~~~~~~~~~~~~
    |      |        |
    |      |        (1) entry to ‘vhost_svq_poll’
    |......
    |  525 |     uint32_t len;
    |      |              ~~~
    |      |              |
    |      |              (2) region created on stack here
    |      |              (3) capacity: 4 bytes
    |......
    |  528 |         if (vhost_svq_more_used(svq)) {
    |      |             ~
    |      |             |
    |      |             (4) inlined call to ‘vhost_svq_more_used’ from ‘vhost_svq_poll’

    (...)

    |  528 |         if (vhost_svq_more_used(svq)) {
    |      |            ^~~~~~~~~~~~~~~~~~~~~~~~~
    |      |            ||
    |      |            |(8) ...to here
    |      |            (7) following ‘true’ branch...
    |......
    |  537 |     vhost_svq_get_buf(svq, &len);
    |      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |     |
    |      |     (9) calling ‘vhost_svq_get_buf’ from ‘vhost_svq_poll’
    |
    +--> ‘vhost_svq_get_buf’: events 10-11
           |
           |  416 | static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,
           |      |                          ^~~~~~~~~~~~~~~~~
           |      |                          |
           |      |                          (10) entry to ‘vhost_svq_get_buf’
           |......
           |  423 |     if (!vhost_svq_more_used(svq)) {
           |      |          ~
           |      |          |
           |      |          (11) inlined call to ‘vhost_svq_more_used’ from ‘vhost_svq_get_buf’
           |

           (...)

           |
         ‘vhost_svq_get_buf’: event 14
           |
           |  423 |     if (!vhost_svq_more_used(svq)) {
           |      |        ^
           |      |        |
           |      |        (14) following ‘false’ branch...
           |
         ‘vhost_svq_get_buf’: event 15
           |
           |cc1:
           | (15): ...to here
           |
    <------+
    |
  ‘vhost_svq_poll’: events 16-17
    |
    |  537 |     vhost_svq_get_buf(svq, &len);
    |      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |     |
    |      |     (16) returning to ‘vhost_svq_poll’ from ‘vhost_svq_get_buf’
    |  538 |     return len;
    |      |            ~~~
    |      |            |
    |      |            (17) use of uninitialized value ‘len’ here

Note by  Laurent Vivier <[email protected]>:

    The return value is only used to detect an error:

    vhost_svq_poll
        vhost_vdpa_net_cvq_add
            vhost_vdpa_net_load_cmd
                vhost_vdpa_net_load_mac
                  -> a negative return is only used to detect error
                vhost_vdpa_net_load_mq
                  -> a negative return is only used to detect error
            vhost_vdpa_net_handle_ctrl_avail
              -> a negative return is only used to detect error

Fixes: d368c0b052 ("vhost: Do not depend on !NULL VirtQueueElement on vhost_svq_flush")
Signed-off-by: Carlos López <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit e4dd39c699)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Eugenio Pérez e2672ec498 vdpa: stop all svq on device deletion
Not stopping them leave the device in a bad state when virtio-net
fronted device is unplugged with device_del monitor command.

This is not triggable in regular poweroff or qemu forces shutdown
because cleanup is called right after vhost_vdpa_dev_start(false).  But
devices hot unplug does not call vdpa device cleanups.  This lead to all
the vhost_vdpa devices without stop the SVQ but the last.

Fix it and clean the code, making it symmetric with
vhost_vdpa_svqs_start.

Fixes: dff4426fa6 ("vhost: Add Shadow VirtQueue kick forwarding capabilities")
Reported-by: Lei Yang <[email protected]>
Signed-off-by: Eugenio Pérez <[email protected]>
Message-Id: <[email protected]>
Tested-by: Laurent Vivier <[email protected]>
Acked-by: Jason Wang <[email protected]>
(cherry picked from commit 2e1a9de96b)
Signed-off-by: Michael Tokarev <[email protected]>
Mjt: this required manual edit for stable-7.2
2023-03-29 10:20:04 +03:00
Akihiko Odaki c21a2456b6 hw/timer/hpet: Fix expiration time overflow
The expiration time provided for timer_mod() can overflow if a
ridiculously large value is set to the comparator register. The
resulting value can represent a past time after rounded, forcing the
timer to fire immediately. If the timer is configured as periodic, it
will rearm the timer again, and form an endless loop.

Check if the expiration value will overflow, and if it will, stop the
timer instead of rearming the timer with the overflowed time.

This bug was found by Alexander Bulekov when fuzzing igb, a new
network device emulation:
https://patchew.org/QEMU/[email protected]/

The fixed test case is:
fuzz/crash_2d7036941dcda1ad4380bb8a9174ed0c949bcefd

Fixes: 16b29ae180 ("Add HPET emulation to qemu (Beth Kon)")
Signed-off-by: Akihiko Odaki <[email protected]>
Acked-by: Michael S. Tsirkin <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 37d2bcbc2a)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Dr. David Alan Gilbert 0546b42bce virtio-rng-pci: fix transitional migration compat for vectors
In bad9c5a516 ("virtio-rng-pci: fix migration compat for vectors") I
fixed the virtio-rng-pci migration compatibility, but it was discovered
that we also need to fix the other aliases of the device for the
transitional cases.

Fixes: 9ea02e8f1 ('virtio-rng-pci: Allow setting nvectors, so we can use MSI-X')
bz: https://bugzilla.redhat.com/show_bug.cgi?id=2162569
Signed-off-by: Dr. David Alan Gilbert <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 62bdb88715)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Dr. David Alan Gilbert 5a1c74097e virtio-rng-pci: fix migration compat for vectors
Fixup the migration compatibility for existing machine types
so that they do not enable msi-x.

Symptom:

(qemu) qemu: get_pci_config_device: Bad config data: i=0x34 read: 84 device: 98 cmask: ff wmask: 0 w1cmask:0
qemu: Failed to load PCIDevice:config
qemu: Failed to load virtio-rng:virtio
qemu: error while loading state for instance 0x0 of device '0000:00:03.0/virtio-rng'
qemu: load of migration failed: Invalid argument

Note: This fix will break migration from 7.2->7.2-fixed with this patch

bz: https://bugzilla.redhat.com/show_bug.cgi?id=2155749
Fixes: 9ea02e8f1 ("virtio-rng-pci: Allow setting nvectors, so we can use MSI-X")

Signed-off-by: Dr. David Alan Gilbert <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Acked-by: David Daney <[email protected]>
Fixes: 9ea02e8f1 (&quot;virtio-rng-pci: Allow setting nvectors, so we can use MSI-X&quot;)<br>
Signed-off-by: Dr. David Alan Gilbert &lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;<br>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit bad9c5a516)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Akihiko Odaki b8db116da1 vhost-user-rng: Back up vqs before cleaning up vhost_dev
vhost_dev_cleanup() clears vhost_dev so back up its vqs member to free
the memory pointed by the member.

Fixes: 821d28b88f ("vhost-user-rng: Add vhost-user-rng implementation")
Signed-off-by: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit f0dac71596)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Akihiko Odaki b5be595c62 vhost-user-i2c: Back up vqs before cleaning up vhost_dev
vhost_dev_cleanup() clears vhost_dev so back up its vqs member to free
the memory pointed by the member.

Fixes: 7221d3b634 ("hw/virtio: add boilerplate for vhost-user-i2c device")
Signed-off-by: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 0126793bee)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Akihiko Odaki fd4bf2632c vhost-user-gpio: Configure vhost_dev when connecting
vhost_dev_cleanup(), called from vu_gpio_disconnect(), clears vhost_dev
so vhost-user-gpio must set the members of vhost_dev each time
connecting.

do_vhost_user_cleanup() should also acquire the pointer to vqs directly
from VHostUserGPIO instead of referring to vhost_dev as it can be called
after vhost_dev_cleanup().

Fixes: 27ba7b027f ("hw/virtio: add boilerplate for vhost-user-gpio device")
Signed-off-by: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Viresh Kumar <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit daae36c13a)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Michael S. Tsirkin b3f36e52ac Revert "hw/i386: pass RNG seed via setup_data entry"
This reverts commit 67f7e426e5.

Additionally to the automatic revert, I went over the code
and dropped all mentions of legacy_no_rng_seed manually,
effectively reverting a combination of 2 additional commits:

    commit ffe2d2382e
    Author: Jason A. Donenfeld <[email protected]>
    Date:   Wed Sep 21 11:31:34 2022 +0200

        x86: re-enable rng seeding via SetupData

    commit 3824e25db1
    Author: Gerd Hoffmann <[email protected]>
    Date:   Wed Aug 17 10:39:40 2022 +0200

        x86: disable rng seeding via setup_data

Fixes: 67f7e426e5 ("hw/i386: pass RNG seed via setup_data entry")
Signed-off-by: Michael S. Tsirkin <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>
Tested-by: Dov Murik <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
(cherry picked from commit 167f487358)
Signed-off-by: Michael Tokarev <[email protected]>
Mjt: this required manual edit for stable-7.2
2023-03-29 10:20:04 +03:00
Michael S. Tsirkin 99fb11df6f Revert "x86: return modified setup_data only if read as memory, not as file"
This reverts commit e935b73508.

Fixes: e935b73508 ("x86: return modified setup_data only if read as memory, not as file")
Signed-off-by: Michael S. Tsirkin <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>
Tested-by: Dov Murik <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
(cherry picked from commit ae80d81cfa)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Michael S. Tsirkin 814c0b185d Revert "x86: use typedef for SetupData struct"
This reverts commit eebb38a563.

Fixes: eebb38a563 ("x86: use typedef for SetupData struct")
Signed-off-by: Michael S. Tsirkin <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>
Tested-by: Dov Murik <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
(cherry picked from commit ea96a78477)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Michael S. Tsirkin 8faaaf1bcd Revert "x86: reinitialize RNG seed on system reboot"
This reverts commit 763a2828bf.

Fixes: 763a2828bf ("x86: reinitialize RNG seed on system reboot")
Signed-off-by: Michael S. Tsirkin <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>
Tested-by: Dov Murik <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
(cherry picked from commit fdc27ced04)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Michael S. Tsirkin 851de2751f Revert "x86: re-initialize RNG seed when selecting kernel"
This reverts commit cc63374a5a.

Fixes: cc63374a5a ("x86: re-initialize RNG seed when selecting kernel")
Signed-off-by: Michael S. Tsirkin <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>
Tested-by: Dov Murik <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
(cherry picked from commit b4bfa0a31d)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Michael S. Tsirkin 538c8180c3 Revert "x86: do not re-randomize RNG seed on snapshot load"
This reverts commit 14b29fea74.

Signed-off-by: Michael S. Tsirkin <[email protected]>
Fixes: 14b29fea74 ("x86: do not re-randomize RNG seed on snapshot load")
Tested-by: Nathan Chancellor <[email protected]>
Tested-by: Dov Murik <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
(cherry picked from commit ef82d893de)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Julia Suvorova 1ca37b7ef6 hw/smbios: fix field corruption in type 4 table
Since table type 4 of SMBIOS version 2.6 is shorter than 3.0, the
strings which follow immediately after the struct fields have been
overwritten by unconditional filling of later fields such as core_count2.
Make these fields dependent on the SMBIOS version.

Fixes: 05e27d74c7 ("hw/smbios: add core_count2 to smbios table type 4")
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2169904

Signed-off-by: Julia Suvorova <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Igor Mammedov <[email protected]>
Reviewed-by: Ani Sinha <[email protected]>
Reviewed-by: Igor Mammedov <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 60d09b8dc7)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Paolo Bonzini 856a67cade block/iscsi: fix double-free on BUSY or similar statuses
Commit 8c460269aa ("iscsi: base all handling of check condition on
scsi_sense_to_errno", 2019-07-15) removed a "goto out" so that the
same coroutine is re-entered twice; once from iscsi_co_generic_cb,
once from the timer callback iscsi_retry_timer_expired.  This can
cause a crash.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1378
Reported-by: Grzegorz Zdanowski <https://gitlab.com/kiler129>
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 5080152e2e)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Richard Henderson f163cf6be4 target/i386: Fix BZHI instruction
We did not correctly handle N >= operand size.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1374
Signed-off-by: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 9ad2ba6e8e)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Paolo Bonzini c45d10f655 target/i386: fix ADOX followed by ADCX
When ADCX is followed by ADOX or vice versa, the second instruction's
carry comes from EFLAGS and the condition codes use the CC_OP_ADCOX
operation.  Retrieving the carry from EFLAGS is handled by this bit
of gen_ADCOX:

        tcg_gen_extract_tl(carry_in, cpu_cc_src,
            ctz32(cc_op == CC_OP_ADCX ? CC_C : CC_O), 1);

Unfortunately, in this case cc_op has been overwritten by the previous
"if" statement to CC_OP_ADCOX.  This works by chance when the first
instruction is ADCX; however, if the first instruction is ADOX,
ADCX will incorrectly take its carry from OF instead of CF.

Fix by moving the computation of the new cc_op at the end of the function.
The included exhaustive test case fails without this patch and passes
afterwards.

Because ADCX/ADOX need not be invoked through the VEX prefix, this
regression bisects to commit 16fc5726a6 ("target/i386: reimplement
0x0f 0x38, add AVX", 2022-10-18).  However, the mistake happened a
little earlier, when BMI instructions were rewritten using the new
decoder framework.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1471
Reported-by: Paul Jolly <https://gitlab.com/myitcv>
Fixes: 1d0b926150 ("target/i386: move scalar 0F 38 and 0F 3A instruction to new decoder", 2022-10-18)
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 60c7dd22e1)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Richard Henderson 6809dbc5c5 target/i386: Fix C flag for BLSI, BLSMSK, BLSR
We forgot to set cc_src, which is used for computing C.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1370
Signed-off-by: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
Cc: [email protected]
Fixes: 1d0b926150 ("target/i386: move scalar 0F 38 and 0F 3A instruction to new decoder", 2022-10-18)
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 99282098dc)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Richard Henderson 8d3c9fc439 target/i386: Fix BEXTR instruction
There were two problems here: not limiting the input to operand bits,
and not correctly handling large extraction length.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1372
Signed-off-by: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
Cc: [email protected]
Fixes: 1d0b926150 ("target/i386: move scalar 0F 38 and 0F 3A instruction to new decoder", 2022-10-18)
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit b14c009897)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Richard Henderson 93ff84d4c0 tests/tcg/i386: Introduce and use reg_t consistently
Define reg_t based on the actual register width.
Define the inlines using that type.  This will allow
input registers to 32-bit insns to be set to 64-bit
values on x86-64, which allows testing various edge cases.

Signed-off-by: Richard Henderson <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 5d62d6649c)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Stefan Hajnoczi 2c0fdb4ed3 block: fix detect-zeroes= with BDRV_REQ_REGISTERED_BUF
When a write request is converted into a write zeroes request by the
detect-zeroes= feature, it is no longer associated with an I/O buffer.
The BDRV_REQ_REGISTERED_BUF flag doesn't make sense without an I/O
buffer and must be cleared because bdrv_co_do_pwrite_zeroes() fails with
-EINVAL when it's set.

Fiona Ebner <[email protected]> bisected and diagnosed this QEMU 7.2
regression where writes containing zeroes to a blockdev with
discard=unmap,detect-zeroes=unmap fail.

Buglink: https://gitlab.com/qemu-project/qemu/-/issues/1404
Fixes: e8b6535533 ("block: add BDRV_REQ_REGISTERED_BUF request flag")
Tested-by: Fiona Ebner <[email protected]>
Cc: [email protected]
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Hanna Czenczek <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
Message-Id: <[email protected]>
(cherry picked from commit 3c5867156e)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Kevin Wolf 6e0c910904 qcow2: Fix theoretical corruption in store_bitmap() error path
In order to write the bitmap table to the image file, it is converted to
big endian. If the write fails, it is passed to clear_bitmap_table() to
free all of the clusters it had allocated before. However, if we don't
convert it back to native endianness first, we'll free things at a wrong
offset.

In practical terms, the offsets will be so high that we won't actually
free any allocated clusters, but just run into an error, but in theory
this can cause image corruption.

Cc: [email protected]
Signed-off-by: Kevin Wolf <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Hanna Czenczek <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit b03dd9613b)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
David Hildenbrand eca533b60a migration/ram: Fix populate_read_range()
Unfortunately, commit f7b9dcfbcf broke populate_read_range(): the loop
end condition is very wrong, resulting in that function not populating the
full range. Lets' fix that.

Fixes: f7b9dcfbcf ("migration/ram: Factor out populating pages readable in ram_block_populate_pages()")
Cc: [email protected]
Reviewed-by: Peter Xu <[email protected]>
Reviewed-by: Juan Quintela <[email protected]>
Signed-off-by: David Hildenbrand <[email protected]>
Signed-off-by: Juan Quintela <[email protected]>
(cherry picked from commit 5f19a44919)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
David Hildenbrand ee2ec0ac52 migration/ram: Fix error handling in ram_write_tracking_start()
If something goes wrong during uffd_change_protection(), we would miss
to unregister uffd-wp and not release our reference. Fix it by
performing the uffd_change_protection(true) last.

Note that a uffd_change_protection(false) on the recovery path without a
prior uffd_change_protection(false) is fine.

Fixes: 278e2f551a ("migration: support UFFD write fault processing in ram_save_iterate()")
Cc: [email protected]
Reviewed-by: Peter Xu <[email protected]>
Reviewed-by: Juan Quintela <[email protected]>
Signed-off-by: David Hildenbrand <[email protected]>
Signed-off-by: Juan Quintela <[email protected]>
(cherry picked from commit 72ef3a3708)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Richard Henderson f759e33000 target/arm: Fix physical address resolution for Stage2
Conversion to probe_access_full missed applying the page offset.

Cc: [email protected]
Reported-by: Sid Manning <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
Fixes: f3639a64f6 ("target/arm: Use softmmu tlbs for page table walking")
Signed-off-by: Richard Henderson <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 9d2617ac7d)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Richard Henderson 75ecd0872f target/arm: Fix in_debug path in S1_ptw_translate
During the conversion, the test against get_phys_addr_lpae got inverted,
meaning that successful translations went to the 'failed' label.

Cc: [email protected]
Fixes: f3639a64f6 ("target/arm: Use softmmu tlbs for page table walking")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1417
Signed-off-by: Richard Henderson <[email protected]>
Message-id: [email protected]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 4a1103afb1)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Evgeny Iakovlev c3ea5ef558 target/arm: allow writes to SCR_EL3.HXEn bit when FEAT_HCX is enabled
ARM trusted firmware, when built with FEAT_HCX support, sets SCR_EL3.HXEn bit
to allow EL2 to modify HCRX_EL2 register without trapping it in EL3. Qemu
uses a valid mask to clear unsupported SCR_EL3 bits when emulating SCR_EL3
write, and that mask doesn't include SCR_EL3.HXEn bit even if FEAT_HCX is
enabled and exposed to the guest. As a result EL3 writes of that bit are
ignored.

Cc: [email protected]
Signed-off-by: Evgeny Iakovlev <[email protected]>
Message-id: [email protected]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 08899b5c68)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Richard Henderson de605876eb target/arm: Fix sve_probe_page
Don't dereference CPUTLBEntryFull until we verify that
the page is valid.  Move the other user-only info field
updates after the valid check to match.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1412
Signed-off-by: Richard Henderson <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit ce848378b9)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Paolo Bonzini f549ee8c25 configure: fix GLIB_VERSION for cross-compilation
configure uses "pkg-config" directly so that GLIB_VERSION is always based
on host glib version.   To correctly handle cross-compilation it should use
"$pkg_config" and take GLIB_VERSION from the cross-compiled glib.

Reported-by: Валентин <[email protected]>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1414
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit acedc9a660)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Klaus Jensen 4e98327e14 hw/nvme: fix missing cq eventidx update
Prior to reading the shadow doorbell cq head, we have to update the
eventidx. Otherwise, we risk that the driver will skip an mmio doorbell
write. This happens on riscv64, as reported by Guenter.

Adding the missing update to the cq eventidx fixes the issue.

Fixes: 3f7fe8de3d ("hw/nvme: Implement shadow doorbell buffer support")
Cc: [email protected]
Cc: [email protected]
Reported-by: Guenter Roeck <[email protected]>
Reviewed-by: Keith Busch <[email protected]>
Signed-off-by: Klaus Jensen <[email protected]>
(cherry picked from commit fa5db2aa16)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Klaus Jensen 9d86da9e07 hw/nvme: fix missing endian conversions for doorbell buffers
The eventidx and doorbell value are not handling endianness correctly.
Fix this.

Fixes: 3f7fe8de3d ("hw/nvme: Implement shadow doorbell buffer support")
Cc: [email protected]
Reported-by: Guenter Roeck <[email protected]>
Reviewed-by: Keith Busch <[email protected]>
Signed-off-by: Klaus Jensen <[email protected]>
(cherry picked from commit 2fda0726e5)
Signed-off-by: Michael Tokarev <[email protected]>
Conflicts: hw/nvme/ctrl.c
2023-03-29 10:20:04 +03:00
Laszlo Ersek 6a3aa014c5 acpi: cpuhp: fix guest-visible maximum access size to the legacy reg block
The modern ACPI CPU hotplug interface was introduced in the following
series (aa1dd39ca307..679dd1a957df), released in v2.7.0:

  1  abd49bc2ed docs: update ACPI CPU hotplug spec with new protocol
  2  16bcab97eb pc: piix4/ich9: add 'cpu-hotplug-legacy' property
  3  5e1b5d9388 acpi: cpuhp: add CPU devices AML with _STA method
  4  ac35f13ba8 pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook
  5  d2238cb678 acpi: cpuhp: implement hot-add parts of CPU hotplug
                  interface
  6  8872c25a26 acpi: cpuhp: implement hot-remove parts of CPU hotplug
                  interface
  7  76623d00ae acpi: cpuhp: add cpu._OST handling
  8  679dd1a957 pc: use new CPU hotplug interface since 2.7 machine type

Before patch#1, "docs/specs/acpi_cpu_hotplug.txt" only specified 1-byte
accesses for the hotplug register block.  Patch#1 preserved the same
restriction for the legacy register block, but:

- it specified DWORD accesses for some of the modern registers,

- in particular, the switch from the legacy block to the modern block
  would require a DWORD write to the *legacy* block.

The latter functionality was then implemented in cpu_status_write()
[hw/acpi/cpu_hotplug.c], in patch#8.

Unfortunately, all DWORD accesses depended on a dormant bug: the one
introduced in earlier commit a014ed07bd ("memory: accept mismatching
sizes in memory_region_access_valid", 2013-05-29); first released in
v1.6.0.  Due to commit a014ed07bd, the DWORD accesses to the *legacy*
CPU hotplug register block would work in spite of the above series *not*
relaxing "valid.max_access_size = 1" in "hw/acpi/cpu_hotplug.c":

> static const MemoryRegionOps AcpiCpuHotplug_ops = {
>     .read = cpu_status_read,
>     .write = cpu_status_write,
>     .endianness = DEVICE_LITTLE_ENDIAN,
>     .valid = {
>         .min_access_size = 1,
>         .max_access_size = 1,
>     },
> };

Later, in commits e6d0c3ce68 ("acpi: cpuhp: introduce 'Command data 2'
field", 2020-01-22) and ae340aa3d2 ("acpi: cpuhp: spec: add typical
usecases", 2020-01-22), first released in v5.0.0, the modern CPU hotplug
interface (including the documentation) was extended with another DWORD
*read* access, namely to the "Command data 2" register, which would be
important for the guest to confirm whether it managed to switch the
register block from legacy to modern.

This functionality too silently depended on the bug from commit
a014ed07bd.

In commit 5d971f9e67 ('memory: Revert "memory: accept mismatching sizes
in memory_region_access_valid"', 2020-06-26), first released in v5.1.0,
the bug from commit a014ed07bd was fixed (the commit was reverted).
That swiftly exposed the bug in "AcpiCpuHotplug_ops", still present from
the v2.7.0 series quoted at the top -- namely the fact that
"valid.max_access_size = 1" didn't match what the guest was supposed to
do, according to the spec ("docs/specs/acpi_cpu_hotplug.txt").

The symptom is that the "modern interface negotiation protocol"
described in commit ae340aa3d2:

> +      Use following steps to detect and enable modern CPU hotplug interface:
> +        1. Store 0x0 to the 'CPU selector' register,
> +           attempting to switch to modern mode
> +        2. Store 0x0 to the 'CPU selector' register,
> +           to ensure valid selector value
> +        3. Store 0x0 to the 'Command field' register,
> +        4. Read the 'Command data 2' register.
> +           If read value is 0x0, the modern interface is enabled.
> +           Otherwise legacy or no CPU hotplug interface available

falls apart for the guest: steps 1 and 2 are lost, because they are DWORD
writes; so no switching happens.  Step 3 (a single-byte write) is not
lost, but it has no effect; see the condition in cpu_status_write() in
patch#8.  And step 4 *misleads* the guest into thinking that the switch
worked: the DWORD read is lost again -- it returns zero to the guest
without ever reaching the device model, so the guest never learns the
switch didn't work.

This means that guest behavior centered on the "Command data 2" register
worked *only* in the v5.0.0 release; it got effectively regressed in
v5.1.0.

To make things *even more* complicated, the breakage was (and remains, as
of today) visible with TCG acceleration only.  Commit 5d971f9e67 makes
no difference with KVM acceleration -- the DWORD accesses still work,
despite "valid.max_access_size = 1".

As commit 5d971f9e67 suggests, fix the problem by raising
"valid.max_access_size" to 4 -- the spec now clearly instructs the guest
to perform DWORD accesses to the legacy register block too, for enabling
(and verifying!) the modern block.  In order to keep compatibility for the
device model implementation though, set "impl.max_access_size = 1", so
that wide accesses be split before they reach the legacy read/write
handlers, like they always have been on KVM, and like they were on TCG
before 5d971f9e67 (v5.1.0).

Tested with:

- OVMF IA32 + qemu-system-i386, CPU hotplug/hot-unplug with SMM,
  intermixed with ACPI S3 suspend/resume, using KVM accel
  (regression-test);

- OVMF IA32X64 + qemu-system-x86_64, CPU hotplug/hot-unplug with SMM,
  intermixed with ACPI S3 suspend/resume, using KVM accel
  (regression-test);

- OVMF IA32 + qemu-system-i386, SMM enabled, using TCG accel; verified the
  register block switch and the present/possible CPU counting through the
  modern hotplug interface, during OVMF boot (bugfix test);

- I do not have any testcase (guest payload) for regression-testing CPU
  hotplug through the *legacy* CPU hotplug register block.

Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Ani Sinha <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: Igor Mammedov <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Cc: [email protected]
Ref: "IO port write width clamping differs between TCG and KVM"
Link: http://mid.mail-archive.com/[email protected]
Link: https://lists.gnu.org/archive/html/qemu-devel/2023-01/msg00199.html
Reported-by: Ard Biesheuvel <[email protected]>
Signed-off-by: Laszlo Ersek <[email protected]>
Tested-by: Ard Biesheuvel <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Tested-by: Igor Mammedov <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit dab30fbef3)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Richard Henderson e05827b632 target/riscv: Set pc_succ_insn for !rvc illegal insn
Failure to set pc_succ_insn may result in a TB covering zero bytes,
which triggers an assert within the code generator.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1224
Signed-off-by: Richard Henderson <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
[ Changes by AF:
 - Add missing run-plugin-test-noc-% line
]
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit ec2918b467)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Paolo Bonzini 6647b6edea meson: accept relative symlinks in "meson introspect --installed" data
When installing shared libraries, as is the case for libvfio-user.so,
Meson will include relative symbolic links in the output of
"meson introspect --installed":

  {
    "libvfio-user.so": "/usr/local/lib64/libvfio-user.so",
    ...
  }

In the case of scripts/symlink-install-tree.py, this will
be a symbolic link to a symbolic link but, in any case, there is
no issue in creating it.

Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit f32eb0021a)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Alex Bennée 305c0f8c54 target/arm: fix handling of HLT semihosting in system mode
The check semihosting_enabled() wants to know if the guest is
currently in user mode. Unlike the other cases the test was inverted
causing us to block semihosting calls in non-EL0 modes.

Cc: [email protected]
Fixes: 19b26317e9 (target/arm: Honour -semihosting-config userspace=on)
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 9788d4c007)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Chenyi Qiang a2093dd6fe virtio-mem: Fix the iterator variable in a vmem->rdl_list loop
It should be the variable rdl2 to revert the already-notified listeners.

Fixes: 2044969f0b ("virtio-mem: Implement RamDiscardManager interface")
Signed-off-by: Chenyi Qiang <[email protected]>
Message-Id: <[email protected]>
Cc: [email protected]
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: David Hildenbrand <[email protected]>
(cherry picked from commit 29f1b328e3)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Chenyi Qiang 5f43c7786e virtio-mem: Fix the bitmap index of the section offset
vmem->bitmap indexes the memory region of the virtio-mem backend at a
granularity of block_size. To calculate the index of target section offset,
the block_size should be divided instead of the bitmap_size.

Fixes: 2044969f0b ("virtio-mem: Implement RamDiscardManager interface")
Signed-off-by: Chenyi Qiang <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Cc: [email protected]
Signed-off-by: David Hildenbrand <[email protected]>
(cherry picked from commit b11cf32e07)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Jason Wang f16011abc1 vhost: fix vq dirty bitmap syncing when vIOMMU is enabled
When vIOMMU is enabled, the vq->used_phys is actually the IOVA not
GPA. So we need to translate it to GPA before the syncing otherwise we
may hit the following crash since IOVA could be out of the scope of
the GPA log size. This could be noted when using virtio-IOMMU with
vhost using 1G memory.

Fixes: c471ad0e9b ("vhost_net: device IOTLB support")
Cc: [email protected]
Tested-by: Lei Yang <[email protected]>
Reported-by: Yalan Zhang <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 345cc1cbcb)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
Guenter Roeck e34f86a2f9 target/sh4: Mask restore of env->flags from tb->flags
The values in env->flags are a subset of tb->flags.
Restore only the bits that belong.

Cc: [email protected]
Fixes: ab419fd8a0 ("target/sh4: Fix TB_FLAG_UNALIGN")
Signed-off-by: Guenter Roeck <[email protected]>
Message-ID: <[email protected]>
[rth: Reduce to only the the superh_cpu_synchronize_from_tb change]
Signed-off-by: Richard Henderson <[email protected]>
(cherry picked from commit bc2331635c)
Signed-off-by: Michael Tokarev <[email protected]>
2023-03-29 10:20:04 +03:00
177 changed files with 3409 additions and 10637 deletions

No files matched your search

-3
View File
@@ -58,9 +58,6 @@
[submodule "roms/vbootrom"]
path = roms/vbootrom
url = https://gitlab.com/qemu-project/vbootrom.git
[submodule "libucontext"]
path = subprojects/libucontext
url = https://github.com/utmapp/libucontext.git
[submodule "tests/lcitool/libvirt-ci"]
path = tests/lcitool/libvirt-ci
url = https://gitlab.com/libvirt/libvirt-ci.git
+1 -1
View File
@@ -1 +1 @@
7.2.0
7.2.2
+92 -311
View File
@@ -57,34 +57,25 @@
#include "sysemu/hvf_int.h"
#include "sysemu/runstate.h"
#include "qemu/guest-random.h"
#include "hw/boards.h"
#include "exec/memory-remap.h"
#include "exec/ram_addr.h"
HVFState *hvf_state;
/* Memory slots */
#define HVF_MAX_SLOTS 512
#ifdef DEBUG_HVF
#define DPRINTF(fmt, ...) \
do { fprintf(stdout, fmt, ## __VA_ARGS__); } while (0)
#else
#define DPRINTF(fmt, ...) \
do { } while (0)
#ifdef __aarch64__
#define HV_VM_DEFAULT NULL
#endif
#define qemu_abort(...) do { g_error(__VA_ARGS__); g_abort(); } while (0)
/* Memory slots */
pthread_rwlock_t mem_lock = PTHREAD_RWLOCK_INITIALIZER;
hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t end) {
hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t size)
{
hvf_slot *slot;
int x;
for (x = 0; x < hvf_state->num_slots; ++x) {
slot = &hvf_state->slots[x];
if (slot->size && start < (slot->start + slot->size) && end > slot->start)
if (slot->size && start < (slot->start + slot->size) &&
(start + size) > slot->start) {
return slot;
}
}
return NULL;
}
@@ -94,236 +85,22 @@ struct mac_slot {
uint64_t size;
uint64_t gpa_start;
uint64_t gva;
void* hva;
};
struct mac_slot mac_slots[HVF_MAX_SLOTS];
struct mac_slot mac_slots[32];
#define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1))
void* hvf_gpa2hva(uint64_t gpa, bool* found) {
struct mac_slot *mslot;
*found = false;
for (uint32_t i = 0; i < HVF_MAX_SLOTS; i++) {
mslot = &mac_slots[i];
if (!mslot->present) continue;
if (gpa >= mslot->gpa_start &&
gpa < mslot->gpa_start + mslot->size) {
*found = true;
return (void*)((char*)(mslot->hva) + (gpa - mslot->gpa_start));
}
}
return 0;
}
#define min(a, b) ((a) < (b) ? (a) : (b))
int hvf_hva2gpa(void* hva, uint64_t length, int array_size,
uint64_t* gpa, uint64_t* size) {
struct mac_slot *mslot;
int count = 0;
for (uint32_t i = 0; i < HVF_MAX_SLOTS; i++) {
mslot = &mac_slots[i];
if (!mslot->present) continue;
uintptr_t hva_start_num = (uintptr_t)mslot->hva;
uintptr_t hva_num = (uintptr_t)hva;
// Start of this hva region is in this slot.
if (hva_num >= hva_start_num &&
hva_num < hva_start_num + mslot->size) {
if (count < array_size) {
gpa[count] = mslot->gpa_start + (hva_num - hva_start_num);
size[count] = min(length,
mslot->size - (hva_num - hva_start_num));
}
count++;
// End of this hva region is in this slot.
// Its start is outside of this slot.
} else if (hva_num + length <= hva_start_num + mslot->size &&
hva_num + length > hva_start_num) {
if (count < array_size) {
gpa[count] = mslot->gpa_start;
size[count] = hva_num + length - hva_start_num;
}
count++;
// This slot belongs to this hva region completely.
} else if (hva_num + length > hva_start_num + mslot->size &&
hva_num < hva_start_num) {
if (count < array_size) {
gpa[count] = mslot->gpa_start;
size[count] = mslot->size;
}
count++;
}
}
return count;
}
static hvf_slot* hvf_next_free_slot() {
hvf_slot* mem = 0;
int x;
for (x = 0; x < hvf_state->num_slots; ++x) {
mem = &hvf_state->slots[x];
if (!mem->size) {
return mem;
}
}
return mem;
}
int __hvf_set_memory(hvf_slot *slot);
int __hvf_set_memory_with_flags_locked(hvf_slot *slot, hv_memory_flags_t flags);
int hvf_map_safe(void* hva, uint64_t gpa, uint64_t size, uint64_t flags) {
pthread_rwlock_wrlock(&mem_lock);
DPRINTF("%s: hva: [%p 0x%llx] gpa: [0x%llx 0x%llx]\n", __func__,
hva, (unsigned long long)(uintptr_t)(((char*)hva) + size),
(unsigned long long)gpa,
(unsigned long long)gpa + size);
hvf_slot *mem;
mem = hvf_find_overlap_slot(gpa, gpa + size);
if (mem &&
mem->mem == hva &&
mem->start == gpa &&
mem->size == size) {
pthread_rwlock_unlock(&mem_lock);
return HV_SUCCESS;
} else if (mem &&
mem->start == gpa &&
mem->size == size) {
// unmap existing mapping, but only if it coincides
mem->size = 0;
__hvf_set_memory_with_flags_locked(mem, 0);
} else if (mem) {
// TODO: Manage and support partially-overlapping user-backed RAM mappings.
// for now, consider it fatal.
pthread_rwlock_unlock(&mem_lock);
qemu_abort("%s: FATAL: tried to map [0x%llx 0x%llx) to %p "
"while it was mapped to [0x%llx 0x%llx), %p",
__func__,
(unsigned long long)gpa,
(unsigned long long)gpa + size,
hva,
(unsigned long long)mem->start,
(unsigned long long)mem->start + mem->size,
mem->mem);
}
mem = hvf_next_free_slot();
if (mem->size) {
qemu_abort("%s: no free slots\n", __func__);
}
mem->mem = (uint8_t*)hva;
mem->start = gpa;
mem->size = size;
int res = __hvf_set_memory_with_flags_locked(mem, (hv_memory_flags_t)flags);
pthread_rwlock_unlock(&mem_lock);
return res;
}
int hvf_unmap_safe(uint64_t gpa, uint64_t size) {
DPRINTF("%s: gpa: [0x%llx 0x%llx]\n", __func__,
(unsigned long long)gpa,
(unsigned long long)gpa + size);
pthread_rwlock_wrlock(&mem_lock);
hvf_slot *mem;
int res = 0;
mem = hvf_find_overlap_slot(gpa, gpa + size);
if (mem &&
(mem->start != gpa ||
mem->size != size)) {
pthread_rwlock_unlock(&mem_lock);
qemu_abort("%s: tried to unmap [0x%llx 0x%llx) but partially overlapping "
"[0x%llx 0x%llx), %p was encountered",
__func__, gpa, gpa + size,
mem->start, mem->start + mem->size, mem->mem);
} else if (mem) {
mem->size = 0;
res = __hvf_set_memory_with_flags_locked(mem, 0);
} else {
// fall through, allow res to be 0 still if slot was not found.
}
pthread_rwlock_unlock(&mem_lock);
return res;
}
int hvf_protect_safe(uint64_t gpa, uint64_t size, uint64_t flags) {
pthread_rwlock_wrlock(&mem_lock);
int res = hv_vm_protect(gpa, size, flags);
pthread_rwlock_unlock(&mem_lock);
return res;
}
int hvf_remap_safe(void* hva, uint64_t gpa, uint64_t size, uint64_t flags) {
pthread_rwlock_wrlock(&mem_lock);
int res = hv_vm_unmap(gpa, size);
assert_hvf_ok(res);
res = hv_vm_map(hva, gpa, size, flags);
assert_hvf_ok(res);
pthread_rwlock_unlock(&mem_lock);
return res;
}
// API for adding and removing mappings of guest RAM and host addrs.
// Implementation depends on the hypervisor.
static hv_memory_flags_t user_backed_flags_to_hvf_flags(int flags) {
hv_memory_flags_t hvf_flags = 0;
if (flags & USER_BACKED_RAM_FLAGS_READ) {
hvf_flags |= HV_MEMORY_READ;
}
if (flags & USER_BACKED_RAM_FLAGS_WRITE) {
hvf_flags |= HV_MEMORY_WRITE;
}
if (flags & USER_BACKED_RAM_FLAGS_EXEC) {
hvf_flags |= HV_MEMORY_EXEC;
}
return hvf_flags;
}
static void hvf_user_backed_ram_map(uint64_t gpa, void* hva, uint64_t size, int flags) {
hvf_map_safe(hva, gpa, size, user_backed_flags_to_hvf_flags(flags));
}
static void hvf_user_backed_ram_unmap(uint64_t gpa, uint64_t size) {
hvf_unmap_safe(gpa, size);
}
int __hvf_set_memory(hvf_slot *slot) {
pthread_rwlock_wrlock(&mem_lock);
int res = __hvf_set_memory_with_flags_locked(slot, HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
pthread_rwlock_unlock(&mem_lock);
return res;
}
int __hvf_set_memory_with_flags_locked(hvf_slot *slot, hv_memory_flags_t flags) {
static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)
{
struct mac_slot *macslot;
hv_return_t ret;
macslot = &mac_slots[slot->slot_id];
if (macslot->present) {
if (macslot->size != slot->size) {
macslot->present = 0;
DPRINTF("%s: hv_vm_unmap for gpa [0x%llx 0x%llx]\n", __func__,
(unsigned long long)macslot->gpa_start,
(unsigned long long)(macslot->gpa_start + macslot->size));
int unmapres = hv_vm_unmap(macslot->gpa_start, macslot->size);
assert_hvf_ok(unmapres);
ret = hv_vm_unmap(macslot->gpa_start, macslot->size);
assert_hvf_ok(ret);
}
}
@@ -334,58 +111,93 @@ int __hvf_set_memory_with_flags_locked(hvf_slot *slot, hv_memory_flags_t flags)
macslot->present = 1;
macslot->gpa_start = slot->start;
macslot->size = slot->size;
macslot->hva = slot->mem;
DPRINTF("%s: hv_vm_map for hva 0x%llx gpa [0x%llx 0x%llx]\n", __func__,
(unsigned long long)(slot->mem),
(unsigned long long)macslot->gpa_start,
(unsigned long long)(macslot->gpa_start + macslot->size));
int mapres = (hv_vm_map(slot->mem, slot->start, slot->size, flags));
assert_hvf_ok(mapres);
ret = hv_vm_map(slot->mem, slot->start, slot->size, flags);
assert_hvf_ok(ret);
return 0;
}
static void hvf_set_phys_mem(MemoryRegionSection* section, bool add) {
static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
{
hvf_slot *mem;
MemoryRegion *area = section->mr;
bool writable = !area->readonly && !area->rom_device;
hv_memory_flags_t flags;
uint64_t page_size = qemu_real_host_page_size();
if (!memory_region_is_ram(area)) return;
if (memory_region_is_user_backed(area)) return;
mem = hvf_find_overlap_slot(
section->offset_within_address_space,
section->offset_within_address_space + int128_get64(section->size));
if (mem && add) {
if (mem->size == int128_get64(section->size) &&
mem->start == section->offset_within_address_space &&
mem->mem == (memory_region_get_ram_ptr(area) + section->offset_within_region))
return; // Same region was attempted to register, go away.
}
// Region needs to be reset. set the size to 0 and remap it.
if (mem) {
mem->size = 0;
if (__hvf_set_memory(mem)) {
qemu_abort("%s: Failed to reset overlapping slot\n", __func__);
if (!memory_region_is_ram(area)) {
if (writable) {
return;
} else if (!memory_region_is_romd(area)) {
/*
* If the memory device is not in romd_mode, then we actually want
* to remove the hvf memory slot so all accesses will trap.
*/
add = false;
}
}
if (!add) return;
if (!QEMU_IS_ALIGNED(int128_get64(section->size), page_size) ||
!QEMU_IS_ALIGNED(section->offset_within_address_space, page_size)) {
/* Not page aligned, so we can not map as RAM */
add = false;
}
// Now make a new slot.
mem = hvf_find_overlap_slot(
section->offset_within_address_space,
int128_get64(section->size));
mem = hvf_next_free_slot();
if (mem && add) {
if (mem->size == int128_get64(section->size) &&
mem->start == section->offset_within_address_space &&
mem->mem == (memory_region_get_ram_ptr(area) +
section->offset_within_region)) {
return; /* Same region was attempted to register, go away. */
}
}
if (!mem) {
qemu_abort("%s: no free slots\n", __func__);
/* Region needs to be reset. set the size to 0 and remap it. */
if (mem) {
mem->size = 0;
if (do_hvf_set_memory(mem, 0)) {
error_report("Failed to reset overlapping slot");
abort();
}
}
if (!add) {
return;
}
if (area->readonly ||
(!memory_region_is_ram(area) && memory_region_is_romd(area))) {
flags = HV_MEMORY_READ | HV_MEMORY_EXEC;
} else {
flags = HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC;
}
/* Now make a new slot. */
int x;
for (x = 0; x < hvf_state->num_slots; ++x) {
mem = &hvf_state->slots[x];
if (!mem->size) {
break;
}
}
if (x == hvf_state->num_slots) {
error_report("No free slots");
abort();
}
mem->size = int128_get64(section->size);
mem->mem = memory_region_get_ram_ptr(area) + section->offset_within_region;
mem->start = section->offset_within_address_space;
mem->region = area;
if (__hvf_set_memory(mem)) {
qemu_abort("%s: error regsitering new memory slot\n", __func__);
if (do_hvf_set_memory(mem, flags)) {
error_report("Error registering new memory slot");
abort();
}
}
@@ -507,47 +319,25 @@ bool hvf_allowed;
static int hvf_accel_init(MachineState *ms)
{
int x;
hv_return_t ret;
HVFState *s = HVF_STATE(ms->accelerator);
HVFState *s;
ret = hvf_arch_vm_create(s);
ret = hv_vm_create(HV_VM_DEFAULT);
assert_hvf_ok(ret);
hvf_state = s;
memory_listener_register(&hvf_memory_listener, &address_space_memory);
qemu_set_user_backed_mapping_funcs(
hvf_user_backed_ram_map,
hvf_user_backed_ram_unmap);
return hvf_arch_init();
}
#if defined(CONFIG_HVF_PRIVATE) && defined(__aarch64__)
static bool hvf_get_tso(Object *obj, Error **errp)
{
HVFState *s = HVF_STATE(obj);
return s->tso_mode;
}
static void hvf_set_tso(Object *obj, bool value, Error **errp)
{
HVFState *s = HVF_STATE(obj);
s->tso_mode = value;
}
#endif
static void hvf_accel_instance_init(Object *obj)
{
int x;
HVFState *s = HVF_STATE(obj);
s = g_new0(HVFState, 1);
s->num_slots = ARRAY_SIZE(s->slots);
for (x = 0; x < s->num_slots; ++x) {
s->slots[x].size = 0;
s->slots[x].slot_id = x;
}
hvf_state = s;
memory_listener_register(&hvf_memory_listener, &address_space_memory);
return hvf_arch_init();
}
static void hvf_accel_class_init(ObjectClass *oc, void *data)
@@ -556,21 +346,12 @@ static void hvf_accel_class_init(ObjectClass *oc, void *data)
ac->name = "HVF";
ac->init_machine = hvf_accel_init;
ac->allowed = &hvf_allowed;
#if defined(CONFIG_HVF_PRIVATE) && defined(__aarch64__)
object_class_property_add_bool(oc, "tso",
hvf_get_tso, hvf_set_tso);
object_class_property_set_description(oc, "tso",
"Set on/off to enable/disable total store ordering mode");
#endif
}
static const TypeInfo hvf_accel_type = {
.name = TYPE_HVF_ACCEL,
.parent = TYPE_ACCEL,
.instance_init = hvf_accel_instance_init,
.class_init = hvf_accel_class_init,
.instance_size = sizeof(HVFState),
};
static void hvf_type_init(void)
-1
View File
@@ -27,7 +27,6 @@
#include "disas/disas.h"
#include "exec/exec-all.h"
#include "tcg/tcg.h"
#include "tcg/tcg-apple-jit.h"
#include "qemu/atomic.h"
#include "qemu/compiler.h"
#include "qemu/timer.h"
-1
View File
@@ -24,7 +24,6 @@
#include "exec/translate-all.h"
#include "sysemu/tcg.h"
#include "tcg/tcg.h"
#include "tcg/tcg-apple-jit.h"
#include "tb-hash.h"
#include "tb-context.h"
#include "internal.h"
-5
View File
@@ -47,11 +47,6 @@ void tcg_cpu_init_cflags(CPUState *cpu, bool parallel)
uint32_t cflags = cpu->cluster_index << CF_CLUSTER_SHIFT;
cflags |= parallel ? CF_PARALLEL : 0;
cflags |= icount_enabled() ? CF_USE_ICOUNT : 0;
#if defined(CONFIG_TCG_THREADED_INTERPRETER)
// GOTO_PTR is too complex to emit a simple gadget for.
// We'll let C handle it, since the overhead is similar.
cflags |= CF_NO_GOTO_PTR;
#endif
cpu->tcg_cflags = cflags;
}
-1
View File
@@ -24,7 +24,6 @@
#include "disas/disas.h"
#include "exec/exec-all.h"
#include "tcg/tcg.h"
#include "tcg/tcg-apple-jit.h"
#if defined(CONFIG_USER_ONLY)
#include "qemu.h"
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+6 -24
View File
@@ -1409,21 +1409,12 @@ void audio_run(AudioState *s, const char *msg)
#endif
}
void audio_generic_initialize_buffer_in(HWVoiceIn *hw)
{
if (hw->buf_emul) {
g_free(hw->buf_emul);
}
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
}
void audio_generic_run_buffer_in(HWVoiceIn *hw)
{
if (unlikely(!hw->buf_emul)) {
audio_generic_initialize_buffer_in(hw);
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
}
while (hw->pending_emul < hw->size_emul) {
@@ -1457,17 +1448,6 @@ void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size)
hw->pending_emul -= size;
}
void audio_generic_initialize_buffer_out(HWVoiceOut *hw)
{
if (hw->buf_emul) {
g_free(hw->buf_emul);
}
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
}
size_t audio_generic_buffer_get_free(HWVoiceOut *hw)
{
if (hw->buf_emul) {
@@ -1499,7 +1479,9 @@ void audio_generic_run_buffer_out(HWVoiceOut *hw)
void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size)
{
if (unlikely(!hw->buf_emul)) {
audio_generic_initialize_buffer_out(hw);
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
}
*size = MIN(hw->size_emul - hw->pending_emul,
-2
View File
@@ -190,11 +190,9 @@ struct audio_pcm_ops {
void (*volume_in)(HWVoiceIn *hw, Volume *vol);
};
void audio_generic_initialize_buffer_in(HWVoiceIn *hw);
void audio_generic_run_buffer_in(HWVoiceIn *hw);
void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size);
void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size);
void audio_generic_initialize_buffer_out(HWVoiceOut *hw);
void audio_generic_run_buffer_out(HWVoiceOut *hw);
size_t audio_generic_buffer_get_free(HWVoiceOut *hw);
void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size);
+22 -28
View File
@@ -360,10 +360,7 @@ static OSStatus audioDeviceIOProc(
static OSStatus init_out_device(coreaudioVoiceOut *core)
{
OSStatus status;
AudioDeviceID deviceID;
AudioValueRange frameRange;
UInt32 audioDevicePropertyBufferFrameSize;
AudioDeviceIOProcID ioprocid;
AudioStreamBasicDescription streamBasicDescription = {
.mBitsPerChannel = core->hw.info.bits,
@@ -376,19 +373,20 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
.mSampleRate = core->hw.info.freq
};
status = coreaudio_get_voice(&deviceID);
status = coreaudio_get_voice(&core->outputDeviceID);
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr (status,
"Could not get default output Device\n");
return status;
}
if (deviceID == kAudioDeviceUnknown) {
if (core->outputDeviceID == kAudioDeviceUnknown) {
dolog ("Could not initialize playback - Unknown Audiodevice\n");
return status;
}
/* get minimum and maximum buffer frame sizes */
status = coreaudio_get_framesizerange(deviceID, &frameRange);
status = coreaudio_get_framesizerange(core->outputDeviceID,
&frameRange);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -399,31 +397,31 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
}
if (frameRange.mMinimum > core->frameSizeSetting) {
audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
} else if (frameRange.mMaximum < core->frameSizeSetting) {
audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum);
} else {
audioDevicePropertyBufferFrameSize = core->frameSizeSetting;
core->audioDevicePropertyBufferFrameSize = core->frameSizeSetting;
}
/* set Buffer Frame Size */
status = coreaudio_set_framesize(deviceID,
&audioDevicePropertyBufferFrameSize);
status = coreaudio_set_framesize(core->outputDeviceID,
&core->audioDevicePropertyBufferFrameSize);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr (status,
"Could not set device buffer frame size %" PRIu32 "\n",
(uint32_t)audioDevicePropertyBufferFrameSize);
(uint32_t)core->audioDevicePropertyBufferFrameSize);
return status;
}
/* get Buffer Frame Size */
status = coreaudio_get_framesize(deviceID,
&audioDevicePropertyBufferFrameSize);
status = coreaudio_get_framesize(core->outputDeviceID,
&core->audioDevicePropertyBufferFrameSize);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -432,9 +430,11 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
"Could not get device buffer frame size\n");
return status;
}
core->hw.samples = core->bufferCount * core->audioDevicePropertyBufferFrameSize;
/* set Samplerate */
status = coreaudio_set_streamformat(deviceID, &streamBasicDescription);
status = coreaudio_set_streamformat(core->outputDeviceID,
&streamBasicDescription);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -442,6 +442,7 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
coreaudio_playback_logerr (status,
"Could not set samplerate %lf\n",
streamBasicDescription.mSampleRate);
core->outputDeviceID = kAudioDeviceUnknown;
return status;
}
@@ -455,25 +456,20 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
* Therefore, the specified callback must be designed to avoid a deadlock
* with the callers of AudioObjectGetPropertyData.
*/
ioprocid = NULL;
status = AudioDeviceCreateIOProcID(deviceID,
core->ioprocid = NULL;
status = AudioDeviceCreateIOProcID(core->outputDeviceID,
audioDeviceIOProc,
&core->hw,
&ioprocid);
&core->ioprocid);
if (status == kAudioHardwareBadDeviceError) {
return 0;
}
if (status != kAudioHardwareNoError || ioprocid == NULL) {
if (status != kAudioHardwareNoError || core->ioprocid == NULL) {
coreaudio_playback_logerr (status, "Could not set IOProc\n");
core->outputDeviceID = kAudioDeviceUnknown;
return status;
}
core->outputDeviceID = deviceID;
core->audioDevicePropertyBufferFrameSize = audioDevicePropertyBufferFrameSize;
core->hw.samples = core->bufferCount * core->audioDevicePropertyBufferFrameSize;
audio_generic_initialize_buffer_out(&core->hw);
core->ioprocid = ioprocid;
return 0;
}
@@ -557,9 +553,7 @@ static OSStatus handle_voice_change(
fini_out_device(core);
}
init_out_device(core);
if (core->outputDeviceID) {
if (!init_out_device(core)) {
update_device_playback_state(core);
}
+37 -7
View File
@@ -37,8 +37,15 @@
// #define DEBUG_VERBOSE
/* CURL 7.85.0 switches to a string based API for specifying
* the desired protocols.
*/
#if LIBCURL_VERSION_NUM >= 0x075500
#define PROTOCOLS "HTTP,HTTPS,FTP,FTPS"
#else
#define PROTOCOLS (CURLPROTO_HTTP | CURLPROTO_HTTPS | \
CURLPROTO_FTP | CURLPROTO_FTPS)
#endif
#define CURL_NUM_STATES 8
#define CURL_NUM_ACB 8
@@ -509,9 +516,18 @@ static int curl_init_state(BDRVCURLState *s, CURLState *state)
* obscure protocols. For example, do not allow POP3/SMTP/IMAP see
* CVE-2013-0249.
*
* Restricting protocols is only supported from 7.19.4 upwards.
* Restricting protocols is only supported from 7.19.4 upwards. Note:
* version 7.85.0 deprecates CURLOPT_*PROTOCOLS in favour of a string
* based CURLOPT_*PROTOCOLS_STR API.
*/
#if LIBCURL_VERSION_NUM >= 0x071304
#if LIBCURL_VERSION_NUM >= 0x075500
if (curl_easy_setopt(state->curl,
CURLOPT_PROTOCOLS_STR, PROTOCOLS) ||
curl_easy_setopt(state->curl,
CURLOPT_REDIR_PROTOCOLS_STR, PROTOCOLS)) {
goto err;
}
#elif LIBCURL_VERSION_NUM >= 0x071304
if (curl_easy_setopt(state->curl, CURLOPT_PROTOCOLS, PROTOCOLS) ||
curl_easy_setopt(state->curl, CURLOPT_REDIR_PROTOCOLS, PROTOCOLS)) {
goto err;
@@ -669,7 +685,12 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
const char *file;
const char *cookie;
const char *cookie_secret;
double d;
/* CURL >= 7.55.0 uses curl_off_t for content length instead of a double */
#if LIBCURL_VERSION_NUM >= 0x073700
curl_off_t cl;
#else
double cl;
#endif
const char *secretid;
const char *protocol_delimiter;
int ret;
@@ -796,27 +817,36 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
}
if (curl_easy_perform(state->curl))
goto out;
if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) {
/* CURL 7.55.0 deprecates CURLINFO_CONTENT_LENGTH_DOWNLOAD in favour of
* the *_T version which returns a more sensible type for content length.
*/
#if LIBCURL_VERSION_NUM >= 0x073700
if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &cl)) {
goto out;
}
#else
if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl)) {
goto out;
}
#endif
/* Prior CURL 7.19.4 return value of 0 could mean that the file size is not
* know or the size is zero. From 7.19.4 CURL returns -1 if size is not
* known and zero if it is really zero-length file. */
#if LIBCURL_VERSION_NUM >= 0x071304
if (d < 0) {
if (cl < 0) {
pstrcpy(state->errmsg, CURL_ERROR_SIZE,
"Server didn't report file size.");
goto out;
}
#else
if (d <= 0) {
if (cl <= 0) {
pstrcpy(state->errmsg, CURL_ERROR_SIZE,
"Unknown file size or zero-length file.");
goto out;
}
#endif
s->len = d;
s->len = cl;
if ((!strncasecmp(s->url, "http://", strlen("http://"))
|| !strncasecmp(s->url, "https://", strlen("https://")))
+2 -19
View File
@@ -43,10 +43,10 @@
#if defined(__APPLE__) && (__MACH__)
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/mount.h>
#if defined(HAVE_HOST_BLOCK_DEVICE)
#include <paths.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOBSD.h>
#include <IOKit/storage/IOMediaBSDClient.h>
@@ -130,14 +130,6 @@
#define RAW_LOCK_PERM_BASE 100
#define RAW_LOCK_SHARED_BASE 200
/*
* qemu_lock_fd_test always returns 0 when fd is not open for writing and
* exclusive is true on macOS 11.3.1.
*/
#ifdef __APPLE__
#define RAW_LOCK_WRITES
#endif
typedef struct BDRVRawState {
int fd;
bool use_lock;
@@ -681,11 +673,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
false);
s->open_flags = open_flags;
#ifdef RAW_LOCK_WRITES
raw_parse_flags(bdrv_flags, &s->open_flags, s->use_lock);
#else
raw_parse_flags(bdrv_flags, &s->open_flags, false);
#endif
s->fd = -1;
fd = qemu_open(filename, s->open_flags, errp);
@@ -1050,11 +1038,6 @@ static int raw_reconfigure_getfd(BlockDriverState *bs, int flags,
bool has_writers = perm &
(BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED | BLK_PERM_RESIZE);
int fcntl_flags = O_APPEND | O_NONBLOCK;
#ifdef RAW_LOCK_WRITES
if (s->use_lock) {
has_writers = true;
}
#endif
#ifdef O_NOATIME
fcntl_flags |= O_NOATIME;
#endif
+3
View File
@@ -2087,6 +2087,9 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child,
if (bs->detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP) {
flags |= BDRV_REQ_MAY_UNMAP;
}
/* Can't use optimization hint with bufferless zero write */
flags &= ~BDRV_REQ_REGISTERED_BUF;
}
if (ret < 0) {
+1
View File
@@ -268,6 +268,7 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
timer_mod(&iTask->retry_timer,
qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + retry_time);
iTask->do_retry = 1;
return;
} else if (status == SCSI_STATUS_CHECK_CONDITION) {
int error = iscsi_translate_sense(&task->sense);
if (error == EAGAIN) {
+3 -2
View File
@@ -115,7 +115,7 @@ static int update_header_sync(BlockDriverState *bs)
return bdrv_flush(bs->file->bs);
}
static inline void bitmap_table_to_be(uint64_t *bitmap_table, size_t size)
static inline void bitmap_table_bswap_be(uint64_t *bitmap_table, size_t size)
{
size_t i;
@@ -1401,9 +1401,10 @@ static int store_bitmap(BlockDriverState *bs, Qcow2Bitmap *bm, Error **errp)
goto fail;
}
bitmap_table_to_be(tb, tb_size);
bitmap_table_bswap_be(tb, tb_size);
ret = bdrv_pwrite(bs->file, tb_offset, tb_size * sizeof(tb[0]), tb, 0);
if (ret < 0) {
bitmap_table_bswap_be(tb, tb_size);
error_setg_errno(errp, -ret, "Failed to write bitmap '%s' to file",
bm_name);
goto fail;
+1 -1
View File
@@ -980,7 +980,7 @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
sector_write = merged_sector;
} else if (i == sectors - 1 && trailing_length) {
/* partial sector at the end of the buffer */
ret = bdrv_pread(bs->file, file_offset,
ret = bdrv_pread(bs->file, file_offset + trailing_length,
VHDX_LOG_SECTOR_SIZE - trailing_length,
merged_sector + trailing_length, 0);
if (ret < 0) {
+1
View File
@@ -1065,6 +1065,7 @@ static void char_socket_finalize(Object *obj)
qio_net_listener_set_client_func_full(s->listener, NULL, NULL,
NULL, chr->gcontext);
object_unref(OBJECT(s->listener));
s->listener = NULL;
}
if (s->tls_creds) {
object_unref(OBJECT(s->tls_creds));
Vendored
+4 -37
View File
@@ -290,7 +290,6 @@ meson=""
ninja=""
bindir="bin"
skip_meson=no
shared_lib="no"
vfio_user_server="disabled"
# The following Meson options are handled manually (still they
@@ -897,12 +896,6 @@ for opt do
;;
--enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
;;
--enable-shared-lib)
shared_lib="yes"
plugins="no"
;;
--disable-shared-lib) shared_lib="no"
;;
# everything else has the same name in configure and meson
--*) meson_option_parse "$opt" "$optarg"
;;
@@ -914,10 +907,6 @@ if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
error_exit "Can't enable plugins on non-TCG builds"
fi
if test "$plugins" = "yes" -a "$shared_lib" = "yes"; then
error_exit "Can't enable plugins on shared library builds"
fi
case $git_submodules_action in
update|validate)
if test ! -e "$source_path/.git"; then
@@ -1042,7 +1031,7 @@ Advanced options (experts only):
--disable-stack-protector disable compiler-provided stack protection
--cpu=CPU Build for host CPU [$cpu]
--with-coroutine=BACKEND coroutine backend. Supported options:
ucontext, libucontext, sigaltstack, windows
ucontext, sigaltstack, windows
--enable-plugins
enable plugins via shared library loading
--disable-containers don't use containers for cross-building
@@ -1606,26 +1595,12 @@ else
error_exit "only the 'windows' coroutine backend is valid for Windows"
fi
;;
libucontext)
;;
*)
error_exit "unknown coroutine backend $coroutine"
;;
esac
fi
case $coroutine in
libucontext)
git_submodules="${git_submodules} subprojects/libucontext"
coroutine_impl=ucontext
libucontext="enabled"
;;
*)
coroutine_impl=$coroutine
libucontext="disabled"
;;
esac
##################################################
# SafeStack
@@ -2403,7 +2378,7 @@ if [ "$bsd" = "yes" ] ; then
echo "CONFIG_BSD=y" >> $config_host_mak
fi
echo "CONFIG_COROUTINE_BACKEND=$coroutine_impl" >> $config_host_mak
echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
if test "$have_asan_iface_fiber" = "yes" ; then
echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
@@ -2417,10 +2392,6 @@ if test "$plugins" = "yes" ; then
echo "CONFIG_PLUGIN=y" >> $config_host_mak
fi
if test "$shared_lib" = "yes" ; then
echo "CONFIG_SHARED_LIBRARY_BUILD=y" >> $config_host_mak
fi
if test -n "$gdb_bin"; then
gdb_version=$($gdb_bin --version | head -n 1)
if version_ge ${gdb_version##* } 9.1; then
@@ -2445,7 +2416,7 @@ echo "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
echo "GLIB_BINDIR=$glib_bindir" >> $config_host_mak
echo "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
echo "GLIB_VERSION=$($pkg_config --modversion glib-2.0)" >> $config_host_mak
echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
echo "EXESUF=$EXESUF" >> $config_host_mak
@@ -2587,11 +2558,7 @@ if test "$skip_meson" = no; then
if has $sdl2_config; then
echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
fi
if test "$shared_lib" = "yes"; then
echo "strip = [$(meson_quote $strip), '-x']" >> $cross
else
echo "strip = [$(meson_quote $strip)]" >> $cross
fi
echo "strip = [$(meson_quote $strip)]" >> $cross
echo "widl = [$(meson_quote $widl)]" >> $cross
echo "windres = [$(meson_quote $windres)]" >> $cross
if test "$cross_compile" = "yes"; then
+2 -2
View File
@@ -323,7 +323,7 @@ virgl_cmd_set_scanout(VuGpu *g,
struct virtio_gpu_ctrl_command *cmd)
{
struct virtio_gpu_set_scanout ss;
struct virgl_renderer_texture_info info;
struct virgl_renderer_resource_info info;
int ret;
VUGPU_FILL_CMD(ss);
@@ -338,7 +338,7 @@ virgl_cmd_set_scanout(VuGpu *g,
memset(&info, 0, sizeof(info));
if (ss.resource_id && ss.r.width && ss.r.height) {
ret = virgl_renderer_borrow_texture_for_scanout(ss.resource_id, &info);
ret = virgl_renderer_resource_get_info(ss.resource_id, &info);
if (ret == -1) {
g_critical("%s: illegal resource specified %d\n",
__func__, ss.resource_id);
-2
View File
@@ -151,8 +151,6 @@ static void initialize_debug_host(CPUDebug *s)
#endif
#if defined(CONFIG_TCG_INTERPRETER)
s->info.print_insn = print_insn_tci;
#elif defined(CONFIG_TCG_THREADED_INTERPRETER)
s->info.print_insn = print_insn_tcti;
#elif defined(__i386__)
s->info.mach = bfd_mach_i386_i386;
s->info.cap_arch = CS_ARCH_X86;
+3
View File
@@ -52,6 +52,9 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 1,
.max_access_size = 4,
},
.impl = {
.max_access_size = 1,
},
};
+4 -1
View File
@@ -686,7 +686,10 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds,
rom_ptr_for_as(as, addr, size));
g_free(fdt);
if (fdt != ms->fdt) {
g_free(ms->fdt);
ms->fdt = fdt;
}
return size;
-4
View File
@@ -1713,11 +1713,7 @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
* irrespective of the underlying capabilities of the HW.
*/
if (!vms->highmem) {
#ifdef CONFIG_DARWIN
pa_bits = 36;
#else
pa_bits = 32;
#endif
}
/*
-3
View File
@@ -47,6 +47,3 @@ config PL041
config CS4231
bool
config SCREAMER
bool
-1
View File
@@ -12,4 +12,3 @@ softmmu_ss.add(when: 'CONFIG_PL041', if_true: files('pl041.c', 'lm4549.c'))
softmmu_ss.add(when: 'CONFIG_SB16', if_true: files('sb16.c'))
softmmu_ss.add(when: 'CONFIG_VT82C686', if_true: files('via-ac97.c'))
softmmu_ss.add(when: 'CONFIG_WM8750', if_true: files('wm8750.c'))
softmmu_ss.add(when: 'CONFIG_SCREAMER', if_true: files('screamer.c'))
-986
View File
@@ -1,986 +0,0 @@
/*
* File: Screamer.c
* Description: Implement the Screamer sound chip used in Apple Macintoshes.
* It works by filling a buffer, then playing the buffer.
*/
#include "qemu/osdep.h"
#include "audio/audio.h"
#include "hw/hw.h"
#include "hw/irq.h"
#include <inttypes.h>
#include "hw/ppc/mac_dbdma.h"
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
#include "include/hw/audio/screamer.h"
#define DEBUG_SCREAMER 0
#define DPRINTF(fmt, ...) \
do { if (DEBUG_SCREAMER) { printf(fmt , ## __VA_ARGS__); } } while (0)
#define SOUND_CONTROL_REG 0
#define CODEC_CONTROL_REG 1
#define CODEC_STATUS_REG 2
#define CLIP_COUNT_REG 3
#define BYTE_SWAP_REG 4
#define FRAME_COUNT_REG 5
#define AWACS_BUSY 0x01000000
/* Used with AWACS register 1 */
#define RECALIBRATE 0x004
#define LOOPTHRU 0x040
#define SPEAKER_MUTE 0x080
#define HEADPHONE_MUTE 0x200
#define OUTPUT_ZERO 0x400
#define OUTPUT_ONE 0x800
#define PARALLEL_OUTPUT 0xc00
/* Function prototypes */
static uint32_t set_busy_bit(uint32_t value, int bit);
static uint32_t set_part_ready_bit(uint32_t value, int bit_value);
static uint32_t set_revision(uint32_t input_value);
static uint32_t set_manufacturer(uint32_t input_value);
static int get_sampling_rate(ScreamerState *s);
static uint32_t get_frame_count_reg(ScreamerState *s);
static void add_to_speaker_buffer(DBDMA_io *io);
static void dma_request(DBDMA_io *io);
/**************************** Getters *************************/
/* Returns the codec control register's encoded AWACS address */
static uint8_t get_codec_control_address(uint32_t value)
{
uint8_t return_value;
return_value = (value >> 12) & 0x00000fff;
return return_value;
}
static uint32_t get_sound_control_reg(ScreamerState *s)
{
DPRINTF("%s() called - returned 0x%x\n", __func__, s->sound_control);
return s->sound_control;
}
/* The AWACS registers are accessed thru this register */
static uint32_t get_codec_control_reg(ScreamerState *s)
{
int awacs_register = get_codec_control_address(s->codec_control);
uint32_t return_value = s->awacs[awacs_register];
return_value = set_busy_bit(return_value, 0); /* Tell CPU we are ready */
DPRINTF("%s() called - returned 0x%x\tAWACS register: %d\n", __func__,
return_value, awacs_register);
return return_value;
}
/*
* Determines if the readback bit is set.
* It is used by the Codec Control register.
*/
static bool readback_enabled(ScreamerState *s)
{
/* Note: bit zero is the readback enabled bit */
if (s->awacs[7] & 1) {
return true;
} else {
return false;
}
}
static uint32_t get_codec_status_reg(ScreamerState *s)
{
uint32_t return_value;
/* if in readback mode - return AWACS register value */
if (readback_enabled(s)) {
int awacs_register = (s->awacs[7] & 0xe) >> 1;
s->awacs[7] = s->awacs[7] & 0xfffffffe; /* turn off readback mode */
return_value = s->awacs[awacs_register] << 4;
DPRINTF("readback enable bit is set, returning AWACS register %d\t"
"value:0x%x\n", awacs_register, return_value);
return return_value;
}
/* Tell CPU we are ready */
return_value = set_part_ready_bit(s->codec_status, 1);
/* Set Revision to Screamer */
return_value = set_revision(return_value);
/* Set the Manufacturer to Crystal */
return_value = set_manufacturer(return_value);
DPRINTF("%s() called - returned 0x%x\n", __func__, return_value);
return return_value;
}
static uint32_t get_clip_count_reg(ScreamerState *s)
{
DPRINTF("%s() called - returned 0x%x\n", __func__, s->clip_count);
uint32_t return_value;
return_value = s->clip_count;
/* This is reset everytime it is read */
s->clip_count = 0;
return return_value;
}
static uint32_t get_byte_swap_reg(ScreamerState *s)
{
DPRINTF("%s() called - returned 0x%x\n", __func__, s->byte_swap);
/*
* If all you hear is noise, it could be this register reporting the
* wrong value.
*/
return s->byte_swap ? 0 : 1;
}
/*
* Returns the frame (sample) count
*/
static uint32_t get_frame_count_reg(ScreamerState *s)
{
DPRINTF("%s() called - returned 0x%x\n", __func__, s->frame_count);
return s->frame_count;
}
static uint8_t get_left_vol(uint32_t value)
{
return value & 0xf;
}
static uint8_t get_right_vol(uint32_t value)
{
return value & 0x3c0 >> 6;
}
/*
* Returns the sampling rate.
* If the audio is playing back too fast or too slow, this function may be the
* cause.
*/
static int get_sampling_rate(ScreamerState *s)
{
uint32_t screamer_rate = s->sound_control & 0x700;
int return_value;
/* All return values are in Hertz */
switch (screamer_rate) {
case 0x0:
return_value = 44100;
break;
case 0x100:
return_value = 29400;
break;
case 0x200:
return_value = 22050;
break;
case 0x300:
return_value = 17640;
break;
case 0x400:
return_value = 14700;
break;
case 0x500:
return_value = 11025;
break;
case 0x600:
return_value = 8820;
break;
case 0x700:
return_value = 7350;
break;
default:
DPRINTF("get_sampling_rate() unknown value: 0x%x\nDefaulting to"
" 44100 Hz.\n", screamer_rate);
return 44100;
}
DPRINTF("%s() called - returning %dHz\n", __func__, return_value);
return return_value;
}
/**************************** End of getters *************************/
/***************************** Speaker call back *************************/
/* resets the play and buffer position markers */
static void reset_markers(ScreamerState *s)
{
s->spk_play_position = 0;
s->spk_buffer_position = 0;
}
/* Sends the samples to the host for playing */
static void send_samples_to_host(ScreamerState *s, int max_samples)
{
int write_length, requested_length;
requested_length = MIN(max_samples, (s->spk_buffer_position -
s->spk_play_position));
write_length = AUD_write(s->speaker_voice,
&s->spk_buffer[s->spk_play_position],
requested_length);
DPRINTF("requested length: %d\twrite length: %d\t",
requested_length, write_length);
s->spk_play_position += write_length;
DPRINTF("AUD_write %d/%d\n", s->spk_play_position, s->spk_buffer_position);
s->frame_count += write_length;
}
/*
* Called by QEMU's audio system to tell the output backend to send samples
* from the buffer to the host sound system.
* opaque: a pointer to the ScreamerState instance.
* max_samples: the number of samples that can be sent to the hardware buffer.
*/
static void speaker_callback(void *opaque, int max_samples)
{
ScreamerState *s = (ScreamerState *) opaque;
/* if we have more samples to play */
if (s->spk_buffer_position > 0) {
if (s->spk_buffer_position > s->spk_play_position) {
DPRINTF("%s() called - max_samples: %d\n", __func__, max_samples);
send_samples_to_host(s, max_samples);
}
if (s->spk_play_position >= s->spk_buffer_position) {
DPRINTF("done playing buffer\n");
DPRINTF("pp: %d\tbp: %d\n", s->spk_play_position,
s->spk_buffer_position);
if (s->spk_play_position > s->spk_buffer_position) {
DPRINTF("Error detected! - pp > bp\n\a");
}
reset_markers(s);
/* play postponed samples */
if (s->dma_io.len > 0) {
DPRINTF("playing postponed samples\n");
add_to_speaker_buffer(&s->dma_io);
return;
}
}
}
}
/************************* End of speaker call back *************************/
/* Opens the speaker's voice */
static void open_speaker_voice(ScreamerState *s)
{
DPRINTF("%s() called\n", __func__);
/* if voice is already open return from function */
if (s->speaker_voice != NULL) {
DPRINTF("closing speaker voice\n");
AUD_close_out(&s->card, s->speaker_voice);
s->speaker_voice = NULL;
}
struct audsettings audio_settings;
audio_settings.freq = get_sampling_rate(s); /* in hertz */
audio_settings.nchannels = 2; /* stereo output */
audio_settings.fmt = AUDIO_FORMAT_S16; /* signed 16 bit */
audio_settings.endianness = get_byte_swap_reg(s); /* endianness */
s->speaker_voice = AUD_open_out(&s->card, s->speaker_voice, SOUND_CHIP_NAME
" speaker", s, speaker_callback,
&audio_settings);
if (!s->speaker_voice) {
AUD_log(SOUND_CHIP_NAME, "Out voice could not be opened\n");
} else {
AUD_set_active_out(s->speaker_voice, true);
}
}
/******************************* Setters *************************************/
/* Updates QEMU's audio backend settings */
static void set_QEMU_audio_settings(ScreamerState *s)
{
DPRINTF("%s() called\n", __func__);
open_speaker_voice(s);
}
/* Return value: 1 = muted 0 = not muted */
static int is_muted(ScreamerState *s)
{
int mute_state = s->awacs[1] & SPEAKER_MUTE ? 1 : 0;
if (s->awacs[1] & SPEAKER_MUTE) {
DPRINTF("speaker is muted\n");
} else {
DPRINTF("speaker is unmuted\n");
}
if (s->awacs[1] & HEADPHONE_MUTE) {
DPRINTF("headphone is muted\n");
} else {
DPRINTF("headphone is unmuted\n");
}
return mute_state;
}
/* Converts Screamer's volume system to QEMU's system */
static int screamer_to_qemu_volume(int x)
{
return -16 * x + 240;
}
/* Sets QEMU's volume. */
static void set_volume(ScreamerState *s)
{
int should_mute = is_muted(s);
/* Get Screamer volume values */
uint8_t left_vol = get_left_vol(s->awacs[4]);
uint8_t right_vol = get_right_vol(s->awacs[4]);
DPRINTF("set_volume() called - M:%d\tL:%d\tR:%d\n", should_mute, left_vol,
right_vol);
/* Convert Screamer to QEMU volume values */
left_vol = screamer_to_qemu_volume(left_vol);
right_vol = screamer_to_qemu_volume(right_vol);
DPRINTF("QEMU volume: L:%d\tR:%d\n", left_vol, right_vol);
AUD_set_volume_out(s->speaker_voice, should_mute, left_vol, right_vol);
}
/* Sets the sound control register */
static void set_sound_control_reg(ScreamerState *s, uint32_t value)
{
DPRINTF("set_sound_control_reg() called - value: 0x%x\n", value);
s->sound_control = value;
set_QEMU_audio_settings(s);
}
/* Used for input gain only - can be ignored for now. */
static void set_awacs_0_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 0 to 0x%x\n", s->awacs[0]);
s->awacs[0] = new_value;
}
static void set_awacs_1_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 1 to 0x%x\n", new_value);
s->awacs[1] = new_value;
/* If recalibration requested */
if (new_value & RECALIBRATE) {
DPRINTF("Recalibration requested - unimplemented\n");
new_value = new_value ^ RECALIBRATE; /* Turn off recalibrate bit */
}
/* If loop thru set - what does this mean? */
if (new_value & LOOPTHRU) {
DPRINTF("Loopthru enabled - doing nothing\n");
}
/* Set headphone jack mute state */
if (new_value & HEADPHONE_MUTE) {
DPRINTF("Headphone muted\n");
}
else {
DPRINTF("Headphone unmuted\n");
}
if (new_value & SPEAKER_MUTE) {
DPRINTF("Speaker muted\n");
}
else {
DPRINTF("Speaker unmuted\n");
}
if (new_value & OUTPUT_ZERO) {
DPRINTF("output zero set - not sure what this means\n");
}
if (new_value & OUTPUT_ONE) {
DPRINTF("output one set - not sure what this means\n");
}
if (new_value & PARALLEL_OUTPUT) {
DPRINTF("parallel port enabled - but no parallel port here\n");
}
set_volume(s);
}
/* This is used for headphone volume - not needed */
static void set_awacs_2_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 2 to 0x%x\n"
"Ignoring change in headphone volume.\n", s->awacs[2]);
s->awacs[2] = new_value;
}
/* Unknown register purpose */
static void set_awacs_3_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 3 to 0x%x\n"
"This register has an unknown purpose and does not do anything\n",
s->awacs[3]);
s->awacs[3] = new_value;
}
/* Mostly deals with speaker volume */
static void set_awacs_4_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("AWACS register 4 write: 0x%x\n", new_value);
s->awacs[4] = new_value;
set_volume(s);
}
/* This register is about loop thru stuff I don't understand */
static void set_awacs_5_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 5 to 0x%x\n"
"Loop thru update ignored.\n", s->awacs[5]);
s->awacs[5] = new_value;
}
/* Prints the states of the AWACS power register */
static void print_power_reg_values(uint32_t value)
{
if ((value & 0x3) == 0) {
printf("Screamer run state set\n");
}
if ((value & 0x3) == 1) {
printf("Screamer doze state set\n");
}
if ((value & 0x3) == 2) {
printf("Screamer idle state set\n");
}
}
/* Power Magement register */
static void set_awacs_6_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 6 to 0x%x\n"
"Power management update ignored.\n", s->awacs[6]);
if (DEBUG_SCREAMER) {
print_power_reg_values(new_value);
}
s->awacs[6] = new_value;
}
/* Read Back - repeating something that was sent to this chip? */
static void set_awacs_7_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 7 to 0x%x\n", new_value);
s->awacs[7] = new_value;
}
/* Sets the AWACs registers - a.k.a. shadow registers */
static void set_awacs_register(ScreamerState *s, uint32_t value)
{
int the_register = get_codec_control_address(value);
switch (the_register) {
case 0:
set_awacs_0_reg(s, value);
break;
case 1:
set_awacs_1_reg(s, value);
break;
case 2:
set_awacs_2_reg(s, value);
break;
case 3:
set_awacs_3_reg(s, value);
break;
case 4:
set_awacs_4_reg(s, value);
break;
case 5:
set_awacs_5_reg(s, value);
break;
case 6:
set_awacs_6_reg(s, value);
break;
case 7:
set_awacs_7_reg(s, value);
break;
default:
DPRINTF("Unhandled awacs registers %d\n", the_register);
}
}
/* Used to set the AWACS registers */
static void set_codec_control_reg(ScreamerState *s, uint32_t value)
{
DPRINTF("set_codec_control_reg() called - value: 0x%x\n", value);
s->codec_control = value;
set_awacs_register(s, value);
}
static void set_codec_status_reg(ScreamerState *s, uint32_t value)
{
DPRINTF("set_codec_status_reg() called - value: 0x%x\n", value);
s->codec_status = value;
}
static void set_clip_count_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("set_clip_count_reg() called - value: 0x%x\n", new_value);
s->clip_count = new_value;
}
static void set_byte_swap_reg(ScreamerState *s, uint32_t value)
{
DPRINTF("set_byte_swap_reg() called - value: 0x%x\n", value);
s->byte_swap = value;
}
static void set_frame_count_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("%s() called - value: 0x%x\n", __func__, new_value);
s->frame_count = new_value;
}
/*
* Sets the busy bit of codec control register.
* It is used to tell the CPU to wait.
* value: the codec control register's value
* bit_value: used to set or disable the busy bit
*/
static uint32_t set_busy_bit(uint32_t value, int bit_value)
{
const int busy_bit = 0x01000000;
uint32_t return_value;
if (bit_value == 1) /* Set this bit */
return_value = (value | busy_bit);
else /* bit_value == 0 Disable this bit */
return_value = (value & ~busy_bit);
return return_value;
}
/*
* Sets the part ready bit of the codec status register
* value: the codec status register's value
* bit_value: used to set or disable the part ready bit
*/
static uint32_t set_part_ready_bit(uint32_t value, int bit_value)
{
const int part_ready_bit = 0x00400000;
uint32_t return_value;
if (bit_value == 1) /* Set this bit */
return_value = (value | part_ready_bit);
else /* bit_value == 0 Disable this bit */
return_value = (value & ~part_ready_bit);
return return_value;
}
/* Sets bits 12 and 13 to 1 to indicate the Screamer revision */
static uint32_t set_revision(uint32_t input_value)
{
uint32_t return_value;
return_value = input_value | 0x3000;
return return_value;
}
/* Sets bit 8 to indicate Crystal as the manufacturer */
static uint32_t set_manufacturer(uint32_t input_value)
{
uint32_t return_value;
return_value = input_value | 0x100;
return return_value;
}
/************************** End of Setters *********************************/
/*************************** DMA functions *********************************/
/*
* Sends audio samples from a microphone or line-in to memory.
* Used for sound input.
* Currently only prevents a deadlock condition with Mac OS 9.
*/
static void screamer_to_dma(DBDMA_io *io)
{
DPRINTF("%s() called\n", __func__);
ScreamerState *s = (ScreamerState *)io->opaque;
DBDMAState *dbs = s->dbdma;
DBDMA_channel *ch = &dbs->channels[0x12];
ch->regs[DBDMA_STATUS] |= DEAD;
ch->regs[DBDMA_STATUS] &= ~ACTIVE;
io->dma_end(io);
return;
}
static void print_dma_info(DBDMA_io *io)
{
#define RUN 0x8000
#define PAUSE 0x4000
#define FLUSH 0x2000
#define WAKE 0x1000
#define DEAD 0x0800
#define ACTIVE 0x0400
#define BT 0x0100
#define DEVSTAT 0x00ff
/*
* RUN and PAUSE are bits under software control only.
* FLUSH and WAKE are set by SW and cleared by hardware.
* DEAD, ACTIVE and BT are only under hardware control.
*/
DBDMA_channel *ch = io->channel;
printf("DMA FLAGS: ");
if (ch->regs[DBDMA_STATUS] & RUN) {
printf("RUN ");
}
if (ch->regs[DBDMA_STATUS] & ACTIVE) {
printf("ACTIVE ");
}
if (ch->regs[DBDMA_STATUS] & PAUSE) {
printf("PAUSE ");
}
if (ch->regs[DBDMA_STATUS] & DEAD) {
printf("DEAD ");
}
if (ch->regs[DBDMA_STATUS] & WAKE) {
printf("WAKE ");
}
if (ch->regs[DBDMA_STATUS] & BT) {
printf("BT ");
}
if (ch->regs[DBDMA_STATUS] & DEVSTAT) {
printf("DEVSTAT ");
}
if (ch->regs[DBDMA_STATUS] & FLUSH) {
printf("FLUSH ");
}
if (ch->io.processing == true) {
printf("processing ");
}
printf("\n");
}
/* Tell the DMA controller we request more samples */
static void dma_request(DBDMA_io *io)
{
DPRINTF("%s() called\n", __func__);
if (DEBUG_SCREAMER) {
print_dma_info(io);
}
io->len = 0;
io->dma_end(io);
}
/* Adds sample data to the buffer */
static void add_to_speaker_buffer(DBDMA_io *io)
{
ScreamerState *s = (ScreamerState *) io->opaque;
if (s->spk_buffer_position + io->len > MAX_BUFFER_SIZE) {
/* postpone calling these samples until the buffer has been emptied */
memcpy(&s->dma_io, io, sizeof(DBDMA_io));
return;
}
dma_memory_read(&address_space_memory, io->addr,
&s->spk_buffer[s->spk_buffer_position], io->len,
MEMTXATTRS_UNSPECIFIED);
s->spk_buffer_position += io->len;
DPRINTF("%s() called - len: %d pos: %d/%d\n", __func__, io->len,
s->spk_buffer_position, MAX_BUFFER_SIZE);
dma_request(io);
}
/*
* Called by the DMA chip to transfer samples from memory to the
* Screamer chip.
* Used for sound output.
*/
static void dma_to_screamer(DBDMA_io *io)
{
add_to_speaker_buffer(io);
}
/*
* This will flush the audio buffer of previous audio - eliminating previous
* audio playback.
*/
static void send_silence_to_speaker(ScreamerState *s)
{
DPRINTF("Silencing audio buffer...\n");
int length = MAX_BUFFER_SIZE;
s->spk_buffer_position = length;
s->spk_play_position = 0;
memset(s->spk_buffer, 0, length);
s->dma_io.len = 0; /* stop any postponed samples from playing */
}
/* This is called after audio stops playing */
static void dma_send_flush(DBDMA_io *io)
{
DPRINTF("dma_send_flush() called\n");
if (DEBUG_SCREAMER) {
print_dma_info(io);
}
ScreamerState *s = (ScreamerState *)io->opaque;
reset_markers(s);
send_silence_to_speaker(s);
if (io->len > 0) {
dma_request(io);
}
}
static void dma_receive_flush(DBDMA_io *io)
{
DPRINTF("dma_receive_flush() called\n");
}
/* Set the functions the DMA system will call */
void screamer_register_dma_functions(ScreamerState *s, void *dbdma,
int send_channel, int receive_channel)
{
DPRINTF("%s() called\n", __func__);
DPRINTF("send channel: %d\treceive channel: %d\n", send_channel,
receive_channel);
s->dbdma = dbdma;
/* Setup the DMA send system */
DBDMA_register_channel(s->dbdma, send_channel, s->dma_send_irq,
dma_to_screamer, dma_send_flush, s);
/* Setup the DMA receive system */
DBDMA_register_channel(s->dbdma, receive_channel, s->dma_receive_irq,
screamer_to_dma, dma_receive_flush, s);
}
/************************* End of DMA functions **************************/
/* Resets this sound chip */
static void screamer_reset(DeviceState *d)
{
DPRINTF("screamer_reset() called\n");
ScreamerState *s = SCREAMER(d);
set_sound_control_reg(s, 0);
set_codec_control_reg(s, 0);
set_codec_status_reg(s, 0);
set_clip_count_reg(s, 0);
set_byte_swap_reg(s, 0);
set_frame_count_reg(s, 0);
int i, num_awacs_regs = 8;
for (i = 0; i < num_awacs_regs; i++) {
s->awacs[i] = 0;
}
set_QEMU_audio_settings(s);
reset_markers(s);
s->dma_io.len = 0;
}
/* Called when the CPU reads the memory addresses assigned to Screamer */
static uint64_t screamer_mmio_read(void *opaque, hwaddr addr, unsigned size)
{
ScreamerState *state = opaque;
uint32_t return_value;
addr = addr >> 4;
switch (addr) {
case SOUND_CONTROL_REG:
return_value = get_sound_control_reg(state);
break;
case CODEC_CONTROL_REG:
return_value = get_codec_control_reg(state);
break;
case CODEC_STATUS_REG:
return_value = get_codec_status_reg(state);
break;
case CLIP_COUNT_REG:
return_value = get_clip_count_reg(state);
break;
case BYTE_SWAP_REG:
return_value = get_byte_swap_reg(state);
break;
case FRAME_COUNT_REG:
return_value = get_frame_count_reg(state);
break;
default:
DPRINTF("Unknown register read - addr:%" HWADDR_PRIx "\tsize:%d\n",
addr, size);
return_value = 12021981; /* Value used for debugging purposes */
}
DPRINTF("screamer_mmio_read() called addr: %" HWADDR_PRIx " size: %d",
addr >> 4, size);
DPRINTF(" returning 0x%x\n", return_value);
return return_value;
}
/* Called when the CPU writes to the memory addresses assigned to Screamer */
static void screamer_mmio_write(void *opaque, hwaddr addr, uint64_t raw_value,
unsigned size)
{
DPRINTF("screamer_mmio_write() called - size: %d\n", size);
ScreamerState *state = opaque;
uint32_t value = raw_value & 0xffffffff;
addr = addr >> 4;
switch (addr) {
case SOUND_CONTROL_REG:
set_sound_control_reg(state, value);
break;
case CODEC_CONTROL_REG:
set_codec_control_reg(state, value);
break;
case CODEC_STATUS_REG:
set_codec_status_reg(state, value);
break;
case CLIP_COUNT_REG:
set_clip_count_reg(state, value);
break;
case BYTE_SWAP_REG:
set_byte_swap_reg(state, value);
break;
case FRAME_COUNT_REG:
set_frame_count_reg(state, value);
break;
default:
DPRINTF("Unknown register write - addr:%" HWADDR_PRIx "\tvalue:%d\n",
addr, value);
}
}
/* Used for memory_region_init_io() for memory mapped I/O */
static const MemoryRegionOps screamer_ops = {
.read = screamer_mmio_read,
.write = screamer_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4,
.max_access_size = 4
}
};
/* Called when the device has become active */
static void screamer_realize(DeviceState *dev, Error **errp)
{
DPRINTF("screamer_realize() called\n");
screamer_reset(dev);
}
/*
* Called when an instance of the Screamer device is created.
* Also called when this HMP command is called: device_add screamer
*/
static void screamer_init(Object *obj)
{
DPRINTF("screamer_init() called\n");
ScreamerState *s = (ScreamerState *)obj;
SysBusDevice *d = SYS_BUS_DEVICE(obj);
const int region_size = 5 * 32;
/* Makes the read and write ops work */
memory_region_init_io(&s->io_memory_region, OBJECT(s),
&screamer_ops, s, SOUND_CHIP_NAME, region_size);
/* Sets the SysBusDevice's memory property */
sysbus_init_mmio(d, &s->io_memory_region);
/* Setup all the interrupt requests */
sysbus_init_irq(d, &s->irq);
sysbus_init_irq(d, &s->dma_send_irq);
sysbus_init_irq(d, &s->dma_receive_irq);
/* Registers Screamer with QEMU's audio system */
AUD_register_card(SOUND_CHIP_NAME, &s->card);
}
/*
* When saving and restoring the state of the VM, this is used to save and
* restore the registers.
*/
static const VMStateDescription vmstate_screamer = {
.name = "Screamer",
.version_id = 1,
.minimum_version_id = 1,
.fields = (VMStateField[]) {
VMSTATE_UINT16_ARRAY(awacs, ScreamerState, 8), /* 8 AWACS registers */
VMSTATE_UINT32(sound_control, ScreamerState),
VMSTATE_UINT32(codec_control, ScreamerState),
VMSTATE_UINT32(codec_status, ScreamerState),
VMSTATE_UINT32(clip_count, ScreamerState),
VMSTATE_UINT32(byte_swap, ScreamerState),
VMSTATE_UINT32(frame_count, ScreamerState),
VMSTATE_END_OF_LIST()
}
};
/*
* Sets the class data. It is like polymorphism and inheritance in object
* oriented languages.
*/
static void screamer_class_init(ObjectClass *class, void *data)
{
DPRINTF("screamer_class_init() called\n");
DeviceClass *dc = DEVICE_CLASS(class);
dc->realize = screamer_realize;
dc->reset = screamer_reset;
dc->desc = "Apple Screamer";
dc->vmsd = &vmstate_screamer;
dc->hotpluggable = false;
}
/* Used for QOM function registration */
static const TypeInfo screamer_info = {
.name = "screamer",
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(ScreamerState),
.instance_init = screamer_init,
.class_init = screamer_class_init,
};
/* QOM registration of above functions for calling */
static void screamer_register_types(void)
{
DPRINTF("screamer_register_types() called\n");
type_register_static(&screamer_info);
}
/* QEMU Object Model (QOM) stuff */
type_init(screamer_register_types)
+3
View File
@@ -42,6 +42,9 @@
GlobalProperty hw_compat_7_1[] = {
{ "virtio-device", "queue_reset", "false" },
{ "virtio-rng-pci", "vectors", "0" },
{ "virtio-rng-pci-transitional", "vectors", "0" },
{ "virtio-rng-pci-non-transitional", "vectors", "0" },
};
const size_t hw_compat_7_1_len = G_N_ELEMENTS(hw_compat_7_1);
-10
View File
@@ -79,16 +79,6 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU')
hw_display_modules += {'virtio-gpu-gl': virtio_gpu_gl_ss}
endif
if config_all_devices.has_key('CONFIG_FW_CFG_DMA')
virtio_ramfb_ss = ss.source_set()
virtio_ramfb_ss.add(when: 'CONFIG_FW_CFG_DMA', if_true: files('virtio-ramfb.c'))
hw_display_modules += {'virtio-ramfb': virtio_ramfb_ss}
virtio_ramfb_gl_ss = ss.source_set()
virtio_ramfb_gl_ss.add(when: ['CONFIG_FW_CFG_DMA', virgl, opengl],
if_true: files('virtio-ramfb-gl.c'))
hw_display_modules += {'virtio-ramfb-gl': virtio_ramfb_gl_ss}
endif
if config_all_devices.has_key('CONFIG_VIRTIO_PCI')
virtio_gpu_pci_ss = ss.source_set()
virtio_gpu_pci_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PCI'],
+1 -2
View File
@@ -165,8 +165,7 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
return false;
}
if (virtio_gpu_virgl_enabled(g->conf) &&
!virtio_gpu_goldfish_pipe_enabled(g->conf)) {
if (virtio_gpu_virgl_enabled(g->conf)) {
error_setg(&g->migration_blocker, "virgl is not yet migratable");
if (migrate_add_blocker(g->migration_blocker, errp) < 0) {
error_free(g->migration_blocker);
+2 -58
View File
@@ -18,25 +18,21 @@
#include "qapi/error.h"
#include "sysemu/sysemu.h"
#include "hw/virtio/virtio.h"
#ifdef CONFIG_ANDROID
#include "hw/virtio/virtio-goldfish-pipe.h"
#endif
#include "hw/virtio/virtio-gpu.h"
#include "hw/virtio/virtio-gpu-bswap.h"
#include "hw/virtio/virtio-gpu-pixman.h"
#include "hw/qdev-properties.h"
#include "hw/virtio/virtio-gpu-virgl.h"
#include <virglrenderer.h>
static void virtio_gpu_gl_update_cursor_data(VirtIOGPU *g,
struct virtio_gpu_scanout *s,
uint32_t resource_id)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
uint32_t width, height;
uint32_t pixels, *data;
data = gl->virgl->virgl_renderer_get_cursor_data(resource_id, &width, &height);
data = virgl_renderer_get_cursor_data(resource_id, &width, &height);
if (!data) {
return;
}
@@ -108,46 +104,9 @@ static void virtio_gpu_gl_reset(VirtIODevice *vdev)
}
}
static int virtio_gpu_gl_save(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field, JSONWriter *vmdesc)
{
VirtIOGPU *g = opaque;
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
if (gl->virgl->virgl_renderer_save_snapshot) {
// First save the renderer state, then the ram slots, because when we
// load, the renderer state and host pointers backing blob resources
// need to be restored first before the ram slots corresponding to the
// blob resources themselves.
gl->virgl->virgl_renderer_save_snapshot(f);
#ifdef CONFIG_ANDROID
virtio_gpu_save_ram_slots(f, g);
#endif
}
return virtio_gpu_save(f, opaque, size, field, vmdesc);
}
static int virtio_gpu_gl_load(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field)
{
VirtIOGPU *g = opaque;
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
if (gl->virgl->virgl_renderer_load_snapshot) {
gl->virgl->virgl_renderer_load_snapshot(f);
#ifdef CONFIG_ANDROID
virtio_gpu_load_ram_slots(f, g);
#endif
}
return virtio_gpu_load(f, opaque, size, field);
}
static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
{
VirtIOGPU *g = VIRTIO_GPU(qdev);
VirtIOGPUGL *gl = VIRTIO_GPU_GL(qdev);
#if HOST_BIG_ENDIAN
error_setg(errp, "virgl is not supported on bigendian platforms");
@@ -164,15 +123,6 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
return;
}
#ifdef CONFIG_ANDROID
if (virtio_gpu_goldfish_pipe_enabled(g->parent_obj.conf)) {
gl->virgl = get_goldfish_pipe_virgl_renderer_virtio_interface();
} else
#endif
{
gl->virgl = get_default_virtio_interface();
}
g->parent_obj.conf.flags |= (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED);
VIRTIO_GPU_BASE(g)->virtio_config.num_capsets =
virtio_gpu_virgl_get_num_capsets(g);
@@ -183,10 +133,6 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
static Property virtio_gpu_gl_properties[] = {
DEFINE_PROP_BIT("stats", VirtIOGPU, parent_obj.conf.flags,
VIRTIO_GPU_FLAG_STATS_ENABLED, false),
#ifdef CONFIG_ANDROID
DEFINE_PROP_BIT("goldfish-pipe", VirtIOGPU, parent_obj.conf.flags,
VIRTIO_GPU_FLAG_GOLDFISH_PIPE_ENABLED, false),
#endif
DEFINE_PROP_END_OF_LIST(),
};
@@ -201,8 +147,6 @@ static void virtio_gpu_gl_class_init(ObjectClass *klass, void *data)
vgc->handle_ctrl = virtio_gpu_gl_handle_ctrl;
vgc->process_cmd = virtio_gpu_virgl_process_cmd;
vgc->update_cursor_data = virtio_gpu_gl_update_cursor_data;
vgc->gpu_save = virtio_gpu_gl_save;
vgc->gpu_load = virtio_gpu_gl_load;
vdc->realize = virtio_gpu_gl_device_realize;
vdc->reset = virtio_gpu_gl_reset;
-84
View File
@@ -20,7 +20,6 @@
#include "hw/virtio/virtio-bus.h"
#include "hw/virtio/virtio-gpu-pci.h"
#include "qom/object.h"
#include "standard-headers/linux/virtio_pci.h"
#define TYPE_VIRTIO_GPU_GL_PCI "virtio-gpu-gl-pci"
typedef struct VirtIOGPUGLPCI VirtIOGPUGLPCI;
@@ -32,88 +31,6 @@ struct VirtIOGPUGLPCI {
VirtIOGPUGL vdev;
};
static void virtio_gpu_pci_gl_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
{
VirtIOGPUGLPCI *vgpu = VIRTIO_GPU_GL_PCI(vpci_dev);
VirtIOGPUGL *gl = &vgpu->vdev;
VirtIOGPUBase *g = &gl->parent_obj.parent_obj;
DeviceState *vdev = DEVICE(&vgpu->vdev);
int i;
// Cool way to lay things out that should not affect stuff
// and is compat with the current android11-5.4 kernel:
// | 0 1 : modern | 2 msix | 4 5 hostshm |
//
// This is similar to the crosvm
// virtio gpu pci bar layout, same except maybe for different msix bar #.
vpci_dev->modern_mem_bar_idx = 0; // Overwritten: legacy io bar idx
vpci_dev->msix_bar_idx = 2;
// Not considered: modern io bar idx (only used in MODERN_PIO_NOTIFY,
// which doesn't seem to be used in virtio-gpu)
vpci_dev->hostshm_mem_bar_idx = 4;
// Note that in future versions of Linux kernels, the bar may be negotiated
// via some other mechanism based off the shm_cap logic below.
#define VIRTIO_GPU_PCI_HOST_COHERENT_BAR_SIZE (1ULL << 32ULL)
memory_region_init_ram_user_backed(
&gl->host_coherent_memory, OBJECT(gl),
"virtio-gpu-host-coherent",
VIRTIO_GPU_PCI_HOST_COHERENT_BAR_SIZE);
// Add shm cap to the guest
// (Doesn't seem to be used in 5.4, but is a way to be fwd compatible
// with newer kernels)
struct virtio_pci_cap64 shm_cap;
uint32_t mask32 = ~0;
shm_cap.cap.cap_len = sizeof(shm_cap);
shm_cap.cap.cfg_type = 8; // PciCapabilityType::SharedMemoryConfig
shm_cap.cap.bar = vpci_dev->hostshm_mem_bar_idx;
shm_cap.cap.length =
cpu_to_le32(mask32 & (int128_get64(gl->host_coherent_memory.size)));
shm_cap.length_hi =
cpu_to_le32(mask32 & (int128_get64(gl->host_coherent_memory.size) >> 32ULL));
shm_cap.cap.offset = mask32 & 0;
shm_cap.offset_hi = mask32 & 0;
#define VIRTIO_GPU_PCI_CAP_HOSTSHM_ID 1
shm_cap.cap.id = VIRTIO_GPU_PCI_CAP_HOSTSHM_ID;
pci_register_bar(&vpci_dev->pci_dev, vpci_dev->hostshm_mem_bar_idx,
PCI_BASE_ADDRESS_SPACE_MEMORY |
PCI_BASE_ADDRESS_MEM_TYPE_64, &gl->host_coherent_memory);
int offset = pci_add_capability(
&vpci_dev->pci_dev, PCI_CAP_ID_VNDR, 0,
shm_cap.cap.cap_len, &error_abort);
// Add the mem cap to virtio-gpu-pci proxy's configuration.
memcpy(vpci_dev->pci_dev.config + offset + PCI_CAP_FLAGS,
&shm_cap.cap.cap_len,
shm_cap.cap.cap_len - PCI_CAP_FLAGS);
virtio_pci_force_virtio_1(vpci_dev);
if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
return;
}
for (i = 0; i < g->conf.max_outputs; i++) {
object_property_set_link(OBJECT(g->scanout[i].con), "device",
OBJECT(vpci_dev), &error_abort);
}
}
static void virtio_gpu_pci_gl_class_init(ObjectClass *klass, void *data)
{
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
k->realize = virtio_gpu_pci_gl_realize;
}
static void virtio_gpu_gl_initfn(Object *obj)
{
VirtIOGPUGLPCI *dev = VIRTIO_GPU_GL_PCI(obj);
@@ -128,7 +45,6 @@ static const VirtioPCIDeviceTypeInfo virtio_gpu_gl_pci_info = {
.parent = TYPE_VIRTIO_GPU_PCI_BASE,
.instance_size = sizeof(VirtIOGPUGLPCI),
.instance_init = virtio_gpu_gl_initfn,
.class_init = virtio_gpu_pci_gl_class_init,
};
module_obj(TYPE_VIRTIO_GPU_GL_PCI);
module_kconfig(VIRTIO_PCI);
+72 -461
View File
@@ -16,17 +16,14 @@
#include "trace.h"
#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-gpu.h"
#include "exec/memory-remap.h"
#include "migration/qemu-file-types.h"
#include "hw/virtio/virtio-gpu-virgl.h"
#include <virglrenderer.h>
static struct virgl_renderer_callbacks virtio_gpu_3d_cbs;
static void virgl_cmd_create_resource_2d(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_resource_create_2d c2d;
struct virgl_renderer_resource_create_args args;
@@ -45,13 +42,12 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g,
args.last_level = 0;
args.nr_samples = 0;
args.flags = VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP;
gl->virgl->virgl_renderer_resource_create(&args, NULL, 0);
virgl_renderer_resource_create(&args, NULL, 0);
}
static void virgl_cmd_create_resource_3d(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_resource_create_3d c3d;
struct virgl_renderer_resource_create_args args;
@@ -70,13 +66,12 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g,
args.last_level = c3d.last_level;
args.nr_samples = c3d.nr_samples;
args.flags = c3d.flags;
gl->virgl->virgl_renderer_resource_create(&args, NULL, 0);
virgl_renderer_resource_create(&args, NULL, 0);
}
static void virgl_cmd_resource_unref(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_resource_unref unref;
struct iovec *res_iovs = NULL;
int num_iovs = 0;
@@ -84,39 +79,37 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g,
VIRTIO_GPU_FILL_CMD(unref);
trace_virtio_gpu_cmd_res_unref(unref.resource_id);
gl->virgl->virgl_renderer_resource_detach_iov(unref.resource_id,
virgl_renderer_resource_detach_iov(unref.resource_id,
&res_iovs,
&num_iovs);
if (res_iovs != NULL && num_iovs != 0) {
virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs);
}
gl->virgl->virgl_renderer_resource_unref(unref.resource_id);
virgl_renderer_resource_unref(unref.resource_id);
}
static void virgl_cmd_context_create(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_ctx_create cc;
VIRTIO_GPU_FILL_CMD(cc);
trace_virtio_gpu_cmd_ctx_create(cc.hdr.ctx_id,
cc.debug_name);
gl->virgl->virgl_renderer_context_create(cc.hdr.ctx_id, cc.nlen,
cc.debug_name);
virgl_renderer_context_create(cc.hdr.ctx_id, cc.nlen,
cc.debug_name);
}
static void virgl_cmd_context_destroy(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_ctx_destroy cd;
VIRTIO_GPU_FILL_CMD(cd);
trace_virtio_gpu_cmd_ctx_destroy(cd.hdr.ctx_id);
gl->virgl->virgl_renderer_context_destroy(cd.hdr.ctx_id);
virgl_renderer_context_destroy(cd.hdr.ctx_id);
}
static void virtio_gpu_rect_update(VirtIOGPU *g, int idx, int x, int y,
@@ -126,9 +119,7 @@ static void virtio_gpu_rect_update(VirtIOGPU *g, int idx, int x, int y,
return;
}
if (!virtio_gpu_goldfish_pipe_enabled(g->parent_obj.conf)) {
dpy_gl_update(g->parent_obj.scanout[idx].con, x, y, width, height);
}
dpy_gl_update(g->parent_obj.scanout[idx].con, x, y, width, height);
}
static void virgl_cmd_resource_flush(VirtIOGPU *g,
@@ -146,50 +137,15 @@ static void virgl_cmd_resource_flush(VirtIOGPU *g,
continue;
}
virtio_gpu_rect_update(g, i, rf.r.x, rf.r.y, rf.r.width, rf.r.height);
#ifdef CONFIG_ANDROID
if (i == 0 && virtio_gpu_goldfish_pipe_enabled(g->parent_obj.conf)) {
stream_renderer_flush_resource_and_readback(rf.resource_id, rf.r.x, rf.r.y,
rf.r.width, rf.r.height,
NULL, 0);
}
#endif
}
}
static GLuint virgl_borrow_texture_for_scanout(uint32_t id, bool *y_0_top,
uint32_t *width,
uint32_t *height)
{
struct virgl_renderer_texture_info info;
int ret;
memset(&info, 0, sizeof(info));
ret = virgl_renderer_borrow_texture_for_scanout(id, &info);
if (ret == -1) {
return 0;
}
if (y_0_top) {
*y_0_top = info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP;
}
if (width) {
*width = info.width;
}
if (height) {
*height = info.height;
}
return info.tex_id;
}
static void virgl_cmd_set_scanout(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_set_scanout ss;
struct virgl_renderer_resource_info info;
int ret;
VIRTIO_GPU_FILL_CMD(ss);
trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id,
@@ -203,17 +159,26 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
}
g->parent_obj.enable = 1;
memset(&info, 0, sizeof(info));
if (ss.resource_id && ss.r.width && ss.r.height) {
ret = virgl_renderer_resource_get_info(ss.resource_id, &info);
if (ret == -1) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: illegal resource specified %d\n",
__func__, ss.resource_id);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
return;
}
qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con,
ss.r.width, ss.r.height);
gl->virgl->virgl_renderer_force_ctx_0();
if (!virtio_gpu_goldfish_pipe_enabled(g->parent_obj.conf)) {
dpy_gl_scanout_texture(
g->parent_obj.scanout[ss.scanout_id].con, ss.resource_id,
virgl_borrow_texture_for_scanout,
ss.r.x, ss.r.y, ss.r.width, ss.r.height);
}
} else if (!virtio_gpu_goldfish_pipe_enabled(g->parent_obj.conf)) {
virgl_renderer_force_ctx_0();
dpy_gl_scanout_texture(
g->parent_obj.scanout[ss.scanout_id].con, info.tex_id,
info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP,
info.width, info.height,
ss.r.x, ss.r.y, ss.r.width, ss.r.height);
} else {
dpy_gfx_replace_surface(
g->parent_obj.scanout[ss.scanout_id].con, NULL);
dpy_gl_scanout_disable(g->parent_obj.scanout[ss.scanout_id].con);
@@ -224,7 +189,6 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
static void virgl_cmd_submit_3d(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_cmd_submit cs;
void *buf;
size_t s;
@@ -247,7 +211,7 @@ static void virgl_cmd_submit_3d(VirtIOGPU *g,
g->stats.bytes_3d += cs.size;
}
gl->virgl->virgl_renderer_submit_cmd(buf, cs.hdr.ctx_id, cs.size / 4);
virgl_renderer_submit_cmd(buf, cs.hdr.ctx_id, cs.size / 4);
out:
g_free(buf);
@@ -256,7 +220,6 @@ out:
static void virgl_cmd_transfer_to_host_2d(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_transfer_to_host_2d t2d;
struct virtio_gpu_box box;
@@ -270,75 +233,71 @@ static void virgl_cmd_transfer_to_host_2d(VirtIOGPU *g,
box.h = t2d.r.height;
box.d = 1;
gl->virgl->virgl_renderer_transfer_write_iov(t2d.resource_id,
0,
0,
0,
0,
(struct virgl_box *)&box,
t2d.offset, NULL, 0);
virgl_renderer_transfer_write_iov(t2d.resource_id,
0,
0,
0,
0,
(struct virgl_box *)&box,
t2d.offset, NULL, 0);
}
static void virgl_cmd_transfer_to_host_3d(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_transfer_host_3d t3d;
VIRTIO_GPU_FILL_CMD(t3d);
trace_virtio_gpu_cmd_res_xfer_toh_3d(t3d.resource_id);
gl->virgl->virgl_renderer_transfer_write_iov(t3d.resource_id,
t3d.hdr.ctx_id,
t3d.level,
t3d.stride,
t3d.layer_stride,
(struct virgl_box *)&t3d.box,
t3d.offset, NULL, 0);
virgl_renderer_transfer_write_iov(t3d.resource_id,
t3d.hdr.ctx_id,
t3d.level,
t3d.stride,
t3d.layer_stride,
(struct virgl_box *)&t3d.box,
t3d.offset, NULL, 0);
}
static void
virgl_cmd_transfer_from_host_3d(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_transfer_host_3d tf3d;
VIRTIO_GPU_FILL_CMD(tf3d);
trace_virtio_gpu_cmd_res_xfer_fromh_3d(tf3d.resource_id);
gl->virgl->virgl_renderer_transfer_read_iov(tf3d.resource_id,
tf3d.hdr.ctx_id,
tf3d.level,
tf3d.stride,
tf3d.layer_stride,
(struct virgl_box *)&tf3d.box,
tf3d.offset, NULL, 0);
virgl_renderer_transfer_read_iov(tf3d.resource_id,
tf3d.hdr.ctx_id,
tf3d.level,
tf3d.stride,
tf3d.layer_stride,
(struct virgl_box *)&tf3d.box,
tf3d.offset, NULL, 0);
}
static void virgl_resource_attach_backing(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_resource_attach_backing att_rb;
struct iovec *res_iovs;
uint32_t res_niov;
int ret;
uint64_t* addrs;
VIRTIO_GPU_FILL_CMD(att_rb);
trace_virtio_gpu_cmd_res_back_attach(att_rb.resource_id);
ret = virtio_gpu_create_mapping_iov(g, att_rb.nr_entries, sizeof(att_rb),
cmd, &addrs, &res_iovs, &res_niov);
cmd, NULL, &res_iovs, &res_niov);
if (ret != 0) {
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
return;
}
ret = gl->virgl->virgl_renderer_resource_attach_iov_with_addrs(att_rb.resource_id,
res_iovs, res_niov, addrs);
ret = virgl_renderer_resource_attach_iov(att_rb.resource_id,
res_iovs, res_niov);
if (ret != 0)
virtio_gpu_cleanup_mapping_iov(g, res_iovs, res_niov);
@@ -347,7 +306,6 @@ static void virgl_resource_attach_backing(VirtIOGPU *g,
static void virgl_resource_detach_backing(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_resource_detach_backing detach_rb;
struct iovec *res_iovs = NULL;
int num_iovs = 0;
@@ -355,9 +313,9 @@ static void virgl_resource_detach_backing(VirtIOGPU *g,
VIRTIO_GPU_FILL_CMD(detach_rb);
trace_virtio_gpu_cmd_res_back_detach(detach_rb.resource_id);
gl->virgl->virgl_renderer_resource_detach_iov(detach_rb.resource_id,
&res_iovs,
&num_iovs);
virgl_renderer_resource_detach_iov(detach_rb.resource_id,
&res_iovs,
&num_iovs);
if (res_iovs == NULL || num_iovs == 0) {
return;
}
@@ -368,33 +326,30 @@ static void virgl_resource_detach_backing(VirtIOGPU *g,
static void virgl_cmd_ctx_attach_resource(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_ctx_resource att_res;
VIRTIO_GPU_FILL_CMD(att_res);
trace_virtio_gpu_cmd_ctx_res_attach(att_res.hdr.ctx_id,
att_res.resource_id);
gl->virgl->virgl_renderer_ctx_attach_resource(att_res.hdr.ctx_id, att_res.resource_id);
virgl_renderer_ctx_attach_resource(att_res.hdr.ctx_id, att_res.resource_id);
}
static void virgl_cmd_ctx_detach_resource(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_ctx_resource det_res;
VIRTIO_GPU_FILL_CMD(det_res);
trace_virtio_gpu_cmd_ctx_res_detach(det_res.hdr.ctx_id,
det_res.resource_id);
gl->virgl->virgl_renderer_ctx_detach_resource(det_res.hdr.ctx_id, det_res.resource_id);
virgl_renderer_ctx_detach_resource(det_res.hdr.ctx_id, det_res.resource_id);
}
static void virgl_cmd_get_capset_info(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_get_capset_info info;
struct virtio_gpu_resp_capset_info resp;
@@ -403,14 +358,14 @@ static void virgl_cmd_get_capset_info(VirtIOGPU *g,
memset(&resp, 0, sizeof(resp));
if (info.capset_index == 0) {
resp.capset_id = VIRTIO_GPU_CAPSET_VIRGL;
gl->virgl->virgl_renderer_get_cap_set(resp.capset_id,
&resp.capset_max_version,
&resp.capset_max_size);
virgl_renderer_get_cap_set(resp.capset_id,
&resp.capset_max_version,
&resp.capset_max_size);
} else if (info.capset_index == 1) {
resp.capset_id = VIRTIO_GPU_CAPSET_VIRGL2;
gl->virgl->virgl_renderer_get_cap_set(resp.capset_id,
&resp.capset_max_version,
&resp.capset_max_size);
virgl_renderer_get_cap_set(resp.capset_id,
&resp.capset_max_version,
&resp.capset_max_size);
} else {
resp.capset_max_version = 0;
resp.capset_max_size = 0;
@@ -422,13 +377,12 @@ static void virgl_cmd_get_capset_info(VirtIOGPU *g,
static void virgl_cmd_get_capset(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_get_capset gc;
struct virtio_gpu_resp_capset *resp;
uint32_t max_ver, max_size;
VIRTIO_GPU_FILL_CMD(gc);
gl->virgl->virgl_renderer_get_cap_set(gc.capset_id, &max_ver,
virgl_renderer_get_cap_set(gc.capset_id, &max_ver,
&max_size);
if (!max_size) {
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
@@ -437,183 +391,19 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,
resp = g_malloc0(sizeof(*resp) + max_size);
resp->hdr.type = VIRTIO_GPU_RESP_OK_CAPSET;
gl->virgl->virgl_renderer_fill_caps(gc.capset_id,
gc.capset_version,
(void *)resp->capset_data);
virgl_renderer_fill_caps(gc.capset_id,
gc.capset_version,
(void *)resp->capset_data);
virtio_gpu_ctrl_response(g, cmd, &resp->hdr, sizeof(*resp) + max_size);
g_free(resp);
}
#ifdef CONFIG_ANDROID
static void virgl_cmd_resource_create_blob(VirtIOGPU *g,
struct virtio_gpu_ctrl_command* cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_resource_create_blob cb;
VIRTIO_GPU_FILL_CMD(cb);
if (!gl->virgl->virgl_renderer_resource_create_v2) {
fprintf(stderr, "%s: not supported\n", __func__);
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
return;
}
gl->virgl->virgl_renderer_resource_create_v2(
cb.resource_id,
cb.blob_id);
}
#define VIRTIO_GPU_MAX_RAM_SLOTS 2048
struct VirtioGpuRamSlotInfo {
int used;
uint64_t gpa;
uint64_t offset;
uint64_t size;
uint32_t resource_id;
};
struct VirtioGpuRamSlotTable {
struct VirtioGpuRamSlotInfo slots[VIRTIO_GPU_MAX_RAM_SLOTS];
};
static struct VirtioGpuRamSlotTable* virtio_gpu_ram_slot_table_get(void) {
static struct VirtioGpuRamSlotTable* s_table;
if (!s_table) {
struct VirtioGpuRamSlotTable* table =
(struct VirtioGpuRamSlotTable*)malloc(sizeof(*table));
memset(table, 0, sizeof(*table));
s_table = table;
}
return s_table;
}
static int virtio_gpu_ram_slot_infos_first_free_slot() {
struct VirtioGpuRamSlotTable* table = virtio_gpu_ram_slot_table_get();
for (int i = 0; i < VIRTIO_GPU_MAX_RAM_SLOTS; ++i) {
if (0 == table->slots[i].used) return i;
}
return -1;
}
static void virtio_gpu_map_slot(
MemoryRegion* parent, uint32_t resource_id,
uint64_t gpa, uint64_t offset, void *hva, uint64_t size, int flags) {
struct VirtioGpuRamSlotTable* table = virtio_gpu_ram_slot_table_get();
int slot = virtio_gpu_ram_slot_infos_first_free_slot();
if (slot < 0) {
fprintf(stderr, "%s: error: no free slots to "
"map hva %p -> gpa [0x%llx 0x%llx)\n", __func__,
hva, (unsigned long long)gpa, (unsigned long long)gpa + size);
return;
}
qemu_user_backed_ram_map(gpa, hva, size, USER_BACKED_RAM_FLAGS_READ | USER_BACKED_RAM_FLAGS_WRITE);
table->slots[slot].gpa = gpa;
table->slots[slot].offset = offset;
table->slots[slot].size = size;
table->slots[slot].used = 1;
table->slots[slot].resource_id = resource_id;
}
static void virtio_gpu_unmap_slot(
MemoryRegion* parent, uint32_t resource_id) {
struct VirtioGpuRamSlotTable* table = virtio_gpu_ram_slot_table_get();
for (int i = 0; i < VIRTIO_GPU_MAX_RAM_SLOTS; ++i) {
if (0 == table->slots[i].used) continue;
if (resource_id != table->slots[i].resource_id) continue;
qemu_user_backed_ram_unmap(table->slots[i].gpa, table->slots[i].size);
table->slots[i].used = 0;
return;
}
}
static void virgl_cmd_resource_map(VirtIOGPU *g,
struct virtio_gpu_ctrl_command* cmd) {
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_resource_map_blob m;
struct virtio_gpu_resp_map_info resp;
VIRTIO_GPU_FILL_CMD(m);
void* hva;
uint64_t size;
uint64_t offset = m.offset;
if (!gl->virgl->virgl_renderer_resource_map) {
fprintf(stderr, "%s: not supported\n", __func__);
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
return;
}
gl->virgl->virgl_renderer_resource_map(m.resource_id, &hva, &size);
if (!hva || !size) {
fprintf(stderr, "%s: failed for resource %u\n", __func__, m.resource_id);
cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY;
return;
}
uint64_t host_coherent_start =
object_property_get_uint(OBJECT(&gl->host_coherent_memory), "addr", NULL);
uint64_t phys_addr =
host_coherent_start + offset;
virtio_gpu_map_slot(
&gl->host_coherent_memory,
m.resource_id,
phys_addr,
offset,
hva,
size,
0xff /* flags, unused */);
memset(&resp, 0, sizeof(resp));
resp.hdr.type = VIRTIO_GPU_RESP_OK_MAP_INFO;
resp.map_info = 0x3;
resp.padding = 0;
virtio_gpu_ctrl_response(g, cmd, &resp.hdr, sizeof(resp));
}
static void virgl_cmd_resource_unmap(VirtIOGPU *g,
struct virtio_gpu_ctrl_command* cmd) {
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
struct virtio_gpu_resource_unmap_blob u;
VIRTIO_GPU_FILL_CMD(u);
if (!gl->virgl->virgl_renderer_resource_unmap) {
fprintf(stderr, "%s: not supported\n", __func__);
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
return;
}
virtio_gpu_unmap_slot(
&gl->host_coherent_memory,
u.resource_id);
gl->virgl->virgl_renderer_resource_unmap(u.resource_id);
}
#endif /* CONFIG_ANDROID */
void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
VIRTIO_GPU_FILL_CMD(cmd->cmd_hdr);
gl->virgl->virgl_renderer_force_ctx_0();
virgl_renderer_force_ctx_0();
switch (cmd->cmd_hdr.type) {
case VIRTIO_GPU_CMD_CTX_CREATE:
virgl_cmd_context_create(g, cmd);
@@ -674,17 +464,6 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
case VIRTIO_GPU_CMD_GET_EDID:
virtio_gpu_get_edid(g, cmd);
break;
#ifdef CONFIG_ANDROID
case VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB:
virgl_cmd_resource_create_blob(g, cmd);
break;
case VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB:
virgl_cmd_resource_map(g, cmd);
break;
case VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB:
virgl_cmd_resource_unmap(g, cmd);
break;
#endif /* CONFIG_ANDROID */
default:
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
break;
@@ -705,7 +484,7 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
}
trace_virtio_gpu_fence_ctrl(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type);
gl->virgl->virgl_renderer_create_fence(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type);
virgl_renderer_create_fence(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type);
}
static void virgl_write_fence(void *opaque, uint32_t fence)
@@ -743,12 +522,6 @@ virgl_create_context(void *opaque, int scanout_idx,
qparams.major_ver = params->major_ver;
qparams.minor_ver = params->minor_ver;
if (virtio_gpu_goldfish_pipe_enabled(g->parent_obj.conf)) {
fprintf(stderr, "%s: error: tried to use "
"standard 3d cbs in proxy mode\n", __func__);
abort();
}
ctx = dpy_gl_ctx_create(g->parent_obj.scanout[scanout_idx].con, &qparams);
return (virgl_renderer_gl_context)ctx;
}
@@ -758,12 +531,6 @@ static void virgl_destroy_context(void *opaque, virgl_renderer_gl_context ctx)
VirtIOGPU *g = opaque;
QEMUGLContext qctx = (QEMUGLContext)ctx;
if (virtio_gpu_goldfish_pipe_enabled(g->parent_obj.conf)) {
fprintf(stderr, "%s: error: tried to use "
"standard 3d cbs in proxy mode\n", __func__);
abort();
}
dpy_gl_ctx_destroy(g->parent_obj.scanout[0].con, qctx);
}
@@ -773,12 +540,6 @@ static int virgl_make_context_current(void *opaque, int scanout_idx,
VirtIOGPU *g = opaque;
QEMUGLContext qctx = (QEMUGLContext)ctx;
if (virtio_gpu_goldfish_pipe_enabled(g->parent_obj.conf)) {
fprintf(stderr, "%s: error: tried to use "
"standard 3d cbs in proxy mode\n", __func__);
abort();
}
return dpy_gl_ctx_make_current(g->parent_obj.scanout[scanout_idx].con,
qctx);
}
@@ -814,9 +575,8 @@ static void virtio_gpu_print_stats(void *opaque)
static void virtio_gpu_fence_poll(void *opaque)
{
VirtIOGPU *g = opaque;
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
gl->virgl->virgl_renderer_poll();
virgl_renderer_poll();
virtio_gpu_process_cmdq(g);
if (!QTAILQ_EMPTY(&g->cmdq) || !QTAILQ_EMPTY(&g->fenceq)) {
timer_mod(g->fence_poll, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 10);
@@ -832,10 +592,6 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)
{
int i;
if (virtio_gpu_goldfish_pipe_enabled(g->parent_obj.conf)) {
return;
}
for (i = 0; i < g->parent_obj.conf.max_outputs; i++) {
dpy_gfx_replace_surface(g->parent_obj.scanout[i].con, NULL);
dpy_gl_scanout_disable(g->parent_obj.scanout[i].con);
@@ -847,22 +603,11 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g)
virgl_renderer_reset();
}
#ifdef CONFIG_ANDROID
static struct virgl_renderer_callbacks proxy_3d_cbs;
#endif
int virtio_gpu_virgl_init(VirtIOGPU *g)
{
int ret;
#ifdef CONFIG_ANDROID
if (virtio_gpu_goldfish_pipe_enabled(g->parent_obj.conf)) {
ret = virgl_renderer_init(g, 0, &proxy_3d_cbs);
} else
#endif
{
ret = virgl_renderer_init(g, 0, &virtio_gpu_3d_cbs);
}
ret = virgl_renderer_init(g, 0, &virtio_gpu_3d_cbs);
if (ret != 0) {
error_report("virgl could not be initialized: %d", ret);
return ret;
@@ -888,137 +633,3 @@ int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g)
return capset2_max_ver ? 2 : 1;
}
#ifdef CONFIG_ANDROID
void virtio_gpu_save_ram_slots(void* qemufile, VirtIOGPU* g) {
struct VirtioGpuRamSlotTable* table = virtio_gpu_ram_slot_table_get();
QEMUFile* file = (QEMUFile*)qemufile;
qemu_put_be32(file, VIRTIO_GPU_MAX_RAM_SLOTS);
for (int i = 0 ; i < VIRTIO_GPU_MAX_RAM_SLOTS; ++i) {
qemu_put_be32(file, table->slots[i].used);
qemu_put_be64(file, table->slots[i].gpa);
qemu_put_be64(file, table->slots[i].offset);
qemu_put_be64(file, table->slots[i].size);
qemu_put_be32(file, table->slots[i].resource_id);
}
}
static void virtio_gpu_clear_slots() {
struct VirtioGpuRamSlotTable* table = virtio_gpu_ram_slot_table_get();
for (int i = 0; i < VIRTIO_GPU_MAX_RAM_SLOTS; ++i) {
if (0 == table->slots[i].used) continue;
qemu_user_backed_ram_unmap(table->slots[i].gpa, table->slots[i].size);
table->slots[i].used = 0;
}
}
void virtio_gpu_load_ram_slots(void* qemufile, VirtIOGPU* g) {
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
QEMUFile* file = (QEMUFile*)qemufile;
struct VirtioGpuRamSlotTable* table = virtio_gpu_ram_slot_table_get();
virtio_gpu_clear_slots();
uint32_t count = qemu_get_be32(file);
for (uint32_t i = 0; i < count; ++i) {
table->slots[i].used = qemu_get_be32(file);
table->slots[i].gpa = qemu_get_be64(file);
table->slots[i].offset = qemu_get_be64(file);
table->slots[i].size = qemu_get_be64(file);
table->slots[i].resource_id = qemu_get_be32(file);
if (!table->slots[i].used) continue;
void* hva;
uint64_t size;
gl->virgl->virgl_renderer_resource_map(table->slots[i].resource_id, &hva, &size);
if (size != table->slots[i].size) {
fprintf(stderr, "%s: resource %u: fatal: size in renderer (0x%llx) did not match slot size (0x%llx)\n", __func__,
table->slots[i].resource_id,
(unsigned long long)size,
(unsigned long long)table->slots[i].size);
abort();
}
qemu_user_backed_ram_map(
table->slots[i].gpa,
hva, size, USER_BACKED_RAM_FLAGS_READ | USER_BACKED_RAM_FLAGS_WRITE);
}
}
static void proxy_virgl_write_fence(void *opaque, uint32_t fence) {
VirtIOGPU *g = opaque;
struct virtio_gpu_ctrl_command *cmd, *tmp;
QTAILQ_FOREACH_SAFE(cmd, &g->fenceq, next, tmp) {
/*
* the guest can end up emitting fences out of order
* so we should check all fenced cmds not just the first one.
*/
if (cmd->cmd_hdr.fence_id > fence) {
continue;
}
trace_virtio_gpu_fence_resp(cmd->cmd_hdr.fence_id);
virtio_gpu_ctrl_response_nodata(g, cmd, VIRTIO_GPU_RESP_OK_NODATA);
QTAILQ_REMOVE(&g->fenceq, cmd, next);
g_free(cmd);
g->inflight--;
if (virtio_gpu_stats_enabled(g->parent_obj.conf)) {
fprintf(stderr, "inflight: %3d (-)\r", g->inflight);
}
}
}
static virgl_renderer_gl_context
proxy_virgl_create_context(void *opaque, int scanout_idx,
struct virgl_renderer_gl_ctx_param *params)
{
return (virgl_renderer_gl_context)0;
}
static void proxy_virgl_destroy_context(
void *opaque, virgl_renderer_gl_context ctx) { }
static int proxy_virgl_make_context_current(
void *opaque, int scanout_idx, virgl_renderer_gl_context ctx) { return 0; }
static struct virgl_renderer_callbacks proxy_3d_cbs = {
.version = 1,
.write_fence = proxy_virgl_write_fence,
.create_gl_context = proxy_virgl_create_context,
.destroy_gl_context = proxy_virgl_destroy_context,
.make_current = proxy_virgl_make_context_current,
#ifdef VIRGL_RENDERER_UNSTABLE_APIS
.write_context_fence = NULL,
#endif
};
#endif
static struct virgl_renderer_virtio_interface default_virtio_interface = {
.virgl_renderer_init = virgl_renderer_init,
.virgl_renderer_poll = virgl_renderer_poll,
.virgl_renderer_get_cursor_data = virgl_renderer_get_cursor_data,
.virgl_renderer_resource_create = virgl_renderer_resource_create,
.virgl_renderer_resource_unref = virgl_renderer_resource_unref,
.virgl_renderer_context_create = virgl_renderer_context_create,
.virgl_renderer_context_destroy = virgl_renderer_context_destroy,
.virgl_renderer_submit_cmd = virgl_renderer_submit_cmd,
.virgl_renderer_transfer_read_iov = virgl_renderer_transfer_read_iov,
.virgl_renderer_transfer_write_iov = virgl_renderer_transfer_write_iov,
.virgl_renderer_get_cap_set = virgl_renderer_get_cap_set,
.virgl_renderer_fill_caps = virgl_renderer_fill_caps,
.virgl_renderer_resource_attach_iov = virgl_renderer_resource_attach_iov,
.virgl_renderer_resource_detach_iov = virgl_renderer_resource_detach_iov,
.virgl_renderer_create_fence = virgl_renderer_create_fence,
.virgl_renderer_force_ctx_0 = virgl_renderer_force_ctx_0,
.virgl_renderer_ctx_attach_resource = virgl_renderer_ctx_attach_resource,
.virgl_renderer_ctx_detach_resource = virgl_renderer_ctx_detach_resource,
};
struct virgl_renderer_virtio_interface* get_default_virtio_interface() {
return &default_virtio_interface;
}
+27 -49
View File
@@ -1174,17 +1174,8 @@ static const VMStateDescription vmstate_virtio_gpu_scanouts = {
},
};
static int _virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field, JSONWriter *vmdesc)
{
VirtIOGPU *g = opaque;
VirtIOGPUClass *vgc = VIRTIO_GPU_GET_CLASS(g);
return vgc->gpu_save(f, opaque, size, field, vmdesc);
}
int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field, JSONWriter *vmdesc)
static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field, JSONWriter *vmdesc)
{
VirtIOGPU *g = opaque;
struct virtio_gpu_simple_resource *res;
@@ -1211,17 +1202,8 @@ int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,
return vmstate_save_state(f, &vmstate_virtio_gpu_scanouts, g, NULL);
}
static int _virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field)
{
VirtIOGPU *g = opaque;
VirtIOGPUClass *vgc = VIRTIO_GPU_GET_CLASS(g);
return vgc->gpu_load(f, opaque, size, field);
}
int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field)
static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field)
{
VirtIOGPU *g = opaque;
struct virtio_gpu_simple_resource *res;
@@ -1304,31 +1286,29 @@ int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
resource_id = qemu_get_be32(f);
}
/* load scanout state */
/* load & apply scanout state */
vmstate_load_state(f, &vmstate_virtio_gpu_scanouts, g, 1);
for (i = 0; i < g->parent_obj.conf.max_outputs; i++) {
scanout = &g->parent_obj.scanout[i];
if (!scanout->resource_id) {
continue;
}
res = virtio_gpu_find_resource(g, scanout->resource_id);
if (!res) {
return -EINVAL;
}
scanout->ds = qemu_create_displaysurface_pixman(res->image);
if (!scanout->ds) {
return -EINVAL;
}
// TODO: Figure out why this hangs the emulator display and causes ANR in the current app.
// for (i = 0; i < g->conf.max_outputs; i++) {
// scanout = &g->scanout[i];
// if (!scanout->resource_id) {
// continue;
// }
// res = virtio_gpu_find_resource(g, scanout->resource_id);
// if (!res) {
// return -EINVAL;
// }
// scanout->ds = qemu_create_displaysurface_pixman(res->image);
// if (!scanout->ds) {
// return -EINVAL;
// }
// dpy_gfx_replace_surface(scanout->con, scanout->ds);
// dpy_gfx_update(scanout->con, 0, 0, scanout->width, scanout->height);
// if (scanout->cursor.resource_id) {
// update_cursor(g, &scanout->cursor);
// }
// res->scanout_bitmask |= (1 << i);
// }
dpy_gfx_replace_surface(scanout->con, scanout->ds);
dpy_gfx_update_full(scanout->con);
if (scanout->cursor.resource_id) {
update_cursor(g, &scanout->cursor);
}
res->scanout_bitmask |= (1 << i);
}
return 0;
}
@@ -1430,8 +1410,8 @@ static const VMStateDescription vmstate_virtio_gpu = {
.name = "virtio-gpu",
.info = &(const VMStateInfo) {
.name = "virtio-gpu",
.get = _virtio_gpu_load,
.put = _virtio_gpu_save,
.get = virtio_gpu_load,
.put = virtio_gpu_save,
},
.flags = VMS_SINGLE,
} /* device */,
@@ -1458,8 +1438,6 @@ static void virtio_gpu_class_init(ObjectClass *klass, void *data)
vgc->handle_ctrl = virtio_gpu_handle_ctrl;
vgc->process_cmd = virtio_gpu_simple_process_cmd;
vgc->update_cursor_data = virtio_gpu_update_cursor_data;
vgc->gpu_save = virtio_gpu_save;
vgc->gpu_load = virtio_gpu_load;
vgbc->gl_flushed = virtio_gpu_handle_gl_flushed;
vdc->realize = virtio_gpu_device_realize;
-50
View File
@@ -1,50 +0,0 @@
#include "qemu/osdep.h"
#include "hw/pci/pci.h"
#include "hw/qdev-properties.h"
#include "hw/virtio/virtio-gpu.h"
#include "hw/display/vga.h"
#include "qapi/error.h"
#include "qemu/module.h"
#include "virtio-ramfb.h"
#include "qom/object.h"
#define TYPE_VIRTIO_RAMFB_GL "virtio-ramfb-gl"
typedef struct VirtIORAMFBGL VirtIORAMFBGL;
DECLARE_INSTANCE_CHECKER(VirtIORAMFBGL, VIRTIO_RAMFB_GL,
TYPE_VIRTIO_RAMFB_GL)
struct VirtIORAMFBGL {
VirtIORAMFBBase parent_obj;
VirtIOGPUGL vdev;
};
static void virtio_ramfb_gl_inst_initfn(Object *obj)
{
VirtIORAMFBGL *dev = VIRTIO_RAMFB_GL(obj);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_GPU_GL);
VIRTIO_RAMFB_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
}
static VirtioPCIDeviceTypeInfo virtio_ramfb_gl_info = {
.generic_name = TYPE_VIRTIO_RAMFB_GL,
.parent = TYPE_VIRTIO_RAMFB_BASE,
.instance_size = sizeof(VirtIORAMFBGL),
.instance_init = virtio_ramfb_gl_inst_initfn,
};
module_obj(TYPE_VIRTIO_RAMFB_GL);
static void virtio_ramfb_register_types(void)
{
if (have_vga) {
virtio_pci_types_register(&virtio_ramfb_gl_info);
}
}
type_init(virtio_ramfb_register_types)
module_dep("hw-display-virtio-ramfb");
-191
View File
@@ -1,191 +0,0 @@
#include "qemu/osdep.h"
#include "sysemu/sysemu.h"
#include "hw/pci/pci.h"
#include "ui/console.h"
#include "hw/qdev-properties.h"
#include "virtio-ramfb.h"
#include "qapi/error.h"
#include "qom/object.h"
static int virtio_ramfb_get_flags(void *opaque)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->get_flags) {
return g->hw_ops->get_flags(g);
} else {
return 0;
}
}
static void virtio_ramfb_invalidate_display(void *opaque)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->enable) {
g->hw_ops->invalidate(g);
}
}
static void virtio_ramfb_text_update(void *opaque, console_ch_t *chardata)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->text_update) {
g->hw_ops->text_update(g, chardata);
}
}
static void virtio_ramfb_update_display(void *opaque)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->enable) {
g->hw_ops->gfx_update(g);
} else {
ramfb_display_update(g->scanout[0].con, vramfb->ramfb);
}
}
static void virtio_ramfb_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->ui_info) {
g->hw_ops->ui_info(g, idx, info);
}
}
static void virtio_ramfb_gl_block(void *opaque, bool block)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->gl_block) {
g->hw_ops->gl_block(g, block);
}
}
static const GraphicHwOps virtio_ramfb_ops = {
.get_flags = virtio_ramfb_get_flags,
.invalidate = virtio_ramfb_invalidate_display,
.gfx_update = virtio_ramfb_update_display,
.text_update = virtio_ramfb_text_update,
.ui_info = virtio_ramfb_ui_info,
.gl_block = virtio_ramfb_gl_block,
};
static const VMStateDescription vmstate_virtio_ramfb = {
.name = "virtio-ramfb",
.version_id = 2,
.minimum_version_id = 2,
.fields = (VMStateField[]) {
/* no pci stuff here, saving the virtio device will handle that */
/* FIXME */
VMSTATE_END_OF_LIST()
}
};
/* RAMFB device wrapper around PCI device around virtio GPU */
static void virtio_ramfb_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
{
VirtIORAMFBBase *vramfb = VIRTIO_RAMFB_BASE(vpci_dev);
VirtIOGPUBase *g = vramfb->vgpu;
int i;
/* init virtio bits */
virtio_pci_force_virtio_1(vpci_dev);
if (!qdev_realize(DEVICE(g), BUS(&vpci_dev->bus), errp)) {
return;
}
/* init ramfb */
vramfb->ramfb = ramfb_setup(errp);
graphic_console_set_hwops(g->scanout[0].con, &virtio_ramfb_ops, vramfb);
for (i = 0; i < g->conf.max_outputs; i++) {
object_property_set_link(OBJECT(g->scanout[i].con), "device",
OBJECT(vpci_dev), &error_abort);
}
}
static void virtio_ramfb_reset(DeviceState *dev)
{
VirtIORAMFBBaseClass *klass = VIRTIO_RAMFB_BASE_GET_CLASS(dev);
/* reset virtio-gpu */
klass->parent_reset(dev);
}
static Property virtio_ramfb_base_properties[] = {
DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
DEFINE_PROP_END_OF_LIST(),
};
static void virtio_ramfb_base_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
VirtIORAMFBBaseClass *v = VIRTIO_RAMFB_BASE_CLASS(klass);
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
device_class_set_props(dc, virtio_ramfb_base_properties);
dc->vmsd = &vmstate_virtio_ramfb;
dc->hotpluggable = false;
device_class_set_parent_reset(dc, virtio_ramfb_reset,
&v->parent_reset);
k->realize = virtio_ramfb_realize;
pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
}
static const TypeInfo virtio_ramfb_base_info = {
.name = TYPE_VIRTIO_RAMFB_BASE,
.parent = TYPE_VIRTIO_PCI,
.instance_size = sizeof(VirtIORAMFBBase),
.class_size = sizeof(VirtIORAMFBBaseClass),
.class_init = virtio_ramfb_base_class_init,
.abstract = true,
};
#define TYPE_VIRTIO_RAMFB "virtio-ramfb"
typedef struct VirtIORAMFB VirtIORAMFB;
DECLARE_INSTANCE_CHECKER(VirtIORAMFB, VIRTIO_RAMFB,
TYPE_VIRTIO_RAMFB)
struct VirtIORAMFB {
VirtIORAMFBBase parent_obj;
VirtIOGPU vdev;
};
static void virtio_ramfb_inst_initfn(Object *obj)
{
VirtIORAMFB *dev = VIRTIO_RAMFB(obj);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_GPU);
VIRTIO_RAMFB_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
}
static VirtioPCIDeviceTypeInfo virtio_ramfb_info = {
.generic_name = TYPE_VIRTIO_RAMFB,
.parent = TYPE_VIRTIO_RAMFB_BASE,
.instance_size = sizeof(VirtIORAMFB),
.instance_init = virtio_ramfb_inst_initfn,
};
static void virtio_ramfb_register_types(void)
{
type_register_static(&virtio_ramfb_base_info);
virtio_pci_types_register(&virtio_ramfb_info);
}
type_init(virtio_ramfb_register_types)
-28
View File
@@ -1,28 +0,0 @@
#ifndef VIRTIO_RAMFB_H
#define VIRTIO_RAMFB_H
#include "hw/virtio/virtio-gpu-pci.h"
#include "hw/display/ramfb.h"
#include "qom/object.h"
/*
* virtio-ramfb-base: This extends VirtioPCIProxy.
*/
#define TYPE_VIRTIO_RAMFB_BASE "virtio-ramfb-base"
OBJECT_DECLARE_TYPE(VirtIORAMFBBase, VirtIORAMFBBaseClass,
VIRTIO_RAMFB_BASE)
struct VirtIORAMFBBase {
VirtIOPCIProxy parent_obj;
VirtIOGPUBase *vgpu;
RAMFBState *ramfb;
};
struct VirtIORAMFBBaseClass {
VirtioPCIClass parent_class;
DeviceReset parent_reset;
};
#endif /* VIRTIO_RAMFB_H */
+15
View File
@@ -3179,6 +3179,7 @@ static int vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
{
VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu);
IntelIOMMUState *s = vtd_as->iommu_state;
X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);
/* TODO: add support for VFIO and vhost users */
if (s->snoop_control) {
@@ -3186,6 +3187,20 @@ static int vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
"Snoop Control with vhost or VFIO is not supported");
return -ENOTSUP;
}
if (!s->caching_mode && (new & IOMMU_NOTIFIER_MAP)) {
error_setg_errno(errp, ENOTSUP,
"device %02x.%02x.%x requires caching mode",
pci_bus_num(vtd_as->bus), PCI_SLOT(vtd_as->devfn),
PCI_FUNC(vtd_as->devfn));
return -ENOTSUP;
}
if (!x86_iommu->dt_supported && (new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP)) {
error_setg_errno(errp, ENOTSUP,
"device %02x.%02x.%x requires device IOTLB mode",
pci_bus_num(vtd_as->bus), PCI_SLOT(vtd_as->devfn),
PCI_FUNC(vtd_as->devfn));
return -ENOTSUP;
}
/* Update per-address-space notifier flags */
vtd_as->notifier_flags = new;
+1 -1
View File
@@ -330,7 +330,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)
rom_set_fw(fw_cfg);
if (machine->kernel_filename != NULL) {
x86_load_linux(x86ms, fw_cfg, 0, true, false);
x86_load_linux(x86ms, fw_cfg, 0, true);
}
if (mms->option_roms) {
+2 -2
View File
@@ -799,7 +799,7 @@ void xen_load_linux(PCMachineState *pcms)
rom_set_fw(fw_cfg);
x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
pcmc->pvh_enabled, pcmc->legacy_no_rng_seed);
pcmc->pvh_enabled);
for (i = 0; i < nb_option_roms; i++) {
assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
!strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
@@ -1119,7 +1119,7 @@ void pc_memory_init(PCMachineState *pcms,
if (linux_boot) {
x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
pcmc->pvh_enabled, pcmc->legacy_no_rng_seed);
pcmc->pvh_enabled);
}
for (i = 0; i < nb_option_roms; i++) {
-2
View File
@@ -449,11 +449,9 @@ DEFINE_I440FX_MACHINE(v7_2, "pc-i440fx-7.2", NULL,
static void pc_i440fx_7_1_machine_options(MachineClass *m)
{
PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
pc_i440fx_7_2_machine_options(m);
m->alias = NULL;
m->is_default = false;
pcmc->legacy_no_rng_seed = true;
compat_props_add(m->compat_props, hw_compat_7_1, hw_compat_7_1_len);
compat_props_add(m->compat_props, pc_compat_7_1, pc_compat_7_1_len);
}
-2
View File
@@ -383,10 +383,8 @@ DEFINE_Q35_MACHINE(v7_2, "pc-q35-7.2", NULL,
static void pc_q35_7_1_machine_options(MachineClass *m)
{
PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
pc_q35_7_2_machine_options(m);
m->alias = NULL;
pcmc->legacy_no_rng_seed = true;
compat_props_add(m->compat_props, hw_compat_7_1, hw_compat_7_1_len);
compat_props_add(m->compat_props, pc_compat_7_1, pc_compat_7_1_len);
}
+17 -71
View File
@@ -26,7 +26,6 @@
#include "qemu/cutils.h"
#include "qemu/units.h"
#include "qemu/datadir.h"
#include "qemu/guest-random.h"
#include "qapi/error.h"
#include "qapi/qmp/qerror.h"
#include "qapi/qapi-visit-common.h"
@@ -37,7 +36,6 @@
#include "sysemu/whpx.h"
#include "sysemu/numa.h"
#include "sysemu/replay.h"
#include "sysemu/reset.h"
#include "sysemu/sysemu.h"
#include "sysemu/cpu-timers.h"
#include "sysemu/xen.h"
@@ -657,12 +655,12 @@ DeviceState *ioapic_init_secondary(GSIState *gsi_state)
return dev;
}
typedef struct SetupData {
struct setup_data {
uint64_t next;
uint32_t type;
uint32_t len;
uint8_t data[];
} __attribute__((packed)) SetupData;
} __attribute__((packed));
/*
@@ -769,35 +767,10 @@ static bool load_elfboot(const char *kernel_filename,
return true;
}
typedef struct SetupDataFixup {
void *pos;
hwaddr orig_val, new_val;
uint32_t addr;
} SetupDataFixup;
static void fixup_setup_data(void *opaque)
{
SetupDataFixup *fixup = opaque;
stq_p(fixup->pos, fixup->new_val);
}
static void reset_setup_data(void *opaque)
{
SetupDataFixup *fixup = opaque;
stq_p(fixup->pos, fixup->orig_val);
}
static void reset_rng_seed(void *opaque)
{
SetupData *setup_data = opaque;
qemu_guest_getrandom_nofail(setup_data->data, le32_to_cpu(setup_data->len));
}
void x86_load_linux(X86MachineState *x86ms,
FWCfgState *fw_cfg,
int acpi_data_size,
bool pvh_enabled,
bool legacy_no_rng_seed)
bool pvh_enabled)
{
bool linuxboot_dma_enabled = X86_MACHINE_GET_CLASS(x86ms)->fwcfg_dma_enabled;
uint16_t protocol;
@@ -805,17 +778,16 @@ void x86_load_linux(X86MachineState *x86ms,
int dtb_size, setup_data_offset;
uint32_t initrd_max;
uint8_t header[8192], *setup, *kernel;
hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0, first_setup_data = 0;
hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0;
FILE *f;
char *vmode;
MachineState *machine = MACHINE(x86ms);
SetupData *setup_data;
struct setup_data *setup_data;
const char *kernel_filename = machine->kernel_filename;
const char *initrd_filename = machine->initrd_filename;
const char *dtb_filename = machine->dtb;
const char *kernel_cmdline = machine->kernel_cmdline;
SevKernelLoaderContext sev_load_ctx = {};
enum { RNG_SEED_LENGTH = 32 };
/* Align to 16 bytes as a paranoia measure */
cmdline_size = (strlen(kernel_cmdline) + 16) & ~15;
@@ -1092,41 +1064,19 @@ void x86_load_linux(X86MachineState *x86ms,
}
setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16);
kernel_size = setup_data_offset + sizeof(SetupData) + dtb_size;
kernel_size = setup_data_offset + sizeof(struct setup_data) + dtb_size;
kernel = g_realloc(kernel, kernel_size);
stq_p(header + 0x250, prot_addr + setup_data_offset);
setup_data = (SetupData *)(kernel + setup_data_offset);
setup_data->next = cpu_to_le64(first_setup_data);
first_setup_data = prot_addr + setup_data_offset;
setup_data = (struct setup_data *)(kernel + setup_data_offset);
setup_data->next = 0;
setup_data->type = cpu_to_le32(SETUP_DTB);
setup_data->len = cpu_to_le32(dtb_size);
load_image_size(dtb_filename, setup_data->data, dtb_size);
}
if (!legacy_no_rng_seed) {
setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16);
kernel_size = setup_data_offset + sizeof(SetupData) + RNG_SEED_LENGTH;
kernel = g_realloc(kernel, kernel_size);
setup_data = (SetupData *)(kernel + setup_data_offset);
setup_data->next = cpu_to_le64(first_setup_data);
first_setup_data = prot_addr + setup_data_offset;
setup_data->type = cpu_to_le32(SETUP_RNG_SEED);
setup_data->len = cpu_to_le32(RNG_SEED_LENGTH);
qemu_guest_getrandom_nofail(setup_data->data, RNG_SEED_LENGTH);
qemu_register_reset_nosnapshotload(reset_rng_seed, setup_data);
fw_cfg_add_bytes_callback(fw_cfg, FW_CFG_KERNEL_DATA, reset_rng_seed, NULL,
setup_data, kernel, kernel_size, true);
} else {
fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
}
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
sev_load_ctx.kernel_data = (char *)kernel;
sev_load_ctx.kernel_size = kernel_size;
/*
* If we're starting an encrypted VM, it will be OVMF based, which uses the
* efi stub for booting and doesn't require any values to be placed in the
@@ -1135,20 +1085,16 @@ void x86_load_linux(X86MachineState *x86ms,
* file the user passed in.
*/
if (!sev_enabled()) {
SetupDataFixup *fixup = g_malloc(sizeof(*fixup));
memcpy(setup, header, MIN(sizeof(header), setup_size));
/* Offset 0x250 is a pointer to the first setup_data link. */
fixup->pos = setup + 0x250;
fixup->orig_val = ldq_p(fixup->pos);
fixup->new_val = first_setup_data;
fixup->addr = cpu_to_le32(real_addr);
fw_cfg_add_bytes_callback(fw_cfg, FW_CFG_SETUP_ADDR, fixup_setup_data, NULL,
fixup, &fixup->addr, sizeof(fixup->addr), true);
qemu_register_reset(reset_setup_data, fixup);
} else {
fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr);
}
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
sev_load_ctx.kernel_data = (char *)kernel;
sev_load_ctx.kernel_size = kernel_size;
fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr);
fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
sev_load_ctx.setup_data = (char *)setup;
-28
View File
@@ -35,7 +35,6 @@
#include "hw/misc/macio/macio.h"
#include "hw/intc/heathrow_pic.h"
#include "trace.h"
#include "include/hw/audio/screamer.h"
#define ESCC_CLOCK 3686400
@@ -105,17 +104,6 @@ static void macio_common_realize(PCIDevice *d, Error **errp)
sysbus_dev = SYS_BUS_DEVICE(&s->dbdma);
memory_region_add_subregion(&s->bar, 0x08000,
sysbus_mmio_get_region(sysbus_dev, 0));
if (!qdev_realize(DEVICE(&s->screamer), BUS(&s->macio_bus), errp)) {
return;
}
/* Add the screamer sound chip */
sysbus_dev = SYS_BUS_DEVICE(&s->screamer);
const int offset = 0x14000; /* Offset from base address register (bar) */
const int region_number = 0; /* which memory region to use */
memory_region_add_subregion(&s->bar, offset,
sysbus_mmio_get_region(sysbus_dev,
region_number));
qdev_prop_set_uint32(DEVICE(&s->escc), "disabled", 0);
qdev_prop_set_uint32(DEVICE(&s->escc), "frequency", ESCC_CLOCK);
@@ -376,19 +364,6 @@ static void macio_newworld_realize(PCIDevice *d, Error **errp)
memory_region_add_subregion(&s->bar, 0x16000,
sysbus_mmio_get_region(sysbus_dev, 0));
}
/* Screamer Sound Chip */
const int gpio_0 = 0;
const int gpio_1 = 1;
const int transmit_channel = 0x10;
const int receive_channel = 0x12;
sysbus_dev = SYS_BUS_DEVICE(&s->screamer);
sysbus_connect_irq(sysbus_dev, gpio_0, qdev_get_gpio_in(pic_dev,
NEWWORLD_SCREAMER_IRQ));
sysbus_connect_irq(sysbus_dev, gpio_1, qdev_get_gpio_in(pic_dev,
NEWWORLD_SCREAMER_DMA_IRQ));
screamer_register_dma_functions(SCREAMER(sysbus_dev), &s->dbdma,
transmit_channel, receive_channel);
}
static void macio_newworld_init(Object *obj)
@@ -418,9 +393,6 @@ static void macio_instance_init(Object *obj)
object_initialize_child(OBJECT(s), "dbdma", &s->dbdma, TYPE_MAC_DBDMA);
object_initialize_child(OBJECT(s), "escc", &s->escc, TYPE_ESCC);
object_initialize_child(OBJECT(s), SOUND_CHIP_NAME, &s->screamer,
TYPE_SCREAMER);
}
static const VMStateDescription vmstate_macio_oldworld = {
+1 -1
View File
@@ -1441,7 +1441,7 @@ static void vmxnet3_activate_device(VMXNET3State *s)
vmxnet3_setup_rx_filtering(s);
/* Cache fields from shared memory */
s->mtu = VMXNET3_READ_DRV_SHARED32(d, s->drv_shmem, devRead.misc.mtu);
assert(VMXNET3_MIN_MTU <= s->mtu && s->mtu < VMXNET3_MAX_MTU);
assert(VMXNET3_MIN_MTU <= s->mtu && s->mtu <= VMXNET3_MAX_MTU);
VMW_CFPRN("MTU is %u", s->mtu);
s->max_rx_frags =
+29 -6
View File
@@ -1331,10 +1331,23 @@ static inline void nvme_blk_write(BlockBackend *blk, int64_t offset,
}
}
static void nvme_update_cq_eventidx(const NvmeCQueue *cq)
{
uint32_t v = cpu_to_le32(cq->head);
//not in 7.2: trace_pci_nvme_update_cq_eventidx(cq->cqid, cq->head);
pci_dma_write(PCI_DEVICE(cq->ctrl), cq->ei_addr, &v, sizeof(v));
}
static void nvme_update_cq_head(NvmeCQueue *cq)
{
pci_dma_read(&cq->ctrl->parent_obj, cq->db_addr, &cq->head,
sizeof(cq->head));
uint32_t v;
pci_dma_read(&cq->ctrl->parent_obj, cq->db_addr, &v, sizeof(v));
cq->head = le32_to_cpu(v);
trace_pci_nvme_shadow_doorbell_cq(cq->cqid, cq->head);
}
@@ -1351,6 +1364,7 @@ static void nvme_post_cqes(void *opaque)
hwaddr addr;
if (n->dbbuf_enabled) {
nvme_update_cq_eventidx(cq);
nvme_update_cq_head(cq);
}
@@ -2477,6 +2491,9 @@ static uint16_t nvme_dsm(NvmeCtrl *n, NvmeRequest *req)
status = nvme_h2c(n, (uint8_t *)iocb->range, sizeof(NvmeDsmRange) * nr,
req);
if (status) {
g_free(iocb->range);
qemu_aio_unref(iocb);
return status;
}
@@ -6141,15 +6158,21 @@ static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeRequest *req)
static void nvme_update_sq_eventidx(const NvmeSQueue *sq)
{
pci_dma_write(&sq->ctrl->parent_obj, sq->ei_addr, &sq->tail,
sizeof(sq->tail));
uint32_t v = cpu_to_le32(sq->tail);
pci_dma_write(&sq->ctrl->parent_obj, sq->ei_addr, &v, sizeof(v));
trace_pci_nvme_eventidx_sq(sq->sqid, sq->tail);
}
static void nvme_update_sq_tail(NvmeSQueue *sq)
{
pci_dma_read(&sq->ctrl->parent_obj, sq->db_addr, &sq->tail,
sizeof(sq->tail));
uint32_t v;
pci_dma_read(&sq->ctrl->parent_obj, sq->db_addr, &v, sizeof(v));
sq->tail = le32_to_cpu(v);
trace_pci_nvme_shadow_doorbell_sq(sq->sqid, sq->tail);
}
+6 -6
View File
@@ -693,12 +693,12 @@ static const VMStateDescription vmstate_fw_cfg = {
}
};
void fw_cfg_add_bytes_callback(FWCfgState *s, uint16_t key,
FWCfgCallback select_cb,
FWCfgWriteCallback write_cb,
void *callback_opaque,
void *data, size_t len,
bool read_only)
static void fw_cfg_add_bytes_callback(FWCfgState *s, uint16_t key,
FWCfgCallback select_cb,
FWCfgWriteCallback write_cb,
void *callback_opaque,
void *data, size_t len,
bool read_only)
{
int arch = !!(key & FW_CFG_ARCH_LOCAL);
-1
View File
@@ -117,7 +117,6 @@ config MAC_NEWWORLD
select MAC_PMU
select UNIN_PCI
select FW_CFG_PPC
select SCREAMER
config E500
bool
+6
View File
@@ -796,6 +796,12 @@ int pvrdma_exec_cmd(PVRDMADev *dev)
dsr_info = &dev->dsr_info;
if (!dsr_info->dsr) {
/* Buggy or malicious guest driver */
rdma_error_report("Exec command without dsr, req or rsp buffers");
goto out;
}
if (dsr_info->req->hdr.cmd >= sizeof(cmd_handlers) /
sizeof(struct cmd_handler)) {
rdma_error_report("Unsupported command");
+5 -3
View File
@@ -749,14 +749,16 @@ static void smbios_build_type_4_table(MachineState *ms, unsigned instance)
t->core_count = (ms->smp.cores > 255) ? 0xFF : ms->smp.cores;
t->core_enabled = t->core_count;
t->core_count2 = t->core_enabled2 = cpu_to_le16(ms->smp.cores);
t->thread_count = (ms->smp.threads > 255) ? 0xFF : ms->smp.threads;
t->thread_count2 = cpu_to_le16(ms->smp.threads);
t->processor_characteristics = cpu_to_le16(0x02); /* Unknown */
t->processor_family2 = cpu_to_le16(0x01); /* Other */
if (tbl_len == SMBIOS_TYPE_4_LEN_V30) {
t->core_count2 = t->core_enabled2 = cpu_to_le16(ms->smp.cores);
t->thread_count2 = cpu_to_le16(ms->smp.threads);
}
SMBIOS_BUILD_TABLE_POST;
smbios_type4_count++;
}
+13 -6
View File
@@ -352,6 +352,16 @@ static const VMStateDescription vmstate_hpet = {
}
};
static void hpet_arm(HPETTimer *t, uint64_t ticks)
{
if (ticks < ns_to_ticks(INT64_MAX / 2)) {
timer_mod(t->qemu_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ticks_to_ns(ticks));
} else {
timer_del(t->qemu_timer);
}
}
/*
* timer expiration callback
*/
@@ -374,13 +384,11 @@ static void hpet_timer(void *opaque)
}
}
diff = hpet_calculate_diff(t, cur_tick);
timer_mod(t->qemu_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + (int64_t)ticks_to_ns(diff));
hpet_arm(t, diff);
} else if (t->config & HPET_TN_32BIT && !timer_is_periodic(t)) {
if (t->wrap_flag) {
diff = hpet_calculate_diff(t, cur_tick);
timer_mod(t->qemu_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
(int64_t)ticks_to_ns(diff));
hpet_arm(t, diff);
t->wrap_flag = 0;
}
}
@@ -407,8 +415,7 @@ static void hpet_set_timer(HPETTimer *t)
t->wrap_flag = 1;
}
}
timer_mod(t->qemu_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + (int64_t)ticks_to_ns(diff));
hpet_arm(t, diff);
}
static void hpet_del_timer(HPETTimer *t)
+1 -2
View File
@@ -1280,8 +1280,7 @@ static void usbredir_create_parser(USBRedirDevice *dev)
}
#endif
if (runstate_check(RUN_STATE_INMIGRATE) ||
runstate_check(RUN_STATE_RESTORE_VM)) {
if (runstate_check(RUN_STATE_INMIGRATE)) {
flags |= usbredirparser_fl_no_hello;
}
usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE,
+1 -1
View File
@@ -522,7 +522,7 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq,
size_t vhost_svq_poll(VhostShadowVirtqueue *svq)
{
int64_t start_us = g_get_monotonic_time();
uint32_t len;
uint32_t len = 0;
do {
if (vhost_svq_more_used(svq)) {
+6 -4
View File
@@ -16,6 +16,7 @@
#include "trace.h"
#define REALIZE_CONNECTION_RETRIES 3
#define VHOST_NVQS 2
/* Features required from VirtIO */
static const int feature_bits[] = {
@@ -198,8 +199,7 @@ static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserGPIO *gpio)
{
virtio_delete_queue(gpio->command_vq);
virtio_delete_queue(gpio->interrupt_vq);
g_free(gpio->vhost_dev.vqs);
gpio->vhost_dev.vqs = NULL;
g_free(gpio->vhost_vqs);
virtio_cleanup(vdev);
vhost_user_cleanup(&gpio->vhost_user);
}
@@ -219,6 +219,9 @@ static int vu_gpio_connect(DeviceState *dev, Error **errp)
vhost_dev_set_config_notifier(vhost_dev, &gpio_ops);
gpio->vhost_user.supports_config = true;
gpio->vhost_dev.nvqs = VHOST_NVQS;
gpio->vhost_dev.vqs = gpio->vhost_vqs;
ret = vhost_dev_init(vhost_dev, &gpio->vhost_user,
VHOST_BACKEND_TYPE_USER, 0, errp);
if (ret < 0) {
@@ -337,10 +340,9 @@ static void vu_gpio_device_realize(DeviceState *dev, Error **errp)
virtio_init(vdev, VIRTIO_ID_GPIO, sizeof(gpio->config));
gpio->vhost_dev.nvqs = 2;
gpio->command_vq = virtio_add_queue(vdev, 256, vu_gpio_handle_output);
gpio->interrupt_vq = virtio_add_queue(vdev, 256, vu_gpio_handle_output);
gpio->vhost_dev.vqs = g_new0(struct vhost_virtqueue, gpio->vhost_dev.nvqs);
gpio->vhost_vqs = g_new0(struct vhost_virtqueue, VHOST_NVQS);
gpio->connected = false;
+3 -2
View File
@@ -143,8 +143,6 @@ static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserI2C *i2c)
vhost_user_cleanup(&i2c->vhost_user);
virtio_delete_queue(i2c->vq);
virtio_cleanup(vdev);
g_free(i2c->vhost_dev.vqs);
i2c->vhost_dev.vqs = NULL;
}
static int vu_i2c_connect(DeviceState *dev)
@@ -228,6 +226,7 @@ static void vu_i2c_device_realize(DeviceState *dev, Error **errp)
ret = vhost_dev_init(&i2c->vhost_dev, &i2c->vhost_user,
VHOST_BACKEND_TYPE_USER, 0, errp);
if (ret < 0) {
g_free(i2c->vhost_dev.vqs);
do_vhost_user_cleanup(vdev, i2c);
}
@@ -239,10 +238,12 @@ static void vu_i2c_device_unrealize(DeviceState *dev)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VHostUserI2C *i2c = VHOST_USER_I2C(dev);
struct vhost_virtqueue *vhost_vqs = i2c->vhost_dev.vqs;
/* This will stop vhost backend if appropriate. */
vu_i2c_set_status(vdev, 0);
vhost_dev_cleanup(&i2c->vhost_dev);
g_free(vhost_vqs);
do_vhost_user_cleanup(vdev, i2c);
}
+3 -2
View File
@@ -229,6 +229,7 @@ static void vu_rng_device_realize(DeviceState *dev, Error **errp)
return;
vhost_dev_init_failed:
g_free(rng->vhost_dev.vqs);
virtio_delete_queue(rng->req_vq);
virtio_add_queue_failed:
virtio_cleanup(vdev);
@@ -239,12 +240,12 @@ static void vu_rng_device_unrealize(DeviceState *dev)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VHostUserRNG *rng = VHOST_USER_RNG(dev);
struct vhost_virtqueue *vhost_vqs = rng->vhost_dev.vqs;
vu_rng_set_status(vdev, 0);
vhost_dev_cleanup(&rng->vhost_dev);
g_free(rng->vhost_dev.vqs);
rng->vhost_dev.vqs = NULL;
g_free(vhost_vqs);
virtio_delete_queue(rng->req_vq);
virtio_cleanup(vdev);
vhost_user_cleanup(&rng->vhost_user);
+2 -15
View File
@@ -707,26 +707,11 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev,
return ret;
}
static void vhost_vdpa_reset_svq(struct vhost_vdpa *v)
{
if (!v->shadow_vqs_enabled) {
return;
}
for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
vhost_svq_stop(svq);
}
}
static int vhost_vdpa_reset_device(struct vhost_dev *dev)
{
struct vhost_vdpa *v = dev->opaque;
int ret;
uint8_t status = 0;
vhost_vdpa_reset_svq(v);
ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status);
trace_vhost_vdpa_reset_device(dev, status);
return ret;
@@ -1088,6 +1073,8 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)
for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
vhost_svq_stop(svq);
vhost_vdpa_svq_unmap_rings(dev, svq);
}
}
+64 -20
View File
@@ -20,6 +20,7 @@
#include "qemu/range.h"
#include "qemu/error-report.h"
#include "qemu/memfd.h"
#include "qemu/log.h"
#include "standard-headers/linux/vhost_types.h"
#include "hw/virtio/virtio-bus.h"
#include "hw/virtio/virtio-access.h"
@@ -106,6 +107,24 @@ static void vhost_dev_sync_region(struct vhost_dev *dev,
}
}
static bool vhost_dev_has_iommu(struct vhost_dev *dev)
{
VirtIODevice *vdev = dev->vdev;
/*
* For vhost, VIRTIO_F_IOMMU_PLATFORM means the backend support
* incremental memory mapping API via IOTLB API. For platform that
* does not have IOMMU, there's no need to enable this feature
* which may cause unnecessary IOTLB miss/update transactions.
*/
if (vdev) {
return virtio_bus_device_iommu_enabled(vdev) &&
virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
} else {
return false;
}
}
static int vhost_sync_dirty_bitmap(struct vhost_dev *dev,
MemoryRegionSection *section,
hwaddr first,
@@ -137,8 +156,51 @@ static int vhost_sync_dirty_bitmap(struct vhost_dev *dev,
continue;
}
vhost_dev_sync_region(dev, section, start_addr, end_addr, vq->used_phys,
range_get_last(vq->used_phys, vq->used_size));
if (vhost_dev_has_iommu(dev)) {
IOMMUTLBEntry iotlb;
hwaddr used_phys = vq->used_phys, used_size = vq->used_size;
hwaddr phys, s, offset;
while (used_size) {
rcu_read_lock();
iotlb = address_space_get_iotlb_entry(dev->vdev->dma_as,
used_phys,
true,
MEMTXATTRS_UNSPECIFIED);
rcu_read_unlock();
if (!iotlb.target_as) {
qemu_log_mask(LOG_GUEST_ERROR, "translation "
"failure for used_iova %"PRIx64"\n",
used_phys);
return -EINVAL;
}
offset = used_phys & iotlb.addr_mask;
phys = iotlb.translated_addr + offset;
/*
* Distance from start of used ring until last byte of
* IOMMU page.
*/
s = iotlb.addr_mask - offset;
/*
* Size of used ring, or of the part of it until end
* of IOMMU page. To avoid zero result, do the adding
* outside of MIN().
*/
s = MIN(s, used_size - 1) + 1;
vhost_dev_sync_region(dev, section, start_addr, end_addr, phys,
range_get_last(phys, s));
used_size -= s;
used_phys += s;
}
} else {
vhost_dev_sync_region(dev, section, start_addr,
end_addr, vq->used_phys,
range_get_last(vq->used_phys, vq->used_size));
}
}
return 0;
}
@@ -306,24 +368,6 @@ static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size)
dev->log_size = size;
}
static bool vhost_dev_has_iommu(struct vhost_dev *dev)
{
VirtIODevice *vdev = dev->vdev;
/*
* For vhost, VIRTIO_F_IOMMU_PLATFORM means the backend support
* incremental memory mapping API via IOTLB API. For platform that
* does not have IOMMU, there's no need to enable this feature
* which may cause unnecessary IOTLB miss/update transactions.
*/
if (vdev) {
return virtio_bus_device_iommu_enabled(vdev) &&
virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
} else {
return false;
}
}
static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr,
hwaddr *plen, bool is_write)
{
+3 -3
View File
@@ -235,7 +235,7 @@ static int virtio_mem_for_each_plugged_section(const VirtIOMEM *vmem,
uint64_t offset, size;
int ret = 0;
first_bit = s->offset_within_region / vmem->bitmap_size;
first_bit = s->offset_within_region / vmem->block_size;
first_bit = find_next_bit(vmem->bitmap, vmem->bitmap_size, first_bit);
while (first_bit < vmem->bitmap_size) {
MemoryRegionSection tmp = *s;
@@ -267,7 +267,7 @@ static int virtio_mem_for_each_unplugged_section(const VirtIOMEM *vmem,
uint64_t offset, size;
int ret = 0;
first_bit = s->offset_within_region / vmem->bitmap_size;
first_bit = s->offset_within_region / vmem->block_size;
first_bit = find_next_zero_bit(vmem->bitmap, vmem->bitmap_size, first_bit);
while (first_bit < vmem->bitmap_size) {
MemoryRegionSection tmp = *s;
@@ -341,7 +341,7 @@ static int virtio_mem_notify_plug(VirtIOMEM *vmem, uint64_t offset,
if (ret) {
/* Notify all already-notified listeners. */
QLIST_FOREACH(rdl2, &vmem->rdl_list, next) {
MemoryRegionSection tmp = *rdl->section;
MemoryRegionSection tmp = *rdl2->section;
if (rdl2 == rdl) {
break;
-1
View File
@@ -416,7 +416,6 @@ typedef struct disassemble_info {
typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *);
int print_insn_tci(bfd_vma, disassemble_info*);
int print_insn_tcti(bfd_vma, disassemble_info*);
int print_insn_big_mips (bfd_vma, disassemble_info*);
int print_insn_little_mips (bfd_vma, disassemble_info*);
int print_insn_nanomips (bfd_vma, disassemble_info*);
-4
View File
@@ -657,11 +657,7 @@ void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr);
#if defined(CONFIG_TCG_INTERPRETER)
extern __thread uintptr_t tci_tb_ptr;
# define GETPC() tci_tb_ptr
#elif defined(CONFIG_TCG_THREADED_INTERPRETER)
extern __thread uintptr_t tcti_call_return_address;
# define GETPC() tcti_call_return_address
#else
/* Note that this is correct for TCTI also; whose gadget behaves like native code. */
# define GETPC() \
((uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0)))
#endif
-17
View File
@@ -1,17 +0,0 @@
#ifndef EXEC_MEMORY_REMAH_H_INCLUDED
#define EXEC_MEMORY_REMAH_H_INCLUDED
#include <stdint.h>
/*
* API for adding and removing mappings of guest RAM and host addrs.
* Implementation depends on the hypervisor.
*/
#define USER_BACKED_RAM_FLAGS_NONE 0x0
#define USER_BACKED_RAM_FLAGS_READ 0x1
#define USER_BACKED_RAM_FLAGS_WRITE 0x2
#define USER_BACKED_RAM_FLAGS_EXEC 0x4
void qemu_user_backed_ram_map(uint64_t gpa, void* hva, uint64_t size, int flags);
void qemu_user_backed_ram_unmap(uint64_t gpa, uint64_t size);
#endif /* EXEC_MEMORY_REMAH_H_INCLUDED */
-28
View File
@@ -188,8 +188,6 @@ typedef struct IOMMUTLBEvent {
/* RAM is a persistent kind memory */
#define RAM_PMEM (1 << 5)
/* RAM backing is managed by user */
#define RAM_USER_BACKED (1 << 6)
/*
* UFFDIO_WRITEPROTECT is used on this RAMBlock to
@@ -739,7 +737,6 @@ struct MemoryRegion {
bool nonvolatile;
bool rom_device;
bool flush_coalesced_mmio;
bool user_backed;
uint8_t dirty_log_mask;
bool is_iommu;
RAMBlock *ram_block;
@@ -1512,16 +1509,6 @@ void memory_region_init_ram(MemoryRegion *mr,
uint64_t size,
Error **errp);
/**
* memory_region_init_ram_user_backed - Initialize RAM memory region where
* the allocation is dynamically managed by the user.
* Accesses into the region will modify memory directly.
*/
void memory_region_init_ram_user_backed(MemoryRegion *mr,
Object *owner,
const char *name,
uint64_t size);
/**
* memory_region_init_rom: Initialize a ROM memory region.
*
@@ -1609,21 +1596,6 @@ static inline bool memory_region_is_ram(MemoryRegion *mr)
return mr->ram;
}
/**
* memory_region_is_user_backed: check whether a memory region is random access
*
* Returns %true if a memory region's backing
* is user managed. This allows hypervisor to avoid
* directly adding the region on initialization,
* which can be a fatal error.
*
* @mr: the memory region being queried
*/
static inline bool memory_region_is_user_backed(MemoryRegion *mr)
{
return mr->user_backed;
}
/**
* memory_region_is_ram_device: check whether a memory region is a ram device
*
-9
View File
@@ -133,15 +133,6 @@ RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size,
uint64_t length,
void *host),
MemoryRegion *mr, Error **errp);
RAMBlock *qemu_ram_alloc_user_backed(ram_addr_t size, MemoryRegion *mr,
Error **errp);
typedef void (*QemuUserBackedRamMapFunc)(uint64_t gpa, void* hva, uint64_t size, int flags);
typedef void (*QemuUserBackedRamUnmapFunc)(uint64_t gpa, uint64_t size);
void qemu_set_user_backed_mapping_funcs(QemuUserBackedRamMapFunc mapFunc,
QemuUserBackedRamUnmapFunc unmapFunc);
void qemu_ram_free(RAMBlock *block);
int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp);
-42
View File
@@ -1,42 +0,0 @@
/*
* File: screamer.h
* Description: header file to the hw/audio/screamer.c file
*/
#ifndef screamer_h
#define screamer_h
#include <inttypes.h>
#include "audio/audio.h"
#include "hw/ppc/mac_dbdma.h"
#define TYPE_SCREAMER "screamer"
#define SCREAMER(obj) OBJECT_CHECK(ScreamerState, (obj), TYPE_SCREAMER)
#define SOUND_CHIP_NAME "Screamer Sound Chip"
#define MAX_BUFFER_SIZE (128 * 64)
typedef struct ScreamerState {
SysBusDevice parent_obj;
uint16_t awacs[8]; /* Shadow/awacs registers */
uint32_t sound_control;
uint32_t codec_control;
uint32_t codec_status;
uint32_t clip_count;
uint32_t byte_swap;
uint32_t frame_count;
SWVoiceOut *speaker_voice;
DBDMAState *dbdma;
qemu_irq dma_send_irq;
qemu_irq dma_receive_irq;
qemu_irq irq;
QEMUSoundCard card;
MemoryRegion io_memory_region;
uint8_t spk_buffer[MAX_BUFFER_SIZE];
uint16_t spk_buffer_position, spk_play_position;
DBDMA_io dma_io;
} ScreamerState;
void screamer_register_dma_functions(ScreamerState *s, void *dbdma,
int send_channel, int receive_channel);
#endif /* screamer_h */
-3
View File
@@ -128,9 +128,6 @@ struct PCMachineClass {
/* create kvmclock device even when KVM PV features are not exposed */
bool kvmclock_create_always;
/* skip passing an rng seed for legacy machines */
bool legacy_no_rng_seed;
};
#define TYPE_PC_MACHINE "generic-pc-machine"
+1 -2
View File
@@ -126,8 +126,7 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware,
void x86_load_linux(X86MachineState *x86ms,
FWCfgState *fw_cfg,
int acpi_data_size,
bool pvh_enabled,
bool legacy_no_rng_seed);
bool pvh_enabled);
bool x86_machine_is_smm_enabled(const X86MachineState *x86ms);
bool x86_machine_is_acpi_enabled(const X86MachineState *x86ms);
-5
View File
@@ -36,7 +36,6 @@
#include "hw/nvram/mac_nvram.h"
#include "hw/ppc/mac_dbdma.h"
#include "hw/ppc/openpic.h"
#include "hw/audio/screamer.h"
#include "qom/object.h"
/* Old World IRQs */
@@ -59,9 +58,6 @@
#define NEWWORLD_IDE1_DMA_IRQ 0x3
#define NEWWORLD_EXTING_GPIO1 0x2f
#define NEWWORLD_EXTING_GPIO9 0x37
#define NEWWORLD_SCREAMER_IRQ 0x18
#define NEWWORLD_SCREAMER_DMA_IRQ 0x9
#define NEWWORLD_SCREAMER_RX_IRQ 0xa
/* MacIO virtual bus */
#define TYPE_MACIO_BUS "macio-bus"
@@ -113,7 +109,6 @@ struct MacIOState {
PMUState pmu;
DBDMAState dbdma;
ESCCState escc;
ScreamerState screamer;
uint64_t frequency;
};
-22
View File
@@ -117,28 +117,6 @@ struct FWCfgMemState {
*/
void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
/**
* fw_cfg_add_bytes_callback:
* @s: fw_cfg device being modified
* @key: selector key value for new fw_cfg item
* @select_cb: callback function when selecting
* @write_cb: callback function after a write
* @callback_opaque: argument to be passed into callback function
* @data: pointer to start of item data
* @len: size of item data
* @read_only: is file read only
*
* Add a new fw_cfg item, available by selecting the given key, as a raw
* "blob" of the given size. The data referenced by the starting pointer
* is only linked, NOT copied, into the data structure of the fw_cfg device.
*/
void fw_cfg_add_bytes_callback(FWCfgState *s, uint16_t key,
FWCfgCallback select_cb,
FWCfgWriteCallback write_cb,
void *callback_opaque,
void *data, size_t len,
bool read_only);
/**
* fw_cfg_add_string:
* @s: fw_cfg device being modified
+1 -1
View File
@@ -23,7 +23,7 @@ struct VHostUserGPIO {
VirtIODevice parent_obj;
CharBackend chardev;
struct virtio_gpio_config config;
struct vhost_virtqueue *vhost_vq;
struct vhost_virtqueue *vhost_vqs;
struct vhost_dev vhost_dev;
VhostUserState vhost_user;
VirtQueue *command_vq;
-134
View File
@@ -1,134 +0,0 @@
#ifndef VIRTIO_GOLDFISH_PIPE
#define VIRTIO_GOLDFISH_PIPE
/* An override of virtio-gpu-3d (virgl) that runs goldfish pipe. One could
* implement an actual virtio goldfish pipe, but this hijacking of virgl is
* done in order to avoid any guest kernel changes. */
#include <virglrenderer.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef uint32_t VirtioGpuCtxId;
typedef uint8_t VirtioGpuRingIdx;
struct virgl_renderer_virtio_interface*
get_goldfish_pipe_virgl_renderer_virtio_interface(void);
/* Needed for goldfish pipe */
void virgl_write_fence(void *opaque, uint32_t fence);
void virtio_goldfish_pipe_reset(void* hwpipe, void* hostpipe);
#define VIRTIO_GOLDFISH_EXPORT_API
#ifdef VIRTIO_GOLDFISH_EXPORT_API
#ifdef _WIN32
#define VG_EXPORT __declspec(dllexport)
#else
#define VG_EXPORT __attribute__((visibility("default")))
#endif
VG_EXPORT int pipe_virgl_renderer_init(void *cookie,
int flags,
struct virgl_renderer_callbacks *cb);
VG_EXPORT void pipe_virgl_renderer_poll(void);
VG_EXPORT void* pipe_virgl_renderer_get_cursor_data(
uint32_t resource_id, uint32_t *width, uint32_t *height);
VG_EXPORT int pipe_virgl_renderer_resource_create(
struct virgl_renderer_resource_create_args *args,
struct iovec *iov, uint32_t num_iovs);
VG_EXPORT void pipe_virgl_renderer_resource_unref(uint32_t res_handle);
VG_EXPORT int pipe_virgl_renderer_context_create(
uint32_t handle, uint32_t nlen, const char *name);
VG_EXPORT void pipe_virgl_renderer_context_destroy(uint32_t handle);
VG_EXPORT int pipe_virgl_renderer_submit_cmd(void *buffer,
int ctx_id,
int bytes);
VG_EXPORT int pipe_virgl_renderer_transfer_read_iov(
uint32_t handle, uint32_t ctx_id,
uint32_t level, uint32_t stride,
uint32_t layer_stride,
struct virgl_box *box,
uint64_t offset, struct iovec *iov,
int iovec_cnt);
VG_EXPORT int pipe_virgl_renderer_transfer_write_iov(
uint32_t handle,
uint32_t ctx_id,
int level,
uint32_t stride,
uint32_t layer_stride,
struct virgl_box *box,
uint64_t offset,
struct iovec *iovec,
unsigned int iovec_cnt);
VG_EXPORT void pipe_virgl_renderer_get_cap_set(uint32_t, uint32_t*, uint32_t*);
VG_EXPORT void pipe_virgl_renderer_fill_caps(uint32_t, uint32_t, void *caps);
VG_EXPORT int pipe_virgl_renderer_resource_attach_iov(
int res_handle, struct iovec *iov,
int num_iovs);
VG_EXPORT void pipe_virgl_renderer_resource_detach_iov(
int res_handle, struct iovec **iov, int *num_iovs);
VG_EXPORT int pipe_virgl_renderer_create_fence(
int client_fence_id, uint32_t cmd_type);
VG_EXPORT void pipe_virgl_renderer_force_ctx_0(void);
VG_EXPORT void pipe_virgl_renderer_ctx_attach_resource(
int ctx_id, int res_handle);
VG_EXPORT void pipe_virgl_renderer_ctx_detach_resource(
int ctx_id, int res_handle);
VG_EXPORT int pipe_virgl_renderer_resource_get_info(
int res_handle,
struct virgl_renderer_resource_info *info);
VG_EXPORT void stream_renderer_flush_resource_and_readback(
uint32_t res_handle, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
void* pixels, uint32_t max_bytes);
VG_EXPORT void stream_renderer_resource_create_v2(
uint32_t res_handle, uint64_t hvaId);
VG_EXPORT uint64_t stream_renderer_resource_get_hva(uint32_t res_handle);
VG_EXPORT uint64_t stream_renderer_resource_get_hva_size(uint32_t res_handle);
VG_EXPORT void stream_renderer_resource_set_hv_slot(uint32_t res_handle, uint32_t slot);
VG_EXPORT uint32_t stream_renderer_resource_get_hv_slot(uint32_t res_handle);
VG_EXPORT int stream_renderer_resource_map(uint32_t res_handle, void** hvaOut, uint64_t* sizeOut);
VG_EXPORT int stream_renderer_resource_unmap(uint32_t res_handle);
VG_EXPORT int stream_renderer_context_create_fence(
uint64_t fence_id, uint32_t ctx_id, uint8_t ring_idx);
// Platform resources and contexts support
#define STREAM_RENDERER_PLATFORM_RESOURCE_TYPE_EGL_NATIVE_PIXMAP 0x01
#define STREAM_RENDERER_PLATFORM_RESOURCE_TYPE_EGL_IMAGE 0x02
VG_EXPORT int stream_renderer_platform_import_resource(int res_handle, int res_type, void* resource);
VG_EXPORT int stream_renderer_platform_resource_info(int res_handle, int* width, int* height, int* internal_format);
VG_EXPORT void* stream_renderer_platform_create_shared_egl_context(void);
VG_EXPORT int stream_renderer_platform_destroy_shared_egl_context(void*);
#else
#define VG_EXPORT
#endif // !VIRTIO_GOLDFISH_EXPORT_API
#ifdef __cplusplus
} // extern "C"
#endif
// based on VIRGL_RENDERER_USE* and friends
enum RendererFlags {
GFXSTREAM_RENDERER_FLAGS_USE_EGL_BIT = 1 << 0,
GFXSTREAM_RENDERER_FLAGS_THREAD_SYNC = 1 << 1,
GFXSTREAM_RENDERER_FLAGS_USE_GLX_BIT = 1 << 2,
GFXSTREAM_RENDERER_FLAGS_USE_SURFACELESS_BIT = 1 << 3,
GFXSTREAM_RENDERER_FLAGS_USE_GLES_BIT = 1 << 4,
GFXSTREAM_RENDERER_FLAGS_NO_VK_BIT = 1 << 5, // for disabling vk
GFXSTREAM_RENDERER_FLAGS_ENABLE_GLES31_BIT =
1 << 9, // disables the PlayStoreImage flag
GFXSTREAM_RENDERER_FLAGS_GUEST_USES_ANGLE = 1 << 21,
GFXSTREAM_RENDERER_FLAGS_VULKAN_NATIVE_SWAPCHAIN_BIT = 1 << 22,
GFXSTREAM_RENDERER_FLAGS_ASYNC_FENCE_CB = 1 << 23,
};
#endif
-1
View File
@@ -34,7 +34,6 @@ struct VirtIOGPUPCIBase {
#define DEFINE_VIRTIO_GPU_PCI_PROPERTIES(_state) \
DEFINE_PROP_BIT("ioeventfd", _state, flags, \
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false), \
DEFINE_PROP_BIT("hostshm", _state, flags, VIRTIO_PCI_FLAG_HOSTSHM_BIT, true), \
DEFINE_PROP_UINT32("vectors", _state, nvectors, 3)
#endif /* HW_VIRTIO_GPU_PCI_H */
-114
View File
@@ -1,114 +0,0 @@
#ifndef HW_VIRTIO_GPU_VIRGL_H
#define HW_VIRTIO_GPU_VIRGL_H
#include <virglrenderer.h>
struct virgl_renderer_resource_info;
/* Struct of virglrenderer API calls in order to be able to switch between
* different virgl API impls, or different devices altogether that use
* the virglrenderer API (e.g., goldfish pipe) */
typedef int (*virgl_renderer_init_t)(
void *cookie, int flags, struct virgl_renderer_callbacks *cb);
typedef void (*virgl_renderer_poll_t)(void); /* force fences */
typedef void* (*virgl_renderer_get_cursor_data_t)(
uint32_t resource_id, uint32_t *width, uint32_t *height);
typedef int (*virgl_renderer_resource_create_t)(
struct virgl_renderer_resource_create_args *args,
struct iovec *iov, uint32_t num_iovs);
typedef void (*virgl_renderer_resource_unref_t)(uint32_t res_handle);
typedef int (*virgl_renderer_context_create_t)(
uint32_t handle, uint32_t nlen, const char *name);
typedef void (*virgl_renderer_context_destroy_t)(uint32_t handle);
typedef int (*virgl_renderer_submit_cmd_t)(void *buffer,
int ctx_id,
int ndw);
typedef int (*virgl_renderer_transfer_read_iov_t)(
uint32_t handle, uint32_t ctx_id,
uint32_t level, uint32_t stride,
uint32_t layer_stride,
struct virgl_box *box,
uint64_t offset, struct iovec *iov,
int iovec_cnt);
typedef int (*virgl_renderer_transfer_write_iov_t)(
uint32_t handle,
uint32_t ctx_id,
int level,
uint32_t stride,
uint32_t layer_stride,
struct virgl_box *box,
uint64_t offset,
struct iovec *iovec,
unsigned int iovec_cnt);
typedef void (*virgl_renderer_get_cap_set_t)(uint32_t set, uint32_t *max_ver,
uint32_t *max_size);
typedef void (*virgl_renderer_fill_caps_t)(uint32_t set, uint32_t version,
void *caps);
typedef int (*virgl_renderer_resource_attach_iov_t)(
int res_handle, struct iovec *iov,
int num_iovs);
typedef void (*virgl_renderer_resource_detach_iov_t)(
int res_handle, struct iovec **iov, int *num_iovs);
typedef int (*virgl_renderer_create_fence_t)(
int client_fence_id, uint32_t ctx_id);
typedef void (*virgl_renderer_force_ctx_0_t)(void);
typedef void (*virgl_renderer_ctx_attach_resource_t)(
int ctx_id, int res_handle);
typedef void (*virgl_renderer_ctx_detach_resource_t)(
int ctx_id, int res_handle);
typedef int (*virgl_renderer_resource_get_info_t)(
int res_handle,
struct virgl_renderer_resource_info *info);
typedef int (*virgl_renderer_resource_create_v2_t)(unsigned int res_handle, uint64_t hvaId);
typedef int (*virgl_renderer_resource_map_t)(unsigned int res_handle, void** hvaOut, uint64_t* sizeOut);
typedef int (*virgl_renderer_resource_unmap_t)(unsigned int res_handle);
typedef void (*virgl_renderer_save_snapshot_t)(void* qemufile);
typedef void (*virgl_renderer_load_snapshot_t)(void* qemufile);
typedef int (*virgl_renderer_resource_attach_iov_with_addrs_t)(
int res_handle, struct iovec *iov, int num_iovs, uint64_t* addrs);
#define LIST_VIRGLRENDERER_API(f) \
f(virgl_renderer_init) \
f(virgl_renderer_poll) \
f(virgl_renderer_get_cursor_data) \
f(virgl_renderer_resource_create) \
f(virgl_renderer_resource_unref) \
f(virgl_renderer_context_create) \
f(virgl_renderer_context_destroy) \
f(virgl_renderer_submit_cmd) \
f(virgl_renderer_transfer_read_iov) \
f(virgl_renderer_transfer_write_iov) \
f(virgl_renderer_get_cap_set) \
f(virgl_renderer_fill_caps) \
f(virgl_renderer_resource_attach_iov) \
f(virgl_renderer_resource_detach_iov) \
f(virgl_renderer_create_fence) \
f(virgl_renderer_force_ctx_0) \
f(virgl_renderer_ctx_attach_resource) \
f(virgl_renderer_ctx_detach_resource) \
f(virgl_renderer_resource_get_info) \
f(virgl_renderer_resource_create_v2) \
f(virgl_renderer_resource_map) \
f(virgl_renderer_resource_unmap) \
f(virgl_renderer_save_snapshot) \
f(virgl_renderer_load_snapshot) \
f(virgl_renderer_resource_attach_iov_with_addrs) \
#define VIRGLRENDERER_API_DEFINE_STRUCT_FIELD(api) \
api##_t api;
struct virgl_renderer_virtio_interface {
LIST_VIRGLRENDERER_API(VIRGLRENDERER_API_DEFINE_STRUCT_FIELD)
};
struct virgl_renderer_virtio_interface* get_default_virtio_interface(void);
extern struct virgl_renderer_virtio_interface *get_goldfish_pipe_virgl_renderer_virtio_interface(void);
#endif /* HW_VIRTIO_GPU_VIRGL_H */
-18
View File
@@ -90,7 +90,6 @@ enum virtio_gpu_base_conf_flags {
VIRTIO_GPU_FLAG_EDID_ENABLED,
VIRTIO_GPU_FLAG_DMABUF_ENABLED,
VIRTIO_GPU_FLAG_BLOB_ENABLED,
VIRTIO_GPU_FLAG_GOLDFISH_PIPE_ENABLED,
};
#define virtio_gpu_virgl_enabled(_cfg) \
@@ -103,8 +102,6 @@ enum virtio_gpu_base_conf_flags {
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED))
#define virtio_gpu_blob_enabled(_cfg) \
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED))
#define virtio_gpu_goldfish_pipe_enabled(_cfg) \
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_GOLDFISH_PIPE_ENABLED))
struct virtio_gpu_base_conf {
uint32_t max_outputs;
@@ -202,10 +199,6 @@ struct VirtIOGPUClass {
void (*update_cursor_data)(VirtIOGPU *g,
struct virtio_gpu_scanout *s,
uint32_t resource_id);
int (*gpu_save)(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field, JSONWriter *vmdesc);
int (*gpu_load)(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field);
};
struct VirtIOGPUGL {
@@ -213,8 +206,6 @@ struct VirtIOGPUGL {
bool renderer_inited;
bool renderer_reset;
struct virgl_renderer_virtio_interface* virgl;
MemoryRegion host_coherent_memory;
};
struct VhostUserGPU {
@@ -274,10 +265,6 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g, struct virtio_gpu_ctrl_command
void virtio_gpu_update_cursor_data(VirtIOGPU *g,
struct virtio_gpu_scanout *s,
uint32_t resource_id);
int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field, JSONWriter *vmdesc);
int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field);
/* virtio-gpu-udmabuf.c */
bool virtio_gpu_have_udmabuf(void);
@@ -298,9 +285,4 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g);
int virtio_gpu_virgl_init(VirtIOGPU *g);
int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g);
#ifdef CONFIG_ANDROID
void virtio_gpu_save_ram_slots(void* qemufile, VirtIOGPU* g);
void virtio_gpu_load_ram_slots(void* qemufile, VirtIOGPU* g);
#endif
#endif
-6
View File
@@ -43,7 +43,6 @@ enum {
VIRTIO_PCI_FLAG_INIT_FLR_BIT,
VIRTIO_PCI_FLAG_AER_BIT,
VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT,
VIRTIO_PCI_FLAG_HOSTSHM_BIT,
};
/* Need to activate work-arounds for buggy guests at vmstate load. */
@@ -90,9 +89,6 @@ enum {
#define VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED \
(1 << VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT)
/* Host coherent shared memory */
#define VIRTIO_PCI_FLAG_HOSTSHM (1 << VIRTIO_PCI_FLAG_HOSTSHM_BIT)
typedef struct {
MSIMessage msg;
int virq;
@@ -146,12 +142,10 @@ struct VirtIOPCIProxy {
};
MemoryRegion modern_bar;
MemoryRegion io_bar;
MemoryRegion hostshm_bar;
uint32_t legacy_io_bar_idx;
uint32_t msix_bar_idx;
uint32_t modern_io_bar_idx;
uint32_t modern_mem_bar_idx;
uint32_t hostshm_mem_bar_idx;
int config_cap;
uint32_t flags;
bool disable_modern;
+21 -1
View File
@@ -177,7 +177,7 @@ extern "C" {
* supports QEMU_ERROR, this will be reported at compile time; otherwise
* this will be reported at link time due to the missing symbol.
*/
extern G_NORETURN
G_NORETURN extern
void QEMU_ERROR("code path is reachable")
qemu_build_not_reached_always(void);
#if defined(__OPTIMIZE__) && !defined(__NO_INLINE__)
@@ -673,6 +673,26 @@ int qemu_msync(void *addr, size_t length, int fd);
*/
size_t qemu_get_host_physmem(void);
/*
* Toggle write/execute on the pages marked MAP_JIT
* for the current thread.
*/
#if defined(MAC_OS_VERSION_11_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
static inline void qemu_thread_jit_execute(void)
{
pthread_jit_write_protect_np(true);
}
static inline void qemu_thread_jit_write(void)
{
pthread_jit_write_protect_np(false);
}
#else
static inline void qemu_thread_jit_write(void) {}
static inline void qemu_thread_jit_execute(void) {}
#endif
/**
* Platforms which do not support system() return ENOSYS
*/
-9
View File
@@ -28,15 +28,6 @@ extern bool hvf_allowed;
#define hvf_get_supported_cpuid(func, idx, reg) 0
#endif /* !CONFIG_HVF */
void* hvf_gpa2hva(uint64_t gpa, bool* found);
int hvf_hva2gpa(void* hva, uint64_t length, int max,
uint64_t* gpa, uint64_t* size);
int hvf_map_safe(void* hva, uint64_t gpa, uint64_t size, uint64_t flags);
int hvf_unmap_safe(uint64_t gpa, uint64_t size);
int hvf_protect_safe(uint64_t gpa, uint64_t size, uint64_t flags);
int hvf_remap_safe(void* hva, uint64_t gpa, uint64_t size, uint64_t flags);
#endif /* NEED_CPU_H */
#define TYPE_HVF_ACCEL ACCEL_CLASS_NAME("hvf")
-13
View File
@@ -17,15 +17,6 @@
#include <Hypervisor/hv.h>
#endif
#if defined(CONFIG_HVF_PRIVATE) && defined(__aarch64__)
extern hv_return_t _hv_vm_config_set_isa(hv_vm_config_t config, uint32_t isa);
extern hv_return_t _hv_vcpu_get_actlr(hv_vcpu_t vcpu, uint64_t* value);
extern hv_return_t _hv_vcpu_set_actlr(hv_vcpu_t vcpu, uint64_t value);
#define HV_VM_CONFIG_ISA_PRIVATE (3)
#define ACTLR_EL1_TSO_ENABLE_MASK ((1 << 1) | (1 << 9))
#endif
/* hvf_slot flags */
#define HVF_SLOT_LOG (1 << 0)
@@ -54,9 +45,6 @@ struct HVFState {
hvf_vcpu_caps *hvf_caps;
uint64_t vtimer_offset;
#if defined(CONFIG_HVF_PRIVATE) && defined(__aarch64__)
bool tso_mode;
#endif
};
extern HVFState *hvf_state;
@@ -68,7 +56,6 @@ struct hvf_vcpu_state {
};
void assert_hvf_ok(hv_return_t ret);
hv_return_t hvf_arch_vm_create(HVFState *s);
int hvf_arch_init(void);
int hvf_arch_init_vcpu(CPUState *cpu);
void hvf_arch_vcpu_destroy(CPUState *cpu);
-100
View File
@@ -1,100 +0,0 @@
/*
* Apple Silicon functions for JIT handling
*
* Copyright (c) 2020 osy
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TCG_APPLE_JIT_H
#define TCG_APPLE_JIT_H
/*
* APRR handling
* Credits to: https://siguza.github.io/APRR/
* Reversed from /usr/lib/system/libsystem_pthread.dylib
*/
#if defined(__aarch64__) && defined(CONFIG_DARWIN)
#define _COMM_PAGE_START_ADDRESS (0x0000000FFFFFC000ULL) /* In TTBR0 */
#define _COMM_PAGE_APRR_SUPPORT (_COMM_PAGE_START_ADDRESS + 0x10C)
#define _COMM_PAGE_APPR_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS + 0x110)
#define _COMM_PAGE_APRR_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS + 0x118)
static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)
{
/* Access shared kernel page at fixed memory location. */
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
return aprr_support > 0;
}
/* write protect enable = write disable */
static __attribute__((__always_inline__)) void jit_write_protect(int enabled)
{
/* Access shared kernel page at fixed memory location. */
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
if (aprr_support == 0 || aprr_support > 3) {
return;
} else if (aprr_support == 1) {
__asm__ __volatile__ (
"mov x0, %0\n"
"ldr x0, [x0]\n"
"msr S3_4_c15_c2_7, x0\n"
"isb sy\n"
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE
: _COMM_PAGE_APPR_WRITE_ENABLE)
: "memory", "x0"
);
} else {
__asm__ __volatile__ (
"mov x0, %0\n"
"ldr x0, [x0]\n"
"msr S3_6_c15_c1_5, x0\n"
"isb sy\n"
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE
: _COMM_PAGE_APPR_WRITE_ENABLE)
: "memory", "x0"
);
}
}
#else /* defined(__aarch64__) && defined(CONFIG_DARWIN) */
static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)
{
return false;
}
static __attribute__((__always_inline__)) void jit_write_protect(int enabled)
{
}
#endif
static inline void qemu_thread_jit_execute(void)
{
if (jit_write_protect_supported()) {
jit_write_protect(true);
}
}
static inline void qemu_thread_jit_write(void)
{
if (jit_write_protect_supported()) {
jit_write_protect(false);
}
}
#endif /* define TCG_APPLE_JIT_H */
-4
View File
@@ -194,11 +194,7 @@ DEF(insn_start, 0, 0, TLADDR_ARGS * TARGET_INSN_START_WORDS,
TCG_OPF_NOT_PRESENT)
DEF(exit_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
DEF(goto_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
#if defined(CONFIG_TCG_THREADED_INTERPRETER)
DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END | TCG_OPF_NOT_PRESENT)
#else
DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
#endif
DEF(plugin_cb_start, 0, 0, 3, TCG_OPF_NOT_PRESENT)
DEF(plugin_cb_end, 0, 0, 0, TCG_OPF_NOT_PRESENT)
+1 -1
View File
@@ -1199,7 +1199,7 @@ static inline size_t tcg_current_code_size(TCGContext *s)
#define TB_EXIT_IDXMAX 1
#define TB_EXIT_REQUESTED 3
#if defined(CONFIG_TCG_INTERPRETER) || defined(CONFIG_TCG_THREADED_INTERPRETER)
#ifdef CONFIG_TCG_INTERPRETER
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *tb_ptr);
#else
typedef uintptr_t tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);
-141
View File
@@ -1,141 +0,0 @@
/*
* QEMU Cocoa CG display driver
*
* Copyright (c) 2008 Mike Kronenberg
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef UI_COCOA_H
#define UI_COCOA_H
#import <Cocoa/Cocoa.h>
#include "ui/clipboard.h"
#include "ui/console.h"
#include "ui/kbd-state.h"
#include "qemu/main-loop.h"
#include "qemu/thread.h"
//#define DEBUG
#ifdef DEBUG
#define COCOA_DEBUG(...) { (void) fprintf (stdout, __VA_ARGS__); }
#else
#define COCOA_DEBUG(...) ((void) 0)
#endif
typedef struct CocoaListener {
DisplayChangeListener dcl;
QEMUCursor *cursor;
int mouse_x;
int mouse_y;
int mouse_on;
#ifdef CONFIG_OPENGL
uint32_t gl_scanout_id;
DisplayGLTextureBorrower gl_scanout_borrow;
bool gl_scanout_y0_top;
#endif
} CocoaListener;
typedef struct {
CocoaListener *active_listener;
CocoaListener *listeners;
size_t listeners_count;
DisplaySurface *surface;
QemuMutex draw_mutex;
QKbdState *kbd;
CGImageRef cursor_cgimage;
int cursor_show;
bool left_command_key_disabled;
bool swap_opt_cmd;
bool inited;
} QEMUScreen;
typedef struct {
QemuClipboardInfo *info;
QemuEvent event;
} QemuCocoaClipboard;
@interface QemuCocoaView : NSView
{
NSTextField *pauseLabel;
NSTrackingArea *trackingArea;
QEMUScreen *screen;
int screen_width;
int screen_height;
BOOL isMouseGrabbed;
BOOL isAbsoluteEnabled;
CFMachPortRef eventsTap;
}
- (id)initWithFrame:(NSRect)frameRect
screen:(QEMUScreen *)given_screen;
- (void) frameUpdated;
- (void) selectConsoleLocked:(unsigned int)index;
- (NSSize) computeUnzoomedSize;
- (NSSize) fixZoomedFullScreenSize:(NSSize)proposedSize;
- (void) resizeWindow;
- (void) updateUIInfo;
- (void) updateScreenWidth:(int)w height:(int)h;
- (void) grabMouse;
- (void) ungrabMouse;
- (void) setFullGrab:(id)sender;
- (bool) handleEvent:(NSEvent *)event;
- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
/* The state surrounding mouse grabbing is potentially confusing.
* isAbsoluteEnabled tracks qemu_input_is_absolute() [ie "is the emulated
* pointing device an absolute-position one?"], but is only updated on
* next refresh.
* isMouseGrabbed tracks whether GUI events are directed to the guest;
* it controls whether special keys like Cmd get sent to the guest,
* and whether we capture the mouse when in non-absolute mode.
*/
- (BOOL) isMouseGrabbed;
- (BOOL) isAbsoluteEnabled;
- (void) setNeedsDisplayForCursorX:(int)x
y:(int)y
width:(int)width
height:(int)height
screenHeight:(int)screen_height;
- (void)displayPause;
- (void)removePause;
@end
@interface QemuCocoaAppController : NSObject
<NSWindowDelegate, NSApplicationDelegate>
{
QemuCocoaView *cocoaView;
}
- (id) initWithScreen:(QEMUScreen *)screen;
- (QemuCocoaView *)cocoaView;
@end
@interface QemuCocoaPasteboardTypeOwner : NSObject<NSPasteboardTypeOwner>
{
QemuCocoaClipboard *cb;
}
- (id) initWith:(QemuCocoaClipboard *)aCb;
@end
void cocoa_listener_select(size_t index);
typedef void (^CodeBlock)(void);
typedef bool (^BoolCodeBlock)(void);
#endif
+11 -10
View File
@@ -94,6 +94,7 @@ void hmp_mouse_set(Monitor *mon, const QDict *qdict);
void kbd_put_keysym_console(QemuConsole *s, int keysym);
bool kbd_put_qcode_console(QemuConsole *s, int qcode, bool ctrl);
void kbd_put_string_console(QemuConsole *s, const char *str, int len);
void kbd_put_keysym(int keysym);
/* consoles */
@@ -108,13 +109,11 @@ struct QemuConsoleClass {
#define QEMU_ALLOCATED_FLAG 0x01
#define QEMU_PLACEHOLDER_FLAG 0x02
typedef uint32_t (* DisplayGLTextureBorrower)(uint32_t id, bool *y_0_top,
uint32_t *width,
uint32_t *height);
typedef struct ScanoutTexture {
uint32_t backing_id;
DisplayGLTextureBorrower backing_borrow;
bool backing_y_0_top;
uint32_t backing_width;
uint32_t backing_height;
uint32_t x;
uint32_t y;
uint32_t width;
@@ -129,7 +128,6 @@ typedef struct DisplaySurface {
GLenum glformat;
GLenum gltype;
GLuint texture;
bool glswapped;
#endif
} DisplaySurface;
@@ -250,7 +248,9 @@ typedef struct DisplayChangeListenerOps {
/* required if GL */
void (*dpy_gl_scanout_texture)(DisplayChangeListener *dcl,
uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h);
/* optional (default to true if has dpy_gl_scanout_dmabuf) */
@@ -353,8 +353,9 @@ bool dpy_gfx_check_format(QemuConsole *con,
pixman_format_code_t format);
void dpy_gl_scanout_disable(QemuConsole *con);
void dpy_gl_scanout_texture(QemuConsole *con, uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
void dpy_gl_scanout_texture(QemuConsole *con,
uint32_t backing_id, bool backing_y_0_top,
uint32_t backing_width, uint32_t backing_height,
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
void dpy_gl_scanout_dmabuf(QemuConsole *con,
QemuDmaBuf *dmabuf);
@@ -454,7 +455,6 @@ void qemu_console_early_init(void);
void qemu_console_set_display_gl_ctx(QemuConsole *con, DisplayGLCtx *ctx);
QemuConsole *qemu_console_lookup_first_graphic_console(void);
QemuConsole *qemu_console_lookup_by_index(unsigned int index);
QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
@@ -475,6 +475,7 @@ int qemu_console_get_window_id(QemuConsole *con);
/* Set the low-level window id for the console */
void qemu_console_set_window_id(QemuConsole *con, int window_id);
void console_select(unsigned int index);
void qemu_console_resize(QemuConsole *con, int width, int height);
DisplaySurface *qemu_console_surface(QemuConsole *con);
+3 -22
View File
@@ -6,9 +6,6 @@
#ifdef CONFIG_GBM
#include <gbm.h>
#endif
#ifdef CONFIG_ANGLE
#include <EGL/eglext_angle.h>
#endif
#include "ui/console.h"
#include "ui/shader.h"
@@ -20,7 +17,6 @@ typedef struct egl_fb {
int width;
int height;
GLuint texture;
GLenum texture_target;
GLuint framebuffer;
bool delete_texture;
QemuDmaBuf *dmabuf;
@@ -28,18 +24,15 @@ typedef struct egl_fb {
void egl_fb_destroy(egl_fb *fb);
void egl_fb_setup_default(egl_fb *fb, int width, int height);
void egl_fb_setup_for_tex_target(egl_fb *fb, int width, int height,
GLuint texture, GLenum target, bool delete);
void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
GLuint texture, bool delete);
void egl_fb_setup_new_tex_target(egl_fb *fb, int width, int height, GLenum target);
void egl_fb_setup_new_tex(egl_fb *fb, int width, int height);
void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip);
void egl_fb_read(DisplaySurface *dst, egl_fb *src);
void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip, bool swap);
void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip);
void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
bool swap, int x, int y, double scale_x, double scale_y);
int x, int y, double scale_x, double scale_y);
#ifdef CONFIG_GBM
@@ -58,13 +51,7 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf);
#endif
EGLSurface qemu_egl_init_surface(EGLContext ectx, EGLNativeWindowType win);
EGLSurface qemu_egl_init_buffer_surface(EGLContext ectx, EGLenum buftype,
EGLClientBuffer buffer, const EGLint *attrib_list);
bool qemu_egl_destroy_surface(EGLSurface surface);
int qemu_egl_init_dpy_cocoa(DisplayGLMode mode);
int qemu_egl_init_dpy_surfaceless(DisplayGLMode mode);
EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win);
#if defined(CONFIG_X11) || defined(CONFIG_GBM)
@@ -73,12 +60,6 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode);
#endif
#if defined(CONFIG_ANGLE)
int qemu_egl_init_dpy_angle(DisplayGLMode mode);
#endif
EGLContext qemu_egl_init_ctx(void);
bool qemu_egl_has_dmabuf(void);
+6 -2
View File
@@ -171,7 +171,9 @@ QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc,
void gd_egl_scanout_disable(DisplayChangeListener *dcl);
void gd_egl_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h);
void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
@@ -205,7 +207,9 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
QemuDmaBuf *dmabuf);
void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h);
void gd_gl_area_scanout_disable(DisplayChangeListener *dcl);
+5 -3
View File
@@ -22,7 +22,7 @@
#endif
#include "ui/kbd-state.h"
#if defined(CONFIG_OPENGL)
#ifdef CONFIG_OPENGL
# include "ui/egl-helpers.h"
#endif
@@ -44,7 +44,7 @@ struct sdl2_console {
int ignore_hotkeys;
SDL_GLContext winctx;
QKbdState *kbd;
#if defined(CONFIG_OPENGL)
#ifdef CONFIG_OPENGL
QemuGLShader *gls;
egl_fb guest_fb;
egl_fb win_fb;
@@ -86,7 +86,9 @@ int sdl2_gl_make_context_current(DisplayGLCtx *dgc,
void sdl2_gl_scanout_disable(DisplayChangeListener *dcl);
void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h);
void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
+1 -1
View File
@@ -5,7 +5,7 @@
typedef struct QemuGLShader QemuGLShader;
void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip, bool swapped);
void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip);
QemuGLShader *qemu_gl_init_shader(void);
void qemu_gl_fini_shader(QemuGLShader *gls);
+1 -18
View File
@@ -27,12 +27,7 @@
#include "ui/qemu-pixman.h"
#include "ui/console.h"
#if defined(CONFIG_IOSURFACE)
#include <CoreFoundation/CoreFoundation.h>
#include <IOSurface/IOSurfaceRef.h>
#endif
#if defined(CONFIG_OPENGL)
#if defined(CONFIG_OPENGL) && defined(CONFIG_GBM)
# if SPICE_SERVER_VERSION >= 0x000d01 /* release 0.13.1 */
# define HAVE_SPICE_GL 1
# include "ui/egl-helpers.h"
@@ -132,20 +127,8 @@ struct SimpleSpiceDisplay {
bool have_scanout;
bool have_surface;
#if defined(CONFIG_GBM)
QemuDmaBuf *guest_dmabuf;
bool guest_dmabuf_refresh;
#endif
#if defined(CONFIG_IOSURFACE)
IOSurfaceRef iosurface;
int surface_send_fd;
#endif
#if defined(CONFIG_ANGLE)
EGLSurface esurface;
egl_fb iosurface_fb;
DisplayGLTextureBorrower backing_borrow;
uint32_t backing_id;
#endif
bool render_cursor;
egl_fb guest_fb;
+3
View File
@@ -74,6 +74,9 @@ qio_channel_tls_new_server(QIOChannel *master,
ioc = QIO_CHANNEL_TLS(object_new(TYPE_QIO_CHANNEL_TLS));
ioc->master = master;
if (qio_channel_has_feature(master, QIO_CHANNEL_FEATURE_SHUTDOWN)) {
qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SHUTDOWN);
}
object_ref(OBJECT(master));
ioc->session = qcrypto_tls_session_new(
+7 -3
View File
@@ -1622,7 +1622,7 @@ TargetFdTrans target_signalfd_trans = {
.host_to_target_data = host_to_target_data_signalfd,
};
static abi_long swap_data_eventfd(void *buf, size_t len)
static abi_long swap_data_u64(void *buf, size_t len)
{
uint64_t *counter = buf;
int i;
@@ -1640,8 +1640,12 @@ static abi_long swap_data_eventfd(void *buf, size_t len)
}
TargetFdTrans target_eventfd_trans = {
.host_to_target_data = swap_data_eventfd,
.target_to_host_data = swap_data_eventfd,
.host_to_target_data = swap_data_u64,
.target_to_host_data = swap_data_u64,
};
TargetFdTrans target_timerfd_trans = {
.host_to_target_data = swap_data_u64,
};
#if defined(CONFIG_INOTIFY) && (defined(TARGET_NR_inotify_init) || \
+1
View File
@@ -130,6 +130,7 @@ extern TargetFdTrans target_netlink_route_trans;
extern TargetFdTrans target_netlink_audit_trans;
extern TargetFdTrans target_signalfd_trans;
extern TargetFdTrans target_eventfd_trans;
extern TargetFdTrans target_timerfd_trans;
#if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \
(defined(CONFIG_INOTIFY1) && defined(TARGET_NR_inotify_init1) && \
defined(__NR_inotify_init1))
+2 -2
View File
@@ -12,8 +12,8 @@ struct target_rlimit {
};
struct target_rlimit64 {
uint64_t rlim_cur;
uint64_t rlim_max;
abi_ullong rlim_cur;
abi_ullong rlim_max;
};
#define TARGET_RLIM_INFINITY ((abi_ulong)-1)
+15 -6
View File
@@ -1755,6 +1755,11 @@ static inline abi_long target_to_host_sockaddr(int fd, struct sockaddr *addr,
lladdr = (struct target_sockaddr_ll *)addr;
lladdr->sll_ifindex = tswap32(lladdr->sll_ifindex);
lladdr->sll_hatype = tswap16(lladdr->sll_hatype);
} else if (sa_family == AF_INET6) {
struct sockaddr_in6 *in6addr;
in6addr = (struct sockaddr_in6 *)addr;
in6addr->sin6_scope_id = tswap32(in6addr->sin6_scope_id);
}
unlock_user(target_saddr, target_addr, 0);
@@ -12883,8 +12888,8 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
if (!lock_user_struct(VERIFY_READ, target_rnew, arg3, 1)) {
return -TARGET_EFAULT;
}
rnew.rlim_cur = tswap64(target_rnew->rlim_cur);
rnew.rlim_max = tswap64(target_rnew->rlim_max);
__get_user(rnew.rlim_cur, &target_rnew->rlim_cur);
__get_user(rnew.rlim_max, &target_rnew->rlim_max);
unlock_user_struct(target_rnew, arg3, 0);
rnewp = &rnew;
}
@@ -12894,8 +12899,8 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
if (!lock_user_struct(VERIFY_WRITE, target_rold, arg4, 1)) {
return -TARGET_EFAULT;
}
target_rold->rlim_cur = tswap64(rold.rlim_cur);
target_rold->rlim_max = tswap64(rold.rlim_max);
__put_user(rold.rlim_cur, &target_rold->rlim_cur);
__put_user(rold.rlim_max, &target_rold->rlim_max);
unlock_user_struct(target_rold, arg4, 1);
}
return ret;
@@ -13115,8 +13120,12 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
#if defined(TARGET_NR_timerfd_create) && defined(CONFIG_TIMERFD)
case TARGET_NR_timerfd_create:
return get_errno(timerfd_create(arg1,
target_to_host_bitmask(arg2, fcntl_flags_tbl)));
ret = get_errno(timerfd_create(arg1,
target_to_host_bitmask(arg2, fcntl_flags_tbl)));
if (ret >= 0) {
fd_trans_register(ret, &target_timerfd_trans);
}
return ret;
#endif
#if defined(TARGET_NR_timerfd_gettime) && defined(CONFIG_TIMERFD)
+8 -79
View File
@@ -50,7 +50,6 @@ bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin
supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv', 'x86', 'x86_64',
'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
tcti_supported_cpus = ['aarch64']
cpu = host_machine.cpu_family()
@@ -382,7 +381,6 @@ socket = []
version_res = []
coref = []
iokit = []
iosurface = not_found
emulator_link_args = []
nvmm =not_found
hvf = not_found
@@ -405,7 +403,6 @@ if targetos == 'windows'
elif targetos == 'darwin'
coref = dependency('appleframeworks', modules: 'CoreFoundation')
iokit = dependency('appleframeworks', modules: 'IOKit', required: false)
iosurface = dependency('appleframeworks', modules: 'IOSurface', required: false)
host_dsosuf = '.dylib'
elif targetos == 'sunos'
socket = [cc.find_library('socket'),
@@ -440,7 +437,6 @@ if get_option('hvf').allowed()
required: get_option('hvf'))
if hvf.found()
accelerators += 'CONFIG_HVF'
config_host_data.set('CONFIG_HVF_PRIVATE', get_option('hvf_private'))
endif
endif
if get_option('hax').allowed()
@@ -473,24 +469,6 @@ if get_option('tcg').allowed()
endif
if get_option('tcg_interpreter')
tcg_arch = 'tci'
elif get_option('tcg_threaded_interpreter')
if cpu not in tcti_supported_cpus
error('Unsupported CPU @0@ for TCTI, try --enable-tcg-interpreter'.format(cpu))
else
warning('TCTI is extremely experimental and incomplete! Things might break!')
tcg_arch = '@0@-tcti'.format(cpu)
endif
# Tell our compiler how to generate our TCTI gadgets.
gadget_generator = 'tcg/@0@/tcti-gadget-gen.py'.format(tcg_arch)
tcti_gadgets = custom_target('tcti-gadgets.c.inc',
output: 'tcti-gadgets.c.inc',
input: gadget_generator,
command: [find_program(gadget_generator), '@OUTPUT@'],
build_by_default: true,
build_always_stale: false)
genh += tcti_gadgets
elif host_arch == 'x86_64'
tcg_arch = 'i386'
elif host_arch == 'ppc64'
@@ -1936,7 +1914,6 @@ config_host_data.set('CONFIG_SPICE', spice.found())
config_host_data.set('CONFIG_X11', x11.found())
config_host_data.set('CONFIG_DBUS_DISPLAY', dbus_display)
config_host_data.set('CONFIG_CFI', get_option('cfi'))
config_host_data.set('CONFIG_IOSURFACE', iosurface.found())
config_host_data.set('CONFIG_SELINUX', selinux.found())
config_host_data.set('CONFIG_XEN_BACKEND', xen.found())
if xen.found()
@@ -1978,7 +1955,6 @@ config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h'))
config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h'))
config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h'))
config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h'))
config_host_data.set('CONFIG_ANGLE', cc.has_header('EGL/eglext_angle.h'))
if targetos == 'windows'
config_host_data.set('HAVE_AFUNIX_H', cc.has_header('afunix.h'))
endif
@@ -2571,8 +2547,6 @@ foreach target : target_dirs
config_all += { sym: 'y' }
if sym == 'CONFIG_TCG' and tcg_arch == 'tci'
config_target += { 'CONFIG_TCG_INTERPRETER': 'y' }
elif sym == 'CONFIG_TCG' and tcg_arch.endswith('tcti')
config_target += { 'CONFIG_TCG_THREADED_INTERPRETER': 'y' }
endif
if target in modular_tcg
config_target += { 'CONFIG_TCG_MODULAR': 'y' }
@@ -2792,18 +2766,9 @@ if not fdt.found() and fdt_required.length() > 0
error('fdt not available but required by targets ' + ', '.join(fdt_required))
endif
ucontext = dependency('libucontext', kwargs: static_kwargs, required : false)
if not ucontext.found() and get_option('ucontext').enabled()
libucontext_proj = subproject('libucontext',
default_options: ['default_library=static',
'freestanding=true'])
ucontext = libucontext_proj.get_variable('libucontext_dep')
endif
config_host_data.set('CONFIG_CAPSTONE', capstone.found())
config_host_data.set('CONFIG_FDT', fdt.found())
config_host_data.set('CONFIG_SLIRP', slirp.found())
config_host_data.set('CONFIG_LIBUCONTEXT', ucontext.found())
#####################
# Generated sources #
@@ -2812,7 +2777,7 @@ config_host_data.set('CONFIG_LIBUCONTEXT', ucontext.found())
genh += configure_file(output: 'config-host.h', configuration: config_host_data)
hxtool = find_program('scripts/hxtool')
shaderinclude = find_program('scripts/shaderinclude.pl')
shaderinclude = find_program('scripts/shaderinclude.py')
qapi_gen = find_program('scripts/qapi-gen.py')
qapi_gen_depends = [ meson.current_source_dir() / 'scripts/qapi/__init__.py',
meson.current_source_dir() / 'scripts/qapi/commands.py',
@@ -3084,7 +3049,7 @@ util_ss.add_all(trace_ss)
util_ss = util_ss.apply(config_all, strict: false)
libqemuutil = static_library('qemuutil',
sources: util_ss.sources() + stub_ss.sources() + genh,
dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman, ucontext])
dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman])
qemuutil = declare_dependency(link_with: libqemuutil,
sources: genh + version_res,
dependencies: [event_loop_base])
@@ -3497,32 +3462,14 @@ foreach target : target_dirs
arch_srcs += target_specific.sources()
arch_deps += target_specific.dependencies()
if config_all.has_key('CONFIG_SHARED_LIBRARY_BUILD')
build_lib_args = {
'target_type': 'shared_library',
'install': true,
'dependencies': arch_deps + deps,
'link_language': link_language,
'link_depends': [block_syms, qemu_syms],
'link_args': link_args + cc.get_supported_link_arguments(['-Wl,-U,_qemu_main']),
'gnu_symbol_visibility': 'default'
}
else
build_lib_args = {
'target_type': 'static_library',
'install': false,
'dependencies': arch_deps,
'name_suffix': 'fa'
}
endif
lib = build_target('qemu-' + target,
lib = static_library('qemu-' + target,
sources: arch_srcs + genh,
dependencies: arch_deps,
objects: objects,
include_directories: target_inc,
c_args: c_args,
build_by_default: false,
kwargs: build_lib_args)
name_suffix: 'fa')
if target.endswith('-softmmu')
execs = [{
@@ -3556,17 +3503,6 @@ foreach target : target_dirs
'dependencies': []
}]
endif
if config_all.has_key('CONFIG_SHARED_LIBRARY_BUILD')
build_exe_args = {
'link_with': lib,
'link_args': link_args + cc.get_supported_link_arguments(['-Wl,--exclude-libs,ALL'])
}
else
build_exe_args = {
'objects': lib.extract_all_objects(recursive: true),
'link_args': link_args
}
endif
foreach exe: execs
exe_name = exe['name']
if targetos == 'darwin'
@@ -3577,10 +3513,11 @@ foreach target : target_dirs
install: true,
c_args: c_args,
dependencies: arch_deps + deps + exe['dependencies'],
objects: lib.extract_all_objects(recursive: true),
link_language: link_language,
link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
win_subsystem: exe['win_subsystem'],
kwargs: build_exe_args)
link_args: link_args,
win_subsystem: exe['win_subsystem'])
if targetos == 'darwin'
icon = 'pc-bios/qemu.rsrc'
@@ -3651,10 +3588,6 @@ if xkbcommon.found()
endif
if have_tools
if config_all.has_key('CONFIG_SHARED_LIBRARY_BUILD')
qemu_img_lib = shared_library('qemu-img', [files('qemu-img.c'), hxdep],
dependencies: [authz, block, crypto, io, qom, qemuutil], install: true)
endif
qemu_img = executable('qemu-img', [files('qemu-img.c'), hxdep],
dependencies: [authz, block, crypto, io, qom, qemuutil], install: true)
qemu_io = executable('qemu-io', files('qemu-io.c'),
@@ -3756,7 +3689,6 @@ endif
summary_info += {'Doc directory': get_option('prefix') / get_option('docdir')}
summary_info += {'Build directory': meson.current_build_dir()}
summary_info += {'Source path': meson.current_source_dir()}
summary_info += {'build shared lib': config_all.has_key('CONFIG_SHARED_LIBRARY_BUILD')}
summary_info += {'GIT submodules': config_host['GIT_SUBMODULES']}
summary(summary_info, bool_yn: true, section: 'Directories')
@@ -3901,8 +3833,6 @@ summary_info += {'TCG support': config_all.has_key('CONFIG_TCG')}
if config_all.has_key('CONFIG_TCG')
if get_option('tcg_interpreter')
summary_info += {'TCG backend': 'TCI (TCG with bytecode interpreter, slow)'}
elif get_option('tcg_threaded_interpreter')
summary_info += {'TCG backend': 'TCTI (TCG with threaded-dispatch bytecode interpreter, experimental and slow; but faster than TCI)'}
else
summary_info += {'TCG backend': 'native (@0@)'.format(cpu)}
endif
@@ -3919,7 +3849,6 @@ summary(summary_info, bool_yn: true, section: 'Targets and accelerators')
# Block layer
summary_info = {}
summary_info += {'libucontext support': ucontext.found()}
summary_info += {'coroutine backend': config_host['CONFIG_COROUTINE_BACKEND']}
summary_info += {'coroutine pool': have_coroutine_pool}
if have_block
-6
View File
@@ -72,8 +72,6 @@ option('whpx', type: 'feature', value: 'auto',
description: 'WHPX acceleration support')
option('hvf', type: 'feature', value: 'auto',
description: 'HVF acceleration support')
option('hvf_private', type: 'boolean', value: 'false',
description: 'HVF private features (entitlements required)')
option('nvmm', type: 'feature', value: 'auto',
description: 'NVMM acceleration support')
option('xen', type: 'feature', value: 'auto',
@@ -84,8 +82,6 @@ option('tcg', type: 'feature', value: 'enabled',
description: 'TCG support')
option('tcg_interpreter', type: 'boolean', value: false,
description: 'TCG with bytecode interpreter (slow)')
option('tcg_threaded_interpreter', type: 'boolean', value: false,
description: 'TCG with threaded-dispatch bytecode interpreter (experimental and slow, but less slow than TCI)')
option('cfi', type: 'boolean', value: false,
description: 'Control-Flow Integrity (CFI)')
option('cfi_debug', type: 'boolean', value: false,
@@ -238,8 +234,6 @@ option('fuse', type: 'feature', value: 'auto',
description: 'FUSE block device export')
option('fuse_lseek', type : 'feature', value : 'auto',
description: 'SEEK_HOLE/SEEK_DATA support for FUSE exports')
option('ucontext', type : 'feature', value : 'disabled',
description: 'libucontext support')
option('trace_backends', type: 'array', value: ['log'],
choices: ['dtrace', 'ftrace', 'log', 'nop', 'simple', 'syslog', 'ust'],
+6 -3
View File
@@ -1765,13 +1765,15 @@ out:
static inline void populate_read_range(RAMBlock *block, ram_addr_t offset,
ram_addr_t size)
{
const ram_addr_t end = offset + size;
/*
* We read one byte of each page; this will preallocate page tables if
* required and populate the shared zeropage on MAP_PRIVATE anonymous memory
* where no page was populated yet. This might require adaption when
* supporting other mappings, like shmem.
*/
for (; offset < size; offset += block->page_size) {
for (; offset < end; offset += block->page_size) {
char tmp = *((char *)block->host + offset);
/* Don't optimize the read out */
@@ -1885,13 +1887,14 @@ int ram_write_tracking_start(void)
block->max_length, UFFDIO_REGISTER_MODE_WP, NULL)) {
goto fail;
}
block->flags |= RAM_UF_WRITEPROTECT;
memory_region_ref(block->mr);
/* Apply UFFD write protection to the block memory range */
if (uffd_change_protection(rs->uffdio_fd, block->host,
block->max_length, true, false)) {
goto fail;
}
block->flags |= RAM_UF_WRITEPROTECT;
memory_region_ref(block->mr);
trace_ram_write_tracking_ramblock_start(block->idstr, block->page_size,
block->host, block->max_length);
+14 -15
View File
@@ -88,16 +88,15 @@ static bool validate_options(const Netdev *netdev, Error **errp)
return false;
}
if (__builtin_available(macOS 11, *)) {
// clang requires a true branch
} else {
if (options->has_isolated) {
error_setg(errp,
"vmnet-bridged.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
#if !defined(MAC_OS_VERSION_11_0) || \
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_11_0
if (options->has_isolated) {
error_setg(errp,
"vmnet-bridged.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
#endif
return true;
}
@@ -116,12 +115,12 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
vmnet_shared_interface_name_key,
options->ifname);
if (__builtin_available(macOS 11, *)) {
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
}
#if defined(MAC_OS_VERSION_11_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
#endif
return if_desc;
}
+13 -35
View File
@@ -17,7 +17,6 @@
#include "clients.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
#include "sysemu/runstate.h"
#include <vmnet/vmnet.h>
#include <dispatch/dispatch.h>
@@ -243,35 +242,6 @@ static void vmnet_bufs_init(VmnetState *s)
}
}
/**
* Called on state change to un-register/re-register handlers
*/
static void vmnet_vm_state_change_cb(void *opaque, bool running, RunState state)
{
VmnetState *s = opaque;
if (running) {
vmnet_interface_set_event_callback(
s->vmnet_if,
VMNET_INTERFACE_PACKETS_AVAILABLE,
s->if_queue,
^(interface_event_t event_id, xpc_object_t event) {
assert(event_id == VMNET_INTERFACE_PACKETS_AVAILABLE);
/*
* This function is being called from a non qemu thread, so
* we only schedule a BH, and do the rest of the io completion
* handling from vmnet_send_bh() which runs in a qemu context.
*/
qemu_bh_schedule(s->send_bh);
});
} else {
vmnet_interface_set_event_callback(
s->vmnet_if,
VMNET_INTERFACE_PACKETS_AVAILABLE,
NULL,
NULL);
}
}
int vmnet_if_create(NetClientState *nc,
xpc_object_t if_desc,
@@ -359,9 +329,19 @@ int vmnet_if_create(NetClientState *nc,
s->packets_send_current_pos = 0;
s->packets_send_end_pos = 0;
vmnet_vm_state_change_cb(s, 1, RUN_STATE_RUNNING);
s->change = qemu_add_vm_change_state_handler(vmnet_vm_state_change_cb, s);
vmnet_interface_set_event_callback(
s->vmnet_if,
VMNET_INTERFACE_PACKETS_AVAILABLE,
s->if_queue,
^(interface_event_t event_id, xpc_object_t event) {
assert(event_id == VMNET_INTERFACE_PACKETS_AVAILABLE);
/*
* This function is being called from a non qemu thread, so
* we only schedule a BH, and do the rest of the io completion
* handling from vmnet_send_bh() which runs in a qemu context.
*/
qemu_bh_schedule(s->send_bh);
});
return 0;
}
@@ -376,8 +356,6 @@ void vmnet_cleanup_common(NetClientState *nc)
return;
}
vmnet_vm_state_change_cb(s, 0, RUN_STATE_SHUTDOWN);
qemu_del_vm_change_state_handler(s->change);
if_stopped_sem = dispatch_semaphore_create(0);
vmnet_stop_interface(
s->vmnet_if,
+35 -31
View File
@@ -22,28 +22,30 @@ static bool validate_options(const Netdev *netdev, Error **errp)
{
const NetdevVmnetHostOptions *options = &(netdev->u.vmnet_host);
if (__builtin_available(macOS 11, *)) {
QemuUUID net_uuid;
if (options->has_net_uuid &&
qemu_uuid_parse(options->net_uuid, &net_uuid) < 0) {
error_setg(errp, "Invalid UUID provided in 'net-uuid'");
return false;
}
} else {
if (options->has_isolated) {
error_setg(errp,
"vmnet-host.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
#if defined(MAC_OS_VERSION_11_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
if (options->has_net_uuid) {
error_setg(errp,
"vmnet-host.net-uuid feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
QemuUUID net_uuid;
if (options->has_net_uuid &&
qemu_uuid_parse(options->net_uuid, &net_uuid) < 0) {
error_setg(errp, "Invalid UUID provided in 'net-uuid'");
return false;
}
#else
if (options->has_isolated) {
error_setg(errp,
"vmnet-host.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
if (options->has_net_uuid) {
error_setg(errp,
"vmnet-host.net-uuid feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
#endif
if ((options->has_start_address ||
options->has_end_address ||
@@ -69,19 +71,21 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
vmnet_operation_mode_key,
VMNET_HOST_MODE);
if (__builtin_available(macOS 11, *)) {
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
#if defined(MAC_OS_VERSION_11_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
QemuUUID net_uuid;
if (options->has_net_uuid) {
qemu_uuid_parse(options->net_uuid, &net_uuid);
xpc_dictionary_set_uuid(if_desc,
vmnet_network_identifier_key,
net_uuid.data);
}
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
QemuUUID net_uuid;
if (options->has_net_uuid) {
qemu_uuid_parse(options->net_uuid, &net_uuid);
xpc_dictionary_set_uuid(if_desc,
vmnet_network_identifier_key,
net_uuid.data);
}
#endif
if (options->has_start_address) {
xpc_dictionary_set_string(if_desc,
+16 -16
View File
@@ -21,16 +21,15 @@ static bool validate_options(const Netdev *netdev, Error **errp)
{
const NetdevVmnetSharedOptions *options = &(netdev->u.vmnet_shared);
if (__builtin_available(macOS 11, *)) {
// clang requires a true branch
} else {
if (options->has_isolated) {
error_setg(errp,
"vmnet-shared.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
#if !defined(MAC_OS_VERSION_11_0) || \
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_11_0
if (options->has_isolated) {
error_setg(errp,
"vmnet-shared.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
#endif
if ((options->has_start_address ||
options->has_end_address ||
@@ -77,13 +76,14 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
options->subnet_mask);
}
if (__builtin_available(macOS 11, *)) {
xpc_dictionary_set_bool(
if_desc,
vmnet_enable_isolation_key,
options->isolated
);
}
#if defined(MAC_OS_VERSION_11_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
xpc_dictionary_set_bool(
if_desc,
vmnet_enable_isolation_key,
options->isolated
);
#endif
return if_desc;
}
-2
View File
@@ -46,8 +46,6 @@ typedef struct VmnetState {
int packets_send_end_pos;
struct iovec iov_buf[VMNET_PACKETS_LIMIT];
VMChangeStateEntry *change;
} VmnetState;
const char *vmnet_status_map_str(vmnet_return_t status);
Loaded 100 of 177 files, more files were not shown because too many files have changed in this diff. Show more