diff mbox series

[v2,2/2] qtest/fuzz: Remove uses of 'first_cpu'

Message ID 20241211233727.98923-3-philmd@linaro.org (mailing list archive)
State New
Headers show
Series qtest: Remove uses of 'first_cpu' | expand

Commit Message

Philippe Mathieu-Daudé Dec. 11, 2024, 11:37 p.m. UTC
There is no vCPU within the QTest accelerator (well, they
are stubs doing nothing, see dummy_cpu_thread_fn).

Directly access the global &address_space_memory to reduce
access to the 'first_cpu' global (which is meaningless in
a heterogeneous emulation setup).

Cast the returned value to (void) to explicit we don't
care about invalid accesses.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
We will likely remove &address_space_memory too, but one
global at a time. first_cpu is more annoying so I'm starting
with it.
---
 tests/qtest/fuzz/generic_fuzz.c   |  3 +-
 tests/qtest/fuzz/qtest_wrappers.c | 53 ++++++++++++++++---------------
 2 files changed, 29 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/tests/qtest/fuzz/generic_fuzz.c b/tests/qtest/fuzz/generic_fuzz.c
index d107a496da6..a72a3e99f7d 100644
--- a/tests/qtest/fuzz/generic_fuzz.c
+++ b/tests/qtest/fuzz/generic_fuzz.c
@@ -20,6 +20,7 @@ 
 #include "tests/qtest/libqos/pci-pc.h"
 #include "fuzz.h"
 #include "string.h"
+#include "exec/address-spaces.h"
 #include "exec/memory.h"
 #include "exec/ramblock.h"
 #include "hw/qdev-core.h"
@@ -239,7 +240,7 @@  void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr)
     MemoryRegion *mr1;
     while (len > 0) {
         l = len;
-        mr1 = address_space_translate(first_cpu->as,
+        mr1 = address_space_translate(&address_space_memory,
                                       addr, &addr1, &l, true,
                                       MEMTXATTRS_UNSPECIFIED);
 
diff --git a/tests/qtest/fuzz/qtest_wrappers.c b/tests/qtest/fuzz/qtest_wrappers.c
index 0580f8df860..a2d562dc7ed 100644
--- a/tests/qtest/fuzz/qtest_wrappers.c
+++ b/tests/qtest/fuzz/qtest_wrappers.c
@@ -13,6 +13,7 @@ 
 
 #include "qemu/osdep.h"
 #include "hw/core/cpu.h"
+#include "exec/address-spaces.h"
 #include "exec/ioport.h"
 
 #include "fuzz.h"
@@ -107,8 +108,8 @@  uint8_t __wrap_qtest_readb(QTestState *s, uint64_t addr)
 {
     uint8_t value;
     if (!serialize) {
-        address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            &value, 1);
+        (void)address_space_read(&address_space_memory, addr,
+                                 MEMTXATTRS_UNSPECIFIED, &value, 1);
         return value;
     } else {
         return __real_qtest_readb(s, addr);
@@ -119,8 +120,8 @@  uint16_t __wrap_qtest_readw(QTestState *s, uint64_t addr)
 {
     uint16_t value;
     if (!serialize) {
-        address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            &value, 2);
+        (void)address_space_read(&address_space_memory, addr,
+                                 MEMTXATTRS_UNSPECIFIED, &value, 2);
         return value;
     } else {
         return __real_qtest_readw(s, addr);
@@ -131,8 +132,8 @@  uint32_t __wrap_qtest_readl(QTestState *s, uint64_t addr)
 {
     uint32_t value;
     if (!serialize) {
-        address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            &value, 4);
+        (void)address_space_read(&address_space_memory, addr,
+                                 MEMTXATTRS_UNSPECIFIED, &value, 4);
         return value;
     } else {
         return __real_qtest_readl(s, addr);
@@ -143,8 +144,8 @@  uint64_t __wrap_qtest_readq(QTestState *s, uint64_t addr)
 {
     uint64_t value;
     if (!serialize) {
-        address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            &value, 8);
+        (void)address_space_read(&address_space_memory, addr,
+                                 MEMTXATTRS_UNSPECIFIED, &value, 8);
         return value;
     } else {
         return __real_qtest_readq(s, addr);
@@ -154,8 +155,8 @@  uint64_t __wrap_qtest_readq(QTestState *s, uint64_t addr)
 void __wrap_qtest_writeb(QTestState *s, uint64_t addr, uint8_t value)
 {
     if (!serialize) {
-        address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            &value, 1);
+        (void)address_space_write(&address_space_memory, addr,
+                                  MEMTXATTRS_UNSPECIFIED, &value, 1);
     } else {
         __real_qtest_writeb(s, addr, value);
     }
@@ -164,8 +165,8 @@  void __wrap_qtest_writeb(QTestState *s, uint64_t addr, uint8_t value)
 void __wrap_qtest_writew(QTestState *s, uint64_t addr, uint16_t value)
 {
     if (!serialize) {
-        address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            &value, 2);
+        (void)address_space_write(&address_space_memory, addr,
+                                  MEMTXATTRS_UNSPECIFIED, &value, 2);
     } else {
         __real_qtest_writew(s, addr, value);
     }
@@ -174,8 +175,8 @@  void __wrap_qtest_writew(QTestState *s, uint64_t addr, uint16_t value)
 void __wrap_qtest_writel(QTestState *s, uint64_t addr, uint32_t value)
 {
     if (!serialize) {
-        address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            &value, 4);
+        (void)address_space_write(&address_space_memory, addr,
+                                  MEMTXATTRS_UNSPECIFIED, &value, 4);
     } else {
         __real_qtest_writel(s, addr, value);
     }
@@ -184,8 +185,8 @@  void __wrap_qtest_writel(QTestState *s, uint64_t addr, uint32_t value)
 void __wrap_qtest_writeq(QTestState *s, uint64_t addr, uint64_t value)
 {
     if (!serialize) {
-        address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            &value, 8);
+        (void)address_space_write(&address_space_memory, addr,
+                                  MEMTXATTRS_UNSPECIFIED, &value, 8);
     } else {
         __real_qtest_writeq(s, addr, value);
     }
@@ -194,8 +195,8 @@  void __wrap_qtest_writeq(QTestState *s, uint64_t addr, uint64_t value)
 void __wrap_qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size)
 {
     if (!serialize) {
-        address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
-                           size);
+        (void)address_space_read(&address_space_memory, addr,
+                                 MEMTXATTRS_UNSPECIFIED, data, size);
     } else {
         __real_qtest_memread(s, addr, data, size);
     }
@@ -204,8 +205,8 @@  void __wrap_qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size)
 void __wrap_qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size)
 {
     if (!serialize) {
-        address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
-                           size);
+        (void)address_space_read(&address_space_memory, addr,
+                                 MEMTXATTRS_UNSPECIFIED, data, size);
     } else {
         __real_qtest_bufread(s, addr, data, size);
     }
@@ -215,8 +216,8 @@  void __wrap_qtest_memwrite(QTestState *s, uint64_t addr, const void *data,
                            size_t size)
 {
     if (!serialize) {
-        address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            data, size);
+        (void)address_space_write(&address_space_memory, addr,
+                                  MEMTXATTRS_UNSPECIFIED, data, size);
     } else {
         __real_qtest_memwrite(s, addr, data, size);
     }
@@ -226,8 +227,8 @@  void __wrap_qtest_bufwrite(QTestState *s, uint64_t addr,
                     const void *data, size_t size)
 {
     if (!serialize) {
-        address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            data, size);
+        (void)address_space_write(&address_space_memory, addr,
+                                  MEMTXATTRS_UNSPECIFIED, data, size);
     } else {
         __real_qtest_bufwrite(s, addr, data, size);
     }
@@ -239,8 +240,8 @@  void __wrap_qtest_memset(QTestState *s, uint64_t addr,
     if (!serialize) {
         data = malloc(size);
         memset(data, patt, size);
-        address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                            data, size);
+        (void)address_space_write(&address_space_memory, addr,
+                                  MEMTXATTRS_UNSPECIFIED, data, size);
     } else {
         __real_qtest_memset(s, addr, patt, size);
     }