1 | One last arm pullreq before I stop work for the end of the year... | 1 | Hi; here's a target-arm pull for rc2. Four arm-related fixes, |
---|---|---|---|
2 | and a couple of bug fixes for other areas of the codebase | ||
3 | that seemed like they'd fallen through the cracks. | ||
2 | 4 | ||
5 | thanks | ||
3 | -- PMM | 6 | -- PMM |
4 | 7 | ||
5 | The following changes since commit 8e5943260a8f765216674ee87ce8588cc4e7463e: | 8 | The following changes since commit ccb86f079a9e4d94918086a9df18c1844347aff8: |
6 | 9 | ||
7 | Merge remote-tracking branch 'remotes/vivier2/tags/trivial-branch-pull-request' into staging (2019-12-20 12:46:10 +0000) | 10 | Merge tag 'pull-nbd-2023-07-28' of https://repo.or.cz/qemu/ericb into staging (2023-07-28 09:56:57 -0700) |
8 | 11 | ||
9 | are available in the Git repository at: | 12 | are available in the Git repository at: |
10 | 13 | ||
11 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20191220 | 14 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20230731 |
12 | 15 | ||
13 | for you to fetch changes up to c8fa6079eb35888587f1be27c1590da4edcc5098: | 16 | for you to fetch changes up to 108e8180c6b0c315711aa54e914030a313505c17: |
14 | 17 | ||
15 | arm/arm-powerctl: rebuild hflags after setting CP15 bits in arm_set_cpu_on() (2019-12-20 14:03:00 +0000) | 18 | gdbstub: Fix client Ctrl-C handling (2023-07-31 14:57:32 +0100) |
16 | 19 | ||
17 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
18 | target-arm queue: | 21 | target-arm queue: |
19 | * Support emulating the generic timers at frequencies other than 62.5MHz | 22 | * Don't build AArch64 decodetree files for qemu-system-arm |
20 | * Various fixes for SMMUv3 emulation bugs | 23 | * Fix TCG assert in v8.1M CSEL etc |
21 | * Improve assert error message for hflags mismatches | 24 | * Fix MemOp for STGP |
22 | * arm-powerctl: rebuild hflags after setting CP15 bits in arm_set_cpu_on() | 25 | * gdbstub: Fix client Ctrl-C handling |
26 | * kvm: Fix crash due to access uninitialized kvm_state | ||
27 | * elf2dmp: Don't abandon when Prcb is set to 0 | ||
23 | 28 | ||
24 | ---------------------------------------------------------------- | 29 | ---------------------------------------------------------------- |
25 | Andrew Jeffery (4): | 30 | Akihiko Odaki (1): |
26 | target/arm: Remove redundant scaling of nexttick | 31 | elf2dmp: Don't abandon when Prcb is set to 0 |
27 | target/arm: Abstract the generic timer frequency | ||
28 | target/arm: Prepare generic timer for per-platform CNTFRQ | ||
29 | ast2600: Configure CNTFRQ at 1125MHz | ||
30 | 32 | ||
31 | Niek Linnenbank (1): | 33 | Gavin Shan (1): |
32 | arm/arm-powerctl: rebuild hflags after setting CP15 bits in arm_set_cpu_on() | 34 | kvm: Fix crash due to access uninitialized kvm_state |
33 | 35 | ||
34 | Philippe Mathieu-Daudé (1): | 36 | Nicholas Piggin (1): |
35 | target/arm: Display helpful message when hflags mismatch | 37 | gdbstub: Fix client Ctrl-C handling |
36 | 38 | ||
37 | Simon Veith (6): | 39 | Peter Maydell (2): |
38 | hw/arm/smmuv3: Apply address mask to linear strtab base address | 40 | target/arm: Avoid writing to constant TCGv in trans_CSEL() |
39 | hw/arm/smmuv3: Correct SMMU_BASE_ADDR_MASK value | 41 | target/arm/tcg: Don't build AArch64 decodetree files for qemu-system-arm |
40 | hw/arm/smmuv3: Check stream IDs against actual table LOG2SIZE | ||
41 | hw/arm/smmuv3: Align stream table base address to table size | ||
42 | hw/arm/smmuv3: Use correct bit positions in EVT_SET_ADDR2 macro | ||
43 | hw/arm/smmuv3: Report F_STE_FETCH fault address in correct word position | ||
44 | 42 | ||
45 | hw/arm/smmuv3-internal.h | 6 ++--- | 43 | Richard Henderson (1): |
46 | target/arm/cpu.h | 5 ++++ | 44 | target/arm: Fix MemOp for STGP |
47 | hw/arm/aspeed_ast2600.c | 3 +++ | ||
48 | hw/arm/smmuv3.c | 28 +++++++++++++++----- | ||
49 | target/arm/arm-powerctl.c | 3 +++ | ||
50 | target/arm/cpu.c | 65 +++++++++++++++++++++++++++++++++++++++++------ | ||
51 | target/arm/helper.c | 42 +++++++++++++++++++++++------- | ||
52 | 7 files changed, 125 insertions(+), 27 deletions(-) | ||
53 | 45 | ||
46 | accel/kvm/kvm-all.c | 2 +- | ||
47 | contrib/elf2dmp/main.c | 5 +++++ | ||
48 | gdbstub/gdbstub.c | 13 +++++++++++-- | ||
49 | target/arm/tcg/translate-a64.c | 21 ++++++++++++++++++--- | ||
50 | target/arm/tcg/translate.c | 15 ++++++++------- | ||
51 | target/arm/tcg/meson.build | 10 +++++++--- | ||
52 | 6 files changed, 50 insertions(+), 16 deletions(-) | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Andrew Jeffery <andrew@aj.id.au> | ||
2 | 1 | ||
3 | The corner-case codepath was adjusting nexttick such that overflow | ||
4 | wouldn't occur when timer_mod() scaled the value back up. Remove a use | ||
5 | of GTIMER_SCALE and avoid unnecessary operations by calling | ||
6 | timer_mod_ns() directly. | ||
7 | |||
8 | Signed-off-by: Andrew Jeffery <andrew@aj.id.au> | ||
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | ||
11 | Message-id: f8c680720e3abe55476e6d9cb604ad27fdbeb2e0.1576215453.git-series.andrew@aj.id.au | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | --- | ||
14 | target/arm/helper.c | 5 +++-- | ||
15 | 1 file changed, 3 insertions(+), 2 deletions(-) | ||
16 | |||
17 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/arm/helper.c | ||
20 | +++ b/target/arm/helper.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx) | ||
22 | * timer expires we will reset the timer for any remaining period. | ||
23 | */ | ||
24 | if (nexttick > INT64_MAX / GTIMER_SCALE) { | ||
25 | - nexttick = INT64_MAX / GTIMER_SCALE; | ||
26 | + timer_mod_ns(cpu->gt_timer[timeridx], INT64_MAX); | ||
27 | + } else { | ||
28 | + timer_mod(cpu->gt_timer[timeridx], nexttick); | ||
29 | } | ||
30 | - timer_mod(cpu->gt_timer[timeridx], nexttick); | ||
31 | trace_arm_gt_recalc(timeridx, irqstate, nexttick); | ||
32 | } else { | ||
33 | /* Timer disabled: ISTATUS and timer output always clear */ | ||
34 | -- | ||
35 | 2.20.1 | ||
36 | |||
37 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Andrew Jeffery <andrew@aj.id.au> | ||
2 | 1 | ||
3 | Prepare for SoCs such as the ASPEED AST2600 whose firmware configures | ||
4 | CNTFRQ to values significantly larger than the static 62.5MHz value | ||
5 | currently derived from GTIMER_SCALE. As the OS potentially derives its | ||
6 | timer periods from the CNTFRQ value the lack of support for running | ||
7 | QEMUTimers at the appropriate rate leads to sticky behaviour in the | ||
8 | guest. | ||
9 | |||
10 | Substitute the GTIMER_SCALE constant with use of a helper to derive the | ||
11 | period from gt_cntfrq_hz stored in struct ARMCPU. Initially set | ||
12 | gt_cntfrq_hz to the frequency associated with GTIMER_SCALE so current | ||
13 | behaviour is maintained. | ||
14 | |||
15 | Signed-off-by: Andrew Jeffery <andrew@aj.id.au> | ||
16 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
17 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
18 | Message-id: 40bd8df043f66e1ccfb3e9482999d099ac72bb2e.1576215453.git-series.andrew@aj.id.au | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
20 | --- | ||
21 | target/arm/cpu.h | 5 +++++ | ||
22 | target/arm/cpu.c | 8 ++++++++ | ||
23 | target/arm/helper.c | 10 +++++++--- | ||
24 | 3 files changed, 20 insertions(+), 3 deletions(-) | ||
25 | |||
26 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/target/arm/cpu.h | ||
29 | +++ b/target/arm/cpu.h | ||
30 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { | ||
31 | */ | ||
32 | DECLARE_BITMAP(sve_vq_map, ARM_MAX_VQ); | ||
33 | DECLARE_BITMAP(sve_vq_init, ARM_MAX_VQ); | ||
34 | + | ||
35 | + /* Generic timer counter frequency, in Hz */ | ||
36 | + uint64_t gt_cntfrq_hz; | ||
37 | }; | ||
38 | |||
39 | +unsigned int gt_cntfrq_period_ns(ARMCPU *cpu); | ||
40 | + | ||
41 | void arm_cpu_post_init(Object *obj); | ||
42 | |||
43 | uint64_t arm_cpu_mp_affinity(int idx, uint8_t clustersz); | ||
44 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/arm/cpu.c | ||
47 | +++ b/target/arm/cpu.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_initfn(Object *obj) | ||
49 | if (tcg_enabled()) { | ||
50 | cpu->psci_version = 2; /* TCG implements PSCI 0.2 */ | ||
51 | } | ||
52 | + | ||
53 | + cpu->gt_cntfrq_hz = NANOSECONDS_PER_SECOND / GTIMER_SCALE; | ||
54 | } | ||
55 | |||
56 | static Property arm_cpu_reset_cbar_property = | ||
57 | @@ -XXX,XX +XXX,XX @@ static void arm_set_init_svtor(Object *obj, Visitor *v, const char *name, | ||
58 | visit_type_uint32(v, name, &cpu->init_svtor, errp); | ||
59 | } | ||
60 | |||
61 | +unsigned int gt_cntfrq_period_ns(ARMCPU *cpu) | ||
62 | +{ | ||
63 | + return NANOSECONDS_PER_SECOND > cpu->gt_cntfrq_hz ? | ||
64 | + NANOSECONDS_PER_SECOND / cpu->gt_cntfrq_hz : 1; | ||
65 | +} | ||
66 | + | ||
67 | void arm_cpu_post_init(Object *obj) | ||
68 | { | ||
69 | ARMCPU *cpu = ARM_CPU(obj); | ||
70 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/target/arm/helper.c | ||
73 | +++ b/target/arm/helper.c | ||
74 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult gt_stimer_access(CPUARMState *env, | ||
75 | |||
76 | static uint64_t gt_get_countervalue(CPUARMState *env) | ||
77 | { | ||
78 | - return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / GTIMER_SCALE; | ||
79 | + ARMCPU *cpu = env_archcpu(env); | ||
80 | + | ||
81 | + return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / gt_cntfrq_period_ns(cpu); | ||
82 | } | ||
83 | |||
84 | static void gt_recalc_timer(ARMCPU *cpu, int timeridx) | ||
85 | @@ -XXX,XX +XXX,XX @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx) | ||
86 | * set the timer for as far in the future as possible. When the | ||
87 | * timer expires we will reset the timer for any remaining period. | ||
88 | */ | ||
89 | - if (nexttick > INT64_MAX / GTIMER_SCALE) { | ||
90 | + if (nexttick > INT64_MAX / gt_cntfrq_period_ns(cpu)) { | ||
91 | timer_mod_ns(cpu->gt_timer[timeridx], INT64_MAX); | ||
92 | } else { | ||
93 | timer_mod(cpu->gt_timer[timeridx], nexttick); | ||
94 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = { | ||
95 | |||
96 | static uint64_t gt_virt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
97 | { | ||
98 | + ARMCPU *cpu = env_archcpu(env); | ||
99 | + | ||
100 | /* Currently we have no support for QEMUTimer in linux-user so we | ||
101 | * can't call gt_get_countervalue(env), instead we directly | ||
102 | * call the lower level functions. | ||
103 | */ | ||
104 | - return cpu_get_clock() / GTIMER_SCALE; | ||
105 | + return cpu_get_clock() / gt_cntfrq_period_ns(cpu); | ||
106 | } | ||
107 | |||
108 | static const ARMCPRegInfo generic_timer_cp_reginfo[] = { | ||
109 | -- | ||
110 | 2.20.1 | ||
111 | |||
112 | diff view generated by jsdifflib |
1 | From: Simon Veith <sveith@amazon.de> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Per the specification, and as observed in hardware, the SMMUv3 aligns | 3 | When converting to decodetree, the code to rebuild mop for the pair |
4 | the SMMU_STRTAB_BASE address to the size of the table by masking out the | 4 | only made it into trans_STP and not into trans_STGP. |
5 | respective least significant bits in the ADDR field. | ||
6 | 5 | ||
7 | Apply this masking logic to our smmu_find_ste() lookup function per the | 6 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1790 |
8 | specification. | 7 | Fixes: 8c212eb6594 ("target/arm: Convert load/store-pair to decodetree") |
9 | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | |
10 | ref. ARM IHI 0070C, section 6.3.23. | 9 | Message-id: 20230726165416.309624-1-richard.henderson@linaro.org |
11 | |||
12 | Signed-off-by: Simon Veith <sveith@amazon.de> | ||
13 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | Message-id: 1576509312-13083-5-git-send-email-sveith@amazon.de | ||
16 | Cc: Eric Auger <eric.auger@redhat.com> | ||
17 | Cc: qemu-devel@nongnu.org | ||
18 | Cc: qemu-arm@nongnu.org | ||
19 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
21 | --- | 12 | --- |
22 | hw/arm/smmuv3.c | 18 ++++++++++++++---- | 13 | target/arm/tcg/translate-a64.c | 21 ++++++++++++++++++--- |
23 | 1 file changed, 14 insertions(+), 4 deletions(-) | 14 | 1 file changed, 18 insertions(+), 3 deletions(-) |
24 | 15 | ||
25 | diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c | 16 | diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c |
26 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/hw/arm/smmuv3.c | 18 | --- a/target/arm/tcg/translate-a64.c |
28 | +++ b/hw/arm/smmuv3.c | 19 | +++ b/target/arm/tcg/translate-a64.c |
29 | @@ -XXX,XX +XXX,XX @@ bad_ste: | 20 | @@ -XXX,XX +XXX,XX @@ static bool trans_STGP(DisasContext *s, arg_ldstpair *a) |
30 | static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, | 21 | MemOp mop; |
31 | SMMUEventInfo *event) | 22 | TCGv_i128 tmp; |
32 | { | 23 | |
33 | - dma_addr_t addr; | 24 | + /* STGP only comes in one size. */ |
34 | + dma_addr_t addr, strtab_base; | 25 | + tcg_debug_assert(a->sz == MO_64); |
35 | uint32_t log2size; | 26 | + |
36 | + int strtab_size_shift; | 27 | if (!dc_isar_feature(aa64_mte_insn_reg, s)) { |
37 | int ret; | 28 | return false; |
38 | |||
39 | trace_smmuv3_find_ste(sid, s->features, s->sid_split); | ||
40 | @@ -XXX,XX +XXX,XX @@ static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, | ||
41 | } | 29 | } |
42 | if (s->features & SMMU_FEATURE_2LVL_STE) { | 30 | @@ -XXX,XX +XXX,XX @@ static bool trans_STGP(DisasContext *s, arg_ldstpair *a) |
43 | int l1_ste_offset, l2_ste_offset, max_l2_ste, span; | 31 | gen_helper_stg(cpu_env, dirty_addr, dirty_addr); |
44 | - dma_addr_t strtab_base, l1ptr, l2ptr; | ||
45 | + dma_addr_t l1ptr, l2ptr; | ||
46 | STEDesc l1std; | ||
47 | |||
48 | - strtab_base = s->strtab_base & SMMU_BASE_ADDR_MASK; | ||
49 | + /* | ||
50 | + * Align strtab base address to table size. For this purpose, assume it | ||
51 | + * is not bounded by SMMU_IDR1_SIDSIZE. | ||
52 | + */ | ||
53 | + strtab_size_shift = MAX(5, (int)log2size - s->sid_split - 1 + 3); | ||
54 | + strtab_base = s->strtab_base & SMMU_BASE_ADDR_MASK & | ||
55 | + ~MAKE_64BIT_MASK(0, strtab_size_shift); | ||
56 | l1_ste_offset = sid >> s->sid_split; | ||
57 | l2_ste_offset = sid & ((1 << s->sid_split) - 1); | ||
58 | l1ptr = (dma_addr_t)(strtab_base + l1_ste_offset * sizeof(l1std)); | ||
59 | @@ -XXX,XX +XXX,XX @@ static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, | ||
60 | } | ||
61 | addr = l2ptr + l2_ste_offset * sizeof(*ste); | ||
62 | } else { | ||
63 | - addr = (s->strtab_base & SMMU_BASE_ADDR_MASK) + sid * sizeof(*ste); | ||
64 | + strtab_size_shift = log2size + 5; | ||
65 | + strtab_base = s->strtab_base & SMMU_BASE_ADDR_MASK & | ||
66 | + ~MAKE_64BIT_MASK(0, strtab_size_shift); | ||
67 | + addr = strtab_base + sid * sizeof(*ste); | ||
68 | } | 32 | } |
69 | 33 | ||
70 | if (smmu_get_ste(s, addr, ste, event)) { | 34 | - mop = finalize_memop(s, a->sz); |
35 | - clean_addr = gen_mte_checkN(s, dirty_addr, true, false, 2 << a->sz, mop); | ||
36 | + mop = finalize_memop(s, MO_64); | ||
37 | + clean_addr = gen_mte_checkN(s, dirty_addr, true, false, 2 << MO_64, mop); | ||
38 | |||
39 | tcg_rt = cpu_reg(s, a->rt); | ||
40 | tcg_rt2 = cpu_reg(s, a->rt2); | ||
41 | |||
42 | - assert(a->sz == 3); | ||
43 | + /* | ||
44 | + * STGP is defined as two 8-byte memory operations and one tag operation. | ||
45 | + * We implement it as one single 16-byte memory operation for convenience. | ||
46 | + * Rebuild mop as for STP. | ||
47 | + * TODO: The atomicity with LSE2 is stronger than required. | ||
48 | + * Need a form of MO_ATOM_WITHIN16_PAIR that never requires | ||
49 | + * 16-byte atomicity. | ||
50 | + */ | ||
51 | + mop = MO_128; | ||
52 | + if (s->align_mem) { | ||
53 | + mop |= MO_ALIGN_8; | ||
54 | + } | ||
55 | + mop = finalize_memop_pair(s, mop); | ||
56 | |||
57 | tmp = tcg_temp_new_i128(); | ||
58 | if (s->be_data == MO_LE) { | ||
71 | -- | 59 | -- |
72 | 2.20.1 | 60 | 2.34.1 |
73 | |||
74 | diff view generated by jsdifflib |
1 | From: Andrew Jeffery <andrew@aj.id.au> | 1 | From: Akihiko Odaki <akihiko.odaki@daynix.com> |
---|---|---|---|
2 | 2 | ||
3 | The ASPEED AST2600 clocks the generic timer at the rate of HPLL. On | 3 | Prcb may be set to 0 for some CPUs if the dump was taken before they |
4 | recent firmwares this is at 1125MHz, which is considerably quicker than | 4 | start. The dump may still contain valuable information for started CPUs |
5 | the assumed 62.5MHz of the current generic timer implementation. The | 5 | so don't abandon conversion in such a case. |
6 | delta between the value as read from CNTFRQ and the true rate of the | ||
7 | underlying QEMUTimer leads to sticky behaviour in AST2600 guests. | ||
8 | 6 | ||
9 | Add a feature-gated property exposing CNTFRQ for ARM CPUs providing the | 7 | Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> |
10 | generic timer. This allows platforms to configure CNTFRQ (and the | 8 | Reviewed-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu> |
11 | associated QEMUTimer) to the appropriate frequency prior to starting the | 9 | Message-id: 20230611033434.14659-1-akihiko.odaki@daynix.com |
12 | guest. | ||
13 | |||
14 | As the platform can now determine the rate of CNTFRQ we're exposed to | ||
15 | limitations of QEMUTimer that didn't previously materialise: In the | ||
16 | course of emulation we need to arbitrarily and accurately convert | ||
17 | between guest ticks and time, but we're constrained by QEMUTimer's use | ||
18 | of an integer scaling factor. The effect is QEMUTimer cannot exactly | ||
19 | capture the period of frequencies that do not cleanly divide | ||
20 | NANOSECONDS_PER_SECOND for scaling ticks to time. As such, provide an | ||
21 | equally inaccurate scaling factor for scaling time to ticks so at least | ||
22 | a self-consistent inverse relationship holds. | ||
23 | |||
24 | Signed-off-by: Andrew Jeffery <andrew@aj.id.au> | ||
25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
26 | Message-id: a22db9325f96e39f76e3c2baddcb712149f46bf2.1576215453.git-series.andrew@aj.id.au | ||
27 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
28 | --- | 11 | --- |
29 | target/arm/cpu.c | 61 +++++++++++++++++++++++++++++++++++++-------- | 12 | contrib/elf2dmp/main.c | 5 +++++ |
30 | target/arm/helper.c | 9 ++++++- | 13 | 1 file changed, 5 insertions(+) |
31 | 2 files changed, 59 insertions(+), 11 deletions(-) | ||
32 | 14 | ||
33 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 15 | diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c |
34 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/target/arm/cpu.c | 17 | --- a/contrib/elf2dmp/main.c |
36 | +++ b/target/arm/cpu.c | 18 | +++ b/contrib/elf2dmp/main.c |
37 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_initfn(Object *obj) | 19 | @@ -XXX,XX +XXX,XX @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg, |
38 | if (tcg_enabled()) { | 20 | return 1; |
39 | cpu->psci_version = 2; /* TCG implements PSCI 0.2 */ | ||
40 | } | ||
41 | - | ||
42 | - cpu->gt_cntfrq_hz = NANOSECONDS_PER_SECOND / GTIMER_SCALE; | ||
43 | } | ||
44 | |||
45 | +static Property arm_cpu_gt_cntfrq_property = | ||
46 | + DEFINE_PROP_UINT64("cntfrq", ARMCPU, gt_cntfrq_hz, | ||
47 | + NANOSECONDS_PER_SECOND / GTIMER_SCALE); | ||
48 | + | ||
49 | static Property arm_cpu_reset_cbar_property = | ||
50 | DEFINE_PROP_UINT64("reset-cbar", ARMCPU, reset_cbar, 0); | ||
51 | |||
52 | @@ -XXX,XX +XXX,XX @@ static void arm_set_init_svtor(Object *obj, Visitor *v, const char *name, | ||
53 | |||
54 | unsigned int gt_cntfrq_period_ns(ARMCPU *cpu) | ||
55 | { | ||
56 | + /* | ||
57 | + * The exact approach to calculating guest ticks is: | ||
58 | + * | ||
59 | + * muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), cpu->gt_cntfrq_hz, | ||
60 | + * NANOSECONDS_PER_SECOND); | ||
61 | + * | ||
62 | + * We don't do that. Rather we intentionally use integer division | ||
63 | + * truncation below and in the caller for the conversion of host monotonic | ||
64 | + * time to guest ticks to provide the exact inverse for the semantics of | ||
65 | + * the QEMUTimer scale factor. QEMUTimer's scale facter is an integer, so | ||
66 | + * it loses precision when representing frequencies where | ||
67 | + * `(NANOSECONDS_PER_SECOND % cpu->gt_cntfrq) > 0` holds. Failing to | ||
68 | + * provide an exact inverse leads to scheduling timers with negative | ||
69 | + * periods, which in turn leads to sticky behaviour in the guest. | ||
70 | + * | ||
71 | + * Finally, CNTFRQ is effectively capped at 1GHz to ensure our scale factor | ||
72 | + * cannot become zero. | ||
73 | + */ | ||
74 | return NANOSECONDS_PER_SECOND > cpu->gt_cntfrq_hz ? | ||
75 | NANOSECONDS_PER_SECOND / cpu->gt_cntfrq_hz : 1; | ||
76 | } | ||
77 | @@ -XXX,XX +XXX,XX @@ void arm_cpu_post_init(Object *obj) | ||
78 | |||
79 | qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property, | ||
80 | &error_abort); | ||
81 | + | ||
82 | + if (arm_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER)) { | ||
83 | + qdev_property_add_static(DEVICE(cpu), &arm_cpu_gt_cntfrq_property, | ||
84 | + &error_abort); | ||
85 | + } | ||
86 | } | ||
87 | |||
88 | static void arm_cpu_finalizefn(Object *obj) | ||
89 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) | ||
90 | } | 21 | } |
91 | } | 22 | |
92 | 23 | + if (!Prcb) { | |
93 | - cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, | 24 | + eprintf("Context for CPU #%d is missing\n", i); |
94 | - arm_gt_ptimer_cb, cpu); | 25 | + continue; |
95 | - cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, | ||
96 | - arm_gt_vtimer_cb, cpu); | ||
97 | - cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, | ||
98 | - arm_gt_htimer_cb, cpu); | ||
99 | - cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, | ||
100 | - arm_gt_stimer_cb, cpu); | ||
101 | + | ||
102 | + { | ||
103 | + uint64_t scale; | ||
104 | + | ||
105 | + if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) { | ||
106 | + if (!cpu->gt_cntfrq_hz) { | ||
107 | + error_setg(errp, "Invalid CNTFRQ: %"PRId64"Hz", | ||
108 | + cpu->gt_cntfrq_hz); | ||
109 | + return; | ||
110 | + } | ||
111 | + scale = gt_cntfrq_period_ns(cpu); | ||
112 | + } else { | ||
113 | + scale = GTIMER_SCALE; | ||
114 | + } | 26 | + } |
115 | + | 27 | + |
116 | + cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, scale, | 28 | if (va_space_rw(vs, Prcb + kdbg->OffsetPrcbContext, |
117 | + arm_gt_ptimer_cb, cpu); | 29 | &Context, sizeof(Context), 0)) { |
118 | + cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, scale, | 30 | eprintf("Failed to read CPU #%d ContextFrame location\n", i); |
119 | + arm_gt_vtimer_cb, cpu); | ||
120 | + cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, scale, | ||
121 | + arm_gt_htimer_cb, cpu); | ||
122 | + cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, scale, | ||
123 | + arm_gt_stimer_cb, cpu); | ||
124 | + } | ||
125 | #endif | ||
126 | |||
127 | cpu_exec_realizefn(cs, &local_err); | ||
128 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
129 | index XXXXXXX..XXXXXXX 100644 | ||
130 | --- a/target/arm/helper.c | ||
131 | +++ b/target/arm/helper.c | ||
132 | @@ -XXX,XX +XXX,XX @@ void arm_gt_stimer_cb(void *opaque) | ||
133 | gt_recalc_timer(cpu, GTIMER_SEC); | ||
134 | } | ||
135 | |||
136 | +static void arm_gt_cntfrq_reset(CPUARMState *env, const ARMCPRegInfo *opaque) | ||
137 | +{ | ||
138 | + ARMCPU *cpu = env_archcpu(env); | ||
139 | + | ||
140 | + cpu->env.cp15.c14_cntfrq = cpu->gt_cntfrq_hz; | ||
141 | +} | ||
142 | + | ||
143 | static const ARMCPRegInfo generic_timer_cp_reginfo[] = { | ||
144 | /* Note that CNTFRQ is purely reads-as-written for the benefit | ||
145 | * of software; writing it doesn't actually change the timer frequency. | ||
146 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = { | ||
147 | .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 0, .opc2 = 0, | ||
148 | .access = PL1_RW | PL0_R, .accessfn = gt_cntfrq_access, | ||
149 | .fieldoffset = offsetof(CPUARMState, cp15.c14_cntfrq), | ||
150 | - .resetvalue = (1000 * 1000 * 1000) / GTIMER_SCALE, | ||
151 | + .resetfn = arm_gt_cntfrq_reset, | ||
152 | }, | ||
153 | /* overall control: mostly access permissions */ | ||
154 | { .name = "CNTKCTL", .state = ARM_CP_STATE_BOTH, | ||
155 | -- | 31 | -- |
156 | 2.20.1 | 32 | 2.34.1 |
157 | |||
158 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Andrew Jeffery <andrew@aj.id.au> | ||
2 | 1 | ||
3 | This matches the configuration set by u-boot on the AST2600. | ||
4 | |||
5 | Signed-off-by: Andrew Jeffery <andrew@aj.id.au> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
9 | Message-id: 080ca1267a09381c43cf3c50d434fb6c186f2b6e.1576215453.git-series.andrew@aj.id.au | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | hw/arm/aspeed_ast2600.c | 3 +++ | ||
13 | 1 file changed, 3 insertions(+) | ||
14 | |||
15 | diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/arm/aspeed_ast2600.c | ||
18 | +++ b/hw/arm/aspeed_ast2600.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) | ||
20 | object_property_set_int(OBJECT(&s->cpu[i]), aspeed_calc_affinity(i), | ||
21 | "mp-affinity", &error_abort); | ||
22 | |||
23 | + object_property_set_int(OBJECT(&s->cpu[i]), 1125000000, "cntfrq", | ||
24 | + &error_abort); | ||
25 | + | ||
26 | /* | ||
27 | * TODO: the secondary CPUs are started and a boot helper | ||
28 | * is needed when using -kernel | ||
29 | -- | ||
30 | 2.20.1 | ||
31 | |||
32 | diff view generated by jsdifflib |
1 | From: Niek Linnenbank <nieklinnenbank@gmail.com> | 1 | In commit 0b188ea05acb5 we changed the implementation of |
---|---|---|---|
2 | trans_CSEL() to use tcg_constant_i32(). However, this change | ||
3 | was incorrect, because the implementation of the function | ||
4 | sets up the TCGv_i32 rn and rm to be either zero or else | ||
5 | a TCG temp created in load_reg(), and these TCG temps are | ||
6 | then in both cases written to by the emitted TCG ops. | ||
7 | The result is that we hit a TCG assertion: | ||
2 | 8 | ||
3 | After setting CP15 bits in arm_set_cpu_on() the cached hflags must | 9 | qemu-system-arm: ../../tcg/tcg.c:4455: tcg_reg_alloc_mov: Assertion `!temp_readonly(ots)' failed. |
4 | be rebuild to reflect the changed processor state. Without rebuilding, | ||
5 | the cached hflags would be inconsistent until the next call to | ||
6 | arm_rebuild_hflags(). When QEMU is compiled with debugging enabled | ||
7 | (--enable-debug), this problem is captured shortly after the first | ||
8 | call to arm_set_cpu_on() for CPUs running in ARM 32-bit non-secure mode: | ||
9 | 10 | ||
10 | qemu-system-arm: target/arm/helper.c:11359: cpu_get_tb_cpu_state: | 11 | (or on a non-debug build, just produce a garbage result) |
11 | Assertion `flags == rebuild_hflags_internal(env)' failed. | ||
12 | Aborted (core dumped) | ||
13 | 12 | ||
14 | Fixes: 0c7f8c43daf65 | 13 | Adjust the code so that rn and rm are always writeable |
14 | temporaries whether the instruction is using the special | ||
15 | case "0" or a normal register as input. | ||
16 | |||
15 | Cc: qemu-stable@nongnu.org | 17 | Cc: qemu-stable@nongnu.org |
16 | Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com> | 18 | Fixes: 0b188ea05acb5 ("target/arm: Use tcg_constant in trans_CSEL") |
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 20 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 21 | Message-id: 20230727103906.2641264-1-peter.maydell@linaro.org |
19 | --- | 22 | --- |
20 | target/arm/arm-powerctl.c | 3 +++ | 23 | target/arm/tcg/translate.c | 15 ++++++++------- |
21 | 1 file changed, 3 insertions(+) | 24 | 1 file changed, 8 insertions(+), 7 deletions(-) |
22 | 25 | ||
23 | diff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c | 26 | diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c |
24 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/target/arm/arm-powerctl.c | 28 | --- a/target/arm/tcg/translate.c |
26 | +++ b/target/arm/arm-powerctl.c | 29 | +++ b/target/arm/tcg/translate.c |
27 | @@ -XXX,XX +XXX,XX @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, | 30 | @@ -XXX,XX +XXX,XX @@ static bool trans_IT(DisasContext *s, arg_IT *a) |
28 | target_cpu->env.regs[0] = info->context_id; | 31 | /* v8.1M CSEL/CSINC/CSNEG/CSINV */ |
32 | static bool trans_CSEL(DisasContext *s, arg_CSEL *a) | ||
33 | { | ||
34 | - TCGv_i32 rn, rm, zero; | ||
35 | + TCGv_i32 rn, rm; | ||
36 | DisasCompare c; | ||
37 | |||
38 | if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) { | ||
39 | @@ -XXX,XX +XXX,XX @@ static bool trans_CSEL(DisasContext *s, arg_CSEL *a) | ||
29 | } | 40 | } |
30 | 41 | ||
31 | + /* CP15 update requires rebuilding hflags */ | 42 | /* In this insn input reg fields of 0b1111 mean "zero", not "PC" */ |
32 | + arm_rebuild_hflags(&target_cpu->env); | 43 | - zero = tcg_constant_i32(0); |
33 | + | 44 | + rn = tcg_temp_new_i32(); |
34 | /* Start the new CPU at the requested address */ | 45 | + rm = tcg_temp_new_i32(); |
35 | cpu_set_pc(target_cpu_state, info->entry); | 46 | if (a->rn == 15) { |
36 | 47 | - rn = zero; | |
48 | + tcg_gen_movi_i32(rn, 0); | ||
49 | } else { | ||
50 | - rn = load_reg(s, a->rn); | ||
51 | + load_reg_var(s, rn, a->rn); | ||
52 | } | ||
53 | if (a->rm == 15) { | ||
54 | - rm = zero; | ||
55 | + tcg_gen_movi_i32(rm, 0); | ||
56 | } else { | ||
57 | - rm = load_reg(s, a->rm); | ||
58 | + load_reg_var(s, rm, a->rm); | ||
59 | } | ||
60 | |||
61 | switch (a->op) { | ||
62 | @@ -XXX,XX +XXX,XX @@ static bool trans_CSEL(DisasContext *s, arg_CSEL *a) | ||
63 | } | ||
64 | |||
65 | arm_test_cc(&c, a->fcond); | ||
66 | - tcg_gen_movcond_i32(c.cond, rn, c.value, zero, rn, rm); | ||
67 | + tcg_gen_movcond_i32(c.cond, rn, c.value, tcg_constant_i32(0), rn, rm); | ||
68 | |||
69 | store_reg(s, a->rd, rn); | ||
70 | return true; | ||
37 | -- | 71 | -- |
38 | 2.20.1 | 72 | 2.34.1 |
39 | |||
40 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | Currently we list all the Arm decodetree files together and add them |
---|---|---|---|
2 | unconditionally to arm_ss. This means we build them for both | ||
3 | qemu-system-aarch64 and qemu-system-arm. However, some of them are | ||
4 | AArch64-specific, so there is no need to build them for | ||
5 | qemu-system-arm. (Meson is smart enough to notice that the generated | ||
6 | .c.inc file is not used by any objects that go into qemu-system-arm, | ||
7 | so we only unnecessarily run decodetree, not anything more | ||
8 | heavyweight like a recompile or relink, but it's still unnecessary | ||
9 | work.) | ||
2 | 10 | ||
3 | Instead of crashing in a confuse way, give some hint to the user | 11 | Split gen into gen_a32 and gen_a64, and only add gen_a64 for |
4 | about why we aborted. He might report the issue without having | 12 | TARGET_AARCH64 compiles. |
5 | to use a debugger. | ||
6 | 13 | ||
7 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Message-id: 20191209134552.27733-1-philmd@redhat.com | ||
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Tested-by: Niek Linnenbank <nieklinnenbank@gmail.com> | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
16 | Message-id: 20230718104628.1137734-1-peter.maydell@linaro.org | ||
12 | --- | 17 | --- |
13 | target/arm/helper.c | 18 +++++++++++++++--- | 18 | target/arm/tcg/meson.build | 10 +++++++--- |
14 | 1 file changed, 15 insertions(+), 3 deletions(-) | 19 | 1 file changed, 7 insertions(+), 3 deletions(-) |
15 | 20 | ||
16 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 21 | diff --git a/target/arm/tcg/meson.build b/target/arm/tcg/meson.build |
17 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/helper.c | 23 | --- a/target/arm/tcg/meson.build |
19 | +++ b/target/arm/helper.c | 24 | +++ b/target/arm/tcg/meson.build |
20 | @@ -XXX,XX +XXX,XX @@ void HELPER(rebuild_hflags_a64)(CPUARMState *env, int el) | 25 | @@ -XXX,XX +XXX,XX @@ |
21 | env->hflags = rebuild_hflags_a64(env, el, fp_el, mmu_idx); | 26 | -gen = [ |
22 | } | 27 | +gen_a64 = [ |
23 | 28 | + decodetree.process('a64.decode', extra_args: ['--static-decode=disas_a64']), | |
24 | +static inline void assert_hflags_rebuild_correctly(CPUARMState *env) | 29 | decodetree.process('sve.decode', extra_args: '--decode=disas_sve'), |
25 | +{ | 30 | decodetree.process('sme.decode', extra_args: '--decode=disas_sme'), |
26 | +#ifdef CONFIG_DEBUG_TCG | 31 | decodetree.process('sme-fa64.decode', extra_args: '--static-decode=disas_sme_fa64'), |
27 | + uint32_t env_flags_current = env->hflags; | 32 | +] |
28 | + uint32_t env_flags_rebuilt = rebuild_hflags_internal(env); | ||
29 | + | 33 | + |
30 | + if (unlikely(env_flags_current != env_flags_rebuilt)) { | 34 | +gen_a32 = [ |
31 | + fprintf(stderr, "TCG hflags mismatch (current:0x%08x rebuilt:0x%08x)\n", | 35 | decodetree.process('neon-shared.decode', extra_args: '--decode=disas_neon_shared'), |
32 | + env_flags_current, env_flags_rebuilt); | 36 | decodetree.process('neon-dp.decode', extra_args: '--decode=disas_neon_dp'), |
33 | + abort(); | 37 | decodetree.process('neon-ls.decode', extra_args: '--decode=disas_neon_ls'), |
34 | + } | 38 | @@ -XXX,XX +XXX,XX @@ gen = [ |
35 | +#endif | 39 | decodetree.process('a32-uncond.decode', extra_args: '--static-decode=disas_a32_uncond'), |
36 | +} | 40 | decodetree.process('t32.decode', extra_args: '--static-decode=disas_t32'), |
37 | + | 41 | decodetree.process('t16.decode', extra_args: ['-w', '16', '--static-decode=disas_t16']), |
38 | void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | 42 | - decodetree.process('a64.decode', extra_args: ['--static-decode=disas_a64']), |
39 | target_ulong *cs_base, uint32_t *pflags) | 43 | ] |
40 | { | 44 | |
41 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | 45 | -arm_ss.add(gen) |
42 | uint32_t pstate_for_ss; | 46 | +arm_ss.add(gen_a32) |
43 | 47 | +arm_ss.add(when: 'TARGET_AARCH64', if_true: gen_a64) | |
44 | *cs_base = 0; | 48 | |
45 | -#ifdef CONFIG_DEBUG_TCG | 49 | arm_ss.add(files( |
46 | - assert(flags == rebuild_hflags_internal(env)); | 50 | 'cpu32.c', |
47 | -#endif | ||
48 | + assert_hflags_rebuild_correctly(env); | ||
49 | |||
50 | if (FIELD_EX32(flags, TBFLAG_ANY, AARCH64_STATE)) { | ||
51 | *pc = env->pc; | ||
52 | -- | 51 | -- |
53 | 2.20.1 | 52 | 2.34.1 |
54 | 53 | ||
55 | 54 | diff view generated by jsdifflib |
1 | From: Simon Veith <sveith@amazon.de> | 1 | From: Gavin Shan <gshan@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | In the SMMU_STRTAB_BASE register, the stream table base address only | 3 | Runs into core dump on arm64 and the backtrace extracted from the |
4 | occupies bits [51:6]. Other bits, such as RA (bit [62]), must be masked | 4 | core dump is shown as below. It's caused by accessing uninitialized |
5 | out to obtain the base address. | 5 | @kvm_state in kvm_flush_coalesced_mmio_buffer() due to commit 176d073029 |
6 | ("hw/arm/virt: Use machine_memory_devices_init()"), where the machine's | ||
7 | memory region is added earlier than before. | ||
6 | 8 | ||
7 | The branch for 2-level stream tables correctly applies this mask by way | 9 | main |
8 | of SMMU_BASE_ADDR_MASK, but the one for linear stream tables does not. | 10 | qemu_init |
11 | configure_accelerators | ||
12 | qemu_opts_foreach | ||
13 | do_configure_accelerator | ||
14 | accel_init_machine | ||
15 | kvm_init | ||
16 | virt_kvm_type | ||
17 | virt_set_memmap | ||
18 | machine_memory_devices_init | ||
19 | memory_region_add_subregion | ||
20 | memory_region_add_subregion_common | ||
21 | memory_region_update_container_subregions | ||
22 | memory_region_transaction_begin | ||
23 | qemu_flush_coalesced_mmio_buffer | ||
24 | kvm_flush_coalesced_mmio_buffer | ||
9 | 25 | ||
10 | Apply the missing mask in that case as well so that the correct stream | 26 | Fix it by bailing early in kvm_flush_coalesced_mmio_buffer() on the |
11 | base address is used by guests which configure a linear stream table. | 27 | uninitialized @kvm_state. With this applied, no crash is observed on |
28 | arm64. | ||
12 | 29 | ||
13 | Linux guests are unaffected by this change because they choose a 2-level | 30 | Fixes: 176d073029 ("hw/arm/virt: Use machine_memory_devices_init()") |
14 | stream table layout for the QEMU SMMUv3, based on the size of its stream | 31 | Signed-off-by: Gavin Shan <gshan@redhat.com> |
15 | ID space. | 32 | Reviewed-by: David Hildenbrand <david@redhat.com> |
16 | 33 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | |
17 | ref. ARM IHI 0070C, section 6.3.23. | 34 | Message-id: 20230731125946.2038742-1-gshan@redhat.com |
18 | |||
19 | Signed-off-by: Simon Veith <sveith@amazon.de> | ||
20 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
21 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
22 | Message-id: 1576509312-13083-2-git-send-email-sveith@amazon.de | ||
23 | Cc: Eric Auger <eric.auger@redhat.com> | ||
24 | Cc: qemu-devel@nongnu.org | ||
25 | Cc: qemu-arm@nongnu.org | ||
26 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
27 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
28 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 35 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
29 | --- | 36 | --- |
30 | hw/arm/smmuv3.c | 2 +- | 37 | accel/kvm/kvm-all.c | 2 +- |
31 | 1 file changed, 1 insertion(+), 1 deletion(-) | 38 | 1 file changed, 1 insertion(+), 1 deletion(-) |
32 | 39 | ||
33 | diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c | 40 | diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c |
34 | index XXXXXXX..XXXXXXX 100644 | 41 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/hw/arm/smmuv3.c | 42 | --- a/accel/kvm/kvm-all.c |
36 | +++ b/hw/arm/smmuv3.c | 43 | +++ b/accel/kvm/kvm-all.c |
37 | @@ -XXX,XX +XXX,XX @@ static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, | 44 | @@ -XXX,XX +XXX,XX @@ void kvm_flush_coalesced_mmio_buffer(void) |
38 | } | 45 | { |
39 | addr = l2ptr + l2_ste_offset * sizeof(*ste); | 46 | KVMState *s = kvm_state; |
40 | } else { | 47 | |
41 | - addr = s->strtab_base + sid * sizeof(*ste); | 48 | - if (s->coalesced_flush_in_progress) { |
42 | + addr = (s->strtab_base & SMMU_BASE_ADDR_MASK) + sid * sizeof(*ste); | 49 | + if (!s || s->coalesced_flush_in_progress) { |
50 | return; | ||
43 | } | 51 | } |
44 | 52 | ||
45 | if (smmu_get_ste(s, addr, ste, event)) { | ||
46 | -- | 53 | -- |
47 | 2.20.1 | 54 | 2.34.1 |
48 | 55 | ||
49 | 56 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Simon Veith <sveith@amazon.de> | ||
2 | 1 | ||
3 | There are two issues with the current value of SMMU_BASE_ADDR_MASK: | ||
4 | |||
5 | - At the lower end, we are clearing bits [4:0]. Per the SMMUv3 spec, | ||
6 | we should also be treating bit 5 as zero in the base address. | ||
7 | - At the upper end, we are clearing bits [63:48]. Per the SMMUv3 spec, | ||
8 | only bits [63:52] must be explicitly treated as zero. | ||
9 | |||
10 | Update the SMMU_BASE_ADDR_MASK value to mask out bits [63:52] and [5:0]. | ||
11 | |||
12 | ref. ARM IHI 0070C, section 6.3.23. | ||
13 | |||
14 | Signed-off-by: Simon Veith <sveith@amazon.de> | ||
15 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
16 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
17 | Message-id: 1576509312-13083-3-git-send-email-sveith@amazon.de | ||
18 | Cc: Eric Auger <eric.auger@redhat.com> | ||
19 | Cc: qemu-devel@nongnu.org | ||
20 | Cc: qemu-arm@nongnu.org | ||
21 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
22 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
23 | --- | ||
24 | hw/arm/smmuv3-internal.h | 2 +- | ||
25 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
26 | |||
27 | diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/hw/arm/smmuv3-internal.h | ||
30 | +++ b/hw/arm/smmuv3-internal.h | ||
31 | @@ -XXX,XX +XXX,XX @@ REG32(GERROR_IRQ_CFG2, 0x74) | ||
32 | |||
33 | #define A_STRTAB_BASE 0x80 /* 64b */ | ||
34 | |||
35 | -#define SMMU_BASE_ADDR_MASK 0xffffffffffe0 | ||
36 | +#define SMMU_BASE_ADDR_MASK 0xfffffffffffc0 | ||
37 | |||
38 | REG32(STRTAB_BASE_CFG, 0x88) | ||
39 | FIELD(STRTAB_BASE_CFG, FMT, 16, 2) | ||
40 | -- | ||
41 | 2.20.1 | ||
42 | |||
43 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Simon Veith <sveith@amazon.de> | ||
2 | 1 | ||
3 | When checking whether a stream ID is in range of the stream table, we | ||
4 | have so far been only checking it against our implementation limit | ||
5 | (SMMU_IDR1_SIDSIZE). However, the guest can program the | ||
6 | STRTAB_BASE_CFG.LOG2SIZE field to a size that is smaller than this | ||
7 | limit. | ||
8 | |||
9 | Check the stream ID against this limit as well to match the hardware | ||
10 | behavior of raising C_BAD_STREAMID events in case the limit is exceeded. | ||
11 | Also, ensure that we do not go one entry beyond the end of the table by | ||
12 | checking that its index is strictly smaller than the table size. | ||
13 | |||
14 | ref. ARM IHI 0070C, section 6.3.24. | ||
15 | |||
16 | Signed-off-by: Simon Veith <sveith@amazon.de> | ||
17 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
18 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
19 | Message-id: 1576509312-13083-4-git-send-email-sveith@amazon.de | ||
20 | Cc: Eric Auger <eric.auger@redhat.com> | ||
21 | Cc: qemu-devel@nongnu.org | ||
22 | Cc: qemu-arm@nongnu.org | ||
23 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
24 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
25 | --- | ||
26 | hw/arm/smmuv3.c | 8 ++++++-- | ||
27 | 1 file changed, 6 insertions(+), 2 deletions(-) | ||
28 | |||
29 | diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/hw/arm/smmuv3.c | ||
32 | +++ b/hw/arm/smmuv3.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, | ||
34 | SMMUEventInfo *event) | ||
35 | { | ||
36 | dma_addr_t addr; | ||
37 | + uint32_t log2size; | ||
38 | int ret; | ||
39 | |||
40 | trace_smmuv3_find_ste(sid, s->features, s->sid_split); | ||
41 | - /* Check SID range */ | ||
42 | - if (sid > (1 << SMMU_IDR1_SIDSIZE)) { | ||
43 | + log2size = FIELD_EX32(s->strtab_base_cfg, STRTAB_BASE_CFG, LOG2SIZE); | ||
44 | + /* | ||
45 | + * Check SID range against both guest-configured and implementation limits | ||
46 | + */ | ||
47 | + if (sid >= (1 << MIN(log2size, SMMU_IDR1_SIDSIZE))) { | ||
48 | event->type = SMMU_EVT_C_BAD_STREAMID; | ||
49 | return -EINVAL; | ||
50 | } | ||
51 | -- | ||
52 | 2.20.1 | ||
53 | |||
54 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Simon Veith <sveith@amazon.de> | ||
2 | 1 | ||
3 | The bit offsets in the EVT_SET_ADDR2 macro do not match those specified | ||
4 | in the ARM SMMUv3 Architecture Specification. In all events that use | ||
5 | this macro, e.g. F_WALK_EABT, the faulting fetch address or IPA actually | ||
6 | occupies the 32-bit words 6 and 7 in the event record contiguously, with | ||
7 | the upper and lower unused bits clear due to alignment or maximum | ||
8 | supported address bits. How many bits are clear depends on the | ||
9 | individual event type. | ||
10 | |||
11 | Update the macro to write to the correct words in the event record so | ||
12 | that guest drivers can obtain accurate address information on events. | ||
13 | |||
14 | ref. ARM IHI 0070C, sections 7.3.12 through 7.3.16. | ||
15 | |||
16 | Signed-off-by: Simon Veith <sveith@amazon.de> | ||
17 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
18 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
19 | Message-id: 1576509312-13083-6-git-send-email-sveith@amazon.de | ||
20 | Cc: Eric Auger <eric.auger@redhat.com> | ||
21 | Cc: qemu-devel@nongnu.org | ||
22 | Cc: qemu-arm@nongnu.org | ||
23 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
24 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
26 | --- | ||
27 | hw/arm/smmuv3-internal.h | 4 ++-- | ||
28 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
29 | |||
30 | diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/hw/arm/smmuv3-internal.h | ||
33 | +++ b/hw/arm/smmuv3-internal.h | ||
34 | @@ -XXX,XX +XXX,XX @@ typedef struct SMMUEventInfo { | ||
35 | } while (0) | ||
36 | #define EVT_SET_ADDR2(x, addr) \ | ||
37 | do { \ | ||
38 | - (x)->word[7] = deposit32((x)->word[7], 3, 29, addr >> 16); \ | ||
39 | - (x)->word[7] = deposit32((x)->word[7], 0, 16, addr & 0xffff);\ | ||
40 | + (x)->word[7] = (uint32_t)(addr >> 32); \ | ||
41 | + (x)->word[6] = (uint32_t)(addr & 0xffffffff); \ | ||
42 | } while (0) | ||
43 | |||
44 | void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *event); | ||
45 | -- | ||
46 | 2.20.1 | ||
47 | |||
48 | diff view generated by jsdifflib |
1 | From: Simon Veith <sveith@amazon.de> | 1 | From: Nicholas Piggin <npiggin@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | The smmuv3_record_event() function that generates the F_STE_FETCH error | 3 | The gdb remote protocol has a special interrupt character (0x03) that is |
4 | uses the EVT_SET_ADDR macro to record the fetch address, placing it in | 4 | transmitted outside the regular packet processing, and represents a |
5 | 32-bit words 4 and 5. | 5 | Ctrl-C pressed in the client. Despite not being a regular packet, it |
6 | does expect a regular stop response if the stub successfully stops the | ||
7 | running program. | ||
6 | 8 | ||
7 | The correct position for this address is in words 6 and 7, per the | 9 | See: https://sourceware.org/gdb/onlinedocs/gdb/Interrupts.html |
8 | SMMUv3 Architecture Specification. | ||
9 | 10 | ||
10 | Update the function to use the EVT_SET_ADDR2 macro instead, which is the | 11 | Inhibiting the stop reply packet can lead to gdb client hang. So permit |
11 | macro intended for writing to these words. | 12 | a stop response when receiving a character from gdb that stops the vm. |
13 | Additionally, add a warning if that was not a 0x03 character, because | ||
14 | the gdb session is likely to end up getting confused if this happens. | ||
12 | 15 | ||
13 | ref. ARM IHI 0070C, section 7.3.4. | 16 | Cc: qemu-stable@nongnu.org |
14 | 17 | Fixes: 758370052fb ("gdbstub: only send stop-reply packets when allowed to") | |
15 | Signed-off-by: Simon Veith <sveith@amazon.de> | 18 | Reported-by: Frederic Barrat <fbarrat@linux.ibm.com> |
16 | Acked-by: Eric Auger <eric.auger@redhat.com> | 19 | Signed-off-by: Nicholas Piggin <npiggin@gmail.com> |
17 | Tested-by: Eric Auger <eric.auger@redhat.com> | 20 | Tested-by: Joel Stanley <joel@jms.id.au> |
18 | Message-id: 1576509312-13083-7-git-send-email-sveith@amazon.de | 21 | Message-id: 20230711085903.304496-1-npiggin@gmail.com |
19 | Cc: Eric Auger <eric.auger@redhat.com> | ||
20 | Cc: qemu-devel@nongnu.org | ||
21 | Cc: qemu-arm@nongnu.org | ||
22 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
23 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 22 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
24 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
25 | --- | 24 | --- |
26 | hw/arm/smmuv3.c | 2 +- | 25 | gdbstub/gdbstub.c | 13 +++++++++++-- |
27 | 1 file changed, 1 insertion(+), 1 deletion(-) | 26 | 1 file changed, 11 insertions(+), 2 deletions(-) |
28 | 27 | ||
29 | diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c | 28 | diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c |
30 | index XXXXXXX..XXXXXXX 100644 | 29 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/hw/arm/smmuv3.c | 30 | --- a/gdbstub/gdbstub.c |
32 | +++ b/hw/arm/smmuv3.c | 31 | +++ b/gdbstub/gdbstub.c |
33 | @@ -XXX,XX +XXX,XX @@ void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *info) | 32 | @@ -XXX,XX +XXX,XX @@ void gdb_read_byte(uint8_t ch) |
34 | case SMMU_EVT_F_STE_FETCH: | 33 | return; |
35 | EVT_SET_SSID(&evt, info->u.f_ste_fetch.ssid); | 34 | } |
36 | EVT_SET_SSV(&evt, info->u.f_ste_fetch.ssv); | 35 | if (runstate_is_running()) { |
37 | - EVT_SET_ADDR(&evt, info->u.f_ste_fetch.addr); | 36 | - /* when the CPU is running, we cannot do anything except stop |
38 | + EVT_SET_ADDR2(&evt, info->u.f_ste_fetch.addr); | 37 | - it when receiving a char */ |
39 | break; | 38 | + /* |
40 | case SMMU_EVT_C_BAD_STE: | 39 | + * When the CPU is running, we cannot do anything except stop |
41 | EVT_SET_SSID(&evt, info->u.c_bad_ste.ssid); | 40 | + * it when receiving a char. This is expected on a Ctrl-C in the |
41 | + * gdb client. Because we are in all-stop mode, gdb sends a | ||
42 | + * 0x03 byte which is not a usual packet, so we handle it specially | ||
43 | + * here, but it does expect a stop reply. | ||
44 | + */ | ||
45 | + if (ch != 0x03) { | ||
46 | + warn_report("gdbstub: client sent packet while target running\n"); | ||
47 | + } | ||
48 | + gdbserver_state.allow_stop_reply = true; | ||
49 | vm_stop(RUN_STATE_PAUSED); | ||
50 | } else | ||
51 | #endif | ||
42 | -- | 52 | -- |
43 | 2.20.1 | 53 | 2.34.1 |
44 | |||
45 | diff view generated by jsdifflib |