1 | target-arm queue for rc1 -- these are all bug fixes. | 1 | Hi; here's a target-arm pullreq to go in before softfreeze. |
---|---|---|---|
2 | This is actually pretty much entirely bugfixes (since the | ||
3 | SEL2 timers we implement here are a missing part of a feature | ||
4 | we claim to already implement). | ||
2 | 5 | ||
3 | thanks | 6 | thanks |
4 | -- PMM | 7 | -- PMM |
5 | 8 | ||
6 | The following changes since commit b9404bf592e7ba74180e1a54ed7a266ec6ee67f2: | 9 | The following changes since commit 98c7362b1efe651327385a25874a73e008c6549e: |
7 | 10 | ||
8 | Merge remote-tracking branch 'remotes/dgilbert/tags/pull-hmp-20190715' into staging (2019-07-15 12:22:07 +0100) | 11 | Merge tag 'accel-cpus-20250306' of https://github.com/philmd/qemu into staging (2025-03-07 07:39:49 +0800) |
9 | 12 | ||
10 | are available in the Git repository at: | 13 | are available in the Git repository at: |
11 | 14 | ||
12 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20190715 | 15 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20250307 |
13 | 16 | ||
14 | for you to fetch changes up to 51c9122e92b776a3f16af0b9282f1dc5012e2a19: | 17 | for you to fetch changes up to 0ce0739d46983e5e88fa9c149cb305689c9d8c6f: |
15 | 18 | ||
16 | target/arm: NS BusFault on vector table fetch escalates to NS HardFault (2019-07-15 14:17:04 +0100) | 19 | target/rx: Remove TCG_CALL_NO_WG from helpers which write env (2025-03-07 15:03:20 +0000) |
17 | 20 | ||
18 | ---------------------------------------------------------------- | 21 | ---------------------------------------------------------------- |
19 | target-arm queue: | 22 | target-arm queue: |
20 | * report ARMv8-A FP support for AArch32 -cpu max | 23 | * hw/arm/smmu-common: Remove the repeated ttb field |
21 | * hw/ssi/xilinx_spips: Avoid AXI writes to the LQSPI linear memory | 24 | * hw/gpio: npcm7xx: fixup out-of-bounds access |
22 | * hw/ssi/xilinx_spips: Avoid out-of-bound access to lqspi_buf[] | 25 | * tests/functional/test_arm_sx1: Check whether the serial console is working |
23 | * hw/ssi/mss-spi: Avoid crash when reading empty RX FIFO | 26 | * target/arm: Fix minor bugs in generic timer register handling |
24 | * hw/display/xlnx_dp: Avoid crash when reading empty RX FIFO | 27 | * target/arm: Implement SEL2 physical and virtual timers |
25 | * hw/arm/virt: Fix non-secure flash mode | 28 | * target/arm: Correct STRD, LDRD atomicity and fault behaviour |
26 | * pl031: Correctly migrate state when using -rtc clock=host | 29 | * target/arm: Make dummy debug registers RAZ, not NOP |
27 | * fix regression that meant arm926 and arm1026 lost VFP | 30 | * util/qemu-timer.c: Don't warp timer from timerlist_rearm() |
28 | double-precision support | 31 | * include/exec/memop.h: Expand comment for MO_ATOM_SUBALIGN |
29 | * v8M: NS BusFault on vector table fetch escalates to NS HardFault | 32 | * hw/arm/smmu: Introduce smmu_configs_inv_sid_range() helper |
33 | * target/rx: Set exception vector base to 0xffffff80 | ||
34 | * target/rx: Remove TCG_CALL_NO_WG from helpers which write env | ||
30 | 35 | ||
31 | ---------------------------------------------------------------- | 36 | ---------------------------------------------------------------- |
32 | Alex Bennée (1): | 37 | Alex Bennée (4): |
33 | target/arm: report ARMv8-A FP support for AArch32 -cpu max | 38 | target/arm: Implement SEL2 physical and virtual timers |
39 | target/arm: Document the architectural names of our GTIMERs | ||
40 | hw/arm: enable secure EL2 timers for virt machine | ||
41 | hw/arm: enable secure EL2 timers for sbsa machine | ||
34 | 42 | ||
35 | David Engraf (1): | 43 | JianChunfu (2): |
36 | hw/arm/virt: Fix non-secure flash mode | 44 | hw/arm/smmu-common: Remove the repeated ttb field |
45 | hw/arm/smmu: Introduce smmu_configs_inv_sid_range() helper | ||
37 | 46 | ||
38 | Peter Maydell (3): | 47 | Keith Packard (2): |
39 | pl031: Correctly migrate state when using -rtc clock=host | 48 | target/rx: Set exception vector base to 0xffffff80 |
40 | target/arm: Set VFP-related MVFR0 fields for arm926 and arm1026 | 49 | target/rx: Remove TCG_CALL_NO_WG from helpers which write env |
41 | target/arm: NS BusFault on vector table fetch escalates to NS HardFault | ||
42 | 50 | ||
43 | Philippe Mathieu-Daudé (5): | 51 | Patrick Venture (1): |
44 | hw/ssi/xilinx_spips: Convert lqspi_read() to read_with_attrs | 52 | hw/gpio: npcm7xx: fixup out-of-bounds access |
45 | hw/ssi/xilinx_spips: Avoid AXI writes to the LQSPI linear memory | ||
46 | hw/ssi/xilinx_spips: Avoid out-of-bound access to lqspi_buf[] | ||
47 | hw/ssi/mss-spi: Avoid crash when reading empty RX FIFO | ||
48 | hw/display/xlnx_dp: Avoid crash when reading empty RX FIFO | ||
49 | 53 | ||
50 | include/hw/timer/pl031.h | 2 ++ | 54 | Peter Maydell (11): |
51 | hw/arm/virt.c | 2 +- | 55 | target/arm: Apply correct timer offset when calculating deadlines |
52 | hw/core/machine.c | 1 + | 56 | target/arm: Don't apply CNTVOFF_EL2 for EL2_VIRT timer |
53 | hw/display/xlnx_dp.c | 15 +++++--- | 57 | target/arm: Make CNTPS_* UNDEF from Secure EL1 when Secure EL2 is enabled |
54 | hw/ssi/mss-spi.c | 8 ++++- | 58 | target/arm: Always apply CNTVOFF_EL2 for CNTV_TVAL_EL02 accesses |
55 | hw/ssi/xilinx_spips.c | 43 +++++++++++++++------- | 59 | target/arm: Refactor handling of timer offset for direct register accesses |
56 | hw/timer/pl031.c | 92 +++++++++++++++++++++++++++++++++++++++++++++--- | 60 | target/arm: Correct LDRD atomicity and fault behaviour |
57 | target/arm/cpu.c | 16 +++++++++ | 61 | target/arm: Correct STRD atomicity |
58 | target/arm/m_helper.c | 21 ++++++++--- | 62 | target/arm: Drop unused address_offset from op_addr_{rr, ri}_post() |
59 | 9 files changed, 174 insertions(+), 26 deletions(-) | 63 | target/arm: Make dummy debug registers RAZ, not NOP |
64 | util/qemu-timer.c: Don't warp timer from timerlist_rearm() | ||
65 | include/exec/memop.h: Expand comment for MO_ATOM_SUBALIGN | ||
60 | 66 | ||
67 | Thomas Huth (1): | ||
68 | tests/functional/test_arm_sx1: Check whether the serial console is working | ||
69 | |||
70 | MAINTAINERS | 1 + | ||
71 | hw/arm/smmu-internal.h | 5 - | ||
72 | include/exec/memop.h | 8 +- | ||
73 | include/hw/arm/bsa.h | 2 + | ||
74 | include/hw/arm/smmu-common.h | 7 +- | ||
75 | target/arm/cpu.h | 2 + | ||
76 | target/arm/gtimer.h | 14 +- | ||
77 | target/arm/internals.h | 5 +- | ||
78 | target/rx/helper.h | 34 ++-- | ||
79 | hw/arm/sbsa-ref.c | 2 + | ||
80 | hw/arm/smmu-common.c | 21 +++ | ||
81 | hw/arm/smmuv3.c | 19 +-- | ||
82 | hw/arm/virt.c | 2 + | ||
83 | hw/gpio/npcm7xx_gpio.c | 3 +- | ||
84 | target/arm/cpu.c | 4 + | ||
85 | target/arm/debug_helper.c | 7 +- | ||
86 | target/arm/helper.c | 324 ++++++++++++++++++++++++++++++++------- | ||
87 | target/arm/tcg/op_helper.c | 8 +- | ||
88 | target/arm/tcg/translate.c | 147 +++++++++++------- | ||
89 | target/rx/helper.c | 2 +- | ||
90 | util/qemu-timer.c | 4 - | ||
91 | hw/arm/trace-events | 3 +- | ||
92 | tests/functional/test_arm_sx1.py | 7 +- | ||
93 | 23 files changed, 455 insertions(+), 176 deletions(-) | ||
94 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: JianChunfu <jansef.jian@hj-micro.com> | ||
1 | 2 | ||
3 | SMMUTransCfg->ttb is never used in QEMU, TT base address | ||
4 | can be accessed by SMMUTransCfg->tt[i]->ttb. | ||
5 | |||
6 | Signed-off-by: JianChunfu <jansef.jian@hj-micro.com> | ||
7 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
8 | Message-id: 20250221031034.69822-1-jansef.jian@hj-micro.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | include/hw/arm/smmu-common.h | 1 - | ||
12 | 1 file changed, 1 deletion(-) | ||
13 | |||
14 | diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/hw/arm/smmu-common.h | ||
17 | +++ b/include/hw/arm/smmu-common.h | ||
18 | @@ -XXX,XX +XXX,XX @@ typedef struct SMMUTransCfg { | ||
19 | /* Used by stage-1 only. */ | ||
20 | bool aa64; /* arch64 or aarch32 translation table */ | ||
21 | bool record_faults; /* record fault events */ | ||
22 | - uint64_t ttb; /* TT base address */ | ||
23 | uint8_t oas; /* output address width */ | ||
24 | uint8_t tbi; /* Top Byte Ignore */ | ||
25 | int asid; | ||
26 | -- | ||
27 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Patrick Venture <venture@google.com> | ||
1 | 2 | ||
3 | The reg isn't validated to be a possible register before | ||
4 | it's dereferenced for one case. The mmio space registered | ||
5 | for the gpio device is 4KiB but there aren't that many | ||
6 | registers in the struct. | ||
7 | |||
8 | Cc: qemu-stable@nongnu.org | ||
9 | Fixes: 526dbbe0874 ("hw/gpio: Add GPIO model for Nuvoton NPCM7xx") | ||
10 | Signed-off-by: Patrick Venture <venture@google.com> | ||
11 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
12 | Message-id: 20250226024603.493148-1-venture@google.com | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | --- | ||
15 | hw/gpio/npcm7xx_gpio.c | 3 +-- | ||
16 | 1 file changed, 1 insertion(+), 2 deletions(-) | ||
17 | |||
18 | diff --git a/hw/gpio/npcm7xx_gpio.c b/hw/gpio/npcm7xx_gpio.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/gpio/npcm7xx_gpio.c | ||
21 | +++ b/hw/gpio/npcm7xx_gpio.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_gpio_regs_write(void *opaque, hwaddr addr, uint64_t v, | ||
23 | return; | ||
24 | } | ||
25 | |||
26 | - diff = s->regs[reg] ^ value; | ||
27 | - | ||
28 | switch (reg) { | ||
29 | case NPCM7XX_GPIO_TLOCK1: | ||
30 | case NPCM7XX_GPIO_TLOCK2: | ||
31 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_gpio_regs_write(void *opaque, hwaddr addr, uint64_t v, | ||
32 | case NPCM7XX_GPIO_PU: | ||
33 | case NPCM7XX_GPIO_PD: | ||
34 | case NPCM7XX_GPIO_IEM: | ||
35 | + diff = s->regs[reg] ^ value; | ||
36 | s->regs[reg] = value; | ||
37 | npcm7xx_gpio_update_pins(s, diff); | ||
38 | break; | ||
39 | -- | ||
40 | 2.43.0 | ||
41 | |||
42 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
1 | 2 | ||
3 | The kernel that is used in the sx1 test prints the usual Linux log | ||
4 | onto the serial console, but this test currently ignores it. To | ||
5 | make sure that the serial device is working properly, let's check | ||
6 | for some strings in the output here. | ||
7 | |||
8 | While we're at it, also add the test to the corresponding section | ||
9 | in the MAINTAINERS file. | ||
10 | |||
11 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
13 | Message-id: 20250226104833.1176253-1-thuth@redhat.com | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | --- | ||
16 | MAINTAINERS | 1 + | ||
17 | tests/functional/test_arm_sx1.py | 7 ++++--- | ||
18 | 2 files changed, 5 insertions(+), 3 deletions(-) | ||
19 | |||
20 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/MAINTAINERS | ||
23 | +++ b/MAINTAINERS | ||
24 | @@ -XXX,XX +XXX,XX @@ S: Maintained | ||
25 | F: hw/*/omap* | ||
26 | F: include/hw/arm/omap.h | ||
27 | F: docs/system/arm/sx1.rst | ||
28 | +F: tests/functional/test_arm_sx1.py | ||
29 | |||
30 | IPack | ||
31 | M: Alberto Garcia <berto@igalia.com> | ||
32 | diff --git a/tests/functional/test_arm_sx1.py b/tests/functional/test_arm_sx1.py | ||
33 | index XXXXXXX..XXXXXXX 100755 | ||
34 | --- a/tests/functional/test_arm_sx1.py | ||
35 | +++ b/tests/functional/test_arm_sx1.py | ||
36 | @@ -XXX,XX +XXX,XX @@ def test_arm_sx1_initrd(self): | ||
37 | self.vm.add_args('-append', f'kunit.enable=0 rdinit=/sbin/init {self.CONSOLE_ARGS}') | ||
38 | self.vm.add_args('-no-reboot') | ||
39 | self.launch_kernel(zimage_path, | ||
40 | - initrd=initrd_path) | ||
41 | + initrd=initrd_path, | ||
42 | + wait_for='Boot successful') | ||
43 | self.vm.wait(timeout=120) | ||
44 | |||
45 | def test_arm_sx1_sd(self): | ||
46 | @@ -XXX,XX +XXX,XX @@ def test_arm_sx1_sd(self): | ||
47 | self.vm.add_args('-no-reboot') | ||
48 | self.vm.add_args('-snapshot') | ||
49 | self.vm.add_args('-drive', f'format=raw,if=sd,file={sd_fs_path}') | ||
50 | - self.launch_kernel(zimage_path) | ||
51 | + self.launch_kernel(zimage_path, wait_for='Boot successful') | ||
52 | self.vm.wait(timeout=120) | ||
53 | |||
54 | def test_arm_sx1_flash(self): | ||
55 | @@ -XXX,XX +XXX,XX @@ def test_arm_sx1_flash(self): | ||
56 | self.vm.add_args('-no-reboot') | ||
57 | self.vm.add_args('-snapshot') | ||
58 | self.vm.add_args('-drive', f'format=raw,if=pflash,file={flash_path}') | ||
59 | - self.launch_kernel(zimage_path) | ||
60 | + self.launch_kernel(zimage_path, wait_for='Boot successful') | ||
61 | self.vm.wait(timeout=120) | ||
62 | |||
63 | if __name__ == '__main__': | ||
64 | -- | ||
65 | 2.43.0 | ||
66 | |||
67 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | When we are calculating timer deadlines, the correct definition of |
---|---|---|---|
2 | whether or not to apply an offset to the physical count is described | ||
3 | in the Arm ARM DDI4087 rev L.a section D12.2.4.1. This is different | ||
4 | from when the offset should be applied for a direct read of the | ||
5 | counter sysreg. | ||
2 | 6 | ||
3 | Lei Sun found while auditing the code that a CPU write would | 7 | We got this right for the EL1 physical timer and for the EL1 virtual |
4 | trigger a NULL pointer dereference. | 8 | timer, but got all the rest wrong: they should be using a zero offset |
9 | always. | ||
5 | 10 | ||
6 | >From UG1085 datasheet [*] AXI writes in this region are ignored | 11 | Factor the offset calculation out into a function that has a comment |
7 | and generates an AXI Slave Error (SLVERR). | 12 | documenting exactly which offset it is calculating and which gets the |
13 | HYP, SEC, and HYPVIRT cases right. | ||
8 | 14 | ||
9 | Fix by implementing the write_with_attrs() handler. | 15 | Cc: qemu-stable@nongnu.org |
10 | Return MEMTX_ERROR when the region is accessed (this error maps | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | to an AXI slave error). | 17 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
18 | Message-id: 20250204125009.2281315-2-peter.maydell@linaro.org | ||
19 | --- | ||
20 | target/arm/helper.c | 29 +++++++++++++++++++++++++++-- | ||
21 | 1 file changed, 27 insertions(+), 2 deletions(-) | ||
12 | 22 | ||
13 | [*] https://www.xilinx.com/support/documentation/user_guides/ug1085-zynq-ultrascale-trm.pdf | 23 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
14 | |||
15 | Reported-by: Lei Sun <slei.casper@gmail.com> | ||
16 | Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com> | ||
17 | Tested-by: Francisco Iglesias <frasse.iglesias@gmail.com> | ||
18 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
20 | --- | ||
21 | hw/ssi/xilinx_spips.c | 16 ++++++++++++++++ | ||
22 | 1 file changed, 16 insertions(+) | ||
23 | |||
24 | diff --git a/hw/ssi/xilinx_spips.c b/hw/ssi/xilinx_spips.c | ||
25 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/ssi/xilinx_spips.c | 25 | --- a/target/arm/helper.c |
27 | +++ b/hw/ssi/xilinx_spips.c | 26 | +++ b/target/arm/helper.c |
28 | @@ -XXX,XX +XXX,XX @@ static MemTxResult lqspi_read(void *opaque, hwaddr addr, uint64_t *value, | 27 | @@ -XXX,XX +XXX,XX @@ static uint64_t gt_phys_cnt_offset(CPUARMState *env) |
29 | return lqspi_read(opaque, addr, value, size, attrs); | 28 | return gt_phys_raw_cnt_offset(env); |
30 | } | 29 | } |
31 | 30 | ||
32 | +static MemTxResult lqspi_write(void *opaque, hwaddr offset, uint64_t value, | 31 | +static uint64_t gt_indirect_access_timer_offset(CPUARMState *env, int timeridx) |
33 | + unsigned size, MemTxAttrs attrs) | ||
34 | +{ | 32 | +{ |
35 | + /* | 33 | + /* |
36 | + * From UG1085, Chapter 24 (Quad-SPI controllers): | 34 | + * Return the timer offset to use for indirect accesses to the timer. |
37 | + * - Writes are ignored | 35 | + * This is the Offset value as defined in D12.2.4.1 "Operation of the |
38 | + * - AXI writes generate an external AXI slave error (SLVERR) | 36 | + * CompareValue views of the timers". |
37 | + * | ||
38 | + * The condition here is not always the same as the condition for | ||
39 | + * whether to apply an offset register when doing a direct read of | ||
40 | + * the counter sysreg; those conditions are described in the | ||
41 | + * access pseudocode for each counter register. | ||
39 | + */ | 42 | + */ |
40 | + qemu_log_mask(LOG_GUEST_ERROR, "%s Unexpected %u-bit access to 0x%" PRIx64 | 43 | + switch (timeridx) { |
41 | + " (value: 0x%" PRIx64 "\n", | 44 | + case GTIMER_PHYS: |
42 | + __func__, size << 3, offset, value); | 45 | + return gt_phys_raw_cnt_offset(env); |
43 | + | 46 | + case GTIMER_VIRT: |
44 | + return MEMTX_ERROR; | 47 | + return env->cp15.cntvoff_el2; |
48 | + case GTIMER_HYP: | ||
49 | + case GTIMER_SEC: | ||
50 | + case GTIMER_HYPVIRT: | ||
51 | + return 0; | ||
52 | + default: | ||
53 | + g_assert_not_reached(); | ||
54 | + } | ||
45 | +} | 55 | +} |
46 | + | 56 | + |
47 | static const MemoryRegionOps lqspi_ops = { | 57 | static void gt_recalc_timer(ARMCPU *cpu, int timeridx) |
48 | .read_with_attrs = lqspi_read, | 58 | { |
49 | + .write_with_attrs = lqspi_write, | 59 | ARMGenericTimer *gt = &cpu->env.cp15.c14_timer[timeridx]; |
50 | .endianness = DEVICE_NATIVE_ENDIAN, | 60 | @@ -XXX,XX +XXX,XX @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx) |
51 | .valid = { | 61 | * Timer enabled: calculate and set current ISTATUS, irq, and |
52 | .min_access_size = 1, | 62 | * reset timer to when ISTATUS next has to change |
63 | */ | ||
64 | - uint64_t offset = timeridx == GTIMER_VIRT ? | ||
65 | - cpu->env.cp15.cntvoff_el2 : gt_phys_raw_cnt_offset(&cpu->env); | ||
66 | + uint64_t offset = gt_indirect_access_timer_offset(&cpu->env, timeridx); | ||
67 | uint64_t count = gt_get_countervalue(&cpu->env); | ||
68 | /* Note that this must be unsigned 64 bit arithmetic: */ | ||
69 | int istatus = count - offset >= gt->cval; | ||
53 | -- | 70 | -- |
54 | 2.20.1 | 71 | 2.43.0 |
55 | 72 | ||
56 | 73 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The CNTVOFF_EL2 offset register should only be applied for accessses | ||
2 | to CNTVCT_EL0 and for the EL1 virtual timer (CNTV_*). We were | ||
3 | incorrectly applying it for the EL2 virtual timer (CNTHV_*). | ||
1 | 4 | ||
5 | Cc: qemu-stable@nongnu.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
8 | Message-id: 20250204125009.2281315-3-peter.maydell@linaro.org | ||
9 | --- | ||
10 | target/arm/helper.c | 2 -- | ||
11 | 1 file changed, 2 deletions(-) | ||
12 | |||
13 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/arm/helper.c | ||
16 | +++ b/target/arm/helper.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri, | ||
18 | |||
19 | switch (timeridx) { | ||
20 | case GTIMER_VIRT: | ||
21 | - case GTIMER_HYPVIRT: | ||
22 | offset = gt_virt_cnt_offset(env); | ||
23 | break; | ||
24 | case GTIMER_PHYS: | ||
25 | @@ -XXX,XX +XXX,XX @@ static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
26 | |||
27 | switch (timeridx) { | ||
28 | case GTIMER_VIRT: | ||
29 | - case GTIMER_HYPVIRT: | ||
30 | offset = gt_virt_cnt_offset(env); | ||
31 | break; | ||
32 | case GTIMER_PHYS: | ||
33 | -- | ||
34 | 2.43.0 | ||
35 | |||
36 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | When we added Secure EL2 support, we missed that this needs an update |
---|---|---|---|
2 | to the access code for the EL3 physical timer registers. These are | ||
3 | supposed to UNDEF from Secure EL1 when Secure EL2 is enabled. | ||
2 | 4 | ||
3 | Reading the RX_DATA register when the RX_FIFO is empty triggers | 5 | (Note for stable backporting: for backports to branches where |
4 | an abort. This can be easily reproduced: | 6 | CP_ACCESS_UNDEFINED is not defined, the old name to use instead |
7 | is CP_ACCESS_TRAP_UNCATEGORIZED.) | ||
5 | 8 | ||
6 | $ qemu-system-arm -M emcraft-sf2 -monitor stdio -S | 9 | Cc: qemu-stable@nongnu.org |
7 | QEMU 4.0.50 monitor - type 'help' for more information | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | (qemu) x 0x40001010 | 11 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
9 | Aborted (core dumped) | 12 | Message-id: 20250204125009.2281315-4-peter.maydell@linaro.org |
13 | --- | ||
14 | target/arm/helper.c | 3 +++ | ||
15 | 1 file changed, 3 insertions(+) | ||
10 | 16 | ||
11 | (gdb) bt | 17 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
12 | #1 0x00007f035874f895 in abort () at /lib64/libc.so.6 | ||
13 | #2 0x00005628686591ff in fifo8_pop (fifo=0x56286a9a4c68) at util/fifo8.c:66 | ||
14 | #3 0x00005628683e0b8e in fifo32_pop (fifo=0x56286a9a4c68) at include/qemu/fifo32.h:137 | ||
15 | #4 0x00005628683e0efb in spi_read (opaque=0x56286a9a4850, addr=4, size=4) at hw/ssi/mss-spi.c:168 | ||
16 | #5 0x0000562867f96801 in memory_region_read_accessor (mr=0x56286a9a4b60, addr=16, value=0x7ffeecb0c5c8, size=4, shift=0, mask=4294967295, attrs=...) at memory.c:439 | ||
17 | #6 0x0000562867f96cdb in access_with_adjusted_size (addr=16, value=0x7ffeecb0c5c8, size=4, access_size_min=1, access_size_max=4, access_fn=0x562867f967c3 <memory_region_read_accessor>, mr=0x56286a9a4b60, attrs=...) at memory.c:569 | ||
18 | #7 0x0000562867f99940 in memory_region_dispatch_read1 (mr=0x56286a9a4b60, addr=16, pval=0x7ffeecb0c5c8, size=4, attrs=...) at memory.c:1420 | ||
19 | #8 0x0000562867f99a08 in memory_region_dispatch_read (mr=0x56286a9a4b60, addr=16, pval=0x7ffeecb0c5c8, size=4, attrs=...) at memory.c:1447 | ||
20 | #9 0x0000562867f38721 in flatview_read_continue (fv=0x56286aec6360, addr=1073745936, attrs=..., buf=0x7ffeecb0c7c0 "\340ǰ\354\376\177", len=4, addr1=16, l=4, mr=0x56286a9a4b60) at exec.c:3385 | ||
21 | #10 0x0000562867f38874 in flatview_read (fv=0x56286aec6360, addr=1073745936, attrs=..., buf=0x7ffeecb0c7c0 "\340ǰ\354\376\177", len=4) at exec.c:3423 | ||
22 | #11 0x0000562867f388ea in address_space_read_full (as=0x56286aa3e890, addr=1073745936, attrs=..., buf=0x7ffeecb0c7c0 "\340ǰ\354\376\177", len=4) at exec.c:3436 | ||
23 | #12 0x0000562867f389c5 in address_space_rw (as=0x56286aa3e890, addr=1073745936, attrs=..., buf=0x7ffeecb0c7c0 "\340ǰ\354\376\177", len=4, is_write=false) at exec.c:3466 | ||
24 | #13 0x0000562867f3bdd7 in cpu_memory_rw_debug (cpu=0x56286aa19d00, addr=1073745936, buf=0x7ffeecb0c7c0 "\340ǰ\354\376\177", len=4, is_write=0) at exec.c:3976 | ||
25 | #14 0x000056286811ed51 in memory_dump (mon=0x56286a8c32d0, count=1, format=120, wsize=4, addr=1073745936, is_physical=0) at monitor/misc.c:730 | ||
26 | #15 0x000056286811eff1 in hmp_memory_dump (mon=0x56286a8c32d0, qdict=0x56286b15c400) at monitor/misc.c:785 | ||
27 | #16 0x00005628684740ee in handle_hmp_command (mon=0x56286a8c32d0, cmdline=0x56286a8caeb2 "0x40001010") at monitor/hmp.c:1082 | ||
28 | |||
29 | From the datasheet "Actel SmartFusion Microcontroller Subsystem | ||
30 | User's Guide" Rev.1, Table 13-3 "SPI Register Summary", this | ||
31 | register has a reset value of 0. | ||
32 | |||
33 | Check the FIFO is not empty before accessing it, else log an | ||
34 | error message. | ||
35 | |||
36 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
37 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
38 | Message-id: 20190709113715.7761-3-philmd@redhat.com | ||
39 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
40 | --- | ||
41 | hw/ssi/mss-spi.c | 8 +++++++- | ||
42 | 1 file changed, 7 insertions(+), 1 deletion(-) | ||
43 | |||
44 | diff --git a/hw/ssi/mss-spi.c b/hw/ssi/mss-spi.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/hw/ssi/mss-spi.c | 19 | --- a/target/arm/helper.c |
47 | +++ b/hw/ssi/mss-spi.c | 20 | +++ b/target/arm/helper.c |
48 | @@ -XXX,XX +XXX,XX @@ spi_read(void *opaque, hwaddr addr, unsigned int size) | 21 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult gt_stimer_access(CPUARMState *env, |
49 | case R_SPI_RX: | 22 | if (!arm_is_secure(env)) { |
50 | s->regs[R_SPI_STATUS] &= ~S_RXFIFOFUL; | 23 | return CP_ACCESS_UNDEFINED; |
51 | s->regs[R_SPI_STATUS] &= ~S_RXCHOVRF; | 24 | } |
52 | - ret = fifo32_pop(&s->rx_fifo); | 25 | + if (arm_is_el2_enabled(env)) { |
53 | + if (fifo32_is_empty(&s->rx_fifo)) { | 26 | + return CP_ACCESS_UNDEFINED; |
54 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
55 | + "%s: Reading empty RX_FIFO\n", | ||
56 | + __func__); | ||
57 | + } else { | ||
58 | + ret = fifo32_pop(&s->rx_fifo); | ||
59 | + } | 27 | + } |
60 | if (fifo32_is_empty(&s->rx_fifo)) { | 28 | if (!(env->cp15.scr_el3 & SCR_ST)) { |
61 | s->regs[R_SPI_STATUS] |= S_RXFIFOEMP; | 29 | return CP_ACCESS_TRAP_EL3; |
62 | } | 30 | } |
63 | -- | 31 | -- |
64 | 2.20.1 | 32 | 2.43.0 |
65 | 33 | ||
66 | 34 | diff view generated by jsdifflib |
1 | The PL031 RTC tracks the difference between the guest RTC | 1 | Currently we handle CNTV_TVAL_EL02 by calling gt_tval_read() for the |
---|---|---|---|
2 | and the host RTC using a tick_offset field. For migration, | 2 | EL1 virt timer. This is almost correct, but the underlying |
3 | however, we currently always migrate the offset between | 3 | CNTV_TVAL_EL0 register behaves slightly differently. CNTV_TVAL_EL02 |
4 | the guest and the vm_clock, even if the RTC clock is not | 4 | always applies the CNTVOFF_EL2 offset; CNTV_TVAL_EL0 doesn't do so if |
5 | the same as the vm_clock; this was an attempt to retain | 5 | we're at EL2 and HCR_EL2.E2H is 1. |
6 | migration backwards compatibility. | ||
7 | 6 | ||
8 | Unfortunately this results in the RTC behaving oddly across | 7 | We were getting this wrong, because we ended up in |
9 | a VM state save and restore -- since the VM clock stands still | 8 | gt_virt_cnt_offset() and did the E2H check. |
10 | across save-then-restore, regardless of how much real world | ||
11 | time has elapsed, the guest RTC ends up out of sync with the | ||
12 | host RTC in the restored VM. | ||
13 | 9 | ||
14 | Fix this by migrating the raw tick_offset. To retain migration | 10 | Factor out the tval read/write calculation from the selection of the |
15 | compatibility as far as possible, we have a new property | 11 | offset, so that we can special case gt_virt_tval_read() and |
16 | migrate-tick-offset; by default this is 'true' and we will | 12 | gt_virt_tval_write() to unconditionally pass CNTVOFF_EL2. |
17 | migrate the true tick offset in a new subsection; if the | ||
18 | incoming data has no subsection we fall back to the old | ||
19 | vm_clock-based offset information, so old->new migration | ||
20 | compatibility is preserved. For complete new->old migration | ||
21 | compatibility, the property is set to 'false' for 4.0 and | ||
22 | earlier machine types (this will only affect 'virt-4.0' | ||
23 | and below, as none of the other pl031-using machines are | ||
24 | versioned). | ||
25 | 13 | ||
26 | Reported-by: Russell King <rmk@armlinux.org.uk> | 14 | Cc: qemu-stable@nongnu.org |
27 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
28 | Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> | 16 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
29 | Message-id: 20190709143912.28905-1-peter.maydell@linaro.org | 17 | Message-id: 20250204125009.2281315-5-peter.maydell@linaro.org |
30 | --- | 18 | --- |
31 | include/hw/timer/pl031.h | 2 + | 19 | target/arm/helper.c | 36 +++++++++++++++++++++++++++--------- |
32 | hw/core/machine.c | 1 + | 20 | 1 file changed, 27 insertions(+), 9 deletions(-) |
33 | hw/timer/pl031.c | 92 ++++++++++++++++++++++++++++++++++++++-- | ||
34 | 3 files changed, 91 insertions(+), 4 deletions(-) | ||
35 | 21 | ||
36 | diff --git a/include/hw/timer/pl031.h b/include/hw/timer/pl031.h | 22 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
37 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
38 | --- a/include/hw/timer/pl031.h | 24 | --- a/target/arm/helper.c |
39 | +++ b/include/hw/timer/pl031.h | 25 | +++ b/target/arm/helper.c |
40 | @@ -XXX,XX +XXX,XX @@ typedef struct PL031State { | 26 | @@ -XXX,XX +XXX,XX @@ static void gt_cval_write(CPUARMState *env, const ARMCPRegInfo *ri, |
41 | */ | 27 | gt_recalc_timer(env_archcpu(env), timeridx); |
42 | uint32_t tick_offset_vmstate; | ||
43 | uint32_t tick_offset; | ||
44 | + bool tick_offset_migrated; | ||
45 | + bool migrate_tick_offset; | ||
46 | |||
47 | uint32_t mr; | ||
48 | uint32_t lr; | ||
49 | diff --git a/hw/core/machine.c b/hw/core/machine.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/hw/core/machine.c | ||
52 | +++ b/hw/core/machine.c | ||
53 | @@ -XXX,XX +XXX,XX @@ GlobalProperty hw_compat_4_0[] = { | ||
54 | { "virtio-gpu-pci", "edid", "false" }, | ||
55 | { "virtio-device", "use-started", "false" }, | ||
56 | { "virtio-balloon-device", "qemu-4-0-config-size", "true" }, | ||
57 | + { "pl031", "migrate-tick-offset", "false" }, | ||
58 | }; | ||
59 | const size_t hw_compat_4_0_len = G_N_ELEMENTS(hw_compat_4_0); | ||
60 | |||
61 | diff --git a/hw/timer/pl031.c b/hw/timer/pl031.c | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/hw/timer/pl031.c | ||
64 | +++ b/hw/timer/pl031.c | ||
65 | @@ -XXX,XX +XXX,XX @@ static int pl031_pre_save(void *opaque) | ||
66 | { | ||
67 | PL031State *s = opaque; | ||
68 | |||
69 | - /* tick_offset is base_time - rtc_clock base time. Instead, we want to | ||
70 | - * store the base time relative to the QEMU_CLOCK_VIRTUAL for backwards-compatibility. */ | ||
71 | + /* | ||
72 | + * The PL031 device model code uses the tick_offset field, which is | ||
73 | + * the offset between what the guest RTC should read and what the | ||
74 | + * QEMU rtc_clock reads: | ||
75 | + * guest_rtc = rtc_clock + tick_offset | ||
76 | + * and so | ||
77 | + * tick_offset = guest_rtc - rtc_clock | ||
78 | + * | ||
79 | + * We want to migrate this offset, which sounds straightforward. | ||
80 | + * Unfortunately older versions of QEMU migrated a conversion of this | ||
81 | + * offset into an offset from the vm_clock. (This was in turn an | ||
82 | + * attempt to be compatible with even older QEMU versions, but it | ||
83 | + * has incorrect behaviour if the rtc_clock is not the same as the | ||
84 | + * vm_clock.) So we put the actual tick_offset into a migration | ||
85 | + * subsection, and the backwards-compatible time-relative-to-vm_clock | ||
86 | + * in the main migration state. | ||
87 | + * | ||
88 | + * Calculate base time relative to QEMU_CLOCK_VIRTUAL: | ||
89 | + */ | ||
90 | int64_t delta = qemu_clock_get_ns(rtc_clock) - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
91 | s->tick_offset_vmstate = s->tick_offset + delta / NANOSECONDS_PER_SECOND; | ||
92 | |||
93 | return 0; | ||
94 | } | 28 | } |
95 | 29 | ||
96 | +static int pl031_pre_load(void *opaque) | 30 | +static uint64_t do_tval_read(CPUARMState *env, int timeridx, uint64_t offset) |
97 | +{ | 31 | +{ |
98 | + PL031State *s = opaque; | 32 | + return (uint32_t)(env->cp15.c14_timer[timeridx].cval - |
99 | + | 33 | + (gt_get_countervalue(env) - offset)); |
100 | + s->tick_offset_migrated = false; | ||
101 | + return 0; | ||
102 | +} | 34 | +} |
103 | + | 35 | + |
104 | static int pl031_post_load(void *opaque, int version_id) | 36 | static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri, |
37 | int timeridx) | ||
105 | { | 38 | { |
106 | PL031State *s = opaque; | 39 | @@ -XXX,XX +XXX,XX @@ static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri, |
107 | 40 | break; | |
108 | - int64_t delta = qemu_clock_get_ns(rtc_clock) - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | 41 | } |
109 | - s->tick_offset = s->tick_offset_vmstate - delta / NANOSECONDS_PER_SECOND; | 42 | |
110 | + /* | 43 | - return (uint32_t)(env->cp15.c14_timer[timeridx].cval - |
111 | + * If we got the tick_offset subsection, then we can just use | 44 | - (gt_get_countervalue(env) - offset)); |
112 | + * the value in that. Otherwise the source is an older QEMU and | 45 | + return do_tval_read(env, timeridx, offset); |
113 | + * has given us the offset from the vm_clock; convert it back to | ||
114 | + * an offset from the rtc_clock. This will cause time to incorrectly | ||
115 | + * go backwards compared to the host RTC, but this is unavoidable. | ||
116 | + */ | ||
117 | + | ||
118 | + if (!s->tick_offset_migrated) { | ||
119 | + int64_t delta = qemu_clock_get_ns(rtc_clock) - | ||
120 | + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
121 | + s->tick_offset = s->tick_offset_vmstate - | ||
122 | + delta / NANOSECONDS_PER_SECOND; | ||
123 | + } | ||
124 | pl031_set_alarm(s); | ||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | +static int pl031_tick_offset_post_load(void *opaque, int version_id) | ||
129 | +{ | ||
130 | + PL031State *s = opaque; | ||
131 | + | ||
132 | + s->tick_offset_migrated = true; | ||
133 | + return 0; | ||
134 | +} | 46 | +} |
135 | + | 47 | + |
136 | +static bool pl031_tick_offset_needed(void *opaque) | 48 | +static void do_tval_write(CPUARMState *env, int timeridx, uint64_t value, |
49 | + uint64_t offset) | ||
137 | +{ | 50 | +{ |
138 | + PL031State *s = opaque; | 51 | + trace_arm_gt_tval_write(timeridx, value); |
139 | + | 52 | + env->cp15.c14_timer[timeridx].cval = gt_get_countervalue(env) - offset + |
140 | + return s->migrate_tick_offset; | 53 | + sextract64(value, 0, 32); |
141 | +} | 54 | + gt_recalc_timer(env_archcpu(env), timeridx); |
142 | + | 55 | } |
143 | +static const VMStateDescription vmstate_pl031_tick_offset = { | 56 | |
144 | + .name = "pl031/tick-offset", | 57 | static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri, |
145 | + .version_id = 1, | 58 | @@ -XXX,XX +XXX,XX @@ static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri, |
146 | + .minimum_version_id = 1, | 59 | offset = gt_phys_cnt_offset(env); |
147 | + .needed = pl031_tick_offset_needed, | 60 | break; |
148 | + .post_load = pl031_tick_offset_post_load, | ||
149 | + .fields = (VMStateField[]) { | ||
150 | + VMSTATE_UINT32(tick_offset, PL031State), | ||
151 | + VMSTATE_END_OF_LIST() | ||
152 | + } | ||
153 | +}; | ||
154 | + | ||
155 | static const VMStateDescription vmstate_pl031 = { | ||
156 | .name = "pl031", | ||
157 | .version_id = 1, | ||
158 | .minimum_version_id = 1, | ||
159 | .pre_save = pl031_pre_save, | ||
160 | + .pre_load = pl031_pre_load, | ||
161 | .post_load = pl031_post_load, | ||
162 | .fields = (VMStateField[]) { | ||
163 | VMSTATE_UINT32(tick_offset_vmstate, PL031State), | ||
164 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pl031 = { | ||
165 | VMSTATE_UINT32(im, PL031State), | ||
166 | VMSTATE_UINT32(is, PL031State), | ||
167 | VMSTATE_END_OF_LIST() | ||
168 | + }, | ||
169 | + .subsections = (const VMStateDescription*[]) { | ||
170 | + &vmstate_pl031_tick_offset, | ||
171 | + NULL | ||
172 | } | 61 | } |
173 | }; | 62 | - |
174 | 63 | - trace_arm_gt_tval_write(timeridx, value); | |
175 | +static Property pl031_properties[] = { | 64 | - env->cp15.c14_timer[timeridx].cval = gt_get_countervalue(env) - offset + |
65 | - sextract64(value, 0, 32); | ||
66 | - gt_recalc_timer(env_archcpu(env), timeridx); | ||
67 | + do_tval_write(env, timeridx, value, offset); | ||
68 | } | ||
69 | |||
70 | static void gt_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
71 | @@ -XXX,XX +XXX,XX @@ static void gt_virt_cval_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
72 | |||
73 | static uint64_t gt_virt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
74 | { | ||
75 | - return gt_tval_read(env, ri, GTIMER_VIRT); | ||
176 | + /* | 76 | + /* |
177 | + * True to correctly migrate the tick offset of the RTC. False to | 77 | + * This is CNTV_TVAL_EL02; unlike the underlying CNTV_TVAL_EL0 |
178 | + * obtain backward migration compatibility with older QEMU versions, | 78 | + * we always apply CNTVOFF_EL2. Special case that here rather |
179 | + * at the expense of the guest RTC going backwards compared with the | 79 | + * than going into the generic gt_tval_read() and then having |
180 | + * host RTC when the VM is saved/restored if using -rtc host. | 80 | + * to re-detect that it's this register. |
181 | + * (Even if set to 'true' older QEMU can migrate forward to newer QEMU; | 81 | + * Note that the accessfn/perms mean we know we're at EL2 or EL3 here. |
182 | + * 'false' also permits newer QEMU to migrate to older QEMU.) | ||
183 | + */ | 82 | + */ |
184 | + DEFINE_PROP_BOOL("migrate-tick-offset", | 83 | + return do_tval_read(env, GTIMER_VIRT, env->cp15.cntvoff_el2); |
185 | + PL031State, migrate_tick_offset, true), | 84 | } |
186 | + DEFINE_PROP_END_OF_LIST() | 85 | |
187 | +}; | 86 | static void gt_virt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri, |
188 | + | 87 | uint64_t value) |
189 | static void pl031_class_init(ObjectClass *klass, void *data) | ||
190 | { | 88 | { |
191 | DeviceClass *dc = DEVICE_CLASS(klass); | 89 | - gt_tval_write(env, ri, GTIMER_VIRT, value); |
192 | 90 | + /* Similarly for writes to CNTV_TVAL_EL02 */ | |
193 | dc->vmsd = &vmstate_pl031; | 91 | + do_tval_write(env, GTIMER_VIRT, value, env->cp15.cntvoff_el2); |
194 | + dc->props = pl031_properties; | ||
195 | } | 92 | } |
196 | 93 | ||
197 | static const TypeInfo pl031_info = { | 94 | static void gt_virt_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri, |
198 | -- | 95 | -- |
199 | 2.20.1 | 96 | 2.43.0 |
200 | 97 | ||
201 | 98 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | When reading or writing the timer registers, sometimes we need to | |
2 | apply one of the timer offsets. Specifically, this happens for | ||
3 | direct reads of the counter registers CNTPCT_EL0 and CNTVCT_EL0 (and | ||
4 | their self-synchronized variants CNTVCTSS_EL0 and CNTPCTSS_EL0). It | ||
5 | also applies for direct reads and writes of the CNT*_TVAL_EL* | ||
6 | registers that provide the 32-bit downcounting view of each timer. | ||
7 | |||
8 | We currently do this with duplicated code in gt_tval_read() and | ||
9 | gt_tval_write() and a special-case in gt_virt_cnt_read() and | ||
10 | gt_cnt_read(). Refactor this so that we handle it all in a single | ||
11 | function gt_direct_access_timer_offset(), to parallel how we handle | ||
12 | the offset for indirect accesses. | ||
13 | |||
14 | The call in the WFIT helper previously to gt_virt_cnt_offset() is | ||
15 | now to gt_direct_access_timer_offset(); this is the correct | ||
16 | behaviour, but it's not immediately obvious that it shouldn't be | ||
17 | considered an indirect access, so we add an explanatory comment. | ||
18 | |||
19 | This commit should make no behavioural changes. | ||
20 | |||
21 | (Cc to stable because the following bugfix commit will | ||
22 | depend on this one.) | ||
23 | |||
24 | Cc: qemu-stable@nongnu.org | ||
25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
26 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
27 | Message-id: 20250204125009.2281315-6-peter.maydell@linaro.org | ||
28 | --- | ||
29 | target/arm/internals.h | 5 +- | ||
30 | target/arm/helper.c | 103 +++++++++++++++++++------------------ | ||
31 | target/arm/tcg/op_helper.c | 8 ++- | ||
32 | 3 files changed, 62 insertions(+), 54 deletions(-) | ||
33 | |||
34 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/target/arm/internals.h | ||
37 | +++ b/target/arm/internals.h | ||
38 | @@ -XXX,XX +XXX,XX @@ int delete_hw_watchpoint(target_ulong addr, target_ulong len, int type); | ||
39 | uint64_t gt_get_countervalue(CPUARMState *env); | ||
40 | /* | ||
41 | * Return the currently applicable offset between the system counter | ||
42 | - * and CNTVCT_EL0 (this will be either 0 or the value of CNTVOFF_EL2). | ||
43 | + * and the counter for the specified timer, as used for direct register | ||
44 | + * accesses. | ||
45 | */ | ||
46 | -uint64_t gt_virt_cnt_offset(CPUARMState *env); | ||
47 | +uint64_t gt_direct_access_timer_offset(CPUARMState *env, int timeridx); | ||
48 | |||
49 | /* | ||
50 | * Return mask of ARMMMUIdxBit values corresponding to an "invalidate | ||
51 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/arm/helper.c | ||
54 | +++ b/target/arm/helper.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static uint64_t gt_phys_raw_cnt_offset(CPUARMState *env) | ||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | -static uint64_t gt_phys_cnt_offset(CPUARMState *env) | ||
60 | -{ | ||
61 | - if (arm_current_el(env) >= 2) { | ||
62 | - return 0; | ||
63 | - } | ||
64 | - return gt_phys_raw_cnt_offset(env); | ||
65 | -} | ||
66 | - | ||
67 | static uint64_t gt_indirect_access_timer_offset(CPUARMState *env, int timeridx) | ||
68 | { | ||
69 | /* | ||
70 | @@ -XXX,XX +XXX,XX @@ static uint64_t gt_indirect_access_timer_offset(CPUARMState *env, int timeridx) | ||
71 | } | ||
72 | } | ||
73 | |||
74 | +uint64_t gt_direct_access_timer_offset(CPUARMState *env, int timeridx) | ||
75 | +{ | ||
76 | + /* | ||
77 | + * Return the timer offset to use for direct accesses to the | ||
78 | + * counter registers CNTPCT and CNTVCT, and for direct accesses | ||
79 | + * to the CNT*_TVAL registers. | ||
80 | + * | ||
81 | + * This isn't exactly the same as the indirect-access offset, | ||
82 | + * because here we also care about what EL the register access | ||
83 | + * is being made from. | ||
84 | + * | ||
85 | + * This corresponds to the access pseudocode for the registers. | ||
86 | + */ | ||
87 | + uint64_t hcr; | ||
88 | + | ||
89 | + switch (timeridx) { | ||
90 | + case GTIMER_PHYS: | ||
91 | + if (arm_current_el(env) >= 2) { | ||
92 | + return 0; | ||
93 | + } | ||
94 | + return gt_phys_raw_cnt_offset(env); | ||
95 | + case GTIMER_VIRT: | ||
96 | + switch (arm_current_el(env)) { | ||
97 | + case 2: | ||
98 | + hcr = arm_hcr_el2_eff(env); | ||
99 | + if (hcr & HCR_E2H) { | ||
100 | + return 0; | ||
101 | + } | ||
102 | + break; | ||
103 | + case 0: | ||
104 | + hcr = arm_hcr_el2_eff(env); | ||
105 | + if ((hcr & (HCR_E2H | HCR_TGE)) == (HCR_E2H | HCR_TGE)) { | ||
106 | + return 0; | ||
107 | + } | ||
108 | + break; | ||
109 | + } | ||
110 | + return env->cp15.cntvoff_el2; | ||
111 | + case GTIMER_HYP: | ||
112 | + case GTIMER_SEC: | ||
113 | + case GTIMER_HYPVIRT: | ||
114 | + return 0; | ||
115 | + default: | ||
116 | + g_assert_not_reached(); | ||
117 | + } | ||
118 | +} | ||
119 | + | ||
120 | static void gt_recalc_timer(ARMCPU *cpu, int timeridx) | ||
121 | { | ||
122 | ARMGenericTimer *gt = &cpu->env.cp15.c14_timer[timeridx]; | ||
123 | @@ -XXX,XX +XXX,XX @@ static void gt_timer_reset(CPUARMState *env, const ARMCPRegInfo *ri, | ||
124 | |||
125 | static uint64_t gt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
126 | { | ||
127 | - return gt_get_countervalue(env) - gt_phys_cnt_offset(env); | ||
128 | -} | ||
129 | - | ||
130 | -uint64_t gt_virt_cnt_offset(CPUARMState *env) | ||
131 | -{ | ||
132 | - uint64_t hcr; | ||
133 | - | ||
134 | - switch (arm_current_el(env)) { | ||
135 | - case 2: | ||
136 | - hcr = arm_hcr_el2_eff(env); | ||
137 | - if (hcr & HCR_E2H) { | ||
138 | - return 0; | ||
139 | - } | ||
140 | - break; | ||
141 | - case 0: | ||
142 | - hcr = arm_hcr_el2_eff(env); | ||
143 | - if ((hcr & (HCR_E2H | HCR_TGE)) == (HCR_E2H | HCR_TGE)) { | ||
144 | - return 0; | ||
145 | - } | ||
146 | - break; | ||
147 | - } | ||
148 | - | ||
149 | - return env->cp15.cntvoff_el2; | ||
150 | + uint64_t offset = gt_direct_access_timer_offset(env, GTIMER_PHYS); | ||
151 | + return gt_get_countervalue(env) - offset; | ||
152 | } | ||
153 | |||
154 | static uint64_t gt_virt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
155 | { | ||
156 | - return gt_get_countervalue(env) - gt_virt_cnt_offset(env); | ||
157 | + uint64_t offset = gt_direct_access_timer_offset(env, GTIMER_VIRT); | ||
158 | + return gt_get_countervalue(env) - offset; | ||
159 | } | ||
160 | |||
161 | static void gt_cval_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
162 | @@ -XXX,XX +XXX,XX @@ static uint64_t do_tval_read(CPUARMState *env, int timeridx, uint64_t offset) | ||
163 | static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri, | ||
164 | int timeridx) | ||
165 | { | ||
166 | - uint64_t offset = 0; | ||
167 | - | ||
168 | - switch (timeridx) { | ||
169 | - case GTIMER_VIRT: | ||
170 | - offset = gt_virt_cnt_offset(env); | ||
171 | - break; | ||
172 | - case GTIMER_PHYS: | ||
173 | - offset = gt_phys_cnt_offset(env); | ||
174 | - break; | ||
175 | - } | ||
176 | + uint64_t offset = gt_direct_access_timer_offset(env, timeridx); | ||
177 | |||
178 | return do_tval_read(env, timeridx, offset); | ||
179 | } | ||
180 | @@ -XXX,XX +XXX,XX @@ static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
181 | int timeridx, | ||
182 | uint64_t value) | ||
183 | { | ||
184 | - uint64_t offset = 0; | ||
185 | + uint64_t offset = gt_direct_access_timer_offset(env, timeridx); | ||
186 | |||
187 | - switch (timeridx) { | ||
188 | - case GTIMER_VIRT: | ||
189 | - offset = gt_virt_cnt_offset(env); | ||
190 | - break; | ||
191 | - case GTIMER_PHYS: | ||
192 | - offset = gt_phys_cnt_offset(env); | ||
193 | - break; | ||
194 | - } | ||
195 | do_tval_write(env, timeridx, value, offset); | ||
196 | } | ||
197 | |||
198 | diff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c | ||
199 | index XXXXXXX..XXXXXXX 100644 | ||
200 | --- a/target/arm/tcg/op_helper.c | ||
201 | +++ b/target/arm/tcg/op_helper.c | ||
202 | @@ -XXX,XX +XXX,XX @@ void HELPER(wfit)(CPUARMState *env, uint64_t timeout) | ||
203 | int target_el = check_wfx_trap(env, false, &excp); | ||
204 | /* The WFIT should time out when CNTVCT_EL0 >= the specified value. */ | ||
205 | uint64_t cntval = gt_get_countervalue(env); | ||
206 | - uint64_t offset = gt_virt_cnt_offset(env); | ||
207 | + /* | ||
208 | + * We want the value that we would get if we read CNTVCT_EL0 from | ||
209 | + * the current exception level, so the direct_access offset, not | ||
210 | + * the indirect_access one. Compare the pseudocode LocalTimeoutEvent(), | ||
211 | + * which calls VirtualCounterTimer(). | ||
212 | + */ | ||
213 | + uint64_t offset = gt_direct_access_timer_offset(env, GTIMER_VIRT); | ||
214 | uint64_t cntvct = cntval - offset; | ||
215 | uint64_t nexttick; | ||
216 | |||
217 | -- | ||
218 | 2.43.0 | ||
219 | |||
220 | diff view generated by jsdifflib |
1 | From: Alex Bennée <alex.bennee@linaro.org> | 1 | From: Alex Bennée <alex.bennee@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | When we converted to using feature bits in 602f6e42cfbf we missed out | 3 | When FEAT_SEL2 was implemented the SEL2 timers were missed. This |
4 | the fact (dp && arm_dc_feature(s, ARM_FEATURE_V8)) was supported for | 4 | shows up when building the latest Hafnium with SPMC_AT_EL=2. The |
5 | -cpu max configurations. This caused a regression in the GCC test | 5 | actual implementation utilises the same logic as the rest of the |
6 | suite. Fix this by setting the appropriate bits in mvfr1.FPHP to | 6 | timers so all we need to do is: |
7 | report ARMv8-A with FP support (but not ARMv8.2-FP16). | 7 | |
8 | 8 | - define the timers and their access functions | |
9 | Fixes: https://bugs.launchpad.net/qemu/+bug/1836078 | 9 | - conditionally add the correct system registers |
10 | - create a new accessfn as the rules are subtly different to the | ||
11 | existing secure timer | ||
12 | |||
13 | Fixes: e9152ee91c (target/arm: add ARMv8.4-SEL2 system registers) | ||
10 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | 14 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> |
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | Message-id: 20190711103737.10017-1-alex.bennee@linaro.org | 16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
17 | Message-id: 20250204125009.2281315-7-peter.maydell@linaro.org | ||
18 | Cc: qemu-stable@nongnu.org | ||
19 | Cc: Andrei Homescu <ahomescu@google.com> | ||
20 | Cc: Arve Hjønnevåg <arve@google.com> | ||
21 | Cc: Rémi Denis-Courmont <remi.denis.courmont@huawei.com> | ||
22 | [PMM: CP_ACCESS_TRAP_UNCATEGORIZED -> CP_ACCESS_UNDEFINED; | ||
23 | offset logic now in gt_{indirect,direct}_access_timer_offset() ] | ||
24 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 26 | --- |
15 | target/arm/cpu.c | 4 ++++ | 27 | include/hw/arm/bsa.h | 2 + |
16 | 1 file changed, 4 insertions(+) | 28 | target/arm/cpu.h | 2 + |
17 | 29 | target/arm/gtimer.h | 4 +- | |
30 | target/arm/cpu.c | 4 ++ | ||
31 | target/arm/helper.c | 163 +++++++++++++++++++++++++++++++++++++++++++ | ||
32 | 5 files changed, 174 insertions(+), 1 deletion(-) | ||
33 | |||
34 | diff --git a/include/hw/arm/bsa.h b/include/hw/arm/bsa.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/include/hw/arm/bsa.h | ||
37 | +++ b/include/hw/arm/bsa.h | ||
38 | @@ -XXX,XX +XXX,XX @@ | ||
39 | #define QEMU_ARM_BSA_H | ||
40 | |||
41 | /* These are architectural INTID values */ | ||
42 | +#define ARCH_TIMER_S_EL2_VIRT_IRQ 19 | ||
43 | +#define ARCH_TIMER_S_EL2_IRQ 20 | ||
44 | #define VIRTUAL_PMU_IRQ 23 | ||
45 | #define ARCH_GIC_MAINT_IRQ 25 | ||
46 | #define ARCH_TIMER_NS_EL2_IRQ 26 | ||
47 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/target/arm/cpu.h | ||
50 | +++ b/target/arm/cpu.h | ||
51 | @@ -XXX,XX +XXX,XX @@ void arm_gt_vtimer_cb(void *opaque); | ||
52 | void arm_gt_htimer_cb(void *opaque); | ||
53 | void arm_gt_stimer_cb(void *opaque); | ||
54 | void arm_gt_hvtimer_cb(void *opaque); | ||
55 | +void arm_gt_sel2timer_cb(void *opaque); | ||
56 | +void arm_gt_sel2vtimer_cb(void *opaque); | ||
57 | |||
58 | unsigned int gt_cntfrq_period_ns(ARMCPU *cpu); | ||
59 | void gt_rme_post_el_change(ARMCPU *cpu, void *opaque); | ||
60 | diff --git a/target/arm/gtimer.h b/target/arm/gtimer.h | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/target/arm/gtimer.h | ||
63 | +++ b/target/arm/gtimer.h | ||
64 | @@ -XXX,XX +XXX,XX @@ enum { | ||
65 | GTIMER_HYP = 2, | ||
66 | GTIMER_SEC = 3, | ||
67 | GTIMER_HYPVIRT = 4, | ||
68 | -#define NUM_GTIMERS 5 | ||
69 | + GTIMER_S_EL2_PHYS = 5, /* CNTHPS_* ; only if FEAT_SEL2 */ | ||
70 | + GTIMER_S_EL2_VIRT = 6, /* CNTHVS_* ; only if FEAT_SEL2 */ | ||
71 | +#define NUM_GTIMERS 7 | ||
72 | }; | ||
73 | |||
74 | #endif | ||
18 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 75 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
19 | index XXXXXXX..XXXXXXX 100644 | 76 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/cpu.c | 77 | --- a/target/arm/cpu.c |
21 | +++ b/target/arm/cpu.c | 78 | +++ b/target/arm/cpu.c |
22 | @@ -XXX,XX +XXX,XX @@ static void arm_max_initfn(Object *obj) | 79 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) |
23 | t = FIELD_DP32(t, ID_ISAR6, SPECRES, 1); | 80 | arm_gt_stimer_cb, cpu); |
24 | cpu->isar.id_isar6 = t; | 81 | cpu->gt_timer[GTIMER_HYPVIRT] = timer_new(QEMU_CLOCK_VIRTUAL, scale, |
25 | 82 | arm_gt_hvtimer_cb, cpu); | |
26 | + t = cpu->isar.mvfr1; | 83 | + cpu->gt_timer[GTIMER_S_EL2_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, scale, |
27 | + t = FIELD_DP32(t, MVFR1, FPHP, 2); /* v8.0 FP support */ | 84 | + arm_gt_sel2timer_cb, cpu); |
28 | + cpu->isar.mvfr1 = t; | 85 | + cpu->gt_timer[GTIMER_S_EL2_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, scale, |
29 | + | 86 | + arm_gt_sel2vtimer_cb, cpu); |
30 | t = cpu->isar.mvfr2; | 87 | } |
31 | t = FIELD_DP32(t, MVFR2, SIMDMISC, 3); /* SIMD MaxNum */ | 88 | #endif |
32 | t = FIELD_DP32(t, MVFR2, FPMISC, 4); /* FP MaxNum */ | 89 | |
90 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
91 | index XXXXXXX..XXXXXXX 100644 | ||
92 | --- a/target/arm/helper.c | ||
93 | +++ b/target/arm/helper.c | ||
94 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult gt_stimer_access(CPUARMState *env, | ||
95 | } | ||
96 | } | ||
97 | |||
98 | +static CPAccessResult gt_sel2timer_access(CPUARMState *env, | ||
99 | + const ARMCPRegInfo *ri, | ||
100 | + bool isread) | ||
101 | +{ | ||
102 | + /* | ||
103 | + * The AArch64 register view of the secure EL2 timers are mostly | ||
104 | + * accessible from EL3 and EL2 although can also be trapped to EL2 | ||
105 | + * from EL1 depending on nested virt config. | ||
106 | + */ | ||
107 | + switch (arm_current_el(env)) { | ||
108 | + case 0: /* UNDEFINED */ | ||
109 | + return CP_ACCESS_UNDEFINED; | ||
110 | + case 1: | ||
111 | + if (!arm_is_secure(env)) { | ||
112 | + /* UNDEFINED */ | ||
113 | + return CP_ACCESS_UNDEFINED; | ||
114 | + } else if (arm_hcr_el2_eff(env) & HCR_NV) { | ||
115 | + /* Aarch64.SystemAccessTrap(EL2, 0x18) */ | ||
116 | + return CP_ACCESS_TRAP_EL2; | ||
117 | + } | ||
118 | + /* UNDEFINED */ | ||
119 | + return CP_ACCESS_UNDEFINED; | ||
120 | + case 2: | ||
121 | + if (!arm_is_secure(env)) { | ||
122 | + /* UNDEFINED */ | ||
123 | + return CP_ACCESS_UNDEFINED; | ||
124 | + } | ||
125 | + return CP_ACCESS_OK; | ||
126 | + case 3: | ||
127 | + if (env->cp15.scr_el3 & SCR_EEL2) { | ||
128 | + return CP_ACCESS_OK; | ||
129 | + } else { | ||
130 | + return CP_ACCESS_UNDEFINED; | ||
131 | + } | ||
132 | + default: | ||
133 | + g_assert_not_reached(); | ||
134 | + } | ||
135 | +} | ||
136 | + | ||
137 | uint64_t gt_get_countervalue(CPUARMState *env) | ||
138 | { | ||
139 | ARMCPU *cpu = env_archcpu(env); | ||
140 | @@ -XXX,XX +XXX,XX @@ static uint64_t gt_indirect_access_timer_offset(CPUARMState *env, int timeridx) | ||
141 | case GTIMER_HYP: | ||
142 | case GTIMER_SEC: | ||
143 | case GTIMER_HYPVIRT: | ||
144 | + case GTIMER_S_EL2_PHYS: | ||
145 | + case GTIMER_S_EL2_VIRT: | ||
146 | return 0; | ||
147 | default: | ||
148 | g_assert_not_reached(); | ||
149 | @@ -XXX,XX +XXX,XX @@ uint64_t gt_direct_access_timer_offset(CPUARMState *env, int timeridx) | ||
150 | case GTIMER_HYP: | ||
151 | case GTIMER_SEC: | ||
152 | case GTIMER_HYPVIRT: | ||
153 | + case GTIMER_S_EL2_PHYS: | ||
154 | + case GTIMER_S_EL2_VIRT: | ||
155 | return 0; | ||
156 | default: | ||
157 | g_assert_not_reached(); | ||
158 | @@ -XXX,XX +XXX,XX @@ static void gt_sec_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
159 | gt_ctl_write(env, ri, GTIMER_SEC, value); | ||
160 | } | ||
161 | |||
162 | +static void gt_sec_pel2_timer_reset(CPUARMState *env, const ARMCPRegInfo *ri) | ||
163 | +{ | ||
164 | + gt_timer_reset(env, ri, GTIMER_S_EL2_PHYS); | ||
165 | +} | ||
166 | + | ||
167 | +static void gt_sec_pel2_cval_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
168 | + uint64_t value) | ||
169 | +{ | ||
170 | + gt_cval_write(env, ri, GTIMER_S_EL2_PHYS, value); | ||
171 | +} | ||
172 | + | ||
173 | +static uint64_t gt_sec_pel2_tval_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
174 | +{ | ||
175 | + return gt_tval_read(env, ri, GTIMER_S_EL2_PHYS); | ||
176 | +} | ||
177 | + | ||
178 | +static void gt_sec_pel2_tval_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
179 | + uint64_t value) | ||
180 | +{ | ||
181 | + gt_tval_write(env, ri, GTIMER_S_EL2_PHYS, value); | ||
182 | +} | ||
183 | + | ||
184 | +static void gt_sec_pel2_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
185 | + uint64_t value) | ||
186 | +{ | ||
187 | + gt_ctl_write(env, ri, GTIMER_S_EL2_PHYS, value); | ||
188 | +} | ||
189 | + | ||
190 | +static void gt_sec_vel2_timer_reset(CPUARMState *env, const ARMCPRegInfo *ri) | ||
191 | +{ | ||
192 | + gt_timer_reset(env, ri, GTIMER_S_EL2_VIRT); | ||
193 | +} | ||
194 | + | ||
195 | +static void gt_sec_vel2_cval_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
196 | + uint64_t value) | ||
197 | +{ | ||
198 | + gt_cval_write(env, ri, GTIMER_S_EL2_VIRT, value); | ||
199 | +} | ||
200 | + | ||
201 | +static uint64_t gt_sec_vel2_tval_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
202 | +{ | ||
203 | + return gt_tval_read(env, ri, GTIMER_S_EL2_VIRT); | ||
204 | +} | ||
205 | + | ||
206 | +static void gt_sec_vel2_tval_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
207 | + uint64_t value) | ||
208 | +{ | ||
209 | + gt_tval_write(env, ri, GTIMER_S_EL2_VIRT, value); | ||
210 | +} | ||
211 | + | ||
212 | +static void gt_sec_vel2_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
213 | + uint64_t value) | ||
214 | +{ | ||
215 | + gt_ctl_write(env, ri, GTIMER_S_EL2_VIRT, value); | ||
216 | +} | ||
217 | + | ||
218 | static void gt_hv_timer_reset(CPUARMState *env, const ARMCPRegInfo *ri) | ||
219 | { | ||
220 | gt_timer_reset(env, ri, GTIMER_HYPVIRT); | ||
221 | @@ -XXX,XX +XXX,XX @@ void arm_gt_stimer_cb(void *opaque) | ||
222 | gt_recalc_timer(cpu, GTIMER_SEC); | ||
223 | } | ||
224 | |||
225 | +void arm_gt_sel2timer_cb(void *opaque) | ||
226 | +{ | ||
227 | + ARMCPU *cpu = opaque; | ||
228 | + | ||
229 | + gt_recalc_timer(cpu, GTIMER_S_EL2_PHYS); | ||
230 | +} | ||
231 | + | ||
232 | +void arm_gt_sel2vtimer_cb(void *opaque) | ||
233 | +{ | ||
234 | + ARMCPU *cpu = opaque; | ||
235 | + | ||
236 | + gt_recalc_timer(cpu, GTIMER_S_EL2_VIRT); | ||
237 | +} | ||
238 | + | ||
239 | void arm_gt_hvtimer_cb(void *opaque) | ||
240 | { | ||
241 | ARMCPU *cpu = opaque; | ||
242 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_sec_cp_reginfo[] = { | ||
243 | .access = PL2_RW, .accessfn = sel2_access, | ||
244 | .nv2_redirect_offset = 0x48, | ||
245 | .fieldoffset = offsetof(CPUARMState, cp15.vstcr_el2) }, | ||
246 | +#ifndef CONFIG_USER_ONLY | ||
247 | + /* Secure EL2 Physical Timer */ | ||
248 | + { .name = "CNTHPS_TVAL_EL2", .state = ARM_CP_STATE_AA64, | ||
249 | + .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 5, .opc2 = 0, | ||
250 | + .type = ARM_CP_NO_RAW | ARM_CP_IO, .access = PL2_RW, | ||
251 | + .accessfn = gt_sel2timer_access, | ||
252 | + .readfn = gt_sec_pel2_tval_read, | ||
253 | + .writefn = gt_sec_pel2_tval_write, | ||
254 | + .resetfn = gt_sec_pel2_timer_reset, | ||
255 | + }, | ||
256 | + { .name = "CNTHPS_CTL_EL2", .state = ARM_CP_STATE_AA64, | ||
257 | + .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 5, .opc2 = 1, | ||
258 | + .type = ARM_CP_IO, .access = PL2_RW, | ||
259 | + .accessfn = gt_sel2timer_access, | ||
260 | + .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_S_EL2_PHYS].ctl), | ||
261 | + .resetvalue = 0, | ||
262 | + .writefn = gt_sec_pel2_ctl_write, .raw_writefn = raw_write, | ||
263 | + }, | ||
264 | + { .name = "CNTHPS_CVAL_EL2", .state = ARM_CP_STATE_AA64, | ||
265 | + .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 5, .opc2 = 2, | ||
266 | + .type = ARM_CP_IO, .access = PL2_RW, | ||
267 | + .accessfn = gt_sel2timer_access, | ||
268 | + .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_S_EL2_PHYS].cval), | ||
269 | + .writefn = gt_sec_pel2_cval_write, .raw_writefn = raw_write, | ||
270 | + }, | ||
271 | + /* Secure EL2 Virtual Timer */ | ||
272 | + { .name = "CNTHVS_TVAL_EL2", .state = ARM_CP_STATE_AA64, | ||
273 | + .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 4, .opc2 = 0, | ||
274 | + .type = ARM_CP_NO_RAW | ARM_CP_IO, .access = PL2_RW, | ||
275 | + .accessfn = gt_sel2timer_access, | ||
276 | + .readfn = gt_sec_vel2_tval_read, | ||
277 | + .writefn = gt_sec_vel2_tval_write, | ||
278 | + .resetfn = gt_sec_vel2_timer_reset, | ||
279 | + }, | ||
280 | + { .name = "CNTHVS_CTL_EL2", .state = ARM_CP_STATE_AA64, | ||
281 | + .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 4, .opc2 = 1, | ||
282 | + .type = ARM_CP_IO, .access = PL2_RW, | ||
283 | + .accessfn = gt_sel2timer_access, | ||
284 | + .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_S_EL2_VIRT].ctl), | ||
285 | + .resetvalue = 0, | ||
286 | + .writefn = gt_sec_vel2_ctl_write, .raw_writefn = raw_write, | ||
287 | + }, | ||
288 | + { .name = "CNTHVS_CVAL_EL2", .state = ARM_CP_STATE_AA64, | ||
289 | + .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 4, .opc2 = 2, | ||
290 | + .type = ARM_CP_IO, .access = PL2_RW, | ||
291 | + .accessfn = gt_sel2timer_access, | ||
292 | + .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_S_EL2_VIRT].cval), | ||
293 | + .writefn = gt_sec_vel2_cval_write, .raw_writefn = raw_write, | ||
294 | + }, | ||
295 | +#endif | ||
296 | }; | ||
297 | |||
298 | static CPAccessResult nsacr_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
33 | -- | 299 | -- |
34 | 2.20.1 | 300 | 2.43.0 |
35 | 301 | ||
36 | 302 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | From: Alex Bennée <alex.bennee@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | In the previous commit we fixed a crash when the guest read a | 3 | As we are about to add more physical and virtual timers let's make it |
4 | register that pop from an empty FIFO. | 4 | clear what each timer does. |
5 | By auditing the repository, we found another similar use with | ||
6 | an easy way to reproduce: | ||
7 | 5 | ||
8 | $ qemu-system-aarch64 -M xlnx-zcu102 -monitor stdio -S | 6 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> |
9 | QEMU 4.0.50 monitor - type 'help' for more information | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | (qemu) xp/b 0xfd4a0134 | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Aborted (core dumped) | 9 | Message-id: 20250204125009.2281315-8-peter.maydell@linaro.org |
12 | 10 | [PMM: Add timer register name prefix to each comment] | |
13 | (gdb) bt | 11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
14 | #0 0x00007f6936dea57f in raise () at /lib64/libc.so.6 | ||
15 | #1 0x00007f6936dd4895 in abort () at /lib64/libc.so.6 | ||
16 | #2 0x0000561ad32975ec in xlnx_dp_aux_pop_rx_fifo (s=0x7f692babee70) at hw/display/xlnx_dp.c:431 | ||
17 | #3 0x0000561ad3297dc0 in xlnx_dp_read (opaque=0x7f692babee70, offset=77, size=4) at hw/display/xlnx_dp.c:667 | ||
18 | #4 0x0000561ad321b896 in memory_region_read_accessor (mr=0x7f692babf620, addr=308, value=0x7ffe05c1db88, size=4, shift=0, mask=4294967295, attrs=...) at memory.c:439 | ||
19 | #5 0x0000561ad321bd70 in access_with_adjusted_size (addr=308, value=0x7ffe05c1db88, size=1, access_size_min=4, access_size_max=4, access_fn=0x561ad321b858 <memory_region_read_accessor>, mr=0x7f692babf620, attrs=...) at memory.c:569 | ||
20 | #6 0x0000561ad321e9d5 in memory_region_dispatch_read1 (mr=0x7f692babf620, addr=308, pval=0x7ffe05c1db88, size=1, attrs=...) at memory.c:1420 | ||
21 | #7 0x0000561ad321ea9d in memory_region_dispatch_read (mr=0x7f692babf620, addr=308, pval=0x7ffe05c1db88, size=1, attrs=...) at memory.c:1447 | ||
22 | #8 0x0000561ad31bd742 in flatview_read_continue (fv=0x561ad69c04f0, addr=4249485620, attrs=..., buf=0x7ffe05c1dcf0 "\020\335\301\005\376\177", len=1, addr1=308, l=1, mr=0x7f692babf620) at exec.c:3385 | ||
23 | #9 0x0000561ad31bd895 in flatview_read (fv=0x561ad69c04f0, addr=4249485620, attrs=..., buf=0x7ffe05c1dcf0 "\020\335\301\005\376\177", len=1) at exec.c:3423 | ||
24 | #10 0x0000561ad31bd90b in address_space_read_full (as=0x561ad5bb3020, addr=4249485620, attrs=..., buf=0x7ffe05c1dcf0 "\020\335\301\005\376\177", len=1) at exec.c:3436 | ||
25 | #11 0x0000561ad33b1c42 in address_space_read (len=1, buf=0x7ffe05c1dcf0 "\020\335\301\005\376\177", attrs=..., addr=4249485620, as=0x561ad5bb3020) at include/exec/memory.h:2131 | ||
26 | #12 0x0000561ad33b1c42 in memory_dump (mon=0x561ad59c4530, count=1, format=120, wsize=1, addr=4249485620, is_physical=1) at monitor/misc.c:723 | ||
27 | #13 0x0000561ad33b1fc1 in hmp_physical_memory_dump (mon=0x561ad59c4530, qdict=0x561ad6c6fd00) at monitor/misc.c:795 | ||
28 | #14 0x0000561ad37b4a9f in handle_hmp_command (mon=0x561ad59c4530, cmdline=0x561ad59d0f22 "/b 0x00000000fd4a0134") at monitor/hmp.c:1082 | ||
29 | |||
30 | Fix by checking the FIFO is not empty before popping from it. | ||
31 | |||
32 | The datasheet is not clear about the reset value of this register, | ||
33 | we choose to return '0'. | ||
34 | |||
35 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
36 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
37 | Message-id: 20190709113715.7761-4-philmd@redhat.com | ||
38 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
39 | --- | 13 | --- |
40 | hw/display/xlnx_dp.c | 15 +++++++++++---- | 14 | target/arm/gtimer.h | 10 +++++----- |
41 | 1 file changed, 11 insertions(+), 4 deletions(-) | 15 | 1 file changed, 5 insertions(+), 5 deletions(-) |
42 | 16 | ||
43 | diff --git a/hw/display/xlnx_dp.c b/hw/display/xlnx_dp.c | 17 | diff --git a/target/arm/gtimer.h b/target/arm/gtimer.h |
44 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/hw/display/xlnx_dp.c | 19 | --- a/target/arm/gtimer.h |
46 | +++ b/hw/display/xlnx_dp.c | 20 | +++ b/target/arm/gtimer.h |
47 | @@ -XXX,XX +XXX,XX @@ static uint8_t xlnx_dp_aux_pop_rx_fifo(XlnxDPState *s) | 21 | @@ -XXX,XX +XXX,XX @@ |
48 | uint8_t ret; | 22 | #define TARGET_ARM_GTIMER_H |
49 | 23 | ||
50 | if (fifo8_is_empty(&s->rx_fifo)) { | 24 | enum { |
51 | - DPRINTF("rx_fifo underflow..\n"); | 25 | - GTIMER_PHYS = 0, |
52 | - abort(); | 26 | - GTIMER_VIRT = 1, |
53 | + qemu_log_mask(LOG_GUEST_ERROR, | 27 | - GTIMER_HYP = 2, |
54 | + "%s: Reading empty RX_FIFO\n", | 28 | - GTIMER_SEC = 3, |
55 | + __func__); | 29 | - GTIMER_HYPVIRT = 4, |
56 | + /* | 30 | + GTIMER_PHYS = 0, /* CNTP_* ; EL1 physical timer */ |
57 | + * The datasheet is not clear about the reset value, it seems | 31 | + GTIMER_VIRT = 1, /* CNTV_* ; EL1 virtual timer */ |
58 | + * to be unspecified. We choose to return '0'. | 32 | + GTIMER_HYP = 2, /* CNTHP_* ; EL2 physical timer */ |
59 | + */ | 33 | + GTIMER_SEC = 3, /* CNTPS_* ; EL3 physical timer */ |
60 | + ret = 0; | 34 | + GTIMER_HYPVIRT = 4, /* CNTHV_* ; EL2 virtual timer ; only if FEAT_VHE */ |
61 | + } else { | 35 | GTIMER_S_EL2_PHYS = 5, /* CNTHPS_* ; only if FEAT_SEL2 */ |
62 | + ret = fifo8_pop(&s->rx_fifo); | 36 | GTIMER_S_EL2_VIRT = 6, /* CNTHVS_* ; only if FEAT_SEL2 */ |
63 | + DPRINTF("pop 0x%" PRIX8 " from rx_fifo.\n", ret); | 37 | #define NUM_GTIMERS 7 |
64 | } | ||
65 | - ret = fifo8_pop(&s->rx_fifo); | ||
66 | - DPRINTF("pop 0x%" PRIX8 " from rx_fifo.\n", ret); | ||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | -- | 38 | -- |
71 | 2.20.1 | 39 | 2.43.0 |
72 | 40 | ||
73 | 41 | diff view generated by jsdifflib |
1 | From: David Engraf <david.engraf@sysgo.com> | 1 | From: Alex Bennée <alex.bennee@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Using the whole 128 MiB flash in non-secure mode is not working because | 3 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> |
4 | virt_flash_fdt() expects the same address for secure_sysmem and sysmem. | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | This is not correctly handled by caller because it forwards NULL for | 5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | secure_sysmem in non-secure flash mode. | 6 | Message-id: 20250204125009.2281315-9-peter.maydell@linaro.org |
7 | 7 | Cc: qemu-stable@nongnu.org | |
8 | Fixed by using sysmem when secure_sysmem is NULL. | ||
9 | |||
10 | Signed-off-by: David Engraf <david.engraf@sysgo.com> | ||
11 | Message-id: 20190712075002.14326-1-david.engraf@sysgo.com | ||
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 10 | --- |
15 | hw/arm/virt.c | 2 +- | 11 | hw/arm/virt.c | 2 ++ |
16 | 1 file changed, 1 insertion(+), 1 deletion(-) | 12 | 1 file changed, 2 insertions(+) |
17 | 13 | ||
18 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | 14 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c |
19 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/arm/virt.c | 16 | --- a/hw/arm/virt.c |
21 | +++ b/hw/arm/virt.c | 17 | +++ b/hw/arm/virt.c |
22 | @@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine) | 18 | @@ -XXX,XX +XXX,XX @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) |
23 | &machine->device_memory->mr); | 19 | [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ, |
24 | } | 20 | [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ, |
25 | 21 | [GTIMER_HYPVIRT] = ARCH_TIMER_NS_EL2_VIRT_IRQ, | |
26 | - virt_flash_fdt(vms, sysmem, secure_sysmem); | 22 | + [GTIMER_S_EL2_PHYS] = ARCH_TIMER_S_EL2_IRQ, |
27 | + virt_flash_fdt(vms, sysmem, secure_sysmem ?: sysmem); | 23 | + [GTIMER_S_EL2_VIRT] = ARCH_TIMER_S_EL2_VIRT_IRQ, |
28 | 24 | }; | |
29 | create_gic(vms, pic); | 25 | |
30 | 26 | for (unsigned irq = 0; irq < ARRAY_SIZE(timer_irq); irq++) { | |
31 | -- | 27 | -- |
32 | 2.20.1 | 28 | 2.43.0 |
33 | 29 | ||
34 | 30 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | From: Alex Bennée <alex.bennee@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Both lqspi_read() and lqspi_load_cache() expect a 32-bit | 3 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> |
4 | aligned address. | 4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
5 | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | |
6 | >From UG1085 datasheet [*] chapter on 'Quad-SPI Controller': | 6 | Message-id: 20250204125009.2281315-10-peter.maydell@linaro.org |
7 | 7 | Cc: qemu-stable@nongnu.org | |
8 | Transfer Size Limitations | ||
9 | |||
10 | Because of the 32-bit wide TX, RX, and generic FIFO, all | ||
11 | APB/AXI transfers must be an integer multiple of 4-bytes. | ||
12 | Shorter transfers are not possible. | ||
13 | |||
14 | Set MemoryRegionOps.impl values to force 32-bit accesses, | ||
15 | this way we are sure we do not access the lqspi_buf[] array | ||
16 | out of bound. | ||
17 | |||
18 | [*] https://www.xilinx.com/support/documentation/user_guides/ug1085-zynq-ultrascale-trm.pdf | ||
19 | |||
20 | Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com> | ||
21 | Tested-by: Francisco Iglesias <frasse.iglesias@gmail.com> | ||
22 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
24 | --- | 9 | --- |
25 | hw/ssi/xilinx_spips.c | 4 ++++ | 10 | hw/arm/sbsa-ref.c | 2 ++ |
26 | 1 file changed, 4 insertions(+) | 11 | 1 file changed, 2 insertions(+) |
27 | 12 | ||
28 | diff --git a/hw/ssi/xilinx_spips.c b/hw/ssi/xilinx_spips.c | 13 | diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c |
29 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/ssi/xilinx_spips.c | 15 | --- a/hw/arm/sbsa-ref.c |
31 | +++ b/hw/ssi/xilinx_spips.c | 16 | +++ b/hw/arm/sbsa-ref.c |
32 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps lqspi_ops = { | 17 | @@ -XXX,XX +XXX,XX @@ static void create_gic(SBSAMachineState *sms, MemoryRegion *mem) |
33 | .read_with_attrs = lqspi_read, | 18 | [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ, |
34 | .write_with_attrs = lqspi_write, | 19 | [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ, |
35 | .endianness = DEVICE_NATIVE_ENDIAN, | 20 | [GTIMER_HYPVIRT] = ARCH_TIMER_NS_EL2_VIRT_IRQ, |
36 | + .impl = { | 21 | + [GTIMER_S_EL2_PHYS] = ARCH_TIMER_S_EL2_IRQ, |
37 | + .min_access_size = 4, | 22 | + [GTIMER_S_EL2_VIRT] = ARCH_TIMER_S_EL2_VIRT_IRQ, |
38 | + .max_access_size = 4, | 23 | }; |
39 | + }, | 24 | |
40 | .valid = { | 25 | for (irq = 0; irq < ARRAY_SIZE(timer_irq); irq++) { |
41 | .min_access_size = 1, | ||
42 | .max_access_size = 4 | ||
43 | -- | 26 | -- |
44 | 2.20.1 | 27 | 2.43.0 |
45 | 28 | ||
46 | 29 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Our LDRD implementation is wrong in two respects: | ||
1 | 2 | ||
3 | * if the address is 4-aligned and the load crosses a page boundary | ||
4 | and the second load faults and the first load was to the | ||
5 | base register (as in cases like "ldrd r2, r3, [r2]", then we | ||
6 | must not update the base register before taking the fault | ||
7 | * if the address is 8-aligned the access must be a 64-bit | ||
8 | single-copy atomic access, not two 32-bit accesses | ||
9 | |||
10 | Rewrite the handling of the loads in LDRD to use a single | ||
11 | tcg_gen_qemu_ld_i64() and split the result into the destination | ||
12 | registers. This allows us to get the atomicity requirements | ||
13 | right, and also implicitly means that we won't update the | ||
14 | base register too early for the page-crossing case. | ||
15 | |||
16 | Note that because we no longer increment 'addr' by 4 in the course of | ||
17 | performing the LDRD we must change the adjustment value we pass to | ||
18 | op_addr_ri_post() and op_addr_rr_post(): it no longer needs to | ||
19 | subtract 4 to get the correct value to use if doing base register | ||
20 | writeback. | ||
21 | |||
22 | STRD has the same problem with not getting the atomicity right; | ||
23 | we will deal with that in the following commit. | ||
24 | |||
25 | Cc: qemu-stable@nongnu.org | ||
26 | Reported-by: Stu Grossman <stu.grossman@gmail.com> | ||
27 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
28 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
29 | Message-id: 20250227142746.1698904-2-peter.maydell@linaro.org | ||
30 | --- | ||
31 | target/arm/tcg/translate.c | 70 +++++++++++++++++++++++++------------- | ||
32 | 1 file changed, 46 insertions(+), 24 deletions(-) | ||
33 | |||
34 | diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/target/arm/tcg/translate.c | ||
37 | +++ b/target/arm/tcg/translate.c | ||
38 | @@ -XXX,XX +XXX,XX @@ static bool op_store_rr(DisasContext *s, arg_ldst_rr *a, | ||
39 | return true; | ||
40 | } | ||
41 | |||
42 | +static void do_ldrd_load(DisasContext *s, TCGv_i32 addr, int rt, int rt2) | ||
43 | +{ | ||
44 | + /* | ||
45 | + * LDRD is required to be an atomic 64-bit access if the | ||
46 | + * address is 8-aligned, two atomic 32-bit accesses if | ||
47 | + * it's only 4-aligned, and to give an alignment fault | ||
48 | + * if it's not 4-aligned. This is MO_ALIGN_4 | MO_ATOM_SUBALIGN. | ||
49 | + * Rt is always the word from the lower address, and Rt2 the | ||
50 | + * data from the higher address, regardless of endianness. | ||
51 | + * So (like gen_load_exclusive) we avoid gen_aa32_ld_i64() | ||
52 | + * so we don't get its SCTLR_B check, and instead do a 64-bit access | ||
53 | + * using MO_BE if appropriate and then split the two halves. | ||
54 | + * | ||
55 | + * For M-profile, and for A-profile before LPAE, the 64-bit | ||
56 | + * atomicity is not required. We could model that using | ||
57 | + * the looser MO_ATOM_IFALIGN_PAIR, but providing a higher | ||
58 | + * level of atomicity than required is harmless (we would not | ||
59 | + * currently generate better code for IFALIGN_PAIR here). | ||
60 | + * | ||
61 | + * This also gives us the correct behaviour of not updating | ||
62 | + * rt if the load of rt2 faults; this is required for cases | ||
63 | + * like "ldrd r2, r3, [r2]" where rt is also the base register. | ||
64 | + */ | ||
65 | + int mem_idx = get_mem_index(s); | ||
66 | + MemOp opc = MO_64 | MO_ALIGN_4 | MO_ATOM_SUBALIGN | s->be_data; | ||
67 | + TCGv taddr = gen_aa32_addr(s, addr, opc); | ||
68 | + TCGv_i64 t64 = tcg_temp_new_i64(); | ||
69 | + TCGv_i32 tmp = tcg_temp_new_i32(); | ||
70 | + TCGv_i32 tmp2 = tcg_temp_new_i32(); | ||
71 | + | ||
72 | + tcg_gen_qemu_ld_i64(t64, taddr, mem_idx, opc); | ||
73 | + if (s->be_data == MO_BE) { | ||
74 | + tcg_gen_extr_i64_i32(tmp2, tmp, t64); | ||
75 | + } else { | ||
76 | + tcg_gen_extr_i64_i32(tmp, tmp2, t64); | ||
77 | + } | ||
78 | + store_reg(s, rt, tmp); | ||
79 | + store_reg(s, rt2, tmp2); | ||
80 | +} | ||
81 | + | ||
82 | static bool trans_LDRD_rr(DisasContext *s, arg_ldst_rr *a) | ||
83 | { | ||
84 | - int mem_idx = get_mem_index(s); | ||
85 | - TCGv_i32 addr, tmp; | ||
86 | + TCGv_i32 addr; | ||
87 | |||
88 | if (!ENABLE_ARCH_5TE) { | ||
89 | return false; | ||
90 | @@ -XXX,XX +XXX,XX @@ static bool trans_LDRD_rr(DisasContext *s, arg_ldst_rr *a) | ||
91 | } | ||
92 | addr = op_addr_rr_pre(s, a); | ||
93 | |||
94 | - tmp = tcg_temp_new_i32(); | ||
95 | - gen_aa32_ld_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); | ||
96 | - store_reg(s, a->rt, tmp); | ||
97 | - | ||
98 | - tcg_gen_addi_i32(addr, addr, 4); | ||
99 | - | ||
100 | - tmp = tcg_temp_new_i32(); | ||
101 | - gen_aa32_ld_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); | ||
102 | - store_reg(s, a->rt + 1, tmp); | ||
103 | + do_ldrd_load(s, addr, a->rt, a->rt + 1); | ||
104 | |||
105 | /* LDRD w/ base writeback is undefined if the registers overlap. */ | ||
106 | - op_addr_rr_post(s, a, addr, -4); | ||
107 | + op_addr_rr_post(s, a, addr, 0); | ||
108 | return true; | ||
109 | } | ||
110 | |||
111 | @@ -XXX,XX +XXX,XX @@ static bool op_store_ri(DisasContext *s, arg_ldst_ri *a, | ||
112 | |||
113 | static bool op_ldrd_ri(DisasContext *s, arg_ldst_ri *a, int rt2) | ||
114 | { | ||
115 | - int mem_idx = get_mem_index(s); | ||
116 | - TCGv_i32 addr, tmp; | ||
117 | + TCGv_i32 addr; | ||
118 | |||
119 | addr = op_addr_ri_pre(s, a); | ||
120 | |||
121 | - tmp = tcg_temp_new_i32(); | ||
122 | - gen_aa32_ld_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); | ||
123 | - store_reg(s, a->rt, tmp); | ||
124 | - | ||
125 | - tcg_gen_addi_i32(addr, addr, 4); | ||
126 | - | ||
127 | - tmp = tcg_temp_new_i32(); | ||
128 | - gen_aa32_ld_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); | ||
129 | - store_reg(s, rt2, tmp); | ||
130 | + do_ldrd_load(s, addr, a->rt, rt2); | ||
131 | |||
132 | /* LDRD w/ base writeback is undefined if the registers overlap. */ | ||
133 | - op_addr_ri_post(s, a, addr, -4); | ||
134 | + op_addr_ri_post(s, a, addr, 0); | ||
135 | return true; | ||
136 | } | ||
137 | |||
138 | -- | ||
139 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Our STRD implementation doesn't correctly implement the requirement: | ||
2 | * if the address is 8-aligned the access must be a 64-bit | ||
3 | single-copy atomic access, not two 32-bit accesses | ||
1 | 4 | ||
5 | Rewrite the handling of STRD to use a single tcg_gen_qemu_st_i64() | ||
6 | of a value produced by concatenating the two 32 bit source registers. | ||
7 | This allows us to get the atomicity right. | ||
8 | |||
9 | As with the LDRD change, now that we don't update 'addr' in the | ||
10 | course of performing the store we need to adjust the offset | ||
11 | we pass to op_addr_ri_post() and op_addr_rr_post(). | ||
12 | |||
13 | Cc: qemu-stable@nongnu.org | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | Message-id: 20250227142746.1698904-3-peter.maydell@linaro.org | ||
17 | --- | ||
18 | target/arm/tcg/translate.c | 59 +++++++++++++++++++++++++------------- | ||
19 | 1 file changed, 39 insertions(+), 20 deletions(-) | ||
20 | |||
21 | diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/arm/tcg/translate.c | ||
24 | +++ b/target/arm/tcg/translate.c | ||
25 | @@ -XXX,XX +XXX,XX @@ static bool trans_LDRD_rr(DisasContext *s, arg_ldst_rr *a) | ||
26 | return true; | ||
27 | } | ||
28 | |||
29 | +static void do_strd_store(DisasContext *s, TCGv_i32 addr, int rt, int rt2) | ||
30 | +{ | ||
31 | + /* | ||
32 | + * STRD is required to be an atomic 64-bit access if the | ||
33 | + * address is 8-aligned, two atomic 32-bit accesses if | ||
34 | + * it's only 4-aligned, and to give an alignment fault | ||
35 | + * if it's not 4-aligned. | ||
36 | + * Rt is always the word from the lower address, and Rt2 the | ||
37 | + * data from the higher address, regardless of endianness. | ||
38 | + * So (like gen_store_exclusive) we avoid gen_aa32_ld_i64() | ||
39 | + * so we don't get its SCTLR_B check, and instead do a 64-bit access | ||
40 | + * using MO_BE if appropriate, using a value constructed | ||
41 | + * by putting the two halves together in the right order. | ||
42 | + * | ||
43 | + * As with LDRD, the 64-bit atomicity is not required for | ||
44 | + * M-profile, or for A-profile before LPAE, and we provide | ||
45 | + * the higher guarantee always for simplicity. | ||
46 | + */ | ||
47 | + int mem_idx = get_mem_index(s); | ||
48 | + MemOp opc = MO_64 | MO_ALIGN_4 | MO_ATOM_SUBALIGN | s->be_data; | ||
49 | + TCGv taddr = gen_aa32_addr(s, addr, opc); | ||
50 | + TCGv_i32 t1 = load_reg(s, rt); | ||
51 | + TCGv_i32 t2 = load_reg(s, rt2); | ||
52 | + TCGv_i64 t64 = tcg_temp_new_i64(); | ||
53 | + | ||
54 | + if (s->be_data == MO_BE) { | ||
55 | + tcg_gen_concat_i32_i64(t64, t2, t1); | ||
56 | + } else { | ||
57 | + tcg_gen_concat_i32_i64(t64, t1, t2); | ||
58 | + } | ||
59 | + tcg_gen_qemu_st_i64(t64, taddr, mem_idx, opc); | ||
60 | +} | ||
61 | + | ||
62 | static bool trans_STRD_rr(DisasContext *s, arg_ldst_rr *a) | ||
63 | { | ||
64 | - int mem_idx = get_mem_index(s); | ||
65 | - TCGv_i32 addr, tmp; | ||
66 | + TCGv_i32 addr; | ||
67 | |||
68 | if (!ENABLE_ARCH_5TE) { | ||
69 | return false; | ||
70 | @@ -XXX,XX +XXX,XX @@ static bool trans_STRD_rr(DisasContext *s, arg_ldst_rr *a) | ||
71 | } | ||
72 | addr = op_addr_rr_pre(s, a); | ||
73 | |||
74 | - tmp = load_reg(s, a->rt); | ||
75 | - gen_aa32_st_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); | ||
76 | + do_strd_store(s, addr, a->rt, a->rt + 1); | ||
77 | |||
78 | - tcg_gen_addi_i32(addr, addr, 4); | ||
79 | - | ||
80 | - tmp = load_reg(s, a->rt + 1); | ||
81 | - gen_aa32_st_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); | ||
82 | - | ||
83 | - op_addr_rr_post(s, a, addr, -4); | ||
84 | + op_addr_rr_post(s, a, addr, 0); | ||
85 | return true; | ||
86 | } | ||
87 | |||
88 | @@ -XXX,XX +XXX,XX @@ static bool trans_LDRD_ri_t32(DisasContext *s, arg_ldst_ri2 *a) | ||
89 | |||
90 | static bool op_strd_ri(DisasContext *s, arg_ldst_ri *a, int rt2) | ||
91 | { | ||
92 | - int mem_idx = get_mem_index(s); | ||
93 | - TCGv_i32 addr, tmp; | ||
94 | + TCGv_i32 addr; | ||
95 | |||
96 | addr = op_addr_ri_pre(s, a); | ||
97 | |||
98 | - tmp = load_reg(s, a->rt); | ||
99 | - gen_aa32_st_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); | ||
100 | + do_strd_store(s, addr, a->rt, rt2); | ||
101 | |||
102 | - tcg_gen_addi_i32(addr, addr, 4); | ||
103 | - | ||
104 | - tmp = load_reg(s, rt2); | ||
105 | - gen_aa32_st_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); | ||
106 | - | ||
107 | - op_addr_ri_post(s, a, addr, -4); | ||
108 | + op_addr_ri_post(s, a, addr, 0); | ||
109 | return true; | ||
110 | } | ||
111 | |||
112 | -- | ||
113 | 2.43.0 | diff view generated by jsdifflib |
1 | In the M-profile architecture, when we do a vector table fetch and it | 1 | All the callers of op_addr_rr_post() and op_addr_ri_post() now pass in |
---|---|---|---|
2 | fails, we need to report a HardFault. Whether this is a Secure HF or | 2 | zero for the address_offset, so we can remove that argument. |
3 | a NonSecure HF depends on several things. If AIRCR.BFHFNMINS is 0 | ||
4 | then HF is always Secure, because there is no NonSecure HardFault. | ||
5 | Otherwise, the answer depends on whether the 'underlying exception' | ||
6 | (MemManage, BusFault, SecureFault) targets Secure or NonSecure. (In | ||
7 | the pseudocode, this is handled in the Vector() function: the final | ||
8 | exc.isSecure is calculated by looking at the exc.isSecure from the | ||
9 | exception returned from the memory access, not the isSecure input | ||
10 | argument.) | ||
11 | |||
12 | We weren't doing this correctly, because we were looking at | ||
13 | the target security domain of the exception we were trying to | ||
14 | load the vector table entry for. This produces errors of two kinds: | ||
15 | * a load from the NS vector table which hits the "NS access | ||
16 | to S memory" SecureFault should end up as a Secure HardFault, | ||
17 | but we were raising an NS HardFault | ||
18 | * a load from the S vector table which causes a BusFault | ||
19 | should raise an NS HardFault if BFHFNMINS == 1 (because | ||
20 | in that case all BusFaults are NonSecure), but we were raising | ||
21 | a Secure HardFault | ||
22 | |||
23 | Correct the logic. | ||
24 | |||
25 | We also fix a comment error where we claimed that we might | ||
26 | be escalating MemManage to HardFault, and forgot about SecureFault. | ||
27 | (Vector loads can never hit MPU access faults, because they're | ||
28 | always aligned and always use the default address map.) | ||
29 | 3 | ||
30 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
31 | Message-id: 20190705094823.28905-1-peter.maydell@linaro.org | 5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
7 | Message-id: 20250227142746.1698904-4-peter.maydell@linaro.org | ||
32 | --- | 8 | --- |
33 | target/arm/m_helper.c | 21 +++++++++++++++++---- | 9 | target/arm/tcg/translate.c | 26 +++++++++++++------------- |
34 | 1 file changed, 17 insertions(+), 4 deletions(-) | 10 | 1 file changed, 13 insertions(+), 13 deletions(-) |
35 | 11 | ||
36 | diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c | 12 | diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c |
37 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
38 | --- a/target/arm/m_helper.c | 14 | --- a/target/arm/tcg/translate.c |
39 | +++ b/target/arm/m_helper.c | 15 | +++ b/target/arm/tcg/translate.c |
40 | @@ -XXX,XX +XXX,XX @@ static bool arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure, | 16 | @@ -XXX,XX +XXX,XX @@ static TCGv_i32 op_addr_rr_pre(DisasContext *s, arg_ldst_rr *a) |
41 | if (sattrs.ns) { | 17 | } |
42 | attrs.secure = false; | 18 | |
43 | } else if (!targets_secure) { | 19 | static void op_addr_rr_post(DisasContext *s, arg_ldst_rr *a, |
44 | - /* NS access to S memory */ | 20 | - TCGv_i32 addr, int address_offset) |
45 | + /* | 21 | + TCGv_i32 addr) |
46 | + * NS access to S memory: the underlying exception which we escalate | 22 | { |
47 | + * to HardFault is SecureFault, which always targets Secure. | 23 | if (!a->p) { |
48 | + */ | 24 | TCGv_i32 ofs = load_reg(s, a->rm); |
49 | + exc_secure = true; | 25 | @@ -XXX,XX +XXX,XX @@ static void op_addr_rr_post(DisasContext *s, arg_ldst_rr *a, |
50 | goto load_fail; | 26 | } else if (!a->w) { |
27 | return; | ||
28 | } | ||
29 | - tcg_gen_addi_i32(addr, addr, address_offset); | ||
30 | store_reg(s, a->rn, addr); | ||
31 | } | ||
32 | |||
33 | @@ -XXX,XX +XXX,XX @@ static bool op_load_rr(DisasContext *s, arg_ldst_rr *a, | ||
34 | * Perform base writeback before the loaded value to | ||
35 | * ensure correct behavior with overlapping index registers. | ||
36 | */ | ||
37 | - op_addr_rr_post(s, a, addr, 0); | ||
38 | + op_addr_rr_post(s, a, addr); | ||
39 | store_reg_from_load(s, a->rt, tmp); | ||
40 | return true; | ||
41 | } | ||
42 | @@ -XXX,XX +XXX,XX @@ static bool op_store_rr(DisasContext *s, arg_ldst_rr *a, | ||
43 | gen_aa32_st_i32(s, tmp, addr, mem_idx, mop); | ||
44 | disas_set_da_iss(s, mop, issinfo); | ||
45 | |||
46 | - op_addr_rr_post(s, a, addr, 0); | ||
47 | + op_addr_rr_post(s, a, addr); | ||
48 | return true; | ||
49 | } | ||
50 | |||
51 | @@ -XXX,XX +XXX,XX @@ static bool trans_LDRD_rr(DisasContext *s, arg_ldst_rr *a) | ||
52 | do_ldrd_load(s, addr, a->rt, a->rt + 1); | ||
53 | |||
54 | /* LDRD w/ base writeback is undefined if the registers overlap. */ | ||
55 | - op_addr_rr_post(s, a, addr, 0); | ||
56 | + op_addr_rr_post(s, a, addr); | ||
57 | return true; | ||
58 | } | ||
59 | |||
60 | @@ -XXX,XX +XXX,XX @@ static bool trans_STRD_rr(DisasContext *s, arg_ldst_rr *a) | ||
61 | |||
62 | do_strd_store(s, addr, a->rt, a->rt + 1); | ||
63 | |||
64 | - op_addr_rr_post(s, a, addr, 0); | ||
65 | + op_addr_rr_post(s, a, addr); | ||
66 | return true; | ||
67 | } | ||
68 | |||
69 | @@ -XXX,XX +XXX,XX @@ static TCGv_i32 op_addr_ri_pre(DisasContext *s, arg_ldst_ri *a) | ||
70 | } | ||
71 | |||
72 | static void op_addr_ri_post(DisasContext *s, arg_ldst_ri *a, | ||
73 | - TCGv_i32 addr, int address_offset) | ||
74 | + TCGv_i32 addr) | ||
75 | { | ||
76 | + int address_offset = 0; | ||
77 | if (!a->p) { | ||
78 | if (a->u) { | ||
79 | - address_offset += a->imm; | ||
80 | + address_offset = a->imm; | ||
81 | } else { | ||
82 | - address_offset -= a->imm; | ||
83 | + address_offset = -a->imm; | ||
51 | } | 84 | } |
52 | } | 85 | } else if (!a->w) { |
53 | @@ -XXX,XX +XXX,XX @@ static bool arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure, | 86 | return; |
54 | vector_entry = address_space_ldl(arm_addressspace(cs, attrs), addr, | 87 | @@ -XXX,XX +XXX,XX @@ static bool op_load_ri(DisasContext *s, arg_ldst_ri *a, |
55 | attrs, &result); | 88 | * Perform base writeback before the loaded value to |
56 | if (result != MEMTX_OK) { | 89 | * ensure correct behavior with overlapping index registers. |
57 | + /* | ||
58 | + * Underlying exception is BusFault: its target security state | ||
59 | + * depends on BFHFNMINS. | ||
60 | + */ | ||
61 | + exc_secure = !(cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK); | ||
62 | goto load_fail; | ||
63 | } | ||
64 | *pvec = vector_entry; | ||
65 | @@ -XXX,XX +XXX,XX @@ load_fail: | ||
66 | /* | ||
67 | * All vector table fetch fails are reported as HardFault, with | ||
68 | * HFSR.VECTTBL and .FORCED set. (FORCED is set because | ||
69 | - * technically the underlying exception is a MemManage or BusFault | ||
70 | + * technically the underlying exception is a SecureFault or BusFault | ||
71 | * that is escalated to HardFault.) This is a terminal exception, | ||
72 | * so we will either take the HardFault immediately or else enter | ||
73 | * lockup (the latter case is handled in armv7m_nvic_set_pending_derived()). | ||
74 | + * The HardFault is Secure if BFHFNMINS is 0 (meaning that all HFs are | ||
75 | + * secure); otherwise it targets the same security state as the | ||
76 | + * underlying exception. | ||
77 | */ | 90 | */ |
78 | - exc_secure = targets_secure || | 91 | - op_addr_ri_post(s, a, addr, 0); |
79 | - !(cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK); | 92 | + op_addr_ri_post(s, a, addr); |
80 | + if (!(cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK)) { | 93 | store_reg_from_load(s, a->rt, tmp); |
81 | + exc_secure = true; | 94 | return true; |
82 | + } | 95 | } |
83 | env->v7m.hfsr |= R_V7M_HFSR_VECTTBL_MASK | R_V7M_HFSR_FORCED_MASK; | 96 | @@ -XXX,XX +XXX,XX @@ static bool op_store_ri(DisasContext *s, arg_ldst_ri *a, |
84 | armv7m_nvic_set_pending_derived(env->nvic, ARMV7M_EXCP_HARD, exc_secure); | 97 | gen_aa32_st_i32(s, tmp, addr, mem_idx, mop); |
85 | return false; | 98 | disas_set_da_iss(s, mop, issinfo); |
99 | |||
100 | - op_addr_ri_post(s, a, addr, 0); | ||
101 | + op_addr_ri_post(s, a, addr); | ||
102 | return true; | ||
103 | } | ||
104 | |||
105 | @@ -XXX,XX +XXX,XX @@ static bool op_ldrd_ri(DisasContext *s, arg_ldst_ri *a, int rt2) | ||
106 | do_ldrd_load(s, addr, a->rt, rt2); | ||
107 | |||
108 | /* LDRD w/ base writeback is undefined if the registers overlap. */ | ||
109 | - op_addr_ri_post(s, a, addr, 0); | ||
110 | + op_addr_ri_post(s, a, addr); | ||
111 | return true; | ||
112 | } | ||
113 | |||
114 | @@ -XXX,XX +XXX,XX @@ static bool op_strd_ri(DisasContext *s, arg_ldst_ri *a, int rt2) | ||
115 | |||
116 | do_strd_store(s, addr, a->rt, rt2); | ||
117 | |||
118 | - op_addr_ri_post(s, a, addr, 0); | ||
119 | + op_addr_ri_post(s, a, addr); | ||
120 | return true; | ||
121 | } | ||
122 | |||
86 | -- | 123 | -- |
87 | 2.20.1 | 124 | 2.43.0 |
88 | 125 | ||
89 | 126 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | In debug_helper.c we provide a few dummy versions of | ||
2 | debug registers: | ||
3 | * DBGVCR (AArch32 only): enable bits for vector-catch | ||
4 | debug events | ||
5 | * MDCCINT_EL1: interrupt enable bits for the DCC | ||
6 | debug communications channel | ||
7 | * DBGVCR32_EL2: the AArch64 accessor for the state in | ||
8 | DBGVCR | ||
1 | 9 | ||
10 | We implemented these only to stop Linux crashing on startup, | ||
11 | but we chose to implement them as ARM_CP_NOP. This worked | ||
12 | for Linux where it only cares about trying to write to these | ||
13 | registers, but is very confusing behaviour for anything that | ||
14 | wants to read the registers (perhaps for context state switches), | ||
15 | because the destination register will be left with whatever | ||
16 | random value it happened to have before the read. | ||
17 | |||
18 | Model these registers instead as RAZ. | ||
19 | |||
20 | Fixes: 5e8b12ffbb8c68 ("target-arm: Implement minimal DBGVCR, OSDLR_EL1, MDCCSR_EL0") | ||
21 | Fixes: 5dbdc4342f479d ("target-arm: Implement dummy MDCCINT_EL1") | ||
22 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2708 | ||
23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
24 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
25 | Message-id: 20250228162424.1917269-1-peter.maydell@linaro.org | ||
26 | --- | ||
27 | target/arm/debug_helper.c | 7 ++++--- | ||
28 | 1 file changed, 4 insertions(+), 3 deletions(-) | ||
29 | |||
30 | diff --git a/target/arm/debug_helper.c b/target/arm/debug_helper.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/target/arm/debug_helper.c | ||
33 | +++ b/target/arm/debug_helper.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo debug_cp_reginfo[] = { | ||
35 | { .name = "DBGVCR", | ||
36 | .cp = 14, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 0, | ||
37 | .access = PL1_RW, .accessfn = access_tda, | ||
38 | - .type = ARM_CP_NOP }, | ||
39 | + .type = ARM_CP_CONST, .resetvalue = 0 }, | ||
40 | /* | ||
41 | * Dummy MDCCINT_EL1, since we don't implement the Debug Communications | ||
42 | * Channel but Linux may try to access this register. The 32-bit | ||
43 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo debug_cp_reginfo[] = { | ||
44 | { .name = "MDCCINT_EL1", .state = ARM_CP_STATE_BOTH, | ||
45 | .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 0, | ||
46 | .access = PL1_RW, .accessfn = access_tdcc, | ||
47 | - .type = ARM_CP_NOP }, | ||
48 | + .type = ARM_CP_CONST, .resetvalue = 0 }, | ||
49 | /* | ||
50 | * Dummy DBGCLAIM registers. | ||
51 | * "The architecture does not define any functionality for the CLAIM tag bits.", | ||
52 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo debug_aa32_el1_reginfo[] = { | ||
53 | { .name = "DBGVCR32_EL2", .state = ARM_CP_STATE_AA64, | ||
54 | .opc0 = 2, .opc1 = 4, .crn = 0, .crm = 7, .opc2 = 0, | ||
55 | .access = PL2_RW, .accessfn = access_dbgvcr32, | ||
56 | - .type = ARM_CP_NOP | ARM_CP_EL3_NO_EL2_KEEP }, | ||
57 | + .type = ARM_CP_CONST | ARM_CP_EL3_NO_EL2_KEEP, | ||
58 | + .resetvalue = 0 }, | ||
59 | }; | ||
60 | |||
61 | static const ARMCPRegInfo debug_lpae_cp_reginfo[] = { | ||
62 | -- | ||
63 | 2.43.0 | diff view generated by jsdifflib |
1 | The ARMv5 architecture didn't specify detailed per-feature ID | 1 | Currently we call icount_start_warp_timer() from timerlist_rearm(). |
---|---|---|---|
2 | registers. Now that we're using the MVFR0 register fields to | 2 | This produces incorrect behaviour, because timerlist_rearm() is |
3 | gate the existence of VFP instructions, we need to set up | 3 | called, for instance, when a timer callback modifies its timer. We |
4 | the correct values in the cpu->isar structure so that we still | 4 | cannot decide here to warp the timer forwards to the next timer |
5 | provide an FPU to the guest. | 5 | deadline merely because all_cpu_threads_idle() is true, because the |
6 | timer callback we were called from (or some other callback later in | ||
7 | the list of callbacks being invoked) may be about to raise a CPU | ||
8 | interrupt and move a CPU from idle to ready. | ||
6 | 9 | ||
7 | This fixes a regression in the arm926 and arm1026 CPUs, which | 10 | The only valid place to choose to warp the timer forward is from the |
8 | are the only ones that both have VFP and are ARMv5 or earlier. | 11 | main loop, when we know we have no outstanding IO or timer callbacks |
9 | This regression was introduced by the VFP refactoring, and more | 12 | that might be about to wake up a CPU. |
10 | specifically by commits 1120827fa182f0e76 and 266bd25c485597c, | ||
11 | which accidentally disabled VFP short-vector support and | ||
12 | double-precision support on these CPUs. | ||
13 | 13 | ||
14 | Fixes: 1120827fa182f0e | 14 | For Arm guests, this bug was mostly latent until the refactoring |
15 | Fixes: 266bd25c485597c | 15 | commit f6fc36deef6abc ("target/arm/helper: Implement |
16 | Fixes: https://bugs.launchpad.net/qemu/+bug/1836192 | 16 | CNTHCTL_EL2.CNT[VP]MASK"), which exposed it because it refactored a |
17 | Reported-by: Christophe Lyon <christophe.lyon@linaro.org> | 17 | timer callback so that it happened to call timer_mod() first and |
18 | raise the interrupt second, when it had previously raised the | ||
19 | interrupt first and called timer_mod() afterwards. | ||
20 | |||
21 | This call seems to have originally derived from the | ||
22 | pre-record-and-replay icount code, which (as of e.g. commit | ||
23 | db1a49726c3c in 2010) in this location did a call to | ||
24 | qemu_notify_event(), necessary to get the icount code in the vCPU | ||
25 | round-robin thread to stop and recalculate the icount deadline when a | ||
26 | timer was reprogrammed from the IO thread. In current QEMU, | ||
27 | everything is done on the vCPU thread when we are in icount mode, so | ||
28 | there's no need to try to notify another thread here. | ||
29 | |||
30 | I suspect that the other reason why this call was doing icount timer | ||
31 | warping is that it pre-dates commit efab87cf79077a from 2015, which | ||
32 | added a call to icount_start_warp_timer() to main_loop_wait(). Once | ||
33 | the call in timerlist_rearm() has been removed, if the timer | ||
34 | callbacks don't cause any CPU to be woken up then we will end up | ||
35 | calling icount_start_warp_timer() from main_loop_wait() when the rr | ||
36 | main loop code calls rr_wait_io_event(). | ||
37 | |||
38 | Remove the incorrect call from timerlist_rearm(). | ||
39 | |||
40 | Cc: qemu-stable@nongnu.org | ||
41 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2703 | ||
18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 42 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
19 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 43 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
20 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 44 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
21 | Tested-by: Christophe Lyon <christophe.lyon@linaro.org> | 45 | Tested-by: Alex Bennée <alex.bennee@linaro.org> |
22 | Message-id: 20190711131241.22231-1-peter.maydell@linaro.org | 46 | Message-id: 20250210135804.3526943-1-peter.maydell@linaro.org |
23 | --- | 47 | --- |
24 | target/arm/cpu.c | 12 ++++++++++++ | 48 | util/qemu-timer.c | 4 ---- |
25 | 1 file changed, 12 insertions(+) | 49 | 1 file changed, 4 deletions(-) |
26 | 50 | ||
27 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 51 | diff --git a/util/qemu-timer.c b/util/qemu-timer.c |
28 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/target/arm/cpu.c | 53 | --- a/util/qemu-timer.c |
30 | +++ b/target/arm/cpu.c | 54 | +++ b/util/qemu-timer.c |
31 | @@ -XXX,XX +XXX,XX @@ static void arm926_initfn(Object *obj) | 55 | @@ -XXX,XX +XXX,XX @@ static bool timer_mod_ns_locked(QEMUTimerList *timer_list, |
32 | * set the field to indicate Jazelle support within QEMU. | 56 | |
33 | */ | 57 | static void timerlist_rearm(QEMUTimerList *timer_list) |
34 | cpu->isar.id_isar1 = FIELD_DP32(cpu->isar.id_isar1, ID_ISAR1, JAZELLE, 1); | 58 | { |
35 | + /* | 59 | - /* Interrupt execution to force deadline recalculation. */ |
36 | + * Similarly, we need to set MVFR0 fields to enable double precision | 60 | - if (icount_enabled() && timer_list->clock->type == QEMU_CLOCK_VIRTUAL) { |
37 | + * and short vector support even though ARMv5 doesn't have this register. | 61 | - icount_start_warp_timer(); |
38 | + */ | 62 | - } |
39 | + cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1); | 63 | timerlist_notify(timer_list); |
40 | + cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPDP, 1); | ||
41 | } | 64 | } |
42 | 65 | ||
43 | static void arm946_initfn(Object *obj) | ||
44 | @@ -XXX,XX +XXX,XX @@ static void arm1026_initfn(Object *obj) | ||
45 | * set the field to indicate Jazelle support within QEMU. | ||
46 | */ | ||
47 | cpu->isar.id_isar1 = FIELD_DP32(cpu->isar.id_isar1, ID_ISAR1, JAZELLE, 1); | ||
48 | + /* | ||
49 | + * Similarly, we need to set MVFR0 fields to enable double precision | ||
50 | + * and short vector support even though ARMv5 doesn't have this register. | ||
51 | + */ | ||
52 | + cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1); | ||
53 | + cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPDP, 1); | ||
54 | |||
55 | { | ||
56 | /* The 1026 had an IFAR at c6,c0,0,1 rather than the ARMv6 c6,c0,0,2 */ | ||
57 | -- | 66 | -- |
58 | 2.20.1 | 67 | 2.43.0 |
59 | 68 | ||
60 | 69 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Expand the example in the comment documenting MO_ATOM_SUBALIGN, | ||
2 | to be clearer about the atomicity guarantees it represents. | ||
1 | 3 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20250228103222.1838913-1-peter.maydell@linaro.org | ||
7 | --- | ||
8 | include/exec/memop.h | 8 ++++++-- | ||
9 | 1 file changed, 6 insertions(+), 2 deletions(-) | ||
10 | |||
11 | diff --git a/include/exec/memop.h b/include/exec/memop.h | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/include/exec/memop.h | ||
14 | +++ b/include/exec/memop.h | ||
15 | @@ -XXX,XX +XXX,XX @@ typedef enum MemOp { | ||
16 | * Depending on alignment, one or both will be single-copy atomic. | ||
17 | * This is the atomicity e.g. of Arm FEAT_LSE2 LDP. | ||
18 | * MO_ATOM_SUBALIGN: the operation is single-copy atomic by parts | ||
19 | - * by the alignment. E.g. if the address is 0 mod 4, then each | ||
20 | - * 4-byte subobject is single-copy atomic. | ||
21 | + * by the alignment. E.g. if an 8-byte value is accessed at an | ||
22 | + * address which is 0 mod 8, then the whole 8-byte access is | ||
23 | + * single-copy atomic; otherwise, if it is accessed at 0 mod 4 | ||
24 | + * then each 4-byte subobject is single-copy atomic; otherwise | ||
25 | + * if it is accessed at 0 mod 2 then the four 2-byte subobjects | ||
26 | + * are single-copy atomic. | ||
27 | * This is the atomicity e.g. of IBM Power. | ||
28 | * MO_ATOM_NONE: the operation has no atomicity requirements. | ||
29 | * | ||
30 | -- | ||
31 | 2.43.0 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | From: JianChunfu <jansef.jian@hj-micro.com> |
---|---|---|---|
2 | 2 | ||
3 | In the next commit we will implement the write_with_attrs() | 3 | Use a similar terminology smmu_hash_remove_by_sid_range() as the one |
4 | handler. To avoid using different APIs, convert the read() | 4 | being used for other hash table matching functions since |
5 | handler first. | 5 | smmuv3_invalidate_ste() name is not self explanatory, and introduce a |
6 | helper that invokes the g_hash_table_foreach_remove. | ||
6 | 7 | ||
7 | Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com> | 8 | No functional change intended. |
8 | Tested-by: Francisco Iglesias <frasse.iglesias@gmail.com> | 9 | |
9 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 10 | Signed-off-by: JianChunfu <jansef.jian@hj-micro.com> |
11 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
12 | Message-id: 20250228031438.3916-1-jansef.jian@hj-micro.com | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 14 | --- |
12 | hw/ssi/xilinx_spips.c | 23 +++++++++++------------ | 15 | hw/arm/smmu-internal.h | 5 ----- |
13 | 1 file changed, 11 insertions(+), 12 deletions(-) | 16 | include/hw/arm/smmu-common.h | 6 ++++++ |
17 | hw/arm/smmu-common.c | 21 +++++++++++++++++++++ | ||
18 | hw/arm/smmuv3.c | 19 ++----------------- | ||
19 | hw/arm/trace-events | 3 ++- | ||
20 | 5 files changed, 31 insertions(+), 23 deletions(-) | ||
14 | 21 | ||
15 | diff --git a/hw/ssi/xilinx_spips.c b/hw/ssi/xilinx_spips.c | 22 | diff --git a/hw/arm/smmu-internal.h b/hw/arm/smmu-internal.h |
16 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/ssi/xilinx_spips.c | 24 | --- a/hw/arm/smmu-internal.h |
18 | +++ b/hw/ssi/xilinx_spips.c | 25 | +++ b/hw/arm/smmu-internal.h |
19 | @@ -XXX,XX +XXX,XX @@ static void lqspi_load_cache(void *opaque, hwaddr addr) | 26 | @@ -XXX,XX +XXX,XX @@ typedef struct SMMUIOTLBPageInvInfo { |
27 | uint64_t mask; | ||
28 | } SMMUIOTLBPageInvInfo; | ||
29 | |||
30 | -typedef struct SMMUSIDRange { | ||
31 | - uint32_t start; | ||
32 | - uint32_t end; | ||
33 | -} SMMUSIDRange; | ||
34 | - | ||
35 | #endif | ||
36 | diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/include/hw/arm/smmu-common.h | ||
39 | +++ b/include/hw/arm/smmu-common.h | ||
40 | @@ -XXX,XX +XXX,XX @@ typedef struct SMMUIOTLBKey { | ||
41 | uint8_t level; | ||
42 | } SMMUIOTLBKey; | ||
43 | |||
44 | +typedef struct SMMUSIDRange { | ||
45 | + uint32_t start; | ||
46 | + uint32_t end; | ||
47 | +} SMMUSIDRange; | ||
48 | + | ||
49 | struct SMMUState { | ||
50 | /* <private> */ | ||
51 | SysBusDevice dev; | ||
52 | @@ -XXX,XX +XXX,XX @@ void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, | ||
53 | uint8_t tg, uint64_t num_pages, uint8_t ttl); | ||
54 | void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_addr_t ipa, uint8_t tg, | ||
55 | uint64_t num_pages, uint8_t ttl); | ||
56 | +void smmu_configs_inv_sid_range(SMMUState *s, SMMUSIDRange sid_range); | ||
57 | /* Unmap the range of all the notifiers registered to any IOMMU mr */ | ||
58 | void smmu_inv_notifiers_all(SMMUState *s); | ||
59 | |||
60 | diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/hw/arm/smmu-common.c | ||
63 | +++ b/hw/arm/smmu-common.c | ||
64 | @@ -XXX,XX +XXX,XX @@ static gboolean smmu_hash_remove_by_vmid_ipa(gpointer key, gpointer value, | ||
65 | ((entry->iova & ~info->mask) == info->iova); | ||
66 | } | ||
67 | |||
68 | +static gboolean | ||
69 | +smmu_hash_remove_by_sid_range(gpointer key, gpointer value, gpointer user_data) | ||
70 | +{ | ||
71 | + SMMUDevice *sdev = (SMMUDevice *)key; | ||
72 | + uint32_t sid = smmu_get_sid(sdev); | ||
73 | + SMMUSIDRange *sid_range = (SMMUSIDRange *)user_data; | ||
74 | + | ||
75 | + if (sid < sid_range->start || sid > sid_range->end) { | ||
76 | + return false; | ||
77 | + } | ||
78 | + trace_smmu_config_cache_inv(sid); | ||
79 | + return true; | ||
80 | +} | ||
81 | + | ||
82 | +void smmu_configs_inv_sid_range(SMMUState *s, SMMUSIDRange sid_range) | ||
83 | +{ | ||
84 | + trace_smmu_configs_inv_sid_range(sid_range.start, sid_range.end); | ||
85 | + g_hash_table_foreach_remove(s->configs, smmu_hash_remove_by_sid_range, | ||
86 | + &sid_range); | ||
87 | +} | ||
88 | + | ||
89 | void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, | ||
90 | uint8_t tg, uint64_t num_pages, uint8_t ttl) | ||
91 | { | ||
92 | diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/hw/arm/smmuv3.c | ||
95 | +++ b/hw/arm/smmuv3.c | ||
96 | @@ -XXX,XX +XXX,XX @@ static void smmuv3_flush_config(SMMUDevice *sdev) | ||
97 | SMMUv3State *s = sdev->smmu; | ||
98 | SMMUState *bc = &s->smmu_state; | ||
99 | |||
100 | - trace_smmuv3_config_cache_inv(smmu_get_sid(sdev)); | ||
101 | + trace_smmu_config_cache_inv(smmu_get_sid(sdev)); | ||
102 | g_hash_table_remove(bc->configs, sdev); | ||
103 | } | ||
104 | |||
105 | @@ -XXX,XX +XXX,XX @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage) | ||
20 | } | 106 | } |
21 | } | 107 | } |
22 | 108 | ||
23 | -static uint64_t | 109 | -static gboolean |
24 | -lqspi_read(void *opaque, hwaddr addr, unsigned int size) | 110 | -smmuv3_invalidate_ste(gpointer key, gpointer value, gpointer user_data) |
25 | +static MemTxResult lqspi_read(void *opaque, hwaddr addr, uint64_t *value, | 111 | -{ |
26 | + unsigned size, MemTxAttrs attrs) | 112 | - SMMUDevice *sdev = (SMMUDevice *)key; |
113 | - uint32_t sid = smmu_get_sid(sdev); | ||
114 | - SMMUSIDRange *sid_range = (SMMUSIDRange *)user_data; | ||
115 | - | ||
116 | - if (sid < sid_range->start || sid > sid_range->end) { | ||
117 | - return false; | ||
118 | - } | ||
119 | - trace_smmuv3_config_cache_inv(sid); | ||
120 | - return true; | ||
121 | -} | ||
122 | - | ||
123 | static int smmuv3_cmdq_consume(SMMUv3State *s) | ||
27 | { | 124 | { |
28 | - XilinxQSPIPS *q = opaque; | 125 | SMMUState *bs = ARM_SMMU(s); |
29 | - uint32_t ret; | 126 | @@ -XXX,XX +XXX,XX @@ static int smmuv3_cmdq_consume(SMMUv3State *s) |
30 | + XilinxQSPIPS *q = XILINX_QSPIPS(opaque); | 127 | sid_range.end = sid_range.start + mask; |
31 | 128 | ||
32 | if (addr >= q->lqspi_cached_addr && | 129 | trace_smmuv3_cmdq_cfgi_ste_range(sid_range.start, sid_range.end); |
33 | addr <= q->lqspi_cached_addr + LQSPI_CACHE_SIZE - 4) { | 130 | - g_hash_table_foreach_remove(bs->configs, smmuv3_invalidate_ste, |
34 | uint8_t *retp = &q->lqspi_buf[addr - q->lqspi_cached_addr]; | 131 | - &sid_range); |
35 | - ret = cpu_to_le32(*(uint32_t *)retp); | 132 | + smmu_configs_inv_sid_range(bs, sid_range); |
36 | - DB_PRINT_L(1, "addr: %08x, data: %08x\n", (unsigned)addr, | 133 | break; |
37 | - (unsigned)ret); | 134 | } |
38 | - return ret; | 135 | case SMMU_CMD_CFGI_CD: |
39 | - } else { | 136 | diff --git a/hw/arm/trace-events b/hw/arm/trace-events |
40 | - lqspi_load_cache(opaque, addr); | 137 | index XXXXXXX..XXXXXXX 100644 |
41 | - return lqspi_read(opaque, addr, size); | 138 | --- a/hw/arm/trace-events |
42 | + *value = cpu_to_le32(*(uint32_t *)retp); | 139 | +++ b/hw/arm/trace-events |
43 | + DB_PRINT_L(1, "addr: %08" HWADDR_PRIx ", data: %08" PRIx64 "\n", | 140 | @@ -XXX,XX +XXX,XX @@ smmu_iotlb_inv_asid_vmid(int asid, int vmid) "IOTLB invalidate asid=%d vmid=%d" |
44 | + addr, *value); | 141 | smmu_iotlb_inv_vmid(int vmid) "IOTLB invalidate vmid=%d" |
45 | + return MEMTX_OK; | 142 | smmu_iotlb_inv_vmid_s1(int vmid) "IOTLB invalidate vmid=%d" |
46 | } | 143 | smmu_iotlb_inv_iova(int asid, uint64_t addr) "IOTLB invalidate asid=%d addr=0x%"PRIx64 |
47 | + | 144 | +smmu_configs_inv_sid_range(uint32_t start, uint32_t end) "Config cache INV SID range from 0x%x to 0x%x" |
48 | + lqspi_load_cache(opaque, addr); | 145 | +smmu_config_cache_inv(uint32_t sid) "Config cache INV for sid=0x%x" |
49 | + return lqspi_read(opaque, addr, value, size, attrs); | 146 | smmu_inv_notifiers_mr(const char *name) "iommu mr=%s" |
50 | } | 147 | smmu_iotlb_lookup_hit(int asid, int vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" |
51 | 148 | smmu_iotlb_lookup_miss(int asid, int vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" | |
52 | static const MemoryRegionOps lqspi_ops = { | 149 | @@ -XXX,XX +XXX,XX @@ smmuv3_cmdq_tlbi_nh(int vmid) "vmid=%d" |
53 | - .read = lqspi_read, | 150 | smmuv3_cmdq_tlbi_nsnh(void) "" |
54 | + .read_with_attrs = lqspi_read, | 151 | smmuv3_cmdq_tlbi_nh_asid(int asid) "asid=%d" |
55 | .endianness = DEVICE_NATIVE_ENDIAN, | 152 | smmuv3_cmdq_tlbi_s12_vmid(int vmid) "vmid=%d" |
56 | .valid = { | 153 | -smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=0x%x" |
57 | .min_access_size = 1, | 154 | smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu mr=%s" |
155 | smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s" | ||
156 | smmuv3_inv_notifiers_iova(const char *name, int asid, int vmid, uint64_t iova, uint8_t tg, uint64_t num_pages, int stage) "iommu mr=%s asid=%d vmid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" stage=%d" | ||
58 | -- | 157 | -- |
59 | 2.20.1 | 158 | 2.43.0 |
60 | |||
61 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Keith Packard <keithp@keithp.com> | ||
1 | 2 | ||
3 | The documentation says the vector is at 0xffffff80, instead of the | ||
4 | previous value of 0xffffffc0. That value must have been a bug because | ||
5 | the standard vector values (20, 21, 23, 25, 30) were all | ||
6 | past the end of the array. | ||
7 | |||
8 | Signed-off-by: Keith Packard <keithp@keithp.com> | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | target/rx/helper.c | 2 +- | ||
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/target/rx/helper.c b/target/rx/helper.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/rx/helper.c | ||
18 | +++ b/target/rx/helper.c | ||
19 | @@ -XXX,XX +XXX,XX @@ void rx_cpu_do_interrupt(CPUState *cs) | ||
20 | cpu_stl_data(env, env->isp, env->pc); | ||
21 | |||
22 | if (vec < 0x100) { | ||
23 | - env->pc = cpu_ldl_data(env, 0xffffffc0 + vec * 4); | ||
24 | + env->pc = cpu_ldl_data(env, 0xffffff80 + vec * 4); | ||
25 | } else { | ||
26 | env->pc = cpu_ldl_data(env, env->intb + (vec & 0xff) * 4); | ||
27 | } | ||
28 | -- | ||
29 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Keith Packard <keithp@keithp.com> | ||
1 | 2 | ||
3 | Functions which modify TCG globals must not be marked TCG_CALL_NO_WG, | ||
4 | as that tells the optimizer that TCG global values already loaded in | ||
5 | machine registers are still valid, and so any changes which these | ||
6 | helpers make to the CPU state may be ignored. | ||
7 | |||
8 | The target/rx code chooses to put (among other things) all the PSW | ||
9 | bits and also ACC into globals, so the NO_WG flag on various | ||
10 | functions that touch the PSW or ACC is incorrect and must be removed. | ||
11 | This includes all the floating point helper functions, because | ||
12 | update_fpsw() will update PSW Z and S. | ||
13 | |||
14 | Signed-off-by: Keith Packard <keithp@keithp.com> | ||
15 | [PMM: Clarified commit message] | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | --- | ||
19 | target/rx/helper.h | 34 +++++++++++++++++----------------- | ||
20 | 1 file changed, 17 insertions(+), 17 deletions(-) | ||
21 | |||
22 | diff --git a/target/rx/helper.h b/target/rx/helper.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/target/rx/helper.h | ||
25 | +++ b/target/rx/helper.h | ||
26 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_1(raise_privilege_violation, noreturn, env) | ||
27 | DEF_HELPER_1(wait, noreturn, env) | ||
28 | DEF_HELPER_2(rxint, noreturn, env, i32) | ||
29 | DEF_HELPER_1(rxbrk, noreturn, env) | ||
30 | -DEF_HELPER_FLAGS_3(fadd, TCG_CALL_NO_WG, f32, env, f32, f32) | ||
31 | -DEF_HELPER_FLAGS_3(fsub, TCG_CALL_NO_WG, f32, env, f32, f32) | ||
32 | -DEF_HELPER_FLAGS_3(fmul, TCG_CALL_NO_WG, f32, env, f32, f32) | ||
33 | -DEF_HELPER_FLAGS_3(fdiv, TCG_CALL_NO_WG, f32, env, f32, f32) | ||
34 | -DEF_HELPER_FLAGS_3(fcmp, TCG_CALL_NO_WG, void, env, f32, f32) | ||
35 | -DEF_HELPER_FLAGS_2(ftoi, TCG_CALL_NO_WG, i32, env, f32) | ||
36 | -DEF_HELPER_FLAGS_2(round, TCG_CALL_NO_WG, i32, env, f32) | ||
37 | -DEF_HELPER_FLAGS_2(itof, TCG_CALL_NO_WG, f32, env, i32) | ||
38 | +DEF_HELPER_3(fadd, f32, env, f32, f32) | ||
39 | +DEF_HELPER_3(fsub, f32, env, f32, f32) | ||
40 | +DEF_HELPER_3(fmul, f32, env, f32, f32) | ||
41 | +DEF_HELPER_3(fdiv, f32, env, f32, f32) | ||
42 | +DEF_HELPER_3(fcmp, void, env, f32, f32) | ||
43 | +DEF_HELPER_2(ftoi, i32, env, f32) | ||
44 | +DEF_HELPER_2(round, i32, env, f32) | ||
45 | +DEF_HELPER_2(itof, f32, env, i32) | ||
46 | DEF_HELPER_2(set_fpsw, void, env, i32) | ||
47 | -DEF_HELPER_FLAGS_2(racw, TCG_CALL_NO_WG, void, env, i32) | ||
48 | -DEF_HELPER_FLAGS_2(set_psw_rte, TCG_CALL_NO_WG, void, env, i32) | ||
49 | -DEF_HELPER_FLAGS_2(set_psw, TCG_CALL_NO_WG, void, env, i32) | ||
50 | +DEF_HELPER_2(racw, void, env, i32) | ||
51 | +DEF_HELPER_2(set_psw_rte, void, env, i32) | ||
52 | +DEF_HELPER_2(set_psw, void, env, i32) | ||
53 | DEF_HELPER_1(pack_psw, i32, env) | ||
54 | -DEF_HELPER_FLAGS_3(div, TCG_CALL_NO_WG, i32, env, i32, i32) | ||
55 | -DEF_HELPER_FLAGS_3(divu, TCG_CALL_NO_WG, i32, env, i32, i32) | ||
56 | -DEF_HELPER_FLAGS_1(scmpu, TCG_CALL_NO_WG, void, env) | ||
57 | +DEF_HELPER_3(div, i32, env, i32, i32) | ||
58 | +DEF_HELPER_3(divu, i32, env, i32, i32) | ||
59 | +DEF_HELPER_1(scmpu, void, env) | ||
60 | DEF_HELPER_1(smovu, void, env) | ||
61 | DEF_HELPER_1(smovf, void, env) | ||
62 | DEF_HELPER_1(smovb, void, env) | ||
63 | DEF_HELPER_2(sstr, void, env, i32) | ||
64 | -DEF_HELPER_FLAGS_2(swhile, TCG_CALL_NO_WG, void, env, i32) | ||
65 | -DEF_HELPER_FLAGS_2(suntil, TCG_CALL_NO_WG, void, env, i32) | ||
66 | -DEF_HELPER_FLAGS_2(rmpa, TCG_CALL_NO_WG, void, env, i32) | ||
67 | +DEF_HELPER_2(swhile, void, env, i32) | ||
68 | +DEF_HELPER_2(suntil, void, env, i32) | ||
69 | +DEF_HELPER_2(rmpa, void, env, i32) | ||
70 | DEF_HELPER_1(satr, void, env) | ||
71 | -- | ||
72 | 2.43.0 | diff view generated by jsdifflib |