1
Handful of bugfixes for rc2. None of these are particularly critical
1
It's been quiet on the arm front this week, so all I have is
2
or exciting.
2
these coverity fixes I posted a while back...
3
3
4
-- PMM
4
-- PMM
5
5
6
The following changes since commit 45a150aa2b3492acf6691c7bdbeb25a8545d8345:
6
The following changes since commit 853546f8128476eefb701d4a55b2781bb3a46faa:
7
7
8
Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-08-03' into staging (2020-08-03 15:13:49 +0100)
8
Merge tag 'pull-loongarch-20240322' of https://gitlab.com/gaosong/qemu into staging (2024-03-22 10:59:57 +0000)
9
9
10
are available in the Git repository at:
10
are available in the Git repository at:
11
11
12
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200803
12
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20240325
13
13
14
for you to fetch changes up to 13557fd392890cbd985bceba7f717e01efd674b8:
14
for you to fetch changes up to 55c79639d553c1b7a82b4cde781ad5f316f45b0e:
15
15
16
hw/timer/imx_epit: Avoid assertion when CR.SWR is written (2020-08-03 17:56:11 +0100)
16
tests/qtest/libqtest.c: Check for g_setenv() failure (2024-03-25 10:41:01 +0000)
17
17
18
----------------------------------------------------------------
18
----------------------------------------------------------------
19
target-arm queue:
19
target-arm queue:
20
* hw/timer/imx_epit: Avoid assertion when CR.SWR is written
20
* Fixes for seven minor coverity issues
21
* netduino2, netduinoplus2, microbit: set system_clock_scale so that
22
SysTick running on the CPU clock works
23
* target/arm: Avoid maybe-uninitialized warning with gcc 4.9
24
* target/arm: Fix AddPAC error indication
25
* Make AIRCR.SYSRESETREQ actually reset the system for the
26
microbit, mps2-*, musca-*, netduino* boards
27
21
28
----------------------------------------------------------------
22
----------------------------------------------------------------
29
Kaige Li (1):
23
Peter Maydell (7):
30
target/arm: Avoid maybe-uninitialized warning with gcc 4.9
24
tests/qtest/npcm7xx_emc_test: Don't leak cmd_line
25
tests/unit/socket-helpers: Don't close(-1)
26
net/af-xdp.c: Don't leak sock_fds array in net_init_af_xdp()
27
hw/misc/pca9554: Correct error check bounds in get/set pin functions
28
hw/nvram/mac_nvram: Report failure to write data
29
tests/unit/test-throttle: Avoid unintended integer division
30
tests/qtest/libqtest.c: Check for g_setenv() failure
31
31
32
Peter Maydell (6):
32
hw/misc/pca9554.c | 4 ++--
33
hw/arm/netduino2, netduinoplus2: Set system_clock_scale
33
hw/nvram/mac_nvram.c | 5 ++++-
34
include/hw/irq.h: New function qemu_irq_is_connected()
34
net/af-xdp.c | 3 +--
35
hw/intc/armv7m_nvic: Provide default "reset the system" behaviour for SYSRESETREQ
35
tests/qtest/libqtest.c | 6 +++++-
36
msf2-soc, stellaris: Don't wire up SYSRESETREQ
36
tests/qtest/npcm7xx_emc-test.c | 4 ++--
37
hw/arm/nrf51_soc: Set system_clock_scale
37
tests/unit/socket-helpers.c | 4 +++-
38
hw/timer/imx_epit: Avoid assertion when CR.SWR is written
38
tests/unit/test-throttle.c | 4 ++--
39
39
7 files changed, 19 insertions(+), 11 deletions(-)
40
Richard Henderson (1):
41
target/arm: Fix AddPAC error indication
42
43
include/hw/arm/armv7m.h | 4 +++-
44
include/hw/irq.h | 18 ++++++++++++++++++
45
hw/arm/msf2-soc.c | 11 -----------
46
hw/arm/netduino2.c | 10 ++++++++++
47
hw/arm/netduinoplus2.c | 10 ++++++++++
48
hw/arm/nrf51_soc.c | 5 +++++
49
hw/arm/stellaris.c | 12 ------------
50
hw/intc/armv7m_nvic.c | 17 ++++++++++++++++-
51
hw/timer/imx_epit.c | 13 ++++++++++---
52
target/arm/pauth_helper.c | 6 +++++-
53
target/arm/translate-a64.c | 2 +-
54
tests/tcg/aarch64/pauth-5.c | 33 +++++++++++++++++++++++++++++++++
55
tests/tcg/aarch64/Makefile.target | 2 +-
56
13 files changed, 112 insertions(+), 31 deletions(-)
57
create mode 100644 tests/tcg/aarch64/pauth-5.c
58
diff view generated by jsdifflib
Deleted patch
1
The netduino2 and netduinoplus2 boards forgot to set the system_clock_scale
2
global, which meant that if guest code used the systick timer in "use
3
the processor clock" mode it would hang because time never advances.
4
1
5
Set the global to match the documented CPU clock speed of these boards.
6
Judging by the data sheet this is slightly simplistic because the
7
SoC allows configuration of the SYSCLK source and frequency via the
8
RCC (reset and clock control) module, but we don't model that.
9
10
Fixes: https://bugs.launchpad.net/qemu/+bug/1876187
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Message-id: 20200727162617.26227-1-peter.maydell@linaro.org
14
---
15
hw/arm/netduino2.c | 10 ++++++++++
16
hw/arm/netduinoplus2.c | 10 ++++++++++
17
2 files changed, 20 insertions(+)
18
19
diff --git a/hw/arm/netduino2.c b/hw/arm/netduino2.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/arm/netduino2.c
22
+++ b/hw/arm/netduino2.c
23
@@ -XXX,XX +XXX,XX @@
24
#include "hw/arm/stm32f205_soc.h"
25
#include "hw/arm/boot.h"
26
27
+/* Main SYSCLK frequency in Hz (120MHz) */
28
+#define SYSCLK_FRQ 120000000ULL
29
+
30
static void netduino2_init(MachineState *machine)
31
{
32
DeviceState *dev;
33
34
+ /*
35
+ * TODO: ideally we would model the SoC RCC and let it handle
36
+ * system_clock_scale, including its ability to define different
37
+ * possible SYSCLK sources.
38
+ */
39
+ system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ;
40
+
41
dev = qdev_new(TYPE_STM32F205_SOC);
42
qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m3"));
43
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
44
diff --git a/hw/arm/netduinoplus2.c b/hw/arm/netduinoplus2.c
45
index XXXXXXX..XXXXXXX 100644
46
--- a/hw/arm/netduinoplus2.c
47
+++ b/hw/arm/netduinoplus2.c
48
@@ -XXX,XX +XXX,XX @@
49
#include "hw/arm/stm32f405_soc.h"
50
#include "hw/arm/boot.h"
51
52
+/* Main SYSCLK frequency in Hz (168MHz) */
53
+#define SYSCLK_FRQ 168000000ULL
54
+
55
static void netduinoplus2_init(MachineState *machine)
56
{
57
DeviceState *dev;
58
59
+ /*
60
+ * TODO: ideally we would model the SoC RCC and let it handle
61
+ * system_clock_scale, including its ability to define different
62
+ * possible SYSCLK sources.
63
+ */
64
+ system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ;
65
+
66
dev = qdev_new(TYPE_STM32F405_SOC);
67
qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m4"));
68
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
69
--
70
2.20.1
71
72
diff view generated by jsdifflib
1
The imx_epit device has a software-controllable reset triggered by
1
In test_rx() and test_tx() we allocate a GString *cmd_line
2
setting the SWR bit in the CR register. An error in commit cc2722ec83ad9
2
but never free it. This is pretty harmless in a test case, but
3
means that we will end up assert()ing if the guest does this, because
3
Coverity spotted it.
4
the code in imx_epit_write() starts ptimer transactions, and then
5
imx_epit_reset() also starts ptimer transactions, triggering
6
"ptimer_transaction_begin: Assertion `!s->in_transaction' failed".
7
4
8
The cleanest way to avoid this double-transaction is to move the
5
Resolves: Coverity CID 1507122
9
start-transaction for the CR write handling down below the check of
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
the SWR bit.
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Thomas Huth <thuth@redhat.com>
9
Message-id: 20240312183810.557768-2-peter.maydell@linaro.org
10
---
11
tests/qtest/npcm7xx_emc-test.c | 4 ++--
12
1 file changed, 2 insertions(+), 2 deletions(-)
11
13
12
Fixes: https://bugs.launchpad.net/qemu/+bug/1880424
14
diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c
13
Fixes: cc2722ec83ad944505fe
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Message-id: 20200727154550.3409-1-peter.maydell@linaro.org
17
---
18
hw/timer/imx_epit.c | 13 ++++++++++---
19
1 file changed, 10 insertions(+), 3 deletions(-)
20
21
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
22
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/timer/imx_epit.c
16
--- a/tests/qtest/npcm7xx_emc-test.c
24
+++ b/hw/timer/imx_epit.c
17
+++ b/tests/qtest/npcm7xx_emc-test.c
25
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
18
@@ -XXX,XX +XXX,XX @@ static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd)
26
19
static void test_tx(gconstpointer test_data)
27
switch (offset >> 2) {
20
{
28
case 0: /* CR */
21
const TestData *td = test_data;
29
- ptimer_transaction_begin(s->timer_cmp);
22
- GString *cmd_line = g_string_new("-machine quanta-gsj");
30
- ptimer_transaction_begin(s->timer_reload);
23
+ g_autoptr(GString) cmd_line = g_string_new("-machine quanta-gsj");
31
24
int *test_sockets = packet_test_init(emc_module_index(td->module),
32
oldcr = s->cr;
25
cmd_line);
33
s->cr = value & 0x03ffffff;
26
QTestState *qts = qtest_init(cmd_line->str);
34
if (s->cr & CR_SWR) {
27
@@ -XXX,XX +XXX,XX @@ static void test_tx(gconstpointer test_data)
35
/* handle the reset */
28
static void test_rx(gconstpointer test_data)
36
imx_epit_reset(DEVICE(s));
29
{
37
- } else {
30
const TestData *td = test_data;
38
+ /*
31
- GString *cmd_line = g_string_new("-machine quanta-gsj");
39
+ * TODO: could we 'break' here? following operations appear
32
+ g_autoptr(GString) cmd_line = g_string_new("-machine quanta-gsj");
40
+ * to duplicate the work imx_epit_reset() already did.
33
int *test_sockets = packet_test_init(emc_module_index(td->module),
41
+ */
34
cmd_line);
42
+ }
35
QTestState *qts = qtest_init(cmd_line->str);
43
+
44
+ ptimer_transaction_begin(s->timer_cmp);
45
+ ptimer_transaction_begin(s->timer_reload);
46
+
47
+ if (!(s->cr & CR_SWR)) {
48
imx_epit_set_freq(s);
49
}
50
51
--
36
--
52
2.20.1
37
2.34.1
53
54
diff view generated by jsdifflib
1
The NVIC provides an outbound qemu_irq "SYSRESETREQ" which it signals
1
In socket_check_afunix_support() we call socket(PF_UNIX, SOCK_STREAM, 0)
2
when the guest sets the SYSRESETREQ bit in the AIRCR register. This
2
to see if it works, but we call close() on the result whether it
3
matches the hardware design (where the CPU has a signal of this name
3
worked or not. Only close the fd if the socket() call succeeded.
4
and it is up to the SoC to connect that up to an actual reset
4
Spotted by Coverity.
5
mechanism), but in QEMU it mostly results in duplicated code in SoC
6
objects and bugs where SoC model implementors forget to wire up the
7
SYSRESETREQ line.
8
5
9
Provide a default behaviour for the case where SYSRESETREQ is not
6
Resolves: Coverity CID 1497481
10
actually connected to anything: use qemu_system_reset_request() to
11
perform a system reset. This will allow us to remove the
12
implementations of SYSRESETREQ handling from the boards where that's
13
exactly what it does, and also fixes the bugs in the board models
14
which forgot to wire up the signal:
15
16
* microbit
17
* mps2-an385
18
* mps2-an505
19
* mps2-an511
20
* mps2-an521
21
* musca-a
22
* musca-b1
23
* netduino
24
* netduinoplus2
25
26
We still allow the board to wire up the signal if it needs to, in case
27
we need to model more complicated reset controller logic or to model
28
buggy SoC hardware which forgot to wire up the line itself. But
29
defaulting to "reset the system" is more often going to be correct
30
than defaulting to "do nothing".
31
7
32
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
33
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
34
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Thomas Huth <thuth@redhat.com>
35
Message-id: 20200728103744.6909-3-peter.maydell@linaro.org
11
Message-id: 20240312183810.557768-3-peter.maydell@linaro.org
36
---
12
---
37
include/hw/arm/armv7m.h | 4 +++-
13
tests/unit/socket-helpers.c | 4 +++-
38
hw/intc/armv7m_nvic.c | 17 ++++++++++++++++-
14
1 file changed, 3 insertions(+), 1 deletion(-)
39
2 files changed, 19 insertions(+), 2 deletions(-)
40
15
41
diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h
16
diff --git a/tests/unit/socket-helpers.c b/tests/unit/socket-helpers.c
42
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
43
--- a/include/hw/arm/armv7m.h
18
--- a/tests/unit/socket-helpers.c
44
+++ b/include/hw/arm/armv7m.h
19
+++ b/tests/unit/socket-helpers.c
45
@@ -XXX,XX +XXX,XX @@ typedef struct {
20
@@ -XXX,XX +XXX,XX @@ void socket_check_afunix_support(bool *has_afunix)
46
21
int fd;
47
/* ARMv7M container object.
22
48
* + Unnamed GPIO input lines: external IRQ lines for the NVIC
23
fd = socket(PF_UNIX, SOCK_STREAM, 0);
49
- * + Named GPIO output SYSRESETREQ: signalled for guest AIRCR.SYSRESETREQ
24
- close(fd);
50
+ * + Named GPIO output SYSRESETREQ: signalled for guest AIRCR.SYSRESETREQ.
25
51
+ * If this GPIO is not wired up then the NVIC will default to performing
26
#ifdef _WIN32
52
+ * a qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET).
27
*has_afunix = (fd != (int)INVALID_SOCKET);
53
* + Property "cpu-type": CPU type to instantiate
28
@@ -XXX,XX +XXX,XX @@ void socket_check_afunix_support(bool *has_afunix)
54
* + Property "num-irq": number of external IRQ lines
29
*has_afunix = (fd >= 0);
55
* + Property "memory": MemoryRegion defining the physical address space
30
#endif
56
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
31
57
index XXXXXXX..XXXXXXX 100644
32
+ if (*has_afunix) {
58
--- a/hw/intc/armv7m_nvic.c
33
+ close(fd);
59
+++ b/hw/intc/armv7m_nvic.c
60
@@ -XXX,XX +XXX,XX @@
61
#include "hw/intc/armv7m_nvic.h"
62
#include "hw/irq.h"
63
#include "hw/qdev-properties.h"
64
+#include "sysemu/runstate.h"
65
#include "target/arm/cpu.h"
66
#include "exec/exec-all.h"
67
#include "exec/memop.h"
68
@@ -XXX,XX +XXX,XX @@ static const uint8_t nvic_id[] = {
69
0x00, 0xb0, 0x1b, 0x00, 0x0d, 0xe0, 0x05, 0xb1
70
};
71
72
+static void signal_sysresetreq(NVICState *s)
73
+{
74
+ if (qemu_irq_is_connected(s->sysresetreq)) {
75
+ qemu_irq_pulse(s->sysresetreq);
76
+ } else {
77
+ /*
78
+ * Default behaviour if the SoC doesn't need to wire up
79
+ * SYSRESETREQ (eg to a system reset controller of some kind):
80
+ * perform a system reset via the usual QEMU API.
81
+ */
82
+ qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
83
+ }
34
+ }
84
+}
35
return;
85
+
36
}
86
static int nvic_pending_prio(NVICState *s)
87
{
88
/* return the group priority of the current pending interrupt,
89
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
90
if (value & R_V7M_AIRCR_SYSRESETREQ_MASK) {
91
if (attrs.secure ||
92
!(cpu->env.v7m.aircr & R_V7M_AIRCR_SYSRESETREQS_MASK)) {
93
- qemu_irq_pulse(s->sysresetreq);
94
+ signal_sysresetreq(s);
95
}
96
}
97
if (value & R_V7M_AIRCR_VECTCLRACTIVE_MASK) {
98
--
37
--
99
2.20.1
38
2.34.1
100
101
diff view generated by jsdifflib
1
From: Kaige Li <likaige@loongson.cn>
1
In net_init_af_xdp() we parse the arguments and allocate
2
a buffer of ints into sock_fds. However, although we
3
free this in the error exit path, we don't ever free it
4
in the successful return path. Coverity spots this leak.
2
5
3
GCC version 4.9.4 isn't clever enough to figure out that all
6
Switch to g_autofree so we don't need to manually free the
4
execution paths in disas_ldst() that use 'fn' will have initialized
7
array.
5
it first, and so it warns:
6
8
7
/home/LiKaige/qemu/target/arm/translate-a64.c: In function ‘disas_ldst’:
9
Resolves: Coverity CID 1534906
8
/home/LiKaige/qemu/target/arm/translate-a64.c:3392:5: error: ‘fn’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
fn(cpu_reg(s, rt), clean_addr, tcg_rs, get_mem_index(s),
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
^
12
Reviewed-by: Thomas Huth <thuth@redhat.com>
11
/home/LiKaige/qemu/target/arm/translate-a64.c:3318:22: note: ‘fn’ was declared here
13
Message-id: 20240312183810.557768-4-peter.maydell@linaro.org
12
AtomicThreeOpFn *fn;
14
---
13
^
15
net/af-xdp.c | 3 +--
16
1 file changed, 1 insertion(+), 2 deletions(-)
14
17
15
Make it happy by initializing the variable to NULL.
18
diff --git a/net/af-xdp.c b/net/af-xdp.c
16
17
Signed-off-by: Kaige Li <likaige@loongson.cn>
18
Message-id: 1596110248-7366-2-git-send-email-likaige@loongson.cn
19
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
20
[PMM: Clean up commit message and note which gcc version this was]
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
---
23
target/arm/translate-a64.c | 2 +-
24
1 file changed, 1 insertion(+), 1 deletion(-)
25
26
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
27
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
28
--- a/target/arm/translate-a64.c
20
--- a/net/af-xdp.c
29
+++ b/target/arm/translate-a64.c
21
+++ b/net/af-xdp.c
30
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn,
22
@@ -XXX,XX +XXX,XX @@ int net_init_af_xdp(const Netdev *netdev,
31
bool r = extract32(insn, 22, 1);
23
NetClientState *nc, *nc0 = NULL;
32
bool a = extract32(insn, 23, 1);
24
unsigned int ifindex;
33
TCGv_i64 tcg_rs, clean_addr;
25
uint32_t prog_id = 0;
34
- AtomicThreeOpFn *fn;
26
- int *sock_fds = NULL;
35
+ AtomicThreeOpFn *fn = NULL;
27
+ g_autofree int *sock_fds = NULL;
36
28
int64_t i, queues;
37
if (is_vector || !dc_isar_feature(aa64_atomics, s)) {
29
Error *err = NULL;
38
unallocated_encoding(s);
30
AFXDPState *s;
31
@@ -XXX,XX +XXX,XX @@ int net_init_af_xdp(const Netdev *netdev,
32
return 0;
33
34
err:
35
- g_free(sock_fds);
36
if (nc0) {
37
qemu_del_net_client(nc0);
38
}
39
--
39
--
40
2.20.1
40
2.34.1
41
42
diff view generated by jsdifflib
1
The nrf51 SoC model wasn't setting the system_clock_scale
1
In pca9554_get_pin() and pca9554_set_pin(), we try to detect an
2
global.which meant that if guest code used the systick timer in "use
2
incorrect pin value, but we get the condition wrong, using ">"
3
the processor clock" mode it would hang because time never advances.
3
when ">=" was intended.
4
4
5
Set the global to match the documented CPU clock speed for this SoC.
5
This has no actual effect, because in pca9554_initfn() we
6
use the correct test when creating the properties and so
7
we'll never be called with an out of range value. However,
8
Coverity complains about the mismatch between the check and
9
the later use of the pin value in a shift operation.
6
10
7
This SoC in fact doesn't have a SysTick timer (which is the only thing
11
Use the correct condition.
8
currently that cares about the system_clock_scale), because it's
9
a configurable option in the Cortex-M0. However our Cortex-M0 and
10
thus our nrf51 and our micro:bit board do provide a SysTick, so
11
we ought to provide a functional one rather than a broken one.
12
12
13
Resolves: Coverity CID 1534917
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 20200727193458.31250-1-peter.maydell@linaro.org
16
Reviewed-by: Thomas Huth <thuth@redhat.com>
17
Message-id: 20240312183810.557768-5-peter.maydell@linaro.org
16
---
18
---
17
hw/arm/nrf51_soc.c | 5 +++++
19
hw/misc/pca9554.c | 4 ++--
18
1 file changed, 5 insertions(+)
20
1 file changed, 2 insertions(+), 2 deletions(-)
19
21
20
diff --git a/hw/arm/nrf51_soc.c b/hw/arm/nrf51_soc.c
22
diff --git a/hw/misc/pca9554.c b/hw/misc/pca9554.c
21
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/arm/nrf51_soc.c
24
--- a/hw/misc/pca9554.c
23
+++ b/hw/arm/nrf51_soc.c
25
+++ b/hw/misc/pca9554.c
24
@@ -XXX,XX +XXX,XX @@
26
@@ -XXX,XX +XXX,XX @@ static void pca9554_get_pin(Object *obj, Visitor *v, const char *name,
25
27
error_setg(errp, "%s: error reading %s", __func__, name);
26
#define BASE_TO_IRQ(base) ((base >> 12) & 0x1F)
27
28
+/* HCLK (the main CPU clock) on this SoC is always 16MHz */
29
+#define HCLK_FRQ 16000000
30
+
31
static uint64_t clock_read(void *opaque, hwaddr addr, unsigned int size)
32
{
33
qemu_log_mask(LOG_UNIMP, "%s: 0x%" HWADDR_PRIx " [%u]\n",
34
@@ -XXX,XX +XXX,XX @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
35
return;
28
return;
36
}
29
}
37
30
- if (pin < 0 || pin > PCA9554_PIN_COUNT) {
38
+ system_clock_scale = NANOSECONDS_PER_SECOND / HCLK_FRQ;
31
+ if (pin < 0 || pin >= PCA9554_PIN_COUNT) {
39
+
32
error_setg(errp, "%s invalid pin %s", __func__, name);
40
object_property_set_link(OBJECT(&s->cpu), "memory", OBJECT(&s->container),
33
return;
41
&error_abort);
34
}
42
if (!sysbus_realize(SYS_BUS_DEVICE(&s->cpu), errp)) {
35
@@ -XXX,XX +XXX,XX @@ static void pca9554_set_pin(Object *obj, Visitor *v, const char *name,
36
error_setg(errp, "%s: error reading %s", __func__, name);
37
return;
38
}
39
- if (pin < 0 || pin > PCA9554_PIN_COUNT) {
40
+ if (pin < 0 || pin >= PCA9554_PIN_COUNT) {
41
error_setg(errp, "%s invalid pin %s", __func__, name);
42
return;
43
}
43
--
44
--
44
2.20.1
45
2.34.1
45
46
diff view generated by jsdifflib
1
The MSF2 SoC model and the Stellaris board code both wire
1
There's no way for the macio_nvram device to report failure to write
2
SYSRESETREQ up to a function that just invokes
2
data, but we can at least report it to the user with error_report()
3
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
3
as we do in other devices like xlnx-efuse.
4
This is now the default action that the NVIC does if the line is
5
not connected, so we can delete the handling code.
6
4
5
Spotted by Coverity.
6
7
Resolves: Coverity CID 1507628
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Thomas Huth <thuth@redhat.com>
10
Message-id: 20200728103744.6909-4-peter.maydell@linaro.org
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
12
Message-id: 20240312183810.557768-6-peter.maydell@linaro.org
11
---
13
---
12
hw/arm/msf2-soc.c | 11 -----------
14
hw/nvram/mac_nvram.c | 5 ++++-
13
hw/arm/stellaris.c | 12 ------------
15
1 file changed, 4 insertions(+), 1 deletion(-)
14
2 files changed, 23 deletions(-)
15
16
16
diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c
17
diff --git a/hw/nvram/mac_nvram.c b/hw/nvram/mac_nvram.c
17
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/arm/msf2-soc.c
19
--- a/hw/nvram/mac_nvram.c
19
+++ b/hw/arm/msf2-soc.c
20
+++ b/hw/nvram/mac_nvram.c
20
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@ static void macio_nvram_writeb(void *opaque, hwaddr addr,
21
#include "hw/irq.h"
22
trace_macio_nvram_write(addr, value);
22
#include "hw/arm/msf2-soc.h"
23
s->data[addr] = value;
23
#include "hw/misc/unimp.h"
24
if (s->blk) {
24
-#include "sysemu/runstate.h"
25
- blk_pwrite(s->blk, addr, 1, &s->data[addr], 0);
25
#include "sysemu/sysemu.h"
26
+ if (blk_pwrite(s->blk, addr, 1, &s->data[addr], 0) < 0) {
26
27
+ error_report("%s: write of NVRAM data to backing store failed",
27
#define MSF2_TIMER_BASE 0x40004000
28
+ blk_name(s->blk));
28
@@ -XXX,XX +XXX,XX @@ static const int spi_irq[MSF2_NUM_SPIS] = { 2, 3 };
29
+ }
29
static const int uart_irq[MSF2_NUM_UARTS] = { 10, 11 };
30
static const int timer_irq[MSF2_NUM_TIMERS] = { 14, 15 };
31
32
-static void do_sys_reset(void *opaque, int n, int level)
33
-{
34
- if (level) {
35
- qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
36
- }
37
-}
38
-
39
static void m2sxxx_soc_initfn(Object *obj)
40
{
41
MSF2State *s = MSF2_SOC(obj);
42
@@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
43
return;
44
}
30
}
45
46
- qdev_connect_gpio_out_named(DEVICE(&s->armv7m.nvic), "SYSRESETREQ", 0,
47
- qemu_allocate_irq(&do_sys_reset, NULL, 0));
48
-
49
system_clock_scale = NANOSECONDS_PER_SECOND / s->m3clk;
50
51
for (i = 0; i < MSF2_NUM_UARTS; i++) {
52
diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
53
index XXXXXXX..XXXXXXX 100644
54
--- a/hw/arm/stellaris.c
55
+++ b/hw/arm/stellaris.c
56
@@ -XXX,XX +XXX,XX @@
57
#include "hw/boards.h"
58
#include "qemu/log.h"
59
#include "exec/address-spaces.h"
60
-#include "sysemu/runstate.h"
61
#include "sysemu/sysemu.h"
62
#include "hw/arm/armv7m.h"
63
#include "hw/char/pl011.h"
64
@@ -XXX,XX +XXX,XX @@ static void stellaris_adc_init(Object *obj)
65
qdev_init_gpio_in(dev, stellaris_adc_trigger, 1);
66
}
31
}
67
32
68
-static
69
-void do_sys_reset(void *opaque, int n, int level)
70
-{
71
- if (level) {
72
- qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
73
- }
74
-}
75
-
76
/* Board init. */
77
static stellaris_board_info stellaris_boards[] = {
78
{ "LM3S811EVB",
79
@@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
80
/* This will exit with an error if the user passed us a bad cpu_type */
81
sysbus_realize_and_unref(SYS_BUS_DEVICE(nvic), &error_fatal);
82
83
- qdev_connect_gpio_out_named(nvic, "SYSRESETREQ", 0,
84
- qemu_allocate_irq(&do_sys_reset, NULL, 0));
85
-
86
if (board->dc1 & (1 << 16)) {
87
dev = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000,
88
qdev_get_gpio_in(nvic, 14),
89
--
33
--
90
2.20.1
34
2.34.1
91
35
92
36
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
In test_compute_wait() we do
2
double units = bkt.max / 10;
3
which does an integer division and then assigns it to a double variable,
4
and similarly later on in the expression for an assertion.
2
5
3
The definition of top_bit used in this function is one higher
6
Use 10.0 so that we do a floating point division and calculate the
4
than that used in the Arm ARM psuedo-code, which put the error
7
exact value, rather than doing an integer division.
5
indication at top_bit - 1 at the wrong place, which meant that
6
it wasn't visible to Auth.
7
8
8
Fixing the definition of top_bit requires more changes, because
9
Spotted by Coverity.
9
its most common use is for the count of bits in top_bit:bot_bit,
10
which would then need to be computed as top_bit - bot_bit + 1.
11
10
12
For now, prefer the minimal fix to the error indication alone.
11
Resolves: Coverity CID 1432564
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Reviewed-by: Thomas Huth <thuth@redhat.com>
15
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
16
Message-id: 20240312183810.557768-7-peter.maydell@linaro.org
17
---
18
tests/unit/test-throttle.c | 4 ++--
19
1 file changed, 2 insertions(+), 2 deletions(-)
13
20
14
Fixes: 63ff0ca94cb
21
diff --git a/tests/unit/test-throttle.c b/tests/unit/test-throttle.c
15
Reported-by: Derrick McKee <derrick.mckee@gmail.com>
16
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
17
Message-id: 20200728195706.11087-1-richard.henderson@linaro.org
18
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
19
[PMM: added comment about the divergence from the pseudocode]
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
---
22
target/arm/pauth_helper.c | 6 +++++-
23
tests/tcg/aarch64/pauth-5.c | 33 +++++++++++++++++++++++++++++++
24
tests/tcg/aarch64/Makefile.target | 2 +-
25
3 files changed, 39 insertions(+), 2 deletions(-)
26
create mode 100644 tests/tcg/aarch64/pauth-5.c
27
28
diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c
29
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
30
--- a/target/arm/pauth_helper.c
23
--- a/tests/unit/test-throttle.c
31
+++ b/target/arm/pauth_helper.c
24
+++ b/tests/unit/test-throttle.c
32
@@ -XXX,XX +XXX,XX @@ static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier,
25
@@ -XXX,XX +XXX,XX @@ static void test_compute_wait(void)
33
*/
26
bkt.avg = 10;
34
test = sextract64(ptr, bot_bit, top_bit - bot_bit);
27
bkt.max = 200;
35
if (test != 0 && test != -1) {
28
for (i = 0; i < 22; i++) {
36
- pac ^= MAKE_64BIT_MASK(top_bit - 1, 1);
29
- double units = bkt.max / 10;
37
+ /*
30
+ double units = bkt.max / 10.0;
38
+ * Note that our top_bit is one greater than the pseudocode's
31
bkt.level += units;
39
+ * version, hence "- 2" here.
32
bkt.burst_level += units;
40
+ */
33
throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 10);
41
+ pac ^= MAKE_64BIT_MASK(top_bit - 2, 1);
34
wait = throttle_compute_wait(&bkt);
42
}
35
g_assert(double_cmp(bkt.burst_level, 0));
43
36
- g_assert(double_cmp(bkt.level, (i + 1) * (bkt.max - bkt.avg) / 10));
44
/*
37
+ g_assert(double_cmp(bkt.level, (i + 1) * (bkt.max - bkt.avg) / 10.0));
45
diff --git a/tests/tcg/aarch64/pauth-5.c b/tests/tcg/aarch64/pauth-5.c
38
/* We can do bursts for the 2 seconds we have configured in
46
new file mode 100644
39
* burst_length. We have 100 extra milliseconds of burst
47
index XXXXXXX..XXXXXXX
40
* because bkt.level has been leaking during this time.
48
--- /dev/null
49
+++ b/tests/tcg/aarch64/pauth-5.c
50
@@ -XXX,XX +XXX,XX @@
51
+#include <assert.h>
52
+
53
+static int x;
54
+
55
+int main()
56
+{
57
+ int *p0 = &x, *p1, *p2, *p3;
58
+ unsigned long salt = 0;
59
+
60
+ /*
61
+ * With TBI enabled and a 48-bit VA, there are 7 bits of auth, and so
62
+ * a 1/128 chance of auth = pac(ptr,key,salt) producing zero.
63
+ * Find a salt that creates auth != 0.
64
+ */
65
+ do {
66
+ salt++;
67
+ asm("pacda %0, %1" : "=r"(p1) : "r"(salt), "0"(p0));
68
+ } while (p0 == p1);
69
+
70
+ /*
71
+ * This pac must fail, because the input pointer bears an encryption,
72
+ * and so is not properly extended within bits [55:47]. This will
73
+ * toggle bit 54 in the output...
74
+ */
75
+ asm("pacda %0, %1" : "=r"(p2) : "r"(salt), "0"(p1));
76
+
77
+ /* ... so that the aut must fail, setting bit 53 in the output ... */
78
+ asm("autda %0, %1" : "=r"(p3) : "r"(salt), "0"(p2));
79
+
80
+ /* ... which means this equality must not hold. */
81
+ assert(p3 != p0);
82
+ return 0;
83
+}
84
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
85
index XXXXXXX..XXXXXXX 100644
86
--- a/tests/tcg/aarch64/Makefile.target
87
+++ b/tests/tcg/aarch64/Makefile.target
88
@@ -XXX,XX +XXX,XX @@ run-fcvt: fcvt
89
90
# Pauth Tests
91
ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_3),)
92
-AARCH64_TESTS += pauth-1 pauth-2 pauth-4
93
+AARCH64_TESTS += pauth-1 pauth-2 pauth-4 pauth-5
94
pauth-%: CFLAGS += -march=armv8.3-a
95
run-pauth-%: QEMU_OPTS += -cpu max
96
run-plugin-pauth-%: QEMU_OPTS += -cpu max
97
--
41
--
98
2.20.1
42
2.34.1
99
43
100
44
diff view generated by jsdifflib
1
Mostly devices don't need to care whether one of their output
1
Coverity points out that g_setenv() can fail and we don't
2
qemu_irq lines is connected, because functions like qemu_set_irq()
2
check for this in qtest_inproc_init(). In practice this will
3
silently do nothing if there is nothing on the other end. However
3
only fail if a memory allocation failed in setenv() or if
4
sometimes a device might want to implement default behaviour for the
4
the caller passed an invalid architecture name (e.g. one
5
case where the machine hasn't wired the line up to anywhere.
5
with an '=' in it), so rather than requiring the callsite
6
to check for failure, make g_setenv() failure fatal here,
7
similarly to what we did in commit aca68d95c515.
6
8
7
Provide a function qemu_irq_is_connected() that devices can use for
9
Resolves: Coverity CID 1497485
8
this purpose. (The test is trivial but encapsulating it in a
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
function makes it easier to see where we're doing it in case we need
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
to change the implementation later.)
12
Reviewed-by: Thomas Huth <thuth@redhat.com>
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
14
Message-id: 20240312183810.557768-8-peter.maydell@linaro.org
15
---
16
tests/qtest/libqtest.c | 6 +++++-
17
1 file changed, 5 insertions(+), 1 deletion(-)
11
18
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
15
Message-id: 20200728103744.6909-2-peter.maydell@linaro.org
16
---
17
include/hw/irq.h | 18 ++++++++++++++++++
18
1 file changed, 18 insertions(+)
19
20
diff --git a/include/hw/irq.h b/include/hw/irq.h
21
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
22
--- a/include/hw/irq.h
21
--- a/tests/qtest/libqtest.c
23
+++ b/include/hw/irq.h
22
+++ b/tests/qtest/libqtest.c
24
@@ -XXX,XX +XXX,XX @@ qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2);
23
@@ -XXX,XX +XXX,XX @@ QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
25
on an existing vector of qemu_irq. */
24
* way, qtest_get_arch works for inproc qtest.
26
void qemu_irq_intercept_in(qemu_irq *gpio_in, qemu_irq_handler handler, int n);
25
*/
27
26
gchar *bin_path = g_strconcat("/qemu-system-", arch, NULL);
28
+/**
27
- g_setenv("QTEST_QEMU_BINARY", bin_path, 0);
29
+ * qemu_irq_is_connected: Return true if IRQ line is wired up
28
+ if (!g_setenv("QTEST_QEMU_BINARY", bin_path, 0)) {
30
+ *
29
+ fprintf(stderr,
31
+ * If a qemu_irq has a device on the other (receiving) end of it,
30
+ "Could not set environment variable QTEST_QEMU_BINARY\n");
32
+ * return true; otherwise return false.
31
+ exit(1);
33
+ *
32
+ }
34
+ * Usually device models don't need to care whether the machine model
33
g_free(bin_path);
35
+ * has wired up their outbound qemu_irq lines, because functions like
34
36
+ * qemu_set_irq() silently do nothing if there is nothing on the other
35
return qts;
37
+ * end of the line. However occasionally a device model will want to
38
+ * provide default behaviour if its output is left floating, and
39
+ * it can use this function to identify when that is the case.
40
+ */
41
+static inline bool qemu_irq_is_connected(qemu_irq irq)
42
+{
43
+ return irq != NULL;
44
+}
45
+
46
#endif
47
--
36
--
48
2.20.1
37
2.34.1
49
38
50
39
diff view generated by jsdifflib