Browse Source
- mark s390x runner system tests as allow_fail
- build semihosting once
- add register write support to plugins
- add virtual memory write support to plugins
- add harder memory read/write support to plugins
- add patcher plugin and tests
- re-stock virtio-gpu MAINTAINERS
- fix context init for Venus fences
-----BEGIN PGP SIGNATURE-----
iQEzBAABCgAdFiEEZoWumedRZ7yvyN81+9DbCVqeKkQFAmhk+PkACgkQ+9DbCVqe
KkRMbAgAgs7sufzfJF+408BpYfciArU/XL0ZbfZnvRdayJaw6hIe9q4ySe+w5xVe
jzSnc/eI3ESl7+Id0eUlC4p7faxgjj/+FoAgCcFSx2Dzt6VQ1WRCMFxc5Z+h/P5i
vm5Zf2vr38RHyIC/A8BRJWmmpF0NtXwYDaVyV92r+qYClBi6RyJ6+Ooio0MEVdzl
62/2bGIsf+BzXQOiHHIyki86GS/9svBNMDbCt+4X1cTtoSArsTj9qJ0CSBNM3BFS
/EJ2e6Hbc9p/8lNPal48/P5L/jN3LJDiQvG+PmxH91gYjsAb6kD4GvKvgT/L6Iai
lD1YrL7vzgiPJWveESe3i7PWMolnCw==
=q7Vs
-----END PGP SIGNATURE-----
Merge tag 'pull-10.1-maintainer-june-2025-020725-1' of https://gitlab.com/stsquad/qemu into staging
Maintainer updates for June (gitlab, semihosting, plugins, virtio-gpu)
- mark s390x runner system tests as allow_fail
- build semihosting once
- add register write support to plugins
- add virtual memory write support to plugins
- add harder memory read/write support to plugins
- add patcher plugin and tests
- re-stock virtio-gpu MAINTAINERS
- fix context init for Venus fences
* tag 'pull-10.1-maintainer-june-2025-020725-1' of https://gitlab.com/stsquad/qemu:
virtio-gpu: support context init multiple timeline
MAINTAINERS: add Akihiko and Dmitry as reviewers
MAINTAINERS: add myself to virtio-gpu for Odd Fixes
plugins: Update plugin version and add notes
plugins: Add patcher plugin and test
tests/tcg: Remove copy-pasted notes and from i386 and add x86_64 system tests to tests
plugins: Add memory hardware address read/write API
plugins: Add memory virtual address write API
plugins: Add enforcement of QEMU_PLUGIN_CB flags in register R/W callbacks
plugins: Add register write API
gdbstub: Expose gdb_write_register function to consumers of gdbstub
semihosting/uaccess: Compile once
semihosting/uaccess: Remove uses of target_ulong type
tests/functional: Add PCI hotplug test for aarch64
gitlab: mark s390x-system to allow failures
Conflicts:
tests/functional/meson.build
Context conflict with commit 7bc86ccbb5 ("tests/functional: test
device passthrough on aarch64"), keep both changes to
tests_aarch64_system_thorough[].
pull/292/head
22 changed files with 863 additions and 42 deletions
@ -0,0 +1,72 @@ |
|||
#!/usr/bin/env python3 |
|||
# |
|||
# The test hotplugs a PCI device and checks it on a Linux guest. |
|||
# |
|||
# Copyright (c) 2025 Linaro Ltd. |
|||
# |
|||
# Author: |
|||
# Gustavo Romero <gustavo.romero@linaro.org> |
|||
# |
|||
# SPDX-License-Identifier: GPL-2.0-or-later |
|||
|
|||
from qemu_test import LinuxKernelTest, Asset, exec_command_and_wait_for_pattern |
|||
from qemu_test import BUILD_DIR |
|||
|
|||
class HotplugPCI(LinuxKernelTest): |
|||
|
|||
ASSET_KERNEL = Asset( |
|||
('https://ftp.debian.org/debian/dists/stable/main/installer-arm64/' |
|||
'20230607+deb12u11/images/netboot/debian-installer/arm64/linux'), |
|||
'd92a60392ce1e379ca198a1a820899f8f0d39a62d047c41ab79492f81541a9d9') |
|||
|
|||
ASSET_INITRD = Asset( |
|||
('https://ftp.debian.org/debian/dists/stable/main/installer-arm64/' |
|||
'20230607+deb12u11/images/netboot/debian-installer/arm64/initrd.gz'), |
|||
'9f817f76951f3237bca8216bee35267bfb826815687f4b2fcdd5e6c2a917790c') |
|||
|
|||
def test_hotplug_pci(self): |
|||
|
|||
self.set_machine('virt') |
|||
|
|||
self.vm.add_args('-m', '512M', |
|||
'-cpu', 'cortex-a57', |
|||
'-append', |
|||
'console=ttyAMA0,115200 init=/bin/sh', |
|||
'-device', |
|||
'pcie-root-port,bus=pcie.0,chassis=1,slot=1,id=pcie.1', |
|||
'-bios', |
|||
self.build_file('pc-bios', 'edk2-aarch64-code.fd')) |
|||
|
|||
# BusyBox prompt |
|||
prompt = "~ #" |
|||
self.launch_kernel(self.ASSET_KERNEL.fetch(), |
|||
self.ASSET_INITRD.fetch(), |
|||
wait_for=prompt) |
|||
|
|||
# Check for initial state: 2 network adapters, lo and enp0s1. |
|||
exec_command_and_wait_for_pattern(self, |
|||
'ls /sys/class/net | wc -l', |
|||
'2') |
|||
|
|||
# Hotplug one network adapter to the root port, i.e. pcie.1 bus. |
|||
self.vm.cmd('device_add', |
|||
driver='virtio-net-pci', |
|||
bus='pcie.1', |
|||
addr=0, |
|||
id='na') |
|||
# Wait for the kernel to recognize the new device. |
|||
self.wait_for_console_pattern('virtio-pci') |
|||
self.wait_for_console_pattern('virtio_net') |
|||
|
|||
# Check if there is a new network adapter. |
|||
exec_command_and_wait_for_pattern(self, |
|||
'ls /sys/class/net | wc -l', |
|||
'3') |
|||
|
|||
self.vm.cmd('device_del', id='na') |
|||
exec_command_and_wait_for_pattern(self, |
|||
'ls /sys/class/net | wc -l', |
|||
'2') |
|||
|
|||
if __name__ == '__main__': |
|||
LinuxKernelTest.main() |
|||
@ -0,0 +1,251 @@ |
|||
/*
|
|||
* SPDX-License-Identifier: GPL-2.0-or-later |
|||
* |
|||
* This plugin patches instructions matching a pattern to a different |
|||
* instruction as they execute |
|||
* |
|||
*/ |
|||
|
|||
#include "glib.h" |
|||
#include "glibconfig.h" |
|||
|
|||
#include <qemu-plugin.h> |
|||
#include <string.h> |
|||
#include <stdio.h> |
|||
|
|||
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; |
|||
|
|||
static bool use_hwaddr; |
|||
static GByteArray *target_data; |
|||
static GByteArray *patch_data; |
|||
|
|||
/**
|
|||
* Parse a string of hexadecimal digits into a GByteArray. The string must be |
|||
* even length |
|||
*/ |
|||
static GByteArray *str_to_bytes(const char *str) |
|||
{ |
|||
size_t len = strlen(str); |
|||
|
|||
if (len == 0 || len % 2 != 0) { |
|||
return NULL; |
|||
} |
|||
|
|||
GByteArray *bytes = g_byte_array_new(); |
|||
char byte[3] = {0}; |
|||
guint8 value = 0; |
|||
|
|||
for (size_t i = 0; i < len; i += 2) { |
|||
byte[0] = str[i]; |
|||
byte[1] = str[i + 1]; |
|||
value = (guint8)g_ascii_strtoull(byte, NULL, 16); |
|||
g_byte_array_append(bytes, &value, 1); |
|||
} |
|||
|
|||
return bytes; |
|||
} |
|||
|
|||
static void patch_hwaddr(unsigned int vcpu_index, void *userdata) |
|||
{ |
|||
uintptr_t addr = (uintptr_t) userdata; |
|||
g_autoptr(GString) str = g_string_new(NULL); |
|||
g_string_printf(str, "patching: @0x%" |
|||
PRIxPTR "\n", |
|||
addr); |
|||
qemu_plugin_outs(str->str); |
|||
|
|||
enum qemu_plugin_hwaddr_operation_result result = |
|||
qemu_plugin_write_memory_hwaddr(addr, patch_data); |
|||
|
|||
|
|||
if (result != QEMU_PLUGIN_HWADDR_OPERATION_OK) { |
|||
g_autoptr(GString) errmsg = g_string_new(NULL); |
|||
g_string_printf(errmsg, "Failed to write memory: %d\n", result); |
|||
qemu_plugin_outs(errmsg->str); |
|||
return; |
|||
} |
|||
|
|||
GByteArray *read_data = g_byte_array_new(); |
|||
|
|||
result = qemu_plugin_read_memory_hwaddr(addr, read_data, |
|||
patch_data->len); |
|||
|
|||
qemu_plugin_outs("Reading memory...\n"); |
|||
|
|||
if (result != QEMU_PLUGIN_HWADDR_OPERATION_OK) { |
|||
g_autoptr(GString) errmsg = g_string_new(NULL); |
|||
g_string_printf(errmsg, "Failed to read memory: %d\n", result); |
|||
qemu_plugin_outs(errmsg->str); |
|||
return; |
|||
} |
|||
|
|||
if (memcmp(patch_data->data, read_data->data, patch_data->len) != 0) { |
|||
qemu_plugin_outs("Failed to read back written data\n"); |
|||
} |
|||
|
|||
qemu_plugin_outs("Success!\n"); |
|||
|
|||
return; |
|||
} |
|||
|
|||
static void patch_vaddr(unsigned int vcpu_index, void *userdata) |
|||
{ |
|||
uintptr_t addr = (uintptr_t) userdata; |
|||
uint64_t hwaddr = 0; |
|||
if (!qemu_plugin_translate_vaddr(addr, &hwaddr)) { |
|||
qemu_plugin_outs("Failed to translate vaddr\n"); |
|||
return; |
|||
} |
|||
g_autoptr(GString) str = g_string_new(NULL); |
|||
g_string_printf(str, "patching: @0x%" |
|||
PRIxPTR " hw: @0x%" PRIx64 "\n", |
|||
addr, hwaddr); |
|||
qemu_plugin_outs(str->str); |
|||
|
|||
qemu_plugin_outs("Writing memory (vaddr)...\n"); |
|||
|
|||
if (!qemu_plugin_write_memory_vaddr(addr, patch_data)) { |
|||
qemu_plugin_outs("Failed to write memory\n"); |
|||
return; |
|||
} |
|||
|
|||
qemu_plugin_outs("Reading memory (vaddr)...\n"); |
|||
|
|||
g_autoptr(GByteArray) read_data = g_byte_array_new(); |
|||
|
|||
if (!qemu_plugin_read_memory_vaddr(addr, read_data, patch_data->len)) { |
|||
qemu_plugin_outs("Failed to read memory\n"); |
|||
return; |
|||
} |
|||
|
|||
if (memcmp(patch_data->data, read_data->data, patch_data->len) != 0) { |
|||
qemu_plugin_outs("Failed to read back written data\n"); |
|||
} |
|||
|
|||
qemu_plugin_outs("Success!\n"); |
|||
|
|||
return; |
|||
} |
|||
|
|||
/*
|
|||
* Callback on translation of a translation block. |
|||
*/ |
|||
static void vcpu_tb_trans_cb(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) |
|||
{ |
|||
g_autoptr(GByteArray) insn_data = g_byte_array_new(); |
|||
uintptr_t addr = 0; |
|||
|
|||
for (size_t i = 0; i < qemu_plugin_tb_n_insns(tb); i++) { |
|||
struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); |
|||
uint64_t vaddr = qemu_plugin_insn_vaddr(insn); |
|||
|
|||
if (use_hwaddr) { |
|||
uint64_t hwaddr = 0; |
|||
if (!qemu_plugin_translate_vaddr(vaddr, &hwaddr)) { |
|||
qemu_plugin_outs("Failed to translate vaddr\n"); |
|||
continue; |
|||
} |
|||
/*
|
|||
* As we cannot emulate 64 bit systems on 32 bit hosts we |
|||
* should never see the top bits set, hence we can safely |
|||
* cast to uintptr_t. |
|||
*/ |
|||
g_assert(hwaddr <= UINTPTR_MAX); |
|||
addr = (uintptr_t) hwaddr; |
|||
} else { |
|||
g_assert(vaddr <= UINTPTR_MAX); |
|||
addr = (uintptr_t) vaddr; |
|||
} |
|||
|
|||
g_byte_array_set_size(insn_data, qemu_plugin_insn_size(insn)); |
|||
qemu_plugin_insn_data(insn, insn_data->data, insn_data->len); |
|||
|
|||
if (insn_data->len >= target_data->len && |
|||
!memcmp(insn_data->data, target_data->data, |
|||
MIN(target_data->len, insn_data->len))) { |
|||
if (use_hwaddr) { |
|||
qemu_plugin_register_vcpu_tb_exec_cb(tb, patch_hwaddr, |
|||
QEMU_PLUGIN_CB_NO_REGS, |
|||
(void *) addr); |
|||
} else { |
|||
qemu_plugin_register_vcpu_tb_exec_cb(tb, patch_vaddr, |
|||
QEMU_PLUGIN_CB_NO_REGS, |
|||
(void *) addr); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
static void usage(void) |
|||
{ |
|||
fprintf(stderr, "Usage: <lib>,target=<bytes>,patch=<new_bytes>" |
|||
"[,use_hwaddr=true|false]"); |
|||
} |
|||
|
|||
/*
|
|||
* Called when the plugin is installed |
|||
*/ |
|||
QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, |
|||
const qemu_info_t *info, int argc, |
|||
char **argv) |
|||
{ |
|||
|
|||
use_hwaddr = true; |
|||
target_data = NULL; |
|||
patch_data = NULL; |
|||
|
|||
if (argc > 4) { |
|||
usage(); |
|||
return -1; |
|||
} |
|||
|
|||
for (size_t i = 0; i < argc; i++) { |
|||
char *opt = argv[i]; |
|||
g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); |
|||
if (g_strcmp0(tokens[0], "use_hwaddr") == 0) { |
|||
if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &use_hwaddr)) { |
|||
fprintf(stderr, |
|||
"Failed to parse boolean argument use_hwaddr\n"); |
|||
return -1; |
|||
} |
|||
} else if (g_strcmp0(tokens[0], "target") == 0) { |
|||
target_data = str_to_bytes(tokens[1]); |
|||
if (!target_data) { |
|||
fprintf(stderr, |
|||
"Failed to parse target bytes.\n"); |
|||
return -1; |
|||
} |
|||
} else if (g_strcmp0(tokens[0], "patch") == 0) { |
|||
patch_data = str_to_bytes(tokens[1]); |
|||
if (!patch_data) { |
|||
fprintf(stderr, "Failed to parse patch bytes.\n"); |
|||
return -1; |
|||
} |
|||
} else { |
|||
fprintf(stderr, "Unknown argument: %s\n", tokens[0]); |
|||
usage(); |
|||
return -1; |
|||
} |
|||
} |
|||
|
|||
if (!target_data) { |
|||
fprintf(stderr, "target argument is required\n"); |
|||
usage(); |
|||
return -1; |
|||
} |
|||
|
|||
if (!patch_data) { |
|||
fprintf(stderr, "patch argument is required\n"); |
|||
usage(); |
|||
return -1; |
|||
} |
|||
|
|||
if (target_data->len != patch_data->len) { |
|||
fprintf(stderr, "Target and patch data must be the same length\n"); |
|||
return -1; |
|||
} |
|||
|
|||
qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans_cb); |
|||
|
|||
return 0; |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
/*
|
|||
* SPDX-License-Identifier: GPL-2.0-or-later |
|||
* |
|||
* This test target increments a value 100 times. The patcher converts the |
|||
* inc instruction to a nop, so it only increments the value once. |
|||
* |
|||
*/ |
|||
#include <minilib.h> |
|||
|
|||
int main(void) |
|||
{ |
|||
ml_printf("Running test...\n"); |
|||
unsigned int x = 0; |
|||
for (int i = 0; i < 100; i++) { |
|||
asm volatile ( |
|||
"inc %[x]" |
|||
: [x] "+a" (x) |
|||
); |
|||
} |
|||
ml_printf("Value: %d\n", x); |
|||
return 0; |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
#!/usr/bin/env python3 |
|||
# |
|||
# validate-patch.py: check the patch applies |
|||
# |
|||
# This program takes two inputs: |
|||
# - the plugin output |
|||
# - the binary output |
|||
# |
|||
# Copyright (C) 2024 |
|||
# |
|||
# SPDX-License-Identifier: GPL-2.0-or-later |
|||
|
|||
import sys |
|||
from argparse import ArgumentParser |
|||
|
|||
def main() -> None: |
|||
""" |
|||
Process the arguments, injest the program and plugin out and |
|||
verify they match up and report if they do not. |
|||
""" |
|||
parser = ArgumentParser(description="Validate patch") |
|||
parser.add_argument('test_output', |
|||
help="The output from the test itself") |
|||
parser.add_argument('plugin_output', |
|||
help="The output from plugin") |
|||
args = parser.parse_args() |
|||
|
|||
with open(args.test_output, 'r') as f: |
|||
test_data = f.read() |
|||
with open(args.plugin_output, 'r') as f: |
|||
plugin_data = f.read() |
|||
if "Value: 1" in test_data: |
|||
sys.exit(0) |
|||
else: |
|||
sys.exit(1) |
|||
|
|||
if __name__ == "__main__": |
|||
main() |
|||
|
|||
Loading…
Reference in new issue