qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06
@ 2025-08-27 15:02 Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 01/59] host-utils: Drop workaround for buggy Apple Clang __builtin_subcll() Michael Tokarev
                   ` (58 more replies)
  0 siblings, 59 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Michael Tokarev

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

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

Patch freeze is 2025-09-06, and the release is planned for 2025-09-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 e74aad9f81cc Peter Maydell:
   host-utils: Drop workaround for buggy Apple Clang __builtin_subcll()
02 b8882becd572 Michael Tokarev:
   hw/display/qxl-render.c: fix qxl_unpack_chunks() chunk size calculation
03 feea87cd6b64 Paolo Bonzini:
   target/i386: fix width of third operand of VINSERTx128
04 3cdd990aa920 Peter Maydell:
   linux-user/aarch64: Clear TPIDR2_EL0 when delivering signals
05 99870aff907b Peter Maydell:
   linux-user/aarch64: Support TPIDR2_MAGIC signal frame record
06 8d6c7de1cc71 Alex Bennée:
   docs/user: clarify user-mode expects the same OS
07 e895095c78ab Philippe Mathieu-Daudé:
   target/mips: Only update MVPControl.EVP bit if executed by master VPE
08 2bfcd27e00a4 Luc Michel:
   hw/net/cadence_gem: fix register mask initialization
09 2865bf1c5795 Pierrick Bouvier:
   system/physmem: fix use-after-free with dispatch
10 653a75a9d7f9 Michael Tokarev:
   roms/Makefile: fix npcmNxx_bootrom build rules
11 e111ffe48b29 Daniel Henrique Barboza:
   linux-user/strace.list: add riscv_hwprobe entry
12 16aa7771afea Daniel Henrique Barboza:
   target/riscv: do not call GETPC() in check_ret_from_m_mode()
13 30ef718423e8 Xu Lu:
   target/riscv: Fix exception type when VU accesses supervisor CSRs
14 77707bfdf871 Vac Chen:
   target/riscv: Fix pmp range wraparound on zero
15 b6f1244678be Yang Jialong:
   intc/riscv_aplic: Fix target register read when source is inactive
16 e443ba03361b Jay Chang:
   target/riscv: Restrict mideleg/medeleg/medelegh access to S-mode harts
17 86bc3a0abf10 Jay Chang:
   target/riscv: Restrict midelegh access to S-mode harts
18 caab7ac83507 Bibo Mao:
   target/loongarch: Fix valid virtual address checking
19 6fcf5ebafad6 Jonah Palmer:
   virtio: fix off-by-one and invalid access in virtqueue_ordered_fill
20 c1997099dc26 Hanna Czenczek:
   vhost: Do not abort on log-start error
21 d63c388dadb7 Hanna Czenczek:
   vhost: Do not abort on log-stop error
22 6071d13c6a37 Akihiko Odaki:
   virtio-net: Fix VLAN filter table reset timing
23 cad9aa6fbdcc Akihiko Odaki:
   pcie_sriov: Fix configuration and state synchronization
24 e8145dcd311b David Woodhouse:
   intel_iommu: Allow both Status Write and Interrupt Flag in QI wait
25 a7842d94067c Sairaj Kodilkar:
   hw/i386/amd_iommu: Move IOAPIC memory region initialization to the end
26 b10bd4bd17ac Zenghui Yu:
   hw/intc/arm_gicv3_kvm: Write all 1's to clear enable/active
27 35cca0f95ff5 Vacha Bhavsar:
   target/arm: Fix big-endian handling of NEON gdb remote debugging
28 97b3d732afec Vacha Bhavsar:
   target/arm: Fix handling of setting SVE registers from gdb
29 13ed972b4ce5 Jamin Lin:
   hw/ssi/aspeed_smc: Fix incorrect FMC_WDT2 register read on AST1030
30 cd9f752fee75 Alex Richardson:
   target/arm: add support for 64-bit PMCCNTR in AArch32 mode
31 0311a6edb9db Peter Maydell:
   scripts/make-release: Go back to cloning all the EDK2 submodules
32 b217d987a3c5 Michael Tokarev:
   qga: correctly write to /sys/power/state on linux
33 d973766e10 Michael Tokarev:
   Revert "i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16]"
34 e68ec2980901 Xiaoyao Li:
   i386/cpu: Move adjustment of CPUID_EXT_PDCM before feature_dependencies[] 
   check
35 f985a1195ba2 Chuang Xu:
   i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16]
36 a62fef582995 Qian Wen:
   i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16]
37 4e5d58969ed6 Zhao Liu:
   target/i386/cpu: Move addressable ID encoding out of compat property in 
   CPUID[0x1]
38 301fbbaf03fb Nicholas Piggin:
   ppc/xive: Fix xive trace event output
39 f0aab779418e Nicholas Piggin:
   ppc/xive: Report access size in XIVE TM operation error logs
40 f16697292add Glenn Miles:
   ppc/xive2: Fix calculation of END queue sizes
41 e8cf73b84987 Michael Kowal:
   ppc/xive2: Remote VSDs need to match on forwarding address
42 d1023a296c82 Nicholas Piggin:
   ppc/xive2: fix context push calculation of IPB priority
43 bde8c148bb22 Nicholas Piggin:
   ppc/xive: Fix PHYS NSR ring matching
44 576830428eea Michael Kowal:
   ppc/xive2: Reset Generation Flipped bit on END Cache Watch
45 8d373176181f Glenn Miles:
   ppc/xive2: Fix irq preempted by lower priority group irq
46 d4720a7faf4b Glenn Miles:
   ppc/xive2: Fix treatment of PIPR in CPPR update
47 c7ac771ee750 William Hu:
   ui/curses: Fix infinite loop on windows
48 e66644c48e96 WANG Rui:
   target/loongarch: Fix [X]VLDI raising exception incorrectly
49 31b737b19dca Klaus Jensen:
   hw/nvme: fix namespace attachment
50 bc0c24fdb157 Klaus Jensen:
   hw/nvme: revert CMIC behavior
51 53493c1f836f Keith Busch:
   hw/nvme: cap MDTS value for internal limitation
52 4af976ef398e Kevin Wolf:
   rbd: Fix .bdrv_get_specific_info implementation
53 c0df98ab1f3d Werner Fink:
   qemu-iotests: Ignore indentation in Killed messages
54 e262646e12ac Philippe Mathieu-Daudé:
   hw/sd/ssi-sd: Return noise (dummy byte) when no card connected
55 6ad034e71232 Sv. Lockal:
   mkvenv: Support pip 25.2
56 f757d9d90d19 Mauro Matteo Cascella:
   hw/uefi: clear uefi-vars buffer in uefi_vars_write callback
57 88e5a28d5aab Gerd Hoffmann:
   hw/uefi: return success for notifications
58 fc8ee8fe58ad Gerd Hoffmann:
   hw/uefi: check access for first variable
59 040237436f42 Gerd Hoffmann:
   hw/uefi: open json file in binary mode


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

* [Stable-10.0.4 01/59] host-utils: Drop workaround for buggy Apple Clang __builtin_subcll()
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 02/59] hw/display/qxl-render.c: fix qxl_unpack_chunks() chunk size calculation Michael Tokarev
                   ` (57 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Peter Maydell, Thomas Huth, Richard Henderson,
	Philippe Mathieu-Daudé, Michael Tokarev

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

In commit b0438861efe ("host-utils: Avoid using __builtin_subcll on
buggy versions of Apple Clang") we added a workaround for a bug in
Apple Clang 14 where its __builtin_subcll() implementation was wrong.
This bug was only present in Apple Clang 14, not in upstream clang,
and is not present in Apple Clang versions 15 and newer.

Since commit 4e035201 we have required at least Apple Clang 15, so we
no longer build with the buggy versions.  We can therefore drop the
workaround. This is effectively a revert of b0438861efe.

This should not be backported to stable branches, which may still
need to support Apple Clang 14.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3030
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20250714145033.1908788-1-peter.maydell@linaro.org
(cherry picked from commit e74aad9f81cc2bfee2057086610e21bd98e9c5a5)
(Mjt: 10.0 already requres clang 15+, so it's okay to backport
 this change to 10.0 branch)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 496dac5ac1..33b425dcf3 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -182,19 +182,6 @@
 #define QEMU_DISABLE_CFI
 #endif
 
-/*
- * Apple clang version 14 has a bug in its __builtin_subcll(); define
- * BUILTIN_SUBCLL_BROKEN for the offending versions so we can avoid it.
- * When a version of Apple clang which has this bug fixed is released
- * we can add an upper bound to this check.
- * See https://gitlab.com/qemu-project/qemu/-/issues/1631
- * and https://gitlab.com/qemu-project/qemu/-/issues/1659 for details.
- * The bug never made it into any upstream LLVM releases, only Apple ones.
- */
-#if defined(__apple_build_version__) && __clang_major__ >= 14
-#define BUILTIN_SUBCLL_BROKEN
-#endif
-
 #if __has_attribute(annotate)
 #define QEMU_ANNOTATE(x) __attribute__((annotate(x)))
 #else
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index 4d28fa22cf..dd558589cb 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -677,7 +677,7 @@ static inline uint64_t uadd64_carry(uint64_t x, uint64_t y, bool *pcarry)
  */
 static inline uint64_t usub64_borrow(uint64_t x, uint64_t y, bool *pborrow)
 {
-#if __has_builtin(__builtin_subcll) && !defined(BUILTIN_SUBCLL_BROKEN)
+#if __has_builtin(__builtin_subcll)
     unsigned long long b = *pborrow;
     x = __builtin_subcll(x, y, b, &b);
     *pborrow = b & 1;
-- 
2.47.2



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

* [Stable-10.0.4 02/59] hw/display/qxl-render.c: fix qxl_unpack_chunks() chunk size calculation
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 01/59] host-utils: Drop workaround for buggy Apple Clang __builtin_subcll() Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 03/59] target/i386: fix width of third operand of VINSERTx128 Michael Tokarev
                   ` (56 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Michael Tokarev, Thomas Huth

In case of multiple chunks, code in qxl_unpack_chunks() takes size of the
wrong (next in the chain) chunk, instead of using current chunk size.
This leads to wrong number of bytes being copied, and to crashes if next
chunk size is larger than the current one.

Based on the code by Gao Yong.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1628
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit b8882becd572d3afb888c836a6ffc7f92c17d1c5)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c
index eda6d3de37..c6a9ac1da1 100644
--- a/hw/display/qxl-render.c
+++ b/hw/display/qxl-render.c
@@ -222,6 +222,7 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,
     uint32_t max_chunks = 32;
     size_t offset = 0;
     size_t bytes;
+    QXLPHYSICAL next_chunk_phys = 0;
 
     for (;;) {
         bytes = MIN(size - offset, chunk->data_size);
@@ -230,7 +231,15 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,
         if (offset == size) {
             return;
         }
-        chunk = qxl_phys2virt(qxl, chunk->next_chunk, group_id,
+        next_chunk_phys = chunk->next_chunk;
+        /* fist time, only get the next chunk's data size */
+        chunk = qxl_phys2virt(qxl, next_chunk_phys, group_id,
+                              sizeof(QXLDataChunk));
+        if (!chunk) {
+            return;
+        }
+        /* second time, check data size and get data */
+        chunk = qxl_phys2virt(qxl, next_chunk_phys, group_id,
                               sizeof(QXLDataChunk) + chunk->data_size);
         if (!chunk) {
             return;
-- 
2.47.2



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

* [Stable-10.0.4 03/59] target/i386: fix width of third operand of VINSERTx128
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 01/59] host-utils: Drop workaround for buggy Apple Clang __builtin_subcll() Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 02/59] hw/display/qxl-render.c: fix qxl_unpack_chunks() chunk size calculation Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 04/59] linux-user/aarch64: Clear TPIDR2_EL0 when delivering signals Michael Tokarev
                   ` (55 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Paolo Bonzini, Eric Biggers, Ard Biesheuvel,
	Jason A. Donenfeld, Guenter Roeck, Michael Tokarev

From: Paolo Bonzini <pbonzini@redhat.com>

Table A-5 of the Intel manual incorrectly lists the third operand of
VINSERTx128 as Wqq, but it is actually a 128-bit value.  This is
visible when W is a memory operand close to the end of the page.

Fixes the recently-added poly1305_kunit test in linux-next.

(No testcase yet, but I plan to modify test-avx2 to use memory
close to the end of the page.  This would work because the test
vectors correctly have the memory operand as xmm2/m128).

Reported-by: Eric Biggers <ebiggers@kernel.org>
Tested-by: Eric Biggers <ebiggers@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: qemu-stable@nongnu.org
Fixes: 79068477686 ("target/i386: reimplement 0x0f 0x3a, add AVX", 2022-10-18)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit feea87cd6b645d5166bdd304aac88f47f63dc2ef)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.c.inc
index cda32ee678..f4cfc196b8 100644
--- a/target/i386/tcg/decode-new.c.inc
+++ b/target/i386/tcg/decode-new.c.inc
@@ -878,10 +878,10 @@ static const X86OpEntry opcodes_0F3A[256] = {
     [0x0e] = X86_OP_ENTRY4(VPBLENDW,   V,x,  H,x,  W,x,  vex4 cpuid(SSE41) avx2_256 p_66),
     [0x0f] = X86_OP_ENTRY4(PALIGNR,    V,x,  H,x,  W,x,  vex4 cpuid(SSSE3) mmx avx2_256 p_00_66),
 
-    [0x18] = X86_OP_ENTRY4(VINSERTx128,  V,qq, H,qq, W,qq, vex6 chk(W0) cpuid(AVX) p_66),
+    [0x18] = X86_OP_ENTRY4(VINSERTx128,  V,qq, H,qq, W,dq, vex6 chk(W0) cpuid(AVX) p_66),
     [0x19] = X86_OP_ENTRY3(VEXTRACTx128, W,dq, V,qq, I,b,  vex6 chk(W0) cpuid(AVX) p_66),
 
-    [0x38] = X86_OP_ENTRY4(VINSERTx128,  V,qq, H,qq, W,qq, vex6 chk(W0) cpuid(AVX2) p_66),
+    [0x38] = X86_OP_ENTRY4(VINSERTx128,  V,qq, H,qq, W,dq, vex6 chk(W0) cpuid(AVX2) p_66),
     [0x39] = X86_OP_ENTRY3(VEXTRACTx128, W,dq, V,qq, I,b,  vex6 chk(W0) cpuid(AVX2) p_66),
 
     /* Listed incorrectly as type 4 */
-- 
2.47.2



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

* [Stable-10.0.4 04/59] linux-user/aarch64: Clear TPIDR2_EL0 when delivering signals
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (2 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 03/59] target/i386: fix width of third operand of VINSERTx128 Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 05/59] linux-user/aarch64: Support TPIDR2_MAGIC signal frame record Michael Tokarev
                   ` (54 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Peter Maydell, Richard Henderson, Pierrick Bouvier,
	Michael Tokarev

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

A recent change to the kernel (Linux commit b376108e1f88
"arm64/fpsimd: signal: Clear TPIDR2 when delivering signals") updated
the signal-handler entry code to always clear TPIDR2_EL0.

This is necessary for the userspace ZA lazy saving scheme to work
correctly when unwinding exceptions across a signal boundary.
(For the essay-length description of the incorrect behaviour and
why this is the correct fix, see the commit message for the
kernel commit.)

Make QEMU also clear TPIDR2_EL0 on signal entry, applying the
equivalent bugfix to our implementation.

Note that getting this unwinding to work correctly also requires
changes to the userspace code, e.g.  as implemented in gcc in
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b5ffc8e75a8

This change is technically an ABI change; from the kernel's
point of view SME was never enabled (it was hidden behind
CONFIG_BROKEN) before the change. From QEMU's point of view
our SME-related signal handling was broken anyway as we weren't
saving and restoring TPIDR2_EL0.

Cc: qemu-stable@nongnu.org
Fixes: 78011586b90d1 ("target/arm: Enable SME for user-only")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250725175510.3864231-2-peter.maydell@linaro.org>
(cherry picked from commit 3cdd990aa920ec8f2994b634f758dab4a86ac167)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c
index bc7a13800d..df85354adc 100644
--- a/linux-user/aarch64/signal.c
+++ b/linux-user/aarch64/signal.c
@@ -666,8 +666,12 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
         env->btype = 2;
     }
 
-    /* Invoke the signal handler with both SM and ZA disabled. */
+    /*
+     * Invoke the signal handler with a clean SME state: both SM and ZA
+     * disabled and TPIDR2_EL0 cleared.
+     */
     aarch64_set_svcr(env, 0, R_SVCR_SM_MASK | R_SVCR_ZA_MASK);
+    env->cp15.tpidr2_el0 = 0;
 
     if (info) {
         frame->info = *info;
-- 
2.47.2



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

* [Stable-10.0.4 05/59] linux-user/aarch64: Support TPIDR2_MAGIC signal frame record
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (3 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 04/59] linux-user/aarch64: Clear TPIDR2_EL0 when delivering signals Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 06/59] docs/user: clarify user-mode expects the same OS Michael Tokarev
                   ` (53 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Peter Maydell, Richard Henderson, Pierrick Bouvier,
	Michael Tokarev

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

FEAT_SME adds the TPIDR2 userspace-accessible system register, which
is used as part of the procedure calling standard's lazy saving
scheme for the ZA registers:
 https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#66the-za-lazy-saving-scheme

The Linux kernel has a signal frame record for saving
and restoring this value when calling signal handlers, but
we forgot to implement this. The result is that code which
tries to unwind an exception out of a signal handler will
not work correctly.

Add support for the missing record.

Cc: qemu-stable@nongnu.org
Fixes: 78011586b90d1 ("target/arm: Enable SME for user-only")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250725175510.3864231-3-peter.maydell@linaro.org>
(cherry picked from commit 99870aff907b1c863cd32558b543f0ab0d0e74ba)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c
index df85354adc..cdb642839c 100644
--- a/linux-user/aarch64/signal.c
+++ b/linux-user/aarch64/signal.c
@@ -121,6 +121,13 @@ struct target_za_context {
 #define TARGET_ZA_SIG_CONTEXT_SIZE(VQ) \
     TARGET_ZA_SIG_ZAV_OFFSET(VQ, VQ * TARGET_SVE_VQ_BYTES)
 
+#define TARGET_TPIDR2_MAGIC 0x54504902
+
+struct target_tpidr2_context {
+    struct target_aarch64_ctx head;
+    uint64_t tpidr2;
+};
+
 struct target_rt_sigframe {
     struct target_siginfo info;
     struct target_ucontext uc;
@@ -253,6 +260,14 @@ static void target_setup_za_record(struct target_za_context *za,
     }
 }
 
+static void target_setup_tpidr2_record(struct target_tpidr2_context *tpidr2,
+                                       CPUARMState *env)
+{
+    __put_user(TARGET_TPIDR2_MAGIC, &tpidr2->head.magic);
+    __put_user(sizeof(struct target_tpidr2_context), &tpidr2->head.size);
+    __put_user(env->cp15.tpidr2_el0, &tpidr2->tpidr2);
+}
+
 static void target_restore_general_frame(CPUARMState *env,
                                          struct target_rt_sigframe *sf)
 {
@@ -403,6 +418,12 @@ static bool target_restore_za_record(CPUARMState *env,
     return true;
 }
 
+static void target_restore_tpidr2_record(CPUARMState *env,
+                                         struct target_tpidr2_context *tpidr2)
+{
+    __get_user(env->cp15.tpidr2_el0, &tpidr2->tpidr2);
+}
+
 static int target_restore_sigframe(CPUARMState *env,
                                    struct target_rt_sigframe *sf)
 {
@@ -410,6 +431,7 @@ static int target_restore_sigframe(CPUARMState *env,
     struct target_fpsimd_context *fpsimd = NULL;
     struct target_sve_context *sve = NULL;
     struct target_za_context *za = NULL;
+    struct target_tpidr2_context *tpidr2 = NULL;
     uint64_t extra_datap = 0;
     bool used_extra = false;
     int sve_size = 0;
@@ -460,6 +482,14 @@ static int target_restore_sigframe(CPUARMState *env,
             za_size = size;
             break;
 
+        case TARGET_TPIDR2_MAGIC:
+            if (tpidr2 || size != sizeof(struct target_tpidr2_context) ||
+                !cpu_isar_feature(aa64_sme, env_archcpu(env))) {
+                goto err;
+            }
+            tpidr2 = (struct target_tpidr2_context *)ctx;
+            break;
+
         case TARGET_EXTRA_MAGIC:
             if (extra || size != sizeof(struct target_extra_context)) {
                 goto err;
@@ -497,6 +527,9 @@ static int target_restore_sigframe(CPUARMState *env,
     if (za && !target_restore_za_record(env, za, za_size, &svcr)) {
         goto err;
     }
+    if (tpidr2) {
+        target_restore_tpidr2_record(env, tpidr2);
+    }
     if (env->svcr != svcr) {
         env->svcr = svcr;
         arm_rebuild_hflags(env);
@@ -568,8 +601,8 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
         .total_size = offsetof(struct target_rt_sigframe,
                                uc.tuc_mcontext.__reserved),
     };
-    int fpsimd_ofs, fr_ofs, sve_ofs = 0, za_ofs = 0;
-    int sve_size = 0, za_size = 0;
+    int fpsimd_ofs, fr_ofs, sve_ofs = 0, za_ofs = 0, tpidr2_ofs = 0;
+    int sve_size = 0, za_size = 0, tpidr2_size = 0;
     struct target_rt_sigframe *frame;
     struct target_rt_frame_record *fr;
     abi_ulong frame_addr, return_addr;
@@ -585,6 +618,8 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
         sve_ofs = alloc_sigframe_space(sve_size, &layout);
     }
     if (cpu_isar_feature(aa64_sme, env_archcpu(env))) {
+        tpidr2_size = sizeof(struct target_tpidr2_context);
+        tpidr2_ofs = alloc_sigframe_space(tpidr2_size, &layout);
         /* ZA state needs saving only if it is enabled.  */
         if (FIELD_EX64(env->svcr, SVCR, ZA)) {
             za_size = TARGET_ZA_SIG_CONTEXT_SIZE(sme_vq(env));
@@ -644,6 +679,9 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
     if (za_ofs) {
         target_setup_za_record((void *)frame + za_ofs, env, za_size);
     }
+    if (tpidr2_ofs) {
+        target_setup_tpidr2_record((void *)frame + tpidr2_ofs, env);
+    }
 
     /* Set up the stack frame for unwinding.  */
     fr = (void *)frame + fr_ofs;
-- 
2.47.2



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

* [Stable-10.0.4 06/59] docs/user: clarify user-mode expects the same OS
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (4 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 05/59] linux-user/aarch64: Support TPIDR2_MAGIC signal frame record Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 07/59] target/mips: Only update MVPControl.EVP bit if executed by master VPE Michael Tokarev
                   ` (52 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Alex Bennée, Manos Pitsidianakis,
	Michael Tokarev

From: Alex Bennée <alex.bennee@linaro.org>

While we somewhat cover this later when we talk about supported
operating systems make it clear in the front matter.

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-ID: <20250725154517.3523095-2-alex.bennee@linaro.org>
(cherry picked from commit 8d6c7de1cc71207ccc047583df0c84363a5da16b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/docs/user/index.rst b/docs/user/index.rst
index 782d27cda2..2307580cb9 100644
--- a/docs/user/index.rst
+++ b/docs/user/index.rst
@@ -5,8 +5,9 @@ User Mode Emulation
 -------------------
 
 This section of the manual is the overall guide for users using QEMU
-for user-mode emulation.  In this mode, QEMU can launch
-processes compiled for one CPU on another CPU.
+for user-mode emulation. In this mode, QEMU can launch programs
+compiled for one CPU architecture on the same Operating System (OS)
+but running on a different CPU architecture.
 
 .. toctree::
    :maxdepth: 2
-- 
2.47.2



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

* [Stable-10.0.4 07/59] target/mips: Only update MVPControl.EVP bit if executed by master VPE
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (5 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 06/59] docs/user: clarify user-mode expects the same OS Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 08/59] hw/net/cadence_gem: fix register mask initialization Michael Tokarev
                   ` (51 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Philippe Mathieu-Daudé, Jiaxun Yang,
	Philippe Mathieu-Daudé, Michael Tokarev

From: Philippe Mathieu-Daudé <f4bug@amsat.org>

According to the 'MIPS MT Application-Specific Extension' manual:

  If the VPE executing the instruction is not a Master VPE,
  with the MVP bit of the VPEConf0 register set, the EVP bit
  is unchanged by the instruction.

Modify the DVPE/EVPE opcodes to only update the MVPControl.EVP bit
if executed on a master VPE.

Cc: qemu-stable@nongnu.org
Reported-by: Hansni Bu
Buglink: https://bugs.launchpad.net/qemu/+bug/1926277
Fixes: f249412c749 ("mips: Add MT halting and waking of VPEs")
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Message-ID: <20210427133343.159718-1-f4bug@amsat.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit e895095c78ab877d40df2dd31ee79d85757d963b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/mips/tcg/system/cp0_helper.c b/target/mips/tcg/system/cp0_helper.c
index 78e422b0ca..97b7fb5e67 100644
--- a/target/mips/tcg/system/cp0_helper.c
+++ b/target/mips/tcg/system/cp0_helper.c
@@ -1561,12 +1561,14 @@ target_ulong helper_dvpe(CPUMIPSState *env)
     CPUState *other_cs = first_cpu;
     target_ulong prev = env->mvp->CP0_MVPControl;
 
-    CPU_FOREACH(other_cs) {
-        MIPSCPU *other_cpu = MIPS_CPU(other_cs);
-        /* Turn off all VPEs except the one executing the dvpe.  */
-        if (&other_cpu->env != env) {
-            other_cpu->env.mvp->CP0_MVPControl &= ~(1 << CP0MVPCo_EVP);
-            mips_vpe_sleep(other_cpu);
+    if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {
+        CPU_FOREACH(other_cs) {
+            MIPSCPU *other_cpu = MIPS_CPU(other_cs);
+            /* Turn off all VPEs except the one executing the dvpe.  */
+            if (&other_cpu->env != env) {
+                other_cpu->env.mvp->CP0_MVPControl &= ~(1 << CP0MVPCo_EVP);
+                mips_vpe_sleep(other_cpu);
+            }
         }
     }
     return prev;
@@ -1577,15 +1579,17 @@ target_ulong helper_evpe(CPUMIPSState *env)
     CPUState *other_cs = first_cpu;
     target_ulong prev = env->mvp->CP0_MVPControl;
 
-    CPU_FOREACH(other_cs) {
-        MIPSCPU *other_cpu = MIPS_CPU(other_cs);
+    if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {
+        CPU_FOREACH(other_cs) {
+            MIPSCPU *other_cpu = MIPS_CPU(other_cs);
 
-        if (&other_cpu->env != env
-            /* If the VPE is WFI, don't disturb its sleep.  */
-            && !mips_vpe_is_wfi(other_cpu)) {
-            /* Enable the VPE.  */
-            other_cpu->env.mvp->CP0_MVPControl |= (1 << CP0MVPCo_EVP);
-            mips_vpe_wake(other_cpu); /* And wake it up.  */
+            if (&other_cpu->env != env
+                /* If the VPE is WFI, don't disturb its sleep.  */
+                && !mips_vpe_is_wfi(other_cpu)) {
+                /* Enable the VPE.  */
+                other_cpu->env.mvp->CP0_MVPControl |= (1 << CP0MVPCo_EVP);
+                mips_vpe_wake(other_cpu); /* And wake it up.  */
+            }
         }
     }
     return prev;
-- 
2.47.2



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

* [Stable-10.0.4 08/59] hw/net/cadence_gem: fix register mask initialization
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (6 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 07/59] target/mips: Only update MVPControl.EVP bit if executed by master VPE Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 09/59] system/physmem: fix use-after-free with dispatch Michael Tokarev
                   ` (50 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Luc Michel, Francisco Iglesias, Sai Pavan Boddu,
	Philippe Mathieu-Daudé, Michael Tokarev

From: Luc Michel <luc.michel@amd.com>

The gem_init_register_masks function was called at init time but it
relies on the num-priority-queues property. Call it at realize time
instead.

Cc: qemu-stable@nongnu.org
Fixes: 4c70e32f05f ("net: cadence_gem: Define access permission for interrupt registers")
Signed-off-by: Luc Michel <luc.michel@amd.com>
Reviewed-by: Francisco Iglesias <francisco.iglesias@amd.com>
Reviewed-by: Sai Pavan Boddu <sai.pavan.boddu@amd.com>
Message-ID: <20250716095432.81923-2-luc.michel@amd.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit 2bfcd27e00a49da2efa5d703121b94cd9cd4948b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index 80fbbacc1e..c36918e504 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -1756,6 +1756,7 @@ static void gem_realize(DeviceState *dev, Error **errp)
         sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq[i]);
     }
 
+    gem_init_register_masks(s);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
     s->nic = qemu_new_nic(&net_gem_info, &s->conf,
@@ -1776,7 +1777,6 @@ static void gem_init(Object *obj)
 
     DB_PRINT("\n");
 
-    gem_init_register_masks(s);
     memory_region_init_io(&s->iomem, OBJECT(s), &gem_ops, s,
                           "enet", sizeof(s->regs));
 
-- 
2.47.2



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

* [Stable-10.0.4 09/59] system/physmem: fix use-after-free with dispatch
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (7 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 08/59] hw/net/cadence_gem: fix register mask initialization Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 10/59] roms/Makefile: fix npcmNxx_bootrom build rules Michael Tokarev
                   ` (49 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Pierrick Bouvier, Richard Henderson, Michael Tokarev,
	Philippe Mathieu-Daudé

From: Pierrick Bouvier <pierrick.bouvier@linaro.org>

A use-after-free bug was reported when booting a Linux kernel during the
pci setup phase. It's quite hard to reproduce (needs smp, and favored by
having several pci devices with BAR and specific Linux config, which
is Debian default one in this case).

After investigation (see the associated bug ticket), it appears that,
under specific conditions, we might access a cached AddressSpaceDispatch
that was reclaimed by RCU thread meanwhile.
In the Linux boot scenario, during the pci phase, memory region are
destroyed/recreated, resulting in exposition of the bug.

The core of the issue is that we cache the dispatch associated to
current cpu in cpu->cpu_ases[asidx].memory_dispatch. It is updated with
tcg_commit, which runs asynchronously on a given cpu.
At some point, we leave the rcu critial section, and the RCU thread
starts reclaiming it, but tcg_commit is not yet invoked, resulting in
the use-after-free.

It's not the first problem around this area, and commit 0d58c660689 [1]
("softmmu: Use async_run_on_cpu in tcg_commit") already tried to
address it. It did a good job, but it seems that we found a specific
situation where it's not enough.

This patch takes a simple approach: remove the cached value creating the
issue, and make sure we always get the current mapping for address
space, using address_space_to_dispatch(cpu->cpu_ases[asidx].as).
It's equivalent to qatomic_rcu_read(&as->current_map)->dispatch;
This is not really costly, we just need two dereferences,
including one atomic (rcu) read, which is negligible considering we are
already on mmu slow path anyway.

Note that tcg_commit is still needed, as it's taking care of flushing
TLB, removing previously mapped entries.

Another solution would be to cache directly values under the dispatch
(dispatch themselves are not ref counted), keep an active reference on
associated memory section, and release it when appropriate (tricky).
Given the time already spent debugging this area now and previously, I
strongly prefer eliminating the root of the issue, instead of adding
more complexity for a hypothetical performance gain. RCU is precisely
used to ensure good performance when reading data, so caching is not as
beneficial as it might seem IMHO.

[1] https://gitlab.com/qemu-project/qemu/-/commit/0d58c660689f6da1e3feff8a997014003d928b3b

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3040
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Tested-by: Michael Tokarev <mjt@tls.msk.ru>
Message-ID: <20250724161142.2803091-1-pierrick.bouvier@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit 2865bf1c5795371ef441e9029bc22566ccff8299)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/system/physmem.c b/system/physmem.c
index 333a5eb94d..32f5895b80 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -164,13 +164,11 @@ static bool ram_is_cpr_compatible(RAMBlock *rb);
  * CPUAddressSpace: all the information a CPU needs about an AddressSpace
  * @cpu: the CPU whose AddressSpace this is
  * @as: the AddressSpace itself
- * @memory_dispatch: its dispatch pointer (cached, RCU protected)
  * @tcg_as_listener: listener for tracking changes to the AddressSpace
  */
 typedef struct CPUAddressSpace {
     CPUState *cpu;
     AddressSpace *as;
-    struct AddressSpaceDispatch *memory_dispatch;
     MemoryListener tcg_as_listener;
 } CPUAddressSpace;
 
@@ -689,7 +687,7 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr orig_addr,
     IOMMUTLBEntry iotlb;
     int iommu_idx;
     hwaddr addr = orig_addr;
-    AddressSpaceDispatch *d = cpu->cpu_ases[asidx].memory_dispatch;
+    AddressSpaceDispatch *d = address_space_to_dispatch(cpu->cpu_ases[asidx].as);
 
     for (;;) {
         section = address_space_translate_internal(d, addr, &addr, plen, false);
@@ -2673,7 +2671,7 @@ MemoryRegionSection *iotlb_to_section(CPUState *cpu,
 {
     int asidx = cpu_asidx_from_attrs(cpu, attrs);
     CPUAddressSpace *cpuas = &cpu->cpu_ases[asidx];
-    AddressSpaceDispatch *d = cpuas->memory_dispatch;
+    AddressSpaceDispatch *d = address_space_to_dispatch(cpuas->as);
     int section_index = index & ~TARGET_PAGE_MASK;
     MemoryRegionSection *ret;
 
@@ -2750,9 +2748,6 @@ static void tcg_log_global_after_sync(MemoryListener *listener)
 
 static void tcg_commit_cpu(CPUState *cpu, run_on_cpu_data data)
 {
-    CPUAddressSpace *cpuas = data.host_ptr;
-
-    cpuas->memory_dispatch = address_space_to_dispatch(cpuas->as);
     tlb_flush(cpu);
 }
 
@@ -2768,11 +2763,7 @@ static void tcg_commit(MemoryListener *listener)
     cpu = cpuas->cpu;
 
     /*
-     * Defer changes to as->memory_dispatch until the cpu is quiescent.
-     * Otherwise we race between (1) other cpu threads and (2) ongoing
-     * i/o for the current cpu thread, with data cached by mmu_lookup().
-     *
-     * In addition, queueing the work function will kick the cpu back to
+     * Queueing the work function will kick the cpu back to
      * the main loop, which will end the RCU critical section and reclaim
      * the memory data structures.
      *
-- 
2.47.2



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

* [Stable-10.0.4 10/59] roms/Makefile: fix npcmNxx_bootrom build rules
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (8 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 09/59] system/physmem: fix use-after-free with dispatch Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 11/59] linux-user/strace.list: add riscv_hwprobe entry Michael Tokarev
                   ` (48 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Michael Tokarev, Philippe Mathieu-Daudé

Since commit 70ce076fa6dff60, the actual rom source dirs
are subdirs of vbootrom/ submodule, not in top-level of it.

Fixes: 70ce076fa6dff60 "roms: Update vbootrom to 1287b6e"
Fixes: 269b7effd90 ("pc-bios: Add NPCM8XX vBootrom")

Cc: qemu-stable@nongnu.org
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250727215511.807880-1-mjt@tls.msk.ru>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit 653a75a9d7f957c4ba9387d1a54bccfdce49cb9c)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/roms/Makefile b/roms/Makefile
index beff58d9d5..6af68a922f 100644
--- a/roms/Makefile
+++ b/roms/Makefile
@@ -193,12 +193,12 @@ qboot:
 	cp qboot/build/bios.bin ../pc-bios/qboot.rom
 
 npcm7xx_bootrom:
-	$(MAKE) -C vbootrom CROSS_COMPILE=$(arm_cross_prefix)
-	cp vbootrom/npcm7xx_bootrom.bin ../pc-bios/npcm7xx_bootrom.bin
+	$(MAKE) -C vbootrom/npcm7xx CROSS_COMPILE=$(arm_cross_prefix)
+	cp vbootrom/npcm7xx/npcm7xx_bootrom.bin ../pc-bios/npcm7xx_bootrom.bin
 
 npcm8xx_bootrom:
-	$(MAKE) -C vbootrom CROSS_COMPILE=$(aarch64_cross_prefix)
-	cp vbootrom/npcm8xx_bootrom.bin ../pc-bios/npcm8xx_bootrom.bin
+	$(MAKE) -C vbootrom/npcm8xx CROSS_COMPILE=$(aarch64_cross_prefix)
+	cp vbootrom/npcm8xx/npcm8xx_bootrom.bin ../pc-bios/npcm8xx_bootrom.bin
 
 hppa-firmware:
 	$(MAKE) -C seabios-hppa parisc
-- 
2.47.2



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

* [Stable-10.0.4 11/59] linux-user/strace.list: add riscv_hwprobe entry
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (9 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 10/59] roms/Makefile: fix npcmNxx_bootrom build rules Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 12/59] target/riscv: do not call GETPC() in check_ret_from_m_mode() Michael Tokarev
                   ` (47 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Daniel Henrique Barboza, Richard Henderson,
	Alistair Francis, Michael Tokarev

From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>

We're missing a strace entry for riscv_hwprobe, and using -strace will
report it as "Unknown syscall 258".

After this patch we'll have:

$ ./build/qemu-riscv64 -strace test_mutex_riscv
110182 riscv_hwprobe(0x7f207efdc700,1,0,0,0,0) = 0
110182 brk(NULL) = 0x0000000000082000
(...)

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250728170633.113384-1-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit e111ffe48b29ca8abd450af9ee5dd71af3f93536)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/linux-user/strace.list b/linux-user/strace.list
index fdf94ef32a..ab818352a9 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1716,3 +1716,6 @@
 { TARGET_NR_clock_gettime64, "clock_gettime64" , NULL, print_clock_gettime64,
                            print_syscall_ret_clock_gettime64 },
 #endif
+#ifdef TARGET_NR_riscv_hwprobe
+{ TARGET_NR_riscv_hwprobe, "riscv_hwprobe" , "%s(%p,%d,%d,%d,%d,%d)", NULL, NULL },
+#endif
-- 
2.47.2



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

* [Stable-10.0.4 12/59] target/riscv: do not call GETPC() in check_ret_from_m_mode()
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (10 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 11/59] linux-user/strace.list: add riscv_hwprobe entry Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 13/59] target/riscv: Fix exception type when VU accesses supervisor CSRs Michael Tokarev
                   ` (46 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Daniel Henrique Barboza, Richard Henderson,
	Nutty Liu, Philippe Mathieu-Daudé, Alistair Francis,
	Michael Tokarev

From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>

GETPC() should always be called from the top level helper, e.g. the
first helper that is called by the translation code. We stopped doing
that in commit 3157a553ec, and then we introduced problems when
unwinding the exceptions being thrown by helper_mret(), as reported by
[1].

Call GETPC() at the top level helper and pass the value along.

[1] https://gitlab.com/qemu-project/qemu/-/issues/3020

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Fixes: 3157a553ec ("target/riscv: Add Smrnmi mnret instruction")
Closes: https://gitlab.com/qemu-project/qemu/-/issues/3020
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Nutty Liu <liujingqi@lanxincomputing.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250714133739.1248296-1-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit 16aa7771afeac422dcf7be2833d5426da6b814fa)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
index 72dc48e58d..6a8c2e1940 100644
--- a/target/riscv/op_helper.c
+++ b/target/riscv/op_helper.c
@@ -353,21 +353,22 @@ target_ulong helper_sret(CPURISCVState *env)
 }
 
 static void check_ret_from_m_mode(CPURISCVState *env, target_ulong retpc,
-                                  target_ulong prev_priv)
+                                  target_ulong prev_priv,
+                                  uintptr_t ra)
 {
     if (!(env->priv >= PRV_M)) {
-        riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
+        riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, ra);
     }
 
     if (!riscv_cpu_allow_16bit_insn(&env_archcpu(env)->cfg,
                                     env->priv_ver,
                                     env->misa_ext) && (retpc & 0x3)) {
-        riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC());
+        riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, ra);
     }
 
     if (riscv_cpu_cfg(env)->pmp &&
         !pmp_get_num_rules(env) && (prev_priv != PRV_M)) {
-        riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC());
+        riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, ra);
     }
 }
 static target_ulong ssdbltrp_mxret(CPURISCVState *env, target_ulong mstatus,
@@ -392,8 +393,9 @@ target_ulong helper_mret(CPURISCVState *env)
     target_ulong retpc = env->mepc;
     uint64_t mstatus = env->mstatus;
     target_ulong prev_priv = get_field(mstatus, MSTATUS_MPP);
+    uintptr_t ra = GETPC();
 
-    check_ret_from_m_mode(env, retpc, prev_priv);
+    check_ret_from_m_mode(env, retpc, prev_priv, ra);
 
     target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV) &&
                              (prev_priv != PRV_M);
@@ -441,8 +443,9 @@ target_ulong helper_mnret(CPURISCVState *env)
     target_ulong retpc = env->mnepc;
     target_ulong prev_priv = get_field(env->mnstatus, MNSTATUS_MNPP);
     target_ulong prev_virt;
+    uintptr_t ra = GETPC();
 
-    check_ret_from_m_mode(env, retpc, prev_priv);
+    check_ret_from_m_mode(env, retpc, prev_priv, ra);
 
     prev_virt = get_field(env->mnstatus, MNSTATUS_MNPV) &&
                 (prev_priv != PRV_M);
-- 
2.47.2



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

* [Stable-10.0.4 13/59] target/riscv: Fix exception type when VU accesses supervisor CSRs
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (11 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 12/59] target/riscv: do not call GETPC() in check_ret_from_m_mode() Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 14/59] target/riscv: Fix pmp range wraparound on zero Michael Tokarev
                   ` (45 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Xu Lu, Anup Patel, Nutty Liu, Alistair Francis,
	Michael Tokarev

From: Xu Lu <luxu.kernel@bytedance.com>

When supervisor CSRs are accessed from VU-mode, a virtual instruction
exception should be raised instead of an illegal instruction.

Fixes: c1fbcecb3a (target/riscv: Fix csr number based privilege checking)
Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
Reviewed-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Nutty Liu <liujingqi@lanxincomputing.com>
Message-ID: <20250708060720.7030-1-luxu.kernel@bytedance.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit 30ef718423e8018723087cd17be0fd9c6dfa2e53)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 7948188356..f1c4c8c1b8 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -5498,7 +5498,7 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
 
     csr_priv = get_field(csrno, 0x300);
     if (!env->debugger && (effective_priv < csr_priv)) {
-        if (csr_priv == (PRV_S + 1) && env->virt_enabled) {
+        if (csr_priv <= (PRV_S + 1) && env->virt_enabled) {
             return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
         }
         return RISCV_EXCP_ILLEGAL_INST;
-- 
2.47.2



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

* [Stable-10.0.4 14/59] target/riscv: Fix pmp range wraparound on zero
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (12 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 13/59] target/riscv: Fix exception type when VU accesses supervisor CSRs Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 15/59] intc/riscv_aplic: Fix target register read when source is inactive Michael Tokarev
                   ` (44 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Vac Chen, Alistair Francis, Michael Tokarev

From: Vac Chen <vacantron@gmail.com>

pmp_is_in_range() prefers to match addresses within the interval
[start, end]. To archieve this, pmpaddrX is decremented during the end
address update.

In TOR mode, a rule is ignored if its start address is greater than or
equal to its end address.

However, if pmpaddrX is set to 0, this decrement operation causes the
calulated end address to wrap around to UINT_MAX. In this scenario, the
address guard for this PMP entry would become ineffective.

This patch addresses the issue by moving the guard check earlier,
preventing the problematic wraparound when pmpaddrX is zero.

Signed-off-by: Vac Chen <vacantron@gmail.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20250706065554.42953-1-vacantron@gmail.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit 77707bfdf871199bbee665e721ced961aaf3a798)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
index c5f6cdaccb..a9e69de917 100644
--- a/target/riscv/pmp.c
+++ b/target/riscv/pmp.c
@@ -206,11 +206,12 @@ void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index)
         break;
 
     case PMP_AMATCH_TOR:
-        sa = prev_addr << 2; /* shift up from [xx:0] to [xx+2:2] */
-        ea = (this_addr << 2) - 1u;
-        if (sa > ea) {
+        if (prev_addr >= this_addr) {
             sa = ea = 0u;
+            break;
         }
+        sa = prev_addr << 2; /* shift up from [xx:0] to [xx+2:2] */
+        ea = (this_addr << 2) - 1u;
         break;
 
     case PMP_AMATCH_NA4:
-- 
2.47.2



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

* [Stable-10.0.4 15/59] intc/riscv_aplic: Fix target register read when source is inactive
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (13 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 14/59] target/riscv: Fix pmp range wraparound on zero Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 16/59] target/riscv: Restrict mideleg/medeleg/medelegh access to S-mode harts Michael Tokarev
                   ` (43 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Yang Jialong, Daniel Henrique Barboza,
	Alistair Francis, Michael Tokarev

From: Yang Jialong <z_bajeer@yeah.net>

The RISC-V Advanced interrupt Architecture:
4.5.16. Interrupt targets:
If interrupt source i is inactive in this domain, register target[i] is
read-only zero.

Signed-off-by: Yang Jialong <z_bajeer@yeah.net>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Message-ID: <20250728055114.252024-1-z_bajeer@yeah.net>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit b6f1244678bebaf7e2c775cfc66d452f95678ebf)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c
index 5964cde7e0..cab8f0cd4d 100644
--- a/hw/intc/riscv_aplic.c
+++ b/hw/intc/riscv_aplic.c
@@ -628,7 +628,7 @@ static void riscv_aplic_request(void *opaque, int irq, int level)
 
 static uint64_t riscv_aplic_read(void *opaque, hwaddr addr, unsigned size)
 {
-    uint32_t irq, word, idc;
+    uint32_t irq, word, idc, sm;
     RISCVAPLICState *aplic = opaque;
 
     /* Reads must be 4 byte words */
@@ -696,6 +696,10 @@ static uint64_t riscv_aplic_read(void *opaque, hwaddr addr, unsigned size)
     } else if ((APLIC_TARGET_BASE <= addr) &&
             (addr < (APLIC_TARGET_BASE + (aplic->num_irqs - 1) * 4))) {
         irq = ((addr - APLIC_TARGET_BASE) >> 2) + 1;
+        sm = aplic->sourcecfg[irq] & APLIC_SOURCECFG_SM_MASK;
+        if (sm == APLIC_SOURCECFG_SM_INACTIVE) {
+            return 0;
+        }
         return aplic->target[irq];
     } else if (!aplic->msimode && (APLIC_IDC_BASE <= addr) &&
             (addr < (APLIC_IDC_BASE + aplic->num_harts * APLIC_IDC_SIZE))) {
-- 
2.47.2



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

* [Stable-10.0.4 16/59] target/riscv: Restrict mideleg/medeleg/medelegh access to S-mode harts
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (14 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 15/59] intc/riscv_aplic: Fix target register read when source is inactive Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 17/59] target/riscv: Restrict midelegh " Michael Tokarev
                   ` (42 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Jay Chang, Frank Chang, Alistair Francis, Nutty Liu,
	Michael Tokarev

From: Jay Chang <jay.chang@sifive.com>

RISC-V Privileged Spec states:
"In harts with S-mode, the medeleg and mideleg registers must exist, and
setting a bit in medeleg or mideleg will delegate the corresponding trap
, when occurring in S-mode or U-mode, to the S-mode trap handler. In
harts without S-mode, the medeleg and mideleg registers should not
exist."

Add smode predicate to ensure these CSRs are only accessible when S-mode
is supported.

Reviewed-by: Frank Chang <frank.chang@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Jay Chang <jay.chang@sifive.com>
Reviewed-by: Nutty Liu<liujingqi@lanxincomputing.com>
Message-ID: <20250701030021.99218-2-jay.chang@sifive.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit e443ba03361b63218e6c3aa4f73d2cb5b9b1d372)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index f1c4c8c1b8..7fe6ac7ea2 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -5783,8 +5783,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
                           NULL,                read_mstatus_i128           },
     [CSR_MISA]        = { "misa",       any,   read_misa,    write_misa,
                           NULL,                read_misa_i128              },
-    [CSR_MIDELEG]     = { "mideleg",    any,   NULL, NULL,   rmw_mideleg   },
-    [CSR_MEDELEG]     = { "medeleg",    any,   read_medeleg, write_medeleg },
+    [CSR_MIDELEG]     = { "mideleg",    smode,   NULL, NULL,   rmw_mideleg   },
+    [CSR_MEDELEG]     = { "medeleg",    smode,   read_medeleg, write_medeleg },
     [CSR_MIE]         = { "mie",        any,   NULL, NULL,   rmw_mie       },
     [CSR_MTVEC]       = { "mtvec",      any,   read_mtvec,   write_mtvec   },
     [CSR_MCOUNTEREN]  = { "mcounteren", umode, read_mcounteren,
@@ -5792,7 +5792,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
 
     [CSR_MSTATUSH]    = { "mstatush",   any32, read_mstatush,
                           write_mstatush                                   },
-    [CSR_MEDELEGH]    = { "medelegh",   any32, read_zero, write_ignore,
+    [CSR_MEDELEGH]    = { "medelegh",   smode32, read_zero, write_ignore,
                           .min_priv_ver = PRIV_VERSION_1_13_0              },
     [CSR_HEDELEGH]    = { "hedelegh",   hmode32, read_hedelegh, write_hedelegh,
                           .min_priv_ver = PRIV_VERSION_1_13_0              },
-- 
2.47.2



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

* [Stable-10.0.4 17/59] target/riscv: Restrict midelegh access to S-mode harts
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (15 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 16/59] target/riscv: Restrict mideleg/medeleg/medelegh access to S-mode harts Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 18/59] target/loongarch: Fix valid virtual address checking Michael Tokarev
                   ` (41 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Jay Chang, Frank Chang, Alistair Francis, Nutty Liu,
	Michael Tokarev

From: Jay Chang <jay.chang@sifive.com>

RISC-V AIA Spec states:
"For a machine-level environment, extension Smaia encompasses all added
CSRs and all modifications to interrupt response behavior that the AIA
specifies for a hart, over all privilege levels. For a supervisor-level
environment, extension Ssaia is essentially the same as Smaia except
excluding the machine-level CSRs and behavior not directly visible to
supervisor level."

Since midelegh is an AIA machine-mode CSR, add Smaia extension check in
aia_smode32 predicate.

Reviewed-by: Frank Chang <frank.chang@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Jay Chang <jay.chang@sifive.com>
Reviewed-by: Nutty Liu<liujingqi@lanxincomputing.com>
Message-ID: <20250701030021.99218-3-jay.chang@sifive.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit 86bc3a0abf10072081cddd8dff25aa72c60e67b8)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 7fe6ac7ea2..66d572af1f 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -372,8 +372,11 @@ static RISCVException aia_smode(CPURISCVState *env, int csrno)
 static RISCVException aia_smode32(CPURISCVState *env, int csrno)
 {
     int ret;
+    int csr_priv = get_field(csrno, 0x300);
 
-    if (!riscv_cpu_cfg(env)->ext_ssaia) {
+    if (csr_priv == PRV_M && !riscv_cpu_cfg(env)->ext_smaia) {
+        return RISCV_EXCP_ILLEGAL_INST;
+    } else if (!riscv_cpu_cfg(env)->ext_ssaia) {
         return RISCV_EXCP_ILLEGAL_INST;
     }
 
@@ -5832,7 +5835,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
     [CSR_MVIP]     = { "mvip",     aia_any, NULL, NULL, rmw_mvip    },
 
     /* Machine-Level High-Half CSRs (AIA) */
-    [CSR_MIDELEGH] = { "midelegh", aia_any32, NULL, NULL, rmw_midelegh },
+    [CSR_MIDELEGH] = { "midelegh", aia_smode32, NULL, NULL, rmw_midelegh },
     [CSR_MIEH]     = { "mieh",     aia_any32, NULL, NULL, rmw_mieh     },
     [CSR_MVIENH]   = { "mvienh",   aia_any32, NULL, NULL, rmw_mvienh   },
     [CSR_MVIPH]    = { "mviph",    aia_any32, NULL, NULL, rmw_mviph    },
-- 
2.47.2



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

* [Stable-10.0.4 18/59] target/loongarch: Fix valid virtual address checking
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (16 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 17/59] target/riscv: Restrict midelegh " Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 19/59] virtio: fix off-by-one and invalid access in virtqueue_ordered_fill Michael Tokarev
                   ` (40 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Bibo Mao, Song Gao, Michael Tokarev

From: Bibo Mao <maobibo@loongson.cn>

On LoongArch64 system, the high 32 bit of 64 bit virtual address should be
0x00000[0-7]yyy or 0xffff8yyy. The bit from 47 to 63 should be all 0 or
all 1.

Function get_physical_address() only checks bit 48 to 63, there will be
problem with the following test case. On physical machine, there is bus
error report and program exits abnormally. However on qemu TCG system
emulation mode, the program runs normally. The virtual address
0xffff000000000000ULL + addr and addr are treated the same on TLB entry
checking. This patch fixes this issue.

void main()
{
        void *addr, *addr1;
        int val;

        addr = malloc(100);
        *(int *)addr = 1;
        addr1 = 0xffff000000000000ULL + addr;
        val = *(int *)addr1;
        printf("val %d \n", val);
}

Cc: qemu-stable@nongnu.org
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Acked-by: Song Gao <gaosong@loongson.cn>
Reviewed-by: Song Gao <gaosong@loongson.cn>
Message-ID: <20250714015446.746163-1-maobibo@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
(cherry picked from commit caab7ac83507e3e9a5fe2f37be5cfa759e766ba2)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/loongarch/cpu_helper.c b/target/loongarch/cpu_helper.c
index 930466ca48..8c332d74a5 100644
--- a/target/loongarch/cpu_helper.c
+++ b/target/loongarch/cpu_helper.c
@@ -299,8 +299,8 @@ int get_physical_address(CPULoongArchState *env, hwaddr *physical,
     }
 
     /* Check valid extension */
-    addr_high = sextract64(address, TARGET_VIRT_ADDR_SPACE_BITS, 16);
-    if (!(addr_high == 0 || addr_high == -1)) {
+    addr_high = (int64_t)address >> (TARGET_VIRT_ADDR_SPACE_BITS - 1);
+    if (!(addr_high == 0 || addr_high == -1ULL)) {
         return TLBRET_BADADDR;
     }
 
-- 
2.47.2



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

* [Stable-10.0.4 19/59] virtio: fix off-by-one and invalid access in virtqueue_ordered_fill
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (17 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 18/59] target/loongarch: Fix valid virtual address checking Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 20/59] vhost: Do not abort on log-start error Michael Tokarev
                   ` (39 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Jonah Palmer, terrynini, Si-Wei Liu, Jason Wang,
	Michael S. Tsirkin, Michael Tokarev

From: Jonah Palmer <jonah.palmer@oracle.com>

Commit b44135daa372 introduced virtqueue_ordered_fill for
VIRTIO_F_IN_ORDER support but had a few issues:

* Conditional while loop used 'steps <= max_steps' but should've been
  'steps < max_steps' since reaching steps == max_steps would indicate
  that we didn't find an element, which is an error. Without this
  change, the code would attempt to read invalid data at an index
  outside of our search range.

* Incremented 'steps' using the next chain's ndescs instead of the
  current one.

This patch corrects the loop bounds and synchronizes 'steps' and index
increments.

We also add a defensive sanity check against malicious or invalid
descriptor counts to avoid a potential infinite loop and DoS.

Fixes: b44135daa372 ("virtio: virtqueue_ordered_fill - VIRTIO_F_IN_ORDER support")
Reported-by: terrynini <terrynini38514@gmail.com>
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
Message-Id: <20250721150208.2409779-1-jonah.palmer@oracle.com>
Reviewed-by: Si-Wei Liu <si-wei.liu@oracle.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit 6fcf5ebafad65adc19a616260ca7dc90005785d1)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index ec54573feb..b756f49867 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -929,18 +929,18 @@ static void virtqueue_packed_fill(VirtQueue *vq, const VirtQueueElement *elem,
 static void virtqueue_ordered_fill(VirtQueue *vq, const VirtQueueElement *elem,
                                    unsigned int len)
 {
-    unsigned int i, steps, max_steps;
+    unsigned int i, steps, max_steps, ndescs;
 
     i = vq->used_idx % vq->vring.num;
     steps = 0;
     /*
-     * We shouldn't need to increase 'i' by more than the distance
-     * between used_idx and last_avail_idx.
+     * We shouldn't need to increase 'i' by more than or equal to
+     * the distance between used_idx and last_avail_idx (max_steps).
      */
     max_steps = (vq->last_avail_idx - vq->used_idx) % vq->vring.num;
 
     /* Search for element in vq->used_elems */
-    while (steps <= max_steps) {
+    while (steps < max_steps) {
         /* Found element, set length and mark as filled */
         if (vq->used_elems[i].index == elem->index) {
             vq->used_elems[i].len = len;
@@ -948,8 +948,18 @@ static void virtqueue_ordered_fill(VirtQueue *vq, const VirtQueueElement *elem,
             break;
         }
 
-        i += vq->used_elems[i].ndescs;
-        steps += vq->used_elems[i].ndescs;
+        ndescs = vq->used_elems[i].ndescs;
+
+        /* Defensive sanity check */
+        if (unlikely(ndescs == 0 || ndescs > vq->vring.num)) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "%s: %s invalid ndescs %u at position %u\n",
+                          __func__, vq->vdev->name, ndescs, i);
+            return;
+        }
+
+        i += ndescs;
+        steps += ndescs;
 
         if (i >= vq->vring.num) {
             i -= vq->vring.num;
-- 
2.47.2



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

* [Stable-10.0.4 20/59] vhost: Do not abort on log-start error
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (18 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 19/59] virtio: fix off-by-one and invalid access in virtqueue_ordered_fill Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 21/59] vhost: Do not abort on log-stop error Michael Tokarev
                   ` (38 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Hanna Czenczek, Tingting Mao, Manos Pitsidianakis,
	Stefano Garzarella, Lei Yang, Michael S. Tsirkin, Michael Tokarev

From: Hanna Czenczek <hreitz@redhat.com>

Commit 3688fec8923 ("memory: Add Error** argument to .log_global_start()
handler") enabled vhost_log_global_start() to return a proper error, but
did not change it to do so; instead, it still aborts the whole process
on error.

This crash can be reproduced by e.g. killing a virtiofsd daemon before
initiating migration.  In such a case, qemu should not crash, but just
make the attempted migration fail.

Buglink: https://issues.redhat.com/browse/RHEL-94534
Reported-by: Tingting Mao <timao@redhat.com>
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Message-Id: <20250724125928.61045-2-hreitz@redhat.com>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Tested-by: Lei Yang <leiyang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit c1997099dc26d95eb9f2249f2894aabf4cf0bf8b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 99d31cc1b4..26e5a67653 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1111,7 +1111,8 @@ static bool vhost_log_global_start(MemoryListener *listener, Error **errp)
 
     r = vhost_migration_log(listener, true);
     if (r < 0) {
-        abort();
+        error_setg_errno(errp, -r, "vhost: Failed to start logging");
+        return false;
     }
     return true;
 }
-- 
2.47.2



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

* [Stable-10.0.4 21/59] vhost: Do not abort on log-stop error
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (19 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 20/59] vhost: Do not abort on log-start error Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 22/59] virtio-net: Fix VLAN filter table reset timing Michael Tokarev
                   ` (37 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Hanna Czenczek, Manos Pitsidianakis,
	Stefano Garzarella, Lei Yang, Michael S. Tsirkin, Michael Tokarev

From: Hanna Czenczek <hreitz@redhat.com>

Failing to stop logging in a vhost device is not exactly fatal.  We can
log such an error, but there is no need to abort the whole qemu process
because of it.

Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Message-Id: <20250724125928.61045-3-hreitz@redhat.com>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Tested-by: Lei Yang <leiyang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit d63c388dadb7717f6391e1bb7f11728c0c1a3e36)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 26e5a67653..e72d991c55 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1123,7 +1123,8 @@ static void vhost_log_global_stop(MemoryListener *listener)
 
     r = vhost_migration_log(listener, false);
     if (r < 0) {
-        abort();
+        /* Not fatal, so report it, but take no further action */
+        warn_report("vhost: Failed to stop logging");
     }
 }
 
-- 
2.47.2



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

* [Stable-10.0.4 22/59] virtio-net: Fix VLAN filter table reset timing
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (20 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 21/59] vhost: Do not abort on log-stop error Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 23/59] pcie_sriov: Fix configuration and state synchronization Michael Tokarev
                   ` (36 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Akihiko Odaki, Konstantin Shkolnyy, Lei Yang,
	Michael S. Tsirkin, Michael Tokarev

From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>

Problem
-------

The expected initial state of the table depends on feature negotiation:

With VIRTIO_NET_F_CTRL_VLAN:
  The table must be empty in accordance with the specification.
Without VIRTIO_NET_F_CTRL_VLAN:
  The table must be filled to permit all VLAN traffic.

Prior to commit 06b636a1e2ad ("virtio-net: do not reset vlan filtering
at set_features"), virtio_net_set_features() always reset the VLAN
table. That commit changed the behavior to skip table reset when
VIRTIO_NET_F_CTRL_VLAN was negotiated, assuming the table would be
properly cleared during device reset and remain stable.

However, this assumption breaks when a driver renegotiates features:
1. Initial negotiation without VIRTIO_NET_F_CTRL_VLAN (table filled)
2. Renegotiation with VIRTIO_NET_F_CTRL_VLAN (table will not be cleared)

The problem was exacerbated by commit 0caed25cd171 ("virtio: Call
set_features during reset"), which triggered virtio_net_set_features()
during device reset, exposing the bug whenever VIRTIO_NET_F_CTRL_VLAN
was negotiated after a device reset.

Solution
--------

Fix the issue by initializing the table when virtio_net_set_features()
is called to change the VIRTIO_NET_F_CTRL_VLAN bit of
vdev->guest_features.

This approach ensures the correct table state regardless of feature
negotiation sequence by performing initialization in
virtio_net_set_features() as QEMU did prior to commit 06b636a1e2ad
("virtio-net: do not reset vlan filtering at set_features").

This change still preserves the goal of the commit, which was to avoid
resetting the table during migration, by checking whether the
VIRTIO_NET_F_CTRL_VLAN bit of vdev->guest_features is being changed;
vdev->guest_features is set before virtio_net_set_features() gets called
during migration.

It also avoids resetting the table when the driver sets a feature
bitmask with no change for the VIRTIO_NET_F_CTRL_VLAN bit, which makes
the operation idempotent and its semantics cleaner.

Additionally, this change ensures the table is initialized after
feature negotiation and before the DRIVER_OK status bit being set for
compatibility with the Linux driver before commit 50c0ada627f5
("virtio-net: fix race between ndo_open() and virtio_device_ready()"),
which did not ensure to set the DRIVER_OK status bit before modifying
the table.

Fixes: 06b636a1e2ad ("virtio-net: do not reset vlan filtering at set_features")
Cc: qemu-stable@nongnu.org
Reported-by: Konstantin Shkolnyy <kshk@linux.ibm.com>
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Tested-by: Konstantin Shkolnyy <kshk@linux.ibm.com>
Tested-by: Lei Yang <leiyang@redhat.com>
Message-Id: <20250727-vlan-v3-1-bbee738619b1@rsg.ci.i.u-tokyo.ac.jp>
Tested-by: Konstantin Shkolnyy <kshk@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit 6071d13c6a37493a6b26e1609b09a98aa058038a)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 5f908e5bca..8a0ea4cff5 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -997,8 +997,9 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
         vhost_net_save_acked_features(nc->peer);
     }
 
-    if (!virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) {
-        memset(n->vlans, 0xff, MAX_VLAN >> 3);
+    if (virtio_has_feature(vdev->guest_features ^ features, VIRTIO_NET_F_CTRL_VLAN)) {
+        bool vlan = virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN);
+        memset(n->vlans, vlan ? 0 : 0xff, MAX_VLAN >> 3);
     }
 
     if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) {
@@ -3896,6 +3897,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
     n->mac_table.macs = g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN);
 
     n->vlans = g_malloc0(MAX_VLAN >> 3);
+    memset(n->vlans, 0xff, MAX_VLAN >> 3);
 
     nc = qemu_get_queue(n->nic);
     nc->rxfilter_notify_enabled = 1;
@@ -3986,7 +3988,6 @@ static void virtio_net_reset(VirtIODevice *vdev)
     memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
     memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac));
     qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
-    memset(n->vlans, 0, MAX_VLAN >> 3);
 
     /* Flush any async TX */
     for (i = 0;  i < n->max_queue_pairs; i++) {
-- 
2.47.2



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

* [Stable-10.0.4 23/59] pcie_sriov: Fix configuration and state synchronization
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (21 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 22/59] virtio-net: Fix VLAN filter table reset timing Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 24/59] intel_iommu: Allow both Status Write and Interrupt Flag in QI wait Michael Tokarev
                   ` (35 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Akihiko Odaki, Corentin BAYET, Michael S. Tsirkin,
	Michael Tokarev

From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>

Fix issues in PCIe SR-IOV configuration register handling that caused
inconsistent internal state due to improper write mask handling and
incorrect migration behavior.

Two main problems were identified:

1. VF Enable bit write mask handling:
   pcie_sriov_config_write() incorrectly assumed that its val parameter
   was already masked, causing it to ignore the actual write mask.
   This led to the VF Enable bit being processed even when masked,
   resulting in incorrect VF registration/unregistration. It is
   identified as CVE-2025-54567.

2. Migration state inconsistency:
   pcie_sriov_pf_post_load() unconditionally called register_vfs()
   regardless of the VF Enable bit state, creating inconsistent
   internal state when VFs should not be enabled. Additionally,
   it failed to properly update the NumVFs write mask based on
   the current configuration. It is identified as CVE-2025-54566.

Root cause analysis revealed that both functions relied on incorrect
special-case assumptions instead of properly reading and consuming
the actual configuration values. This change introduces a unified
consume_config() function that reads actual configuration values and
synchronize the internal state without special-case assumptions.

The solution only adds register read overhead in non-hot-path code
while ensuring correct SR-IOV state management across configuration
writes and migration scenarios.

Fixes: 5e7dd17e4348 ("pcie_sriov: Remove num_vfs from PCIESriovPF")
Fixes: f9efcd47110d ("pcie_sriov: Register VFs after migration")
Fixes: CVE-2025-54566
Fixes: CVE-2025-54567
Cc: qemu-stable@nongnu.org
Reported-by: Corentin BAYET <corentin.bayet@reversetactics.com>
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Message-Id: <20250727-wmask-v2-1-394910b1c0b6@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit cad9aa6fbdccd95e56e10cfa57c354a20a333717)
(Mjt: context fix)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c
index 1eb4358256..dd4fbaea46 100644
--- a/hw/pci/pcie_sriov.c
+++ b/hw/pci/pcie_sriov.c
@@ -211,6 +211,27 @@ static void unregister_vfs(PCIDevice *dev)
     pci_set_word(dev->wmask + dev->exp.sriov_cap + PCI_SRIOV_NUM_VF, 0xffff);
 }
 
+static void consume_config(PCIDevice *dev)
+{
+    uint8_t *cfg = dev->config + dev->exp.sriov_cap;
+
+    if (pci_get_word(cfg + PCI_SRIOV_CTRL) & PCI_SRIOV_CTRL_VFE) {
+        register_vfs(dev);
+    } else {
+        uint8_t *wmask = dev->wmask + dev->exp.sriov_cap;
+        uint16_t num_vfs = pci_get_word(cfg + PCI_SRIOV_NUM_VF);
+        uint16_t wmask_val = PCI_SRIOV_CTRL_MSE | PCI_SRIOV_CTRL_ARI;
+
+        unregister_vfs(dev);
+
+        if (num_vfs <= pci_get_word(cfg + PCI_SRIOV_TOTAL_VF)) {
+            wmask_val |= PCI_SRIOV_CTRL_VFE;
+        }
+
+        pci_set_word(wmask + PCI_SRIOV_CTRL, wmask_val);
+    }
+}
+
 void pcie_sriov_config_write(PCIDevice *dev, uint32_t address,
                              uint32_t val, int len)
 {
@@ -228,30 +249,13 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t address,
     trace_sriov_config_write(dev->name, PCI_SLOT(dev->devfn),
                              PCI_FUNC(dev->devfn), off, val, len);
 
-    if (range_covers_byte(off, len, PCI_SRIOV_CTRL)) {
-        if (val & PCI_SRIOV_CTRL_VFE) {
-            register_vfs(dev);
-        } else {
-            unregister_vfs(dev);
-        }
-    } else if (range_covers_byte(off, len, PCI_SRIOV_NUM_VF)) {
-        uint8_t *cfg = dev->config + sriov_cap;
-        uint8_t *wmask = dev->wmask + sriov_cap;
-        uint16_t num_vfs = pci_get_word(cfg + PCI_SRIOV_NUM_VF);
-        uint16_t wmask_val = PCI_SRIOV_CTRL_MSE | PCI_SRIOV_CTRL_ARI;
-
-        if (num_vfs <= pci_get_word(cfg + PCI_SRIOV_TOTAL_VF)) {
-            wmask_val |= PCI_SRIOV_CTRL_VFE;
-        }
-
-        pci_set_word(wmask + PCI_SRIOV_CTRL, wmask_val);
-    }
+    consume_config(dev);
 }
 
 void pcie_sriov_pf_post_load(PCIDevice *dev)
 {
     if (dev->exp.sriov_cap) {
-        register_vfs(dev);
+        consume_config(dev);
     }
 }
 
-- 
2.47.2



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

* [Stable-10.0.4 24/59] intel_iommu: Allow both Status Write and Interrupt Flag in QI wait
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (22 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 23/59] pcie_sriov: Fix configuration and state synchronization Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 25/59] hw/i386/amd_iommu: Move IOAPIC memory region initialization to the end Michael Tokarev
                   ` (34 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, David Woodhouse, Michael S. Tsirkin, Michael Tokarev

From: David Woodhouse <dwmw@amazon.co.uk>

FreeBSD does both, and this appears to be perfectly valid. The VT-d
spec even talks about the ordering (the status write should be done
first, unsurprisingly).

We certainly shouldn't assert() and abort QEMU if the guest asks for
both.

Fixes: ed7b8fbcfb88 ("intel-iommu: add supports for queued invalidation interface")
Closes: https://gitlab.com/qemu-project/qemu/-/issues/3028
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Message-Id: <0122cbabc0adcc3cf878f5fd7834d8f258c7a2f2.camel@infradead.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit e8145dcd311b58921f3a45121792cbfab38fd2f6)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index dffd7ee885..a117a0b6b1 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2830,6 +2830,7 @@ static bool vtd_process_wait_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc)
 {
     uint64_t mask[4] = {VTD_INV_DESC_WAIT_RSVD_LO, VTD_INV_DESC_WAIT_RSVD_HI,
                         VTD_INV_DESC_ALL_ONE, VTD_INV_DESC_ALL_ONE};
+    bool ret = true;
 
     if (!vtd_inv_desc_reserved_check(s, inv_desc, mask, false,
                                      __func__, "wait")) {
@@ -2841,8 +2842,6 @@ static bool vtd_process_wait_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc)
         uint32_t status_data = (uint32_t)(inv_desc->lo >>
                                VTD_INV_DESC_WAIT_DATA_SHIFT);
 
-        assert(!(inv_desc->lo & VTD_INV_DESC_WAIT_IF));
-
         /* FIXME: need to be masked with HAW? */
         dma_addr_t status_addr = inv_desc->hi;
         trace_vtd_inv_desc_wait_sw(status_addr, status_data);
@@ -2851,18 +2850,22 @@ static bool vtd_process_wait_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc)
                              &status_data, sizeof(status_data),
                              MEMTXATTRS_UNSPECIFIED)) {
             trace_vtd_inv_desc_wait_write_fail(inv_desc->hi, inv_desc->lo);
-            return false;
+            ret = false;
         }
-    } else if (inv_desc->lo & VTD_INV_DESC_WAIT_IF) {
+    }
+
+    if (inv_desc->lo & VTD_INV_DESC_WAIT_IF) {
         /* Interrupt flag */
         vtd_generate_completion_event(s);
-    } else {
+    }
+
+    if (!(inv_desc->lo & (VTD_INV_DESC_WAIT_IF | VTD_INV_DESC_WAIT_SW))) {
         error_report_once("%s: invalid wait desc: hi=%"PRIx64", lo=%"PRIx64
                           " (unknown type)", __func__, inv_desc->hi,
                           inv_desc->lo);
         return false;
     }
-    return true;
+    return ret;
 }
 
 static bool vtd_process_context_cache_desc(IntelIOMMUState *s,
-- 
2.47.2



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

* [Stable-10.0.4 25/59] hw/i386/amd_iommu: Move IOAPIC memory region initialization to the end
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (23 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 24/59] intel_iommu: Allow both Status Write and Interrupt Flag in QI wait Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 26/59] hw/intc/arm_gicv3_kvm: Write all 1's to clear enable/active Michael Tokarev
                   ` (33 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Sairaj Kodilkar, Vasant Hegde, Michael S. Tsirkin,
	Michael Tokarev

From: Sairaj Kodilkar <sarunkod@amd.com>

Setting up IOAPIC memory region requires mr_sys and mr_ir. Currently
these two memory regions are setup after the initializing the IOAPIC
memory region, which cause `amdvi_host_dma_iommu()` to use unitialized
mr_sys and mr_ir.

Move the IOAPIC memory region initialization to the end in order to use
the mr_sys and mr_ir regions after they are fully initialized.

Fixes: 577c470f4326 ("x86_iommu/amd: Prepare for interrupt remap support")
Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Message-Id: <20250801060507.3382-4-sarunkod@amd.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit a7842d94067cddc80b47ac42fb6e49e2fc02a3c5)
(Mjt: context fix due to missing v10.0.0-833-gf864a3235ea1
 "hw/i386/amd_iommu: Isolate AMDVI-PCI from amd-iommu device
 to allow full control over the PCI device creation")
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index f773653487..37447dca25 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -1620,9 +1620,6 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    /* Pseudo address space under root PCI bus. */
-    x86ms->ioapic_as = amdvi_host_dma_iommu(bus, s, AMDVI_IOAPIC_SB_DEVID);
-
     /* set up MMIO */
     memory_region_init_io(&s->mr_mmio, OBJECT(s), &mmio_mem_ops, s,
                           "amdvi-mmio", AMDVI_MMIO_SIZE);
@@ -1645,6 +1642,9 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp)
     memory_region_add_subregion_overlap(&s->mr_sys, AMDVI_INT_ADDR_FIRST,
                                         &s->mr_ir, 1);
 
+    /* Pseudo address space under root PCI bus. */
+    x86ms->ioapic_as = amdvi_host_dma_iommu(bus, s, AMDVI_IOAPIC_SB_DEVID);
+
     if (kvm_enabled() && x86ms->apic_id_limit > 255 && !s->xtsup) {
         error_report("AMD IOMMU with x2APIC configuration requires xtsup=on");
         exit(EXIT_FAILURE);
-- 
2.47.2



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

* [Stable-10.0.4 26/59] hw/intc/arm_gicv3_kvm: Write all 1's to clear enable/active
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (24 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 25/59] hw/i386/amd_iommu: Move IOAPIC memory region initialization to the end Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 27/59] target/arm: Fix big-endian handling of NEON gdb remote debugging Michael Tokarev
                   ` (32 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Zenghui Yu, Peter Maydell, Michael Tokarev

From: Zenghui Yu <zenghui.yu@linux.dev>

KVM's userspace access interface to the GICD enable and active bits
is via set/clear register pairs which implement the hardware's "write
1s to the clear register to clear the 0 bits, and write 1s to the set
register to set the 1 bits" semantics.  We didn't get this right,
because we were writing 0 to the clear register.

Writing 0 to GICD_IC{ENABLE,ACTIVE}R architecturally has no effect on
interrupt status (all writes are simply ignored by KVM) and doesn't
comply with the intention of "first write to the clear-reg to clear
all bits".

Write all 1's to actually clear the enable/active status.

This didn't have any adverse effects on migration because there
we start with a clean VM state; it would be guest-visible when
doing a system reset, but since Linux always cleans up the
register state of the GIC during bootup before it enables it
most users won't have run into a problem here.

Cc: qemu-stable@nongnu.org
Fixes: 367b9f527bec ("hw/intc/arm_gicv3_kvm: Implement get/put functions")
Signed-off-by: Zenghui Yu <zenghui.yu@linux.dev>
Message-id: 20250729161650.43758-3-zenghui.yu@linux.dev
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
(cherry picked from commit b10bd4bd17ac8628ede8735a08ad82dc3b721c64)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c
index 8e17cab2a0..d6e23426c0 100644
--- a/hw/intc/arm_gicv3_kvm.c
+++ b/hw/intc/arm_gicv3_kvm.c
@@ -294,7 +294,7 @@ static void kvm_dist_putbmp(GICv3State *s, uint32_t offset,
          * the 1 bits.
          */
         if (clroffset != 0) {
-            reg = 0;
+            reg = ~0;
             kvm_gicd_access(s, clroffset, &reg, true);
             clroffset += 4;
         }
-- 
2.47.2



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

* [Stable-10.0.4 27/59] target/arm: Fix big-endian handling of NEON gdb remote debugging
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (25 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 26/59] hw/intc/arm_gicv3_kvm: Write all 1's to clear enable/active Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 28/59] target/arm: Fix handling of setting SVE registers from gdb Michael Tokarev
                   ` (31 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Vacha Bhavsar, Peter Maydell, Michael Tokarev

From: Vacha Bhavsar <vacha.bhavsar@oss.qualcomm.com>

In the code for allowing the gdbstub to set the value of an AArch64
FP/SIMD register, we weren't accounting for target_big_endian()
being true. This meant that for aarch64_be-linux-user we would
set the two halves of the FP register the wrong way around.
The much more common case of a little-endian guest is not affected;
nor are big-endian hosts.

Correct the handling of this case.

Cc: qemu-stable@nongnu.org
Signed-off-by: Vacha Bhavsar <vacha.bhavsar@oss.qualcomm.com>
Message-id: 20250722173736.2332529-2-vacha.bhavsar@oss.qualcomm.com
[PMM: added comment, expanded commit message, fixed missing space]
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
(cherry picked from commit 35cca0f95ff5345f54c11d116efc8940a0dab8aa)
(Mjt: s/target_big_endian/target_words_bigendian/ due to missing
 v10.0.0-277-gb939b8e42a "exec: Rename target_words_bigendian() -> target_big_endian()")
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c
index 1a4dbec567..d4d808a49b 100644
--- a/target/arm/gdbstub64.c
+++ b/target/arm/gdbstub64.c
@@ -111,8 +111,22 @@ int aarch64_gdb_set_fpu_reg(CPUState *cs, uint8_t *buf, int reg)
         /* 128 bit FP register */
         {
             uint64_t *q = aa64_vfp_qreg(env, reg);
-            q[0] = ldq_le_p(buf);
-            q[1] = ldq_le_p(buf + 8);
+
+            /*
+             * On the wire these are target-endian 128 bit values.
+             * In the CPU state these are host-order uint64_t values
+             * with the least-significant one first. This means they're
+             * the other way around for target_words_bigendian() (which is
+             * only true for us for aarch64_be-linux-user).
+             */
+            if (target_words_bigendian()) {
+                q[1] = ldq_p(buf);
+                q[0] = ldq_p(buf + 8);
+            } else{
+                q[0] = ldq_p(buf);
+                q[1] = ldq_p(buf + 8);
+            }
+
             return 16;
         }
     case 32:
-- 
2.47.2



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

* [Stable-10.0.4 28/59] target/arm: Fix handling of setting SVE registers from gdb
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (26 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 27/59] target/arm: Fix big-endian handling of NEON gdb remote debugging Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 29/59] hw/ssi/aspeed_smc: Fix incorrect FMC_WDT2 register read on AST1030 Michael Tokarev
                   ` (30 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Vacha Bhavsar, Peter Maydell, Michael Tokarev

From: Vacha Bhavsar <vacha.bhavsar@oss.qualcomm.com>

The code to handle setting SVE registers via the gdbstub is broken:
 * it sets each pair of elements in the zregs[].d[] array in the
   wrong order for the most common (little endian) case: the least
   significant 64-bit value comes first
 * it makes no attempt to handle target_endian()
 * it does a simple copy out of the (target endian) gdbstub buffer
   into the (host endan) zregs data structure, which is wrong on
   big endian hosts

Fix all these problems:
 * use ldq_p() to read from the gdbstub buffer
 * check target_big_endian() to see if we need to handle the
   128-bit values the opposite way around

Cc: qemu-stable@nongnu.org
Signed-off-by: Vacha Bhavsar <vacha.bhavsar@oss.qualcomm.com>
Message-id: 20250722173736.2332529-3-vacha.bhavsar@oss.qualcomm.com
[PMM: adjusted commit message, fixed spacing]
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
(cherry picked from commit 97b3d732afec9b165c33697452e31267a845338f)
(Mjt: s/target_big_endian/target_words_bigendian/ due to missing
 v10.0.0-277-gb939b8e42a "exec: Rename target_words_bigendian() -> target_big_endian()")
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c
index d4d808a49b..b9b2b14c93 100644
--- a/target/arm/gdbstub64.c
+++ b/target/arm/gdbstub64.c
@@ -202,10 +202,17 @@ int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)
     case 0 ... 31:
     {
         int vq, len = 0;
-        uint64_t *p = (uint64_t *) buf;
         for (vq = 0; vq < cpu->sve_max_vq; vq++) {
-            env->vfp.zregs[reg].d[vq * 2 + 1] = *p++;
-            env->vfp.zregs[reg].d[vq * 2] = *p++;
+            if (target_words_bigendian()) {
+                env->vfp.zregs[reg].d[vq * 2 + 1] = ldq_p(buf);
+                buf += 8;
+                env->vfp.zregs[reg].d[vq * 2] = ldq_p(buf);
+            } else{
+                env->vfp.zregs[reg].d[vq * 2] = ldq_p(buf);
+                buf += 8;
+                env->vfp.zregs[reg].d[vq * 2 + 1] = ldq_p(buf);
+            }
+            buf += 8;
             len += 16;
         }
         return len;
@@ -220,9 +227,9 @@ int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)
     {
         int preg = reg - 34;
         int vq, len = 0;
-        uint64_t *p = (uint64_t *) buf;
         for (vq = 0; vq < cpu->sve_max_vq; vq = vq + 4) {
-            env->vfp.pregs[preg].p[vq / 4] = *p++;
+            env->vfp.pregs[preg].p[vq / 4] = ldq_p(buf);
+            buf += 8;
             len += 8;
         }
         return len;
-- 
2.47.2



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

* [Stable-10.0.4 29/59] hw/ssi/aspeed_smc: Fix incorrect FMC_WDT2 register read on AST1030
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (27 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 28/59] target/arm: Fix handling of setting SVE registers from gdb Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 30/59] target/arm: add support for 64-bit PMCCNTR in AArch32 mode Michael Tokarev
                   ` (29 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Jamin Lin, Cédric Le Goater, Michael Tokarev

From: Jamin Lin <jamin_lin@aspeedtech.com>

On AST1030, reading the FMC_WDT2 register always returns 0xFFFFFFFF.
This issue is due to the aspeed_smc_read function, which checks for the
ASPEED_SMC_FEATURE_WDT_CONTROL feature. Since AST1030 was missing this
feature flag, the read operation fails and returns -1.

To resolve this, add the WDT_CONTROL feature to AST1030's feature set
so that FMC_WDT2 can be correctly accessed by firmware.

Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Fixes: 2850df6a81bcdc2e063dfdd56751ee2d11c58030 ("aspeed/smc: Add AST1030 support ")
Link: https://lore.kernel.org/qemu-devel/20250804014633.512737-1-jamin_lin@aspeedtech.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit 13ed972b4ce57198914a37217251d30fbec20e41)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
index faef1a8e5b..b4a17a52a3 100644
--- a/hw/ssi/aspeed_smc.c
+++ b/hw/ssi/aspeed_smc.c
@@ -1857,7 +1857,8 @@ static void aspeed_1030_fmc_class_init(ObjectClass *klass, void *data)
     asc->resets            = aspeed_1030_fmc_resets;
     asc->flash_window_base = 0x80000000;
     asc->flash_window_size = 0x10000000;
-    asc->features          = ASPEED_SMC_FEATURE_DMA;
+    asc->features          = ASPEED_SMC_FEATURE_DMA |
+                             ASPEED_SMC_FEATURE_WDT_CONTROL;
     asc->dma_flash_mask    = 0x0FFFFFFC;
     asc->dma_dram_mask     = 0x000BFFFC;
     asc->dma_start_length  = 1;
-- 
2.47.2



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

* [Stable-10.0.4 30/59] target/arm: add support for 64-bit PMCCNTR in AArch32 mode
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (28 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 29/59] hw/ssi/aspeed_smc: Fix incorrect FMC_WDT2 register read on AST1030 Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 31/59] scripts/make-release: Go back to cloning all the EDK2 submodules Michael Tokarev
                   ` (28 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Alex Richardson, Peter Maydell, Michael Tokarev

From: Alex Richardson <alexrichardson@google.com>

In the PMUv3, a new AArch32 64-bit (MCRR/MRRC) accessor for the
PMCCNTR was added. In QEMU we forgot to implement this, so only
provide the 32-bit accessor. Since we have a 64-bit PMCCNTR
sysreg for AArch64, adding the 64-bit AArch32 version is easy.

We add the PMCCNTR to the v8_cp_reginfo because PMUv3 was added
in the ARMv8 architecture. This is consistent with how we
handle the existing PMCCNTR support, where we always implement
it for all v7 CPUs. This is arguably something we should
clean up so it is gated on ARM_FEATURE_PMU and/or an ID
register check for the relevant PMU version, but we should
do that as its own tidyup rather than being inconsistent between
this PMCCNTR accessor and the others.

Since the register name is the same as the 32-bit PMCCNTR, we set
ARM_CP_NO_GDB on the 32-bit one to avoid generating an invalid GDB XML.

See https://developer.arm.com/documentation/ddi0601/2024-06/AArch32-Registers/PMCCNTR--Performance-Monitors-Cycle-Count-Register?lang=en

Note for potential backporting:
 * this code in cpregs-pmu.c will be in helper.c on stable
   branches that don't have commit ae2086426d37

Cc: qemu-stable@nongnu.org
Signed-off-by: Alex Richardson <alexrichardson@google.com>
Message-id: 20250725170136.145116-1-alexrichardson@google.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
(cherry picked from commit cd9f752fee75238f842a91be1146c988bd16a010)
(Mjt: moved code to target/arm/helper.c and modified it for 10.0)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/arm/helper.c b/target/arm/helper.c
index bb445e30cd..4f89eaa2c2 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -1946,11 +1946,6 @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
       .fgt = FGT_PMSELR_EL0,
       .fieldoffset = offsetof(CPUARMState, cp15.c9_pmselr),
       .writefn = pmselr_write, .raw_writefn = raw_write, },
-    { .name = "PMCCNTR", .cp = 15, .crn = 9, .crm = 13, .opc1 = 0, .opc2 = 0,
-      .access = PL0_RW, .resetvalue = 0, .type = ARM_CP_ALIAS | ARM_CP_IO,
-      .fgt = FGT_PMCCNTR_EL0,
-      .readfn = pmccntr_read, .writefn = pmccntr_write32,
-      .accessfn = pmreg_access_ccntr },
     { .name = "PMCCNTR_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 13, .opc2 = 0,
       .access = PL0_RW, .accessfn = pmreg_access_ccntr,
@@ -6849,9 +6844,26 @@ static void define_pmu_regs(ARMCPU *cpu)
         .readfn = pmcr_read, .raw_readfn = raw_read,
         .writefn = pmcr_write, .raw_writefn = raw_write,
     };
+    /*
+     * 32-bit AArch32 PMCCNTR. We don't expose this to GDB if the
+     * new-in-v8 PMUv3 64-bit AArch32 PMCCNTR register is implemented
+     * (as that will provide the GDB user's view of "PMCCNTR").
+     */
+    ARMCPRegInfo pmccntr = {
+        .name = "PMCCNTR",
+        .cp = 15, .crn = 9, .crm = 13, .opc1 = 0, .opc2 = 0,
+        .access = PL0_RW, .accessfn = pmreg_access_ccntr,
+        .resetvalue = 0, .type = ARM_CP_ALIAS | ARM_CP_IO,
+        .fgt = FGT_PMCCNTR_EL0,
+        .readfn = pmccntr_read, .writefn = pmccntr_write32,
+    };
+    if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {
+        pmccntr.type |= ARM_CP_NO_GDB;
+    }
 
     define_one_arm_cp_reg(cpu, &pmcr);
     define_one_arm_cp_reg(cpu, &pmcr64);
+    define_one_arm_cp_reg(cpu, &pmccntr);
     for (i = 0; i < pmcrn; i++) {
         char *pmevcntr_name = g_strdup_printf("PMEVCNTR%d", i);
         char *pmevcntr_el0_name = g_strdup_printf("PMEVCNTR%d_EL0", i);
@@ -8162,6 +8174,13 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST,
               .fgt = FGT_PMCEIDN_EL0,
               .resetvalue = cpu->pmceid1 },
+            /* AArch32 64-bit PMCCNTR view: added in PMUv3 with Armv8 */
+            { .name = "PMCCNTR", .state = ARM_CP_STATE_AA32,
+              .cp = 15, .crm = 9, .opc1 = 0,
+              .access = PL0_RW, .accessfn = pmreg_access_ccntr, .resetvalue = 0,
+              .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_64BIT,
+              .fgt = FGT_PMCCNTR_EL0, .readfn = pmccntr_read,
+              .writefn = pmccntr_write,  },
         };
 #ifdef CONFIG_USER_ONLY
         static const ARMCPRegUserSpaceInfo v8_user_idregs[] = {
-- 
2.47.2



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

* [Stable-10.0.4 31/59] scripts/make-release: Go back to cloning all the EDK2 submodules
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (29 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 30/59] target/arm: add support for 64-bit PMCCNTR in AArch32 mode Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 32/59] qga: correctly write to /sys/power/state on linux Michael Tokarev
                   ` (27 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Peter Maydell, Michael Tokarev, Alex Bennée

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

In commit bd0da3a3d4f we changed make-release so that instead of
cloning every git submodule of EDK2 we only cloned a fixed list.
The original motivation for this was that one of the submodules:
 * was from a non-github repo
 * that repo had a "SSL certificate expired" failure
 * wasn't actually needed for the set of EDK2 binaries we build
and at the time we were trying to build the EDK2 binaries in one of
our CI jobs.

Unfortunately this change meant that we were exposed to bugs where
EDK2 adds a new submodule and the sources we ship in the release
tarball won't build any more.  In particular, in EDK2 commit
c6bb7d54beb05 the MipiSysTLib submodule was added, causing failure of
the ROM build in our tarball starting from QEMU release 8.2.0:

/tmp/qemu-10.0.0/roms/edk2/MdePkg/MdePkg.dec(32): error 000E: File/directory not found in workspace
        Library/MipiSysTLib/mipisyst/library/include is not found in packages path:
        /tmp/qemu-10.0.0/roms/.
        /tmp/qemu-10.0.0/roms/edk2

(Building from a QEMU git checkout works fine.)

In the intervening time EDK2 moved the submodule that had a problem
to be one they mirrored themselves (and at time of writing all their
submodules are hosted on github), and we stopped trying to build
EDK2 binaries in our own CI jobs with commit 690ceb71936f9037f6.

Go back to cloning every EDK2 submodule, so we don't have an
untested explicit list of submodules which will break without
our noticing it.

This increases the size of the QEMU tarball .tar.xz file from
133M to 139M in my testing.

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3041
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Message-ID: <20250721153341.2910800-1-peter.maydell@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
(cherry picked from commit 0311a6edb9db34a41a2662d94c37e1fbaabf6ecf)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/scripts/make-release b/scripts/make-release
index 8c3594a1a4..7e37ffad42 100755
--- a/scripts/make-release
+++ b/scripts/make-release
@@ -61,17 +61,15 @@ meson subprojects download $SUBPROJECTS
 (cd roms/skiboot && ./make_version.sh > .version)
 # Fetch edk2 submodule's submodules, since it won't have access to them via
 # the tarball later.
-#
-# A more uniform way to handle this sort of situation would be nice, but we
-# don't necessarily have much control over how a submodule handles its
-# submodule dependencies, so we continue to handle these on a case-by-case
-# basis for now.
-(cd roms/edk2 && \
-    git submodule update --init --depth 1 -- \
-        ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3 \
-        BaseTools/Source/C/BrotliCompress/brotli \
-        CryptoPkg/Library/OpensslLib/openssl \
-        MdeModulePkg/Library/BrotliCustomDecompressLib/brotli)
+
+# As recommended by the EDK2 readme, we don't use --recursive here.
+# EDK2 won't use any code or feature from a submodule of a submodule,
+# so we don't need to add them to the tarball.
+# Although we don't necessarily need all of the submodules that EDK2
+# has, we clone them all, to avoid running into problems where EDK2
+# adds a new submodule or changes its use of an existing one and
+# the sources we ship in the tarball then fail to build.
+(cd roms/edk2 && git submodule update --init --depth 1)
 popd
 
 exclude=(--exclude=.git)
-- 
2.47.2



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

* [Stable-10.0.4 32/59] qga: correctly write to /sys/power/state on linux
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (30 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 31/59] scripts/make-release: Go back to cloning all the EDK2 submodules Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 33/59] Revert "i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16]" Michael Tokarev
                   ` (26 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Michael Tokarev, Stefan Hajnoczi

Commit v9.0.0-343-g2048129625 introduced usage of
g_file_set_contents() function to write to /sys/power/state.
This function uses G_FILE_SET_CONTENTS_CONSISTENT flag to
g_file_set_contents_full(), which is implemented by creating
a temp file in the same directory and renaming it to the final
destination.  Which is not how sysfs works.

Here, there's not a big deal to do open/write/close - it becomes
almost the same as using g_file_set_contents[_full]().  But it
does not have surprises like this.

Also, since this is linux code, it should be ok to use %m in
the error reporting function.

Fixes: 2048129625 "qga/commands-posix: don't do fork()/exec() when suspending via sysfs"
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3057
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-ID: <20250801115316.6845-1-mjt@tls.msk.ru>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit b217d987a3c5c6e2473956723b396bc1ff0f5b2b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/qga/commands-linux.c b/qga/commands-linux.c
index 9e8a934b9a..9dc0c82503 100644
--- a/qga/commands-linux.c
+++ b/qga/commands-linux.c
@@ -1400,20 +1400,22 @@ static bool linux_sys_state_supports_mode(SuspendMode mode, Error **errp)
 
 static void linux_sys_state_suspend(SuspendMode mode, Error **errp)
 {
-    g_autoptr(GError) local_gerr = NULL;
     const char *sysfile_strs[3] = {"disk", "mem", NULL};
     const char *sysfile_str = sysfile_strs[mode];
+    int fd;
 
     if (!sysfile_str) {
         error_setg(errp, "unknown guest suspend mode");
         return;
     }
 
-    if (!g_file_set_contents(LINUX_SYS_STATE_FILE, sysfile_str,
-                             -1, &local_gerr)) {
-        error_setg(errp, "suspend: cannot write to '%s': %s",
-                   LINUX_SYS_STATE_FILE, local_gerr->message);
-        return;
+    fd = open(LINUX_SYS_STATE_FILE, O_WRONLY);
+    if (fd < 0 || write(fd, sysfile_str, strlen(sysfile_str)) < 0) {
+        error_setg(errp, "suspend: cannot write to '%s': %m",
+                   LINUX_SYS_STATE_FILE);
+    }
+    if (fd >= 0) {
+        close(fd);
     }
 }
 
-- 
2.47.2



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

* [Stable-10.0.4 33/59] Revert "i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16]"
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (31 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 32/59] qga: correctly write to /sys/power/state on linux Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 34/59] i386/cpu: Move adjustment of CPUID_EXT_PDCM before feature_dependencies[] check Michael Tokarev
                   ` (25 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Michael Tokarev

This reverts commit d0975531586742ec2eff8796b7ba93bc4858e63d,
which is a modified commit a62fef58299562aae6667b8d8552247423e886b3
from the master branch.

Since more changes from the master branch are needed in the areas
which are being touched by this one, and this change has been
modified to apply without the previous commit(s), let's revert it
for now, apply previous patches, and re-apply it without modifications
on top.

Additionally, when I cherry-picked a62fef58299562aa, it somehow lost
its original authorship (Qian Wen).  So this revert fixes both issues.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index b768d8ea33..46619288ed 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6835,8 +6835,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         }
         *edx = env->features[FEAT_1_EDX];
         if (threads_per_pkg > 1) {
-            /* Fixup overflow: max value for bits 23-16 is 255. */
-            *ebx |= MIN(threads_per_pkg, 255) << 16;
+            *ebx |= threads_per_pkg << 16;
         }
         if (!cpu->enable_pmu) {
             *ecx &= ~CPUID_EXT_PDCM;
-- 
2.47.2



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

* [Stable-10.0.4 34/59] i386/cpu: Move adjustment of CPUID_EXT_PDCM before feature_dependencies[] check
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (32 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 33/59] Revert "i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16]" Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 35/59] i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16] Michael Tokarev
                   ` (24 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Xiaoyao Li, Zhao Liu, Paolo Bonzini, Michael Tokarev

From: Xiaoyao Li <xiaoyao.li@intel.com>

There is one entry relates to CPUID_EXT_PDCM in feature_dependencies[].
So it needs to get correct value of CPUID_EXT_PDCM before using
feature_dependencies[] to apply dependencies.

Besides, it also ensures CPUID_EXT_PDCM value is tracked in
env->features[FEAT_1_ECX].

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20250304052450.465445-2-xiaoyao.li@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit e68ec2980901c8e7f948f3305770962806c53f0b)
(Mjt: this simple cleanup is not strictly necessary for 10.0,
 but pick it up so subsequent changes in this area applies cleanly)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 46619288ed..d3e3ca13ca 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6837,9 +6837,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         if (threads_per_pkg > 1) {
             *ebx |= threads_per_pkg << 16;
         }
-        if (!cpu->enable_pmu) {
-            *ecx &= ~CPUID_EXT_PDCM;
-        }
         break;
     case 2:
         /* cache info: needed for Pentium Pro compatibility */
@@ -7829,6 +7826,10 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         }
     }
 
+    if (!cpu->enable_pmu) {
+        env->features[FEAT_1_ECX] &= ~CPUID_EXT_PDCM;
+    }
+
     for (i = 0; i < ARRAY_SIZE(feature_dependencies); i++) {
         FeatureDep *d = &feature_dependencies[i];
         if (!(env->features[d->from.index] & d->from.mask)) {
-- 
2.47.2



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

* [Stable-10.0.4 35/59] i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16]
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (33 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 34/59] i386/cpu: Move adjustment of CPUID_EXT_PDCM before feature_dependencies[] check Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 36/59] i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16] Michael Tokarev
                   ` (23 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Chuang Xu, Zhao Liu, Guixiong Wei, Yipeng Yin,
	Paolo Bonzini, Michael Tokarev

From: Chuang Xu <xuchuangxclwt@bytedance.com>

When QEMU is started with:
-cpu host,migratable=on,host-cache-info=on,l3-cache=off
-smp 180,sockets=2,dies=1,cores=45,threads=2

On Intel platform:
CPUID.01H.EBX[23:16] is defined as "max number of addressable IDs for
logical processors in the physical package".

When executing "cpuid -1 -l 1 -r" in the guest, we obtain a value of 90 for
CPUID.01H.EBX[23:16], whereas the expected value is 128. Additionally,
executing "cpuid -1 -l 4 -r" in the guest yields a value of 63 for
CPUID.04H.EAX[31:26], which matches the expected result.

As (1+CPUID.04H.EAX[31:26]) rounds up to the nearest power-of-2 integer,
it's necessary to round up CPUID.01H.EBX[23:16] to the nearest power-of-2
integer too. Otherwise there would be unexpected results in guest with
older kernel.

For example, when QEMU is started with CLI above and xtopology is disabled,
guest kernel 5.15.120 uses CPUID.01H.EBX[23:16]/(1+CPUID.04H.EAX[31:26]) to
calculate threads-per-core in detect_ht(). Then guest will get "90/(1+63)=1"
as the result, even though threads-per-core should actually be 2.

And on AMD platform:
CPUID.01H.EBX[23:16] is defined as "Logical processor count". Current
result meets our expectation.

So round up CPUID.01H.EBX[23:16] to the nearest power-of-2 integer only
for Intel platform to solve the unexpected result.

Use the "x-vendor-cpuid-only-v2" compat option to fix this issue.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Guixiong Wei <weiguixiong@bytedance.com>
Signed-off-by: Yipeng Yin <yinyipeng@bytedance.com>
Signed-off-by: Chuang Xu <xuchuangxclwt@bytedance.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20250714080859.1960104-5-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit f985a1195ba2d9c6f6f33e83fe2e419a7e8acb60)
(Mjt: this change refers to cpu->vendor_cpuid_only_v2 which is introduced
 after 10.0, but this reference is removed later.  Replace it with false
 for now, so effectively this commit is a no-op, but prepares the code
 for the next change in this area and keeps historical references)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index d3e3ca13ca..ed262edcc8 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6835,7 +6835,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         }
         *edx = env->features[FEAT_1_EDX];
         if (threads_per_pkg > 1) {
-            *ebx |= threads_per_pkg << 16;
+            /*
+             * For CPUID.01H.EBX[Bits 23-16], AMD requires logical processor
+             * count, but Intel needs maximum number of addressable IDs for
+             * logical processors per package.
+             */
+            if (/*10.0: cpu->vendor_cpuid_only_v2*/ false &&
+                (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) {
+                *ebx |= 1 << apicid_pkg_offset(topo_info) << 16;
+            } else {
+                *ebx |= threads_per_pkg << 16;
+            }
         }
         break;
     case 2:
-- 
2.47.2



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

* [Stable-10.0.4 36/59] i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16]
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (34 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 35/59] i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16] Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 37/59] target/i386/cpu: Move addressable ID encoding out of compat property in CPUID[0x1] Michael Tokarev
                   ` (22 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Qian Wen, Xiaoyao Li, Zhao Liu, Paolo Bonzini,
	Michael Tokarev

From: Qian Wen <qian.wen@intel.com>

The legacy topology enumerated by CPUID.1.EBX[23:16] is defined in SDM
Vol2:

Bits 23-16: Maximum number of addressable IDs for logical processors in
this physical package.

When threads_per_socket > 255, it will 1) overwrite bits[31:24] which is
apic_id, 2) bits [23:16] get truncated.

Specifically, if launching the VM with -smp 256, the value written to
EBX[23:16] is 0 because of data overflow. If the guest only supports
legacy topology, without V2 Extended Topology enumerated by CPUID.0x1f
or Extended Topology enumerated by CPUID.0x0b to support over 255 CPUs,
the return of the kernel invoking cpu_smt_allowed() is false and APs
(application processors) will fail to bring up. Then only CPU 0 is online,
and others are offline.

For example, launch VM via:
qemu-system-x86_64 -M q35,accel=kvm,kernel-irqchip=split \
    -cpu qemu64,cpuid-0xb=off -smp 256 -m 32G \
    -drive file=guest.img,if=none,id=virtio-disk0,format=raw \
    -device virtio-blk-pci,drive=virtio-disk0,bootindex=1 --nographic

The guest shows:
    CPU(s):               256
    On-line CPU(s) list:  0
    Off-line CPU(s) list: 1-255

To avoid this issue caused by overflow, limit the max value written to
EBX[23:16] to 255 as the HW does.

Cc: qemu-stable@nongnu.org
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Qian Wen <qian.wen@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20250714080859.1960104-6-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit a62fef58299562aae6667b8d8552247423e886b3)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ed262edcc8..56af1857b9 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6835,6 +6835,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         }
         *edx = env->features[FEAT_1_EDX];
         if (threads_per_pkg > 1) {
+            uint32_t num;
+
             /*
              * For CPUID.01H.EBX[Bits 23-16], AMD requires logical processor
              * count, but Intel needs maximum number of addressable IDs for
@@ -6842,10 +6844,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
              */
             if (/*10.0: cpu->vendor_cpuid_only_v2*/ false &&
                 (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) {
-                *ebx |= 1 << apicid_pkg_offset(topo_info) << 16;
+                num = 1 << apicid_pkg_offset(topo_info);
             } else {
-                *ebx |= threads_per_pkg << 16;
+                num = threads_per_pkg;
             }
+
+            /* Fixup overflow: max value for bits 23-16 is 255. */
+            *ebx |= MIN(num, 255) << 16;
         }
         break;
     case 2:
-- 
2.47.2



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

* [Stable-10.0.4 37/59] target/i386/cpu: Move addressable ID encoding out of compat property in CPUID[0x1]
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (35 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 36/59] i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16] Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 38/59] ppc/xive: Fix xive trace event output Michael Tokarev
                   ` (21 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Zhao Liu, Michael Tokarev, Chuang Xu,
	Philippe Mathieu-Daudé

From: Zhao Liu <zhao1.liu@intel.com>

Currently, the addressable ID encoding for CPUID[0x1].EBX[bits 16-23]
(Maximum number of addressable IDs for logical processors in this
physical package) is covered by vendor_cpuid_only_v2 compat property.
The previous consideration was to avoid breaking migration and this
compat property makes it unfriendly to backport the commit f985a1195ba2
("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX
[23:16]").

However, NetBSD booting is broken since the commit 88dd4ca06c83
("i386/cpu: Use APIC ID info to encode cache topo in CPUID[4]"),
because NetBSD calculates smt information via `lp_max` / `core_max` for
legacy Intel CPUs which doesn't support 0xb leaf, where `lp_max` is from
CPUID[0x1].EBX.bits[16-23] and `core_max` is from CPUID[0x4].0x0.bits[26
-31].

The commit 88dd4ca0 changed the encoding rule of `core_max` but didn't
update `lp_max`, so that NetBSD would get the wrong smt information,
which leads to the module loading failure.

Luckily, the commit f985a1195ba2 ("i386/cpu: Fix number of addressable
IDs field for CPUID.01H.EBX[23:16]") updated the encoding rule for
`lp_max` and accidentally fixed the NetBSD issue too. This also shows
that using CPUID[0x1] and CPUID[0x4].0x0 to calculate HT/SMT information
is a common practice to detect CPU topology on legacy Intel CPUs.

Therefore, it's necessary to backport the commit f985a1195ba2 to
previous stable QEMU to help address the similar issues as well. Then
the compat property is not needed any more since all stable QEMUs will
follow the same encoding way.

So, in CPUID[0x1], move addressable ID encoding out of compat property.

Reported-by: Michael Tokarev <mjt@tls.msk.ru>
Inspired-by: Chuang Xu <xuchuangxclwt@bytedance.com>
Fixes: commit f985a1195ba2 ("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16]")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3061
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Tested-by: Michael Tokarev <mjt@tls.msk.ru>
Message-ID: <20250804053548.1808629-1-zhao1.liu@intel.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit 4e5d58969ed6927a7f1b08ba6223c34c8b990c92)
(Mjt: when picking up commit f985a1195ba2d9c6f6f33e83fe2e419a7e8acb60
 "i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16]"
 to 10.0, I commented out the condition (vendor_cpuid_only_v2 comparison)
 which is now being removed)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 56af1857b9..58c62ff5b5 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6842,8 +6842,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
              * count, but Intel needs maximum number of addressable IDs for
              * logical processors per package.
              */
-            if (/*10.0: cpu->vendor_cpuid_only_v2*/ false &&
-                (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) {
+            if ((IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) {
                 num = 1 << apicid_pkg_offset(topo_info);
             } else {
                 num = threads_per_pkg;
-- 
2.47.2



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

* [Stable-10.0.4 38/59] ppc/xive: Fix xive trace event output
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (36 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 37/59] target/i386/cpu: Move addressable ID encoding out of compat property in CPUID[0x1] Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 39/59] ppc/xive: Report access size in XIVE TM operation error logs Michael Tokarev
                   ` (20 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Nicholas Piggin, Glenn Miles, Michael Kowal,
	Caleb Schlossin, Gautam Menghani, Cédric Le Goater,
	Michael Tokarev

From: Nicholas Piggin <npiggin@gmail.com>

Typo, IBP should be IPB.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Michael Kowal <kowal@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.ibm.com>
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20250512031100.439842-2-npiggin@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit 301fbbaf03fb114a1e45833987ddfd7bbb403963)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 0ba9a02e73..f77f9733c9 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -274,9 +274,9 @@ kvm_xive_cpu_connect(uint32_t id) "connect CPU%d to KVM device"
 kvm_xive_source_reset(uint32_t srcno) "IRQ 0x%x"
 
 # xive.c
-xive_tctx_accept(uint32_t index, uint8_t ring, uint8_t ipb, uint8_t pipr, uint8_t cppr, uint8_t nsr) "target=%d ring=0x%x IBP=0x%02x PIPR=0x%02x CPPR=0x%02x NSR=0x%02x ACK"
-xive_tctx_notify(uint32_t index, uint8_t ring, uint8_t ipb, uint8_t pipr, uint8_t cppr, uint8_t nsr) "target=%d ring=0x%x IBP=0x%02x PIPR=0x%02x CPPR=0x%02x NSR=0x%02x raise !"
-xive_tctx_set_cppr(uint32_t index, uint8_t ring, uint8_t ipb, uint8_t pipr, uint8_t cppr, uint8_t nsr) "target=%d ring=0x%x IBP=0x%02x PIPR=0x%02x new CPPR=0x%02x NSR=0x%02x"
+xive_tctx_accept(uint32_t index, uint8_t ring, uint8_t ipb, uint8_t pipr, uint8_t cppr, uint8_t nsr) "target=%d ring=0x%x IPB=0x%02x PIPR=0x%02x CPPR=0x%02x NSR=0x%02x ACK"
+xive_tctx_notify(uint32_t index, uint8_t ring, uint8_t ipb, uint8_t pipr, uint8_t cppr, uint8_t nsr) "target=%d ring=0x%x IPB=0x%02x PIPR=0x%02x CPPR=0x%02x NSR=0x%02x raise !"
+xive_tctx_set_cppr(uint32_t index, uint8_t ring, uint8_t ipb, uint8_t pipr, uint8_t cppr, uint8_t nsr) "target=%d ring=0x%x IPB=0x%02x PIPR=0x%02x new CPPR=0x%02x NSR=0x%02x"
 xive_source_esb_read(uint64_t addr, uint32_t srcno, uint64_t value) "@0x%"PRIx64" IRQ 0x%x val=0x%"PRIx64
 xive_source_esb_write(uint64_t addr, uint32_t srcno, uint64_t value) "@0x%"PRIx64" IRQ 0x%x val=0x%"PRIx64
 xive_router_end_notify(uint8_t end_blk, uint32_t end_idx, uint32_t end_data) "END 0x%02x/0x%04x -> enqueue 0x%08x"
-- 
2.47.2



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

* [Stable-10.0.4 39/59] ppc/xive: Report access size in XIVE TM operation error logs
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (37 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 38/59] ppc/xive: Fix xive trace event output Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 40/59] ppc/xive2: Fix calculation of END queue sizes Michael Tokarev
                   ` (19 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Nicholas Piggin, Glenn Miles, Michael Kowal,
	Caleb Schlossin, Gautam Menghani, Cédric Le Goater,
	Michael Tokarev

From: Nicholas Piggin <npiggin@gmail.com>

Report access size in XIVE TM operation error logs.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Michael Kowal <kowal@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.ibm.com>
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20250512031100.439842-3-npiggin@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit f0aab779418ed883ea2b5ffcc3985ef26f6e3545)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/xive.c b/hw/intc/xive.c
index 3eb28c2265..80b07a0afe 100644
--- a/hw/intc/xive.c
+++ b/hw/intc/xive.c
@@ -326,7 +326,7 @@ static void xive_tm_raw_write(XiveTCTX *tctx, hwaddr offset, uint64_t value,
      */
     if (size < 4 || !mask || ring_offset == TM_QW0_USER) {
         qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid write access at TIMA @%"
-                      HWADDR_PRIx"\n", offset);
+                      HWADDR_PRIx" size %d\n", offset, size);
         return;
     }
 
@@ -357,7 +357,7 @@ static uint64_t xive_tm_raw_read(XiveTCTX *tctx, hwaddr offset, unsigned size)
      */
     if (size < 4 || !mask || ring_offset == TM_QW0_USER) {
         qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid read access at TIMA @%"
-                      HWADDR_PRIx"\n", offset);
+                      HWADDR_PRIx" size %d\n", offset, size);
         return -1;
     }
 
@@ -688,7 +688,7 @@ void xive_tctx_tm_write(XivePresenter *xptr, XiveTCTX *tctx, hwaddr offset,
         xto = xive_tm_find_op(tctx->xptr, offset, size, true);
         if (!xto) {
             qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid write access at TIMA "
-                          "@%"HWADDR_PRIx"\n", offset);
+                          "@%"HWADDR_PRIx" size %d\n", offset, size);
         } else {
             xto->write_handler(xptr, tctx, offset, value, size);
         }
@@ -727,7 +727,7 @@ uint64_t xive_tctx_tm_read(XivePresenter *xptr, XiveTCTX *tctx, hwaddr offset,
         xto = xive_tm_find_op(tctx->xptr, offset, size, false);
         if (!xto) {
             qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid read access to TIMA"
-                          "@%"HWADDR_PRIx"\n", offset);
+                          "@%"HWADDR_PRIx" size %d\n", offset, size);
             return -1;
         }
         ret = xto->read_handler(xptr, tctx, offset, size);
-- 
2.47.2



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

* [Stable-10.0.4 40/59] ppc/xive2: Fix calculation of END queue sizes
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (38 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 39/59] ppc/xive: Report access size in XIVE TM operation error logs Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 41/59] ppc/xive2: Remote VSDs need to match on forwarding address Michael Tokarev
                   ` (18 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Glenn Miles, Nicholas Piggin, Michael Kowal,
	Caleb Schlossin, Gautam Menghani, Cédric Le Goater,
	Michael Tokarev

From: Glenn Miles <milesg@linux.ibm.com>

The queue size of an Event Notification Descriptor (END)
is determined by the 'cl' and QsZ fields of the END.
If the cl field is 1, then the queue size (in bytes) will
be the size of a cache line 128B * 2^QsZ and QsZ is limited
to 4.  Otherwise, it will be 4096B * 2^QsZ with QsZ limited
to 12.

Fixes: f8a233dedf2 ("ppc/xive2: Introduce a XIVE2 core framework")
Signed-off-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Michael Kowal <kowal@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.ibm.com>
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20250512031100.439842-4-npiggin@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit f16697292add6c3c15014a20fd5fce70b8c56734)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/xive2.c b/hw/intc/xive2.c
index 7d584dfafa..790152a2a6 100644
--- a/hw/intc/xive2.c
+++ b/hw/intc/xive2.c
@@ -188,12 +188,27 @@ void xive2_eas_pic_print_info(Xive2Eas *eas, uint32_t lisn, GString *buf)
                            (uint32_t) xive_get_field64(EAS2_END_DATA, eas->w));
 }
 
+#define XIVE2_QSIZE_CHUNK_CL    128
+#define XIVE2_QSIZE_CHUNK_4k   4096
+/* Calculate max number of queue entries for an END */
+static uint32_t xive2_end_get_qentries(Xive2End *end)
+{
+    uint32_t w3 = end->w3;
+    uint32_t qsize = xive_get_field32(END2_W3_QSIZE, w3);
+    if (xive_get_field32(END2_W3_CL, w3)) {
+        g_assert(qsize <= 4);
+        return (XIVE2_QSIZE_CHUNK_CL << qsize) / sizeof(uint32_t);
+    } else {
+        g_assert(qsize <= 12);
+        return (XIVE2_QSIZE_CHUNK_4k << qsize) / sizeof(uint32_t);
+    }
+}
+
 void xive2_end_queue_pic_print_info(Xive2End *end, uint32_t width, GString *buf)
 {
     uint64_t qaddr_base = xive2_end_qaddr(end);
-    uint32_t qsize = xive_get_field32(END2_W3_QSIZE, end->w3);
     uint32_t qindex = xive_get_field32(END2_W1_PAGE_OFF, end->w1);
-    uint32_t qentries = 1 << (qsize + 10);
+    uint32_t qentries = xive2_end_get_qentries(end);
     int i;
 
     /*
@@ -223,8 +238,7 @@ void xive2_end_pic_print_info(Xive2End *end, uint32_t end_idx, GString *buf)
     uint64_t qaddr_base = xive2_end_qaddr(end);
     uint32_t qindex = xive_get_field32(END2_W1_PAGE_OFF, end->w1);
     uint32_t qgen = xive_get_field32(END2_W1_GENERATION, end->w1);
-    uint32_t qsize = xive_get_field32(END2_W3_QSIZE, end->w3);
-    uint32_t qentries = 1 << (qsize + 10);
+    uint32_t qentries = xive2_end_get_qentries(end);
 
     uint32_t nvx_blk = xive_get_field32(END2_W6_VP_BLOCK, end->w6);
     uint32_t nvx_idx = xive_get_field32(END2_W6_VP_OFFSET, end->w6);
@@ -341,13 +355,12 @@ void xive2_nvgc_pic_print_info(Xive2Nvgc *nvgc, uint32_t nvgc_idx, GString *buf)
 static void xive2_end_enqueue(Xive2End *end, uint32_t data)
 {
     uint64_t qaddr_base = xive2_end_qaddr(end);
-    uint32_t qsize = xive_get_field32(END2_W3_QSIZE, end->w3);
     uint32_t qindex = xive_get_field32(END2_W1_PAGE_OFF, end->w1);
     uint32_t qgen = xive_get_field32(END2_W1_GENERATION, end->w1);
 
     uint64_t qaddr = qaddr_base + (qindex << 2);
     uint32_t qdata = cpu_to_be32((qgen << 31) | (data & 0x7fffffff));
-    uint32_t qentries = 1 << (qsize + 10);
+    uint32_t qentries = xive2_end_get_qentries(end);
 
     if (dma_memory_write(&address_space_memory, qaddr, &qdata, sizeof(qdata),
                          MEMTXATTRS_UNSPECIFIED)) {
diff --git a/include/hw/ppc/xive2_regs.h b/include/hw/ppc/xive2_regs.h
index b11395c563..3c28de8a30 100644
--- a/include/hw/ppc/xive2_regs.h
+++ b/include/hw/ppc/xive2_regs.h
@@ -87,6 +87,7 @@ typedef struct Xive2End {
 #define END2_W2_EQ_ADDR_HI         PPC_BITMASK32(8, 31)
         uint32_t       w3;
 #define END2_W3_EQ_ADDR_LO         PPC_BITMASK32(0, 24)
+#define END2_W3_CL                 PPC_BIT32(27)
 #define END2_W3_QSIZE              PPC_BITMASK32(28, 31)
         uint32_t       w4;
 #define END2_W4_END_BLOCK          PPC_BITMASK32(4, 7)
-- 
2.47.2



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

* [Stable-10.0.4 41/59] ppc/xive2: Remote VSDs need to match on forwarding address
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (39 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 40/59] ppc/xive2: Fix calculation of END queue sizes Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 42/59] ppc/xive2: fix context push calculation of IPB priority Michael Tokarev
                   ` (17 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Michael Kowal, Nicholas Piggin, Glenn Miles,
	Caleb Schlossin, Gautam Menghani, Cédric Le Goater,
	Michael Tokarev

From: Michael Kowal <kowal@linux.ibm.com>

In a multi chip environment there will be remote/forwarded VSDs.  The check
to find a matching INT controller (XIVE) of the remote block number was
checking the INTs chip number.  Block numbers are not tied to a chip number.
The matching remote INT is the one that matches the forwarded VSD address
with VSD types associated MMIO BAR.

Signed-off-by: Michael Kowal <kowal@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Michael Kowal <kowal@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.ibm.com>
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20250512031100.439842-5-npiggin@gmail.com
[ clg: Fixed log format in pnv_xive2_get_remote() ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit e8cf73b849879cd93b1d1b5fd3bde79fb42064dc)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/pnv_xive2.c b/hw/intc/pnv_xive2.c
index 0b81dad6ba..92e62b3e5f 100644
--- a/hw/intc/pnv_xive2.c
+++ b/hw/intc/pnv_xive2.c
@@ -101,12 +101,10 @@ static uint32_t pnv_xive2_block_id(PnvXive2 *xive)
 }
 
 /*
- * Remote access to controllers. HW uses MMIOs. For now, a simple scan
- * of the chips is good enough.
- *
- * TODO: Block scope support
+ * Remote access to INT controllers. HW uses MMIOs(?). For now, a simple
+ * scan of all the chips INT controller is good enough.
  */
-static PnvXive2 *pnv_xive2_get_remote(uint8_t blk)
+static PnvXive2 *pnv_xive2_get_remote(uint32_t vsd_type, hwaddr fwd_addr)
 {
     PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
     int i;
@@ -115,10 +113,23 @@ static PnvXive2 *pnv_xive2_get_remote(uint8_t blk)
         Pnv10Chip *chip10 = PNV10_CHIP(pnv->chips[i]);
         PnvXive2 *xive = &chip10->xive;
 
-        if (pnv_xive2_block_id(xive) == blk) {
+        /*
+         * Is this the XIVE matching the forwarded VSD address is for this
+         * VSD type
+         */
+        if ((vsd_type == VST_ESB   && fwd_addr == xive->esb_base) ||
+            (vsd_type == VST_END   && fwd_addr == xive->end_base)  ||
+            ((vsd_type == VST_NVP ||
+              vsd_type == VST_NVG) && fwd_addr == xive->nvpg_base) ||
+            (vsd_type == VST_NVC   && fwd_addr == xive->nvc_base)) {
             return xive;
         }
     }
+
+    qemu_log_mask(LOG_GUEST_ERROR,
+                 "XIVE: >>>>> %s vsd_type %u  fwd_addr 0x%"HWADDR_PRIx
+                  " NOT FOUND\n",
+                  __func__, vsd_type, fwd_addr);
     return NULL;
 }
 
@@ -251,8 +262,7 @@ static uint64_t pnv_xive2_vst_addr(PnvXive2 *xive, uint32_t type, uint8_t blk,
 
     /* Remote VST access */
     if (GETFIELD(VSD_MODE, vsd) == VSD_MODE_FORWARD) {
-        xive = pnv_xive2_get_remote(blk);
-
+        xive = pnv_xive2_get_remote(type, (vsd & VSD_ADDRESS_MASK));
         return xive ? pnv_xive2_vst_addr(xive, type, blk, idx) : 0;
     }
 
-- 
2.47.2



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

* [Stable-10.0.4 42/59] ppc/xive2: fix context push calculation of IPB priority
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (40 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 41/59] ppc/xive2: Remote VSDs need to match on forwarding address Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 43/59] ppc/xive: Fix PHYS NSR ring matching Michael Tokarev
                   ` (16 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Nicholas Piggin, Glenn Miles, Caleb Schlossin,
	Gautam Menghani, Cédric Le Goater, Michael Tokarev

From: Nicholas Piggin <npiggin@gmail.com>

Pushing a context and loading IPB from NVP is defined to merge ('or')
that IPB into the TIMA IPB register. PIPR should therefore be calculated
based on the final IPB value, not just the NVP value.

Fixes: 9d2b6058c5b ("ppc/xive2: Add grouping level to notification")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.ibm.com>
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20250512031100.439842-6-npiggin@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit d1023a296c8297454fc4b207d58707c0a5e62e0a)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/xive2.c b/hw/intc/xive2.c
index 790152a2a6..4dd04a0398 100644
--- a/hw/intc/xive2.c
+++ b/hw/intc/xive2.c
@@ -835,8 +835,9 @@ static void xive2_tctx_need_resend(Xive2Router *xrtr, XiveTCTX *tctx,
         nvp.w2 = xive_set_field32(NVP2_W2_IPB, nvp.w2, 0);
         xive2_router_write_nvp(xrtr, nvp_blk, nvp_idx, &nvp, 2);
     }
+    /* IPB bits in the backlog are merged with the TIMA IPB bits */
     regs[TM_IPB] |= ipb;
-    backlog_prio = xive_ipb_to_pipr(ipb);
+    backlog_prio = xive_ipb_to_pipr(regs[TM_IPB]);
     backlog_level = 0;
 
     first_group = xive_get_field32(NVP2_W0_PGOFIRST, nvp.w0);
-- 
2.47.2



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

* [Stable-10.0.4 43/59] ppc/xive: Fix PHYS NSR ring matching
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (41 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 42/59] ppc/xive2: fix context push calculation of IPB priority Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 44/59] ppc/xive2: Reset Generation Flipped bit on END Cache Watch Michael Tokarev
                   ` (15 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Nicholas Piggin, Glenn Miles, Michael Kowal,
	Caleb Schlossin, Gautam Menghani, Cédric Le Goater,
	Michael Tokarev

From: Nicholas Piggin <npiggin@gmail.com>

Test that the NSR exception bit field is equal to the pool ring value,
rather than any common bits set, which is more correct (although there
is no practical bug because the LSI NSR type is not implemented and
POOL/PHYS NSR are encoded with exclusive bits).

Fixes: 4c3ccac636 ("pnv/xive: Add special handling for pool targets")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Michael Kowal <kowal@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.ibm.com>
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20250512031100.439842-7-npiggin@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit bde8c148bb22b99cb84cda800fa555851b8cb358)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/xive.c b/hw/intc/xive.c
index 80b07a0afe..cebe409a1a 100644
--- a/hw/intc/xive.c
+++ b/hw/intc/xive.c
@@ -54,7 +54,8 @@ static uint64_t xive_tctx_accept(XiveTCTX *tctx, uint8_t ring)
         uint8_t *alt_regs;
 
         /* POOL interrupt uses IPB in QW2, POOL ring */
-        if ((ring == TM_QW3_HV_PHYS) && (nsr & (TM_QW3_NSR_HE_POOL << 6))) {
+        if ((ring == TM_QW3_HV_PHYS) &&
+            ((nsr & TM_QW3_NSR_HE) == (TM_QW3_NSR_HE_POOL << 6))) {
             alt_ring = TM_QW2_HV_POOL;
         } else {
             alt_ring = ring;
-- 
2.47.2



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

* [Stable-10.0.4 44/59] ppc/xive2: Reset Generation Flipped bit on END Cache Watch
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (42 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 43/59] ppc/xive: Fix PHYS NSR ring matching Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 45/59] ppc/xive2: Fix irq preempted by lower priority group irq Michael Tokarev
                   ` (14 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Michael Kowal, Nicholas Piggin, Glenn Miles,
	Caleb Schlossin, Gautam Menghani, Cédric Le Goater,
	Michael Tokarev

From: Michael Kowal <kowal@linux.ibm.com>

When the END Event Queue wraps the END EQ Generation bit is flipped and the
Generation Flipped bit is set to one.  On a END cache Watch read operation,
the Generation Flipped bit needs to be reset.

While debugging an error modified END not valid error messages to include
the method since all were the same.

Signed-off-by: Michael Kowal <kowal@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Michael Kowal <kowal@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.ibm.com>
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20250512031100.439842-8-npiggin@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit 576830428eea6ebfc85792851a343214b834e401)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/pnv_xive2.c b/hw/intc/pnv_xive2.c
index 92e62b3e5f..7535fb67b9 100644
--- a/hw/intc/pnv_xive2.c
+++ b/hw/intc/pnv_xive2.c
@@ -1325,10 +1325,11 @@ static uint64_t pnv_xive2_ic_vc_read(void *opaque, hwaddr offset,
     case VC_ENDC_WATCH3_DATA0:
         /*
          * Load DATA registers from cache with data requested by the
-         * SPEC register
+         * SPEC register.  Clear gen_flipped bit in word 1.
          */
         watch_engine = (offset - VC_ENDC_WATCH0_DATA0) >> 6;
         pnv_xive2_end_cache_load(xive, watch_engine);
+        xive->vc_regs[reg] &= ~(uint64_t)END2_W1_GEN_FLIPPED;
         val = xive->vc_regs[reg];
         break;
 
diff --git a/hw/intc/xive2.c b/hw/intc/xive2.c
index 4dd04a0398..453fe37f18 100644
--- a/hw/intc/xive2.c
+++ b/hw/intc/xive2.c
@@ -374,8 +374,8 @@ static void xive2_end_enqueue(Xive2End *end, uint32_t data)
         qgen ^= 1;
         end->w1 = xive_set_field32(END2_W1_GENERATION, end->w1, qgen);
 
-        /* TODO(PowerNV): reset GF bit on a cache watch operation */
-        end->w1 = xive_set_field32(END2_W1_GEN_FLIPPED, end->w1, qgen);
+        /* Set gen flipped to 1, it gets reset on a cache watch operation */
+        end->w1 = xive_set_field32(END2_W1_GEN_FLIPPED, end->w1, 1);
     }
     end->w1 = xive_set_field32(END2_W1_PAGE_OFF, end->w1, qindex);
 }
-- 
2.47.2



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

* [Stable-10.0.4 45/59] ppc/xive2: Fix irq preempted by lower priority group irq
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (43 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 44/59] ppc/xive2: Reset Generation Flipped bit on END Cache Watch Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 46/59] ppc/xive2: Fix treatment of PIPR in CPPR update Michael Tokarev
                   ` (13 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Glenn Miles, Nicholas Piggin, Michael Kowal,
	Caleb Schlossin, Gautam Menghani, Cédric Le Goater,
	Michael Tokarev

From: Glenn Miles <milesg@linux.ibm.com>

A problem was seen where uart interrupts would be lost resulting in the
console hanging. Traces showed that a lower priority interrupt was
preempting a higher priority interrupt, which would result in the higher
priority interrupt never being handled.

The new interrupt's priority was being compared against the CPPR
(Current Processor Priority Register) instead of the PIPR (Post
Interrupt Priority Register), as was required by the XIVE spec.
This allowed for a window between raising an interrupt and ACK'ing
the interrupt where a lower priority interrupt could slip in.

Fixes: 26c55b99418 ("ppc/xive2: Process group backlog when updating the CPPR")
Signed-off-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Michael Kowal <kowal@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.ibm.com>
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20250512031100.439842-10-npiggin@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit 8d373176181fbc11f8d8eae2b4532b867f083ea6)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/xive2.c b/hw/intc/xive2.c
index 453fe37f18..2b4d0f51be 100644
--- a/hw/intc/xive2.c
+++ b/hw/intc/xive2.c
@@ -1283,7 +1283,7 @@ bool xive2_tm_irq_precluded(XiveTCTX *tctx, int ring, uint8_t priority)
      * priority to know if the thread can take the interrupt now or if
      * it is precluded.
      */
-    if (priority < alt_regs[TM_CPPR]) {
+    if (priority < alt_regs[TM_PIPR]) {
         return false;
     }
     return true;
-- 
2.47.2



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

* [Stable-10.0.4 46/59] ppc/xive2: Fix treatment of PIPR in CPPR update
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (44 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 45/59] ppc/xive2: Fix irq preempted by lower priority group irq Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 47/59] ui/curses: Fix infinite loop on windows Michael Tokarev
                   ` (12 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Glenn Miles, Nicholas Piggin, Michael Kowal,
	Caleb Schlossin, Gautam Menghani, Cédric Le Goater,
	Michael Tokarev

From: Glenn Miles <milesg@linux.ibm.com>

According to the XIVE spec, updating the CPPR should also update the
PIPR. The final value of the PIPR depends on other factors, but it
should never be set to a value that is above the CPPR.

Also added support for redistributing an active group interrupt when it
is precluded as a result of changing the CPPR value.

Signed-off-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Michael Kowal <kowal@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.ibm.com>
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20250512031100.439842-11-npiggin@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit d4720a7faf4bb415f3fe7f10e5c888212b81316a)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/intc/xive2.c b/hw/intc/xive2.c
index 2b4d0f51be..1971c05fa1 100644
--- a/hw/intc/xive2.c
+++ b/hw/intc/xive2.c
@@ -995,7 +995,9 @@ static void xive2_tctx_set_cppr(XiveTCTX *tctx, uint8_t ring, uint8_t cppr)
             }
         }
     }
-    regs[TM_PIPR] = pipr_min;
+
+    /* PIPR should not be set to a value greater than CPPR */
+    regs[TM_PIPR] = (pipr_min > cppr) ? cppr : pipr_min;
 
     rc = xive2_tctx_get_nvp_indexes(tctx, ring_min, &nvp_blk, &nvp_idx);
     if (rc) {
-- 
2.47.2



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

* [Stable-10.0.4 47/59] ui/curses: Fix infinite loop on windows
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (45 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 46/59] ppc/xive2: Fix treatment of PIPR in CPPR update Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 48/59] target/loongarch: Fix [X]VLDI raising exception incorrectly Michael Tokarev
                   ` (11 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, William Hu, Philippe Mathieu-Daudé,
	Marc-André Lureau, Michael Tokarev

From: William Hu <purplearmadillo77@proton.me>

Replace -1 comparisons for wint_t with WEOF to fix infinite loop caused by a
65535 == -1 comparison.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2905
Signed-off-by: William Hu <purplearmadillo77@proton.me>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
[ Marc-André - Add missing similar code change, remove a comment ]
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <tSO5to8--iex6QMThG3Z8ElfnNOUahK_yitw2G2tEVRPoMKV936CBdrpyfbeNpVEpziKqeQ1ShBwPOoDkofgApM8YWwnPKJR_JrPDThV8Bc=@proton.me>
(cherry picked from commit c7ac771ee750e37808928b62388fd27dcbf00f46)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/ui/curses.c b/ui/curses.c
index a39aee8762..161f78c35c 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -265,7 +265,8 @@ static int curses2foo(const int _curses2foo[], const int _curseskey2foo[],
 
 static void curses_refresh(DisplayChangeListener *dcl)
 {
-    int chr, keysym, keycode, keycode_alt;
+    wint_t chr = 0;
+    int keysym, keycode, keycode_alt;
     enum maybe_keycode maybe_keycode = CURSES_KEYCODE;
 
     curses_winch_check();
@@ -284,8 +285,9 @@ static void curses_refresh(DisplayChangeListener *dcl)
         /* while there are any pending key strokes to process */
         chr = console_getch(&maybe_keycode);
 
-        if (chr == -1)
+        if (chr == WEOF) {
             break;
+        }
 
 #ifdef KEY_RESIZE
         /* this shouldn't occur when we use a custom SIGWINCH handler */
@@ -304,9 +306,9 @@ static void curses_refresh(DisplayChangeListener *dcl)
         /* alt or esc key */
         if (keycode == 1) {
             enum maybe_keycode next_maybe_keycode = CURSES_KEYCODE;
-            int nextchr = console_getch(&next_maybe_keycode);
+            wint_t nextchr = console_getch(&next_maybe_keycode);
 
-            if (nextchr != -1) {
+            if (nextchr != WEOF) {
                 chr = nextchr;
                 maybe_keycode = next_maybe_keycode;
                 keycode_alt = ALT;
-- 
2.47.2



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

* [Stable-10.0.4 48/59] target/loongarch: Fix [X]VLDI raising exception incorrectly
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (46 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 47/59] ui/curses: Fix infinite loop on windows Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 49/59] hw/nvme: fix namespace attachment Michael Tokarev
                   ` (10 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, WANG Rui, Zhou Qiankang, Song Gao, Michael Tokarev

From: WANG Rui <wangrui@loongson.cn>

According to the specification, [X]VLDI should trigger an invalid instruction
exception only when Bit[12] is 1 and Bit[11:8] > 12. This patch fixes an issue
where an exception was incorrectly raised even when Bit[12] was 0.

Test case:

```
    .global main
main:
    vldi    $vr0, 3328
    ret
```

Reported-by: Zhou Qiankang <wszqkzqk@qq.com>
Signed-off-by: WANG Rui <wangrui@loongson.cn>
Reviewed-by: Song Gao <gaosong@loongson.cn>
Message-ID: <20250804132212.4816-1-wangrui@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
(cherry picked from commit e66644c48e96e81848c6aa94b185f59fc212d080)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/loongarch/tcg/insn_trans/trans_vec.c.inc b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
index 78730029cb..38bccf2838 100644
--- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
@@ -3585,7 +3585,9 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz)
     int sel, vece;
     uint64_t value;
 
-    if (!check_valid_vldi_mode(a)) {
+    sel = (a->imm >> 12) & 0x1;
+
+    if (sel && !check_valid_vldi_mode(a)) {
         generate_exception(ctx, EXCCODE_INE);
         return true;
     }
@@ -3594,8 +3596,6 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz)
         return true;
     }
 
-    sel = (a->imm >> 12) & 0x1;
-
     if (sel) {
         value = vldi_get_value(ctx, a->imm);
         vece = MO_64;
-- 
2.47.2



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

* [Stable-10.0.4 49/59] hw/nvme: fix namespace attachment
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (47 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 48/59] target/loongarch: Fix [X]VLDI raising exception incorrectly Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 50/59] hw/nvme: revert CMIC behavior Michael Tokarev
                   ` (9 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Klaus Jensen, Jesper Wendel Devantier,
	Michael Tokarev

From: Klaus Jensen <k.jensen@samsung.com>

Commit 6ccca4b6bb9f ("hw/nvme: rework csi handling") introduced a bug in
Namespace Attachment, causing it to

  a) not allow a controller to attach namespaces to other controllers
  b) assert if a valid non-attached namespace is detached

This fixes both issues.

Fixes: 6ccca4b6bb9f ("hw/nvme: rework csi handling")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2976
Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
(cherry picked from commit 31b737b19dca4d50758f5e9834d27b683102f2f1)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index d6b77d4fbc..669fff41c7 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6816,7 +6816,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
 
         switch (sel) {
         case NVME_NS_ATTACHMENT_ATTACH:
-            if (nvme_ns(n, nsid)) {
+            if (nvme_ns(ctrl, nsid)) {
                 return NVME_NS_ALREADY_ATTACHED | NVME_DNR;
             }
 
@@ -6824,7 +6824,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
                 return NVME_NS_PRIVATE | NVME_DNR;
             }
 
-            if (!nvme_csi_supported(n, ns->csi)) {
+            if (!nvme_csi_supported(ctrl, ns->csi)) {
                 return NVME_IOCS_NOT_SUPPORTED | NVME_DNR;
             }
 
@@ -6834,6 +6834,10 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
             break;
 
         case NVME_NS_ATTACHMENT_DETACH:
+            if (!nvme_ns(ctrl, nsid)) {
+                return NVME_NS_NOT_ATTACHED | NVME_DNR;
+            }
+
             nvme_detach_ns(ctrl, ns);
             nvme_update_dsm_limits(ctrl, NULL);
 
-- 
2.47.2



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

* [Stable-10.0.4 50/59] hw/nvme: revert CMIC behavior
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (48 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 49/59] hw/nvme: fix namespace attachment Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 51/59] hw/nvme: cap MDTS value for internal limitation Michael Tokarev
                   ` (8 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Klaus Jensen, Alan Adamson, Michael Tokarev

From: Klaus Jensen <k.jensen@samsung.com>

Commit cd59f50ab017 ("hw/nvme: always initialize a subsystem") causes
the controller to always set the CMIC.MCTRS ("Multiple Controllers")
bit. While spec-compliant, this is a deviation from the previous
behavior where this was only set if an nvme-subsys device was explicitly
created (to configure a subsystem with multiple controllers/namespaces).

Revert the behavior to only set CMIC.MCTRS if an nvme-subsys device is
created explicitly.

Reported-by: Alan Adamson <alan.adamson@oracle.com>
Fixes: cd59f50ab017 ("hw/nvme: always initialize a subsystem")
Reviewed-by: Alan Adamson <alan.adamson@oracle.com>
Tested-by: Alan Adamson <alan.adamson@oracle.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
(cherry picked from commit bc0c24fdb157b014932a5012fe4ccbeba7617f17)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 669fff41c7..f34bd68c04 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -8780,7 +8780,7 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)
     uint8_t *pci_conf = pci_dev->config;
     uint64_t cap = ldq_le_p(&n->bar.cap);
     NvmeSecCtrlEntry *sctrl = nvme_sctrl(n);
-    uint32_t ctratt;
+    uint32_t ctratt = le32_to_cpu(id->ctratt);
     uint16_t oacs;
 
     memcpy(n->cse.acs, nvme_cse_acs_default, sizeof(n->cse.acs));
@@ -8798,10 +8798,11 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)
 
     id->oaes = cpu_to_le32(NVME_OAES_NS_ATTR);
 
-    ctratt = NVME_CTRATT_ELBAS;
+    ctratt |= NVME_CTRATT_ELBAS;
     if (n->params.ctratt.mem) {
         ctratt |= NVME_CTRATT_MEM;
     }
+    id->ctratt = cpu_to_le32(ctratt);
 
     id->rab = 6;
 
@@ -8884,17 +8885,6 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)
     id->psd[0].enlat = cpu_to_le32(0x10);
     id->psd[0].exlat = cpu_to_le32(0x4);
 
-    id->cmic |= NVME_CMIC_MULTI_CTRL;
-    ctratt |= NVME_CTRATT_ENDGRPS;
-
-    id->endgidmax = cpu_to_le16(0x1);
-
-    if (n->subsys->endgrp.fdp.enabled) {
-        ctratt |= NVME_CTRATT_FDPS;
-    }
-
-    id->ctratt = cpu_to_le32(ctratt);
-
     NVME_CAP_SET_MQES(cap, n->params.mqes);
     NVME_CAP_SET_CQR(cap, 1);
     NVME_CAP_SET_TO(cap, 0xf);
@@ -8927,6 +8917,20 @@ static int nvme_init_subsys(NvmeCtrl *n, Error **errp)
         }
 
         n->subsys = NVME_SUBSYS(dev);
+    } else {
+        NvmeIdCtrl *id = &n->id_ctrl;
+        uint32_t ctratt = le32_to_cpu(id->ctratt);
+
+        id->cmic |= NVME_CMIC_MULTI_CTRL;
+        ctratt |= NVME_CTRATT_ENDGRPS;
+
+        id->endgidmax = cpu_to_le16(0x1);
+
+        if (n->subsys->endgrp.fdp.enabled) {
+            ctratt |= NVME_CTRATT_FDPS;
+        }
+
+        id->ctratt = cpu_to_le32(ctratt);
     }
 
     cntlid = nvme_subsys_register_ctrl(n, errp);
-- 
2.47.2



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

* [Stable-10.0.4 51/59] hw/nvme: cap MDTS value for internal limitation
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (49 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 50/59] hw/nvme: revert CMIC behavior Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 52/59] rbd: Fix .bdrv_get_specific_info implementation Michael Tokarev
                   ` (7 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Keith Busch, Klaus Jensen, Michael Tokarev

From: Keith Busch <kbusch@kernel.org>

The emulated device had let the user set whatever max transfers size
they wanted, including no limit. However the device does have an
internal limit of 1024 segments. NVMe doesn't report max segments,
though. This is implicitly inferred based on the MDTS and MPSMIN values.

IOV_MAX is currently 1024 which 4k PRPs can exceed with 2MB transfers.
Don't allow MDTS values that can exceed this, otherwise users risk
seeing "internal error" status to their otherwise protocol compliant
commands.

Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
(cherry picked from commit 53493c1f836f4dda90a6b5f2fb3d9264918c6871)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index f34bd68c04..67cb95c809 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -8339,6 +8339,11 @@ static bool nvme_check_params(NvmeCtrl *n, Error **errp)
         host_memory_backend_set_mapped(n->pmr.dev, true);
     }
 
+    if (!n->params.mdts || ((1 << n->params.mdts) + 1) > IOV_MAX) {
+        error_setg(errp, "mdts exceeds IOV_MAX");
+        return false;
+    }
+
     if (n->params.zasl > n->params.mdts) {
         error_setg(errp, "zoned.zasl (Zone Append Size Limit) must be less "
                    "than or equal to mdts (Maximum Data Transfer Size)");
-- 
2.47.2



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

* [Stable-10.0.4 52/59] rbd: Fix .bdrv_get_specific_info implementation
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (50 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 51/59] hw/nvme: cap MDTS value for internal limitation Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 53/59] qemu-iotests: Ignore indentation in Killed messages Michael Tokarev
                   ` (6 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Kevin Wolf, Hanna Czenczek, Michael Tokarev

From: Kevin Wolf <kwolf@redhat.com>

qemu_rbd_get_specific_info() has at least two problems:

The first is that it issues a blocking rbd_read() call in order to probe
the encryption format for the image while querying the node. This means
that if the connection to the server goes down, not only I/O is stuck
(which is unavoidable), but query-names-block-nodes will actually make
the whole QEMU instance unresponsive. .bdrv_get_specific_info
implementations shouldn't perform blocking operations, but only return
what is already known.

The second is that the information returned isn't even correct. If the
image is already opened with encryption enabled at the RBD level, we'll
probe for "double encryption", i.e. if the encrypted data contains
another encryption header. If it doesn't (which is the normal case), we
won't return the encryption format. If it does, we return misleading
information because it looks like we're talking about the outer level
(the encryption format of the image itself) while the information is
about an encryption header in the guest data.

Fix this by storing the encryption format in BDRVRBDState when the image
is opened (and we do blocking operations anyway) and returning only the
stored information in qemu_rbd_get_specific_info().

The information we'll store is either the actual encryption format that
we enabled on the RBD level, or if the image is unencrypted, the result
of the same probing as we previously did when querying the node. Probing
image formats based on content that can be modified by the guest has
long been known as problematic, but as long as we only output it to the
user instead of making decisions based on it, it should be okay. It is
undoubtedly useful in the context of 'qemu-img info' when you're trying
to figure out which encryption options you have to use to open the
image successfully.

Fixes: 42e4ac9ef5a6 ("block/rbd: Add support for rbd image encryption")
Buglink: https://issues.redhat.com/browse/RHEL-105440
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20250811134010.81787-1-kwolf@redhat.com>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 4af976ef398e4e823addc00bf1c58787ba4952fe)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/block/rbd.c b/block/rbd.c
index af984fb7db..446e90d34c 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -99,6 +99,14 @@ typedef struct BDRVRBDState {
     char *namespace;
     uint64_t image_size;
     uint64_t object_size;
+
+    /*
+     * If @bs->encrypted is true, this is the encryption format actually loaded
+     * at the librbd level. If it is false, it is the result of probing.
+     * RBD_IMAGE_ENCRYPTION_FORMAT__MAX means that encryption is not enabled and
+     * probing didn't find any known encryption header either.
+     */
+    RbdImageEncryptionFormat encryption_format;
 } BDRVRBDState;
 
 typedef struct RBDTask {
@@ -471,10 +479,12 @@ static int qemu_rbd_encryption_format(rbd_image_t image,
     return 0;
 }
 
-static int qemu_rbd_encryption_load(rbd_image_t image,
+static int qemu_rbd_encryption_load(BlockDriverState *bs,
+                                    rbd_image_t image,
                                     RbdEncryptionOptions *encrypt,
                                     Error **errp)
 {
+    BDRVRBDState *s = bs->opaque;
     int r = 0;
     g_autofree char *passphrase = NULL;
     rbd_encryption_luks1_format_options_t luks_opts;
@@ -545,15 +555,19 @@ static int qemu_rbd_encryption_load(rbd_image_t image,
         error_setg_errno(errp, -r, "encryption load fail");
         return r;
     }
+    bs->encrypted = true;
+    s->encryption_format = encrypt->format;
 
     return 0;
 }
 
 #ifdef LIBRBD_SUPPORTS_ENCRYPTION_LOAD2
-static int qemu_rbd_encryption_load2(rbd_image_t image,
+static int qemu_rbd_encryption_load2(BlockDriverState *bs,
+                                     rbd_image_t image,
                                      RbdEncryptionOptions *encrypt,
                                      Error **errp)
 {
+    BDRVRBDState *s = bs->opaque;
     int r = 0;
     int encrypt_count = 1;
     int i;
@@ -639,6 +653,8 @@ static int qemu_rbd_encryption_load2(rbd_image_t image,
         error_setg_errno(errp, -r, "layered encryption load fail");
         goto exit;
     }
+    bs->encrypted = true;
+    s->encryption_format = encrypt->format;
 
 exit:
     for (i = 0; i < encrypt_count; ++i) {
@@ -672,6 +688,45 @@ exit:
 #endif
 #endif
 
+/*
+ * For an image without encryption enabled on the rbd layer, probe the start of
+ * the image if it could be opened as an encrypted image so that we can display
+ * it when the user queries the node (most importantly in qemu-img).
+ *
+ * If the guest writes an encryption header to its disk after this probing, this
+ * won't be reflected when queried, but that's okay. There is no reason why the
+ * user should want to apply encryption at the rbd level while the image is
+ * still in use. This is just guest data.
+ */
+static void qemu_rbd_encryption_probe(BlockDriverState *bs)
+{
+    BDRVRBDState *s = bs->opaque;
+    char buf[RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN] = {0};
+    int r;
+
+    assert(s->encryption_format == RBD_IMAGE_ENCRYPTION_FORMAT__MAX);
+
+    r = rbd_read(s->image, 0,
+                 RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN, buf);
+    if (r < RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) {
+        return;
+    }
+
+    if (memcmp(buf, rbd_luks_header_verification,
+               RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) == 0) {
+        s->encryption_format = RBD_IMAGE_ENCRYPTION_FORMAT_LUKS;
+    } else if (memcmp(buf, rbd_luks2_header_verification,
+               RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) == 0) {
+        s->encryption_format = RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2;
+    } else if (memcmp(buf, rbd_layered_luks_header_verification,
+               RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) == 0) {
+        s->encryption_format = RBD_IMAGE_ENCRYPTION_FORMAT_LUKS;
+    } else if (memcmp(buf, rbd_layered_luks2_header_verification,
+               RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) == 0) {
+        s->encryption_format = RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2;
+    }
+}
+
 /* FIXME Deprecate and remove keypairs or make it available in QMP. */
 static int qemu_rbd_do_create(BlockdevCreateOptions *options,
                               const char *keypairs, const char *password_secret,
@@ -1134,17 +1189,18 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
         goto failed_open;
     }
 
+    s->encryption_format = RBD_IMAGE_ENCRYPTION_FORMAT__MAX;
     if (opts->encrypt) {
 #ifdef LIBRBD_SUPPORTS_ENCRYPTION
         if (opts->encrypt->parent) {
 #ifdef LIBRBD_SUPPORTS_ENCRYPTION_LOAD2
-            r = qemu_rbd_encryption_load2(s->image, opts->encrypt, errp);
+            r = qemu_rbd_encryption_load2(bs, s->image, opts->encrypt, errp);
 #else
             r = -ENOTSUP;
             error_setg(errp, "RBD library does not support layered encryption");
 #endif
         } else {
-            r = qemu_rbd_encryption_load(s->image, opts->encrypt, errp);
+            r = qemu_rbd_encryption_load(bs, s->image, opts->encrypt, errp);
         }
         if (r < 0) {
             goto failed_post_open;
@@ -1154,6 +1210,8 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
         error_setg(errp, "RBD library does not support image encryption");
         goto failed_post_open;
 #endif
+    } else {
+        qemu_rbd_encryption_probe(bs);
     }
 
     r = rbd_stat(s->image, &info, sizeof(info));
@@ -1413,17 +1471,6 @@ static ImageInfoSpecific *qemu_rbd_get_specific_info(BlockDriverState *bs,
 {
     BDRVRBDState *s = bs->opaque;
     ImageInfoSpecific *spec_info;
-    char buf[RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN] = {0};
-    int r;
-
-    if (s->image_size >= RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) {
-        r = rbd_read(s->image, 0,
-                     RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN, buf);
-        if (r < 0) {
-            error_setg_errno(errp, -r, "cannot read image start for probe");
-            return NULL;
-        }
-    }
 
     spec_info = g_new(ImageInfoSpecific, 1);
     *spec_info = (ImageInfoSpecific){
@@ -1431,28 +1478,13 @@ static ImageInfoSpecific *qemu_rbd_get_specific_info(BlockDriverState *bs,
         .u.rbd.data = g_new0(ImageInfoSpecificRbd, 1),
     };
 
-    if (memcmp(buf, rbd_luks_header_verification,
-               RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) == 0) {
-        spec_info->u.rbd.data->encryption_format =
-                RBD_IMAGE_ENCRYPTION_FORMAT_LUKS;
-        spec_info->u.rbd.data->has_encryption_format = true;
-    } else if (memcmp(buf, rbd_luks2_header_verification,
-               RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) == 0) {
-        spec_info->u.rbd.data->encryption_format =
-                RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2;
-        spec_info->u.rbd.data->has_encryption_format = true;
-    } else if (memcmp(buf, rbd_layered_luks_header_verification,
-               RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) == 0) {
-        spec_info->u.rbd.data->encryption_format =
-                RBD_IMAGE_ENCRYPTION_FORMAT_LUKS;
-        spec_info->u.rbd.data->has_encryption_format = true;
-    } else if (memcmp(buf, rbd_layered_luks2_header_verification,
-               RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) == 0) {
-        spec_info->u.rbd.data->encryption_format =
-                RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2;
-        spec_info->u.rbd.data->has_encryption_format = true;
+    if (s->encryption_format == RBD_IMAGE_ENCRYPTION_FORMAT__MAX) {
+        assert(!bs->encrypted);
     } else {
-        spec_info->u.rbd.data->has_encryption_format = false;
+        ImageInfoSpecificRbd *rbd_info = spec_info->u.rbd.data;
+
+        rbd_info->has_encryption_format = true;
+        rbd_info->encryption_format = s->encryption_format;
     }
 
     return spec_info;
diff --git a/qapi/block-core.json b/qapi/block-core.json
index b1937780e1..807efd27fd 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -158,7 +158,14 @@
 ##
 # @ImageInfoSpecificRbd:
 #
-# @encryption-format: Image encryption format
+# @encryption-format: Image encryption format. If encryption is enabled for the
+#     image (see encrypted in BlockNodeInfo), this is the actual format in which the
+#     image is accessed. If encryption is not enabled, this is the result of
+#     probing when the image was opened, to give a suggestion which encryption
+#     format could be enabled. Note that probing results can be changed by the
+#     guest by writing a (possibly partial) encryption format header to the
+#     image, so don't treat this information as trusted if the guest is not
+#     trusted.
 #
 # Since: 6.1
 ##
-- 
2.47.2



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

* [Stable-10.0.4 53/59] qemu-iotests: Ignore indentation in Killed messages
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (51 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 52/59] rbd: Fix .bdrv_get_specific_info implementation Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:02 ` [Stable-10.0.4 54/59] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected Michael Tokarev
                   ` (5 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Werner Fink, Kevin Wolf, Martin Kletzander,
	Michael Tokarev

From: Werner Fink <werner@suse.de>

New bash 5.3 uses a different padding for reporting job status.

Resolves: boo#1246830
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3050
Signed-off-by: Werner Fink <werner@suse.de>
Message-ID: <aJL8RH8ePPNEteMg@boole.nue2.suse.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Tested-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit c0df98ab1f3d348bc05f09d1c093abc529f2b530)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/qemu-iotests/039.out b/tests/qemu-iotests/039.out
index e52484d4be..8fdbcc528a 100644
--- a/tests/qemu-iotests/039.out
+++ b/tests/qemu-iotests/039.out
@@ -11,7 +11,7 @@ No errors were found on the image.
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./common.rc: Killed                  ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
+./common.rc: Killed ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
 incompatible_features     [0]
 ERROR cluster 5 refcount=0 reference=1
 ERROR OFLAG_COPIED data cluster: l2_entry=8000000000050000 refcount=0
@@ -46,7 +46,7 @@ read 512/512 bytes at offset 0
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./common.rc: Killed                  ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
+./common.rc: Killed ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
 incompatible_features     [0]
 ERROR cluster 5 refcount=0 reference=1
 Rebuilding refcount structure
@@ -60,7 +60,7 @@ incompatible_features     []
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./common.rc: Killed                  ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
+./common.rc: Killed ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
 incompatible_features     []
 No errors were found on the image.
 
@@ -79,7 +79,7 @@ No errors were found on the image.
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./common.rc: Killed                  ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
+./common.rc: Killed ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
 incompatible_features     [0]
 ERROR cluster 5 refcount=0 reference=1
 ERROR OFLAG_COPIED data cluster: l2_entry=8000000000050000 refcount=0
@@ -89,7 +89,7 @@ Data may be corrupted, or further writes to the image may corrupt it.
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./common.rc: Killed                  ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
+./common.rc: Killed ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
 incompatible_features     []
 No errors were found on the image.
 *** done
diff --git a/tests/qemu-iotests/061.out b/tests/qemu-iotests/061.out
index 24c33add7c..951c6bf3e6 100644
--- a/tests/qemu-iotests/061.out
+++ b/tests/qemu-iotests/061.out
@@ -118,7 +118,7 @@ No errors were found on the image.
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
 wrote 131072/131072 bytes at offset 0
 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./common.rc: Killed                  ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
+./common.rc: Killed ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
 magic                     0x514649fb
 version                   3
 backing_file_offset       0x0
@@ -304,7 +304,7 @@ No errors were found on the image.
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
 wrote 131072/131072 bytes at offset 0
 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./common.rc: Killed                  ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
+./common.rc: Killed ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
 magic                     0x514649fb
 version                   3
 backing_file_offset       0x0
diff --git a/tests/qemu-iotests/137.out b/tests/qemu-iotests/137.out
index 86377c80cd..e19df5b6ba 100644
--- a/tests/qemu-iotests/137.out
+++ b/tests/qemu-iotests/137.out
@@ -35,7 +35,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
 qemu-io: Unsupported value 'blubb' for qcow2 option 'overlap-check'. Allowed are any of the following: none, constant, cached, all
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./common.rc: Killed                  ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
+./common.rc: Killed ( VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" )
 OK: Dirty bit not set
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
 qemu-io: Parameter 'lazy-refcounts' expects 'on' or 'off'
diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
index fc3c64bcb8..a8226e8b42 100644
--- a/tests/qemu-iotests/common.filter
+++ b/tests/qemu-iotests/common.filter
@@ -74,7 +74,7 @@ _filter_qemu_io()
 {
     _filter_win32 | \
     gsed -e "s/[0-9]* ops\; [0-9/:. sec]* ([0-9/.inf]* [EPTGMKiBbytes]*\/sec and [0-9/.inf]* ops\/sec)/X ops\; XX:XX:XX.X (XXX YYY\/sec and XXX ops\/sec)/" \
-        -e "s/: line [0-9][0-9]*:  *[0-9][0-9]*\( Aborted\| Killed\)/:\1/" \
+        -e "s/: line [0-9][0-9]*:  *[0-9][0-9]*\( Aborted\| Killed\) \{2,\}/:\1 /" \
         -e "s/qemu-io> //g"
 }
 
-- 
2.47.2



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

* [Stable-10.0.4 54/59] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (52 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 53/59] qemu-iotests: Ignore indentation in Killed messages Michael Tokarev
@ 2025-08-27 15:02 ` Michael Tokarev
  2025-08-27 15:03 ` [Stable-10.0.4 55/59] mkvenv: Support pip 25.2 Michael Tokarev
                   ` (4 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Philippe Mathieu-Daudé, Guenter Roeck,
	Alex Bennée, Gustavo Romero, Michael Tokarev

From: Philippe Mathieu-Daudé <philmd@linaro.org>

Commit 1585ab9f1ba ("hw/sd/sdcard: Fill SPI response bits in card
code") exposed a bug in the SPI adapter: if no SD card is plugged,
we are returning "there is a card with an error". This is wrong,
we shouldn't return any particular packet response, but the noise
shifted on the MISO line. Return the dummy byte, otherwise we get:

  qemu-system-riscv64: ../hw/sd/ssi-sd.c:160: ssi_sd_transfer: Assertion `s->arglen > 0' failed.

Reported-by: Guenter Roeck <linux@roeck-us.net>
Fixes: 775616c3ae8 ("Partial SD card SPI mode support")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Gustavo Romero <gustavo.romero@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20250812140415.70153-2-philmd@linaro.org>
(cherry picked from commit e262646e12acd6c1132e03d57fea20680a503251)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index c4a58da0ab..fbbcb5c750 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -106,6 +106,10 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
     SDRequest request;
     uint8_t longresp[16];
 
+    if (!sdbus_get_inserted(&s->sdbus)) {
+        return SSI_DUMMY;
+    }
+
     /*
      * Special case: allow CMD12 (STOP TRANSMISSION) while reading data.
      *
-- 
2.47.2



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

* [Stable-10.0.4 55/59] mkvenv: Support pip 25.2
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (53 preceding siblings ...)
  2025-08-27 15:02 ` [Stable-10.0.4 54/59] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected Michael Tokarev
@ 2025-08-27 15:03 ` Michael Tokarev
  2025-08-27 15:03 ` [Stable-10.0.4 56/59] hw/uefi: clear uefi-vars buffer in uefi_vars_write callback Michael Tokarev
                   ` (3 subsequent siblings)
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Sv. Lockal, John Snow, Stefan Hajnoczi,
	Michael Tokarev

From: "Sv. Lockal" <lockalsash@gmail.com>

Fix compilation with pip-25.2 due to missing distlib.version

Bug: https://gitlab.com/qemu-project/qemu/-/issues/3062

Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
[Edits: Type "safety" whackamole --js]
Signed-off-by: John Snow <jsnow@redhat.com>
Message-ID: <20250811190159.237321-1-jsnow@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit 6ad034e71232c2929ed546304c9d249312bb632f)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/python/scripts/mkvenv.py b/python/scripts/mkvenv.py
index 8ac5b0b2a0..f102527c4d 100644
--- a/python/scripts/mkvenv.py
+++ b/python/scripts/mkvenv.py
@@ -84,6 +84,7 @@
     Sequence,
     Tuple,
     Union,
+    cast,
 )
 import venv
 
@@ -94,17 +95,39 @@
 HAVE_DISTLIB = True
 try:
     import distlib.scripts
-    import distlib.version
 except ImportError:
     try:
         # Reach into pip's cookie jar.  pylint and flake8 don't understand
         # that these imports will be used via distlib.xxx.
         from pip._vendor import distlib
         import pip._vendor.distlib.scripts  # noqa, pylint: disable=unused-import
-        import pip._vendor.distlib.version  # noqa, pylint: disable=unused-import
     except ImportError:
         HAVE_DISTLIB = False
 
+# pip 25.2 does not vendor distlib.version, but it uses vendored
+# packaging.version
+HAVE_DISTLIB_VERSION = True
+try:
+    import distlib.version  # pylint: disable=ungrouped-imports
+except ImportError:
+    try:
+        # pylint: disable=unused-import,ungrouped-imports
+        import pip._vendor.distlib.version  # noqa
+    except ImportError:
+        HAVE_DISTLIB_VERSION = False
+
+HAVE_PACKAGING_VERSION = True
+try:
+    # Do not bother importing non-vendored packaging, because it is not
+    # in stdlib.
+    from pip._vendor import packaging
+    # pylint: disable=unused-import
+    import pip._vendor.packaging.requirements  # noqa
+    import pip._vendor.packaging.version  # noqa
+except ImportError:
+    HAVE_PACKAGING_VERSION = False
+
+
 # Try to load tomllib, with a fallback to tomli.
 # HAVE_TOMLLIB is checked below, just-in-time, so that mkvenv does not fail
 # outside the venv or before a potential call to ensurepip in checkpip().
@@ -133,6 +156,39 @@ class Ouch(RuntimeError):
     """An Exception class we can't confuse with a builtin."""
 
 
+class Matcher:
+    """Compatibility appliance for version/requirement string parsing."""
+    def __init__(self, name_and_constraint: str):
+        """Create a matcher from a requirement-like string."""
+        if HAVE_DISTLIB_VERSION:
+            self._m = distlib.version.LegacyMatcher(name_and_constraint)
+        elif HAVE_PACKAGING_VERSION:
+            self._m = packaging.requirements.Requirement(name_and_constraint)
+        else:
+            raise Ouch("found neither distlib.version nor packaging.version")
+        self.name = self._m.name
+
+    def match(self, version_str: str) -> bool:
+        """Return True if `version` satisfies the stored constraint."""
+        if HAVE_DISTLIB_VERSION:
+            return cast(
+                bool,
+                self._m.match(distlib.version.LegacyVersion(version_str))
+            )
+
+        assert HAVE_PACKAGING_VERSION
+        return cast(
+            bool,
+            self._m.specifier.contains(
+                packaging.version.Version(version_str), prereleases=True
+            )
+        )
+
+    def __repr__(self) -> str:
+        """Stable debug representation delegated to the backend."""
+        return repr(self._m)
+
+
 class QemuEnvBuilder(venv.EnvBuilder):
     """
     An extension of venv.EnvBuilder for building QEMU's configure-time venv.
@@ -669,7 +725,7 @@ def _do_ensure(
     canary = None
     for name, info in group.items():
         constraint = _make_version_constraint(info, False)
-        matcher = distlib.version.LegacyMatcher(name + constraint)
+        matcher = Matcher(name + constraint)
         print(f"mkvenv: checking for {matcher}", file=sys.stderr)
 
         dist: Optional[Distribution] = None
@@ -683,7 +739,7 @@ def _do_ensure(
             # Always pass installed package to pip, so that they can be
             # updated if the requested version changes
             or not _is_system_package(dist)
-            or not matcher.match(distlib.version.LegacyVersion(dist.version))
+            or not matcher.match(dist.version)
         ):
             absent.append(name + _make_version_constraint(info, True))
             if len(absent) == 1:
-- 
2.47.2



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

* [Stable-10.0.4 56/59] hw/uefi: clear uefi-vars buffer in uefi_vars_write callback
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (54 preceding siblings ...)
  2025-08-27 15:03 ` [Stable-10.0.4 55/59] mkvenv: Support pip 25.2 Michael Tokarev
@ 2025-08-27 15:03 ` Michael Tokarev
  2025-08-29 17:41   ` zdi-disclosures@trendmicro.com via
  2025-08-27 15:03 ` [Stable-10.0.4 57/59] hw/uefi: return success for notifications Michael Tokarev
                   ` (2 subsequent siblings)
  58 siblings, 1 reply; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Mauro Matteo Cascella, ZDI, Gerd Hoffmann,
	Michael Tokarev

From: Mauro Matteo Cascella <mcascell@redhat.com>

When the guest writes to register UEFI_VARS_REG_BUFFER_SIZE, the .write
callback `uefi_vars_write` is invoked. The function allocates a
heap buffer without zeroing the memory, leaving the buffer filled with
residual data from prior allocations. When the guest later reads from
register UEFI_VARS_REG_PIO_BUFFER_TRANSFER, the .read callback
`uefi_vars_read` returns leftover metadata or other sensitive process
memory from the previously allocated buffer, leading to an information
disclosure vulnerability.

Fixes: CVE-2025-8860
Fixes: 90ca4e03c27d ("hw/uefi: add var-service-core.c")
Reported-by: ZDI <zdi-disclosures@trendmicro.com>
Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Mauro Matteo Cascella <mcascell@redhat.com>
Message-ID: <20250811101128.17661-1-mcascell@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit f757d9d90d19b914d4023663bfc4da73bbbf007e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/uefi/var-service-core.c b/hw/uefi/var-service-core.c
index 4836a0cb81..92fc121fe7 100644
--- a/hw/uefi/var-service-core.c
+++ b/hw/uefi/var-service-core.c
@@ -259,8 +259,8 @@ static void uefi_vars_write(void *opaque, hwaddr addr, uint64_t val, unsigned si
         uv->buf_size = val;
         g_free(uv->buffer);
         g_free(uv->pio_xfer_buffer);
-        uv->buffer = g_malloc(uv->buf_size);
-        uv->pio_xfer_buffer = g_malloc(uv->buf_size);
+        uv->buffer = g_malloc0(uv->buf_size);
+        uv->pio_xfer_buffer = g_malloc0(uv->buf_size);
         break;
     case UEFI_VARS_REG_DMA_BUFFER_ADDR_LO:
         uv->buf_addr_lo = val;
-- 
2.47.2



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

* [Stable-10.0.4 57/59] hw/uefi: return success for notifications
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (55 preceding siblings ...)
  2025-08-27 15:03 ` [Stable-10.0.4 56/59] hw/uefi: clear uefi-vars buffer in uefi_vars_write callback Michael Tokarev
@ 2025-08-27 15:03 ` Michael Tokarev
  2025-08-27 15:03 ` [Stable-10.0.4 58/59] hw/uefi: check access for first variable Michael Tokarev
  2025-08-27 15:03 ` [Stable-10.0.4 59/59] hw/uefi: open json file in binary mode Michael Tokarev
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Gerd Hoffmann, Philippe Mathieu-Daudé,
	Michael Tokarev

From: Gerd Hoffmann <kraxel@redhat.com>

Set status to SUCCESS for ready-to-boot and exit-boot-services
notification calls.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-ID: <20250811130110.820958-2-kraxel@redhat.com>
(cherry picked from commit 88e5a28d5aabb57f44c1805fbba0a458023f5106)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/uefi/var-service-vars.c b/hw/uefi/var-service-vars.c
index 7f98d77a38..58ae560d6e 100644
--- a/hw/uefi/var-service-vars.c
+++ b/hw/uefi/var-service-vars.c
@@ -702,12 +702,14 @@ uint32_t uefi_vars_mm_vars_proto(uefi_vars_state *uv)
     case SMM_VARIABLE_FUNCTION_READY_TO_BOOT:
         trace_uefi_event("ready-to-boot");
         uv->ready_to_boot = true;
+        mvar->status = EFI_SUCCESS;
         length = 0;
         break;
 
     case SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE:
         trace_uefi_event("exit-boot-service");
         uv->exit_boot_service = true;
+        mvar->status = EFI_SUCCESS;
         length = 0;
         break;
 
-- 
2.47.2



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

* [Stable-10.0.4 58/59] hw/uefi: check access for first variable
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (56 preceding siblings ...)
  2025-08-27 15:03 ` [Stable-10.0.4 57/59] hw/uefi: return success for notifications Michael Tokarev
@ 2025-08-27 15:03 ` Michael Tokarev
  2025-08-27 15:03 ` [Stable-10.0.4 59/59] hw/uefi: open json file in binary mode Michael Tokarev
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Gerd Hoffmann, Philippe Mathieu-Daudé,
	Michael Tokarev

From: Gerd Hoffmann <kraxel@redhat.com>

When listing variables (via get-next-variable-name) only the names of
variables which can be accessed will be returned.  That check was
missing for the first variable though.  Add it.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-ID: <20250811130110.820958-3-kraxel@redhat.com>
(cherry picked from commit fc8ee8fe58ad410f27fca64e4ad212c5a3eabe00)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/uefi/var-service-vars.c b/hw/uefi/var-service-vars.c
index 58ae560d6e..e382fb2813 100644
--- a/hw/uefi/var-service-vars.c
+++ b/hw/uefi/var-service-vars.c
@@ -357,6 +357,9 @@ uefi_vars_mm_get_next_variable(uefi_vars_state *uv, mm_header *mhdr,
     if (uefi_strlen(name, nv->name_size) == 0) {
         /* empty string -> first */
         var = QTAILQ_FIRST(&uv->variables);
+        while (var && !check_access(uv, var)) {
+            var = QTAILQ_NEXT(var, next);
+        }
         if (!var) {
             return uefi_vars_mm_error(mhdr, mvar, EFI_NOT_FOUND);
         }
-- 
2.47.2



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

* [Stable-10.0.4 59/59] hw/uefi: open json file in binary mode
  2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
                   ` (57 preceding siblings ...)
  2025-08-27 15:03 ` [Stable-10.0.4 58/59] hw/uefi: check access for first variable Michael Tokarev
@ 2025-08-27 15:03 ` Michael Tokarev
  58 siblings, 0 replies; 62+ messages in thread
From: Michael Tokarev @ 2025-08-27 15:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Gerd Hoffmann, Philippe Mathieu-Daudé,
	Michael Tokarev

From: Gerd Hoffmann <kraxel@redhat.com>

Fixes file length discrepancies due to line ending conversions
on windows hosts.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3058
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-ID: <20250811130110.820958-4-kraxel@redhat.com>
(cherry picked from commit 040237436f423253f3397547aa78d449394dfbca)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/uefi/var-service-json.c b/hw/uefi/var-service-json.c
index ad3462cd15..f5f1556833 100644
--- a/hw/uefi/var-service-json.c
+++ b/hw/uefi/var-service-json.c
@@ -172,7 +172,7 @@ static GString *uefi_vars_to_json(uefi_vars_state *uv)
 void uefi_vars_json_init(uefi_vars_state *uv, Error **errp)
 {
     if (uv->jsonfile) {
-        uv->jsonfd = qemu_create(uv->jsonfile, O_RDWR, 0666, errp);
+        uv->jsonfd = qemu_create(uv->jsonfile, O_RDWR | O_BINARY, 0666, errp);
     }
 }
 
-- 
2.47.2



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

* RE: [Stable-10.0.4 56/59] hw/uefi: clear uefi-vars buffer in uefi_vars_write callback
  2025-08-27 15:03 ` [Stable-10.0.4 56/59] hw/uefi: clear uefi-vars buffer in uefi_vars_write callback Michael Tokarev
@ 2025-08-29 17:41   ` zdi-disclosures@trendmicro.com via
  2025-08-29 17:56     ` Mauro Matteo Cascella
  0 siblings, 1 reply; 62+ messages in thread
From: zdi-disclosures@trendmicro.com via @ 2025-08-29 17:41 UTC (permalink / raw)
  To: Michael Tokarev, qemu-devel@nongnu.org
  Cc: qemu-stable@nongnu.org, Mauro Matteo Cascella, Gerd Hoffmann

Hello Team,

May we know the ZDI-CAN mapped to CVE-2025-8860?

Regards,
The ZDI

-----Original Message-----
From: Michael Tokarev <mjt@tls.msk.ru>
Sent: Wednesday, August 27, 2025 8:03 AM
To: qemu-devel@nongnu.org
Cc: qemu-stable@nongnu.org; Mauro Matteo Cascella <mcascell@redhat.com>; ZDI Disclosures Mailbox <zdi-disclosures@trendmicro.com>; Gerd Hoffmann <kraxel@redhat.com>; Michael Tokarev <mjt@tls.msk.ru>
Subject: [Stable-10.0.4 56/59] hw/uefi: clear uefi-vars buffer in uefi_vars_write callback

From: Mauro Matteo Cascella <mcascell@redhat.com>

When the guest writes to register UEFI_VARS_REG_BUFFER_SIZE, the .write
callback `uefi_vars_write` is invoked. The function allocates a
heap buffer without zeroing the memory, leaving the buffer filled with
residual data from prior allocations. When the guest later reads from
register UEFI_VARS_REG_PIO_BUFFER_TRANSFER, the .read callback
`uefi_vars_read` returns leftover metadata or other sensitive process
memory from the previously allocated buffer, leading to an information
disclosure vulnerability.

Fixes: CVE-2025-8860
Fixes: 90ca4e03c27d ("hw/uefi: add var-service-core.c")
Reported-by: ZDI <zdi-disclosures@trendmicro.com>
Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Mauro Matteo Cascella <mcascell@redhat.com>
Message-ID: <20250811101128.17661-1-mcascell@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit f757d9d90d19b914d4023663bfc4da73bbbf007e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/uefi/var-service-core.c b/hw/uefi/var-service-core.c
index 4836a0cb81..92fc121fe7 100644
--- a/hw/uefi/var-service-core.c
+++ b/hw/uefi/var-service-core.c
@@ -259,8 +259,8 @@ static void uefi_vars_write(void *opaque, hwaddr addr, uint64_t val, unsigned si
         uv->buf_size = val;
         g_free(uv->buffer);
         g_free(uv->pio_xfer_buffer);
-        uv->buffer = g_malloc(uv->buf_size);
-        uv->pio_xfer_buffer = g_malloc(uv->buf_size);
+        uv->buffer = g_malloc0(uv->buf_size);
+        uv->pio_xfer_buffer = g_malloc0(uv->buf_size);
         break;
     case UEFI_VARS_REG_DMA_BUFFER_ADDR_LO:
         uv->buf_addr_lo = val;
--
2.47.2

TREND MICRO EMAIL NOTICE

The information contained in this email and any attachments is confidential and may be subject to copyright or other intellectual property protection. If you are not the intended recipient, you are not authorized to use or disclose this information, and we request that you notify us by reply mail or telephone and delete the original message from your mail system.

For details about what personal information we collect and why, please see our Privacy Notice on our website at: Read privacy policy<http://www.trendmicro.com/privacy>


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

* Re: [Stable-10.0.4 56/59] hw/uefi: clear uefi-vars buffer in uefi_vars_write callback
  2025-08-29 17:41   ` zdi-disclosures@trendmicro.com via
@ 2025-08-29 17:56     ` Mauro Matteo Cascella
  0 siblings, 0 replies; 62+ messages in thread
From: Mauro Matteo Cascella @ 2025-08-29 17:56 UTC (permalink / raw)
  To: zdi-disclosures@trendmicro.com
  Cc: Michael Tokarev, qemu-devel@nongnu.org, qemu-stable@nongnu.org,
	Gerd Hoffmann

On Fri, Aug 29, 2025 at 7:41 PM zdi-disclosures@trendmicro.com
<zdi-disclosures@trendmicro.com> wrote:
>
> Hello Team,
>
> May we know the ZDI-CAN mapped to CVE-2025-8860?

This was reported (by you) to the qemu-security ML as ZDI-CAN-27261.

> Regards,
> The ZDI
>
> -----Original Message-----
> From: Michael Tokarev <mjt@tls.msk.ru>
> Sent: Wednesday, August 27, 2025 8:03 AM
> To: qemu-devel@nongnu.org
> Cc: qemu-stable@nongnu.org; Mauro Matteo Cascella <mcascell@redhat.com>; ZDI Disclosures Mailbox <zdi-disclosures@trendmicro.com>; Gerd Hoffmann <kraxel@redhat.com>; Michael Tokarev <mjt@tls.msk.ru>
> Subject: [Stable-10.0.4 56/59] hw/uefi: clear uefi-vars buffer in uefi_vars_write callback
>
> From: Mauro Matteo Cascella <mcascell@redhat.com>
>
> When the guest writes to register UEFI_VARS_REG_BUFFER_SIZE, the .write
> callback `uefi_vars_write` is invoked. The function allocates a
> heap buffer without zeroing the memory, leaving the buffer filled with
> residual data from prior allocations. When the guest later reads from
> register UEFI_VARS_REG_PIO_BUFFER_TRANSFER, the .read callback
> `uefi_vars_read` returns leftover metadata or other sensitive process
> memory from the previously allocated buffer, leading to an information
> disclosure vulnerability.
>
> Fixes: CVE-2025-8860
> Fixes: 90ca4e03c27d ("hw/uefi: add var-service-core.c")
> Reported-by: ZDI <zdi-disclosures@trendmicro.com>
> Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
> Signed-off-by: Mauro Matteo Cascella <mcascell@redhat.com>
> Message-ID: <20250811101128.17661-1-mcascell@redhat.com>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> (cherry picked from commit f757d9d90d19b914d4023663bfc4da73bbbf007e)
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
>
> diff --git a/hw/uefi/var-service-core.c b/hw/uefi/var-service-core.c
> index 4836a0cb81..92fc121fe7 100644
> --- a/hw/uefi/var-service-core.c
> +++ b/hw/uefi/var-service-core.c
> @@ -259,8 +259,8 @@ static void uefi_vars_write(void *opaque, hwaddr addr, uint64_t val, unsigned si
>          uv->buf_size = val;
>          g_free(uv->buffer);
>          g_free(uv->pio_xfer_buffer);
> -        uv->buffer = g_malloc(uv->buf_size);
> -        uv->pio_xfer_buffer = g_malloc(uv->buf_size);
> +        uv->buffer = g_malloc0(uv->buf_size);
> +        uv->pio_xfer_buffer = g_malloc0(uv->buf_size);
>          break;
>      case UEFI_VARS_REG_DMA_BUFFER_ADDR_LO:
>          uv->buf_addr_lo = val;
> --
> 2.47.2
>
> TREND MICRO EMAIL NOTICE
>
> The information contained in this email and any attachments is confidential and may be subject to copyright or other intellectual property protection. If you are not the intended recipient, you are not authorized to use or disclose this information, and we request that you notify us by reply mail or telephone and delete the original message from your mail system.
>
> For details about what personal information we collect and why, please see our Privacy Notice on our website at: Read privacy policy<http://www.trendmicro.com/privacy>
>


-- 
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0



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

end of thread, other threads:[~2025-08-30 17:06 UTC | newest]

Thread overview: 62+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27 15:02 [Stable-10.0.4 00/59] Patch Round-up for stable 10.0.4, freeze on 2025-09-06 Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 01/59] host-utils: Drop workaround for buggy Apple Clang __builtin_subcll() Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 02/59] hw/display/qxl-render.c: fix qxl_unpack_chunks() chunk size calculation Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 03/59] target/i386: fix width of third operand of VINSERTx128 Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 04/59] linux-user/aarch64: Clear TPIDR2_EL0 when delivering signals Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 05/59] linux-user/aarch64: Support TPIDR2_MAGIC signal frame record Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 06/59] docs/user: clarify user-mode expects the same OS Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 07/59] target/mips: Only update MVPControl.EVP bit if executed by master VPE Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 08/59] hw/net/cadence_gem: fix register mask initialization Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 09/59] system/physmem: fix use-after-free with dispatch Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 10/59] roms/Makefile: fix npcmNxx_bootrom build rules Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 11/59] linux-user/strace.list: add riscv_hwprobe entry Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 12/59] target/riscv: do not call GETPC() in check_ret_from_m_mode() Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 13/59] target/riscv: Fix exception type when VU accesses supervisor CSRs Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 14/59] target/riscv: Fix pmp range wraparound on zero Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 15/59] intc/riscv_aplic: Fix target register read when source is inactive Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 16/59] target/riscv: Restrict mideleg/medeleg/medelegh access to S-mode harts Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 17/59] target/riscv: Restrict midelegh " Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 18/59] target/loongarch: Fix valid virtual address checking Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 19/59] virtio: fix off-by-one and invalid access in virtqueue_ordered_fill Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 20/59] vhost: Do not abort on log-start error Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 21/59] vhost: Do not abort on log-stop error Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 22/59] virtio-net: Fix VLAN filter table reset timing Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 23/59] pcie_sriov: Fix configuration and state synchronization Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 24/59] intel_iommu: Allow both Status Write and Interrupt Flag in QI wait Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 25/59] hw/i386/amd_iommu: Move IOAPIC memory region initialization to the end Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 26/59] hw/intc/arm_gicv3_kvm: Write all 1's to clear enable/active Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 27/59] target/arm: Fix big-endian handling of NEON gdb remote debugging Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 28/59] target/arm: Fix handling of setting SVE registers from gdb Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 29/59] hw/ssi/aspeed_smc: Fix incorrect FMC_WDT2 register read on AST1030 Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 30/59] target/arm: add support for 64-bit PMCCNTR in AArch32 mode Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 31/59] scripts/make-release: Go back to cloning all the EDK2 submodules Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 32/59] qga: correctly write to /sys/power/state on linux Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 33/59] Revert "i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16]" Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 34/59] i386/cpu: Move adjustment of CPUID_EXT_PDCM before feature_dependencies[] check Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 35/59] i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16] Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 36/59] i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16] Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 37/59] target/i386/cpu: Move addressable ID encoding out of compat property in CPUID[0x1] Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 38/59] ppc/xive: Fix xive trace event output Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 39/59] ppc/xive: Report access size in XIVE TM operation error logs Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 40/59] ppc/xive2: Fix calculation of END queue sizes Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 41/59] ppc/xive2: Remote VSDs need to match on forwarding address Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 42/59] ppc/xive2: fix context push calculation of IPB priority Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 43/59] ppc/xive: Fix PHYS NSR ring matching Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 44/59] ppc/xive2: Reset Generation Flipped bit on END Cache Watch Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 45/59] ppc/xive2: Fix irq preempted by lower priority group irq Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 46/59] ppc/xive2: Fix treatment of PIPR in CPPR update Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 47/59] ui/curses: Fix infinite loop on windows Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 48/59] target/loongarch: Fix [X]VLDI raising exception incorrectly Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 49/59] hw/nvme: fix namespace attachment Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 50/59] hw/nvme: revert CMIC behavior Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 51/59] hw/nvme: cap MDTS value for internal limitation Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 52/59] rbd: Fix .bdrv_get_specific_info implementation Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 53/59] qemu-iotests: Ignore indentation in Killed messages Michael Tokarev
2025-08-27 15:02 ` [Stable-10.0.4 54/59] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected Michael Tokarev
2025-08-27 15:03 ` [Stable-10.0.4 55/59] mkvenv: Support pip 25.2 Michael Tokarev
2025-08-27 15:03 ` [Stable-10.0.4 56/59] hw/uefi: clear uefi-vars buffer in uefi_vars_write callback Michael Tokarev
2025-08-29 17:41   ` zdi-disclosures@trendmicro.com via
2025-08-29 17:56     ` Mauro Matteo Cascella
2025-08-27 15:03 ` [Stable-10.0.4 57/59] hw/uefi: return success for notifications Michael Tokarev
2025-08-27 15:03 ` [Stable-10.0.4 58/59] hw/uefi: check access for first variable Michael Tokarev
2025-08-27 15:03 ` [Stable-10.0.4 59/59] hw/uefi: open json file in binary mode 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).