qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen)
@ 2025-10-05 17:36 Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 39/58] hw/usb/hcd-uhci: don't assert for SETUP to non-0 endpoint Michael Tokarev
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Michael Tokarev

The following patches are queued for QEMU stable v10.0.5:

  https://gitlab.com/qemu-project/qemu/-/commits/staging-10.0

Patch freeze is 2025-10-06 (frozen), and the release is planned for 2025-10-08:

  https://wiki.qemu.org/Planning/10.0

Please respond here or CC qemu-stable@nongnu.org on any additional patches
you think should (or shouldn't) be included in the release.

The changes which are staging for inclusion, with the original commit hash
from master branch, are given below the bottom line.

Thanks!

/mjt

--------------------------------------
01* 256df51e7272 WANG Rui:
   target/loongarch: Add CRC feature flag and use it to gate CRC instructions
02* 96e7448c1f82 WANG Rui:
   target/loongarch: Guard 64-bit-only insn translation with TRANS64 macro
03* 38dd513263d8 Thomas Huth:
   ui/vnc: Fix crash when specifying [vnc] without id in the config file
04* 1e343714bfc0 John Snow:
   python: backport 'kick event queue on legacy event_pull()'
05* f9d2e0a3bd7b John Snow:
   python: backport 'drop Python3.6 workarounds'
06* 0408b8d7a086 John Snow:
   python: backport 'Use @asynciocontextmanager'
07* fcaeeb7653d2 John Snow:
   python: backport 'qmp-shell-wrap: handle missing binary gracefully'
08* fd0ed46d4eff John Snow:
   python: backport 'qmp-tui: Do not crash if optional dependencies are not met'
09* 5d99044d09db John Snow:
   python: backport 'Remove deprecated get_event_loop calls'
10* 85f223e5b031 John Snow:
   python: backport 'avoid creating additional event loops per thread'
11* 82c7cb93c750 Daniel P. Berrangé:
   iotests: drop compat for old version context manager
12* 6ccb48ffc19f Daniel P. Berrangé:
   python: ensure QEMUQtestProtocol closes its socket
13* d4d0ebfcc926 Daniel P. Berrangé:
   iotests/147: ensure temporary sockets are closed before exiting
14* 2b2fb25c2aaf Daniel P. Berrangé:
   iotests/151: ensure subprocesses are cleaned up
15* 9a494d835386 Daniel P. Berrangé:
   iotests/check: always enable all python warnings
16* a11d1847d5ef Alex Bennée:
   .gitmodules: move u-boot mirrors to qemu-project-mirrors
17* 8b182b6600 Michael Tokarev:
   tests/docker/dockerfiles/python.docker: pull fedora:40 image instead of 
   fedora:latest
18* eb8f7292e131 Paolo Bonzini:
   ci: run RISC-V cross jobs by default
19* 6b3fad084fc4 Paolo Bonzini:
   rust: hpet: fix new warning
20* aaf042299acf Stéphane Graber:
   hw/usb/network: Remove hardcoded 0x40 prefix in STRING_ETHADDR response
21* 0516f4b70264 Xiaoyao Li:
   i386/cpu: Enable SMM cpu address space under KVM
22* 591f817d819f Xiaoyao Li:
   target/i386: Define enum X86ASIdx for x86's address spaces
23* 4c8f69b94839 Xiaoyao Li:
   multiboot: Fix the split lock
24* db05b0d21ec1 Paolo Bonzini:
   linux-user: avoid -Werror=int-in-bool-context
25* b7cd0a1821ad Richard Henderson:
   target/sparc: Allow TRANS macro with no extra arguments
26* b6cdd6c60505 Richard Henderson:
   target/sparc: Loosen decode of STBAR for v8
27* 49d669ccf33a Richard Henderson:
   target/sparc: Loosen decode of RDY for v7
28* a0345f628394 Richard Henderson:
   target/sparc: Loosen decode of RDPSR for v7
29* dc9678cc9725 Richard Henderson:
   target/sparc: Loosen decode of RDWIM for v7
30* 6ff52f9dee06 Richard Henderson:
   target/sparc: Loosen decode of RDTBR for v7
31* df663ac0a4e5 Richard Henderson:
   target/sparc: Relax decode of rs2_or_imm for v7
32* e4a1b308b27c Peter Maydell:
   hw/pci-host/dino: Don't call pci_register_root_bus() in init
33* 76d2b8d42adb Peter Maydell:
   hw/pci-host/astro: Don't call pci_regsiter_root_bus() in init
34* a50347a4145f WANG Rui:
   tcg/optimize: Fix folding of vector bitsel
35* fd34f56fe886 Peter Maydell:
   .gitlab-ci.d/buildtest.yml: Unset CI_COMMIT_DESCRIPTION for htags
36* 4f1ebc7712a7 Thomas Huth:
   tests: Fix "make check-functional" for targets without thorough tests
37* 03fe6659803f Richard Henderson:
   accel/tcg: Properly unlink a TB linked to itself
38* e13e1195db8a Richard Henderson:
   tests/tcg/multiarch: Add tb-link test
39 d0af3cd0274e Peter Maydell:
   hw/usb/hcd-uhci: don't assert for SETUP to non-0 endpoint
40 f5738aedc217 Fabian Vogt:
   hw/intc/xics: Add missing call to register vmstate_icp_server
41 6285eebd3a5f Harsh Prateek Bora:
   ppc/spapr: init lrdr-capapcity phys with ram size if maxmem not provided
42 e7ecb533ee0d Mohamed Akram:
   ui/spice: Fix abort on macOS
43 9163424c5098 Thomas Huth:
   ui/icons/qemu.svg: Add metadata information (author, license) to the logo
44 4f7528295b3e Andrew Jones:
   hw/riscv/riscv-iommu: Fix MSI table size limit
45 da14767b356c Andrea Bolognani:
   docs/interop/firmware: Add riscv64 to FirmwareArchitecture
46 191df3461752 Frank Chang:
   hw/char: sifive_uart: Raise IRQ according to the Tx/Rx watermark thresholds
47 cebaf7434b4a stove:
   target/riscv: use riscv_csrr in riscv_csr_read
48 a86d3352ab70 Vladimir Isaev:
   target/riscv: do not use translator_ldl in opcode_at
49 15abfced8039 Guo Ren (Alibaba DAMO Academy):
   hw/riscv/riscv-iommu: Fixup PDT Nested Walk
50 b25133d38fe6 vhaudiquet:
   target/riscv: Fix endianness swap on compressed instructions
51 ae4a37f57818 Max Chou:
   target/riscv: rvv: Replace checking V by checking Zve32x
52 be50ff3a7385 Max Chou:
   target/riscv: rvv: Modify minimum VLEN according to enabled vector 
   extensions
53 725a9e5f7885 Juraj Marcin:
   migration: Fix state transition in postcopy_start() error handling
54 9e7bfda4909c Peter Maydell:
   include/system/memory.h: Clarify address_space_destroy() behaviour
55 041600e23f2f Peter Xu:
   memory: New AS helper to serialize destroy+free
56 300a87c502c4 Peter Maydell:
   physmem: Destroy all CPU AddressSpaces on unrealize
57 3b1cf40dd665 Thomas Huth:
   tests/functional/test_ppc_bamboo: Replace broken link with working assets
58 01e2b1bc27ba Thomas Huth:
   tests/functional/test_aarch64_sbsaref_freebsd: Fix the URL of the ISO image

(commit(s) marked with * were in previous series and are not resent)


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 39/58] hw/usb/hcd-uhci: don't assert for SETUP to non-0 endpoint
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 40/58] hw/intc/xics: Add missing call to register vmstate_icp_server Michael Tokarev
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Peter Maydell, Michael Tokarev

From: Peter Maydell <peter.maydell@linaro.org>

If the guest feeds invalid data to the UHCI controller, we
can assert:
qemu-system-x86_64: ../../hw/usb/core.c:744: usb_ep_get: Assertion `pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT' failed.

(see issue 2548 for the repro case).  This happens because the guest
attempts USB_TOKEN_SETUP to an endpoint other than 0, which is not
valid.  The controller code doesn't catch this guest error, so
instead we hit the assertion in the USB core code.

Catch the case of SETUP to non-zero endpoint, and treat it as a fatal
error in the TD, in the same way we do for an invalid PID value in
the TD.

This is the UHCI equivalent of the same bug in OHCI that we fixed in
commit 3c3c233677 ("hw/usb/hcd-ohci: Fix #1510, #303: pid not IN or
OUT").

This bug has been tracked as CVE-2024-8354.

Cc: qemu-stable@nongnu.org
Fixes: https://gitlab.com/qemu-project/qemu/-/issues/2548
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
(cherry picked from commit d0af3cd0274e265435170a583c72b9f0a4100dff)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index 0561a6d801..8f4d6a0f71 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -735,6 +735,7 @@ static int uhci_handle_td(UHCIState *s, UHCIQueue *q, uint32_t qh_addr,
     bool spd;
     bool queuing = (q != NULL);
     uint8_t pid = td->token & 0xff;
+    uint8_t ep_id = (td->token >> 15) & 0xf;
     UHCIAsync *async;
 
     async = uhci_async_find_td(s, td_addr);
@@ -778,9 +779,14 @@ static int uhci_handle_td(UHCIState *s, UHCIQueue *q, uint32_t qh_addr,
 
     switch (pid) {
     case USB_TOKEN_OUT:
-    case USB_TOKEN_SETUP:
     case USB_TOKEN_IN:
         break;
+    case USB_TOKEN_SETUP:
+        /* SETUP is only valid to endpoint 0 */
+        if (ep_id == 0) {
+            break;
+        }
+        /* fallthrough */
     default:
         /* invalid pid : frame interrupted */
         s->status |= UHCI_STS_HCPERR;
@@ -829,7 +835,7 @@ static int uhci_handle_td(UHCIState *s, UHCIQueue *q, uint32_t qh_addr,
             return uhci_handle_td_error(s, td, td_addr, USB_RET_NODEV,
                                         int_mask);
         }
-        ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf);
+        ep = usb_ep_get(dev, pid, ep_id);
         q = uhci_queue_new(s, qh_addr, td, ep);
     }
     async = uhci_async_alloc(q, td_addr);
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 40/58] hw/intc/xics: Add missing call to register vmstate_icp_server
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 39/58] hw/usb/hcd-uhci: don't assert for SETUP to non-0 endpoint Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 41/58] ppc/spapr: init lrdr-capapcity phys with ram size if maxmem not provided Michael Tokarev
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Fabian Vogt, Philippe Mathieu-Daudé,
	Fabiano Rosas, Gautam Menghani, Harsh Prateek Bora,
	Michael Tokarev

From: Fabian Vogt <fvogt@suse.de>

An obsolete wrapper function with a workaround was removed entirely,
without restoring the call it wrapped.

Without this, the guest is stuck after savevm/loadvm.

Fixes: 24ee9229fe31 ("ppc/spapr: remove deprecated machine pseries-2.9")
Signed-off-by: Fabian Vogt <fvogt@suse.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Link: https://lore.kernel.org/qemu-devel/6187781.lOV4Wx5bFT@fvogt-thinkpad
Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Gautam Menghani <gautam@linux.ibm.com>
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Link: https://lore.kernel.org/r/20250819223905.2247-2-farosas@suse.de
Message-ID: <20250819223905.2247-2-farosas@suse.de>
(cherry picked from commit f5738aedc21790bd07dbead6b6272a605d5c1138)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/xics.c b/hw/intc/xics.c
index 9c1b7bbe9e..bb8504f53d 100644
--- a/hw/intc/xics.c
+++ b/hw/intc/xics.c
@@ -335,6 +335,8 @@ static void icp_realize(DeviceState *dev, Error **errp)
             return;
         }
     }
+
+    vmstate_register(NULL, icp->cs->cpu_index, &vmstate_icp_server, icp);
 }
 
 static void icp_unrealize(DeviceState *dev)
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 41/58] ppc/spapr: init lrdr-capapcity phys with ram size if maxmem not provided
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 39/58] hw/usb/hcd-uhci: don't assert for SETUP to non-0 endpoint Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 40/58] hw/intc/xics: Add missing call to register vmstate_icp_server Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 42/58] ui/spice: Fix abort on macOS Michael Tokarev
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Harsh Prateek Bora, Gaurav Batra, David Christensen,
	Shivaprasad G Bhat, Michael Tokarev

From: Harsh Prateek Bora <harshpb@linux.ibm.com>

lrdr-capacity contains phys field which communicates the maximum address
in bytes and therefore, the most memory that can be allocated to this
partition. This is usually populated when maxmem is provided alongwith
memory size on qemu command line. However since maxmem is an optional
param, this leads to bits being set to 0 in absence of maxmem param.
Fix this by initializing the respective bits as per total mem size in
such case.

Reported-by: Gaurav Batra <gbatra@us.ibm.com>
Tested-by: David Christensen <drc@linux.ibm.com>
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Reviewed-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Link: https://lore.kernel.org/r/20250506042903.76250-1-harshpb@linux.ibm.com
Message-ID: <20250506042903.76250-1-harshpb@linux.ibm.com>
(cherry picked from commit 6285eebd3a5fea018eb51d696b51079f44dd1eb3)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index b0a0f8c689..98cf00af5b 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -907,6 +907,7 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt)
     int rtas;
     GString *hypertas = g_string_sized_new(256);
     GString *qemu_hypertas = g_string_sized_new(256);
+    uint64_t max_device_addr = 0;
     uint32_t lrdr_capacity[] = {
         0,
         0,
@@ -917,13 +918,15 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt)
 
     /* Do we have device memory? */
     if (MACHINE(spapr)->device_memory) {
-        uint64_t max_device_addr = MACHINE(spapr)->device_memory->base +
+        max_device_addr = MACHINE(spapr)->device_memory->base +
             memory_region_size(&MACHINE(spapr)->device_memory->mr);
-
-        lrdr_capacity[0] = cpu_to_be32(max_device_addr >> 32);
-        lrdr_capacity[1] = cpu_to_be32(max_device_addr & 0xffffffff);
+    } else if (ms->ram_size == ms->maxram_size) {
+        max_device_addr = ms->ram_size;
     }
 
+    lrdr_capacity[0] = cpu_to_be32(max_device_addr >> 32);
+    lrdr_capacity[1] = cpu_to_be32(max_device_addr & 0xffffffff);
+
     _FDT(rtas = fdt_add_subnode(fdt, 0, "rtas"));
 
     /* hypertas */
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 42/58] ui/spice: Fix abort on macOS
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (2 preceding siblings ...)
  2025-10-05 17:36 ` [Stable-10.0.5 41/58] ppc/spapr: init lrdr-capapcity phys with ram size if maxmem not provided Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 43/58] ui/icons/qemu.svg: Add metadata information (author, license) to the logo Michael Tokarev
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Mohamed Akram, Marc-André Lureau,
	Michael Tokarev

From: Mohamed Akram <mohd.akram@outlook.com>

The check is faulty because the thread variable was assigned in the main
thread while the main loop runs in a different thread on macOS.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3070
Signed-off-by: Mohamed Akram <mohd.akram@outlook.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <C87205B9-DD8F-4E53-AB5B-C8BF82EF1D16@outlook.com>
(cherry picked from commit e7ecb533ee0dbfbe30c90abb213247f4943a9a12)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/ui/spice-core.c b/ui/spice-core.c
index 0326c63bec..6ad619143c 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -50,8 +50,6 @@ static int spice_migration_completed;
 static int spice_display_is_running;
 static int spice_have_target_host;
 
-static QemuThread me;
-
 struct SpiceTimer {
     QEMUTimer *timer;
 };
@@ -220,7 +218,7 @@ static void channel_event(int event, SpiceChannelEventInfo *info)
      * thread and grab the BQL if so before calling qemu
      * functions.
      */
-    bool need_lock = !qemu_thread_is_self(&me);
+    bool need_lock = !bql_locked();
     if (need_lock) {
         bql_lock();
     }
@@ -667,8 +665,6 @@ static void qemu_spice_init(void)
     spice_wan_compression_t wan_compr;
     bool seamless_migration;
 
-    qemu_thread_get_self(&me);
-
     if (!opts) {
         return;
     }
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 43/58] ui/icons/qemu.svg: Add metadata information (author, license) to the logo
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (3 preceding siblings ...)
  2025-10-05 17:36 ` [Stable-10.0.5 42/58] ui/spice: Fix abort on macOS Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 44/58] hw/riscv/riscv-iommu: Fix MSI table size limit Michael Tokarev
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Thomas Huth, Marc-André Lureau, Michael Tokarev

From: Thomas Huth <thuth@redhat.com>

We've got two versions of the QEMU logo in the repository, one with
the whole word "QEMU" (pc-bios/qemu_logo.svg) and one that only contains
the letter "Q" (ui/icons/qemu.svg). While qemu_logo.svg contains the
proper metadata with license and author information, this is missing
from the ui/icons/qemu.svg file. Copy the meta data there so that
people have a chance to know the license of the file if they only
look at the qemu.svg file.

Closes: https://gitlab.com/qemu-project/qemu/-/issues/3139
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20250930071419.117592-1-thuth@redhat.com>
(cherry picked from commit 9163424c50981dbc4ded9990228ac01a3b193656)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/ui/icons/qemu.svg b/ui/icons/qemu.svg
index 24ca23a1e9..f2500de339 100644
--- a/ui/icons/qemu.svg
+++ b/ui/icons/qemu.svg
@@ -918,7 +918,26 @@
         <dc:format>image/svg+xml</dc:format>
         <dc:type
            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
-        <dc:title />
+        <dc:title>Kew the Angry Emu</dc:title>
+        <dc:creator>
+          <cc:Agent>
+            <dc:title>Benoît Canet</dc:title>
+          </cc:Agent>
+        </dc:creator>
+        <dc:rights>
+          <cc:Agent>
+            <dc:title>CC BY 3.0</dc:title>
+          </cc:Agent>
+        </dc:rights>
+        <dc:publisher>
+          <cc:Agent>
+            <dc:title>QEMU Community</dc:title>
+          </cc:Agent>
+        </dc:publisher>
+        <dc:date>2012-02-15</dc:date>
+        <cc:license
+           rdf:resource="http://creativecommons.org/licenses/by/3.0/" />
+        <dc:source>https://lists.gnu.org/archive/html/qemu-devel/2012-02/msg02865.html</dc:source>
       </cc:Work>
     </rdf:RDF>
   </metadata>
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 44/58] hw/riscv/riscv-iommu: Fix MSI table size limit
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (4 preceding siblings ...)
  2025-10-05 17:36 ` [Stable-10.0.5 43/58] ui/icons/qemu.svg: Add metadata information (author, license) to the logo Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 45/58] docs/interop/firmware: Add riscv64 to FirmwareArchitecture Michael Tokarev
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Andrew Jones, Daniel Henrique Barboza,
	Alistair Francis, Michael Tokarev

From: Andrew Jones <ajones@ventanamicro.com>

The MSI table is not limited to 4k. The only constraint the table has
is that its base address must be aligned to its size, ensuring no
offsets of the table size will overrun when added to the base address
(see "8.5. MSI page tables" of the AIA spec).

Fixes: 0c54acb8243d ("hw/riscv: add RISC-V IOMMU base emulation")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Message-ID: <20250904132723.614507-2-ajones@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit 4f7528295b3e6dfe1189f660fa7865ad972d82e7)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
index 76e0fcd873..a4f62c89e2 100644
--- a/hw/riscv/riscv-iommu.c
+++ b/hw/riscv/riscv-iommu.c
@@ -557,6 +557,7 @@ static MemTxResult riscv_iommu_msi_write(RISCVIOMMUState *s,
     MemTxResult res;
     dma_addr_t addr;
     uint64_t intn;
+    size_t offset;
     uint32_t n190;
     uint64_t pte[2];
     int fault_type = RISCV_IOMMU_FQ_TTYPE_UADDR_WR;
@@ -564,16 +565,18 @@ static MemTxResult riscv_iommu_msi_write(RISCVIOMMUState *s,
 
     /* Interrupt File Number */
     intn = riscv_iommu_pext_u64(PPN_DOWN(gpa), ctx->msi_addr_mask);
-    if (intn >= 256) {
+    offset = intn * sizeof(pte);
+
+    /* fetch MSI PTE */
+    addr = PPN_PHYS(get_field(ctx->msiptp, RISCV_IOMMU_DC_MSIPTP_PPN));
+    if (addr & offset) {
         /* Interrupt file number out of range */
         res = MEMTX_ACCESS_ERROR;
         cause = RISCV_IOMMU_FQ_CAUSE_MSI_LOAD_FAULT;
         goto err;
     }
 
-    /* fetch MSI PTE */
-    addr = PPN_PHYS(get_field(ctx->msiptp, RISCV_IOMMU_DC_MSIPTP_PPN));
-    addr = addr | (intn * sizeof(pte));
+    addr |= offset;
     res = dma_memory_read(s->target_as, addr, &pte, sizeof(pte),
             MEMTXATTRS_UNSPECIFIED);
     if (res != MEMTX_OK) {
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 45/58] docs/interop/firmware: Add riscv64 to FirmwareArchitecture
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (5 preceding siblings ...)
  2025-10-05 17:36 ` [Stable-10.0.5 44/58] hw/riscv/riscv-iommu: Fix MSI table size limit Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 46/58] hw/char: sifive_uart: Raise IRQ according to the Tx/Rx watermark thresholds Michael Tokarev
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Andrea Bolognani, Kashyap Chamarthy,
	Alistair Francis, Michael Tokarev

From: Andrea Bolognani <abologna@redhat.com>

Descriptors using this value have been shipped for years
by distros, so we just need to update the spec to match
reality.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Kashyap Chamarthy <kchamart@redhat.com>
Message-ID: <20250910121501.676219-1-abologna@redhat.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit da14767b356c2342197708a997eeb0da053262a0)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/docs/interop/firmware.json b/docs/interop/firmware.json
index 745d21d822..ea88da0fec 100644
--- a/docs/interop/firmware.json
+++ b/docs/interop/firmware.json
@@ -76,12 +76,14 @@
 #
 # @loongarch64: 64-bit LoongArch. (since: 7.1)
 #
+# @riscv64: 64-bit RISC-V.
+#
 # @x86_64: 64-bit x86.
 #
 # Since: 3.0
 ##
 { 'enum' : 'FirmwareArchitecture',
-  'data' : [ 'aarch64', 'arm', 'i386', 'loongarch64', 'x86_64' ] }
+  'data' : [ 'aarch64', 'arm', 'i386', 'loongarch64', 'riscv64', 'x86_64' ] }
 
 ##
 # @FirmwareTarget:
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 46/58] hw/char: sifive_uart: Raise IRQ according to the Tx/Rx watermark thresholds
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (6 preceding siblings ...)
  2025-10-05 17:36 ` [Stable-10.0.5 45/58] docs/interop/firmware: Add riscv64 to FirmwareArchitecture Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 47/58] target/riscv: use riscv_csrr in riscv_csr_read Michael Tokarev
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Frank Chang, Emmanuel Blot, Alistair Francis,
	Michael Tokarev

From: Frank Chang <frank.chang@sifive.com>

Currently, the SiFive UART raises an IRQ whenever:

  1. ie.txwm is enabled.
  2. ie.rxwm is enabled and the Rx FIFO is not empty.

It does not check the watermark thresholds set by software. However,
since commit [1] changed the SiFive UART character printing from
synchronous to asynchronous, Tx overflows may occur, causing characters
to be dropped when running Linux because:

  1. The Linux SiFive UART driver sets the transmit watermark level to 1
     [2], meaning a transmit watermark interrupt is raised whenever a
     character is enqueued into the Tx FIFO.
  2. Upon receiving a transmit watermark interrupt, the Linux driver
     transfers up to a full Tx FIFO's worth of characters from the Linux
     serial transmit buffer [3], without checking the txdata.full flag
     before transferring multiple characters [4].

To fix this issue, we must honor the Tx/Rx watermark thresholds and
raise interrupts only when the Tx threshold is exceeded or the Rx
threshold is undercut.

[1] 53c1557b230986ab6320a58e1b2c26216ecd86d5
[2] https://github.com/torvalds/linux/blob/master/drivers/tty/serial/sifive.c#L1039
[3] https://github.com/torvalds/linux/blob/master/drivers/tty/serial/sifive.c#L538
[4] https://github.com/torvalds/linux/blob/master/drivers/tty/serial/sifive.c#L291

Signed-off-by: Frank Chang <frank.chang@sifive.com>
Signed-off-by: Emmanuel Blot <emmanuel.blot@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20250911160647.5710-2-frank.chang@sifive.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit 191df346175283af013f414375f4be59fb850120)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c
index b45e6c098c..6da3401aa3 100644
--- a/hw/char/sifive_uart.c
+++ b/hw/char/sifive_uart.c
@@ -35,16 +35,17 @@
  */
 
 /* Returns the state of the IP (interrupt pending) register */
-static uint64_t sifive_uart_ip(SiFiveUARTState *s)
+static uint32_t sifive_uart_ip(SiFiveUARTState *s)
 {
-    uint64_t ret = 0;
+    uint32_t ret = 0;
 
-    uint64_t txcnt = SIFIVE_UART_GET_TXCNT(s->txctrl);
-    uint64_t rxcnt = SIFIVE_UART_GET_RXCNT(s->rxctrl);
+    uint32_t txcnt = SIFIVE_UART_GET_TXCNT(s->txctrl);
+    uint32_t rxcnt = SIFIVE_UART_GET_RXCNT(s->rxctrl);
 
-    if (txcnt != 0) {
+    if (fifo8_num_used(&s->tx_fifo) < txcnt) {
         ret |= SIFIVE_UART_IP_TXWM;
     }
+
     if (s->rx_fifo_len > rxcnt) {
         ret |= SIFIVE_UART_IP_RXWM;
     }
@@ -55,15 +56,14 @@ static uint64_t sifive_uart_ip(SiFiveUARTState *s)
 static void sifive_uart_update_irq(SiFiveUARTState *s)
 {
     int cond = 0;
-    if ((s->ie & SIFIVE_UART_IE_TXWM) ||
-        ((s->ie & SIFIVE_UART_IE_RXWM) && s->rx_fifo_len)) {
+    uint32_t ip = sifive_uart_ip(s);
+
+    if (((ip & SIFIVE_UART_IP_TXWM) && (s->ie & SIFIVE_UART_IE_TXWM)) ||
+        ((ip & SIFIVE_UART_IP_RXWM) && (s->ie & SIFIVE_UART_IE_RXWM))) {
         cond = 1;
     }
-    if (cond) {
-        qemu_irq_raise(s->irq);
-    } else {
-        qemu_irq_lower(s->irq);
-    }
+
+    qemu_set_irq(s->irq, cond);
 }
 
 static gboolean sifive_uart_xmit(void *do_not_use, GIOCondition cond,
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 47/58] target/riscv: use riscv_csrr in riscv_csr_read
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (7 preceding siblings ...)
  2025-10-05 17:36 ` [Stable-10.0.5 46/58] hw/char: sifive_uart: Raise IRQ according to the Tx/Rx watermark thresholds Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 48/58] target/riscv: do not use translator_ldl in opcode_at Michael Tokarev
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, stove, Daniel Henrique Barboza, Alistair Francis,
	Michael Tokarev

From: stove <stove@rivosinc.com>

Commit 38c83e8d3a33 ("target/riscv: raise an exception when CSRRS/CSRRC
writes a read-only CSR") changed the behavior of riscv_csrrw, which
would formerly be treated as read-only if the write mask were set to 0.

Fixes an exception being raised when accessing read-only vector CSRs
like vtype.

Fixes: 38c83e8d3a33 ("target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR")

Signed-off-by: stove <stove@rivosinc.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Message-ID: <20250827203617.79947-1-stove@rivosinc.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit cebaf7434b4af059caca053ee1ec7ed8df91c2a7)
(Mjt: context fix for v10.0.0-1030-gf1304836ea "target/riscv: Pass ra to riscv_csrrw")
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 7a56666f9a..71141f4ea6 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -839,7 +839,7 @@ static inline void riscv_csr_write(CPURISCVState *env, int csrno,
 static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno)
 {
     target_ulong val = 0;
-    riscv_csrrw(env, csrno, &val, 0, 0);
+    riscv_csrr(env, csrno, &val);
     return val;
 }
 
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 48/58] target/riscv: do not use translator_ldl in opcode_at
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (8 preceding siblings ...)
  2025-10-05 17:36 ` [Stable-10.0.5 47/58] target/riscv: use riscv_csrr in riscv_csr_read Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 49/58] hw/riscv/riscv-iommu: Fixup PDT Nested Walk Michael Tokarev
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Vladimir Isaev, Richard Henderson, Alistair Francis,
	Michael Tokarev

From: Vladimir Isaev <vladimir.isaev@syntacore.com>

opcode_at is used only in semihosting checks to match opcodes with expected
pattern.

This is not a translator and if we got following assert if page is not in TLB:
qemu-system-riscv64: ../accel/tcg/translator.c:363: record_save: Assertion
`offset == db->record_start + db->record_len' failed.

Fixes: 1f9c4462334f ("target/riscv: Use translator_ld* for everything")
Signed-off-by: Vladimir Isaev <vladimir.isaev@syntacore.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250815140633.86920-1-vladimir.isaev@syntacore.com>
[ Changes by AF:
 - Fixup header includes after rebase
]
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit a86d3352ab70f33f5feabbf9bad9450d3c19d0bf)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index d6651f244f..fc31b21f29 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -25,6 +25,7 @@
 #include "exec/helper-gen.h"
 
 #include "exec/translator.h"
+#include "accel/tcg/cpu-ldst.h"
 #include "exec/translation-block.h"
 #include "exec/log.h"
 #include "semihosting/semihost.h"
@@ -1167,7 +1168,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
     CPUState *cpu = ctx->cs;
     CPURISCVState *env = cpu_env(cpu);
 
-    return translator_ldl(env, &ctx->base, pc);
+    return cpu_ldl_code(env, pc);
 }
 
 #define SS_MMU_INDEX(ctx) (ctx->mem_idx | MMU_IDX_SS_WRITE)
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 49/58] hw/riscv/riscv-iommu: Fixup PDT Nested Walk
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (9 preceding siblings ...)
  2025-10-05 17:36 ` [Stable-10.0.5 48/58] target/riscv: do not use translator_ldl in opcode_at Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:36 ` [Stable-10.0.5 50/58] target/riscv: Fix endianness swap on compressed instructions Michael Tokarev
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Guo Ren (Alibaba DAMO Academy), Sebastien Boeuf,
	Tomasz Jeznach, Weiwei Li, Nutty Liu, Chen Pei, Fangyu Yu ,
	Alistair Francis, Michael Tokarev

From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>

Current implementation is wrong when iohgatp != bare. The RISC-V
IOMMU specification has defined that the PDT is based on GPA, not
SPA. So this patch fixes the problem, making PDT walk correctly
when the G-stage table walk is enabled.

Fixes: 0c54acb8243d ("hw/riscv: add RISC-V IOMMU base emulation")
Cc: qemu-stable@nongnu.org
Cc: Sebastien Boeuf <seb@rivosinc.com>
Cc: Tomasz Jeznach <tjeznach@rivosinc.com>
Reviewed-by: Weiwei Li <liwei1518@gmail.com>
Reviewed-by: Nutty Liu <liujingqi@lanxincomputing.com>
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
Tested-by: Chen Pei <cp0613@linux.alibaba.com>
Tested-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Message-ID: <20250913041233.972870-1-guoren@kernel.org>
[ Changes by AF:
 - Add braces to if statements
]
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit 15abfced803929f935bb59a0e1b02558bd8325c4)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
index a4f62c89e2..92ba45bed7 100644
--- a/hw/riscv/riscv-iommu.c
+++ b/hw/riscv/riscv-iommu.c
@@ -868,6 +868,145 @@ static bool riscv_iommu_validate_process_ctx(RISCVIOMMUState *s,
     return true;
 }
 
+/**
+ * pdt_memory_read: PDT wrapper of dma_memory_read.
+ *
+ * @s: IOMMU Device State
+ * @ctx: Device Translation Context with devid and pasid set
+ * @addr: address within that address space
+ * @buf: buffer with the data transferred
+ * @len: length of the data transferred
+ * @attrs: memory transaction attributes
+ */
+static MemTxResult pdt_memory_read(RISCVIOMMUState *s,
+                                   RISCVIOMMUContext *ctx,
+                                   dma_addr_t addr,
+                                   void *buf, dma_addr_t len,
+                                   MemTxAttrs attrs)
+{
+    uint64_t gatp_mode, pte;
+    struct {
+        unsigned char step;
+        unsigned char levels;
+        unsigned char ptidxbits;
+        unsigned char ptesize;
+    } sc;
+    MemTxResult ret;
+    dma_addr_t base = addr;
+
+    /* G stages translation mode */
+    gatp_mode = get_field(ctx->gatp, RISCV_IOMMU_ATP_MODE_FIELD);
+    if (gatp_mode == RISCV_IOMMU_DC_IOHGATP_MODE_BARE) {
+        goto out;
+    }
+
+    /* G stages translation tables root pointer */
+    base = PPN_PHYS(get_field(ctx->gatp, RISCV_IOMMU_ATP_PPN_FIELD));
+
+    /* Start at step 0 */
+    sc.step = 0;
+
+    if (s->fctl & RISCV_IOMMU_FCTL_GXL) {
+        /* 32bit mode for GXL == 1 */
+        switch (gatp_mode) {
+        case RISCV_IOMMU_DC_IOHGATP_MODE_SV32X4:
+            if (!(s->cap & RISCV_IOMMU_CAP_SV32X4)) {
+                return MEMTX_ACCESS_ERROR;
+            }
+            sc.levels    = 2;
+            sc.ptidxbits = 10;
+            sc.ptesize   = 4;
+            break;
+        default:
+            return MEMTX_ACCESS_ERROR;
+        }
+    } else {
+        /* 64bit mode for GXL == 0 */
+        switch (gatp_mode) {
+        case RISCV_IOMMU_DC_IOHGATP_MODE_SV39X4:
+            if (!(s->cap & RISCV_IOMMU_CAP_SV39X4)) {
+                return MEMTX_ACCESS_ERROR;
+            }
+            sc.levels    = 3;
+            sc.ptidxbits = 9;
+            sc.ptesize   = 8;
+            break;
+        case RISCV_IOMMU_DC_IOHGATP_MODE_SV48X4:
+            if (!(s->cap & RISCV_IOMMU_CAP_SV48X4)) {
+                return MEMTX_ACCESS_ERROR;
+            }
+            sc.levels    = 4;
+            sc.ptidxbits = 9;
+            sc.ptesize   = 8;
+            break;
+        case RISCV_IOMMU_DC_IOHGATP_MODE_SV57X4:
+            if (!(s->cap & RISCV_IOMMU_CAP_SV57X4)) {
+                return MEMTX_ACCESS_ERROR;
+            }
+            sc.levels    = 5;
+            sc.ptidxbits = 9;
+            sc.ptesize   = 8;
+            break;
+        default:
+            return MEMTX_ACCESS_ERROR;
+        }
+    }
+
+    do {
+        const unsigned va_bits = (sc.step ? 0 : 2) + sc.ptidxbits;
+        const unsigned va_skip = TARGET_PAGE_BITS + sc.ptidxbits *
+                                 (sc.levels - 1 - sc.step);
+        const unsigned idx = (addr >> va_skip) & ((1 << va_bits) - 1);
+        const dma_addr_t pte_addr = base + idx * sc.ptesize;
+
+        /* Address range check before first level lookup */
+        if (!sc.step) {
+            const uint64_t va_mask = (1ULL << (va_skip + va_bits)) - 1;
+            if ((addr & va_mask) != addr) {
+                return MEMTX_ACCESS_ERROR;
+            }
+        }
+
+        /* Read page table entry */
+        if (sc.ptesize == 4) {
+            uint32_t pte32 = 0;
+            ret = ldl_le_dma(s->target_as, pte_addr, &pte32, attrs);
+            pte = pte32;
+        } else {
+            ret = ldq_le_dma(s->target_as, pte_addr, &pte, attrs);
+        }
+        if (ret != MEMTX_OK) {
+            return ret;
+        }
+
+        sc.step++;
+        hwaddr ppn = pte >> PTE_PPN_SHIFT;
+
+        if (!(pte & PTE_V)) {
+            return MEMTX_ACCESS_ERROR; /* Invalid PTE */
+        } else if (!(pte & (PTE_R | PTE_W | PTE_X))) {
+            base = PPN_PHYS(ppn); /* Inner PTE, continue walking */
+        } else if ((pte & (PTE_R | PTE_W | PTE_X)) == PTE_W) {
+            return MEMTX_ACCESS_ERROR; /* Reserved leaf PTE flags: PTE_W */
+        } else if ((pte & (PTE_R | PTE_W | PTE_X)) == (PTE_W | PTE_X)) {
+            return MEMTX_ACCESS_ERROR; /* Reserved leaf PTE flags: PTE_W + PTE_X */
+        } else if (ppn & ((1ULL << (va_skip - TARGET_PAGE_BITS)) - 1)) {
+            return MEMTX_ACCESS_ERROR; /* Misaligned PPN */
+        } else {
+            /* Leaf PTE, translation completed. */
+            base = PPN_PHYS(ppn) | (addr & ((1ULL << va_skip) - 1));
+            break;
+        }
+
+        if (sc.step == sc.levels) {
+            return MEMTX_ACCESS_ERROR; /* Can't find leaf PTE */
+        }
+    } while (1);
+
+out:
+    return dma_memory_read(s->target_as, base, buf, len, attrs);
+}
+
 /*
  * RISC-V IOMMU Device Context Loopkup - Device Directory Tree Walk
  *
@@ -1040,7 +1179,7 @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx)
          */
         const int split = depth * 9 + 8;
         addr |= ((ctx->process_id >> split) << 3) & ~TARGET_PAGE_MASK;
-        if (dma_memory_read(s->target_as, addr, &de, sizeof(de),
+        if (pdt_memory_read(s, ctx, addr, &de, sizeof(de),
                             MEMTXATTRS_UNSPECIFIED) != MEMTX_OK) {
             return RISCV_IOMMU_FQ_CAUSE_PDT_LOAD_FAULT;
         }
@@ -1055,7 +1194,7 @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx)
 
     /* Leaf entry in PDT */
     addr |= (ctx->process_id << 4) & ~TARGET_PAGE_MASK;
-    if (dma_memory_read(s->target_as, addr, &dc.ta, sizeof(uint64_t) * 2,
+    if (pdt_memory_read(s, ctx, addr, &dc.ta, sizeof(uint64_t) * 2,
                         MEMTXATTRS_UNSPECIFIED) != MEMTX_OK) {
         return RISCV_IOMMU_FQ_CAUSE_PDT_LOAD_FAULT;
     }
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 50/58] target/riscv: Fix endianness swap on compressed instructions
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (10 preceding siblings ...)
  2025-10-05 17:36 ` [Stable-10.0.5 49/58] hw/riscv/riscv-iommu: Fixup PDT Nested Walk Michael Tokarev
@ 2025-10-05 17:36 ` Michael Tokarev
  2025-10-05 17:37 ` [Stable-10.0.5 51/58] target/riscv: rvv: Replace checking V by checking Zve32x Michael Tokarev
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, vhaudiquet, Valentin Haudiquet, Anton Johansson,
	Daniel Henrique Barboza, Heinrich Schuchardt, Richard Henderson,
	Alistair Francis, Michael Tokarev

From: vhaudiquet <vhaudiquet343@hotmail.fr>

Three instructions were not using the endianness swap flag, which resulted in a bug on big-endian architectures.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3131
Buglink: https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/2123828

Fixes: e0a3054f18e ("target/riscv: add support for Zcb extension")
Signed-off-by: Valentin Haudiquet <valentin.haudiquet@canonical.com>
Cc: qemu-stable@nongnu.org
Reviewed-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250929115543.1648157-1-valentin.haudiquet@canonical.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit b25133d38fe693589cf695b85968caa0724bfafd)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/riscv/insn_trans/trans_rvzce.c.inc b/target/riscv/insn_trans/trans_rvzce.c.inc
index c77c2b927b..dd15af0f54 100644
--- a/target/riscv/insn_trans/trans_rvzce.c.inc
+++ b/target/riscv/insn_trans/trans_rvzce.c.inc
@@ -88,13 +88,13 @@ static bool trans_c_lbu(DisasContext *ctx, arg_c_lbu *a)
 static bool trans_c_lhu(DisasContext *ctx, arg_c_lhu *a)
 {
     REQUIRE_ZCB(ctx);
-    return gen_load(ctx, a, MO_UW);
+    return gen_load(ctx, a, MO_TEUW);
 }
 
 static bool trans_c_lh(DisasContext *ctx, arg_c_lh *a)
 {
     REQUIRE_ZCB(ctx);
-    return gen_load(ctx, a, MO_SW);
+    return gen_load(ctx, a, MO_TESW);
 }
 
 static bool trans_c_sb(DisasContext *ctx, arg_c_sb *a)
@@ -106,7 +106,7 @@ static bool trans_c_sb(DisasContext *ctx, arg_c_sb *a)
 static bool trans_c_sh(DisasContext *ctx, arg_c_sh *a)
 {
     REQUIRE_ZCB(ctx);
-    return gen_store(ctx, a, MO_UW);
+    return gen_store(ctx, a, MO_TEUW);
 }
 
 #define X_S0    8
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 51/58] target/riscv: rvv: Replace checking V by checking Zve32x
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (11 preceding siblings ...)
  2025-10-05 17:36 ` [Stable-10.0.5 50/58] target/riscv: Fix endianness swap on compressed instructions Michael Tokarev
@ 2025-10-05 17:37 ` Michael Tokarev
  2025-10-05 17:37 ` [Stable-10.0.5 52/58] target/riscv: rvv: Modify minimum VLEN according to enabled vector extensions Michael Tokarev
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Max Chou, Alistair Francis, Michael Tokarev

From: Max Chou <max.chou@sifive.com>

The Zve32x extension will be applied by the V and Zve* extensions.
Therefore we can replace the original V checking with Zve32x checking for both
the V and Zve* extensions.

Signed-off-by: Max Chou <max.chou@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20250923090729.1887406-2-max.chou@sifive.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit ae4a37f57818e47e212272821a5a86ad54620eb8)
(Mjt: drop the MonitorDef change due to missing v10.1.0-850-ge06d209aa6 "target/riscv: implement MonitorDef HMP API")
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 09ded6829a..2ff56bd017 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -945,7 +945,7 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
             }
         }
     }
-    if (riscv_has_ext(env, RVV) && (flags & CPU_DUMP_VPU)) {
+    if (riscv_cpu_cfg(env)->ext_zve32x && (flags & CPU_DUMP_VPU)) {
         static const int dump_rvv_csrs[] = {
                     CSR_VSTART,
                     CSR_VXSAT,
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 66d572af1f..76e2f7e1d5 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -1990,7 +1990,8 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
     if (riscv_has_ext(env, RVF)) {
         mask |= MSTATUS_FS;
     }
-    if (riscv_has_ext(env, RVV)) {
+
+    if (riscv_cpu_cfg(env)->ext_zve32x) {
         mask |= MSTATUS_VS;
     }
 
diff --git a/target/riscv/machine.c b/target/riscv/machine.c
index 889e2b6570..0697d813b7 100644
--- a/target/riscv/machine.c
+++ b/target/riscv/machine.c
@@ -130,7 +130,8 @@ static bool vector_needed(void *opaque)
     RISCVCPU *cpu = opaque;
     CPURISCVState *env = &cpu->env;
 
-    return riscv_has_ext(env, RVV);
+    return kvm_enabled() ? riscv_has_ext(env, RVV) :
+                           riscv_cpu_cfg(env)->ext_zve32x;
 }
 
 static const VMStateDescription vmstate_vector = {
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 5aef9eef36..2b21580ef7 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -515,7 +515,7 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
         return;
     }
 
-    if (riscv_has_ext(env, RVV)) {
+    if (cpu->cfg.ext_zve32x) {
         riscv_cpu_validate_v(env, &cpu->cfg, &local_err);
         if (local_err != NULL) {
             error_propagate(errp, local_err);
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 52/58] target/riscv: rvv: Modify minimum VLEN according to enabled vector extensions
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (12 preceding siblings ...)
  2025-10-05 17:37 ` [Stable-10.0.5 51/58] target/riscv: rvv: Replace checking V by checking Zve32x Michael Tokarev
@ 2025-10-05 17:37 ` Michael Tokarev
  2025-10-05 17:37 ` [Stable-10.0.5 53/58] migration: Fix state transition in postcopy_start() error handling Michael Tokarev
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Max Chou, Alistair Francis, Michael Tokarev

From: Max Chou <max.chou@sifive.com>

According to the RISC-V unprivileged specification, the VLEN should be greater
or equal to the ELEN. This commit modifies the minimum VLEN based on the vector
extensions and introduces a check rule for VLEN and ELEN.

  Extension     Minimum VLEN
* V                      128
* Zve64[d|f|x]            64
* Zve32[f|x]              32

Signed-off-by: Max Chou <max.chou@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20250923090729.1887406-3-max.chou@sifive.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit be50ff3a73859ebbbdc0e6f704793062b1743d93)
(Mjt: compensate #include for the lack of v10.0.0-214-g42fa9665e5 "exec: Restrict 'cpu_ldst.h' to accel/tcg/")
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 2b21580ef7..863aebec45 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -280,12 +280,21 @@ static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp)
 static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
                                  Error **errp)
 {
+    uint32_t min_vlen;
     uint32_t vlen = cfg->vlenb << 3;
 
-    if (vlen > RV_VLEN_MAX || vlen < 128) {
+    if (riscv_has_ext(env, RVV)) {
+        min_vlen = 128;
+    } else if (cfg->ext_zve64x) {
+        min_vlen = 64;
+    } else if (cfg->ext_zve32x) {
+        min_vlen = 32;
+    }
+
+    if (vlen > RV_VLEN_MAX || vlen < min_vlen) {
         error_setg(errp,
                    "Vector extension implementation only supports VLEN "
-                   "in the range [128, %d]", RV_VLEN_MAX);
+                   "in the range [%d, %d]", min_vlen, RV_VLEN_MAX);
         return;
     }
 
@@ -295,6 +304,12 @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
                    "in the range [8, 64]");
         return;
     }
+
+    if (vlen < cfg->elen) {
+        error_setg(errp, "Vector extension implementation requires VLEN "
+                         "to be greater than or equal to ELEN");
+        return;
+    }
 }
 
 static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu)
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index fc31b21f29..e1e087a36b 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -25,7 +25,7 @@
 #include "exec/helper-gen.h"
 
 #include "exec/translator.h"
-#include "accel/tcg/cpu-ldst.h"
+#include "exec/cpu_ldst.h"
 #include "exec/translation-block.h"
 #include "exec/log.h"
 #include "semihosting/semihost.h"
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 53/58] migration: Fix state transition in postcopy_start() error handling
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (13 preceding siblings ...)
  2025-10-05 17:37 ` [Stable-10.0.5 52/58] target/riscv: rvv: Modify minimum VLEN according to enabled vector extensions Michael Tokarev
@ 2025-10-05 17:37 ` Michael Tokarev
  2025-10-05 17:37 ` [Stable-10.0.5 54/58] include/system/memory.h: Clarify address_space_destroy() behaviour Michael Tokarev
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Juraj Marcin, Peter Xu, Fabiano Rosas,
	Michael Tokarev

From: Juraj Marcin <jmarcin@redhat.com>

Commit 48814111366b ("migration: Always set DEVICE state") introduced
DEVICE state to postcopy, which moved the actual state transition that
leads to POSTCOPY_ACTIVE.

However, the error handling part of the postcopy_start() function still
expects the state POSTCOPY_ACTIVE, but depending on where an error
happens, now the state can be either ACTIVE, DEVICE or CANCELLING, but
never POSTCOPY_ACTIVE, as this transition now happens just before a
successful return from the function.

Instead, accept any state except CANCELLING when transitioning to FAILED
state.

Cc: qemu-stable@nongnu.org
Fixes: 48814111366b ("migration: Always set DEVICE state")
Signed-off-by: Juraj Marcin <jmarcin@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20250826115145.871272-1-jmarcin@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
(cherry picked from commit 725a9e5f7885a3c0d0cd82022d6eb5a758ac9d47)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/migration/migration.c b/migration/migration.c
index d46e776e24..50bd2dd51f 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2843,8 +2843,9 @@ static int postcopy_start(MigrationState *ms, Error **errp)
 fail_closefb:
     qemu_fclose(fb);
 fail:
-    migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE,
-                          MIGRATION_STATUS_FAILED);
+    if (ms->state != MIGRATION_STATUS_CANCELLING) {
+        migrate_set_state(&ms->state, ms->state, MIGRATION_STATUS_FAILED);
+    }
     migration_block_activate(NULL);
     migration_call_notifiers(ms, MIG_EVENT_PRECOPY_FAILED, NULL);
     bql_unlock();
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 54/58] include/system/memory.h: Clarify address_space_destroy() behaviour
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (14 preceding siblings ...)
  2025-10-05 17:37 ` [Stable-10.0.5 53/58] migration: Fix state transition in postcopy_start() error handling Michael Tokarev
@ 2025-10-05 17:37 ` Michael Tokarev
  2025-10-05 17:37 ` [Stable-10.0.5 55/58] memory: New AS helper to serialize destroy+free Michael Tokarev
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Peter Maydell, David Hildenbrand, Peter Xu,
	Michael Tokarev

From: Peter Maydell <peter.maydell@linaro.org>

address_space_destroy() doesn't actually immediately destroy the AS;
it queues it to be destroyed via RCU. This means you can't g_free()
the memory the AS struct is in until that has happened.

Clarify this in the documentation.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20250929144228.1994037-2-peter.maydell@linaro.org
Signed-off-by: Peter Xu <peterx@redhat.com>
(cherry picked from commit 9e7bfda4909cc688dd0327e17985019f08a78d5d)
(Mjt: this is just a comment fix, but it makes subsequent changes to apply cleanly)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/include/exec/memory.h b/include/exec/memory.h
index e1c196a0c2..2ad3f93344 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2627,9 +2627,14 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name);
 /**
  * address_space_destroy: destroy an address space
  *
- * Releases all resources associated with an address space.  After an address space
- * is destroyed, its root memory region (given by address_space_init()) may be destroyed
- * as well.
+ * Releases all resources associated with an address space.  After an
+ * address space is destroyed, the reference the AddressSpace had to
+ * its root memory region is dropped, which may result in the
+ * destruction of that memory region as well.
+ *
+ * Note that destruction of the AddressSpace is done via RCU;
+ * it is therefore not valid to free the memory the AddressSpace
+ * struct is in until after that RCU callback has completed.
  *
  * @as: address space to be destroyed
  */
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 55/58] memory: New AS helper to serialize destroy+free
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (15 preceding siblings ...)
  2025-10-05 17:37 ` [Stable-10.0.5 54/58] include/system/memory.h: Clarify address_space_destroy() behaviour Michael Tokarev
@ 2025-10-05 17:37 ` Michael Tokarev
  2025-10-05 17:37 ` [Stable-10.0.5 56/58] physmem: Destroy all CPU AddressSpaces on unrealize Michael Tokarev
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Peter Xu, Peter Maydell, David Hildenbrand,
	Michael Tokarev

From: Peter Xu <peterx@redhat.com>

If an AddressSpace has been created in its own allocated
memory, cleaning it up requires first destroying the AS
and then freeing the memory. Doing this doesn't work:

    address_space_destroy(as);
    g_free_rcu(as, rcu);

because both address_space_destroy() and g_free_rcu()
try to use the same 'rcu' node in the AddressSpace struct
and the address_space_destroy hook gets overwritten.

Provide a new address_space_destroy_free() function which
will destroy the AS and then free the memory it uses, all
in one RCU callback.

(CC to stable because the next commit needs this function.)

Cc: qemu-stable@nongnu.org
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20250929144228.1994037-3-peter.maydell@linaro.org
Signed-off-by: Peter Xu <peterx@redhat.com>
(cherry picked from commit 041600e23f2fe2a9c252c9a8b26c7d147bedf982)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 2ad3f93344..ef6af5caee 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2635,11 +2635,24 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name);
  * Note that destruction of the AddressSpace is done via RCU;
  * it is therefore not valid to free the memory the AddressSpace
  * struct is in until after that RCU callback has completed.
+ * If you want to g_free() the AddressSpace after destruction you
+ * can do that with address_space_destroy_free().
  *
  * @as: address space to be destroyed
  */
 void address_space_destroy(AddressSpace *as);
 
+/**
+ * address_space_destroy_free: destroy an address space and free it
+ *
+ * This does the same thing as address_space_destroy(), and then also
+ * frees (via g_free()) the AddressSpace itself once the destruction
+ * is complete.
+ *
+ * @as: address space to be destroyed
+ */
+void address_space_destroy_free(AddressSpace *as);
+
 /**
  * address_space_remove_listeners: unregister all listeners of an address space
  *
diff --git a/system/memory.c b/system/memory.c
index 4c829793a0..94cb60c83b 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -3254,7 +3254,14 @@ static void do_address_space_destroy(AddressSpace *as)
     memory_region_unref(as->root);
 }
 
-void address_space_destroy(AddressSpace *as)
+static void do_address_space_destroy_free(AddressSpace *as)
+{
+    do_address_space_destroy(as);
+    g_free(as);
+}
+
+/* Detach address space from global view, notify all listeners */
+static void address_space_detach(AddressSpace *as)
 {
     MemoryRegion *root = as->root;
 
@@ -3269,9 +3276,20 @@ void address_space_destroy(AddressSpace *as)
      * values to expire before freeing the data.
      */
     as->root = root;
+}
+
+void address_space_destroy(AddressSpace *as)
+{
+    address_space_detach(as);
     call_rcu(as, do_address_space_destroy, rcu);
 }
 
+void address_space_destroy_free(AddressSpace *as)
+{
+    address_space_detach(as);
+    call_rcu(as, do_address_space_destroy_free, rcu);
+}
+
 static const char *memory_region_type(MemoryRegion *mr)
 {
     if (mr->alias) {
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 56/58] physmem: Destroy all CPU AddressSpaces on unrealize
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (16 preceding siblings ...)
  2025-10-05 17:37 ` [Stable-10.0.5 55/58] memory: New AS helper to serialize destroy+free Michael Tokarev
@ 2025-10-05 17:37 ` Michael Tokarev
  2025-10-05 17:37 ` [Stable-10.0.5 57/58] tests/functional/test_ppc_bamboo: Replace broken link with working assets Michael Tokarev
  2025-10-05 17:37 ` [Stable-10.0.5 58/58] tests/functional/test_aarch64_sbsaref_freebsd: Fix the URL of the ISO image Michael Tokarev
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Peter Maydell, David Hildenbrand, Peter Xu,
	Michael Tokarev

From: Peter Maydell <peter.maydell@linaro.org>

When we unrealize a CPU object (which happens on vCPU hot-unplug), we
should destroy all the AddressSpace objects we created via calls to
cpu_address_space_init() when the CPU was realized.

Commit 24bec42f3d6eae added a function to do this for a specific
AddressSpace, but did not add any places where the function was
called.

Since we always want to destroy all the AddressSpaces on unrealize,
regardless of the target architecture, we don't need to try to keep
track of how many are still undestroyed, or make the target
architecture code manually call a destroy function for each AS it
created.  Instead we can adjust the function to always completely
destroy the whole cpu->ases array, and arrange for it to be called
during CPU unrealize as part of the common code.

Without this fix, AddressSanitizer will report a leak like this
from a run where we hot-plugged and then hot-unplugged an x86 KVM
vCPU:

Direct leak of 416 byte(s) in 1 object(s) allocated from:
    #0 0x5b638565053d in calloc (/data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/qemu-system-x86_64+0x1ee153d) (BuildId: c1cd6022b195142106e1bffeca23498c2b752bca)
    #1 0x7c28083f77b1 in g_malloc0 (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x637b1) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75)
    #2 0x5b6386999c7c in cpu_address_space_init /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../system/physmem.c:797:25
    #3 0x5b638727f049 in kvm_cpu_realizefn /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../target/i386/kvm/kvm-cpu.c:102:5
    #4 0x5b6385745f40 in accel_cpu_common_realize /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../accel/accel-common.c:101:13
    #5 0x5b638568fe3c in cpu_exec_realizefn /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../hw/core/cpu-common.c:232:10
    #6 0x5b63874a2cd5 in x86_cpu_realizefn /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../target/i386/cpu.c:9321:5
    #7 0x5b6387a0469a in device_set_realized /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../hw/core/qdev.c:494:13
    #8 0x5b6387a27d9e in property_set_bool /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../qom/object.c:2375:5
    #9 0x5b6387a2090b in object_property_set /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../qom/object.c:1450:5
    #10 0x5b6387a35b05 in object_property_set_qobject /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../qom/qom-qobject.c:28:10
    #11 0x5b6387a21739 in object_property_set_bool /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../qom/object.c:1520:15
    #12 0x5b63879fe510 in qdev_realize /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../hw/core/qdev.c:276:12

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2517
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20250929144228.1994037-4-peter.maydell@linaro.org
Signed-off-by: Peter Xu <peterx@redhat.com>
(cherry picked from commit 300a87c502c4ba7ffc7720d8f3583e3d1a68348a)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 9064dd24f8..51a3b84afd 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -248,6 +248,7 @@ void cpu_exec_unrealizefn(CPUState *cpu)
      * accel_cpu_common_unrealize, which may free fields using call_rcu.
      */
     accel_cpu_common_unrealize(cpu);
+    cpu_destroy_address_spaces(cpu);
 }
 
 static void cpu_common_initfn(Object *obj)
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 3771b2130c..c48469c47b 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -132,13 +132,13 @@ size_t qemu_ram_pagesize_largest(void);
 void cpu_address_space_init(CPUState *cpu, int asidx,
                             const char *prefix, MemoryRegion *mr);
 /**
- * cpu_address_space_destroy:
- * @cpu: CPU for which address space needs to be destroyed
- * @asidx: integer index of this address space
+ * cpu_destroy_address_spaces:
+ * @cpu: CPU for which address spaces need to be destroyed
  *
- * Note that with KVM only one address space is supported.
+ * Destroy all address spaces associated with this CPU; this
+ * is called as part of unrealizing the CPU.
  */
-void cpu_address_space_destroy(CPUState *cpu, int asidx);
+void cpu_destroy_address_spaces(CPUState *cpu);
 
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             hwaddr len, bool is_write);
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index e136b067cd..2be01bcee9 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -500,7 +500,6 @@ struct CPUState {
     QSIMPLEQ_HEAD(, qemu_work_item) work_list;
 
     struct CPUAddressSpace *cpu_ases;
-    int cpu_ases_count;
     int num_ases;
     AddressSpace *as;
     MemoryRegion *memory;
diff --git a/stubs/cpu-destroy-address-spaces.c b/stubs/cpu-destroy-address-spaces.c
new file mode 100644
index 0000000000..dc6813f5bd
--- /dev/null
+++ b/stubs/cpu-destroy-address-spaces.c
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "exec/cpu-common.h"
+
+/*
+ * user-mode CPUs never create address spaces with
+ * cpu_address_space_init(), so the cleanup function doesn't
+ * need to do anything. We need this stub because cpu-common.c
+ * is built-once so it can't #ifndef CONFIG_USER around the
+ * call; the real function is in physmem.c which is system-only.
+ */
+void cpu_destroy_address_spaces(CPUState *cpu)
+{
+}
diff --git a/stubs/meson.build b/stubs/meson.build
index 63392f5e78..8b5387601f 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -55,6 +55,7 @@ endif
 if have_user
   # Symbols that are used by hw/core.
   stub_ss.add(files('cpu-synchronize-state.c'))
+  stub_ss.add(files('cpu-destroy-address-spaces.c'))
 
   # Stubs for QAPI events.  Those can always be included in the build, but
   # they are not built at all for --disable-system builds.
diff --git a/system/physmem.c b/system/physmem.c
index 82d453ddde..0c2652c25a 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -765,7 +765,6 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
 
     if (!cpu->cpu_ases) {
         cpu->cpu_ases = g_new0(CPUAddressSpace, cpu->num_ases);
-        cpu->cpu_ases_count = cpu->num_ases;
     }
 
     newas = &cpu->cpu_ases[asidx];
@@ -779,30 +778,29 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
     }
 }
 
-void cpu_address_space_destroy(CPUState *cpu, int asidx)
+void cpu_destroy_address_spaces(CPUState *cpu)
 {
     CPUAddressSpace *cpuas;
+    int asidx;
 
     assert(cpu->cpu_ases);
-    assert(asidx >= 0 && asidx < cpu->num_ases);
 
-    cpuas = &cpu->cpu_ases[asidx];
-    if (tcg_enabled()) {
-        memory_listener_unregister(&cpuas->tcg_as_listener);
-    }
+    /* convenience alias just points to some cpu_ases[n] */
+    cpu->as = NULL;
 
-    address_space_destroy(cpuas->as);
-    g_free_rcu(cpuas->as, rcu);
-
-    if (asidx == 0) {
-        /* reset the convenience alias for address space 0 */
-        cpu->as = NULL;
+    for (asidx = 0; asidx < cpu->num_ases; asidx++) {
+        cpuas = &cpu->cpu_ases[asidx];
+        if (!cpuas->as) {
+            /* This index was never initialized; no deinit needed */
+            continue;
+        }
+        if (tcg_enabled()) {
+            memory_listener_unregister(&cpuas->tcg_as_listener);
+        }
+        g_clear_pointer(&cpuas->as, address_space_destroy_free);
     }
 
-    if (--cpu->cpu_ases_count == 0) {
-        g_free(cpu->cpu_ases);
-        cpu->cpu_ases = NULL;
-    }
+    g_clear_pointer(&cpu->cpu_ases, g_free);
 }
 
 AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 57/58] tests/functional/test_ppc_bamboo: Replace broken link with working assets
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (17 preceding siblings ...)
  2025-10-05 17:37 ` [Stable-10.0.5 56/58] physmem: Destroy all CPU AddressSpaces on unrealize Michael Tokarev
@ 2025-10-05 17:37 ` Michael Tokarev
  2025-10-05 17:37 ` [Stable-10.0.5 58/58] tests/functional/test_aarch64_sbsaref_freebsd: Fix the URL of the ISO image Michael Tokarev
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Thomas Huth, Stefan Hajnoczi, Cédric Le Goater,
	Cédric Le Goater, Michael Tokarev

From: Thomas Huth <thuth@redhat.com>

The old image that we used for testing the bamboo machine has disappeared
from the internet. Fortunately there is another kernel + initrd provided
by Cédric that can be used for testing this machine, too.

Reported-by: Stefan Hajnoczi <stefanha@gmail.com>
Suggested-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20250707184736.88660-1-thuth@redhat.com>
(cherry picked from commit 3b1cf40dd665a0c4c38bc339fea6eacf1742b46c)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/functional/test_ppc_bamboo.py b/tests/functional/test_ppc_bamboo.py
index fddcc24d0d..c634ae7b4a 100755
--- a/tests/functional/test_ppc_bamboo.py
+++ b/tests/functional/test_ppc_bamboo.py
@@ -16,28 +16,32 @@ class BambooMachine(QemuSystemTest):
 
     timeout = 90
 
-    ASSET_IMAGE = Asset(
-        ('http://landley.net/aboriginal/downloads/binaries/'
-         'system-image-powerpc-440fp.tar.gz'),
-        'c12b58f841c775a0e6df4832a55afe6b74814d1565d08ddeafc1fb949a075c5e')
+    ASSET_KERNEL = Asset(
+        ('https://github.com/legoater/qemu-ppc-boot/raw/refs/heads/main/'
+         'buildroot/qemu_ppc_bamboo-2023.11-8-gdcd9f0f6eb-20240105/vmlinux'),
+        'a2e12eb45b73491ac62fc0bbeb68dead0dc5c0f22cf83146558389209b420ad1')
+    ASSET_INITRD = Asset(
+        ('https://github.com/legoater/qemu-ppc-boot/raw/refs/heads/main/'
+         'buildroot/qemu_ppc_bamboo-2023.11-8-gdcd9f0f6eb-20240105/rootfs.cpio'),
+        'd2a36bdb8763b389765dc8c29d4904cec2bd001c587f92e85ab9eb10d5ddda54')
 
     def test_ppc_bamboo(self):
         self.set_machine('bamboo')
         self.require_accelerator("tcg")
         self.require_netdev('user')
-        self.archive_extract(self.ASSET_IMAGE)
+
+        kernel = self.ASSET_KERNEL.fetch()
+        initrd = self.ASSET_INITRD.fetch()
+
         self.vm.set_console()
-        self.vm.add_args('-kernel',
-                         self.scratch_file('system-image-powerpc-440fp',
-                                           'linux'),
-                         '-initrd',
-                         self.scratch_file('system-image-powerpc-440fp',
-                                           'rootfs.cpio.gz'),
-                         '-nic', 'user,model=rtl8139,restrict=on')
+        self.vm.add_args('-kernel', kernel,
+                         '-initrd', initrd,
+                         '-nic', 'user,model=virtio-net-pci,restrict=on')
         self.vm.launch()
-        wait_for_console_pattern(self, 'Type exit when done')
-        exec_command_and_wait_for_pattern(self, 'ping 10.0.2.2',
-                                          '10.0.2.2 is alive!')
+        wait_for_console_pattern(self, 'buildroot login:')
+        exec_command_and_wait_for_pattern(self, 'root', '#')
+        exec_command_and_wait_for_pattern(self, 'ping -c1 10.0.2.2',
+                '1 packets transmitted, 1 packets received, 0% packet loss')
         exec_command_and_wait_for_pattern(self, 'halt', 'System Halted')
 
 if __name__ == '__main__':
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Stable-10.0.5 58/58] tests/functional/test_aarch64_sbsaref_freebsd: Fix the URL of the ISO image
  2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
                   ` (18 preceding siblings ...)
  2025-10-05 17:37 ` [Stable-10.0.5 57/58] tests/functional/test_ppc_bamboo: Replace broken link with working assets Michael Tokarev
@ 2025-10-05 17:37 ` Michael Tokarev
  19 siblings, 0 replies; 21+ messages in thread
From: Michael Tokarev @ 2025-10-05 17:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Thomas Huth, Stefan Hajnoczi, Michael Tokarev

From: Thomas Huth <thuth@redhat.com>

The original image has been removed from the server, so the test
currently fails if it has to fetch the asset, but we can still
download the ISO from the archive server. While we're at it, prefer
the XZ compressed image, it's much smaller and thus the download
should be faster.

Message-ID: <20250701105809.366180-1-thuth@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit 01e2b1bc27bae874bfeb6978ce093deac5bb9639)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/functional/test_aarch64_sbsaref_freebsd.py b/tests/functional/test_aarch64_sbsaref_freebsd.py
index bd6728dc70..2a26281d25 100755
--- a/tests/functional/test_aarch64_sbsaref_freebsd.py
+++ b/tests/functional/test_aarch64_sbsaref_freebsd.py
@@ -20,9 +20,9 @@
 class Aarch64SbsarefFreeBSD(QemuSystemTest):
 
     ASSET_FREEBSD_ISO = Asset(
-        ('https://download.freebsd.org/releases/arm64/aarch64/ISO-IMAGES/'
-         '14.1/FreeBSD-14.1-RELEASE-arm64-aarch64-bootonly.iso'),
-        '44cdbae275ef1bb6dab1d5fbb59473d4f741e1c8ea8a80fd9e906b531d6ad461')
+        ('http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/arm64'
+         '/aarch64/ISO-IMAGES/14.1/FreeBSD-14.1-RELEASE-arm64-aarch64-bootonly.iso.xz'),
+        '7313a4495ffd71ab77b49b1e83f571521c32756e1d75bf48bd890e0ab0f75827')
 
     # This tests the whole boot chain from EFI to Userspace
     # We only boot a whole OS for the current top level CPU and GIC
@@ -30,7 +30,7 @@ class Aarch64SbsarefFreeBSD(QemuSystemTest):
     def boot_freebsd14(self, cpu=None):
         fetch_firmware(self)
 
-        img_path = self.ASSET_FREEBSD_ISO.fetch()
+        img_path = self.uncompress(self.ASSET_FREEBSD_ISO)
 
         self.vm.set_console()
         self.vm.add_args(
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2025-10-05 17:42 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-05 17:36 [Stable-10.0.5 v2 00/58] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 (frozen) Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 39/58] hw/usb/hcd-uhci: don't assert for SETUP to non-0 endpoint Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 40/58] hw/intc/xics: Add missing call to register vmstate_icp_server Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 41/58] ppc/spapr: init lrdr-capapcity phys with ram size if maxmem not provided Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 42/58] ui/spice: Fix abort on macOS Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 43/58] ui/icons/qemu.svg: Add metadata information (author, license) to the logo Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 44/58] hw/riscv/riscv-iommu: Fix MSI table size limit Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 45/58] docs/interop/firmware: Add riscv64 to FirmwareArchitecture Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 46/58] hw/char: sifive_uart: Raise IRQ according to the Tx/Rx watermark thresholds Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 47/58] target/riscv: use riscv_csrr in riscv_csr_read Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 48/58] target/riscv: do not use translator_ldl in opcode_at Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 49/58] hw/riscv/riscv-iommu: Fixup PDT Nested Walk Michael Tokarev
2025-10-05 17:36 ` [Stable-10.0.5 50/58] target/riscv: Fix endianness swap on compressed instructions Michael Tokarev
2025-10-05 17:37 ` [Stable-10.0.5 51/58] target/riscv: rvv: Replace checking V by checking Zve32x Michael Tokarev
2025-10-05 17:37 ` [Stable-10.0.5 52/58] target/riscv: rvv: Modify minimum VLEN according to enabled vector extensions Michael Tokarev
2025-10-05 17:37 ` [Stable-10.0.5 53/58] migration: Fix state transition in postcopy_start() error handling Michael Tokarev
2025-10-05 17:37 ` [Stable-10.0.5 54/58] include/system/memory.h: Clarify address_space_destroy() behaviour Michael Tokarev
2025-10-05 17:37 ` [Stable-10.0.5 55/58] memory: New AS helper to serialize destroy+free Michael Tokarev
2025-10-05 17:37 ` [Stable-10.0.5 56/58] physmem: Destroy all CPU AddressSpaces on unrealize Michael Tokarev
2025-10-05 17:37 ` [Stable-10.0.5 57/58] tests/functional/test_ppc_bamboo: Replace broken link with working assets Michael Tokarev
2025-10-05 17:37 ` [Stable-10.0.5 58/58] tests/functional/test_aarch64_sbsaref_freebsd: Fix the URL of the ISO image Michael Tokarev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).