* [Stable-8.0.5 59/70] include/exec: Provide the tswap() functions for target independent code, too
2023-09-20 12:18 [Stable-8.0.5 00/70] v3 Patch Round-up for stable 8.0.5, freeze on 2023-09-19 Michael Tokarev
@ 2023-09-20 12:18 ` Michael Tokarev
2023-09-20 12:18 ` [Stable-8.0.5 68/70] ui: fix crash when there are no active_console Michael Tokarev
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Michael Tokarev @ 2023-09-20 12:18 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Thomas Huth, Richard Henderson,
Cédric Le Goater, Michael Tokarev
From: Thomas Huth <thuth@redhat.com>
In some cases of target independent code, it would be useful to have access
to the functions that swap endianess in case it differs between guest and
host. Thus re-implement the tswapXX() functions in a new header that can be
included separately. The check whether the swapping is needed continues to
be done at compile-time for target specific code, while it is done at
run-time in target-independent code.
Message-Id: <20230411183418.1640500-3-thuth@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit 24be3369ad63c3882be42dd510a45bad52816fd1)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
(trivial change needed for the next commit 058096f1c5
"hw/char/riscv_htif: Fix the console syscall on big endian hosts")
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 090922e4a8..ad824fee52 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -21,6 +21,7 @@
#include "exec/cpu-common.h"
#include "exec/memory.h"
+#include "exec/tswap.h"
#include "qemu/thread.h"
#include "hw/core/cpu.h"
#include "qemu/rcu.h"
@@ -44,69 +45,6 @@
#define BSWAP_NEEDED
#endif
-#ifdef BSWAP_NEEDED
-
-static inline uint16_t tswap16(uint16_t s)
-{
- return bswap16(s);
-}
-
-static inline uint32_t tswap32(uint32_t s)
-{
- return bswap32(s);
-}
-
-static inline uint64_t tswap64(uint64_t s)
-{
- return bswap64(s);
-}
-
-static inline void tswap16s(uint16_t *s)
-{
- *s = bswap16(*s);
-}
-
-static inline void tswap32s(uint32_t *s)
-{
- *s = bswap32(*s);
-}
-
-static inline void tswap64s(uint64_t *s)
-{
- *s = bswap64(*s);
-}
-
-#else
-
-static inline uint16_t tswap16(uint16_t s)
-{
- return s;
-}
-
-static inline uint32_t tswap32(uint32_t s)
-{
- return s;
-}
-
-static inline uint64_t tswap64(uint64_t s)
-{
- return s;
-}
-
-static inline void tswap16s(uint16_t *s)
-{
-}
-
-static inline void tswap32s(uint32_t *s)
-{
-}
-
-static inline void tswap64s(uint64_t *s)
-{
-}
-
-#endif
-
#if TARGET_LONG_SIZE == 4
#define tswapl(s) tswap32(s)
#define tswapls(s) tswap32s((uint32_t *)(s))
diff --git a/include/exec/tswap.h b/include/exec/tswap.h
new file mode 100644
index 0000000000..68944a880b
--- /dev/null
+++ b/include/exec/tswap.h
@@ -0,0 +1,72 @@
+/*
+ * Macros for swapping a value if the endianness is different
+ * between the target and the host.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef TSWAP_H
+#define TSWAP_H
+
+#include "hw/core/cpu.h"
+#include "qemu/bswap.h"
+
+/*
+ * If we're in target-specific code, we can hard-code the swapping
+ * condition, otherwise we have to do (slower) run-time checks.
+ */
+#ifdef NEED_CPU_H
+#define target_needs_bswap() (HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN)
+#else
+#define target_needs_bswap() (target_words_bigendian() != HOST_BIG_ENDIAN)
+#endif
+
+static inline uint16_t tswap16(uint16_t s)
+{
+ if (target_needs_bswap()) {
+ return bswap16(s);
+ } else {
+ return s;
+ }
+}
+
+static inline uint32_t tswap32(uint32_t s)
+{
+ if (target_needs_bswap()) {
+ return bswap32(s);
+ } else {
+ return s;
+ }
+}
+
+static inline uint64_t tswap64(uint64_t s)
+{
+ if (target_needs_bswap()) {
+ return bswap64(s);
+ } else {
+ return s;
+ }
+}
+
+static inline void tswap16s(uint16_t *s)
+{
+ if (target_needs_bswap()) {
+ *s = bswap16(*s);
+ }
+}
+
+static inline void tswap32s(uint32_t *s)
+{
+ if (target_needs_bswap()) {
+ *s = bswap32(*s);
+ }
+}
+
+static inline void tswap64s(uint64_t *s)
+{
+ if (target_needs_bswap()) {
+ *s = bswap64(*s);
+ }
+}
+
+#endif /* TSWAP_H */
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Stable-8.0.5 68/70] ui: fix crash when there are no active_console
2023-09-20 12:18 [Stable-8.0.5 00/70] v3 Patch Round-up for stable 8.0.5, freeze on 2023-09-19 Michael Tokarev
2023-09-20 12:18 ` [Stable-8.0.5 59/70] include/exec: Provide the tswap() functions for target independent code, too Michael Tokarev
@ 2023-09-20 12:18 ` Michael Tokarev
2023-09-20 12:18 ` [Stable-8.0.5 69/70] s390x/ap: fix missing subsystem reset registration Michael Tokarev
2023-09-20 12:18 ` [Stable-8.0.5 70/70] tpm: fix crash when FD >= 1024 and unnecessary errors due to EINTR Michael Tokarev
3 siblings, 0 replies; 5+ messages in thread
From: Michael Tokarev @ 2023-09-20 12:18 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Marc-André Lureau, Albert Esteve,
Michael Tokarev
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.
0x0000555555888630 in dpy_ui_info_supported (con=0x0) at ../ui/console.c:812
812 return con->hw_ops->ui_info != NULL;
(gdb) bt
#0 0x0000555555888630 in dpy_ui_info_supported (con=0x0) at ../ui/console.c:812
#1 0x00005555558a44b1 in protocol_client_msg (vs=0x5555578c76c0, data=0x5555581e93f0 <incomplete sequence \373>, len=24) at ../ui/vnc.c:2585
#2 0x00005555558a19ac in vnc_client_read (vs=0x5555578c76c0) at ../ui/vnc.c:1607
#3 0x00005555558a1ac2 in vnc_client_io (ioc=0x5555581eb0e0, condition=G_IO_IN, opaque=0x5555578c76c0) at ../ui/vnc.c:1635
Fixes:
https://issues.redhat.com/browse/RHEL-2600
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Albert Esteve <aesteve@redhat.com>
(cherry picked from commit 48a35e12faf90a896c5aa4755812201e00d60316)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/ui/console.c b/ui/console.c
index 7461446e71..a327c9f94a 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1707,6 +1707,9 @@ bool dpy_ui_info_supported(QemuConsole *con)
if (con == NULL) {
con = active_console;
}
+ if (con == NULL) {
+ return false;
+ }
return con->hw_ops->ui_info != NULL;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Stable-8.0.5 69/70] s390x/ap: fix missing subsystem reset registration
2023-09-20 12:18 [Stable-8.0.5 00/70] v3 Patch Round-up for stable 8.0.5, freeze on 2023-09-19 Michael Tokarev
2023-09-20 12:18 ` [Stable-8.0.5 59/70] include/exec: Provide the tswap() functions for target independent code, too Michael Tokarev
2023-09-20 12:18 ` [Stable-8.0.5 68/70] ui: fix crash when there are no active_console Michael Tokarev
@ 2023-09-20 12:18 ` Michael Tokarev
2023-09-20 12:18 ` [Stable-8.0.5 70/70] tpm: fix crash when FD >= 1024 and unnecessary errors due to EINTR Michael Tokarev
3 siblings, 0 replies; 5+ messages in thread
From: Michael Tokarev @ 2023-09-20 12:18 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Janosch Frank, Jason J . Herne, Tony Krowiak,
Thomas Huth, Michael Tokarev
From: Janosch Frank <frankja@linux.ibm.com>
A subsystem reset contains a reset of AP resources which has been
missing. Adding the AP bridge to the list of device types that need
reset fixes this issue.
Reviewed-by: Jason J. Herne <jjherne@linux.ibm.com>
Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Fixes: a51b3153 ("s390x/ap: base Adjunct Processor (AP) object model")
Message-ID: <20230823142219.1046522-2-seiden@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit 297ec01f0b9864ea8209ca0ddc6643b4c0574bdb)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 0daf445d60..ea048e4667 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -109,6 +109,7 @@ static const char *const reset_dev_types[] = {
"s390-flic",
"diag288",
TYPE_S390_PCI_HOST_BRIDGE,
+ TYPE_AP_BRIDGE,
};
static void subsystem_reset(void)
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Stable-8.0.5 70/70] tpm: fix crash when FD >= 1024 and unnecessary errors due to EINTR
2023-09-20 12:18 [Stable-8.0.5 00/70] v3 Patch Round-up for stable 8.0.5, freeze on 2023-09-19 Michael Tokarev
` (2 preceding siblings ...)
2023-09-20 12:18 ` [Stable-8.0.5 69/70] s390x/ap: fix missing subsystem reset registration Michael Tokarev
@ 2023-09-20 12:18 ` Michael Tokarev
3 siblings, 0 replies; 5+ messages in thread
From: Michael Tokarev @ 2023-09-20 12:18 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Marc-André Lureau, Michael Tokarev,
Stefan Berger
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Replace select() with poll() to fix a crash when QEMU has a large number
of FDs. Also use RETRY_ON_EINTR to avoid unnecessary errors due to EINTR.
Cc: qemu-stable@nongnu.org
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2020133
Fixes: 56a3c24ffc ("tpm: Probe for connected TPM 1.2 or TPM 2")
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
(cherry picked from commit 8e32ddff69b6b4547cc00592ad816484e160817a)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/backends/tpm/tpm_util.c b/backends/tpm/tpm_util.c
index a6e6d3e72f..1856589c3b 100644
--- a/backends/tpm/tpm_util.c
+++ b/backends/tpm/tpm_util.c
@@ -112,12 +112,8 @@ static int tpm_util_request(int fd,
void *response,
size_t responselen)
{
- fd_set readfds;
+ GPollFD fds[1] = { {.fd = fd, .events = G_IO_IN } };
int n;
- struct timeval tv = {
- .tv_sec = 1,
- .tv_usec = 0,
- };
n = write(fd, request, requestlen);
if (n < 0) {
@@ -127,11 +123,8 @@ static int tpm_util_request(int fd,
return -EFAULT;
}
- FD_ZERO(&readfds);
- FD_SET(fd, &readfds);
-
/* wait for a second */
- n = select(fd + 1, &readfds, NULL, NULL, &tv);
+ n = RETRY_ON_EINTR(g_poll(fds, 1, 1000));
if (n != 1) {
return -errno;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread