qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19
@ 2023-11-09 13:42 Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 01/55] hw/pvrdma: Protect against buggy or malicious guest driver Michael Tokarev
                   ` (55 more replies)
  0 siblings, 56 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Michael Tokarev

The following patches are queued for QEMU stable v8.1.3:

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

Patch freeze is 2023-11-19, and the release is planned for 2023-11-21:

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

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 85fc35afa93c Yuval Shaia:
   hw/pvrdma: Protect against buggy or malicious guest driver
02 caea03279e11 Fabiano Rosas:
   migration: Fix analyze-migration read operation signedness
03 d4f34485ca8a Juan Quintela:
   migration: Non multifd migration don't care about multifd flushes
04 acf873873ae3 John Snow:
   python/qmp: remove Server.wait_closed() call for Python 3.12
05 a5e3cb3b90a6 Paolo Bonzini:
   tests/docker: avoid invalid escape in Python string
06 e4b6532cc0a5 Paolo Bonzini:
   docs/sphinx: avoid invalid escape in Python string
07 e41c40d101fc Paolo Bonzini:
   target/hexagon: avoid invalid escape in Python string
08 1b5f3f65cc71 Paolo Bonzini:
   tests/avocado: avoid invalid escape in Python string
09 86a8989d4557 Paolo Bonzini:
   tests/vm: avoid invalid escape in Python string
10 e6d8e5e6e366 Paolo Bonzini:
   tracetool: avoid invalid escape in Python string
11 e6e66b032873 Richard Henderson:
   linux-user: Fixes for zero_bss
12 6fad9b4bb91d Mikulas Patocka:
   linux-user/mips: fix abort on integer overflow
13 3b894b699c9a Mikulas Patocka:
   linux-user/sh4: Fix crashes on signal delivery
14 a1e6a5c46219 Helge Deller:
   lasips2: LASI PS/2 devices are not user-createable
15 d01448c79d89 Michal Orzel:
   target/arm: Fix CNTPCT_EL0 trapping from EL0 when HCR_EL2.E2H is 0
16 ae5f70baf549 Lu Gao:
   hw/sd/sdhci: Block Size Register bits [14:12] is lost
17 4ab9a7429bf7 Peter Maydell:
   hw/rdma/vmw/pvrdma_cmd: Use correct struct in query_port()
18 930f1865cc65 Richard Henderson:
   target/sparc: Clear may_lookup for npc == DYNAMIC_PC
19 307521d6e29e Peter Maydell:
   target/arm: Fix syndrome for FGT traps on ERET
20 6f83dc67168d Glenn Miles:
   misc/led: LED state is set opposite of what is expected
21 fed824501501 Kevin Wolf:
   block: Fix locking in media change monitor commands
22 580731dcc87e Akihiko Odaki:
   tests/tcg: Add -fno-stack-protector
23 8b097fd6b06e Andrey Drobyshev:
   qemu-img: rebase: stop when reaching EOF of old backing file
24 827171c31805 Andrey Drobyshev:
   qemu-iotests: 024: add rebasing test case for overlay_size > backing_size
25 b11293c212c2 Richard Henderson:
   target/arm: Fix SVE STR increment
26 4c09abeae870 Peter Maydell:
   target/arm: Correctly propagate stage 1 BTI guarded bit in a two-stage walk
27 721da0396cfa Cédric Le Goater:
   util/uuid: Add UUID_STR_LEN definition
28 f8d6f3b16c37 Cédric Le Goater:
   vfio/pci: Fix buffer overrun when writing the VF token
29 4ef9d97b1a37 Cédric Le Goater:
   util/uuid: Remove UUID_FMT_LEN
30 e969f992c656 David Woodhouse:
   i386/xen: Don't advertise XENFEAT_supervisor_mode_kernel
31 e7dbb62ff19c David Woodhouse:
   i386/xen: fix per-vCPU upcall vector for Xen emulation
32 18e83f28bf39 David Woodhouse:
   hw/xen: select kernel mode for per-vCPU event channel upcall vector
33 3de75ed35241 David Woodhouse:
   hw/xen: don't clear map_track[] in xen_gnttab_reset()
34 4a5780f52095 David Woodhouse:
   hw/xen: fix XenStore watch delivery to guest
35 debc995e883b David Woodhouse:
   hw/xen: take iothread mutex in xen_evtchn_reset_op()
36 a1c1082908dd David Woodhouse:
   hw/xen: use correct default protocol for xen-block on x86
37 9c549ab6895a Marc-André Lureau:
   virtio-gpu: block migration of VMs with blob=true
38 cc8fb0c3ae3c Vladimir Sementsov-Ogievskiy:
   block/nvme: nvme_process_completion() fix bound for cid
39 5722fc471296 Peter Maydell:
   target/arm: Fix A64 LDRA immediate decode
40 b2b109041ecd Jean-Louis Dupond:
   qcow2: keep reference on zeroize with discard-no-unref enabled
41 10b9e0802a07 Sam Li:
   block/file-posix: fix update_zones_wp() caller
42 ad4feaca61d7 Naohiro Aota:
   file-posix: fix over-writing of returning zone_append offset
43 08730ee0cc01 BALATON Zoltan:
   ati-vga: Implement fallback for pixman routines
44 565f85a9c293 Marc-André Lureau:
   ui/gtk: force realization of drawing area
45 47fd6ab1e334 Dongwon Kim:
   ui/gtk-egl: apply scale factor when calculating window's dimension
46 6f189a08c1b0 Antonio Caggiano:
   ui/gtk-egl: Check EGLSurface before doing scanout
47 04591b3ddd9a Philippe Mathieu-Daudé:
   target/mips: Fix MSA BZ/BNZ opcodes displacement
48 18f86aecd6a1 Philippe Mathieu-Daudé:
   target/mips: Fix TX79 LQ/SQ opcodes
49 7d7512019fc4 Fiona Ebner:
   hw/ide: reset: cancel async DMA operation before resetting state
50 cc610857bbd3 Fiona Ebner:
   tests/qtest: ahci-test: add test exposing reset issue with pending callback
51 aba2ec341c6d Ilya Leoshkevich:
   target/s390x: Fix CLC corrupting cc_src
52 43fecbe7a53f Ilya Leoshkevich:
   tests/tcg/s390x: Test CLC with inaccessible second operand
53 bea402482a8c Ilya Leoshkevich:
   target/s390x: Fix LAALG not updating cc_src
54 ebc14107f1f3 Ilya Leoshkevich:
   tests/tcg/s390x: Test LAALG with negative cc_src
55 b523a3d54f3d Niklas Cassel:
   hw/ide/ahci: trigger either error IRQ or regular IRQ, not both


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

* [Stable-8.1.3 01/55] hw/pvrdma: Protect against buggy or malicious guest driver
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 02/55] migration: Fix analyze-migration read operation signedness Michael Tokarev
                   ` (54 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Yuval Shaia, Soul Chen, Thomas Huth, Michael Tokarev

From: Yuval Shaia <yuval.shaia.ml@gmail.com>

Guest driver allocates and initialize page tables to be used as a ring
of descriptors for CQ and async events.
The page table that represents the ring, along with the number of pages
in the page table is passed to the device.
Currently our device supports only one page table for a ring.

Let's make sure that the number of page table entries the driver
reports, do not exceeds the one page table size.

Reported-by: Soul Chen <soulchen8650@gmail.com>
Signed-off-by: Yuval Shaia <yuval.shaia.ml@gmail.com>
Fixes: CVE-2023-1544
Message-ID: <20230301142926.18686-1-yuval.shaia.ml@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit 85fc35afa93c7320d1641d344d0c5dfbe341d087)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
index 4fc6712025..55b338046e 100644
--- a/hw/rdma/vmw/pvrdma_main.c
+++ b/hw/rdma/vmw/pvrdma_main.c
@@ -91,19 +91,33 @@ static int init_dev_ring(PvrdmaRing *ring, PvrdmaRingState **ring_state,
                          dma_addr_t dir_addr, uint32_t num_pages)
 {
     uint64_t *dir, *tbl;
-    int rc = 0;
+    int max_pages, rc = 0;
 
     if (!num_pages) {
         rdma_error_report("Ring pages count must be strictly positive");
         return -EINVAL;
     }
 
+    /*
+     * Make sure we can satisfy the requested number of pages in a single
+     * TARGET_PAGE_SIZE sized page table (taking into account that first entry
+     * is reserved for ring-state)
+     */
+    max_pages = TARGET_PAGE_SIZE / sizeof(dma_addr_t) - 1;
+    if (num_pages > max_pages) {
+        rdma_error_report("Maximum pages on a single directory must not exceed %d\n",
+                          max_pages);
+        return -EINVAL;
+    }
+
     dir = rdma_pci_dma_map(pci_dev, dir_addr, TARGET_PAGE_SIZE);
     if (!dir) {
         rdma_error_report("Failed to map to page directory (ring %s)", name);
         rc = -ENOMEM;
         goto out;
     }
+
+    /* We support only one page table for a ring */
     tbl = rdma_pci_dma_map(pci_dev, dir[0], TARGET_PAGE_SIZE);
     if (!tbl) {
         rdma_error_report("Failed to map to page table (ring %s)", name);
-- 
2.39.2



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

* [Stable-8.1.3 02/55] migration: Fix analyze-migration read operation signedness
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 01/55] hw/pvrdma: Protect against buggy or malicious guest driver Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 03/55] migration: Non multifd migration don't care about multifd flushes Michael Tokarev
                   ` (53 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Fabiano Rosas, Juan Quintela, Michael Tokarev

From: Fabiano Rosas <farosas@suse.de>

The migration code uses unsigned values for 16, 32 and 64-bit
operations. Fix the script to do the same.

This was causing an issue when parsing the migration stream generated
on the ppc64 target because one of instance_ids was larger than the
32bit signed maximum:

Traceback (most recent call last):
  File "/home/fabiano/kvm/qemu/build/scripts/analyze-migration.py", line 658, in <module>
    dump.read(dump_memory = args.memory)
  File "/home/fabiano/kvm/qemu/build/scripts/analyze-migration.py", line 592, in read
    classdesc = self.section_classes[section_key]
KeyError: ('spapr_iommu', -2147483648)

Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-ID: <20231009184326.15777-6-farosas@suse.de>
(cherry picked from commit caea03279e11dfcb0e5a567b81fe7f02ee80af02)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py
index b82a1b0c58..44d306aedc 100755
--- a/scripts/analyze-migration.py
+++ b/scripts/analyze-migration.py
@@ -38,13 +38,13 @@ def __init__(self, filename):
         self.file = open(self.filename, "rb")
 
     def read64(self):
-        return int.from_bytes(self.file.read(8), byteorder='big', signed=True)
+        return int.from_bytes(self.file.read(8), byteorder='big', signed=False)
 
     def read32(self):
-        return int.from_bytes(self.file.read(4), byteorder='big', signed=True)
+        return int.from_bytes(self.file.read(4), byteorder='big', signed=False)
 
     def read16(self):
-        return int.from_bytes(self.file.read(2), byteorder='big', signed=True)
+        return int.from_bytes(self.file.read(2), byteorder='big', signed=False)
 
     def read8(self):
         return int.from_bytes(self.file.read(1), byteorder='big', signed=True)
-- 
2.39.2



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

* [Stable-8.1.3 03/55] migration: Non multifd migration don't care about multifd flushes
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 01/55] hw/pvrdma: Protect against buggy or malicious guest driver Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 02/55] migration: Fix analyze-migration read operation signedness Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 04/55] python/qmp: remove Server.wait_closed() call for Python 3.12 Michael Tokarev
                   ` (52 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Juan Quintela, Li Zhijian, Peter Xu, Michael Tokarev

From: Juan Quintela <quintela@redhat.com>

RDMA was having trouble because
migrate_multifd_flush_after_each_section() can only be true or false,
but we don't want to send any flush when we are not in multifd
migration.

CC: Fabiano Rosas <farosas@suse.de
Fixes: 294e5a4034e81 ("multifd: Only flush once each full round of memory")

Reported-by: Li Zhijian <lizhijian@fujitsu.com>
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-ID: <20231011205548.10571-2-quintela@redhat.com>
(cherry picked from commit d4f34485ca8a077c98fc2303451e9bece9200dd7)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/migration/ram.c b/migration/ram.c
index 9040d66e61..6e1514f69f 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1399,7 +1399,8 @@ static int find_dirty_block(RAMState *rs, PageSearchStatus *pss)
         pss->page = 0;
         pss->block = QLIST_NEXT_RCU(pss->block, next);
         if (!pss->block) {
-            if (!migrate_multifd_flush_after_each_section()) {
+            if (migrate_multifd() &&
+                !migrate_multifd_flush_after_each_section()) {
                 QEMUFile *f = rs->pss[RAM_CHANNEL_PRECOPY].pss_channel;
                 int ret = multifd_send_sync_main(f);
                 if (ret < 0) {
@@ -3076,7 +3077,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
         return ret;
     }
 
-    if (!migrate_multifd_flush_after_each_section()) {
+    if (migrate_multifd() && !migrate_multifd_flush_after_each_section()) {
         qemu_put_be64(f, RAM_SAVE_FLAG_MULTIFD_FLUSH);
     }
 
@@ -3188,7 +3189,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 out:
     if (ret >= 0
         && migration_is_setup_or_active(migrate_get_current()->state)) {
-        if (migrate_multifd_flush_after_each_section()) {
+        if (migrate_multifd() && migrate_multifd_flush_after_each_section()) {
             ret = multifd_send_sync_main(rs->pss[RAM_CHANNEL_PRECOPY].pss_channel);
             if (ret < 0) {
                 return ret;
@@ -3265,7 +3266,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
         return ret;
     }
 
-    if (!migrate_multifd_flush_after_each_section()) {
+    if (migrate_multifd() && !migrate_multifd_flush_after_each_section()) {
         qemu_put_be64(f, RAM_SAVE_FLAG_MULTIFD_FLUSH);
     }
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
@@ -3774,7 +3775,8 @@ int ram_load_postcopy(QEMUFile *f, int channel)
             break;
         case RAM_SAVE_FLAG_EOS:
             /* normal exit */
-            if (migrate_multifd_flush_after_each_section()) {
+            if (migrate_multifd() &&
+                migrate_multifd_flush_after_each_section()) {
                 multifd_recv_sync_main();
             }
             break;
@@ -4052,7 +4054,8 @@ static int ram_load_precopy(QEMUFile *f)
             break;
         case RAM_SAVE_FLAG_EOS:
             /* normal exit */
-            if (migrate_multifd_flush_after_each_section()) {
+            if (migrate_multifd() &&
+                migrate_multifd_flush_after_each_section()) {
                 multifd_recv_sync_main();
             }
             break;
-- 
2.39.2



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

* [Stable-8.1.3 04/55] python/qmp: remove Server.wait_closed() call for Python 3.12
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (2 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 03/55] migration: Non multifd migration don't care about multifd flushes Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 05/55] tests/docker: avoid invalid escape in Python string Michael Tokarev
                   ` (51 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, John Snow, Vladimir Sementsov-Ogievskiy,
	Michael Tokarev

From: John Snow <jsnow@redhat.com>

This patch is a backport from
https://gitlab.com/qemu-project/python-qemu-qmp/-/commit/e03a3334b6a477beb09b293708632f2c06fe9f61

According to Guido in https://github.com/python/cpython/issues/104344 ,
this call was never meant to wait for the server to shut down - that is
handled synchronously - but instead, this waits for all connections to
close. Or, it would have, if it wasn't broken since it was introduced.

3.12 fixes the bug, which now causes a hang in our code. The fix is just
to remove the wait.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-id: 20231006195243.3131140-3-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
(cherry picked from commit acf873873ae38e68371b0c53c42d3530636ff94e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/python/qemu/qmp/protocol.py b/python/qemu/qmp/protocol.py
index 753182131f..a4ffdfad51 100644
--- a/python/qemu/qmp/protocol.py
+++ b/python/qemu/qmp/protocol.py
@@ -495,7 +495,6 @@ async def _stop_server(self) -> None:
         try:
             self.logger.debug("Stopping server.")
             self._server.close()
-            await self._server.wait_closed()
             self.logger.debug("Server stopped.")
         finally:
             self._server = None
-- 
2.39.2



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

* [Stable-8.1.3 05/55] tests/docker: avoid invalid escape in Python string
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (3 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 04/55] python/qmp: remove Server.wait_closed() call for Python 3.12 Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 06/55] docs/sphinx: " Michael Tokarev
                   ` (50 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Paolo Bonzini, Michael Tokarev

From: Paolo Bonzini <pbonzini@redhat.com>

This is an error in Python 3.12; fix it by using a raw string literal.

Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit a5e3cb3b90a62a42cd19ad9a20ca25c7df1dc3da)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 688ef62989..3b8a26704d 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -186,7 +186,7 @@ def _check_binfmt_misc(executable):
               (binary))
         return None, True
 
-    m = re.search("interpreter (\S+)\n", entry)
+    m = re.search(r"interpreter (\S+)\n", entry)
     interp = m.group(1)
     if interp and interp != executable:
         print("binfmt_misc for %s does not point to %s, using %s" %
-- 
2.39.2



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

* [Stable-8.1.3 06/55] docs/sphinx: avoid invalid escape in Python string
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (4 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 05/55] tests/docker: avoid invalid escape in Python string Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 07/55] target/hexagon: " Michael Tokarev
                   ` (49 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Paolo Bonzini, Michael Tokarev

From: Paolo Bonzini <pbonzini@redhat.com>

This is an error in Python 3.12; fix it by using a raw string literal.

Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit e4b6532cc0a5518c0dea15eeca573829df9ec1df)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/docs/sphinx/hxtool.py b/docs/sphinx/hxtool.py
index fb0649a3d5..9f6b9d87dc 100644
--- a/docs/sphinx/hxtool.py
+++ b/docs/sphinx/hxtool.py
@@ -49,7 +49,7 @@ def serror(file, lnum, errtext):
 
 def parse_directive(line):
     """Return first word of line, if any"""
-    return re.split('\W', line)[0]
+    return re.split(r'\W', line)[0]
 
 def parse_defheading(file, lnum, line):
     """Handle a DEFHEADING directive"""
-- 
2.39.2



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

* [Stable-8.1.3 07/55] target/hexagon: avoid invalid escape in Python string
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (5 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 06/55] docs/sphinx: " Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 08/55] tests/avocado: " Michael Tokarev
                   ` (48 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Paolo Bonzini, Michael Tokarev

From: Paolo Bonzini <pbonzini@redhat.com>

This is an error in Python 3.12; fix it by using a raw string literal.

Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit e41c40d101fce79af4d679955eb6e0d31e02c47c)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/hexagon/hex_common.py b/target/hexagon/hex_common.py
index dce1b852a7..0da65d6dd6 100755
--- a/target/hexagon/hex_common.py
+++ b/target/hexagon/hex_common.py
@@ -45,7 +45,7 @@ def uniquify(seq):
 immre = re.compile(r"[#]([rRsSuUm])(\d+)(?:[:](\d+))?")
 reg_or_immre = re.compile(
     r"(((?<!DUP)[MNRCOPQXSGVZA])([stuvwxyzdefg]+)"
-    + "([.]?[LlHh]?)(\d+S?))|([#]([rRsSuUm])(\d+)[:]?(\d+)?)"
+    r"([.]?[LlHh]?)(\d+S?))|([#]([rRsSuUm])(\d+)[:]?(\d+)?)"
 )
 relimmre = re.compile(r"[#]([rR])(\d+)(?:[:](\d+))?")
 absimmre = re.compile(r"[#]([sSuUm])(\d+)(?:[:](\d+))?")
@@ -337,7 +337,7 @@ def read_attribs_file(name):
 
 
 def read_overrides_file(name):
-    overridere = re.compile("#define fGEN_TCG_([A-Za-z0-9_]+)\(.*")
+    overridere = re.compile(r"#define fGEN_TCG_([A-Za-z0-9_]+)\(.*")
     for line in open(name, "rt").readlines():
         if not overridere.match(line):
             continue
-- 
2.39.2



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

* [Stable-8.1.3 08/55] tests/avocado: avoid invalid escape in Python string
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (6 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 07/55] target/hexagon: " Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 09/55] tests/vm: " Michael Tokarev
                   ` (47 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Paolo Bonzini, Michael Tokarev

From: Paolo Bonzini <pbonzini@redhat.com>

This is an error in Python 3.12; fix it by using a raw string literal.

Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 1b5f3f65cc71341a4f9fc9e89bb6985fde703758)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/avocado/virtio_check_params.py b/tests/avocado/virtio_check_params.py
index 4093da8a67..0b1e99fc24 100644
--- a/tests/avocado/virtio_check_params.py
+++ b/tests/avocado/virtio_check_params.py
@@ -43,7 +43,7 @@
 class VirtioMaxSegSettingsCheck(QemuSystemTest):
     @staticmethod
     def make_pattern(props):
-        pattern_items = ['{0} = \w+'.format(prop) for prop in props]
+        pattern_items = [r'{0} = \w+'.format(prop) for prop in props]
         return '|'.join(pattern_items)
 
     def query_virtqueue(self, vm, dev_type_name):
-- 
2.39.2



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

* [Stable-8.1.3 09/55] tests/vm: avoid invalid escape in Python string
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (7 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 08/55] tests/avocado: " Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 10/55] tracetool: " Michael Tokarev
                   ` (46 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Paolo Bonzini, Michael Tokarev

From: Paolo Bonzini <pbonzini@redhat.com>

This is an error in Python 3.12; fix it by using a raw string literal
or by double-escaping the backslash.

Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 86a8989d4557a09b68f8b78b6c3fb6ad3f23ca6f)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index a97e23b0ce..6e31698906 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -331,8 +331,8 @@ def console_init(self, timeout = None):
     def console_log(self, text):
         for line in re.split("[\r\n]", text):
             # filter out terminal escape sequences
-            line = re.sub("\x1b\[[0-9;?]*[a-zA-Z]", "", line)
-            line = re.sub("\x1b\([0-9;?]*[a-zA-Z]", "", line)
+            line = re.sub("\x1b\\[[0-9;?]*[a-zA-Z]", "", line)
+            line = re.sub("\x1b\\([0-9;?]*[a-zA-Z]", "", line)
             # replace unprintable chars
             line = re.sub("\x1b", "<esc>", line)
             line = re.sub("[\x00-\x1f]", ".", line)
@@ -530,7 +530,7 @@ def get_qemu_version(qemu_path):
        and return the major number."""
     output = subprocess.check_output([qemu_path, '--version'])
     version_line = output.decode("utf-8")
-    version_num = re.split(' |\(', version_line)[3].split('.')[0]
+    version_num = re.split(r' |\(', version_line)[3].split('.')[0]
     return int(version_num)
 
 def parse_config(config, args):
-- 
2.39.2



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

* [Stable-8.1.3 10/55] tracetool: avoid invalid escape in Python string
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (8 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 09/55] tests/vm: " Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 11/55] linux-user: Fixes for zero_bss Michael Tokarev
                   ` (45 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Paolo Bonzini, Michael Tokarev

From: Paolo Bonzini <pbonzini@redhat.com>

This is an error in Python 3.12; fix it by using a raw string literal.

Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit e6d8e5e6e366ab4c9ed7d8ed1572f98c6ad6a38e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 33cf85e2b0..b29594d75e 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -210,12 +210,12 @@ class Event(object):
 
     """
 
-    _CRE = re.compile("((?P<props>[\w\s]+)\s+)?"
-                      "(?P<name>\w+)"
-                      "\((?P<args>[^)]*)\)"
-                      "\s*"
-                      "(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"
-                      "\s*")
+    _CRE = re.compile(r"((?P<props>[\w\s]+)\s+)?"
+                      r"(?P<name>\w+)"
+                      r"\((?P<args>[^)]*)\)"
+                      r"\s*"
+                      r"(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"
+                      r"\s*")
 
     _VALID_PROPS = set(["disable", "vcpu"])
 
@@ -326,7 +326,7 @@ def __repr__(self):
                                           fmt)
     # Star matching on PRI is dangerous as one might have multiple
     # arguments with that format, hence the non-greedy version of it.
-    _FMT = re.compile("(%[\d\.]*\w+|%.*?PRI\S+)")
+    _FMT = re.compile(r"(%[\d\.]*\w+|%.*?PRI\S+)")
 
     def formats(self):
         """List conversion specifiers in the argument print format string."""
diff --git a/scripts/tracetool/format/log_stap.py b/scripts/tracetool/format/log_stap.py
index 0b6549d534..b49afababd 100644
--- a/scripts/tracetool/format/log_stap.py
+++ b/scripts/tracetool/format/log_stap.py
@@ -83,7 +83,7 @@ def c_fmt_to_stap(fmt):
     # and "%ll" is not valid at all. Similarly the size_t
     # based "%z" size qualifier is not valid. We just
     # strip all size qualifiers for sanity.
-    fmt = re.sub("%(\d*)(l+|z)(x|u|d)", "%\\1\\3", "".join(bits))
+    fmt = re.sub(r"%(\d*)(l+|z)(x|u|d)", r"%\1\3", "".join(bits))
     return fmt
 
 def generate(events, backend, group):
-- 
2.39.2



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

* [Stable-8.1.3 11/55] linux-user: Fixes for zero_bss
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (9 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 10/55] tracetool: " Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 12/55] linux-user/mips: fix abort on integer overflow Michael Tokarev
                   ` (44 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Richard Henderson, Philippe Mathieu-Daudé,
	Michael Tokarev

From: Richard Henderson <richard.henderson@linaro.org>

The previous change, 2d385be6152, assumed !PAGE_VALID meant that
the page would be unmapped by the elf image.  However, since we
reserved the entire image space via mmap, PAGE_VALID will always
be set.  Instead, assume PROT_NONE for the same condition.

Furthermore, assume bss is only ever present for writable segments,
and that there is no page overlap between PT_LOAD segments.
Instead of an assert, return false to indicate failure.

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1854
Fixes: 2d385be6152 ("linux-user: Do not adjust zero_bss for host page size")
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit e6e66b03287331abc6f184456dbc6d25505590ec)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index a69e7d7eab..47170fe5d3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2217,31 +2217,58 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm,
  * Map and zero the bss.  We need to explicitly zero any fractional pages
  * after the data section (i.e. bss).  Return false on mapping failure.
  */
-static bool zero_bss(abi_ulong start_bss, abi_ulong end_bss, int prot)
+static bool zero_bss(abi_ulong start_bss, abi_ulong end_bss,
+                     int prot, Error **errp)
 {
     abi_ulong align_bss;
 
+    /* We only expect writable bss; the code segment shouldn't need this. */
+    if (!(prot & PROT_WRITE)) {
+        error_setg(errp, "PT_LOAD with non-writable bss");
+        return false;
+    }
+
     align_bss = TARGET_PAGE_ALIGN(start_bss);
     end_bss = TARGET_PAGE_ALIGN(end_bss);
 
     if (start_bss < align_bss) {
         int flags = page_get_flags(start_bss);
 
-        if (!(flags & PAGE_VALID)) {
-            /* Map the start of the bss. */
+        if (!(flags & PAGE_BITS)) {
+            /*
+             * The whole address space of the executable was reserved
+             * at the start, therefore all pages will be VALID.
+             * But assuming there are no PROT_NONE PT_LOAD segments,
+             * a PROT_NONE page means no data all bss, and we can
+             * simply extend the new anon mapping back to the start
+             * of the page of bss.
+             */
             align_bss -= TARGET_PAGE_SIZE;
-        } else if (flags & PAGE_WRITE) {
-            /* The page is already mapped writable. */
-            memset(g2h_untagged(start_bss), 0, align_bss - start_bss);
         } else {
-            /* Read-only zeros? */
-            g_assert_not_reached();
+            /*
+             * The start of the bss shares a page with something.
+             * The only thing that we expect is the data section,
+             * which would already be marked writable.
+             * Overlapping the RX code segment seems malformed.
+             */
+            if (!(flags & PAGE_WRITE)) {
+                error_setg(errp, "PT_LOAD with bss overlapping "
+                           "non-writable page");
+                return false;
+            }
+
+            /* The page is already mapped and writable. */
+            memset(g2h_untagged(start_bss), 0, align_bss - start_bss);
         }
     }
 
-    return align_bss >= end_bss ||
-           target_mmap(align_bss, end_bss - align_bss, prot,
-                       MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) != -1;
+    if (align_bss < end_bss &&
+        target_mmap(align_bss, end_bss - align_bss, prot,
+                    MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) == -1) {
+        error_setg_errno(errp, errno, "Error mapping bss");
+        return false;
+    }
+    return true;
 }
 
 #if defined(TARGET_ARM)
@@ -3265,8 +3292,8 @@ static void load_elf_image(const char *image_name, int image_fd,
 
             /* If the load segment requests extra zeros (e.g. bss), map it. */
             if (vaddr_ef < vaddr_em &&
-                !zero_bss(vaddr_ef, vaddr_em, elf_prot)) {
-                goto exit_mmap;
+                !zero_bss(vaddr_ef, vaddr_em, elf_prot, &err)) {
+                goto exit_errmsg;
             }
 
             /* Find the full program boundaries.  */
-- 
2.39.2



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

* [Stable-8.1.3 12/55] linux-user/mips: fix abort on integer overflow
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (10 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 11/55] linux-user: Fixes for zero_bss Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 13/55] linux-user/sh4: Fix crashes on signal delivery Michael Tokarev
                   ` (43 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Mikulas Patocka, Richard Henderson, Michael Tokarev

From: Mikulas Patocka <mpatocka@redhat.com>

QEMU mips userspace emulation crashes with "qemu: unhandled CPU exception
0x15 - aborting" when one of the integer arithmetic instructions detects
an overflow.

This patch fixes it so that it delivers SIGFPE with FPE_INTOVF instead.

Cc: qemu-stable@nongnu.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Message-Id: <3ef979a8-3ee1-eb2d-71f7-d788ff88dd11@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit 6fad9b4bb91dcc824f9c00a36ee843883b58313b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c
index 8735e58bad..990b03e727 100644
--- a/linux-user/mips/cpu_loop.c
+++ b/linux-user/mips/cpu_loop.c
@@ -180,7 +180,9 @@ done_syscall:
             }
             force_sig_fault(TARGET_SIGFPE, si_code, env->active_tc.PC);
             break;
-
+	case EXCP_OVERFLOW:
+            force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, env->active_tc.PC);
+            break;
         /* The code below was inspired by the MIPS Linux kernel trap
          * handling code in arch/mips/kernel/traps.c.
          */
-- 
2.39.2



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

* [Stable-8.1.3 13/55] linux-user/sh4: Fix crashes on signal delivery
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (11 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 12/55] linux-user/mips: fix abort on integer overflow Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 14/55] lasips2: LASI PS/2 devices are not user-createable Michael Tokarev
                   ` (42 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Mikulas Patocka, Yoshinori Sato, Richard Henderson,
	Michael Tokarev

From: Mikulas Patocka <mpatocka@redhat.com>

sh4 uses gUSA (general UserSpace Atomicity) to provide atomicity on CPUs
that don't have atomic instructions. A gUSA region that adds 1 to an
atomic variable stored in @R2 looks like this:

  4004b6:       03 c7           mova    4004c4 <gusa+0x10>,r0
  4004b8:       f3 61           mov     r15,r1
  4004ba:       09 00           nop
  4004bc:       fa ef           mov     #-6,r15
  4004be:       22 63           mov.l   @r2,r3
  4004c0:       01 73           add     #1,r3
  4004c2:       32 22           mov.l   r3,@r2
  4004c4:       13 6f           mov     r1,r15

R0 contains a pointer to the end of the gUSA region
R1 contains the saved stack pointer
R15 contains negative length of the gUSA region

When this region is interrupted by a signal, the kernel detects if
R15 >= -128U. If yes, the kernel rolls back PC to the beginning of the
region and restores SP by copying R1 to R15.

The problem happens if we are interrupted by a signal at address 4004c4.
R15 still holds the value -6, but the atomic value was already written by
an instruction at address 4004c2. In this situation we can't undo the
gUSA. The function unwind_gusa does nothing, the signal handler attempts
to push a signal frame to the address -6 and crashes.

This patch fixes it, so that if we are interrupted at the last instruction
in a gUSA region, we copy R1 to R15 to restore the correct stack pointer
and avoid crashing.

There's another bug: if we are interrupted in a delay slot, we save the
address of the instruction in the delay slot. We must save the address of
the previous instruction.

Cc: qemu-stable@nongnu.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Reviewed-by: Yoshinori Sato <ysato@users.sourcefoege.jp>
Message-Id: <b16389f7-6c62-70b7-59b3-87533c0bcc@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit 3b894b699c9a9c064466e128c18be80a3f2113bc)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c
index c4ba962708..c16c2c2d57 100644
--- a/linux-user/sh4/signal.c
+++ b/linux-user/sh4/signal.c
@@ -104,6 +104,14 @@ static void unwind_gusa(CPUSH4State *regs)
 
         /* Reset the SP to the saved version in R1.  */
         regs->gregs[15] = regs->gregs[1];
+    } else if (regs->gregs[15] >= -128u && regs->pc == regs->gregs[0]) {
+        /* If we are on the last instruction of a gUSA region, we must reset
+           the SP, otherwise we would be pushing the signal context to
+           invalid memory.  */
+        regs->gregs[15] = regs->gregs[1];
+    } else if (regs->flags & TB_FLAG_DELAY_SLOT) {
+        /* If we are in a delay slot, push the previous instruction.  */
+        regs->pc -= 2;
     }
 }
 
-- 
2.39.2



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

* [Stable-8.1.3 14/55] lasips2: LASI PS/2 devices are not user-createable
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (12 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 13/55] linux-user/sh4: Fix crashes on signal delivery Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 15/55] target/arm: Fix CNTPCT_EL0 trapping from EL0 when HCR_EL2.E2H is 0 Michael Tokarev
                   ` (41 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Helge Deller, Michael Tokarev

From: Helge Deller <deller@gmx.de>

Those PS/2 ports are created with the LASI controller when
a 32-bit PA-RISC machine is created.

Mark them not user-createable to avoid showing them in
the qemu device list.

Signed-off-by: Helge Deller <deller@gmx.de>
Cc: qemu-stable@nongnu.org
(cherry picked from commit a1e6a5c46219bada2c7b932748527553b36559ae)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/input/lasips2.c b/hw/input/lasips2.c
index ea7c07a2ba..6075121b72 100644
--- a/hw/input/lasips2.c
+++ b/hw/input/lasips2.c
@@ -351,6 +351,11 @@ static void lasips2_port_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
+    /*
+     * The PS/2 mouse port is integreal part of LASI and can not be
+     * created by users without LASI.
+     */
+    dc->user_creatable = false;
     dc->realize = lasips2_port_realize;
 }
 
@@ -397,6 +402,11 @@ static void lasips2_kbd_port_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     LASIPS2PortDeviceClass *lpdc = LASIPS2_PORT_CLASS(klass);
 
+    /*
+     * The PS/2 keyboard port is integreal part of LASI and can not be
+     * created by users without LASI.
+     */
+    dc->user_creatable = false;
     device_class_set_parent_realize(dc, lasips2_kbd_port_realize,
                                     &lpdc->parent_realize);
 }
-- 
2.39.2



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

* [Stable-8.1.3 15/55] target/arm: Fix CNTPCT_EL0 trapping from EL0 when HCR_EL2.E2H is 0
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (13 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 14/55] lasips2: LASI PS/2 devices are not user-createable Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 16/55] hw/sd/sdhci: Block Size Register bits [14:12] is lost Michael Tokarev
                   ` (40 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Michal Orzel, Oleksandr Tyshchenko, Peter Maydell,
	Michael Tokarev

From: Michal Orzel <michal.orzel@amd.com>

On an attempt to access CNTPCT_EL0 from EL0 using a guest running on top
of Xen, a trap from EL2 was observed which is something not reproducible
on HW (also, Xen does not trap accesses to physical counter).

This is because gt_counter_access() checks for an incorrect bit (1
instead of 0) of CNTHCTL_EL2 if HCR_EL2.E2H is 0 and access is made to
physical counter. Refer ARM ARM DDI 0487J.a, D19.12.2:
When HCR_EL2.E2H is 0:
 - EL1PCTEN, bit [0]: refers to physical counter
 - EL1PCEN, bit [1]: refers to physical timer registers

Drop entire block "if (hcr & HCR_E2H) {...} else {...}" from EL0 case
and fall through to EL1 case, given that after fixing checking for the
correct bit, the handling is the same.

Fixes: 5bc8437136fb ("target/arm: Update timer access for VHE")
Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Tested-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Message-id: 20230928094404.20802-1-michal.orzel@amd.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
(cherry picked from commit d01448c79d89cfdc86228081b1dd1dfaf85fb4c3)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/arm/helper.c b/target/arm/helper.c
index 50f61e42ca..f66b610bdd 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -2475,22 +2475,7 @@ static CPAccessResult gt_counter_access(CPUARMState *env, int timeridx,
         if (!extract32(env->cp15.c14_cntkctl, timeridx, 1)) {
             return CP_ACCESS_TRAP;
         }
-
-        /* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PCTEN. */
-        if (hcr & HCR_E2H) {
-            if (timeridx == GTIMER_PHYS &&
-                !extract32(env->cp15.cnthctl_el2, 10, 1)) {
-                return CP_ACCESS_TRAP_EL2;
-            }
-        } else {
-            /* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */
-            if (has_el2 && timeridx == GTIMER_PHYS &&
-                !extract32(env->cp15.cnthctl_el2, 1, 1)) {
-                return CP_ACCESS_TRAP_EL2;
-            }
-        }
-        break;
-
+        /* fall through */
     case 1:
         /* Check CNTHCTL_EL2.EL1PCTEN, which changes location based on E2H. */
         if (has_el2 && timeridx == GTIMER_PHYS &&
-- 
2.39.2



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

* [Stable-8.1.3 16/55] hw/sd/sdhci: Block Size Register bits [14:12] is lost
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (14 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 15/55] target/arm: Fix CNTPCT_EL0 trapping from EL0 when HCR_EL2.E2H is 0 Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 17/55] hw/rdma/vmw/pvrdma_cmd: Use correct struct in query_port() Michael Tokarev
                   ` (39 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Lu Gao, Jianxian Wen, Philippe Mathieu-Daudé,
	Philippe Mathieu-Daudé, Michael Tokarev

From: Lu Gao <lu.gao@verisilicon.com>

Block Size Register bits [14:12] is SDMA Buffer Boundary, it is missed
in register write, but it is needed in SDMA transfer. e.g. it will be
used in sdhci_sdma_transfer_multi_blocks to calculate boundary_ variables.

Missing this field will cause wrong operation for different SDMA Buffer
Boundary settings.

Fixes: d7dfca0807 ("hw/sdhci: introduce standard SD host controller")
Fixes: dfba99f17f ("hw/sdhci: Fix DMA Transfer Block Size field")
Signed-off-by: Lu Gao <lu.gao@verisilicon.com>
Signed-off-by: Jianxian Wen <jianxian.wen@verisilicon.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-ID: <20220321055618.4026-1-lu.gao@verisilicon.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit ae5f70baf549925080fcdbc6c1939c98a4a39246)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 362c2c86aa..1bf89a1155 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -321,6 +321,8 @@ static void sdhci_poweron_reset(DeviceState *dev)
 
 static void sdhci_data_transfer(void *opaque);
 
+#define BLOCK_SIZE_MASK (4 * KiB - 1)
+
 static void sdhci_send_command(SDHCIState *s)
 {
     SDRequest request;
@@ -371,7 +373,8 @@ static void sdhci_send_command(SDHCIState *s)
 
     sdhci_update_irq(s);
 
-    if (!timeout && s->blksize && (s->cmdreg & SDHC_CMD_DATA_PRESENT)) {
+    if (!timeout && (s->blksize & BLOCK_SIZE_MASK) &&
+        (s->cmdreg & SDHC_CMD_DATA_PRESENT)) {
         s->data_count = 0;
         sdhci_data_transfer(s);
     }
@@ -406,7 +409,6 @@ static void sdhci_end_transfer(SDHCIState *s)
 /*
  * Programmed i/o data transfer
  */
-#define BLOCK_SIZE_MASK (4 * KiB - 1)
 
 /* Fill host controller's read buffer with BLKSIZE bytes of data from card */
 static void sdhci_read_block_from_card(SDHCIState *s)
@@ -1154,7 +1156,8 @@ sdhci_write(void *opaque, hwaddr offset, uint64_t val, unsigned size)
             s->sdmasysad = (s->sdmasysad & mask) | value;
             MASKED_WRITE(s->sdmasysad, mask, value);
             /* Writing to last byte of sdmasysad might trigger transfer */
-            if (!(mask & 0xFF000000) && s->blkcnt && s->blksize &&
+            if (!(mask & 0xFF000000) && s->blkcnt &&
+                (s->blksize & BLOCK_SIZE_MASK) &&
                 SDHC_DMA_TYPE(s->hostctl1) == SDHC_CTRL_SDMA) {
                 if (s->trnmod & SDHC_TRNS_MULTI) {
                     sdhci_sdma_transfer_multi_blocks(s);
@@ -1168,7 +1171,11 @@ sdhci_write(void *opaque, hwaddr offset, uint64_t val, unsigned size)
         if (!TRANSFERRING_DATA(s->prnsts)) {
             uint16_t blksize = s->blksize;
 
-            MASKED_WRITE(s->blksize, mask, extract32(value, 0, 12));
+            /*
+             * [14:12] SDMA Buffer Boundary
+             * [11:00] Transfer Block Size
+             */
+            MASKED_WRITE(s->blksize, mask, extract32(value, 0, 15));
             MASKED_WRITE(s->blkcnt, mask >> 16, value >> 16);
 
             /* Limit block size to the maximum buffer size */
-- 
2.39.2



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

* [Stable-8.1.3 17/55] hw/rdma/vmw/pvrdma_cmd: Use correct struct in query_port()
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (15 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 16/55] hw/sd/sdhci: Block Size Register bits [14:12] is lost Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 18/55] target/sparc: Clear may_lookup for npc == DYNAMIC_PC Michael Tokarev
                   ` (38 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Peter Maydell, Michael Tokarev

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

In query_port() we pass the address of a local pvrdma_port_attr
struct to the rdma_query_backend_port() function.  Unfortunately,
rdma_backend_query_port() wants a pointer to a struct ibv_port_attr,
and the two are not the same length.

Coverity spotted this (CID 1507146): pvrdma_port_attr is 48 bytes
long, and ibv_port_attr is 52 bytes, because it has a few extra
fields at the end.

Fortunately, all we do with the attrs struct after the call is to
read a few specific fields out of it which are all at the same
offsets in both structs, so we can simply make the local variable the
correct type.  This also lets us drop the cast (which should have
been a bit of a warning flag that we were doing something wrong
here).

We do however need to add extra casts for the fields of the
struct that are enums: clang will complain about the implicit
cast to a different enum type otherwise.

Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
(cherry picked from commit 4ab9a7429bf7507fba4b96b97d4147628c91ba14)

diff --git a/hw/rdma/vmw/pvrdma_cmd.c b/hw/rdma/vmw/pvrdma_cmd.c
index c6ed025982..d385d18d9c 100644
--- a/hw/rdma/vmw/pvrdma_cmd.c
+++ b/hw/rdma/vmw/pvrdma_cmd.c
@@ -129,23 +129,27 @@ static int query_port(PVRDMADev *dev, union pvrdma_cmd_req *req,
 {
     struct pvrdma_cmd_query_port *cmd = &req->query_port;
     struct pvrdma_cmd_query_port_resp *resp = &rsp->query_port_resp;
-    struct pvrdma_port_attr attrs = {};
+    struct ibv_port_attr attrs = {};
 
     if (cmd->port_num > MAX_PORTS) {
         return -EINVAL;
     }
 
-    if (rdma_backend_query_port(&dev->backend_dev,
-                                (struct ibv_port_attr *)&attrs)) {
+    if (rdma_backend_query_port(&dev->backend_dev, &attrs)) {
         return -ENOMEM;
     }
 
     memset(resp, 0, sizeof(*resp));
 
-    resp->attrs.state = dev->func0->device_active ? attrs.state :
-                                                    PVRDMA_PORT_DOWN;
-    resp->attrs.max_mtu = attrs.max_mtu;
-    resp->attrs.active_mtu = attrs.active_mtu;
+    /*
+     * The state, max_mtu and active_mtu fields are enums; the values
+     * for pvrdma_port_state and pvrdma_mtu match those for
+     * ibv_port_state and ibv_mtu, so we can cast them safely.
+     */
+    resp->attrs.state = dev->func0->device_active ?
+        (enum pvrdma_port_state)attrs.state : PVRDMA_PORT_DOWN;
+    resp->attrs.max_mtu = (enum pvrdma_mtu)attrs.max_mtu;
+    resp->attrs.active_mtu = (enum pvrdma_mtu)attrs.active_mtu;
     resp->attrs.phys_state = attrs.phys_state;
     resp->attrs.gid_tbl_len = MIN(MAX_PORT_GIDS, attrs.gid_tbl_len);
     resp->attrs.max_msg_sz = 1024;
-- 
2.39.2



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

* [Stable-8.1.3 18/55] target/sparc: Clear may_lookup for npc == DYNAMIC_PC
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (16 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 17/55] hw/rdma/vmw/pvrdma_cmd: Use correct struct in query_port() Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 19/55] target/arm: Fix syndrome for FGT traps on ERET Michael Tokarev
                   ` (37 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Richard Henderson, Mark Cave-Ayland, Michael Tokarev

From: Richard Henderson <richard.henderson@linaro.org>

With pairs of jmp+rett, pc == DYNAMIC_PC_LOOKUP and
npc == DYNAMIC_PC.  Make sure that we exit for interrupts.

Cc: qemu-stable@nongnu.org
Fixes: 633c42834c7 ("target/sparc: Introduce DYNAMIC_PC_LOOKUP")
Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit 930f1865cc654b637ffe1207fa5b44bf0a156279)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/sparc/translate.c b/target/sparc/translate.c
index bd877a5e4a..9074a90818 100644
--- a/target/sparc/translate.c
+++ b/target/sparc/translate.c
@@ -5664,10 +5664,10 @@ static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
             break;
         }
 
+        may_lookup = true;
         if (dc->pc & 3) {
             switch (dc->pc) {
             case DYNAMIC_PC_LOOKUP:
-                may_lookup = true;
                 break;
             case DYNAMIC_PC:
                 may_lookup = false;
@@ -5677,10 +5677,24 @@ static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
             }
         } else {
             tcg_gen_movi_tl(cpu_pc, dc->pc);
-            may_lookup = true;
         }
 
-        save_npc(dc);
+        if (dc->npc & 3) {
+            switch (dc->npc) {
+            case JUMP_PC:
+                gen_generic_branch(dc);
+                break;
+            case DYNAMIC_PC:
+                may_lookup = false;
+                break;
+            case DYNAMIC_PC_LOOKUP:
+                break;
+            default:
+                g_assert_not_reached();
+            }
+        } else {
+            tcg_gen_movi_tl(cpu_npc, dc->npc);
+        }
         if (may_lookup) {
             tcg_gen_lookup_and_goto_ptr();
         } else {
-- 
2.39.2



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

* [Stable-8.1.3 19/55] target/arm: Fix syndrome for FGT traps on ERET
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (17 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 18/55] target/sparc: Clear may_lookup for npc == DYNAMIC_PC Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 20/55] misc/led: LED state is set opposite of what is expected Michael Tokarev
                   ` (36 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Peter Maydell, Richard Henderson, Michael Tokarev

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

In commit 442c9d682c94fc2 when we converted the ERET, ERETAA, ERETAB
instructions to decodetree, the conversion accidentally lost the
correct setting of the syndrome register when taking a trap because
of the FEAT_FGT HFGITR_EL1.ERET bit.  Instead of reporting a correct
full syndrome value with the EC and IL bits, we only reported the low
two bits of the syndrome, because the call to syn_erettrap() got
dropped.

Fix the syndrome values for these traps by reinstating the
syn_erettrap() calls.

Fixes: 442c9d682c94fc2 ("target/arm: Convert ERET, ERETAA, ERETAB to decodetree")
Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20231024172438.2990945-1-peter.maydell@linaro.org
(cherry picked from commit 307521d6e29e559c89afa9dbd337ae75fe3c436d)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
index 5fa1257d32..58787ee8a7 100644
--- a/target/arm/tcg/translate-a64.c
+++ b/target/arm/tcg/translate-a64.c
@@ -1627,7 +1627,7 @@ static bool trans_ERET(DisasContext *s, arg_ERET *a)
         return false;
     }
     if (s->fgt_eret) {
-        gen_exception_insn_el(s, 0, EXCP_UDEF, 0, 2);
+        gen_exception_insn_el(s, 0, EXCP_UDEF, syn_erettrap(0), 2);
         return true;
     }
     dst = tcg_temp_new_i64();
@@ -1654,7 +1654,7 @@ static bool trans_ERETA(DisasContext *s, arg_reta *a)
     }
     /* The FGT trap takes precedence over an auth trap. */
     if (s->fgt_eret) {
-        gen_exception_insn_el(s, 0, EXCP_UDEF, a->m ? 3 : 2, 2);
+        gen_exception_insn_el(s, 0, EXCP_UDEF, syn_erettrap(a->m ? 3 : 2), 2);
         return true;
     }
     dst = tcg_temp_new_i64();
-- 
2.39.2



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

* [Stable-8.1.3 20/55] misc/led: LED state is set opposite of what is expected
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (18 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 19/55] target/arm: Fix syndrome for FGT traps on ERET Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 21/55] block: Fix locking in media change monitor commands Michael Tokarev
                   ` (35 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Glenn Miles, Peter Maydell, Andrew Jeffery,
	Philippe Mathieu-Daudé, Michael Tokarev

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

Testing of the LED state showed that when the LED polarity was
set to GPIO_POLARITY_ACTIVE_LOW and a low logic value was set on
the input GPIO of the LED, the LED was being turn off when it was
expected to be turned on.

Fixes: ddb67f6402 ("hw/misc/led: Allow connecting from GPIO output")
Signed-off-by: Glenn Miles <milesg@linux.vnet.ibm.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Andrew Jeffery <andrew@codeconstruct.com.au>
Message-id: 20231024191945.4135036-1-milesg@linux.vnet.ibm.com
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
(cherry picked from commit 6f83dc67168d17856744275e2a0d7a6addf6cfb9)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/misc/led.c b/hw/misc/led.c
index f6d6d68bce..42bb43a39a 100644
--- a/hw/misc/led.c
+++ b/hw/misc/led.c
@@ -63,7 +63,7 @@ static void led_set_state_gpio_handler(void *opaque, int line, int new_state)
     LEDState *s = LED(opaque);
 
     assert(line == 0);
-    led_set_state(s, !!new_state != s->gpio_active_high);
+    led_set_state(s, !!new_state == s->gpio_active_high);
 }
 
 static void led_reset(DeviceState *dev)
-- 
2.39.2



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

* [Stable-8.1.3 21/55] block: Fix locking in media change monitor commands
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (19 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 20/55] misc/led: LED state is set opposite of what is expected Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 22/55] tests/tcg: Add -fno-stack-protector Michael Tokarev
                   ` (34 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Kevin Wolf, Hanna Czenczek, Michael Tokarev

From: Kevin Wolf <kwolf@redhat.com>

blk_insert_bs() requires that the caller holds the AioContext lock for
the node to be inserted. Since commit c066e808e11, neglecting to do so
causes a crash when the child has to be moved to a different AioContext
to attach it to the BlockBackend.

This fixes qmp_blockdev_insert_anon_medium(), which is called for the
QMP commands 'blockdev-insert-medium' and 'blockdev-change-medium', to
correctly take the lock.

Cc: qemu-stable@nongnu.org
Fixes: https://issues.redhat.com/browse/RHEL-3922
Fixes: c066e808e11a5c181b625537b6c78e0de27a4801
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20231013153302.39234-2-kwolf@redhat.com>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit fed824501501518b1ad3dc08a39f8f855508190d)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c
index ef07151892..305225db32 100644
--- a/block/qapi-sysemu.c
+++ b/block/qapi-sysemu.c
@@ -232,6 +232,7 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
                                             BlockDriverState *bs, Error **errp)
 {
     Error *local_err = NULL;
+    AioContext *ctx;
     bool has_device;
     int ret;
 
@@ -253,7 +254,11 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
         return;
     }
 
+    ctx = bdrv_get_aio_context(bs);
+    aio_context_acquire(ctx);
     ret = blk_insert_bs(blk, bs, errp);
+    aio_context_release(ctx);
+
     if (ret < 0) {
         return;
     }
-- 
2.39.2



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

* [Stable-8.1.3 22/55] tests/tcg: Add -fno-stack-protector
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (20 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 21/55] block: Fix locking in media change monitor commands Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 23/55] qemu-img: rebase: stop when reaching EOF of old backing file Michael Tokarev
                   ` (33 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Akihiko Odaki, Richard Henderson, Alex Bennée,
	Michael Tokarev

From: Akihiko Odaki <akihiko.odaki@daynix.com>

A build of GCC 13.2 will have stack protector enabled by default if it
was configured with --enable-default-ssp option. For such a compiler,
it is necessary to explicitly disable stack protector when linking
without standard libraries.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-Id: <20230731091042.139159-3-akihiko.odaki@daynix.com>
[AJB: fix comment string typo]
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20231029145033.592566-3-alex.bennee@linaro.org>
(cherry picked from commit 580731dcc87eb27a2b0dc20ec331f1ce51864c97)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target
index 462289f47c..9606eacf0a 100644
--- a/tests/tcg/Makefile.target
+++ b/tests/tcg/Makefile.target
@@ -123,7 +123,7 @@ else
 # For softmmu targets we include a different Makefile fragment as the
 # build options for bare programs are usually pretty different. They
 # are expected to provide their own build recipes.
-EXTRA_CFLAGS += -ffreestanding
+EXTRA_CFLAGS += -ffreestanding -fno-stack-protector
 -include $(SRC_PATH)/tests/tcg/minilib/Makefile.target
 -include $(SRC_PATH)/tests/tcg/multiarch/system/Makefile.softmmu-target
 -include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
index 681dfa077c..49e1ffea93 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -49,7 +49,7 @@ endif
 # bti-1 tests the elf notes, so we require special compiler support.
 ifneq ($(CROSS_CC_HAS_ARMV8_BTI),)
 AARCH64_TESTS += bti-1 bti-3
-bti-1 bti-3: CFLAGS += -mbranch-protection=standard
+bti-1 bti-3: CFLAGS += -fno-stack-protector -mbranch-protection=standard
 bti-1 bti-3: LDFLAGS += -nostdlib
 endif
 # bti-2 tests PROT_BTI, so no special compiler support required.
diff --git a/tests/tcg/arm/Makefile.target b/tests/tcg/arm/Makefile.target
index 0038cef02c..3473f4619e 100644
--- a/tests/tcg/arm/Makefile.target
+++ b/tests/tcg/arm/Makefile.target
@@ -12,7 +12,7 @@ float_madds: CFLAGS+=-mfpu=neon-vfpv4
 
 # Basic Hello World
 ARM_TESTS = hello-arm
-hello-arm: CFLAGS+=-marm -ffreestanding
+hello-arm: CFLAGS+=-marm -ffreestanding -fno-stack-protector
 hello-arm: LDFLAGS+=-nostdlib
 
 # IWMXT floating point extensions
diff --git a/tests/tcg/cris/Makefile.target b/tests/tcg/cris/Makefile.target
index 43587d2769..713e2a5b6c 100644
--- a/tests/tcg/cris/Makefile.target
+++ b/tests/tcg/cris/Makefile.target
@@ -30,7 +30,7 @@ AS	= $(CC) -x assembler-with-cpp
 LD      = $(CC)
 
 # we rely on GCC inline:ing the stuff we tell it to in many places here.
-CFLAGS  = -Winline -Wall -g -O2 -static
+CFLAGS  = -Winline -Wall -g -O2 -static -fno-stack-protector
 NOSTDFLAGS = -nostartfiles -nostdlib
 ASFLAGS += -mcpu=v10 -g -Wa,-I,$(SRC_PATH)/tests/tcg/cris/bare
 CRT_FILES = crt.o sys.o
diff --git a/tests/tcg/hexagon/Makefile.target b/tests/tcg/hexagon/Makefile.target
index 87ed2c90b9..f839b2c0d5 100644
--- a/tests/tcg/hexagon/Makefile.target
+++ b/tests/tcg/hexagon/Makefile.target
@@ -19,7 +19,7 @@
 EXTRA_RUNS =
 
 CFLAGS += -Wno-incompatible-pointer-types -Wno-undefined-internal
-CFLAGS += -fno-unroll-loops
+CFLAGS += -fno-unroll-loops -fno-stack-protector
 
 HEX_SRC=$(SRC_PATH)/tests/tcg/hexagon
 VPATH += $(HEX_SRC)
diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target
index fdf757c6ce..3dec7c6c42 100644
--- a/tests/tcg/i386/Makefile.target
+++ b/tests/tcg/i386/Makefile.target
@@ -35,7 +35,7 @@ run-test-aes: QEMU_OPTS += -cpu max
 #
 # hello-i386 is a barebones app
 #
-hello-i386: CFLAGS+=-ffreestanding
+hello-i386: CFLAGS+=-ffreestanding -fno-stack-protector
 hello-i386: LDFLAGS+=-nostdlib
 
 # test-386 includes a couple of additional objects that need to be
diff --git a/tests/tcg/minilib/Makefile.target b/tests/tcg/minilib/Makefile.target
index c821d2806a..af0bf54be9 100644
--- a/tests/tcg/minilib/Makefile.target
+++ b/tests/tcg/minilib/Makefile.target
@@ -12,7 +12,7 @@ SYSTEM_MINILIB_SRC=$(SRC_PATH)/tests/tcg/minilib
 MINILIB_SRCS=$(wildcard $(SYSTEM_MINILIB_SRC)/*.c)
 MINILIB_OBJS=$(patsubst $(SYSTEM_MINILIB_SRC)/%.c, %.o, $(MINILIB_SRCS))
 
-MINILIB_CFLAGS+=-nostdlib -ggdb -O0
+MINILIB_CFLAGS+=-nostdlib -fno-stack-protector -ggdb -O0
 MINILIB_INC=-isystem $(SYSTEM_MINILIB_SRC)
 
 .PRECIOUS: $(MINILIB_OBJS)
diff --git a/tests/tcg/mips/Makefile.target b/tests/tcg/mips/Makefile.target
index 1a994d5525..5d17c1706e 100644
--- a/tests/tcg/mips/Makefile.target
+++ b/tests/tcg/mips/Makefile.target
@@ -14,6 +14,6 @@ MIPS_TESTS=hello-mips
 
 TESTS += $(MIPS_TESTS)
 
-hello-mips: CFLAGS+=-mno-abicalls -fno-PIC -mabi=32
+hello-mips: CFLAGS+=-mno-abicalls -fno-PIC -fno-stack-protector -mabi=32
 hello-mips: LDFLAGS+=-nostdlib
 endif
diff --git a/tests/tcg/mips/hello-mips.c b/tests/tcg/mips/hello-mips.c
index 4e1cf501af..38e22d00e3 100644
--- a/tests/tcg/mips/hello-mips.c
+++ b/tests/tcg/mips/hello-mips.c
@@ -5,8 +5,8 @@
 * http://www.linux-mips.org/wiki/MIPSABIHistory
 * http://www.linux.com/howtos/Assembly-HOWTO/mips.shtml
 *
-* mipsel-linux-gcc -nostdlib -mno-abicalls -fno-PIC -mabi=32 \
-*                  -O2 -static -o hello-mips hello-mips.c
+* mipsel-linux-gcc -nostdlib -mno-abicalls -fno-PIC -fno-stack-protector \
+*                  -mabi=32 -O2 -static -o hello-mips hello-mips.c
 *
 */
 #define __NR_SYSCALL_BASE	4000
-- 
2.39.2



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

* [Stable-8.1.3 23/55] qemu-img: rebase: stop when reaching EOF of old backing file
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (21 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 22/55] tests/tcg: Add -fno-stack-protector Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 24/55] qemu-iotests: 024: add rebasing test case for overlay_size > backing_size Michael Tokarev
                   ` (32 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Andrey Drobyshev, Denis V . Lunev, Hanna Czenczek,
	Kevin Wolf, Michael Tokarev

From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>

In case when we're rebasing within one backing chain, and when target image
is larger than old backing file, bdrv_is_allocated_above() ends up setting
*pnum = 0.  As a result, target offset isn't getting incremented, and we
get stuck in an infinite for loop.  Let's detect this case and proceed
further down the loop body, as the offsets beyond the old backing size need
to be explicitly zeroed.

Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Message-ID: <20230919165804.439110-2-andrey.drobyshev@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 8b097fd6b06ec295faefd4f30f96f8709abc9605)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/qemu-img.c b/qemu-img.c
index 27f48051b0..78433f3746 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3801,6 +3801,8 @@ static int img_rebase(int argc, char **argv)
             }
 
             if (prefix_chain_bs) {
+                uint64_t bytes = n;
+
                 /*
                  * If cluster wasn't changed since prefix_chain, we don't need
                  * to take action
@@ -3813,9 +3815,18 @@ static int img_rebase(int argc, char **argv)
                                  strerror(-ret));
                     goto out;
                 }
-                if (!ret) {
+                if (!ret && n) {
                     continue;
                 }
+                if (!n) {
+                    /*
+                     * If we've reached EOF of the old backing, it means that
+                     * offsets beyond the old backing size were read as zeroes.
+                     * Now we will need to explicitly zero the cluster in
+                     * order to preserve that state after the rebase.
+                     */
+                    n = bytes;
+                }
             }
 
             /*
-- 
2.39.2



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

* [Stable-8.1.3 24/55] qemu-iotests: 024: add rebasing test case for overlay_size > backing_size
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (22 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 23/55] qemu-img: rebase: stop when reaching EOF of old backing file Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 25/55] target/arm: Fix SVE STR increment Michael Tokarev
                   ` (31 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Andrey Drobyshev, Denis V . Lunev, Hanna Czenczek,
	Kevin Wolf, Michael Tokarev

From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>

Before previous commit, rebase was getting infitely stuck in case of
rebasing within the same backing chain and when overlay_size > backing_size.
Let's add this case to the rebasing test 024 to make sure it doesn't
break again.

Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Message-ID: <20230919165804.439110-3-andrey.drobyshev@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 827171c3180533f4ad0bc338ea166f401bb5d348)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/qemu-iotests/024 b/tests/qemu-iotests/024
index 25a564a150..98a7c8fd65 100755
--- a/tests/qemu-iotests/024
+++ b/tests/qemu-iotests/024
@@ -199,6 +199,63 @@ echo
 # $BASE_OLD and $BASE_NEW)
 $QEMU_IMG map "$OVERLAY" | _filter_qemu_img_map
 
+# Check that rebase within the chain is working when
+# overlay_size > old_backing_size
+#
+# base_new <-- base_old <-- overlay
+#
+# Backing (new): 11 11 11 11 11
+# Backing (old): 22 22 22 22
+# Overlay:       -- -- -- -- --
+#
+# As a result, overlay should contain data identical to base_old, with the
+# last cluster remaining unallocated.
+
+echo
+echo "=== Test rebase within one backing chain ==="
+echo
+
+echo "Creating backing chain"
+echo
+
+TEST_IMG=$BASE_NEW _make_test_img $(( CLUSTER_SIZE * 5 ))
+TEST_IMG=$BASE_OLD _make_test_img -b "$BASE_NEW" -F $IMGFMT \
+    $(( CLUSTER_SIZE * 4 ))
+TEST_IMG=$OVERLAY _make_test_img -b "$BASE_OLD" -F $IMGFMT \
+    $(( CLUSTER_SIZE * 5 ))
+
+echo
+echo "Fill backing files with data"
+echo
+
+$QEMU_IO "$BASE_NEW" -c "write -P 0x11 0 $(( CLUSTER_SIZE * 5 ))" \
+    | _filter_qemu_io
+$QEMU_IO "$BASE_OLD" -c "write -P 0x22 0 $(( CLUSTER_SIZE * 4 ))" \
+    | _filter_qemu_io
+
+echo
+echo "Check the last cluster is zeroed in overlay before the rebase"
+echo
+$QEMU_IO "$OVERLAY" -c "read -P 0x00 $(( CLUSTER_SIZE * 4 )) $CLUSTER_SIZE" \
+    | _filter_qemu_io
+
+echo
+echo "Rebase onto another image in the same chain"
+echo
+
+$QEMU_IMG rebase -b "$BASE_NEW" -F $IMGFMT "$OVERLAY"
+
+echo "Verify that data is read the same before and after rebase"
+echo
+
+# Verify the first 4 clusters are still read the same as in the old base
+$QEMU_IO "$OVERLAY" -c "read -P 0x22 0 $(( CLUSTER_SIZE * 4 ))" \
+    | _filter_qemu_io
+# Verify the last cluster still reads as zeroes
+$QEMU_IO "$OVERLAY" -c "read -P 0x00 $(( CLUSTER_SIZE * 4 )) $CLUSTER_SIZE" \
+    | _filter_qemu_io
+
+echo
 
 # success, all done
 echo "*** done"
diff --git a/tests/qemu-iotests/024.out b/tests/qemu-iotests/024.out
index 973a5a3711..245fe8b1d1 100644
--- a/tests/qemu-iotests/024.out
+++ b/tests/qemu-iotests/024.out
@@ -171,4 +171,34 @@ read 65536/65536 bytes at offset 196608
 Offset          Length          File
 0               0x30000         TEST_DIR/subdir/t.IMGFMT
 0x30000         0x10000         TEST_DIR/subdir/t.IMGFMT.base_new
+
+=== Test rebase within one backing chain ===
+
+Creating backing chain
+
+Formatting 'TEST_DIR/subdir/t.IMGFMT.base_new', fmt=IMGFMT size=327680
+Formatting 'TEST_DIR/subdir/t.IMGFMT.base_old', fmt=IMGFMT size=262144 backing_file=TEST_DIR/subdir/t.IMGFMT.base_new backing_fmt=IMGFMT
+Formatting 'TEST_DIR/subdir/t.IMGFMT', fmt=IMGFMT size=327680 backing_file=TEST_DIR/subdir/t.IMGFMT.base_old backing_fmt=IMGFMT
+
+Fill backing files with data
+
+wrote 327680/327680 bytes at offset 0
+320 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+wrote 262144/262144 bytes at offset 0
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+Check the last cluster is zeroed in overlay before the rebase
+
+read 65536/65536 bytes at offset 262144
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+Rebase onto another image in the same chain
+
+Verify that data is read the same before and after rebase
+
+read 262144/262144 bytes at offset 0
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+read 65536/65536 bytes at offset 262144
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
 *** done
-- 
2.39.2



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

* [Stable-8.1.3 25/55] target/arm: Fix SVE STR increment
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (23 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 24/55] qemu-iotests: 024: add rebasing test case for overlay_size > backing_size Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 26/55] target/arm: Correctly propagate stage 1 BTI guarded bit in a two-stage walk Michael Tokarev
                   ` (30 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Richard Henderson, Philippe Mathieu-Daudé,
	Peter Maydell, Michael Tokarev, Alex Bennée

From: Richard Henderson <richard.henderson@linaro.org>

The previous change missed updating one of the increments and
one of the MemOps.  Add a test case for all vector lengths.

Cc: qemu-stable@nongnu.org
Fixes: e6dd5e782be ("target/arm: Use tcg_gen_qemu_{ld, st}_i128 in gen_sve_{ld, st}r")
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20231031143215.29764-1-richard.henderson@linaro.org
[PMM: fixed checkpatch nit]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
(cherry picked from commit b11293c212c2927fcea1befc50dabec9baba4fcc)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
(Mjt: context fix in tests/tcg/aarch64/Makefile.target)
Tested-by: Alex Bennée <alex.bennee@linaro.org>

diff --git a/target/arm/tcg/translate-sve.c b/target/arm/tcg/translate-sve.c
index 2ba5efadfd..90865d8696 100644
--- a/target/arm/tcg/translate-sve.c
+++ b/target/arm/tcg/translate-sve.c
@@ -4294,7 +4294,7 @@ void gen_sve_str(DisasContext *s, TCGv_ptr base, int vofs,
         t0 = tcg_temp_new_i64();
         t1 = tcg_temp_new_i64();
         t16 = tcg_temp_new_i128();
-        for (i = 0; i < len_align; i += 8) {
+        for (i = 0; i < len_align; i += 16) {
             tcg_gen_ld_i64(t0, base, vofs + i);
             tcg_gen_ld_i64(t1, base, vofs + i + 8);
             tcg_gen_concat_i64_i128(t16, t0, t1);
@@ -4320,7 +4320,8 @@ void gen_sve_str(DisasContext *s, TCGv_ptr base, int vofs,
         t16 = tcg_temp_new_i128();
         tcg_gen_concat_i64_i128(t16, t0, t1);
 
-        tcg_gen_qemu_st_i128(t16, clean_addr, midx, MO_LEUQ);
+        tcg_gen_qemu_st_i128(t16, clean_addr, midx,
+                             MO_LE | MO_128 | MO_ATOM_NONE);
         tcg_gen_addi_i64(clean_addr, clean_addr, 16);
 
         tcg_gen_brcondi_ptr(TCG_COND_LTU, i, len_align, loop);
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
index 49e1ffea93..6c2a6d6206 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -100,7 +100,11 @@ sha512-sve: CFLAGS=-O3 -march=armv8.1-a+sve
 sha512-sve: sha512.c
 	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
 
-TESTS += sha512-sve
+sve-str: CFLAGS=-O1 -march=armv8.1-a+sve
+sve-str: sve-str.c
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
+
+TESTS += sha512-sve sve-str
 endif
 
 ifeq ($(HOST_GDB_SUPPORTS_ARCH),y)
diff --git a/tests/tcg/aarch64/sve-str.c b/tests/tcg/aarch64/sve-str.c
new file mode 100644
index 0000000000..ae271c9d87
--- /dev/null
+++ b/tests/tcg/aarch64/sve-str.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <sys/prctl.h>
+
+#define N  (256 + 16)
+
+static int __attribute__((noinline)) test(int vl)
+{
+    unsigned char buf[N];
+    int err = 0;
+
+    for (int i = 0; i < N; ++i) {
+        buf[i] = (unsigned char)i;
+    }
+
+    asm volatile (
+        "mov z0.b, #255\n\t"
+        "str z0, %0"
+        : : "m" (buf) : "z0", "memory");
+
+    for (int i = 0; i < vl; ++i) {
+        if (buf[i] != 0xff) {
+            fprintf(stderr, "vl %d, index %d, expected 255, got %d\n",
+                    vl, i, buf[i]);
+            err = 1;
+        }
+    }
+
+    for (int i = vl; i < N; ++i) {
+        if (buf[i] != (unsigned char)i) {
+            fprintf(stderr, "vl %d, index %d, expected %d, got %d\n",
+                    vl, i, (unsigned char)i, buf[i]);
+            err = 1;
+        }
+    }
+
+    return err;
+}
+
+int main()
+{
+    int err = 0;
+
+    for (int i = 16; i <= 256; i += 16) {
+        if (prctl(PR_SVE_SET_VL, i, 0, 0, 0, 0) == i) {
+            err |= test(i);
+        }
+    }
+    return err;
+}
-- 
2.39.2



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

* [Stable-8.1.3 26/55] target/arm: Correctly propagate stage 1 BTI guarded bit in a two-stage walk
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (24 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 25/55] target/arm: Fix SVE STR increment Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 27/55] util/uuid: Add UUID_STR_LEN definition Michael Tokarev
                   ` (29 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Peter Maydell, Richard Henderson, Michael Tokarev

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

In a two-stage translation, the result of the BTI guarded bit should
be the guarded bit from the first stage of translation, as there is
no BTI guard information in stage two.  Our code tried to do this,
but got it wrong, because we currently have two fields where the GP
bit information might live (ARMCacheAttrs::guarded and
CPUTLBEntryFull::extra::arm::guarded), and we were storing the GP bit
in the latter during the stage 1 walk but trying to copy the former
in combine_cacheattrs().

Remove the duplicated storage, and always use the field in
CPUTLBEntryFull; correctly propagate the stage 1 value to the output
in get_phys_addr_twostage().

Note for stable backports: in v8.0 and earlier the field is named
result->f.guarded, not result->f.extra.arm.guarded.

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1950
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20231031173723.26582-1-peter.maydell@linaro.org
(cherry picked from commit 4c09abeae8704970ff03bf2196973f6bf08ab6f9)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
(Mjt: replace f.extra.arm.guarded -> f.guarded due to v8.1.0-1179-ga81fef4b64)

diff --git a/target/arm/internals.h b/target/arm/internals.h
index 0f01bc32a8..784f1e0fab 100644
--- a/target/arm/internals.h
+++ b/target/arm/internals.h
@@ -1180,7 +1180,6 @@ typedef struct ARMCacheAttrs {
     unsigned int attrs:8;
     unsigned int shareability:2; /* as in the SH field of the VMSAv8-64 PTEs */
     bool is_s2_format:1;
-    bool guarded:1;              /* guarded bit of the v8-64 PTE */
 } ARMCacheAttrs;
 
 /* Fields that are valid upon success. */
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
index 8f94100c61..3195d5d401 100644
--- a/target/arm/ptw.c
+++ b/target/arm/ptw.c
@@ -2979,7 +2979,6 @@ static ARMCacheAttrs combine_cacheattrs(uint64_t hcr,
 
     assert(!s1.is_s2_format);
     ret.is_s2_format = false;
-    ret.guarded = s1.guarded;
 
     if (s1.attrs == 0xf0) {
         tagged = true;
@@ -3119,7 +3118,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw,
     int s1_prot, s1_lgpgsz;
     bool is_secure = ptw->in_secure;
     ARMSecuritySpace in_space = ptw->in_space;
-    bool ret, ipa_secure;
+    bool ret, ipa_secure, s1_guarded;
     ARMCacheAttrs cacheattrs1;
     ARMSecuritySpace ipa_space;
     uint64_t hcr;
@@ -3147,6 +3146,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw,
      */
     s1_prot = result->f.prot;
     s1_lgpgsz = result->f.lg_page_size;
+    s1_guarded = result->f.guarded;
     cacheattrs1 = result->cacheattrs;
     memset(result, 0, sizeof(*result));
 
@@ -3197,6 +3197,9 @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw,
     result->cacheattrs = combine_cacheattrs(hcr, cacheattrs1,
                                             result->cacheattrs);
 
+    /* No BTI GP information in stage 2, we just use the S1 value */
+    result->f.guarded = s1_guarded;
+
     /*
      * Check if IPA translates to secure or non-secure PA space.
      * Note that VSTCR overrides VTCR and {N}SW overrides {N}SA.
-- 
2.39.2



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

* [Stable-8.1.3 27/55] util/uuid: Add UUID_STR_LEN definition
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (25 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 26/55] target/arm: Correctly propagate stage 1 BTI guarded bit in a two-stage walk Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 28/55] vfio/pci: Fix buffer overrun when writing the VF token Michael Tokarev
                   ` (28 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Cédric Le Goater, Fam Zheng,
	Philippe Mathieu-Daudé, Juan Quintela, Denis V. Lunev,
	Michael Tokarev

From: Cédric Le Goater <clg@redhat.com>

qemu_uuid_unparse() includes a trailing NUL when writing the uuid
string and the buffer size should be UUID_FMT_LEN + 1 bytes. Add a
define for this size and use it where required.

Cc: Fam Zheng <fam@euphon.net>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: "Denis V. Lunev" <den@openvz.org>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit 721da0396cfa0a4859cefb57e32cc79d19d80f54)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/block/parallels-ext.c b/block/parallels-ext.c
index 8a109f005a..4d8ecf5047 100644
--- a/block/parallels-ext.c
+++ b/block/parallels-ext.c
@@ -130,7 +130,7 @@ static BdrvDirtyBitmap *parallels_load_bitmap(BlockDriverState *bs,
     g_autofree uint64_t *l1_table = NULL;
     BdrvDirtyBitmap *bitmap;
     QemuUUID uuid;
-    char uuidstr[UUID_FMT_LEN + 1];
+    char uuidstr[UUID_STR_LEN];
     int i;
 
     if (data_size < sizeof(bf)) {
diff --git a/block/vdi.c b/block/vdi.c
index 6c35309e04..af2feaa129 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -239,7 +239,7 @@ static void vdi_header_to_le(VdiHeader *header)
 
 static void vdi_header_print(VdiHeader *header)
 {
-    char uuidstr[37];
+    char uuidstr[UUID_STR_LEN];
     QemuUUID uuid;
     logout("text        %s", header->text);
     logout("signature   0x%08x\n", header->signature);
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 6d5d43eda2..d54f527728 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -1105,7 +1105,7 @@ static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
 {
     Property *prop = opaque;
     QemuUUID *uuid = object_field_prop_ptr(obj, prop);
-    char buffer[UUID_FMT_LEN + 1];
+    char buffer[UUID_STR_LEN];
     char *p = buffer;
 
     qemu_uuid_unparse(uuid, buffer);
diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
index 271289f902..c64eaa5a46 100644
--- a/hw/hyperv/vmbus.c
+++ b/hw/hyperv/vmbus.c
@@ -2271,7 +2271,7 @@ static void vmbus_dev_realize(DeviceState *dev, Error **errp)
     VMBus *vmbus = VMBUS(qdev_get_parent_bus(dev));
     BusChild *child;
     Error *err = NULL;
-    char idstr[UUID_FMT_LEN + 1];
+    char idstr[UUID_STR_LEN];
 
     assert(!qemu_uuid_is_null(&vdev->instanceid));
 
@@ -2467,7 +2467,7 @@ static char *vmbus_get_dev_path(DeviceState *dev)
 static char *vmbus_get_fw_dev_path(DeviceState *dev)
 {
     VMBusDevice *vdev = VMBUS_DEVICE(dev);
-    char uuid[UUID_FMT_LEN + 1];
+    char uuid[UUID_STR_LEN];
 
     qemu_uuid_unparse(&vdev->instanceid, uuid);
     return g_strdup_printf("%s@%s", qdev_fw_name(dev), uuid);
diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h
index dc40ee1fc9..9e160d65aa 100644
--- a/include/qemu/uuid.h
+++ b/include/qemu/uuid.h
@@ -79,6 +79,7 @@ typedef struct {
                  "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
 
 #define UUID_FMT_LEN 36
+#define UUID_STR_LEN (UUID_FMT_LEN + 1)
 
 #define UUID_NONE "00000000-0000-0000-0000-000000000000"
 
diff --git a/migration/savevm.c b/migration/savevm.c
index a2cb8855e2..d60c4f487a 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -469,8 +469,8 @@ static bool vmstate_uuid_needed(void *opaque)
 static int vmstate_uuid_post_load(void *opaque, int version_id)
 {
     SaveState *state = opaque;
-    char uuid_src[UUID_FMT_LEN + 1];
-    char uuid_dst[UUID_FMT_LEN + 1];
+    char uuid_src[UUID_STR_LEN];
+    char uuid_dst[UUID_STR_LEN];
 
     if (!qemu_uuid_set) {
         /*
diff --git a/tests/unit/test-uuid.c b/tests/unit/test-uuid.c
index c111de5fc1..224c6d9936 100644
--- a/tests/unit/test-uuid.c
+++ b/tests/unit/test-uuid.c
@@ -145,7 +145,7 @@ static void test_uuid_unparse(void)
     int i;
 
     for (i = 0; i < ARRAY_SIZE(uuid_test_data); i++) {
-        char out[37];
+        char out[UUID_STR_LEN];
 
         if (!uuid_test_data[i].check_unparse) {
             continue;
diff --git a/util/uuid.c b/util/uuid.c
index b1108dde78..cedabea155 100644
--- a/util/uuid.c
+++ b/util/uuid.c
@@ -51,7 +51,7 @@ int qemu_uuid_is_equal(const QemuUUID *lhv, const QemuUUID *rhv)
 void qemu_uuid_unparse(const QemuUUID *uuid, char *out)
 {
     const unsigned char *uu = &uuid->data[0];
-    snprintf(out, UUID_FMT_LEN + 1, UUID_FMT,
+    snprintf(out, UUID_STR_LEN, UUID_FMT,
              uu[0], uu[1], uu[2], uu[3], uu[4], uu[5], uu[6], uu[7],
              uu[8], uu[9], uu[10], uu[11], uu[12], uu[13], uu[14], uu[15]);
 }
-- 
2.39.2



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

* [Stable-8.1.3 28/55] vfio/pci: Fix buffer overrun when writing the VF token
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (26 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 27/55] util/uuid: Add UUID_STR_LEN definition Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 29/55] util/uuid: Remove UUID_FMT_LEN Michael Tokarev
                   ` (27 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Cédric Le Goater, Alex Williamson,
	Juan Quintela, Denis V. Lunev, Michael Tokarev

From: Cédric Le Goater <clg@redhat.com>

qemu_uuid_unparse() includes a trailing NUL when writing the uuid
string and the buffer size should be UUID_FMT_LEN + 1 bytes. Use the
recently added UUID_STR_LEN which defines the correct size.

Fixes: CID 1522913
Fixes: 2dca1b37a760 ("vfio/pci: add support for VF token")
Cc: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: "Denis V. Lunev" <den@openvz.org>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit f8d6f3b16c37bd516a026e92a31dade5d761d3a6)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index a205c6b113..aab02ebb98 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2987,7 +2987,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
     int groupid;
     int i, ret;
     bool is_mdev;
-    char uuid[UUID_FMT_LEN];
+    char uuid[UUID_STR_LEN];
     char *name;
 
     if (!vbasedev->sysfsdev) {
-- 
2.39.2



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

* [Stable-8.1.3 29/55] util/uuid: Remove UUID_FMT_LEN
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (27 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 28/55] vfio/pci: Fix buffer overrun when writing the VF token Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 30/55] i386/xen: Don't advertise XENFEAT_supervisor_mode_kernel Michael Tokarev
                   ` (26 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Cédric Le Goater, Fam Zheng,
	Philippe Mathieu-Daudé, Denis V. Lunev, Juan Quintela,
	Michael Tokarev

From: Cédric Le Goater <clg@redhat.com>

Dangerous and now unused.

Cc: Fam Zheng <fam@euphon.net>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: "Denis V. Lunev" <den@openvz.org>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit 4ef9d97b1a37b8cfd152cc3ac5f9576e406868b1)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h
index 9e160d65aa..008926ab32 100644
--- a/include/qemu/uuid.h
+++ b/include/qemu/uuid.h
@@ -78,8 +78,7 @@ typedef struct {
                  "%02hhx%02hhx-" \
                  "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
 
-#define UUID_FMT_LEN 36
-#define UUID_STR_LEN (UUID_FMT_LEN + 1)
+#define UUID_STR_LEN (36 + 1)
 
 #define UUID_NONE "00000000-0000-0000-0000-000000000000"
 
-- 
2.39.2



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

* [Stable-8.1.3 30/55] i386/xen: Don't advertise XENFEAT_supervisor_mode_kernel
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (28 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 29/55] util/uuid: Remove UUID_FMT_LEN Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 31/55] i386/xen: fix per-vCPU upcall vector for Xen emulation Michael Tokarev
                   ` (25 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, David Woodhouse, Paul Durrant, Michael Tokarev

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

This confuses lscpu into thinking it's running in PVH mode.

Cc: qemu-stable@nongnu.org
Fixes: bedcc139248 ("i386/xen: implement HYPERVISOR_xen_version")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
(cherry picked from commit e969f992c6562222e245dd8557f5b132a11ec29c)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c
index a8146115f0..b307c75713 100644
--- a/target/i386/kvm/xen-emu.c
+++ b/target/i386/kvm/xen-emu.c
@@ -267,7 +267,6 @@ static bool kvm_xen_hcall_xen_version(struct kvm_xen_exit *exit, X86CPU *cpu,
             fi.submap |= 1 << XENFEAT_writable_page_tables |
                          1 << XENFEAT_writable_descriptor_tables |
                          1 << XENFEAT_auto_translated_physmap |
-                         1 << XENFEAT_supervisor_mode_kernel |
                          1 << XENFEAT_hvm_callback_vector |
                          1 << XENFEAT_hvm_safe_pvclock |
                          1 << XENFEAT_hvm_pirqs;
-- 
2.39.2



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

* [Stable-8.1.3 31/55] i386/xen: fix per-vCPU upcall vector for Xen emulation
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (29 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 30/55] i386/xen: Don't advertise XENFEAT_supervisor_mode_kernel Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 32/55] hw/xen: select kernel mode for per-vCPU event channel upcall vector Michael Tokarev
                   ` (24 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, David Woodhouse, Paul Durrant, Michael Tokarev

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

The per-vCPU upcall vector support had three problems. Firstly it was
using the wrong hypercall argument and would always return -EFAULT when
the guest tried to set it up. Secondly it was using the wrong ioctl() to
pass the vector to the kernel and thus the *kernel* would always return
-EINVAL. Finally, even when delivering the event directly from userspace
with an MSI, it put the destination CPU ID into the wrong bits of the
MSI address.

Linux doesn't (yet) use this mode so it went without decent testing
for a while.

Cc: qemu-stable@nongnu.org
Fixes: 105b47fdf2d0 ("i386/xen: implement HVMOP_set_evtchn_upcall_vector")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
(cherry picked from commit e7dbb62ff19ce55548c785d76e814e7b144e6217)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c
index b307c75713..9d512bb859 100644
--- a/target/i386/kvm/xen-emu.c
+++ b/target/i386/kvm/xen-emu.c
@@ -306,7 +306,7 @@ static int kvm_xen_set_vcpu_callback_vector(CPUState *cs)
 
     trace_kvm_xen_set_vcpu_callback(cs->cpu_index, vector);
 
-    return kvm_vcpu_ioctl(cs, KVM_XEN_HVM_SET_ATTR, &xva);
+    return kvm_vcpu_ioctl(cs, KVM_XEN_VCPU_SET_ATTR, &xva);
 }
 
 static void do_set_vcpu_callback_vector(CPUState *cs, run_on_cpu_data data)
@@ -440,7 +440,8 @@ void kvm_xen_inject_vcpu_callback_vector(uint32_t vcpu_id, int type)
          * deliver it as an MSI.
          */
         MSIMessage msg = {
-            .address = APIC_DEFAULT_ADDRESS | X86_CPU(cs)->apic_id,
+            .address = APIC_DEFAULT_ADDRESS |
+                       (X86_CPU(cs)->apic_id << MSI_ADDR_DEST_ID_SHIFT),
             .data = vector | (1UL << MSI_DATA_LEVEL_SHIFT),
         };
         kvm_irqchip_send_msi(kvm_state, msg);
@@ -849,8 +850,7 @@ static bool kvm_xen_hcall_hvm_op(struct kvm_xen_exit *exit, X86CPU *cpu,
     int ret = -ENOSYS;
     switch (cmd) {
     case HVMOP_set_evtchn_upcall_vector:
-        ret = kvm_xen_hcall_evtchn_upcall_vector(exit, cpu,
-                                                 exit->u.hcall.params[0]);
+        ret = kvm_xen_hcall_evtchn_upcall_vector(exit, cpu, arg);
         break;
 
     case HVMOP_pagetable_dying:
-- 
2.39.2



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

* [Stable-8.1.3 32/55] hw/xen: select kernel mode for per-vCPU event channel upcall vector
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (30 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 31/55] i386/xen: fix per-vCPU upcall vector for Xen emulation Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 33/55] hw/xen: don't clear map_track[] in xen_gnttab_reset() Michael Tokarev
                   ` (23 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, David Woodhouse, Paul Durrant, Michael Tokarev

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

A guest which has configured the per-vCPU upcall vector may set the
HVM_PARAM_CALLBACK_IRQ param to fairly much anything other than zero.

For example, Linux v6.0+ after commit b1c3497e604 ("x86/xen: Add support
for HVMOP_set_evtchn_upcall_vector") will just do this after setting the
vector:

       /* Trick toolstack to think we are enlightened. */
       if (!cpu)
               rc = xen_set_callback_via(1);

That's explicitly setting the delivery to GSI#1, but it's supposed to be
overridden by the per-vCPU vector setting. This mostly works in Qemu
*except* for the logic to enable the in-kernel handling of event channels,
which falsely determines that the kernel cannot accelerate GSI delivery
in this case.

Add a kvm_xen_has_vcpu_callback_vector() to report whether vCPU#0 has
the vector set, and use that in xen_evtchn_set_callback_param() to
enable the kernel acceleration features even when the param *appears*
to be set to target a GSI.

Preserve the Xen behaviour that when HVM_PARAM_CALLBACK_IRQ is set to
*zero* the event channel delivery is disabled completely. (Which is
what that bizarre guest behaviour is working round in the first place.)

Cc: qemu-stable@nongnu.org
Fixes: 91cce756179 ("hw/xen: Add xen_evtchn device for event channel emulation")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
(cherry picked from commit 18e83f28bf39ffd2784aeb2e4e229096a86d349b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index a731738411..3d6f4b4a0a 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -490,6 +490,12 @@ int xen_evtchn_set_callback_param(uint64_t param)
         break;
     }
 
+    /* If the guest has set a per-vCPU callback vector, prefer that. */
+    if (gsi && kvm_xen_has_vcpu_callback_vector()) {
+        in_kernel = kvm_xen_has_cap(EVTCHN_SEND);
+        gsi = 0;
+    }
+
     if (!ret) {
         /* If vector delivery was turned *off* then tell the kernel */
         if ((s->callback_param >> CALLBACK_VIA_TYPE_SHIFT) ==
diff --git a/include/sysemu/kvm_xen.h b/include/sysemu/kvm_xen.h
index 595abfbe40..961c702c4e 100644
--- a/include/sysemu/kvm_xen.h
+++ b/include/sysemu/kvm_xen.h
@@ -22,6 +22,7 @@
 int kvm_xen_soft_reset(void);
 uint32_t kvm_xen_get_caps(void);
 void *kvm_xen_get_vcpu_info_hva(uint32_t vcpu_id);
+bool kvm_xen_has_vcpu_callback_vector(void);
 void kvm_xen_inject_vcpu_callback_vector(uint32_t vcpu_id, int type);
 void kvm_xen_set_callback_asserted(void);
 int kvm_xen_set_vcpu_virq(uint32_t vcpu_id, uint16_t virq, uint16_t port);
diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c
index 9d512bb859..00941c1c8a 100644
--- a/target/i386/kvm/xen-emu.c
+++ b/target/i386/kvm/xen-emu.c
@@ -424,6 +424,13 @@ void kvm_xen_set_callback_asserted(void)
     }
 }
 
+bool kvm_xen_has_vcpu_callback_vector(void)
+{
+    CPUState *cs = qemu_get_cpu(0);
+
+    return cs && !!X86_CPU(cs)->env.xen_vcpu_callback_vector;
+}
+
 void kvm_xen_inject_vcpu_callback_vector(uint32_t vcpu_id, int type)
 {
     CPUState *cs = qemu_get_cpu(vcpu_id);
-- 
2.39.2



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

* [Stable-8.1.3 33/55] hw/xen: don't clear map_track[] in xen_gnttab_reset()
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (31 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 32/55] hw/xen: select kernel mode for per-vCPU event channel upcall vector Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 34/55] hw/xen: fix XenStore watch delivery to guest Michael Tokarev
                   ` (22 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, David Woodhouse, Paul Durrant, Michael Tokarev

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

The refcounts actually correspond to 'active_ref' structures stored in a
GHashTable per "user" on the backend side (mostly, per XenDevice).

If we zero map_track[] on reset, then when the backend drivers get torn
down and release their mapping we hit the assert(s->map_track[ref] != 0)
in gnt_unref().

So leave them in place. Each backend driver will disconnect and reconnect
as the guest comes back up again and reconnects, and it all works out OK
in the end as the old refs get dropped.

Cc: qemu-stable@nongnu.org
Fixes: de26b2619789 ("hw/xen: Implement soft reset for emulated gnttab")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
(cherry picked from commit 3de75ed352411899dbc9222e82fe164890c77e78)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/i386/kvm/xen_gnttab.c b/hw/i386/kvm/xen_gnttab.c
index 21c30e3659..839ec920a1 100644
--- a/hw/i386/kvm/xen_gnttab.c
+++ b/hw/i386/kvm/xen_gnttab.c
@@ -541,7 +541,5 @@ int xen_gnttab_reset(void)
     s->entries.v1[GNTTAB_RESERVED_XENSTORE].flags = GTF_permit_access;
     s->entries.v1[GNTTAB_RESERVED_XENSTORE].frame = XEN_SPECIAL_PFN(XENSTORE);
 
-    memset(s->map_track, 0, s->max_frames * ENTRIES_PER_FRAME_V1);
-
     return 0;
 }
-- 
2.39.2



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

* [Stable-8.1.3 34/55] hw/xen: fix XenStore watch delivery to guest
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (32 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 33/55] hw/xen: don't clear map_track[] in xen_gnttab_reset() Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 35/55] hw/xen: take iothread mutex in xen_evtchn_reset_op() Michael Tokarev
                   ` (21 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, David Woodhouse, Paul Durrant, Michael Tokarev

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

When fire_watch_cb() found the response buffer empty, it would call
deliver_watch() to generate the XS_WATCH_EVENT message in the response
buffer and send an event channel notification to the guest… without
actually *copying* the response buffer into the ring. So there was
nothing for the guest to see. The pending response didn't actually get
processed into the ring until the guest next triggered some activity
from its side.

Add the missing call to put_rsp().

It might have been slightly nicer to call xen_xenstore_event() here,
which would *almost* have worked. Except for the fact that it calls
xen_be_evtchn_pending() to check that it really does have an event
pending (and clear the eventfd for next time). And under Xen it's
defined that setting that fd to O_NONBLOCK isn't guaranteed to work,
so the emu implementation follows suit.

This fixes Xen device hot-unplug.

Cc: qemu-stable@nongnu.org
Fixes: 0254c4d19df ("hw/xen: Add xenstore wire implementation and implementation stubs")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
(cherry picked from commit 4a5780f52095f1daf23618dc6198a2a1665ea505)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c
index 133d89e953..725ca2f15d 100644
--- a/hw/i386/kvm/xen_xenstore.c
+++ b/hw/i386/kvm/xen_xenstore.c
@@ -1357,10 +1357,12 @@ static void fire_watch_cb(void *opaque, const char *path, const char *token)
     } else {
         deliver_watch(s, path, token);
         /*
-         * If the message was queued because there was already ring activity,
-         * no need to wake the guest. But if not, we need to send the evtchn.
+         * Attempt to queue the message into the actual ring, and send
+         * the event channel notification if any bytes are copied.
          */
-        xen_be_evtchn_notify(s->eh, s->be_port);
+        if (s->rsp_pending && put_rsp(s) > 0) {
+            xen_be_evtchn_notify(s->eh, s->be_port);
+        }
     }
 }
 
-- 
2.39.2



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

* [Stable-8.1.3 35/55] hw/xen: take iothread mutex in xen_evtchn_reset_op()
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (33 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 34/55] hw/xen: fix XenStore watch delivery to guest Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 36/55] hw/xen: use correct default protocol for xen-block on x86 Michael Tokarev
                   ` (20 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, David Woodhouse, Paul Durrant, Michael Tokarev

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

The xen_evtchn_soft_reset() function requires the iothread mutex, but is
also called for the EVTCHNOP_reset hypercall. Ensure the mutex is taken
in that case.

Cc: qemu-stable@nongnu.org
Fixes: a15b10978fe6 ("hw/xen: Implement EVTCHNOP_reset")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
(cherry picked from commit debc995e883b05c2fd02fb797a61ab1328e5bae2)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index 3d6f4b4a0a..b2b4be9983 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -1135,6 +1135,7 @@ int xen_evtchn_reset_op(struct evtchn_reset *reset)
         return -ESRCH;
     }
 
+    QEMU_IOTHREAD_LOCK_GUARD();
     return xen_evtchn_soft_reset();
 }
 
-- 
2.39.2



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

* [Stable-8.1.3 36/55] hw/xen: use correct default protocol for xen-block on x86
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (34 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 35/55] hw/xen: take iothread mutex in xen_evtchn_reset_op() Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 37/55] virtio-gpu: block migration of VMs with blob=true Michael Tokarev
                   ` (19 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, David Woodhouse, Paul Durrant, Michael Tokarev

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

Even on x86_64 the default protocol is the x86-32 one if the guest doesn't
specifically ask for x86-64.

Cc: qemu-stable@nongnu.org
Fixes: b6af8926fb85 ("xen: add implementations of xen-block connect and disconnect functions...")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
(cherry picked from commit a1c1082908dde4867b1ac55f546bea0c17d52318)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index 3906b9058b..c754126711 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -115,9 +115,13 @@ static void xen_block_connect(XenDevice *xendev, Error **errp)
         return;
     }
 
-    if (xen_device_frontend_scanf(xendev, "protocol", "%ms",
-                                  &str) != 1) {
-        protocol = BLKIF_PROTOCOL_NATIVE;
+    if (xen_device_frontend_scanf(xendev, "protocol", "%ms", &str) != 1) {
+        /* x86 defaults to the 32-bit protocol even for 64-bit guests. */
+        if (object_dynamic_cast(OBJECT(qdev_get_machine()), "x86-machine")) {
+            protocol = BLKIF_PROTOCOL_X86_32;
+        } else {
+            protocol = BLKIF_PROTOCOL_NATIVE;
+        }
     } else {
         if (strcmp(str, XEN_IO_PROTO_ABI_X86_32) == 0) {
             protocol = BLKIF_PROTOCOL_X86_32;
-- 
2.39.2



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

* [Stable-8.1.3 37/55] virtio-gpu: block migration of VMs with blob=true
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (35 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 36/55] hw/xen: use correct default protocol for xen-block on x86 Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 38/55] block/nvme: nvme_process_completion() fix bound for cid Michael Tokarev
                   ` (18 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Marc-André Lureau, Peter Xu, Michael Tokarev

From: Marc-André Lureau <marcandre.lureau@redhat.com>

"blob" resources don't have an associated pixman image:

#0  pixman_image_get_stride (image=0x0) at ../pixman/pixman-image.c:921
#1  0x0000562327c25236 in virtio_gpu_save (f=0x56232bb13b00, opaque=0x56232b555a60, size=0, field=0x5623289ab6c8 <__compound_literal.3+104>, vmdesc=0x56232ab59fe0) at ../hw/display/virtio-gpu.c:1225

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=2236353

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Peter Xu <peterx@redhat.com>
(cherry picked from commit 9c549ab6895a43ad0cb33e684e11cdb0b5400897)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 93857ad523..5b64942637 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -26,6 +26,7 @@
 #include "hw/virtio/virtio-gpu-pixman.h"
 #include "hw/virtio/virtio-bus.h"
 #include "hw/qdev-properties.h"
+#include "migration/blocker.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include "qapi/error.h"
@@ -44,6 +45,8 @@ static void virtio_gpu_cleanup_mapping(VirtIOGPU *g,
                                        struct virtio_gpu_simple_resource *res);
 static void virtio_gpu_reset_bh(void *opaque);
 
+static Error *blob_mig_blocker;
+
 void virtio_gpu_update_cursor_data(VirtIOGPU *g,
                                    struct virtio_gpu_scanout *s,
                                    uint32_t resource_id)
@@ -1376,6 +1379,14 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
             error_setg(errp, "blobs and virgl are not compatible (yet)");
             return;
         }
+
+        if (!blob_mig_blocker) {
+            error_setg(&blob_mig_blocker,
+                       "virtio-gpu blob VMs are currently not migratable.");
+        }
+        if (migrate_add_blocker(blob_mig_blocker, errp)) {
+            return;
+        }
     }
 
     if (!virtio_gpu_base_device_realize(qdev,
@@ -1402,6 +1413,9 @@ static void virtio_gpu_device_unrealize(DeviceState *qdev)
 {
     VirtIOGPU *g = VIRTIO_GPU(qdev);
 
+    if (virtio_gpu_blob_enabled(g->parent_obj.conf)) {
+        migrate_del_blocker(blob_mig_blocker);
+    }
     g_clear_pointer(&g->ctrl_bh, qemu_bh_delete);
     g_clear_pointer(&g->cursor_bh, qemu_bh_delete);
     g_clear_pointer(&g->reset_bh, qemu_bh_delete);
-- 
2.39.2



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

* [Stable-8.1.3 38/55] block/nvme: nvme_process_completion() fix bound for cid
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (36 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 37/55] virtio-gpu: block migration of VMs with blob=true Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 39/55] target/arm: Fix A64 LDRA immediate decode Michael Tokarev
                   ` (17 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Vladimir Sementsov-Ogievskiy, Stefan Hajnoczi,
	Maksim Davydov, Peter Maydell, Michael Tokarev

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

NVMeQueuePair::reqs has length NVME_NUM_REQS, which less than
NVME_QUEUE_SIZE by 1.

Fixes: 1086e95da17050 ("block/nvme: switch to a NVMeRequest freelist")
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru>
Message-id: 20231017125941.810461-5-vsementsov@yandex-team.ru
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
(cherry picked from commit cc8fb0c3ae3c950eb40e969607e17ff16a7519ac)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/block/nvme.c b/block/nvme.c
index b6e95f0b7e..0faedf3072 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -416,9 +416,10 @@ static bool nvme_process_completion(NVMeQueuePair *q)
             q->cq_phase = !q->cq_phase;
         }
         cid = le16_to_cpu(c->cid);
-        if (cid == 0 || cid > NVME_QUEUE_SIZE) {
-            warn_report("NVMe: Unexpected CID in completion queue: %"PRIu32", "
-                        "queue size: %u", cid, NVME_QUEUE_SIZE);
+        if (cid == 0 || cid > NVME_NUM_REQS) {
+            warn_report("NVMe: Unexpected CID in completion queue: %" PRIu32
+                        ", should be within: 1..%u inclusively", cid,
+                        NVME_NUM_REQS);
             continue;
         }
         trace_nvme_complete_command(s, q->index, cid);
-- 
2.39.2



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

* [Stable-8.1.3 39/55] target/arm: Fix A64 LDRA immediate decode
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (37 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 38/55] block/nvme: nvme_process_completion() fix bound for cid Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 40/55] qcow2: keep reference on zeroize with discard-no-unref enabled Michael Tokarev
                   ` (16 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Peter Maydell, Philippe Mathieu-Daudé,
	Michael Tokarev

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

In commit be23a049 in the conversion to decodetree we broke the
decoding of the immediate value in the LDRA instruction.  This should
be a 10 bit signed value that is scaled by 8, but in the conversion
we incorrectly ended up scaling it only by 2.  Fix the scaling
factor.

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1970
Fixes: be23a049 ("target/arm: Convert load (pointer auth) insns to decodetree")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20231106113445.1163063-1-peter.maydell@linaro.org
(cherry picked from commit 5722fc471296d5f042df4b005a851cc8008df0c9)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/arm/tcg/a64.decode b/target/arm/tcg/a64.decode
index ef64a3f9cb..7e09fd18b4 100644
--- a/target/arm/tcg/a64.decode
+++ b/target/arm/tcg/a64.decode
@@ -461,7 +461,7 @@ LDAPR           sz:2 111 0 00 1 0 1 11111 1100 00 rn:5 rt:5
 # Load/store register (pointer authentication)
 
 # LDRA immediate is 10 bits signed and scaled, but the bits aren't all contiguous
-%ldra_imm       22:s1 12:9 !function=times_2
+%ldra_imm       22:s1 12:9 !function=times_8
 
 LDRA            11 111 0 00 m:1 . 1 ......... w:1 1 rn:5 rt:5 imm=%ldra_imm
 
diff --git a/target/arm/tcg/translate.h b/target/arm/tcg/translate.h
index d1cacff0b2..1afcd16ab1 100644
--- a/target/arm/tcg/translate.h
+++ b/target/arm/tcg/translate.h
@@ -203,6 +203,11 @@ static inline int times_4(DisasContext *s, int x)
     return x * 4;
 }
 
+static inline int times_8(DisasContext *s, int x)
+{
+    return x * 8;
+}
+
 static inline int times_2_plus_1(DisasContext *s, int x)
 {
     return x * 2 + 1;
-- 
2.39.2



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

* [Stable-8.1.3 40/55] qcow2: keep reference on zeroize with discard-no-unref enabled
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (38 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 39/55] target/arm: Fix A64 LDRA immediate decode Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 41/55] block/file-posix: fix update_zones_wp() caller Michael Tokarev
                   ` (15 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Jean-Louis Dupond, Hanna Czenczek, Michael Tokarev

From: Jean-Louis Dupond <jean-louis@dupond.be>

When the discard-no-unref flag is enabled, we keep the reference for
normal discard requests.
But when a discard is executed on a snapshot/qcow2 image with backing,
the discards are saved as zero clusters in the snapshot image.

When committing the snapshot to the backing file, not
discard_in_l2_slice is called but zero_in_l2_slice. Which did not had
any logic to keep the reference when discard-no-unref is enabled.

Therefor we add logic in the zero_in_l2_slice call to keep the reference
on commit.

Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1621
Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
Message-Id: <20231003125236.216473-2-jean-louis@dupond.be>
[hreitz: Made the documentation change more verbose, as discussed
         on-list]
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
(cherry picked from commit b2b109041ecd1095384f5be5bb9badd13c1cf286)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index f4f6cd6ad0..fc764aea4d 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1984,7 +1984,7 @@ static int discard_in_l2_slice(BlockDriverState *bs, uint64_t offset,
             /* If we keep the reference, pass on the discard still */
             bdrv_pdiscard(s->data_file, old_l2_entry & L2E_OFFSET_MASK,
                           s->cluster_size);
-       }
+        }
     }
 
     qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice);
@@ -2062,9 +2062,15 @@ zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,
         QCow2ClusterType type = qcow2_get_cluster_type(bs, old_l2_entry);
         bool unmap = (type == QCOW2_CLUSTER_COMPRESSED) ||
             ((flags & BDRV_REQ_MAY_UNMAP) && qcow2_cluster_is_allocated(type));
-        uint64_t new_l2_entry = unmap ? 0 : old_l2_entry;
+        bool keep_reference =
+            (s->discard_no_unref && type != QCOW2_CLUSTER_COMPRESSED);
+        uint64_t new_l2_entry = old_l2_entry;
         uint64_t new_l2_bitmap = old_l2_bitmap;
 
+        if (unmap && !keep_reference) {
+            new_l2_entry = 0;
+        }
+
         if (has_subclusters(s)) {
             new_l2_bitmap = QCOW_L2_BITMAP_ALL_ZEROES;
         } else {
@@ -2082,9 +2088,17 @@ zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,
             set_l2_bitmap(s, l2_slice, l2_index + i, new_l2_bitmap);
         }
 
-        /* Then decrease the refcount */
         if (unmap) {
-            qcow2_free_any_cluster(bs, old_l2_entry, QCOW2_DISCARD_REQUEST);
+            if (!keep_reference) {
+                /* Then decrease the refcount */
+                qcow2_free_any_cluster(bs, old_l2_entry, QCOW2_DISCARD_REQUEST);
+            } else if (s->discard_passthrough[QCOW2_DISCARD_REQUEST] &&
+                       (type == QCOW2_CLUSTER_NORMAL ||
+                        type == QCOW2_CLUSTER_ZERO_ALLOC)) {
+                /* If we keep the reference, pass on the discard still */
+                bdrv_pdiscard(s->data_file, old_l2_entry & L2E_OFFSET_MASK,
+                            s->cluster_size);
+            }
         }
     }
 
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 2b1d493d6e..bca1a0c372 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -3473,16 +3473,20 @@
 # @pass-discard-other: whether discard requests for the data source
 #     should be issued on other occasions where a cluster gets freed
 #
-# @discard-no-unref: when enabled, discards from the guest will not
-#     cause cluster allocations to be relinquished.  This prevents
-#     qcow2 fragmentation that would be caused by such discards.
-#     Besides potential performance degradation, such fragmentation
-#     can lead to increased allocation of clusters past the end of the
-#     image file, resulting in image files whose file length can grow
-#     much larger than their guest disk size would suggest.  If image
-#     file length is of concern (e.g. when storing qcow2 images
-#     directly on block devices), you should consider enabling this
-#     option.  (since 8.1)
+# @discard-no-unref: when enabled, data clusters will remain
+#     preallocated when they are no longer used, e.g. because they are
+#     discarded or converted to zero clusters.  As usual, whether the
+#     old data is discarded or kept on the protocol level (i.e. in the
+#     image file) depends on the setting of the pass-discard-request
+#     option.  Keeping the clusters preallocated prevents qcow2
+#     fragmentation that would otherwise be caused by freeing and
+#     re-allocating them later.  Besides potential performance
+#     degradation, such fragmentation can lead to increased allocation
+#     of clusters past the end of the image file, resulting in image
+#     files whose file length can grow much larger than their guest disk
+#     size would suggest.  If image file length is of concern (e.g. when
+#     storing qcow2 images directly on block devices), you should
+#     consider enabling this option.  (since 8.1)
 #
 # @overlap-check: which overlap checks to perform for writes to the
 #     image, defaults to 'cached' (since 2.2)
diff --git a/qemu-options.hx b/qemu-options.hx
index b56f6b2fb2..8073f5edf5 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1436,9 +1436,13 @@ SRST
             (on/off; default: off)
 
         ``discard-no-unref``
-            When enabled, discards from the guest will not cause cluster
-            allocations to be relinquished. This prevents qcow2 fragmentation
-            that would be caused by such discards. Besides potential
+            When enabled, data clusters will remain preallocated when they are
+            no longer used, e.g. because they are discarded or converted to
+            zero clusters. As usual, whether the old data is discarded or kept
+            on the protocol level (i.e. in the image file) depends on the
+            setting of the pass-discard-request option. Keeping the clusters
+            preallocated prevents qcow2 fragmentation that would otherwise be
+            caused by freeing and re-allocating them later. Besides potential
             performance degradation, such fragmentation can lead to increased
             allocation of clusters past the end of the image file,
             resulting in image files whose file length can grow much larger
-- 
2.39.2



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

* [Stable-8.1.3 41/55] block/file-posix: fix update_zones_wp() caller
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (39 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 40/55] qcow2: keep reference on zeroize with discard-no-unref enabled Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 42/55] file-posix: fix over-writing of returning zone_append offset Michael Tokarev
                   ` (14 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Sam Li, Stefan Hajnoczi, Hanna Czenczek,
	Michael Tokarev

From: Sam Li <faithilikerun@gmail.com>

When the zoned request fail, it needs to update only the wp of
the target zones for not disrupting the in-flight writes on
these other zones. The wp is updated successfully after the
request completes.

Fixed the callers with right offset and nr_zones.

Signed-off-by: Sam Li <faithilikerun@gmail.com>
Message-Id: <20230825040556.4217-1-faithilikerun@gmail.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[hreitz: Rebased and fixed comment spelling]
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
(cherry picked from commit 10b9e0802a074c991e1ce485631d75641d0b0f9e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/block/file-posix.c b/block/file-posix.c
index aa89789737..4e2902f66f 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2523,7 +2523,10 @@ out:
                 }
             }
         } else {
-            update_zones_wp(bs, s->fd, 0, 1);
+            /*
+             * write and append write are not allowed to cross zone boundaries
+             */
+            update_zones_wp(bs, s->fd, offset, 1);
         }
 
         qemu_co_mutex_unlock(&wps->colock);
@@ -3470,7 +3473,7 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op,
                         len >> BDRV_SECTOR_BITS);
     ret = raw_thread_pool_submit(handle_aiocb_zone_mgmt, &acb);
     if (ret != 0) {
-        update_zones_wp(bs, s->fd, offset, i);
+        update_zones_wp(bs, s->fd, offset, nrz);
         error_report("ioctl %s failed %d", op_name, ret);
         return ret;
     }
-- 
2.39.2



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

* [Stable-8.1.3 42/55] file-posix: fix over-writing of returning zone_append offset
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (40 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 41/55] block/file-posix: fix update_zones_wp() caller Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 43/55] ati-vga: Implement fallback for pixman routines Michael Tokarev
                   ` (13 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Naohiro Aota, Naohiro Aota, Sam Li, Stefan Hajnoczi,
	Hanna Czenczek, Michael Tokarev

From: Naohiro Aota <nao.aota@gmail.com>

raw_co_zone_append() sets "s->offset" where "BDRVRawState *s". This pointer
is used later at raw_co_prw() to save the block address where the data is
written.

When multiple IOs are on-going at the same time, a later IO's
raw_co_zone_append() call over-writes a former IO's offset address before
raw_co_prw() completes. As a result, the former zone append IO returns the
initial value (= the start address of the writing zone), instead of the
proper address.

Fix the issue by passing the offset pointer to raw_co_prw() instead of
passing it through s->offset. Also, remove "offset" from BDRVRawState as
there is no usage anymore.

Fixes: 4751d09adcc3 ("block: introduce zone append write for zoned devices")
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Message-Id: <20231030073853.2601162-1-naohiro.aota@wdc.com>
Reviewed-by: Sam Li <faithilikerun@gmail.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
(cherry picked from commit ad4feaca61d76fecad784e6d5e7bae40d0411c46)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/block/file-posix.c b/block/file-posix.c
index 4e2902f66f..7f540b03ed 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -160,7 +160,6 @@ typedef struct BDRVRawState {
     bool has_write_zeroes:1;
     bool use_linux_aio:1;
     bool use_linux_io_uring:1;
-    int64_t *offset; /* offset of zone append operation */
     int page_cache_inconsistent; /* errno from fdatasync failure */
     bool has_fallocate;
     bool needs_alignment;
@@ -2445,12 +2444,13 @@ static bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov)
     return true;
 }
 
-static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset,
+static int coroutine_fn raw_co_prw(BlockDriverState *bs, int64_t *offset_ptr,
                                    uint64_t bytes, QEMUIOVector *qiov, int type)
 {
     BDRVRawState *s = bs->opaque;
     RawPosixAIOData acb;
     int ret;
+    uint64_t offset = *offset_ptr;
 
     if (fd_open(bs) < 0)
         return -EIO;
@@ -2513,8 +2513,8 @@ out:
             uint64_t *wp = &wps->wp[offset / bs->bl.zone_size];
             if (!BDRV_ZT_IS_CONV(*wp)) {
                 if (type & QEMU_AIO_ZONE_APPEND) {
-                    *s->offset = *wp;
-                    trace_zbd_zone_append_complete(bs, *s->offset
+                    *offset_ptr = *wp;
+                    trace_zbd_zone_append_complete(bs, *offset_ptr
                         >> BDRV_SECTOR_BITS);
                 }
                 /* Advance the wp if needed */
@@ -2539,14 +2539,14 @@ static int coroutine_fn raw_co_preadv(BlockDriverState *bs, int64_t offset,
                                       int64_t bytes, QEMUIOVector *qiov,
                                       BdrvRequestFlags flags)
 {
-    return raw_co_prw(bs, offset, bytes, qiov, QEMU_AIO_READ);
+    return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_READ);
 }
 
 static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, int64_t offset,
                                        int64_t bytes, QEMUIOVector *qiov,
                                        BdrvRequestFlags flags)
 {
-    return raw_co_prw(bs, offset, bytes, qiov, QEMU_AIO_WRITE);
+    return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_WRITE);
 }
 
 static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs)
@@ -3509,8 +3509,6 @@ static int coroutine_fn raw_co_zone_append(BlockDriverState *bs,
     int64_t zone_size_mask = bs->bl.zone_size - 1;
     int64_t iov_len = 0;
     int64_t len = 0;
-    BDRVRawState *s = bs->opaque;
-    s->offset = offset;
 
     if (*offset & zone_size_mask) {
         error_report("sector offset %" PRId64 " is not aligned to zone size "
@@ -3531,7 +3529,7 @@ static int coroutine_fn raw_co_zone_append(BlockDriverState *bs,
     }
 
     trace_zbd_zone_append(bs, *offset >> BDRV_SECTOR_BITS);
-    return raw_co_prw(bs, *offset, len, qiov, QEMU_AIO_ZONE_APPEND);
+    return raw_co_prw(bs, offset, len, qiov, QEMU_AIO_ZONE_APPEND);
 }
 #endif
 
-- 
2.39.2



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

* [Stable-8.1.3 43/55] ati-vga: Implement fallback for pixman routines
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (41 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 42/55] file-posix: fix over-writing of returning zone_append offset Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 44/55] ui/gtk: force realization of drawing area Michael Tokarev
                   ` (12 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, BALATON Zoltan, Marc-André Lureau,
	Michael Tokarev

From: BALATON Zoltan <balaton@eik.bme.hu>

Pixman routines can fail if no implementation is available and it will
become optional soon so add fallbacks when pixman does not work.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <ed0fba3f74e48143f02228b83bf8796ca49f3e7d.1698871239.git.balaton@eik.bme.hu>
(cherry picked from commit 08730ee0cc01c3fceb907a93436d15170a7556c4)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/display/ati.c b/hw/display/ati.c
index 6e38e00502..4f3bebcfd3 100644
--- a/hw/display/ati.c
+++ b/hw/display/ati.c
@@ -1014,6 +1014,7 @@ static Property ati_vga_properties[] = {
     DEFINE_PROP_UINT16("x-device-id", ATIVGAState, dev_id,
                        PCI_DEVICE_ID_ATI_RAGE128_PF),
     DEFINE_PROP_BOOL("guest_hwcursor", ATIVGAState, cursor_guest_mode, false),
+    DEFINE_PROP_UINT8("x-pixman", ATIVGAState, use_pixman, 3),
     DEFINE_PROP_END_OF_LIST()
 };
 
@@ -1035,11 +1036,18 @@ static void ati_vga_class_init(ObjectClass *klass, void *data)
     k->exit = ati_vga_exit;
 }
 
+static void ati_vga_init(Object *o)
+{
+    object_property_set_description(o, "x-pixman", "Use pixman for: "
+                                    "1: fill, 2: blit");
+}
+
 static const TypeInfo ati_vga_info = {
     .name = TYPE_ATI_VGA,
     .parent = TYPE_PCI_DEVICE,
     .instance_size = sizeof(ATIVGAState),
     .class_init = ati_vga_class_init,
+    .instance_init = ati_vga_init,
     .interfaces = (InterfaceInfo[]) {
           { INTERFACE_CONVENTIONAL_PCI_DEVICE },
           { },
diff --git a/hw/display/ati_2d.c b/hw/display/ati_2d.c
index 7d786653e8..0e6b8e4367 100644
--- a/hw/display/ati_2d.c
+++ b/hw/display/ati_2d.c
@@ -92,6 +92,7 @@ void ati_2d_blt(ATIVGAState *s)
     switch (s->regs.dp_mix & GMC_ROP3_MASK) {
     case ROP3_SRCCOPY:
     {
+        bool fallback = false;
         unsigned src_x = (s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT ?
                        s->regs.src_x : s->regs.src_x + 1 - s->regs.dst_width);
         unsigned src_y = (s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM ?
@@ -122,27 +123,50 @@ void ati_2d_blt(ATIVGAState *s)
                 src_bits, dst_bits, src_stride, dst_stride, bpp, bpp,
                 src_x, src_y, dst_x, dst_y,
                 s->regs.dst_width, s->regs.dst_height);
-        if (s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT &&
+        if ((s->use_pixman & BIT(1)) &&
+            s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT &&
             s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM) {
-            pixman_blt((uint32_t *)src_bits, (uint32_t *)dst_bits,
-                       src_stride, dst_stride, bpp, bpp,
-                       src_x, src_y, dst_x, dst_y,
-                       s->regs.dst_width, s->regs.dst_height);
-        } else {
+            fallback = !pixman_blt((uint32_t *)src_bits, (uint32_t *)dst_bits,
+                                   src_stride, dst_stride, bpp, bpp,
+                                   src_x, src_y, dst_x, dst_y,
+                                   s->regs.dst_width, s->regs.dst_height);
+        } else if (s->use_pixman & BIT(1)) {
             /* FIXME: We only really need a temporary if src and dst overlap */
             int llb = s->regs.dst_width * (bpp / 8);
             int tmp_stride = DIV_ROUND_UP(llb, sizeof(uint32_t));
             uint32_t *tmp = g_malloc(tmp_stride * sizeof(uint32_t) *
                                      s->regs.dst_height);
-            pixman_blt((uint32_t *)src_bits, tmp,
-                       src_stride, tmp_stride, bpp, bpp,
-                       src_x, src_y, 0, 0,
-                       s->regs.dst_width, s->regs.dst_height);
-            pixman_blt(tmp, (uint32_t *)dst_bits,
-                       tmp_stride, dst_stride, bpp, bpp,
-                       0, 0, dst_x, dst_y,
-                       s->regs.dst_width, s->regs.dst_height);
+            fallback = !pixman_blt((uint32_t *)src_bits, tmp,
+                                   src_stride, tmp_stride, bpp, bpp,
+                                   src_x, src_y, 0, 0,
+                                   s->regs.dst_width, s->regs.dst_height);
+            if (!fallback) {
+                fallback = !pixman_blt(tmp, (uint32_t *)dst_bits,
+                                       tmp_stride, dst_stride, bpp, bpp,
+                                       0, 0, dst_x, dst_y,
+                                       s->regs.dst_width, s->regs.dst_height);
+            }
             g_free(tmp);
+        } else {
+            fallback = true;
+        }
+        if (fallback) {
+            unsigned int y, i, j, bypp = bpp / 8;
+            unsigned int src_pitch = src_stride * sizeof(uint32_t);
+            unsigned int dst_pitch = dst_stride * sizeof(uint32_t);
+
+            for (y = 0; y < s->regs.dst_height; y++) {
+                i = dst_x * bypp;
+                j = src_x * bypp;
+                if (s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM) {
+                    i += (dst_y + y) * dst_pitch;
+                    j += (src_y + y) * src_pitch;
+                } else {
+                    i += (dst_y + s->regs.dst_height - 1 - y) * dst_pitch;
+                    j += (src_y + s->regs.dst_height - 1 - y) * src_pitch;
+                }
+                memmove(&dst_bits[i], &src_bits[j], s->regs.dst_width * bypp);
+            }
         }
         if (dst_bits >= s->vga.vram_ptr + s->vga.vbe_start_addr &&
             dst_bits < s->vga.vram_ptr + s->vga.vbe_start_addr +
@@ -180,14 +204,21 @@ void ati_2d_blt(ATIVGAState *s)
 
         dst_stride /= sizeof(uint32_t);
         DPRINTF("pixman_fill(%p, %d, %d, %d, %d, %d, %d, %x)\n",
-                dst_bits, dst_stride, bpp,
-                dst_x, dst_y,
-                s->regs.dst_width, s->regs.dst_height,
-                filler);
-        pixman_fill((uint32_t *)dst_bits, dst_stride, bpp,
-                    dst_x, dst_y,
-                    s->regs.dst_width, s->regs.dst_height,
-                    filler);
+                dst_bits, dst_stride, bpp, dst_x, dst_y,
+                s->regs.dst_width, s->regs.dst_height, filler);
+        if (!(s->use_pixman & BIT(0)) ||
+            !pixman_fill((uint32_t *)dst_bits, dst_stride, bpp, dst_x, dst_y,
+                    s->regs.dst_width, s->regs.dst_height, filler)) {
+            /* fallback when pixman failed or we don't want to call it */
+            unsigned int x, y, i, bypp = bpp / 8;
+            unsigned int dst_pitch = dst_stride * sizeof(uint32_t);
+            for (y = 0; y < s->regs.dst_height; y++) {
+                i = dst_x * bypp + (dst_y + y) * dst_pitch;
+                for (x = 0; x < s->regs.dst_width; x++, i += bypp) {
+                    stn_he_p(&dst_bits[i], bypp, filler);
+                }
+            }
+        }
         if (dst_bits >= s->vga.vram_ptr + s->vga.vbe_start_addr &&
             dst_bits < s->vga.vram_ptr + s->vga.vbe_start_addr +
             s->vga.vbe_regs[VBE_DISPI_INDEX_YRES] * s->vga.vbe_line_offset) {
diff --git a/hw/display/ati_int.h b/hw/display/ati_int.h
index e8d3c7af75..f03a21ff23 100644
--- a/hw/display/ati_int.h
+++ b/hw/display/ati_int.h
@@ -89,6 +89,7 @@ struct ATIVGAState {
     char *model;
     uint16_t dev_id;
     uint8_t mode;
+    uint8_t use_pixman;
     bool cursor_guest_mode;
     uint16_t cursor_size;
     uint32_t cursor_offset;
-- 
2.39.2



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

* [Stable-8.1.3 44/55] ui/gtk: force realization of drawing area
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (42 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 43/55] ati-vga: Implement fallback for pixman routines Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 45/55] ui/gtk-egl: apply scale factor when calculating window's dimension Michael Tokarev
                   ` (11 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Marc-André Lureau, Antonio Caggiano,
	Michael Tokarev

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Fixes the GL context creation from a widget that isn't yet realized (in
a hidden tab for example).

Resolves:
https://gitlab.com/qemu-project/qemu/-/issues/1727

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Antonio Caggiano <quic_acaggian@quicinc.com>
Message-Id: <20231017111642.1155545-1-marcandre.lureau@redhat.com>
(cherry picked from commit 565f85a9c293818a91a3d3414311303de7e00cec)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/ui/gtk.c b/ui/gtk.c
index 8ba41c8f13..cddbc46791 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2364,6 +2364,7 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     GdkDisplay *window_display;
     GtkIconTheme *theme;
     char *dir;
+    int idx;
 
     if (!gtkinit) {
         fprintf(stderr, "gtk initialization failed\n");
@@ -2426,6 +2427,15 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     gtk_container_add(GTK_CONTAINER(s->window), s->vbox);
 
     gtk_widget_show_all(s->window);
+
+    for (idx = 0;; idx++) {
+        QemuConsole *con = qemu_console_lookup_by_index(idx);
+        if (!con) {
+            break;
+        }
+        gtk_widget_realize(s->vc[idx].gfx.drawing_area);
+    }
+
     if (opts->u.gtk.has_show_menubar &&
         !opts->u.gtk.show_menubar) {
         gtk_widget_hide(s->menu_bar);
-- 
2.39.2



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

* [Stable-8.1.3 45/55] ui/gtk-egl: apply scale factor when calculating window's dimension
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (43 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 44/55] ui/gtk: force realization of drawing area Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 46/55] ui/gtk-egl: Check EGLSurface before doing scanout Michael Tokarev
                   ` (10 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Dongwon Kim, Marc-André Lureau, Michael Tokarev

From: Dongwon Kim <dongwon.kim@intel.com>

Scale factor needs to be applied when calculating width/height of the
GTK windows.

Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20231012222643.13996-1-dongwon.kim@intel.com>
(cherry picked from commit 47fd6ab1e334962890bc3e8d2e32857f6594e1c1)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index a1060fd80f..45c7544337 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -69,15 +69,16 @@ void gd_egl_draw(VirtualConsole *vc)
 #ifdef CONFIG_GBM
     QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
 #endif
-    int ww, wh;
+    int ww, wh, ws;
 
     if (!vc->gfx.gls) {
         return;
     }
 
     window = gtk_widget_get_window(vc->gfx.drawing_area);
-    ww = gdk_window_get_width(window);
-    wh = gdk_window_get_height(window);
+    ws = gdk_window_get_scale_factor(window);
+    ww = gdk_window_get_width(window) * ws;
+    wh = gdk_window_get_height(window) * ws;
 
     if (vc->gfx.scanout_mode) {
 #ifdef CONFIG_GBM
@@ -312,7 +313,7 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl,
 {
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
     GdkWindow *window;
-    int ww, wh;
+    int ww, wh, ws;
 
     if (!vc->gfx.scanout_mode) {
         return;
@@ -325,8 +326,9 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl,
                    vc->gfx.esurface, vc->gfx.ectx);
 
     window = gtk_widget_get_window(vc->gfx.drawing_area);
-    ww = gdk_window_get_width(window);
-    wh = gdk_window_get_height(window);
+    ws = gdk_window_get_scale_factor(window);
+    ww = gdk_window_get_width(window) * ws;
+    wh = gdk_window_get_height(window) * ws;
     egl_fb_setup_default(&vc->gfx.win_fb, ww, wh);
     if (vc->gfx.cursor_fb.texture) {
         egl_texture_blit(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.guest_fb,
-- 
2.39.2



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

* [Stable-8.1.3 46/55] ui/gtk-egl: Check EGLSurface before doing scanout
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (44 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 45/55] ui/gtk-egl: apply scale factor when calculating window's dimension Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 47/55] target/mips: Fix MSA BZ/BNZ opcodes displacement Michael Tokarev
                   ` (9 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Antonio Caggiano, Marc-André Lureau,
	Michael Tokarev

From: Antonio Caggiano <quic_acaggian@quicinc.com>

The first time gd_egl_scanout_texture() is called, there's a possibility
that the GTK drawing area might not be realized yet, in which case its
associated GdkWindow is NULL. This means gd_egl_init() was also skipped
and the EGLContext and EGLSurface stored in the VirtualGfxConsole are
not valid yet.

Continuing with the scanout in this conditions would result in hitting
an assert in libepoxy: "Couldn't find current GLX or EGL context".

A possible workaround is to just ignore the scanout request, giving the
the GTK drawing area some time to finish its realization. At that point,
the gd_egl_init() will succeed and the EGLContext and EGLSurface stored
in the VirtualGfxConsole will be valid.

Signed-off-by: Antonio Caggiano <quic_acaggian@quicinc.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20231016123215.2699269-1-quic_acaggian@quicinc.com>
(cherry picked from commit 6f189a08c1b0085808af1bfbf4567f0da193ecc1)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index 45c7544337..cd2f176502 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -244,12 +244,19 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,
     vc->gfx.h = h;
     vc->gfx.y0_top = backing_y_0_top;
 
-    eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
-                   vc->gfx.esurface, vc->gfx.ectx);
+    if (!vc->gfx.esurface) {
+        gd_egl_init(vc);
+        if (!vc->gfx.esurface) {
+            return;
+        }
+
+        eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
+                       vc->gfx.esurface, vc->gfx.ectx);
 
-    gtk_egl_set_scanout_mode(vc, true);
-    egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
-                         backing_id, false);
+        gtk_egl_set_scanout_mode(vc, true);
+        egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
+                             backing_id, false);
+    }
 }
 
 void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
-- 
2.39.2



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

* [Stable-8.1.3 47/55] target/mips: Fix MSA BZ/BNZ opcodes displacement
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (45 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 46/55] ui/gtk-egl: Check EGLSurface before doing scanout Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 48/55] target/mips: Fix TX79 LQ/SQ opcodes Michael Tokarev
                   ` (8 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Philippe Mathieu-Daudé, Sergey Evlashev,
	Richard Henderson, Michael Tokarev

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

The PC offset is *signed*.

Cc: qemu-stable@nongnu.org
Reported-by: Sergey Evlashev <vectorchiefrocks@gmail.com>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1624
Fixes: c7a9ef7517 ("target/mips: Introduce decode tree bindings for MSA ASE")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230914085807.12241-1-philmd@linaro.org>
(cherry picked from commit 04591b3ddd9a96b9298a1dd437a6464ab55e62ee)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/mips/tcg/msa.decode b/target/mips/tcg/msa.decode
index 9575289195..4410e2a02e 100644
--- a/target/mips/tcg/msa.decode
+++ b/target/mips/tcg/msa.decode
@@ -31,8 +31,8 @@
 
 @lsa                ...... rs:5 rt:5 rd:5 ... sa:2 ......   &r
 @ldst               ...... sa:s10 ws:5 wd:5 .... df:2       &msa_i
-@bz_v               ...... ... ..    wt:5 sa:16             &msa_bz df=3
-@bz                 ...... ...  df:2 wt:5 sa:16             &msa_bz
+@bz_v               ...... ... ..    wt:5 sa:s16            &msa_bz df=3
+@bz                 ...... ...  df:2 wt:5 sa:s16            &msa_bz
 @elm_df             ...... .... ......    ws:5 wd:5 ......  &msa_elm_df df=%elm_df n=%elm_n
 @elm                ...... ..........     ws:5 wd:5 ......  &msa_elm
 @vec                ...... .....     wt:5 ws:5 wd:5 ......  &msa_r df=0
-- 
2.39.2



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

* [Stable-8.1.3 48/55] target/mips: Fix TX79 LQ/SQ opcodes
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (46 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 47/55] target/mips: Fix MSA BZ/BNZ opcodes displacement Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 49/55] hw/ide: reset: cancel async DMA operation before resetting state Michael Tokarev
                   ` (7 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Philippe Mathieu-Daudé, Richard Henderson,
	Michael Tokarev

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

The base register address offset is *signed*.

Cc: qemu-stable@nongnu.org
Fixes: aaaa82a9f9 ("target/mips/tx79: Introduce LQ opcode (Load Quadword)")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230914090447.12557-1-philmd@linaro.org>
(cherry picked from commit 18f86aecd6a1bea0f78af14587a684ad966d8d3a)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/mips/tcg/tx79.decode b/target/mips/tcg/tx79.decode
index 57d87a2076..578b8c54c0 100644
--- a/target/mips/tcg/tx79.decode
+++ b/target/mips/tcg/tx79.decode
@@ -24,7 +24,7 @@
 @rs             ...... rs:5  ..... ..........  ......   &r sa=0      rt=0 rd=0
 @rd             ...... ..........  rd:5  ..... ......   &r sa=0 rs=0 rt=0
 
-@ldst            ...... base:5 rt:5 offset:16           &i
+@ldst            ...... base:5 rt:5 offset:s16          &i
 
 ###########################################################################
 
-- 
2.39.2



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

* [Stable-8.1.3 49/55] hw/ide: reset: cancel async DMA operation before resetting state
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (47 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 48/55] target/mips: Fix TX79 LQ/SQ opcodes Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 50/55] tests/qtest: ahci-test: add test exposing reset issue with pending callback Michael Tokarev
                   ` (6 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Fiona Ebner, Philippe Mathieu-Daudé, simon.rowe,
	Michael Tokarev

From: Fiona Ebner <f.ebner@proxmox.com>

If there is a pending DMA operation during ide_bus_reset(), the fact
that the IDEState is already reset before the operation is canceled
can be problematic. In particular, ide_dma_cb() might be called and
then use the reset IDEState which contains the signature after the
reset. When used to construct the IO operation this leads to
ide_get_sector() returning 0 and nsector being 1. This is particularly
bad, because a write command will thus destroy the first sector which
often contains a partition table or similar.

Traces showing the unsolicited write happening with IDEState
0x5595af6949d0 being used after reset:

> ahci_port_write ahci(0x5595af6923f0)[0]: port write [reg:PxSCTL] @ 0x2c: 0x00000300
> ahci_reset_port ahci(0x5595af6923f0)[0]: reset port
> ide_reset IDEstate 0x5595af6949d0
> ide_reset IDEstate 0x5595af694da8
> ide_bus_reset_aio aio_cancel
> dma_aio_cancel dbs=0x7f64600089a0
> dma_blk_cb dbs=0x7f64600089a0 ret=0
> dma_complete dbs=0x7f64600089a0 ret=0 cb=0x5595acd40b30
> ahci_populate_sglist ahci(0x5595af6923f0)[0]
> ahci_dma_prepare_buf ahci(0x5595af6923f0)[0]: prepare buf limit=512 prepared=512
> ide_dma_cb IDEState 0x5595af6949d0; sector_num=0 n=1 cmd=DMA WRITE
> dma_blk_io dbs=0x7f6420802010 bs=0x5595ae2c6c30 offset=0 to_dev=1
> dma_blk_cb dbs=0x7f6420802010 ret=0

> (gdb) p *qiov
> $11 = {iov = 0x7f647c76d840, niov = 1, {{nalloc = 1, local_iov = {iov_base = 0x0,
>       iov_len = 512}}, {__pad = "\001\000\000\000\000\000\000\000\000\000\000",
>       size = 512}}}
> (gdb) bt
> #0  blk_aio_pwritev (blk=0x5595ae2c6c30, offset=0, qiov=0x7f6420802070, flags=0,
>     cb=0x5595ace6f0b0 <dma_blk_cb>, opaque=0x7f6420802010)
>     at ../block/block-backend.c:1682
> #1  0x00005595ace6f185 in dma_blk_cb (opaque=0x7f6420802010, ret=<optimized out>)
>     at ../softmmu/dma-helpers.c:179
> #2  0x00005595ace6f778 in dma_blk_io (ctx=0x5595ae0609f0,
>     sg=sg@entry=0x5595af694d00, offset=offset@entry=0, align=align@entry=512,
>     io_func=io_func@entry=0x5595ace6ee30 <dma_blk_write_io_func>,
>     io_func_opaque=io_func_opaque@entry=0x5595ae2c6c30,
>     cb=0x5595acd40b30 <ide_dma_cb>, opaque=0x5595af6949d0,
>     dir=DMA_DIRECTION_TO_DEVICE) at ../softmmu/dma-helpers.c:244
> #3  0x00005595ace6f90a in dma_blk_write (blk=0x5595ae2c6c30,
>     sg=sg@entry=0x5595af694d00, offset=offset@entry=0, align=align@entry=512,
>     cb=cb@entry=0x5595acd40b30 <ide_dma_cb>, opaque=opaque@entry=0x5595af6949d0)
>     at ../softmmu/dma-helpers.c:280
> #4  0x00005595acd40e18 in ide_dma_cb (opaque=0x5595af6949d0, ret=<optimized out>)
>     at ../hw/ide/core.c:953
> #5  0x00005595ace6f319 in dma_complete (ret=0, dbs=0x7f64600089a0)
>     at ../softmmu/dma-helpers.c:107
> #6  dma_blk_cb (opaque=0x7f64600089a0, ret=0) at ../softmmu/dma-helpers.c:127
> #7  0x00005595ad12227d in blk_aio_complete (acb=0x7f6460005b10)
>     at ../block/block-backend.c:1527
> #8  blk_aio_complete (acb=0x7f6460005b10) at ../block/block-backend.c:1524
> #9  blk_aio_write_entry (opaque=0x7f6460005b10) at ../block/block-backend.c:1594
> #10 0x00005595ad258cfb in coroutine_trampoline (i0=<optimized out>,
>     i1=<optimized out>) at ../util/coroutine-ucontext.c:177

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: simon.rowe@nutanix.com
Message-ID: <20230906130922.142845-1-f.ebner@proxmox.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit 7d7512019fc40c577e2bdd61f114f31a9eb84a8e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 07971c0218..c3508acbb1 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2515,19 +2515,19 @@ static void ide_dummy_transfer_stop(IDEState *s)
 
 void ide_bus_reset(IDEBus *bus)
 {
-    bus->unit = 0;
-    bus->cmd = 0;
-    ide_reset(&bus->ifs[0]);
-    ide_reset(&bus->ifs[1]);
-    ide_clear_hob(bus);
-
-    /* pending async DMA */
+    /* pending async DMA - needs the IDEState before it is reset */
     if (bus->dma->aiocb) {
         trace_ide_bus_reset_aio();
         blk_aio_cancel(bus->dma->aiocb);
         bus->dma->aiocb = NULL;
     }
 
+    bus->unit = 0;
+    bus->cmd = 0;
+    ide_reset(&bus->ifs[0]);
+    ide_reset(&bus->ifs[1]);
+    ide_clear_hob(bus);
+
     /* reset dma provider too */
     if (bus->dma->ops->reset) {
         bus->dma->ops->reset(bus->dma);
-- 
2.39.2



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

* [Stable-8.1.3 50/55] tests/qtest: ahci-test: add test exposing reset issue with pending callback
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (48 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 49/55] hw/ide: reset: cancel async DMA operation before resetting state Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 51/55] target/s390x: Fix CLC corrupting cc_src Michael Tokarev
                   ` (5 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Fiona Ebner, Philippe Mathieu-Daudé,
	Michael Tokarev

From: Fiona Ebner <f.ebner@proxmox.com>

Before commit "hw/ide: reset: cancel async DMA operation before
resetting state", this test would fail, because a reset with a
pending write operation would lead to an unsolicited write to the
first sector of the disk.

The test writes a pattern to the beginning of the disk and verifies
that it is still intact after a reset with a pending operation. It
also checks that the pending operation actually completes correctly.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Message-ID: <20230906130922.142845-2-f.ebner@proxmox.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit cc610857bbd3551f4b86ae2299336b5d9aa0db2b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index abab761c26..2615c9f65c 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -1424,6 +1424,89 @@ static void test_reset(void)
     ahci_shutdown(ahci);
 }
 
+static void test_reset_pending_callback(void)
+{
+    AHCIQState *ahci;
+    AHCICommand *cmd;
+    uint8_t port;
+    uint64_t ptr1;
+    uint64_t ptr2;
+
+    int bufsize = 4 * 1024;
+    int speed = bufsize + (bufsize / 2);
+    int offset1 = 0;
+    int offset2 = bufsize / AHCI_SECTOR_SIZE;
+
+    g_autofree unsigned char *tx1 = g_malloc(bufsize);
+    g_autofree unsigned char *tx2 = g_malloc(bufsize);
+    g_autofree unsigned char *rx1 = g_malloc0(bufsize);
+    g_autofree unsigned char *rx2 = g_malloc0(bufsize);
+
+    /* Uses throttling to make test independent of specific environment. */
+    ahci = ahci_boot_and_enable("-drive if=none,id=drive0,file=%s,"
+                                "cache=writeback,format=%s,"
+                                "throttling.bps-write=%d "
+                                "-M q35 "
+                                "-device ide-hd,drive=drive0 ",
+                                tmp_path, imgfmt, speed);
+
+    port = ahci_port_select(ahci);
+    ahci_port_clear(ahci, port);
+
+    ptr1 = ahci_alloc(ahci, bufsize);
+    ptr2 = ahci_alloc(ahci, bufsize);
+
+    g_assert(ptr1 && ptr2);
+
+    /* Need two different patterns. */
+    do {
+        generate_pattern(tx1, bufsize, AHCI_SECTOR_SIZE);
+        generate_pattern(tx2, bufsize, AHCI_SECTOR_SIZE);
+    } while (memcmp(tx1, tx2, bufsize) == 0);
+
+    qtest_bufwrite(ahci->parent->qts, ptr1, tx1, bufsize);
+    qtest_bufwrite(ahci->parent->qts, ptr2, tx2, bufsize);
+
+    /* Write to beginning of disk to check it wasn't overwritten later. */
+    ahci_guest_io(ahci, port, CMD_WRITE_DMA_EXT, ptr1, bufsize, offset1);
+
+    /* Issue asynchronously to get a pending callback during reset. */
+    cmd = ahci_command_create(CMD_WRITE_DMA_EXT);
+    ahci_command_adjust(cmd, offset2, ptr2, bufsize, 0);
+    ahci_command_commit(ahci, cmd, port);
+    ahci_command_issue_async(ahci, cmd);
+
+    ahci_set(ahci, AHCI_GHC, AHCI_GHC_HR);
+
+    ahci_command_free(cmd);
+
+    /* Wait for throttled write to finish. */
+    sleep(1);
+
+    /* Start again. */
+    ahci_clean_mem(ahci);
+    ahci_pci_enable(ahci);
+    ahci_hba_enable(ahci);
+    port = ahci_port_select(ahci);
+    ahci_port_clear(ahci, port);
+
+    /* Read and verify. */
+    ahci_guest_io(ahci, port, CMD_READ_DMA_EXT, ptr1, bufsize, offset1);
+    qtest_bufread(ahci->parent->qts, ptr1, rx1, bufsize);
+    g_assert_cmphex(memcmp(tx1, rx1, bufsize), ==, 0);
+
+    ahci_guest_io(ahci, port, CMD_READ_DMA_EXT, ptr2, bufsize, offset2);
+    qtest_bufread(ahci->parent->qts, ptr2, rx2, bufsize);
+    g_assert_cmphex(memcmp(tx2, rx2, bufsize), ==, 0);
+
+    ahci_free(ahci, ptr1);
+    ahci_free(ahci, ptr2);
+
+    ahci_clean_mem(ahci);
+
+    ahci_shutdown(ahci);
+}
+
 static void test_ncq_simple(void)
 {
     AHCIQState *ahci;
@@ -1945,7 +2028,8 @@ int main(int argc, char **argv)
     qtest_add_func("/ahci/migrate/dma/halted", test_migrate_halted_dma);
 
     qtest_add_func("/ahci/max", test_max);
-    qtest_add_func("/ahci/reset", test_reset);
+    qtest_add_func("/ahci/reset/simple", test_reset);
+    qtest_add_func("/ahci/reset/pending_callback", test_reset_pending_callback);
 
     qtest_add_func("/ahci/io/ncq/simple", test_ncq_simple);
     qtest_add_func("/ahci/migrate/ncq/simple", test_migrate_ncq);
-- 
2.39.2



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

* [Stable-8.1.3 51/55] target/s390x: Fix CLC corrupting cc_src
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (49 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 50/55] tests/qtest: ahci-test: add test exposing reset issue with pending callback Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 52/55] tests/tcg/s390x: Test CLC with inaccessible second operand Michael Tokarev
                   ` (4 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Ilya Leoshkevich, Richard Henderson,
	David Hildenbrand, Thomas Huth, Michael Tokarev

From: Ilya Leoshkevich <iii@linux.ibm.com>

CLC updates cc_src before accessing the second operand; if the latter
is inaccessible, the former ends up containing a bogus value.

Fix by reading cc_src into a temporary first.

Fixes: 4f7403d52b1c ("target-s390: Convert CLC")
Closes: https://gitlab.com/qemu-project/qemu/-/issues/1865
Cc: qemu-stable@nongnu.org
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Message-ID: <20231106093605.1349201-2-iii@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit aba2ec341c6d20c8dc3e6ecf87fa7c1a71e30c1e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c
index dc7041e1d8..97ab1b3daa 100644
--- a/target/s390x/tcg/translate.c
+++ b/target/s390x/tcg/translate.c
@@ -2007,6 +2007,7 @@ static DisasJumpType op_cksm(DisasContext *s, DisasOps *o)
 static DisasJumpType op_clc(DisasContext *s, DisasOps *o)
 {
     int l = get_field(s, l1);
+    TCGv_i64 src;
     TCGv_i32 vl;
     MemOp mop;
 
@@ -2016,9 +2017,11 @@ static DisasJumpType op_clc(DisasContext *s, DisasOps *o)
     case 4:
     case 8:
         mop = ctz32(l + 1) | MO_TE;
-        tcg_gen_qemu_ld_tl(cc_src, o->addr1, get_mem_index(s), mop);
+        /* Do not update cc_src yet: loading cc_dst may cause an exception. */
+        src = tcg_temp_new_i64();
+        tcg_gen_qemu_ld_tl(src, o->addr1, get_mem_index(s), mop);
         tcg_gen_qemu_ld_tl(cc_dst, o->in2, get_mem_index(s), mop);
-        gen_op_update2_cc_i64(s, CC_OP_LTUGTU_64, cc_src, cc_dst);
+        gen_op_update2_cc_i64(s, CC_OP_LTUGTU_64, src, cc_dst);
         return DISAS_NEXT;
     default:
         vl = tcg_constant_i32(l);
-- 
2.39.2



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

* [Stable-8.1.3 52/55] tests/tcg/s390x: Test CLC with inaccessible second operand
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (50 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 51/55] target/s390x: Fix CLC corrupting cc_src Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 53/55] target/s390x: Fix LAALG not updating cc_src Michael Tokarev
                   ` (3 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Ilya Leoshkevich, Richard Henderson, Thomas Huth,
	Michael Tokarev

From: Ilya Leoshkevich <iii@linux.ibm.com>

Add a small test to prevent regressions.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20231106093605.1349201-3-iii@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit 43fecbe7a53fe8e5a6aff0d6471b1cc624e26b51)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 1fc9809907..3ddbde1a9d 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -41,6 +41,7 @@ TESTS+=larl
 TESTS+=mdeb
 TESTS+=cgebra
 TESTS+=clgebr
+TESTS+=clc
 
 cdsg: CFLAGS+=-pthread
 cdsg: LDFLAGS+=-pthread
diff --git a/tests/tcg/s390x/clc.c b/tests/tcg/s390x/clc.c
new file mode 100644
index 0000000000..e14189bd75
--- /dev/null
+++ b/tests/tcg/s390x/clc.c
@@ -0,0 +1,48 @@
+/*
+ * Test the CLC instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static void handle_sigsegv(int sig, siginfo_t *info, void *ucontext)
+{
+    mcontext_t *mcontext = &((ucontext_t *)ucontext)->uc_mcontext;
+    if (mcontext->gregs[0] != 600) {
+        write(STDERR_FILENO, "bad r0\n", 7);
+        _exit(EXIT_FAILURE);
+    }
+    if (((mcontext->psw.mask >> 44) & 3) != 1) {
+        write(STDERR_FILENO, "bad cc\n", 7);
+        _exit(EXIT_FAILURE);
+    }
+    _exit(EXIT_SUCCESS);
+}
+
+int main(void)
+{
+    register unsigned long r0 asm("r0");
+    unsigned long mem = 42, rhs = 500;
+    struct sigaction act;
+    int err;
+
+    memset(&act, 0, sizeof(act));
+    act.sa_sigaction = handle_sigsegv;
+    act.sa_flags = SA_SIGINFO;
+    err = sigaction(SIGSEGV, &act, NULL);
+    assert(err == 0);
+
+    r0 = 100;
+    asm("algr %[r0],%[rhs]\n"
+        "clc 0(8,%[mem]),0(0)\n"  /* The 2nd operand will cause a SEGV. */
+        : [r0] "+r" (r0)
+        : [mem] "r" (&mem)
+        , [rhs] "r" (rhs)
+        : "cc", "memory");
+
+    return EXIT_FAILURE;
+}
-- 
2.39.2



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

* [Stable-8.1.3 53/55] target/s390x: Fix LAALG not updating cc_src
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (51 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 52/55] tests/tcg/s390x: Test CLC with inaccessible second operand Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 54/55] tests/tcg/s390x: Test LAALG with negative cc_src Michael Tokarev
                   ` (2 subsequent siblings)
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Ilya Leoshkevich, David Hildenbrand,
	Richard Henderson, Thomas Huth, Michael Tokarev

From: Ilya Leoshkevich <iii@linux.ibm.com>

LAALG uses op_laa() and wout_addu64(). The latter expects cc_src to be
set, but the former does not do it. This can lead to assertion failures
if something sets cc_src to neither 0 nor 1 before.

Fix by introducing op_laa_addu64(), which sets cc_src, and using it for
LAALG.

Fixes: 4dba4d6fef61 ("target/s390x: Use atomic operations for LOAD AND OP")
Cc: qemu-stable@nongnu.org
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20231106093605.1349201-4-iii@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit bea402482a8c94389638cbd3d7fe3963fb317f4c)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/target/s390x/tcg/insn-data.h.inc b/target/s390x/tcg/insn-data.h.inc
index 0bfd88d3c3..2f07f39d9c 100644
--- a/target/s390x/tcg/insn-data.h.inc
+++ b/target/s390x/tcg/insn-data.h.inc
@@ -442,7 +442,7 @@
     D(0xebe8, LAAG,    RSY_a, ILA, r3, a2, new, in2_r1, laa, adds64, MO_TEUQ)
 /* LOAD AND ADD LOGICAL */
     D(0xebfa, LAAL,    RSY_a, ILA, r3_32u, a2, new, in2_r1_32, laa, addu32, MO_TEUL)
-    D(0xebea, LAALG,   RSY_a, ILA, r3, a2, new, in2_r1, laa, addu64, MO_TEUQ)
+    D(0xebea, LAALG,   RSY_a, ILA, r3, a2, new, in2_r1, laa_addu64, addu64, MO_TEUQ)
 /* LOAD AND AND */
     D(0xebf4, LAN,     RSY_a, ILA, r3_32s, a2, new, in2_r1_32, lan, nz32, MO_TESL)
     D(0xebe4, LANG,    RSY_a, ILA, r3, a2, new, in2_r1, lan, nz64, MO_TEUQ)
diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c
index 97ab1b3daa..d927e01c0c 100644
--- a/target/s390x/tcg/translate.c
+++ b/target/s390x/tcg/translate.c
@@ -2677,17 +2677,32 @@ static DisasJumpType op_kxb(DisasContext *s, DisasOps *o)
     return DISAS_NEXT;
 }
 
-static DisasJumpType op_laa(DisasContext *s, DisasOps *o)
+static DisasJumpType help_laa(DisasContext *s, DisasOps *o, bool addu64)
 {
     /* The real output is indeed the original value in memory;
        recompute the addition for the computation of CC.  */
     tcg_gen_atomic_fetch_add_i64(o->in2, o->in2, o->in1, get_mem_index(s),
                                  s->insn->data | MO_ALIGN);
     /* However, we need to recompute the addition for setting CC.  */
-    tcg_gen_add_i64(o->out, o->in1, o->in2);
+    if (addu64) {
+        tcg_gen_movi_i64(cc_src, 0);
+        tcg_gen_add2_i64(o->out, cc_src, o->in1, cc_src, o->in2, cc_src);
+    } else {
+        tcg_gen_add_i64(o->out, o->in1, o->in2);
+    }
     return DISAS_NEXT;
 }
 
+static DisasJumpType op_laa(DisasContext *s, DisasOps *o)
+{
+    return help_laa(s, o, false);
+}
+
+static DisasJumpType op_laa_addu64(DisasContext *s, DisasOps *o)
+{
+    return help_laa(s, o, true);
+}
+
 static DisasJumpType op_lan(DisasContext *s, DisasOps *o)
 {
     /* The real output is indeed the original value in memory;
-- 
2.39.2



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

* [Stable-8.1.3 54/55] tests/tcg/s390x: Test LAALG with negative cc_src
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (52 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 53/55] target/s390x: Fix LAALG not updating cc_src Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 13:42 ` [Stable-8.1.3 55/55] hw/ide/ahci: trigger either error IRQ or regular IRQ, not both Michael Tokarev
  2023-11-13 17:44 ` [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Daniel Henrique Barboza
  55 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Ilya Leoshkevich, Richard Henderson, Thomas Huth,
	Michael Tokarev

From: Ilya Leoshkevich <iii@linux.ibm.com>

Add a small test to prevent regressions.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20231106093605.1349201-5-iii@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit ebc14107f1f3ac1db13132cd28cf94adcd38e5d7)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 3ddbde1a9d..9325944cc7 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -42,6 +42,7 @@ TESTS+=mdeb
 TESTS+=cgebra
 TESTS+=clgebr
 TESTS+=clc
+TESTS+=laalg
 
 cdsg: CFLAGS+=-pthread
 cdsg: LDFLAGS+=-pthread
diff --git a/tests/tcg/s390x/laalg.c b/tests/tcg/s390x/laalg.c
new file mode 100644
index 0000000000..797d168bb1
--- /dev/null
+++ b/tests/tcg/s390x/laalg.c
@@ -0,0 +1,27 @@
+/*
+ * Test the LAALG instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdlib.h>
+
+int main(void)
+{
+    unsigned long cc = 0, op1, op2 = 40, op3 = 2;
+
+    asm("slgfi %[cc],1\n"  /* Set cc_src = -1. */
+        "laalg %[op1],%[op3],%[op2]\n"
+        "ipm %[cc]"
+        : [cc] "+r" (cc)
+        , [op1] "=r" (op1)
+        , [op2] "+T" (op2)
+        : [op3] "r" (op3)
+        : "cc");
+
+    assert(cc == 0xffffffff10ffffff);
+    assert(op1 == 40);
+    assert(op2 == 42);
+
+    return EXIT_SUCCESS;
+}
-- 
2.39.2



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

* [Stable-8.1.3 55/55] hw/ide/ahci: trigger either error IRQ or regular IRQ, not both
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (53 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 54/55] tests/tcg/s390x: Test LAALG with negative cc_src Michael Tokarev
@ 2023-11-09 13:42 ` Michael Tokarev
  2023-11-09 14:10   ` Michael Tokarev
  2023-11-13 17:44 ` [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Daniel Henrique Barboza
  55 siblings, 1 reply; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 13:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Niklas Cassel, Philippe Mathieu-Daudé,
	Kevin Wolf, Michael Tokarev

From: Niklas Cassel <niklas.cassel@wdc.com>

According to AHCI 1.3.1, 5.3.8.1 RegFIS:Entry, if ERR_STAT is set,
we jump to state ERR:FatalTaskfile, which will raise a TFES IRQ
unconditionally, regardless if the I bit is set in the FIS or not.

Thus, we should never raise a normal IRQ after having sent an error
IRQ.

NOTE: for QEMU platforms that use SeaBIOS, this patch depends on QEMU
commit 784155cdcb02 ("seabios: update submodule to git snapshot"), and
QEMU commit 14f5a7bae4cb ("seabios: update binaries to git snapshot"),
which update SeaBIOS to a version that contains SeaBIOS commit 1281e340
("ahci: handle TFES irq correctly").

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Message-ID: <20231011131220.1992064-1-nks@flawful.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit b523a3d54f3d031a54cd0931cc5d855608e63140)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index d0a774bc17..0cc538dfce 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -897,11 +897,10 @@ static bool ahci_write_fis_d2h(AHCIDevice *ad, bool d2h_fis_i)
     pr->tfdata = (ad->port.ifs[0].error << 8) |
         ad->port.ifs[0].status;
 
+    /* TFES IRQ is always raised if ERR_STAT is set, regardless of I bit. */
     if (d2h_fis[2] & ERR_STAT) {
         ahci_trigger_irq(ad->hba, ad, AHCI_PORT_IRQ_BIT_TFES);
-    }
-
-    if (d2h_fis_i) {
+    } else if (d2h_fis_i) {
         ahci_trigger_irq(ad->hba, ad, AHCI_PORT_IRQ_BIT_DHRS);
     }
 
-- 
2.39.2



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

* Re: [Stable-8.1.3 55/55] hw/ide/ahci: trigger either error IRQ or regular IRQ, not both
  2023-11-09 13:42 ` [Stable-8.1.3 55/55] hw/ide/ahci: trigger either error IRQ or regular IRQ, not both Michael Tokarev
@ 2023-11-09 14:10   ` Michael Tokarev
  0 siblings, 0 replies; 60+ messages in thread
From: Michael Tokarev @ 2023-11-09 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Niklas Cassel, Philippe Mathieu-Daudé,
	Kevin Wolf

09.11.2023 16:42, Michael Tokarev:
> From: Niklas Cassel <niklas.cassel@wdc.com>
> 
> According to AHCI 1.3.1, 5.3.8.1 RegFIS:Entry, if ERR_STAT is set,
> we jump to state ERR:FatalTaskfile, which will raise a TFES IRQ
> unconditionally, regardless if the I bit is set in the FIS or not.
> 
> Thus, we should never raise a normal IRQ after having sent an error
> IRQ.
> 
> NOTE: for QEMU platforms that use SeaBIOS, this patch depends on QEMU
> commit 784155cdcb02 ("seabios: update submodule to git snapshot"), and
> QEMU commit 14f5a7bae4cb ("seabios: update binaries to git snapshot"),
> which update SeaBIOS to a version that contains SeaBIOS commit 1281e340
> ("ahci: handle TFES irq correctly").

And as carefully stated in the commit message, this change should not
come alone without seabios fix.  I'll drop it from both stable series
for now.

/mjt


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

* Re: [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19
  2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
                   ` (54 preceding siblings ...)
  2023-11-09 13:42 ` [Stable-8.1.3 55/55] hw/ide/ahci: trigger either error IRQ or regular IRQ, not both Michael Tokarev
@ 2023-11-13 17:44 ` Daniel Henrique Barboza
  2023-11-13 18:01   ` Michael Tokarev
  55 siblings, 1 reply; 60+ messages in thread
From: Daniel Henrique Barboza @ 2023-11-13 17:44 UTC (permalink / raw)
  To: Michael Tokarev, qemu-devel; +Cc: qemu-stable

Hi Michael,

On 11/9/23 10:42, Michael Tokarev wrote:
> The following patches are queued for QEMU stable v8.1.3:
> 
>    https://gitlab.com/qemu-project/qemu/-/commits/staging-8.1
> 
> Patch freeze is 2023-11-19, and the release is planned for 2023-11-21:
> 
>    https://wiki.qemu.org/Planning/8.1
> 
> Please respond here or CC qemu-stable@nongnu.org on any additional patches
> you think should (or shouldn't) be included in the release.

It would be good to have these 2:

082e9e4a58 ("target/riscv/kvm: improve 'init_multiext_cfg' error msg")
608bdebb60 ("target/riscv/kvm: support KVM_GET_REG_LIST")

The first is an error msg fix. The second fixes a problem with KVM guests when
running Linux 6.6 and QEMU 8.1.


This is not a clear cherry-pick though. I'll send both in separate for you
convenience. Thanks,


Daniel

> 
> The changes which are staging for inclusion, with the original commit hash
> from master branch, are given below the bottom line.
> 
> Thanks!
> 
> /mjt
> 
> --------------------------------------
> 01 85fc35afa93c Yuval Shaia:
>     hw/pvrdma: Protect against buggy or malicious guest driver
> 02 caea03279e11 Fabiano Rosas:
>     migration: Fix analyze-migration read operation signedness
> 03 d4f34485ca8a Juan Quintela:
>     migration: Non multifd migration don't care about multifd flushes
> 04 acf873873ae3 John Snow:
>     python/qmp: remove Server.wait_closed() call for Python 3.12
> 05 a5e3cb3b90a6 Paolo Bonzini:
>     tests/docker: avoid invalid escape in Python string
> 06 e4b6532cc0a5 Paolo Bonzini:
>     docs/sphinx: avoid invalid escape in Python string
> 07 e41c40d101fc Paolo Bonzini:
>     target/hexagon: avoid invalid escape in Python string
> 08 1b5f3f65cc71 Paolo Bonzini:
>     tests/avocado: avoid invalid escape in Python string
> 09 86a8989d4557 Paolo Bonzini:
>     tests/vm: avoid invalid escape in Python string
> 10 e6d8e5e6e366 Paolo Bonzini:
>     tracetool: avoid invalid escape in Python string
> 11 e6e66b032873 Richard Henderson:
>     linux-user: Fixes for zero_bss
> 12 6fad9b4bb91d Mikulas Patocka:
>     linux-user/mips: fix abort on integer overflow
> 13 3b894b699c9a Mikulas Patocka:
>     linux-user/sh4: Fix crashes on signal delivery
> 14 a1e6a5c46219 Helge Deller:
>     lasips2: LASI PS/2 devices are not user-createable
> 15 d01448c79d89 Michal Orzel:
>     target/arm: Fix CNTPCT_EL0 trapping from EL0 when HCR_EL2.E2H is 0
> 16 ae5f70baf549 Lu Gao:
>     hw/sd/sdhci: Block Size Register bits [14:12] is lost
> 17 4ab9a7429bf7 Peter Maydell:
>     hw/rdma/vmw/pvrdma_cmd: Use correct struct in query_port()
> 18 930f1865cc65 Richard Henderson:
>     target/sparc: Clear may_lookup for npc == DYNAMIC_PC
> 19 307521d6e29e Peter Maydell:
>     target/arm: Fix syndrome for FGT traps on ERET
> 20 6f83dc67168d Glenn Miles:
>     misc/led: LED state is set opposite of what is expected
> 21 fed824501501 Kevin Wolf:
>     block: Fix locking in media change monitor commands
> 22 580731dcc87e Akihiko Odaki:
>     tests/tcg: Add -fno-stack-protector
> 23 8b097fd6b06e Andrey Drobyshev:
>     qemu-img: rebase: stop when reaching EOF of old backing file
> 24 827171c31805 Andrey Drobyshev:
>     qemu-iotests: 024: add rebasing test case for overlay_size > backing_size
> 25 b11293c212c2 Richard Henderson:
>     target/arm: Fix SVE STR increment
> 26 4c09abeae870 Peter Maydell:
>     target/arm: Correctly propagate stage 1 BTI guarded bit in a two-stage walk
> 27 721da0396cfa Cédric Le Goater:
>     util/uuid: Add UUID_STR_LEN definition
> 28 f8d6f3b16c37 Cédric Le Goater:
>     vfio/pci: Fix buffer overrun when writing the VF token
> 29 4ef9d97b1a37 Cédric Le Goater:
>     util/uuid: Remove UUID_FMT_LEN
> 30 e969f992c656 David Woodhouse:
>     i386/xen: Don't advertise XENFEAT_supervisor_mode_kernel
> 31 e7dbb62ff19c David Woodhouse:
>     i386/xen: fix per-vCPU upcall vector for Xen emulation
> 32 18e83f28bf39 David Woodhouse:
>     hw/xen: select kernel mode for per-vCPU event channel upcall vector
> 33 3de75ed35241 David Woodhouse:
>     hw/xen: don't clear map_track[] in xen_gnttab_reset()
> 34 4a5780f52095 David Woodhouse:
>     hw/xen: fix XenStore watch delivery to guest
> 35 debc995e883b David Woodhouse:
>     hw/xen: take iothread mutex in xen_evtchn_reset_op()
> 36 a1c1082908dd David Woodhouse:
>     hw/xen: use correct default protocol for xen-block on x86
> 37 9c549ab6895a Marc-André Lureau:
>     virtio-gpu: block migration of VMs with blob=true
> 38 cc8fb0c3ae3c Vladimir Sementsov-Ogievskiy:
>     block/nvme: nvme_process_completion() fix bound for cid
> 39 5722fc471296 Peter Maydell:
>     target/arm: Fix A64 LDRA immediate decode
> 40 b2b109041ecd Jean-Louis Dupond:
>     qcow2: keep reference on zeroize with discard-no-unref enabled
> 41 10b9e0802a07 Sam Li:
>     block/file-posix: fix update_zones_wp() caller
> 42 ad4feaca61d7 Naohiro Aota:
>     file-posix: fix over-writing of returning zone_append offset
> 43 08730ee0cc01 BALATON Zoltan:
>     ati-vga: Implement fallback for pixman routines
> 44 565f85a9c293 Marc-André Lureau:
>     ui/gtk: force realization of drawing area
> 45 47fd6ab1e334 Dongwon Kim:
>     ui/gtk-egl: apply scale factor when calculating window's dimension
> 46 6f189a08c1b0 Antonio Caggiano:
>     ui/gtk-egl: Check EGLSurface before doing scanout
> 47 04591b3ddd9a Philippe Mathieu-Daudé:
>     target/mips: Fix MSA BZ/BNZ opcodes displacement
> 48 18f86aecd6a1 Philippe Mathieu-Daudé:
>     target/mips: Fix TX79 LQ/SQ opcodes
> 49 7d7512019fc4 Fiona Ebner:
>     hw/ide: reset: cancel async DMA operation before resetting state
> 50 cc610857bbd3 Fiona Ebner:
>     tests/qtest: ahci-test: add test exposing reset issue with pending callback
> 51 aba2ec341c6d Ilya Leoshkevich:
>     target/s390x: Fix CLC corrupting cc_src
> 52 43fecbe7a53f Ilya Leoshkevich:
>     tests/tcg/s390x: Test CLC with inaccessible second operand
> 53 bea402482a8c Ilya Leoshkevich:
>     target/s390x: Fix LAALG not updating cc_src
> 54 ebc14107f1f3 Ilya Leoshkevich:
>     tests/tcg/s390x: Test LAALG with negative cc_src
> 55 b523a3d54f3d Niklas Cassel:
>     hw/ide/ahci: trigger either error IRQ or regular IRQ, not both
> 


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

* Re: [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19
  2023-11-13 17:44 ` [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Daniel Henrique Barboza
@ 2023-11-13 18:01   ` Michael Tokarev
  2023-11-13 18:27     ` Daniel Henrique Barboza
  0 siblings, 1 reply; 60+ messages in thread
From: Michael Tokarev @ 2023-11-13 18:01 UTC (permalink / raw)
  To: Daniel Henrique Barboza, qemu-devel; +Cc: qemu-stable

13.11.2023 20:44, Daniel Henrique Barboza wrote:

> It would be good to have these 2:
> 
> 082e9e4a58 ("target/riscv/kvm: improve 'init_multiext_cfg' error msg")
> 608bdebb60 ("target/riscv/kvm: support KVM_GET_REG_LIST")
> 
> The first is an error msg fix. The second fixes a problem with KVM guests when
> running Linux 6.6 and QEMU 8.1.

Sure.

> This is not a clear cherry-pick though. I'll send both in separate for you
> convenience. Thanks,

Actually both are trivial to cherry-pick. First is a clear c-p, second needs
a trivial context fix (where in the file to place the new functions, that's
kvm_riscv_init_user_properties() thing).  The rest goes as-is.

I've picked up both.  Thank you!

/mjt


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

* Re: [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19
  2023-11-13 18:01   ` Michael Tokarev
@ 2023-11-13 18:27     ` Daniel Henrique Barboza
  0 siblings, 0 replies; 60+ messages in thread
From: Daniel Henrique Barboza @ 2023-11-13 18:27 UTC (permalink / raw)
  To: Michael Tokarev, qemu-devel; +Cc: qemu-stable



On 11/13/23 15:01, Michael Tokarev wrote:
> 13.11.2023 20:44, Daniel Henrique Barboza wrote:
> 
>> It would be good to have these 2:
>>
>> 082e9e4a58 ("target/riscv/kvm: improve 'init_multiext_cfg' error msg")
>> 608bdebb60 ("target/riscv/kvm: support KVM_GET_REG_LIST")
>>
>> The first is an error msg fix. The second fixes a problem with KVM guests when
>> running Linux 6.6 and QEMU 8.1.
> 
> Sure.
> 
>> This is not a clear cherry-pick though. I'll send both in separate for you
>> convenience. Thanks,
> 
> Actually both are trivial to cherry-pick. First is a clear c-p, second needs
> a trivial context fix (where in the file to place the new functions, that's
> kvm_riscv_init_user_properties() thing).  The rest goes as-is.

Yeah, it's not a clean cherry-pick but it's trivial enough.


> 
> I've picked up both.  Thank you!

Thanks!


Daniel

> 
> /mjt


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

end of thread, other threads:[~2023-11-13 18:28 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-09 13:42 [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 01/55] hw/pvrdma: Protect against buggy or malicious guest driver Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 02/55] migration: Fix analyze-migration read operation signedness Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 03/55] migration: Non multifd migration don't care about multifd flushes Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 04/55] python/qmp: remove Server.wait_closed() call for Python 3.12 Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 05/55] tests/docker: avoid invalid escape in Python string Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 06/55] docs/sphinx: " Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 07/55] target/hexagon: " Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 08/55] tests/avocado: " Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 09/55] tests/vm: " Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 10/55] tracetool: " Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 11/55] linux-user: Fixes for zero_bss Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 12/55] linux-user/mips: fix abort on integer overflow Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 13/55] linux-user/sh4: Fix crashes on signal delivery Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 14/55] lasips2: LASI PS/2 devices are not user-createable Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 15/55] target/arm: Fix CNTPCT_EL0 trapping from EL0 when HCR_EL2.E2H is 0 Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 16/55] hw/sd/sdhci: Block Size Register bits [14:12] is lost Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 17/55] hw/rdma/vmw/pvrdma_cmd: Use correct struct in query_port() Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 18/55] target/sparc: Clear may_lookup for npc == DYNAMIC_PC Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 19/55] target/arm: Fix syndrome for FGT traps on ERET Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 20/55] misc/led: LED state is set opposite of what is expected Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 21/55] block: Fix locking in media change monitor commands Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 22/55] tests/tcg: Add -fno-stack-protector Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 23/55] qemu-img: rebase: stop when reaching EOF of old backing file Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 24/55] qemu-iotests: 024: add rebasing test case for overlay_size > backing_size Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 25/55] target/arm: Fix SVE STR increment Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 26/55] target/arm: Correctly propagate stage 1 BTI guarded bit in a two-stage walk Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 27/55] util/uuid: Add UUID_STR_LEN definition Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 28/55] vfio/pci: Fix buffer overrun when writing the VF token Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 29/55] util/uuid: Remove UUID_FMT_LEN Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 30/55] i386/xen: Don't advertise XENFEAT_supervisor_mode_kernel Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 31/55] i386/xen: fix per-vCPU upcall vector for Xen emulation Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 32/55] hw/xen: select kernel mode for per-vCPU event channel upcall vector Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 33/55] hw/xen: don't clear map_track[] in xen_gnttab_reset() Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 34/55] hw/xen: fix XenStore watch delivery to guest Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 35/55] hw/xen: take iothread mutex in xen_evtchn_reset_op() Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 36/55] hw/xen: use correct default protocol for xen-block on x86 Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 37/55] virtio-gpu: block migration of VMs with blob=true Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 38/55] block/nvme: nvme_process_completion() fix bound for cid Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 39/55] target/arm: Fix A64 LDRA immediate decode Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 40/55] qcow2: keep reference on zeroize with discard-no-unref enabled Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 41/55] block/file-posix: fix update_zones_wp() caller Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 42/55] file-posix: fix over-writing of returning zone_append offset Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 43/55] ati-vga: Implement fallback for pixman routines Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 44/55] ui/gtk: force realization of drawing area Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 45/55] ui/gtk-egl: apply scale factor when calculating window's dimension Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 46/55] ui/gtk-egl: Check EGLSurface before doing scanout Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 47/55] target/mips: Fix MSA BZ/BNZ opcodes displacement Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 48/55] target/mips: Fix TX79 LQ/SQ opcodes Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 49/55] hw/ide: reset: cancel async DMA operation before resetting state Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 50/55] tests/qtest: ahci-test: add test exposing reset issue with pending callback Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 51/55] target/s390x: Fix CLC corrupting cc_src Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 52/55] tests/tcg/s390x: Test CLC with inaccessible second operand Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 53/55] target/s390x: Fix LAALG not updating cc_src Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 54/55] tests/tcg/s390x: Test LAALG with negative cc_src Michael Tokarev
2023-11-09 13:42 ` [Stable-8.1.3 55/55] hw/ide/ahci: trigger either error IRQ or regular IRQ, not both Michael Tokarev
2023-11-09 14:10   ` Michael Tokarev
2023-11-13 17:44 ` [Stable-8.1.3 00/55] Patch Round-up for stable 8.1.3, freeze on 2023-11-19 Daniel Henrique Barboza
2023-11-13 18:01   ` Michael Tokarev
2023-11-13 18:27     ` Daniel Henrique Barboza

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).