1
Hi; here's this week's arm pullreq. Mostly this is my
1
A random mix of items here, nothing very major. v2 is just
2
work on FEAT_MOPS and FEAT_HBC, but there are some
2
squashing in the fix for the clang unused-function error.
3
other bits and pieces in there too, including a recent
4
set of elf2dmp patches.
5
3
6
thanks
4
thanks
7
-- PMM
5
-- PMM
8
6
9
The following changes since commit 55394dcbec8f0c29c30e792c102a0edd50a52bf4:
10
7
11
Merge tag 'pull-loongarch-20230920' of https://gitlab.com/gaosong/qemu into staging (2023-09-20 13:56:18 -0400)
8
The following changes since commit d0dff238a87fa81393ed72754d4dc8b09e50b08b:
12
9
13
are available in the Git repository at:
10
Merge remote-tracking branch 'remotes/juanquintela/tags/migration/20170206' into staging (2017-02-07 15:29:26 +0000)
14
11
15
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20230921
12
are available in the git repository at:
16
13
17
for you to fetch changes up to 231f6a7d66254a58bedbee458591b780e0a507b1:
14
git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20170207-1
18
15
19
elf2dmp: rework PDB_STREAM_INDEXES::segments obtaining (2023-09-21 16:13:54 +0100)
16
for you to fetch changes up to aecfbbc97a2e52bbee34a53c32f961a182046a95:
17
18
stellaris: Use the 'unimplemented' device for parts we don't implement (2017-02-07 18:55:15 +0000)
20
19
21
----------------------------------------------------------------
20
----------------------------------------------------------------
22
target-arm queue:
21
target-arm:
23
* target/m68k: Add URL to semihosting spec
22
* new "unimplemented" device for stubbing out devices in a
24
* docs/devel/loads-stores: Fix git grep regexes
23
system model so accesses can be logged
25
* hw/arm/boot: Set SCR_EL3.FGTEn when booting kernel
24
* stellaris: document the SoC memory map
26
* linux-user: Correct SME feature names reported in cpuinfo
25
* arm: create instruction syndromes for AArch32 data aborts
27
* linux-user: Add missing arm32 hwcaps
26
* arm: Correctly handle watchpoints for BE32 CPUs
28
* Don't skip MTE checks for LDRT/STRT at EL0
27
* Fix Thumb-1 BE32 execution and disassembly
29
* Implement FEAT_HBC
28
* arm: Add cfgend parameter for ARM CPU selection
30
* Implement FEAT_MOPS
29
* sd: sdhci: check data length during dma_memory_read
31
* audio/jackaudio: Avoid dynamic stack allocation
30
* aspeed: add a watchdog controller
32
* sbsa-ref: add non-secure EL2 virtual timer
31
* integratorcp: adding vmstate for save/restore
33
* elf2dmp: improve Win2022, Win11 and large dumps
34
32
35
----------------------------------------------------------------
33
----------------------------------------------------------------
36
Fabian Vogt (1):
34
Cédric Le Goater (2):
37
hw/arm/boot: Set SCR_EL3.FGTEn when booting kernel
35
wdt: Add Aspeed watchdog device model
36
aspeed: add a watchdog controller
38
37
39
Marcin Juszkiewicz (1):
38
Julian Brown (4):
40
sbsa-ref: add non-secure EL2 virtual timer
39
hw/arm/integratorcp: Support specifying features via -cpu
40
target/arm: Add cfgend parameter for ARM CPU selection.
41
Fix Thumb-1 BE32 execution and disassembly.
42
arm: Correctly handle watchpoints for BE32 CPUs
41
43
42
Peter Maydell (23):
44
Pavel Dovgalyuk (1):
43
target/m68k: Add URL to semihosting spec
45
integratorcp: adding vmstate for save/restore
44
docs/devel/loads-stores: Fix git grep regexes
45
linux-user/elfload.c: Correct SME feature names reported in cpuinfo
46
linux-user/elfload.c: Add missing arm and arm64 hwcap values
47
linux-user/elfload.c: Report previously missing arm32 hwcaps
48
target/arm: Update AArch64 ID register field definitions
49
target/arm: Update user-mode ID reg mask values
50
target/arm: Implement FEAT_HBC
51
target/arm: Remove unused allocation_tag_mem() argument
52
target/arm: Don't skip MTE checks for LDRT/STRT at EL0
53
target/arm: Implement FEAT_MOPS enable bits
54
target/arm: Pass unpriv bool to get_a64_user_mem_index()
55
target/arm: Define syndrome function for MOPS exceptions
56
target/arm: New function allocation_tag_mem_probe()
57
target/arm: Implement MTE tag-checking functions for FEAT_MOPS
58
target/arm: Implement the SET* instructions
59
target/arm: Define new TB flag for ATA0
60
target/arm: Implement the SETG* instructions
61
target/arm: Implement MTE tag-checking functions for FEAT_MOPS copies
62
target/arm: Implement the CPY* instructions
63
target/arm: Enable FEAT_MOPS for CPU 'max'
64
audio/jackaudio: Avoid dynamic stack allocation in qjack_client_init
65
audio/jackaudio: Avoid dynamic stack allocation in qjack_process()
66
46
67
Viktor Prutyanov (5):
47
Peter Maydell (5):
68
elf2dmp: replace PE export name check with PDB name check
48
target/arm: Abstract out pbit/wbit tests in ARM ldr/str decode
69
elf2dmp: introduce physical block alignment
49
target/arm: A32, T32: Create Instruction Syndromes for Data Aborts
70
elf2dmp: introduce merging of physical memory runs
50
stellaris: Document memory map and which SoC devices are unimplemented
71
elf2dmp: use Linux mmap with MAP_NORESERVE when possible
51
hw/misc: New "unimplemented" sysbus device
72
elf2dmp: rework PDB_STREAM_INDEXES::segments obtaining
52
stellaris: Use the 'unimplemented' device for parts we don't implement
73
53
74
docs/devel/loads-stores.rst | 40 +-
54
Prasad J Pandit (1):
75
docs/system/arm/emulation.rst | 2 +
55
sd: sdhci: check data length during dma_memory_read
76
contrib/elf2dmp/addrspace.h | 1 +
56
77
contrib/elf2dmp/pdb.h | 2 +-
57
hw/misc/Makefile.objs | 2 +
78
contrib/elf2dmp/qemu_elf.h | 2 +
58
hw/watchdog/Makefile.objs | 1 +
79
target/arm/cpu.h | 35 ++
59
include/disas/bfd.h | 7 ++
80
target/arm/internals.h | 55 +++
60
include/hw/arm/aspeed_soc.h | 2 +
81
target/arm/syndrome.h | 12 +
61
include/hw/misc/unimp.h | 39 +++++++
82
target/arm/tcg/helper-a64.h | 14 +
62
include/hw/watchdog/wdt_aspeed.h | 32 ++++++
83
target/arm/tcg/translate.h | 4 +-
63
include/qom/cpu.h | 3 +
84
target/arm/tcg/a64.decode | 38 +-
64
target/arm/arm_ldst.h | 10 +-
85
audio/jackaudio.c | 21 +-
65
target/arm/cpu.h | 7 ++
86
contrib/elf2dmp/addrspace.c | 31 +-
66
target/arm/internals.h | 5 +
87
contrib/elf2dmp/main.c | 154 ++++----
67
target/arm/translate.h | 14 +++
88
contrib/elf2dmp/pdb.c | 15 +-
68
disas.c | 1 +
89
contrib/elf2dmp/qemu_elf.c | 68 +++-
69
exec.c | 1 +
90
hw/arm/boot.c | 4 +
70
hw/arm/aspeed_soc.c | 13 +++
91
hw/arm/sbsa-ref.c | 2 +
71
hw/arm/integratorcp.c | 78 +++++++++++++-
92
linux-user/elfload.c | 72 +++-
72
hw/arm/stellaris.c | 48 +++++++++
93
target/arm/helper.c | 39 +-
73
hw/misc/unimp.c | 107 +++++++++++++++++++
94
target/arm/tcg/cpu64.c | 5 +
74
hw/sd/sdhci.c | 2 +-
95
target/arm/tcg/helper-a64.c | 878 +++++++++++++++++++++++++++++++++++++++++
75
hw/watchdog/wdt_aspeed.c | 225 +++++++++++++++++++++++++++++++++++++++
96
target/arm/tcg/hflags.c | 21 +
76
qom/cpu.c | 6 ++
97
target/arm/tcg/mte_helper.c | 281 +++++++++++--
77
target/arm/cpu.c | 39 +++++++
98
target/arm/tcg/translate-a64.c | 164 +++++++-
78
target/arm/op_helper.c | 22 ++++
99
target/m68k/m68k-semi.c | 4 +
79
target/arm/translate-a64.c | 14 ---
100
tests/tcg/aarch64/sysregs.c | 4 +-
80
target/arm/translate.c | 193 ++++++++++++++++++++++++---------
101
27 files changed, 1768 insertions(+), 200 deletions(-)
81
24 files changed, 801 insertions(+), 70 deletions(-)
82
create mode 100644 include/hw/misc/unimp.h
83
create mode 100644 include/hw/watchdog/wdt_aspeed.h
84
create mode 100644 hw/misc/unimp.c
85
create mode 100644 hw/watchdog/wdt_aspeed.c
86
diff view generated by jsdifflib
Deleted patch
1
The spec for m68k semihosting is documented in the libgloss
2
sources. Add a comment with the URL for it, as we already
3
have for nios2 semihosting.
4
1
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
9
Message-id: 20230801154451.3505492-1-peter.maydell@linaro.org
10
---
11
target/m68k/m68k-semi.c | 4 ++++
12
1 file changed, 4 insertions(+)
13
14
diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/m68k/m68k-semi.c
17
+++ b/target/m68k/m68k-semi.c
18
@@ -XXX,XX +XXX,XX @@
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, see <http://www.gnu.org/licenses/>.
22
+ *
23
+ * The semihosting protocol implemented here is described in the
24
+ * libgloss sources:
25
+ * https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=libgloss/m68k/m68k-semi.txt;hb=HEAD
26
*/
27
28
#include "qemu/osdep.h"
29
--
30
2.34.1
31
32
diff view generated by jsdifflib
Deleted patch
1
The loads-and-stores documentation includes git grep regexes to find
2
occurrences of the various functions. Some of these regexes have
3
errors, typically failing to escape the '?', '(' and ')' when they
4
should be metacharacters (since these are POSIX basic REs). We also
5
weren't consistent about whether to have a ':' on the end of the
6
line introducing the list of regexes in each section.
7
1
8
Fix the errors.
9
10
The following shell rune will complain about any REs in the
11
file which don't have any matches in the codebase:
12
for re in $(sed -ne 's/ - ``\(\\<.*\)``/\1/p' docs/devel/loads-stores.rst); do git grep -q "$re" || echo "no matches for re $re"; done
13
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
16
Message-id: 20230904161703.3996734-1-peter.maydell@linaro.org
17
---
18
docs/devel/loads-stores.rst | 40 ++++++++++++++++++-------------------
19
1 file changed, 20 insertions(+), 20 deletions(-)
20
21
diff --git a/docs/devel/loads-stores.rst b/docs/devel/loads-stores.rst
22
index XXXXXXX..XXXXXXX 100644
23
--- a/docs/devel/loads-stores.rst
24
+++ b/docs/devel/loads-stores.rst
25
@@ -XXX,XX +XXX,XX @@ which stores ``val`` to ``ptr`` as an ``{endian}`` order value
26
of size ``sz`` bytes.
27
28
29
-Regexes for git grep
30
+Regexes for git grep:
31
- ``\<ld[us]\?[bwlq]\(_[hbl]e\)\?_p\>``
32
- ``\<st[bwlq]\(_[hbl]e\)\?_p\>``
33
- ``\<st24\(_[hbl]e\)\?_p\>``
34
- - ``\<ldn_\([hbl]e\)?_p\>``
35
- - ``\<stn_\([hbl]e\)?_p\>``
36
+ - ``\<ldn_\([hbl]e\)\?_p\>``
37
+ - ``\<stn_\([hbl]e\)\?_p\>``
38
39
``cpu_{ld,st}*_mmu``
40
~~~~~~~~~~~~~~~~~~~~
41
@@ -XXX,XX +XXX,XX @@ store: ``cpu_st{size}{end}_mmu(env, ptr, val, oi, retaddr)``
42
- ``_le`` : little endian
43
44
Regexes for git grep:
45
- - ``\<cpu_ld[bwlq](_[bl]e)\?_mmu\>``
46
- - ``\<cpu_st[bwlq](_[bl]e)\?_mmu\>``
47
+ - ``\<cpu_ld[bwlq]\(_[bl]e\)\?_mmu\>``
48
+ - ``\<cpu_st[bwlq]\(_[bl]e\)\?_mmu\>``
49
50
51
``cpu_{ld,st}*_mmuidx_ra``
52
@@ -XXX,XX +XXX,XX @@ store: ``cpu_st{size}{end}_mmuidx_ra(env, ptr, val, mmuidx, retaddr)``
53
- ``_le`` : little endian
54
55
Regexes for git grep:
56
- - ``\<cpu_ld[us]\?[bwlq](_[bl]e)\?_mmuidx_ra\>``
57
- - ``\<cpu_st[bwlq](_[bl]e)\?_mmuidx_ra\>``
58
+ - ``\<cpu_ld[us]\?[bwlq]\(_[bl]e\)\?_mmuidx_ra\>``
59
+ - ``\<cpu_st[bwlq]\(_[bl]e\)\?_mmuidx_ra\>``
60
61
``cpu_{ld,st}*_data_ra``
62
~~~~~~~~~~~~~~~~~~~~~~~~
63
@@ -XXX,XX +XXX,XX @@ store: ``cpu_st{size}{end}_data_ra(env, ptr, val, ra)``
64
- ``_le`` : little endian
65
66
Regexes for git grep:
67
- - ``\<cpu_ld[us]\?[bwlq](_[bl]e)\?_data_ra\>``
68
- - ``\<cpu_st[bwlq](_[bl]e)\?_data_ra\>``
69
+ - ``\<cpu_ld[us]\?[bwlq]\(_[bl]e\)\?_data_ra\>``
70
+ - ``\<cpu_st[bwlq]\(_[bl]e\)\?_data_ra\>``
71
72
``cpu_{ld,st}*_data``
73
~~~~~~~~~~~~~~~~~~~~~
74
@@ -XXX,XX +XXX,XX @@ store: ``cpu_st{size}{end}_data(env, ptr, val)``
75
- ``_be`` : big endian
76
- ``_le`` : little endian
77
78
-Regexes for git grep
79
- - ``\<cpu_ld[us]\?[bwlq](_[bl]e)\?_data\>``
80
- - ``\<cpu_st[bwlq](_[bl]e)\?_data\+\>``
81
+Regexes for git grep:
82
+ - ``\<cpu_ld[us]\?[bwlq]\(_[bl]e\)\?_data\>``
83
+ - ``\<cpu_st[bwlq]\(_[bl]e\)\?_data\+\>``
84
85
``cpu_ld*_code``
86
~~~~~~~~~~~~~~~~
87
@@ -XXX,XX +XXX,XX @@ swap: ``translator_ld{sign}{size}_swap(env, ptr, swap)``
88
- ``l`` : 32 bits
89
- ``q`` : 64 bits
90
91
-Regexes for git grep
92
+Regexes for git grep:
93
- ``\<translator_ld[us]\?[bwlq]\(_swap\)\?\>``
94
95
``helper_{ld,st}*_mmu``
96
@@ -XXX,XX +XXX,XX @@ store: ``helper_{size}_mmu(env, addr, val, opindex, retaddr)``
97
- ``l`` : 32 bits
98
- ``q`` : 64 bits
99
100
-Regexes for git grep
101
+Regexes for git grep:
102
- ``\<helper_ld[us]\?[bwlq]_mmu\>``
103
- ``\<helper_st[bwlq]_mmu\>``
104
105
@@ -XXX,XX +XXX,XX @@ succeeded using a MemTxResult return code.
106
107
The ``_{endian}`` suffix is omitted for byte accesses.
108
109
-Regexes for git grep
110
+Regexes for git grep:
111
- ``\<address_space_\(read\|write\|rw\)\>``
112
- ``\<address_space_ldu\?[bwql]\(_[lb]e\)\?\>``
113
- ``\<address_space_st[bwql]\(_[lb]e\)\?\>``
114
@@ -XXX,XX +XXX,XX @@ Note that portions of the write which attempt to write data to a
115
device will be silently ignored -- only real RAM and ROM will
116
be written to.
117
118
-Regexes for git grep
119
+Regexes for git grep:
120
- ``address_space_write_rom``
121
122
``{ld,st}*_phys``
123
@@ -XXX,XX +XXX,XX @@ device doing the access has no way to report such an error.
124
125
The ``_{endian}_`` infix is omitted for byte accesses.
126
127
-Regexes for git grep
128
+Regexes for git grep:
129
- ``\<ldu\?[bwlq]\(_[bl]e\)\?_phys\>``
130
- ``\<st[bwlq]\(_[bl]e\)\?_phys\>``
131
132
@@ -XXX,XX +XXX,XX @@ For new code they are better avoided:
133
134
``cpu_physical_memory_rw``
135
136
-Regexes for git grep
137
+Regexes for git grep:
138
- ``\<cpu_physical_memory_\(read\|write\|rw\)\>``
139
140
``cpu_memory_rw_debug``
141
@@ -XXX,XX +XXX,XX @@ make sure our existing code is doing things correctly.
142
143
``dma_memory_rw``
144
145
-Regexes for git grep
146
+Regexes for git grep:
147
- ``\<dma_memory_\(read\|write\|rw\)\>``
148
- ``\<ldu\?[bwlq]\(_[bl]e\)\?_dma\>``
149
- ``\<st[bwlq]\(_[bl]e\)\?_dma\>``
150
@@ -XXX,XX +XXX,XX @@ correct address space for that device.
151
152
The ``_{endian}_`` infix is omitted for byte accesses.
153
154
-Regexes for git grep
155
+Regexes for git grep:
156
- ``\<pci_dma_\(read\|write\|rw\)\>``
157
- ``\<ldu\?[bwlq]\(_[bl]e\)\?_pci_dma\>``
158
- ``\<st[bwlq]\(_[bl]e\)\?_pci_dma\>``
159
--
160
2.34.1
161
162
diff view generated by jsdifflib
Deleted patch
1
From: Fabian Vogt <fvogt@suse.de>
2
1
3
Just like d7ef5e16a17c sets SCR_EL3.HXEn for FEAT_HCX, this commit
4
handles SCR_EL3.FGTEn for FEAT_FGT:
5
6
When we direct boot a kernel on a CPU which emulates EL3, we need to
7
set up the EL3 system registers as the Linux kernel documentation
8
specifies:
9
https://www.kernel.org/doc/Documentation/arm64/booting.rst
10
11
> For CPUs with the Fine Grained Traps (FEAT_FGT) extension present:
12
> - If EL3 is present and the kernel is entered at EL2:
13
> - SCR_EL3.FGTEn (bit 27) must be initialised to 0b1.
14
15
Cc: qemu-stable@nongnu.org
16
Signed-off-by: Fabian Vogt <fvogt@suse.de>
17
Message-id: 4831384.GXAFRqVoOG@linux-e202.suse.de
18
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
19
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
---
21
hw/arm/boot.c | 4 ++++
22
1 file changed, 4 insertions(+)
23
24
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
25
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/arm/boot.c
27
+++ b/hw/arm/boot.c
28
@@ -XXX,XX +XXX,XX @@ static void do_cpu_reset(void *opaque)
29
if (cpu_isar_feature(aa64_hcx, cpu)) {
30
env->cp15.scr_el3 |= SCR_HXEN;
31
}
32
+ if (cpu_isar_feature(aa64_fgt, cpu)) {
33
+ env->cp15.scr_el3 |= SCR_FGTEN;
34
+ }
35
+
36
/* AArch64 kernels never boot in secure mode */
37
assert(!info->secure_boot);
38
/* This hook is only supported for AArch32 currently:
39
--
40
2.34.1
diff view generated by jsdifflib
Deleted patch
1
Some of the names we use for CPU features in linux-user's dummy
2
/proc/cpuinfo don't match the strings in the real kernel in
3
arch/arm64/kernel/cpuinfo.c. Specifically, the SME related
4
features have an underscore in the HWCAP_FOO define name,
5
but (like the SVE ones) they do not have an underscore in the
6
string in cpuinfo. Correct the errors.
7
1
8
Fixes: a55b9e7226708 ("linux-user: Emulate /proc/cpuinfo on aarch64 and arm")
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
---
13
linux-user/elfload.c | 14 +++++++-------
14
1 file changed, 7 insertions(+), 7 deletions(-)
15
16
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/linux-user/elfload.c
19
+++ b/linux-user/elfload.c
20
@@ -XXX,XX +XXX,XX @@ const char *elf_hwcap2_str(uint32_t bit)
21
[__builtin_ctz(ARM_HWCAP2_A64_RPRES )] = "rpres",
22
[__builtin_ctz(ARM_HWCAP2_A64_MTE3 )] = "mte3",
23
[__builtin_ctz(ARM_HWCAP2_A64_SME )] = "sme",
24
- [__builtin_ctz(ARM_HWCAP2_A64_SME_I16I64 )] = "sme_i16i64",
25
- [__builtin_ctz(ARM_HWCAP2_A64_SME_F64F64 )] = "sme_f64f64",
26
- [__builtin_ctz(ARM_HWCAP2_A64_SME_I8I32 )] = "sme_i8i32",
27
- [__builtin_ctz(ARM_HWCAP2_A64_SME_F16F32 )] = "sme_f16f32",
28
- [__builtin_ctz(ARM_HWCAP2_A64_SME_B16F32 )] = "sme_b16f32",
29
- [__builtin_ctz(ARM_HWCAP2_A64_SME_F32F32 )] = "sme_f32f32",
30
- [__builtin_ctz(ARM_HWCAP2_A64_SME_FA64 )] = "sme_fa64",
31
+ [__builtin_ctz(ARM_HWCAP2_A64_SME_I16I64 )] = "smei16i64",
32
+ [__builtin_ctz(ARM_HWCAP2_A64_SME_F64F64 )] = "smef64f64",
33
+ [__builtin_ctz(ARM_HWCAP2_A64_SME_I8I32 )] = "smei8i32",
34
+ [__builtin_ctz(ARM_HWCAP2_A64_SME_F16F32 )] = "smef16f32",
35
+ [__builtin_ctz(ARM_HWCAP2_A64_SME_B16F32 )] = "smeb16f32",
36
+ [__builtin_ctz(ARM_HWCAP2_A64_SME_F32F32 )] = "smef32f32",
37
+ [__builtin_ctz(ARM_HWCAP2_A64_SME_FA64 )] = "smefa64",
38
};
39
40
return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
41
--
42
2.34.1
43
44
diff view generated by jsdifflib
Deleted patch
1
Our lists of Arm 32 and 64 bit hwcap values have lagged behind
2
the Linux kernel. Update them to include all the bits defined
3
as of upstream Linux git commit a48fa7efaf1161c1 (in the middle
4
of the kernel 6.6 dev cycle).
5
1
6
For 64-bit, we don't yet implement any of the features reported via
7
these hwcap bits. For 32-bit we do in fact already implement them
8
all; we'll add the code to set them in a subsequent commit.
9
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
---
14
linux-user/elfload.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
15
1 file changed, 44 insertions(+)
16
17
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/linux-user/elfload.c
20
+++ b/linux-user/elfload.c
21
@@ -XXX,XX +XXX,XX @@ enum
22
ARM_HWCAP_ARM_VFPD32 = 1 << 19,
23
ARM_HWCAP_ARM_LPAE = 1 << 20,
24
ARM_HWCAP_ARM_EVTSTRM = 1 << 21,
25
+ ARM_HWCAP_ARM_FPHP = 1 << 22,
26
+ ARM_HWCAP_ARM_ASIMDHP = 1 << 23,
27
+ ARM_HWCAP_ARM_ASIMDDP = 1 << 24,
28
+ ARM_HWCAP_ARM_ASIMDFHM = 1 << 25,
29
+ ARM_HWCAP_ARM_ASIMDBF16 = 1 << 26,
30
+ ARM_HWCAP_ARM_I8MM = 1 << 27,
31
};
32
33
enum {
34
@@ -XXX,XX +XXX,XX @@ enum {
35
ARM_HWCAP2_ARM_SHA1 = 1 << 2,
36
ARM_HWCAP2_ARM_SHA2 = 1 << 3,
37
ARM_HWCAP2_ARM_CRC32 = 1 << 4,
38
+ ARM_HWCAP2_ARM_SB = 1 << 5,
39
+ ARM_HWCAP2_ARM_SSBS = 1 << 6,
40
};
41
42
/* The commpage only exists for 32 bit kernels */
43
@@ -XXX,XX +XXX,XX @@ const char *elf_hwcap_str(uint32_t bit)
44
[__builtin_ctz(ARM_HWCAP_ARM_VFPD32 )] = "vfpd32",
45
[__builtin_ctz(ARM_HWCAP_ARM_LPAE )] = "lpae",
46
[__builtin_ctz(ARM_HWCAP_ARM_EVTSTRM )] = "evtstrm",
47
+ [__builtin_ctz(ARM_HWCAP_ARM_FPHP )] = "fphp",
48
+ [__builtin_ctz(ARM_HWCAP_ARM_ASIMDHP )] = "asimdhp",
49
+ [__builtin_ctz(ARM_HWCAP_ARM_ASIMDDP )] = "asimddp",
50
+ [__builtin_ctz(ARM_HWCAP_ARM_ASIMDFHM )] = "asimdfhm",
51
+ [__builtin_ctz(ARM_HWCAP_ARM_ASIMDBF16)] = "asimdbf16",
52
+ [__builtin_ctz(ARM_HWCAP_ARM_I8MM )] = "i8mm",
53
};
54
55
return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
56
@@ -XXX,XX +XXX,XX @@ const char *elf_hwcap2_str(uint32_t bit)
57
[__builtin_ctz(ARM_HWCAP2_ARM_SHA1 )] = "sha1",
58
[__builtin_ctz(ARM_HWCAP2_ARM_SHA2 )] = "sha2",
59
[__builtin_ctz(ARM_HWCAP2_ARM_CRC32)] = "crc32",
60
+ [__builtin_ctz(ARM_HWCAP2_ARM_SB )] = "sb",
61
+ [__builtin_ctz(ARM_HWCAP2_ARM_SSBS )] = "ssbs",
62
};
63
64
return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
65
@@ -XXX,XX +XXX,XX @@ enum {
66
ARM_HWCAP2_A64_SME_B16F32 = 1 << 28,
67
ARM_HWCAP2_A64_SME_F32F32 = 1 << 29,
68
ARM_HWCAP2_A64_SME_FA64 = 1 << 30,
69
+ ARM_HWCAP2_A64_WFXT = 1ULL << 31,
70
+ ARM_HWCAP2_A64_EBF16 = 1ULL << 32,
71
+ ARM_HWCAP2_A64_SVE_EBF16 = 1ULL << 33,
72
+ ARM_HWCAP2_A64_CSSC = 1ULL << 34,
73
+ ARM_HWCAP2_A64_RPRFM = 1ULL << 35,
74
+ ARM_HWCAP2_A64_SVE2P1 = 1ULL << 36,
75
+ ARM_HWCAP2_A64_SME2 = 1ULL << 37,
76
+ ARM_HWCAP2_A64_SME2P1 = 1ULL << 38,
77
+ ARM_HWCAP2_A64_SME_I16I32 = 1ULL << 39,
78
+ ARM_HWCAP2_A64_SME_BI32I32 = 1ULL << 40,
79
+ ARM_HWCAP2_A64_SME_B16B16 = 1ULL << 41,
80
+ ARM_HWCAP2_A64_SME_F16F16 = 1ULL << 42,
81
+ ARM_HWCAP2_A64_MOPS = 1ULL << 43,
82
+ ARM_HWCAP2_A64_HBC = 1ULL << 44,
83
};
84
85
#define ELF_HWCAP get_elf_hwcap()
86
@@ -XXX,XX +XXX,XX @@ const char *elf_hwcap2_str(uint32_t bit)
87
[__builtin_ctz(ARM_HWCAP2_A64_SME_B16F32 )] = "smeb16f32",
88
[__builtin_ctz(ARM_HWCAP2_A64_SME_F32F32 )] = "smef32f32",
89
[__builtin_ctz(ARM_HWCAP2_A64_SME_FA64 )] = "smefa64",
90
+ [__builtin_ctz(ARM_HWCAP2_A64_WFXT )] = "wfxt",
91
+ [__builtin_ctzll(ARM_HWCAP2_A64_EBF16 )] = "ebf16",
92
+ [__builtin_ctzll(ARM_HWCAP2_A64_SVE_EBF16 )] = "sveebf16",
93
+ [__builtin_ctzll(ARM_HWCAP2_A64_CSSC )] = "cssc",
94
+ [__builtin_ctzll(ARM_HWCAP2_A64_RPRFM )] = "rprfm",
95
+ [__builtin_ctzll(ARM_HWCAP2_A64_SVE2P1 )] = "sve2p1",
96
+ [__builtin_ctzll(ARM_HWCAP2_A64_SME2 )] = "sme2",
97
+ [__builtin_ctzll(ARM_HWCAP2_A64_SME2P1 )] = "sme2p1",
98
+ [__builtin_ctzll(ARM_HWCAP2_A64_SME_I16I32 )] = "smei16i32",
99
+ [__builtin_ctzll(ARM_HWCAP2_A64_SME_BI32I32)] = "smebi32i32",
100
+ [__builtin_ctzll(ARM_HWCAP2_A64_SME_B16B16 )] = "smeb16b16",
101
+ [__builtin_ctzll(ARM_HWCAP2_A64_SME_F16F16 )] = "smef16f16",
102
+ [__builtin_ctzll(ARM_HWCAP2_A64_MOPS )] = "mops",
103
+ [__builtin_ctzll(ARM_HWCAP2_A64_HBC )] = "hbc",
104
};
105
106
return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
107
--
108
2.34.1
109
110
diff view generated by jsdifflib
Deleted patch
1
Add the code to report the arm32 hwcaps we were previously missing:
2
ss, ssbs, fphp, asimdhp, asimddp, asimdfhm, asimdbf16, i8mm
3
1
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
---
7
linux-user/elfload.c | 12 ++++++++++++
8
1 file changed, 12 insertions(+)
9
10
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
11
index XXXXXXX..XXXXXXX 100644
12
--- a/linux-user/elfload.c
13
+++ b/linux-user/elfload.c
14
@@ -XXX,XX +XXX,XX @@ uint32_t get_elf_hwcap(void)
15
}
16
}
17
GET_FEATURE_ID(aa32_simdfmac, ARM_HWCAP_ARM_VFPv4);
18
+ /*
19
+ * MVFR1.FPHP and .SIMDHP must be in sync, and QEMU uses the same
20
+ * isar_feature function for both. The kernel reports them as two hwcaps.
21
+ */
22
+ GET_FEATURE_ID(aa32_fp16_arith, ARM_HWCAP_ARM_FPHP);
23
+ GET_FEATURE_ID(aa32_fp16_arith, ARM_HWCAP_ARM_ASIMDHP);
24
+ GET_FEATURE_ID(aa32_dp, ARM_HWCAP_ARM_ASIMDDP);
25
+ GET_FEATURE_ID(aa32_fhm, ARM_HWCAP_ARM_ASIMDFHM);
26
+ GET_FEATURE_ID(aa32_bf16, ARM_HWCAP_ARM_ASIMDBF16);
27
+ GET_FEATURE_ID(aa32_i8mm, ARM_HWCAP_ARM_I8MM);
28
29
return hwcaps;
30
}
31
@@ -XXX,XX +XXX,XX @@ uint32_t get_elf_hwcap2(void)
32
GET_FEATURE_ID(aa32_sha1, ARM_HWCAP2_ARM_SHA1);
33
GET_FEATURE_ID(aa32_sha2, ARM_HWCAP2_ARM_SHA2);
34
GET_FEATURE_ID(aa32_crc32, ARM_HWCAP2_ARM_CRC32);
35
+ GET_FEATURE_ID(aa32_sb, ARM_HWCAP2_ARM_SB);
36
+ GET_FEATURE_ID(aa32_ssbs, ARM_HWCAP2_ARM_SSBS);
37
return hwcaps;
38
}
39
40
--
41
2.34.1
diff view generated by jsdifflib
Deleted patch
1
Update our AArch64 ID register field definitions from the 2023-06
2
system register XML release:
3
https://developer.arm.com/documentation/ddi0601/2023-06/
4
1
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
---
8
target/arm/cpu.h | 23 +++++++++++++++++++++++
9
1 file changed, 23 insertions(+)
10
11
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
12
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/cpu.h
14
+++ b/target/arm/cpu.h
15
@@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64ISAR0, SHA1, 8, 4)
16
FIELD(ID_AA64ISAR0, SHA2, 12, 4)
17
FIELD(ID_AA64ISAR0, CRC32, 16, 4)
18
FIELD(ID_AA64ISAR0, ATOMIC, 20, 4)
19
+FIELD(ID_AA64ISAR0, TME, 24, 4)
20
FIELD(ID_AA64ISAR0, RDM, 28, 4)
21
FIELD(ID_AA64ISAR0, SHA3, 32, 4)
22
FIELD(ID_AA64ISAR0, SM3, 36, 4)
23
@@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64ISAR2, APA3, 12, 4)
24
FIELD(ID_AA64ISAR2, MOPS, 16, 4)
25
FIELD(ID_AA64ISAR2, BC, 20, 4)
26
FIELD(ID_AA64ISAR2, PAC_FRAC, 24, 4)
27
+FIELD(ID_AA64ISAR2, CLRBHB, 28, 4)
28
+FIELD(ID_AA64ISAR2, SYSREG_128, 32, 4)
29
+FIELD(ID_AA64ISAR2, SYSINSTR_128, 36, 4)
30
+FIELD(ID_AA64ISAR2, PRFMSLC, 40, 4)
31
+FIELD(ID_AA64ISAR2, RPRFM, 48, 4)
32
+FIELD(ID_AA64ISAR2, CSSC, 52, 4)
33
+FIELD(ID_AA64ISAR2, ATS1A, 60, 4)
34
35
FIELD(ID_AA64PFR0, EL0, 0, 4)
36
FIELD(ID_AA64PFR0, EL1, 4, 4)
37
@@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64PFR1, SME, 24, 4)
38
FIELD(ID_AA64PFR1, RNDR_TRAP, 28, 4)
39
FIELD(ID_AA64PFR1, CSV2_FRAC, 32, 4)
40
FIELD(ID_AA64PFR1, NMI, 36, 4)
41
+FIELD(ID_AA64PFR1, MTE_FRAC, 40, 4)
42
+FIELD(ID_AA64PFR1, GCS, 44, 4)
43
+FIELD(ID_AA64PFR1, THE, 48, 4)
44
+FIELD(ID_AA64PFR1, MTEX, 52, 4)
45
+FIELD(ID_AA64PFR1, DF2, 56, 4)
46
+FIELD(ID_AA64PFR1, PFAR, 60, 4)
47
48
FIELD(ID_AA64MMFR0, PARANGE, 0, 4)
49
FIELD(ID_AA64MMFR0, ASIDBITS, 4, 4)
50
@@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64MMFR1, AFP, 44, 4)
51
FIELD(ID_AA64MMFR1, NTLBPA, 48, 4)
52
FIELD(ID_AA64MMFR1, TIDCP1, 52, 4)
53
FIELD(ID_AA64MMFR1, CMOW, 56, 4)
54
+FIELD(ID_AA64MMFR1, ECBHB, 60, 4)
55
56
FIELD(ID_AA64MMFR2, CNP, 0, 4)
57
FIELD(ID_AA64MMFR2, UAO, 4, 4)
58
@@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64DFR0, DEBUGVER, 0, 4)
59
FIELD(ID_AA64DFR0, TRACEVER, 4, 4)
60
FIELD(ID_AA64DFR0, PMUVER, 8, 4)
61
FIELD(ID_AA64DFR0, BRPS, 12, 4)
62
+FIELD(ID_AA64DFR0, PMSS, 16, 4)
63
FIELD(ID_AA64DFR0, WRPS, 20, 4)
64
+FIELD(ID_AA64DFR0, SEBEP, 24, 4)
65
FIELD(ID_AA64DFR0, CTX_CMPS, 28, 4)
66
FIELD(ID_AA64DFR0, PMSVER, 32, 4)
67
FIELD(ID_AA64DFR0, DOUBLELOCK, 36, 4)
68
@@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64DFR0, TRACEFILT, 40, 4)
69
FIELD(ID_AA64DFR0, TRACEBUFFER, 44, 4)
70
FIELD(ID_AA64DFR0, MTPMU, 48, 4)
71
FIELD(ID_AA64DFR0, BRBE, 52, 4)
72
+FIELD(ID_AA64DFR0, EXTTRCBUFF, 56, 4)
73
FIELD(ID_AA64DFR0, HPMN0, 60, 4)
74
75
FIELD(ID_AA64ZFR0, SVEVER, 0, 4)
76
FIELD(ID_AA64ZFR0, AES, 4, 4)
77
FIELD(ID_AA64ZFR0, BITPERM, 16, 4)
78
FIELD(ID_AA64ZFR0, BFLOAT16, 20, 4)
79
+FIELD(ID_AA64ZFR0, B16B16, 24, 4)
80
FIELD(ID_AA64ZFR0, SHA3, 32, 4)
81
FIELD(ID_AA64ZFR0, SM4, 40, 4)
82
FIELD(ID_AA64ZFR0, I8MM, 44, 4)
83
@@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64ZFR0, F32MM, 52, 4)
84
FIELD(ID_AA64ZFR0, F64MM, 56, 4)
85
86
FIELD(ID_AA64SMFR0, F32F32, 32, 1)
87
+FIELD(ID_AA64SMFR0, BI32I32, 33, 1)
88
FIELD(ID_AA64SMFR0, B16F32, 34, 1)
89
FIELD(ID_AA64SMFR0, F16F32, 35, 1)
90
FIELD(ID_AA64SMFR0, I8I32, 36, 4)
91
+FIELD(ID_AA64SMFR0, F16F16, 42, 1)
92
+FIELD(ID_AA64SMFR0, B16B16, 43, 1)
93
+FIELD(ID_AA64SMFR0, I16I32, 44, 4)
94
FIELD(ID_AA64SMFR0, F64F64, 48, 1)
95
FIELD(ID_AA64SMFR0, I16I64, 52, 4)
96
FIELD(ID_AA64SMFR0, SMEVER, 56, 4)
97
--
98
2.34.1
diff view generated by jsdifflib
Deleted patch
1
For user-only mode we reveal a subset of the AArch64 ID registers
2
to the guest, to emulate the kernel's trap-and-emulate-ID-regs
3
handling. Update the feature bit masks to match upstream kernel
4
commit a48fa7efaf1161c1c.
5
1
6
None of these features are yet implemented by QEMU, so this
7
doesn't yet have a behavioural change, but implementation of
8
FEAT_MOPS and FEAT_HBC is imminent.
9
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
---
13
target/arm/helper.c | 11 ++++++++++-
14
tests/tcg/aarch64/sysregs.c | 4 ++--
15
2 files changed, 12 insertions(+), 3 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 @@ void register_cp_regs_for_features(ARMCPU *cpu)
22
R_ID_AA64ZFR0_F64MM_MASK },
23
{ .name = "ID_AA64SMFR0_EL1",
24
.exported_bits = R_ID_AA64SMFR0_F32F32_MASK |
25
+ R_ID_AA64SMFR0_BI32I32_MASK |
26
R_ID_AA64SMFR0_B16F32_MASK |
27
R_ID_AA64SMFR0_F16F32_MASK |
28
R_ID_AA64SMFR0_I8I32_MASK |
29
+ R_ID_AA64SMFR0_F16F16_MASK |
30
+ R_ID_AA64SMFR0_B16B16_MASK |
31
+ R_ID_AA64SMFR0_I16I32_MASK |
32
R_ID_AA64SMFR0_F64F64_MASK |
33
R_ID_AA64SMFR0_I16I64_MASK |
34
+ R_ID_AA64SMFR0_SMEVER_MASK |
35
R_ID_AA64SMFR0_FA64_MASK },
36
{ .name = "ID_AA64MMFR0_EL1",
37
.exported_bits = R_ID_AA64MMFR0_ECV_MASK,
38
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
39
.exported_bits = R_ID_AA64ISAR2_WFXT_MASK |
40
R_ID_AA64ISAR2_RPRES_MASK |
41
R_ID_AA64ISAR2_GPA3_MASK |
42
- R_ID_AA64ISAR2_APA3_MASK },
43
+ R_ID_AA64ISAR2_APA3_MASK |
44
+ R_ID_AA64ISAR2_MOPS_MASK |
45
+ R_ID_AA64ISAR2_BC_MASK |
46
+ R_ID_AA64ISAR2_RPRFM_MASK |
47
+ R_ID_AA64ISAR2_CSSC_MASK },
48
{ .name = "ID_AA64ISAR*_EL1_RESERVED",
49
.is_glob = true },
50
};
51
diff --git a/tests/tcg/aarch64/sysregs.c b/tests/tcg/aarch64/sysregs.c
52
index XXXXXXX..XXXXXXX 100644
53
--- a/tests/tcg/aarch64/sysregs.c
54
+++ b/tests/tcg/aarch64/sysregs.c
55
@@ -XXX,XX +XXX,XX @@ int main(void)
56
*/
57
get_cpu_reg_check_mask(id_aa64isar0_el1, _m(f0ff,ffff,f0ff,fff0));
58
get_cpu_reg_check_mask(id_aa64isar1_el1, _m(00ff,f0ff,ffff,ffff));
59
- get_cpu_reg_check_mask(SYS_ID_AA64ISAR2_EL1, _m(0000,0000,0000,ffff));
60
+ get_cpu_reg_check_mask(SYS_ID_AA64ISAR2_EL1, _m(00ff,0000,00ff,ffff));
61
/* TGran4 & TGran64 as pegged to -1 */
62
get_cpu_reg_check_mask(id_aa64mmfr0_el1, _m(f000,0000,ff00,0000));
63
get_cpu_reg_check_mask(id_aa64mmfr1_el1, _m(0000,f000,0000,0000));
64
@@ -XXX,XX +XXX,XX @@ int main(void)
65
get_cpu_reg_check_mask(id_aa64dfr0_el1, _m(0000,0000,0000,0006));
66
get_cpu_reg_check_zero(id_aa64dfr1_el1);
67
get_cpu_reg_check_mask(SYS_ID_AA64ZFR0_EL1, _m(0ff0,ff0f,00ff,00ff));
68
- get_cpu_reg_check_mask(SYS_ID_AA64SMFR0_EL1, _m(80f1,00fd,0000,0000));
69
+ get_cpu_reg_check_mask(SYS_ID_AA64SMFR0_EL1, _m(8ff1,fcff,0000,0000));
70
71
get_cpu_reg_check_zero(id_aa64afr0_el1);
72
get_cpu_reg_check_zero(id_aa64afr1_el1);
73
--
74
2.34.1
diff view generated by jsdifflib
Deleted patch
1
FEAT_HBC (Hinted conditional branches) provides a new instruction
2
BC.cond, which behaves exactly like the existing B.cond except
3
that it provides a hint to the branch predictor about the
4
likely behaviour of the branch.
5
1
6
Since QEMU does not implement branch prediction, we can treat
7
this identically to B.cond.
8
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
---
13
docs/system/arm/emulation.rst | 1 +
14
target/arm/cpu.h | 5 +++++
15
target/arm/tcg/a64.decode | 3 ++-
16
linux-user/elfload.c | 1 +
17
target/arm/tcg/cpu64.c | 4 ++++
18
target/arm/tcg/translate-a64.c | 4 ++++
19
6 files changed, 17 insertions(+), 1 deletion(-)
20
21
diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst
22
index XXXXXXX..XXXXXXX 100644
23
--- a/docs/system/arm/emulation.rst
24
+++ b/docs/system/arm/emulation.rst
25
@@ -XXX,XX +XXX,XX @@ the following architecture extensions:
26
- FEAT_FlagM2 (Enhancements to flag manipulation instructions)
27
- FEAT_GTG (Guest translation granule size)
28
- FEAT_HAFDBS (Hardware management of the access flag and dirty bit state)
29
+- FEAT_HBC (Hinted conditional branches)
30
- FEAT_HCX (Support for the HCRX_EL2 register)
31
- FEAT_HPDS (Hierarchical permission disables)
32
- FEAT_HPDS2 (Translation table page-based hardware attributes)
33
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
34
index XXXXXXX..XXXXXXX 100644
35
--- a/target/arm/cpu.h
36
+++ b/target/arm/cpu.h
37
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_i8mm(const ARMISARegisters *id)
38
return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, I8MM) != 0;
39
}
40
41
+static inline bool isar_feature_aa64_hbc(const ARMISARegisters *id)
42
+{
43
+ return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, BC) != 0;
44
+}
45
+
46
static inline bool isar_feature_aa64_tgran4_lpa2(const ARMISARegisters *id)
47
{
48
return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 1;
49
diff --git a/target/arm/tcg/a64.decode b/target/arm/tcg/a64.decode
50
index XXXXXXX..XXXXXXX 100644
51
--- a/target/arm/tcg/a64.decode
52
+++ b/target/arm/tcg/a64.decode
53
@@ -XXX,XX +XXX,XX @@ CBZ sf:1 011010 nz:1 ................... rt:5 &cbz imm=%imm19
54
55
TBZ . 011011 nz:1 ..... .............. rt:5 &tbz imm=%imm14 bitpos=%imm31_19
56
57
-B_cond 0101010 0 ................... 0 cond:4 imm=%imm19
58
+# B.cond and BC.cond
59
+B_cond 0101010 0 ................... c:1 cond:4 imm=%imm19
60
61
BR 1101011 0000 11111 000000 rn:5 00000 &r
62
BLR 1101011 0001 11111 000000 rn:5 00000 &r
63
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
64
index XXXXXXX..XXXXXXX 100644
65
--- a/linux-user/elfload.c
66
+++ b/linux-user/elfload.c
67
@@ -XXX,XX +XXX,XX @@ uint32_t get_elf_hwcap2(void)
68
GET_FEATURE_ID(aa64_sme_f64f64, ARM_HWCAP2_A64_SME_F64F64);
69
GET_FEATURE_ID(aa64_sme_i16i64, ARM_HWCAP2_A64_SME_I16I64);
70
GET_FEATURE_ID(aa64_sme_fa64, ARM_HWCAP2_A64_SME_FA64);
71
+ GET_FEATURE_ID(aa64_hbc, ARM_HWCAP2_A64_HBC);
72
73
return hwcaps;
74
}
75
diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c
76
index XXXXXXX..XXXXXXX 100644
77
--- a/target/arm/tcg/cpu64.c
78
+++ b/target/arm/tcg/cpu64.c
79
@@ -XXX,XX +XXX,XX @@ void aarch64_max_tcg_initfn(Object *obj)
80
t = FIELD_DP64(t, ID_AA64ISAR1, I8MM, 1); /* FEAT_I8MM */
81
cpu->isar.id_aa64isar1 = t;
82
83
+ t = cpu->isar.id_aa64isar2;
84
+ t = FIELD_DP64(t, ID_AA64ISAR2, BC, 1); /* FEAT_HBC */
85
+ cpu->isar.id_aa64isar2 = t;
86
+
87
t = cpu->isar.id_aa64pfr0;
88
t = FIELD_DP64(t, ID_AA64PFR0, FP, 1); /* FEAT_FP16 */
89
t = FIELD_DP64(t, ID_AA64PFR0, ADVSIMD, 1); /* FEAT_FP16 */
90
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
91
index XXXXXXX..XXXXXXX 100644
92
--- a/target/arm/tcg/translate-a64.c
93
+++ b/target/arm/tcg/translate-a64.c
94
@@ -XXX,XX +XXX,XX @@ static bool trans_TBZ(DisasContext *s, arg_tbz *a)
95
96
static bool trans_B_cond(DisasContext *s, arg_B_cond *a)
97
{
98
+ /* BC.cond is only present with FEAT_HBC */
99
+ if (a->c && !dc_isar_feature(aa64_hbc, s)) {
100
+ return false;
101
+ }
102
reset_btype(s);
103
if (a->cond < 0x0e) {
104
/* genuinely conditional branches */
105
--
106
2.34.1
107
108
diff view generated by jsdifflib
Deleted patch
1
The allocation_tag_mem() function takes an argument tag_size,
2
but it never uses it. Remove the argument. In mte_probe_int()
3
in particular this also lets us delete the code computing
4
the value we were passing in.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
9
---
10
target/arm/tcg/mte_helper.c | 42 +++++++++++++------------------------
11
1 file changed, 14 insertions(+), 28 deletions(-)
12
13
diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/tcg/mte_helper.c
16
+++ b/target/arm/tcg/mte_helper.c
17
@@ -XXX,XX +XXX,XX @@ static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude)
18
* @ptr_access: the access to use for the virtual address
19
* @ptr_size: the number of bytes in the normal memory access
20
* @tag_access: the access to use for the tag memory
21
- * @tag_size: the number of bytes in the tag memory access
22
* @ra: the return address for exception handling
23
*
24
* Our tag memory is formatted as a sequence of little-endian nibbles.
25
@@ -XXX,XX +XXX,XX @@ static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude)
26
* a pointer to the corresponding tag byte. Exit with exception if the
27
* virtual address is not accessible for @ptr_access.
28
*
29
- * The @ptr_size and @tag_size values may not have an obvious relation
30
- * due to the alignment of @ptr, and the number of tag checks required.
31
- *
32
* If there is no tag storage corresponding to @ptr, return NULL.
33
*/
34
static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx,
35
uint64_t ptr, MMUAccessType ptr_access,
36
int ptr_size, MMUAccessType tag_access,
37
- int tag_size, uintptr_t ra)
38
+ uintptr_t ra)
39
{
40
#ifdef CONFIG_USER_ONLY
41
uint64_t clean_ptr = useronly_clean_ptr(ptr);
42
@@ -XXX,XX +XXX,XX @@ uint64_t HELPER(ldg)(CPUARMState *env, uint64_t ptr, uint64_t xt)
43
44
/* Trap if accessing an invalid page. */
45
mem = allocation_tag_mem(env, mmu_idx, ptr, MMU_DATA_LOAD, 1,
46
- MMU_DATA_LOAD, 1, GETPC());
47
+ MMU_DATA_LOAD, GETPC());
48
49
/* Load if page supports tags. */
50
if (mem) {
51
@@ -XXX,XX +XXX,XX @@ static inline void do_stg(CPUARMState *env, uint64_t ptr, uint64_t xt,
52
53
/* Trap if accessing an invalid page. */
54
mem = allocation_tag_mem(env, mmu_idx, ptr, MMU_DATA_STORE, TAG_GRANULE,
55
- MMU_DATA_STORE, 1, ra);
56
+ MMU_DATA_STORE, ra);
57
58
/* Store if page supports tags. */
59
if (mem) {
60
@@ -XXX,XX +XXX,XX @@ static inline void do_st2g(CPUARMState *env, uint64_t ptr, uint64_t xt,
61
if (ptr & TAG_GRANULE) {
62
/* Two stores unaligned mod TAG_GRANULE*2 -- modify two bytes. */
63
mem1 = allocation_tag_mem(env, mmu_idx, ptr, MMU_DATA_STORE,
64
- TAG_GRANULE, MMU_DATA_STORE, 1, ra);
65
+ TAG_GRANULE, MMU_DATA_STORE, ra);
66
mem2 = allocation_tag_mem(env, mmu_idx, ptr + TAG_GRANULE,
67
MMU_DATA_STORE, TAG_GRANULE,
68
- MMU_DATA_STORE, 1, ra);
69
+ MMU_DATA_STORE, ra);
70
71
/* Store if page(s) support tags. */
72
if (mem1) {
73
@@ -XXX,XX +XXX,XX @@ static inline void do_st2g(CPUARMState *env, uint64_t ptr, uint64_t xt,
74
} else {
75
/* Two stores aligned mod TAG_GRANULE*2 -- modify one byte. */
76
mem1 = allocation_tag_mem(env, mmu_idx, ptr, MMU_DATA_STORE,
77
- 2 * TAG_GRANULE, MMU_DATA_STORE, 1, ra);
78
+ 2 * TAG_GRANULE, MMU_DATA_STORE, ra);
79
if (mem1) {
80
tag |= tag << 4;
81
qatomic_set(mem1, tag);
82
@@ -XXX,XX +XXX,XX @@ uint64_t HELPER(ldgm)(CPUARMState *env, uint64_t ptr)
83
84
/* Trap if accessing an invalid page. */
85
tag_mem = allocation_tag_mem(env, mmu_idx, ptr, MMU_DATA_LOAD,
86
- gm_bs_bytes, MMU_DATA_LOAD,
87
- gm_bs_bytes / (2 * TAG_GRANULE), ra);
88
+ gm_bs_bytes, MMU_DATA_LOAD, ra);
89
90
/* The tag is squashed to zero if the page does not support tags. */
91
if (!tag_mem) {
92
@@ -XXX,XX +XXX,XX @@ void HELPER(stgm)(CPUARMState *env, uint64_t ptr, uint64_t val)
93
94
/* Trap if accessing an invalid page. */
95
tag_mem = allocation_tag_mem(env, mmu_idx, ptr, MMU_DATA_STORE,
96
- gm_bs_bytes, MMU_DATA_LOAD,
97
- gm_bs_bytes / (2 * TAG_GRANULE), ra);
98
+ gm_bs_bytes, MMU_DATA_LOAD, ra);
99
100
/*
101
* Tag store only happens if the page support tags,
102
@@ -XXX,XX +XXX,XX @@ void HELPER(stzgm_tags)(CPUARMState *env, uint64_t ptr, uint64_t val)
103
ptr &= -dcz_bytes;
104
105
mem = allocation_tag_mem(env, mmu_idx, ptr, MMU_DATA_STORE, dcz_bytes,
106
- MMU_DATA_STORE, tag_bytes, ra);
107
+ MMU_DATA_STORE, ra);
108
if (mem) {
109
int tag_pair = (val & 0xf) * 0x11;
110
memset(mem, tag_pair, tag_bytes);
111
@@ -XXX,XX +XXX,XX @@ static int mte_probe_int(CPUARMState *env, uint32_t desc, uint64_t ptr,
112
int mmu_idx, ptr_tag, bit55;
113
uint64_t ptr_last, prev_page, next_page;
114
uint64_t tag_first, tag_last;
115
- uint64_t tag_byte_first, tag_byte_last;
116
- uint32_t sizem1, tag_count, tag_size, n, c;
117
+ uint32_t sizem1, tag_count, n, c;
118
uint8_t *mem1, *mem2;
119
MMUAccessType type;
120
121
@@ -XXX,XX +XXX,XX @@ static int mte_probe_int(CPUARMState *env, uint32_t desc, uint64_t ptr,
122
tag_last = QEMU_ALIGN_DOWN(ptr_last, TAG_GRANULE);
123
tag_count = ((tag_last - tag_first) / TAG_GRANULE) + 1;
124
125
- /* Round the bounds to twice the tag granule, and compute the bytes. */
126
- tag_byte_first = QEMU_ALIGN_DOWN(ptr, 2 * TAG_GRANULE);
127
- tag_byte_last = QEMU_ALIGN_DOWN(ptr_last, 2 * TAG_GRANULE);
128
-
129
/* Locate the page boundaries. */
130
prev_page = ptr & TARGET_PAGE_MASK;
131
next_page = prev_page + TARGET_PAGE_SIZE;
132
133
if (likely(tag_last - prev_page < TARGET_PAGE_SIZE)) {
134
/* Memory access stays on one page. */
135
- tag_size = ((tag_byte_last - tag_byte_first) / (2 * TAG_GRANULE)) + 1;
136
mem1 = allocation_tag_mem(env, mmu_idx, ptr, type, sizem1 + 1,
137
- MMU_DATA_LOAD, tag_size, ra);
138
+ MMU_DATA_LOAD, ra);
139
if (!mem1) {
140
return 1;
141
}
142
@@ -XXX,XX +XXX,XX @@ static int mte_probe_int(CPUARMState *env, uint32_t desc, uint64_t ptr,
143
n = checkN(mem1, ptr & TAG_GRANULE, ptr_tag, tag_count);
144
} else {
145
/* Memory access crosses to next page. */
146
- tag_size = (next_page - tag_byte_first) / (2 * TAG_GRANULE);
147
mem1 = allocation_tag_mem(env, mmu_idx, ptr, type, next_page - ptr,
148
- MMU_DATA_LOAD, tag_size, ra);
149
+ MMU_DATA_LOAD, ra);
150
151
- tag_size = ((tag_byte_last - next_page) / (2 * TAG_GRANULE)) + 1;
152
mem2 = allocation_tag_mem(env, mmu_idx, next_page, type,
153
ptr_last - next_page + 1,
154
- MMU_DATA_LOAD, tag_size, ra);
155
+ MMU_DATA_LOAD, ra);
156
157
/*
158
* Perform all of the comparisons.
159
@@ -XXX,XX +XXX,XX @@ uint64_t HELPER(mte_check_zva)(CPUARMState *env, uint32_t desc, uint64_t ptr)
160
mmu_idx = FIELD_EX32(desc, MTEDESC, MIDX);
161
(void) probe_write(env, ptr, 1, mmu_idx, ra);
162
mem = allocation_tag_mem(env, mmu_idx, align_ptr, MMU_DATA_STORE,
163
- dcz_bytes, MMU_DATA_LOAD, tag_bytes, ra);
164
+ dcz_bytes, MMU_DATA_LOAD, ra);
165
if (!mem) {
166
goto done;
167
}
168
--
169
2.34.1
170
171
diff view generated by jsdifflib
Deleted patch
1
The LDRT/STRT "unprivileged load/store" instructions behave like
2
normal ones if executed at EL0. We handle this correctly for
3
the load/store semantics, but get the MTE checking wrong.
4
1
5
We always look at s->mte_active[is_unpriv] to see whether we should
6
be doing MTE checks, but in hflags.c when we set the TB flags that
7
will be used to fill the mte_active[] array we only set the
8
MTE0_ACTIVE bit if UNPRIV is true (i.e. we are not at EL0).
9
10
This means that a LDRT at EL0 will see s->mte_active[1] as 0,
11
and will not do MTE checks even when MTE is enabled.
12
13
To avoid the translate-time code having to do an explicit check on
14
s->unpriv to see if it is OK to index into the mte_active[] array,
15
duplicate MTE_ACTIVE into MTE0_ACTIVE when UNPRIV is false.
16
17
(This isn't a very serious bug because generally nobody executes
18
LDRT/STRT at EL0, because they have no use there.)
19
20
Cc: qemu-stable@nongnu.org
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
23
Message-id: 20230912140434.1333369-2-peter.maydell@linaro.org
24
---
25
target/arm/tcg/hflags.c | 9 +++++++++
26
1 file changed, 9 insertions(+)
27
28
diff --git a/target/arm/tcg/hflags.c b/target/arm/tcg/hflags.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/target/arm/tcg/hflags.c
31
+++ b/target/arm/tcg/hflags.c
32
@@ -XXX,XX +XXX,XX @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el,
33
&& !(env->pstate & PSTATE_TCO)
34
&& (sctlr & (el == 0 ? SCTLR_TCF0 : SCTLR_TCF))) {
35
DP_TBFLAG_A64(flags, MTE_ACTIVE, 1);
36
+ if (!EX_TBFLAG_A64(flags, UNPRIV)) {
37
+ /*
38
+ * In non-unpriv contexts (eg EL0), unpriv load/stores
39
+ * act like normal ones; duplicate the MTE info to
40
+ * avoid translate-a64.c having to check UNPRIV to see
41
+ * whether it is OK to index into MTE_ACTIVE[].
42
+ */
43
+ DP_TBFLAG_A64(flags, MTE0_ACTIVE, 1);
44
+ }
45
}
46
}
47
/* And again for unprivileged accesses, if required. */
48
--
49
2.34.1
diff view generated by jsdifflib
Deleted patch
1
FEAT_MOPS defines a handful of new enable bits:
2
* HCRX_EL2.MSCEn, SCTLR_EL1.MSCEn, SCTLR_EL2.MSCen:
3
define whether the new insns should UNDEF or not
4
* HCRX_EL2.MCE2: defines whether memops exceptions from
5
EL1 should be taken to EL1 or EL2
6
1
7
Since we don't sanitise what bits can be written for the SCTLR
8
registers, we only need to handle the new bits in HCRX_EL2, and
9
define SCTLR_MSCEN for the new SCTLR bit value.
10
11
The precedence of "HCRX bits acts as 0 if SCR_EL3.HXEn is 0" versus
12
"bit acts as 1 if EL2 disabled" is not clear from the register
13
definition text, but it is clear in the CheckMOPSEnabled()
14
pseudocode(), so we follow that. We'll have to check whether other
15
bits we need to implement in future follow the same logic or not.
16
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
19
Message-id: 20230912140434.1333369-3-peter.maydell@linaro.org
20
---
21
target/arm/cpu.h | 6 ++++++
22
target/arm/helper.c | 28 +++++++++++++++++++++-------
23
2 files changed, 27 insertions(+), 7 deletions(-)
24
25
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
26
index XXXXXXX..XXXXXXX 100644
27
--- a/target/arm/cpu.h
28
+++ b/target/arm/cpu.h
29
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
30
#define SCTLR_EnIB (1U << 30) /* v8.3, AArch64 only */
31
#define SCTLR_EnIA (1U << 31) /* v8.3, AArch64 only */
32
#define SCTLR_DSSBS_32 (1U << 31) /* v8.5, AArch32 only */
33
+#define SCTLR_MSCEN (1ULL << 33) /* FEAT_MOPS */
34
#define SCTLR_BT0 (1ULL << 35) /* v8.5-BTI */
35
#define SCTLR_BT1 (1ULL << 36) /* v8.5-BTI */
36
#define SCTLR_ITFSB (1ULL << 37) /* v8.5-MemTag */
37
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_doublelock(const ARMISARegisters *id)
38
return FIELD_SEX64(id->id_aa64dfr0, ID_AA64DFR0, DOUBLELOCK) >= 0;
39
}
40
41
+static inline bool isar_feature_aa64_mops(const ARMISARegisters *id)
42
+{
43
+ return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, MOPS);
44
+}
45
+
46
/*
47
* Feature tests for "does this exist in either 32-bit or 64-bit?"
48
*/
49
diff --git a/target/arm/helper.c b/target/arm/helper.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/target/arm/helper.c
52
+++ b/target/arm/helper.c
53
@@ -XXX,XX +XXX,XX @@ static void hcrx_write(CPUARMState *env, const ARMCPRegInfo *ri,
54
{
55
uint64_t valid_mask = 0;
56
57
- /* No features adding bits to HCRX are implemented. */
58
+ /* FEAT_MOPS adds MSCEn and MCE2 */
59
+ if (cpu_isar_feature(aa64_mops, env_archcpu(env))) {
60
+ valid_mask |= HCRX_MSCEN | HCRX_MCE2;
61
+ }
62
63
/* Clear RES0 bits. */
64
env->cp15.hcrx_el2 = value & valid_mask;
65
@@ -XXX,XX +XXX,XX @@ uint64_t arm_hcrx_el2_eff(CPUARMState *env)
66
{
67
/*
68
* The bits in this register behave as 0 for all purposes other than
69
- * direct reads of the register if:
70
- * - EL2 is not enabled in the current security state,
71
- * - SCR_EL3.HXEn is 0.
72
+ * direct reads of the register if SCR_EL3.HXEn is 0.
73
+ * If EL2 is not enabled in the current security state, then the
74
+ * bit may behave as if 0, or as if 1, depending on the bit.
75
+ * For the moment, we treat the EL2-disabled case as taking
76
+ * priority over the HXEn-disabled case. This is true for the only
77
+ * bit for a feature which we implement where the answer is different
78
+ * for the two cases (MSCEn for FEAT_MOPS).
79
+ * This may need to be revisited for future bits.
80
*/
81
- if (!arm_is_el2_enabled(env)
82
- || (arm_feature(env, ARM_FEATURE_EL3)
83
- && !(env->cp15.scr_el3 & SCR_HXEN))) {
84
+ if (!arm_is_el2_enabled(env)) {
85
+ uint64_t hcrx = 0;
86
+ if (cpu_isar_feature(aa64_mops, env_archcpu(env))) {
87
+ /* MSCEn behaves as 1 if EL2 is not enabled */
88
+ hcrx |= HCRX_MSCEN;
89
+ }
90
+ return hcrx;
91
+ }
92
+ if (arm_feature(env, ARM_FEATURE_EL3) && !(env->cp15.scr_el3 & SCR_HXEN)) {
93
return 0;
94
}
95
return env->cp15.hcrx_el2;
96
--
97
2.34.1
diff view generated by jsdifflib
Deleted patch
1
In every place that we call the get_a64_user_mem_index() function
2
we do it like this:
3
memidx = a->unpriv ? get_a64_user_mem_index(s) : get_mem_index(s);
4
Refactor so the caller passes in the bool that says whether they
5
want the 'unpriv' or 'normal' mem_index rather than having to
6
do the ?: themselves.
7
1
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Message-id: 20230912140434.1333369-4-peter.maydell@linaro.org
10
---
11
target/arm/tcg/translate-a64.c | 20 ++++++++++++++------
12
1 file changed, 14 insertions(+), 6 deletions(-)
13
14
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/tcg/translate-a64.c
17
+++ b/target/arm/tcg/translate-a64.c
18
@@ -XXX,XX +XXX,XX @@ void a64_translate_init(void)
19
}
20
21
/*
22
- * Return the core mmu_idx to use for A64 "unprivileged load/store" insns
23
+ * Return the core mmu_idx to use for A64 load/store insns which
24
+ * have a "unprivileged load/store" variant. Those insns access
25
+ * EL0 if executed from an EL which has control over EL0 (usually
26
+ * EL1) but behave like normal loads and stores if executed from
27
+ * elsewhere (eg EL3).
28
+ *
29
+ * @unpriv : true for the unprivileged encoding; false for the
30
+ * normal encoding (in which case we will return the same
31
+ * thing as get_mem_index().
32
*/
33
-static int get_a64_user_mem_index(DisasContext *s)
34
+static int get_a64_user_mem_index(DisasContext *s, bool unpriv)
35
{
36
/*
37
* If AccType_UNPRIV is not used, the insn uses AccType_NORMAL,
38
@@ -XXX,XX +XXX,XX @@ static int get_a64_user_mem_index(DisasContext *s)
39
*/
40
ARMMMUIdx useridx = s->mmu_idx;
41
42
- if (s->unpriv) {
43
+ if (unpriv && s->unpriv) {
44
/*
45
* We have pre-computed the condition for AccType_UNPRIV.
46
* Therefore we should never get here with a mmu_idx for
47
@@ -XXX,XX +XXX,XX @@ static void op_addr_ldst_imm_pre(DisasContext *s, arg_ldst_imm *a,
48
if (!a->p) {
49
tcg_gen_addi_i64(*dirty_addr, *dirty_addr, offset);
50
}
51
- memidx = a->unpriv ? get_a64_user_mem_index(s) : get_mem_index(s);
52
+ memidx = get_a64_user_mem_index(s, a->unpriv);
53
*clean_addr = gen_mte_check1_mmuidx(s, *dirty_addr, is_store,
54
a->w || a->rn != 31,
55
mop, a->unpriv, memidx);
56
@@ -XXX,XX +XXX,XX @@ static bool trans_STR_i(DisasContext *s, arg_ldst_imm *a)
57
{
58
bool iss_sf, iss_valid = !a->w;
59
TCGv_i64 clean_addr, dirty_addr, tcg_rt;
60
- int memidx = a->unpriv ? get_a64_user_mem_index(s) : get_mem_index(s);
61
+ int memidx = get_a64_user_mem_index(s, a->unpriv);
62
MemOp mop = finalize_memop(s, a->sz + a->sign * MO_SIGN);
63
64
op_addr_ldst_imm_pre(s, a, &clean_addr, &dirty_addr, a->imm, true, mop);
65
@@ -XXX,XX +XXX,XX @@ static bool trans_LDR_i(DisasContext *s, arg_ldst_imm *a)
66
{
67
bool iss_sf, iss_valid = !a->w;
68
TCGv_i64 clean_addr, dirty_addr, tcg_rt;
69
- int memidx = a->unpriv ? get_a64_user_mem_index(s) : get_mem_index(s);
70
+ int memidx = get_a64_user_mem_index(s, a->unpriv);
71
MemOp mop = finalize_memop(s, a->sz + a->sign * MO_SIGN);
72
73
op_addr_ldst_imm_pre(s, a, &clean_addr, &dirty_addr, a->imm, false, mop);
74
--
75
2.34.1
diff view generated by jsdifflib
Deleted patch
1
The FEAT_MOPS memory operations can raise a Memory Copy or Memory Set
2
exception if a copy or set instruction is executed when the CPU
3
register state is not correct for that instruction. Define the
4
usual syn_* function that constructs the syndrome register value
5
for these exceptions.
6
1
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20230912140434.1333369-5-peter.maydell@linaro.org
10
---
11
target/arm/syndrome.h | 12 ++++++++++++
12
1 file changed, 12 insertions(+)
13
14
diff --git a/target/arm/syndrome.h b/target/arm/syndrome.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/syndrome.h
17
+++ b/target/arm/syndrome.h
18
@@ -XXX,XX +XXX,XX @@ enum arm_exception_class {
19
EC_DATAABORT = 0x24,
20
EC_DATAABORT_SAME_EL = 0x25,
21
EC_SPALIGNMENT = 0x26,
22
+ EC_MOP = 0x27,
23
EC_AA32_FPTRAP = 0x28,
24
EC_AA64_FPTRAP = 0x2c,
25
EC_SERROR = 0x2f,
26
@@ -XXX,XX +XXX,XX @@ static inline uint32_t syn_serror(uint32_t extra)
27
return (EC_SERROR << ARM_EL_EC_SHIFT) | ARM_EL_IL | extra;
28
}
29
30
+static inline uint32_t syn_mop(bool is_set, bool is_setg, int options,
31
+ bool epilogue, bool wrong_option, bool option_a,
32
+ int destreg, int srcreg, int sizereg)
33
+{
34
+ return (EC_MOP << ARM_EL_EC_SHIFT) | ARM_EL_IL |
35
+ (is_set << 24) | (is_setg << 23) | (options << 19) |
36
+ (epilogue << 18) | (wrong_option << 17) | (option_a << 16) |
37
+ (destreg << 10) | (srcreg << 5) | sizereg;
38
+}
39
+
40
+
41
#endif /* TARGET_ARM_SYNDROME_H */
42
--
43
2.34.1
diff view generated by jsdifflib
Deleted patch
1
For the FEAT_MOPS operations, the existing allocation_tag_mem()
2
function almost does what we want, but it will take a watchpoint
3
exception even for an ra == 0 probe request, and it requires that the
4
caller guarantee that the memory is accessible. For FEAT_MOPS we
5
want a function that will not take any kind of exception, and will
6
return NULL for the not-accessible case.
7
1
8
Rename allocation_tag_mem() to allocation_tag_mem_probe() and add an
9
extra 'probe' argument that lets us distinguish these cases;
10
allocation_tag_mem() is now a wrapper that always passes 'false'.
11
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20230912140434.1333369-6-peter.maydell@linaro.org
15
---
16
target/arm/tcg/mte_helper.c | 48 ++++++++++++++++++++++++++++---------
17
1 file changed, 37 insertions(+), 11 deletions(-)
18
19
diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/arm/tcg/mte_helper.c
22
+++ b/target/arm/tcg/mte_helper.c
23
@@ -XXX,XX +XXX,XX @@ static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude)
24
}
25
26
/**
27
- * allocation_tag_mem:
28
+ * allocation_tag_mem_probe:
29
* @env: the cpu environment
30
* @ptr_mmu_idx: the addressing regime to use for the virtual address
31
* @ptr: the virtual address for which to look up tag memory
32
* @ptr_access: the access to use for the virtual address
33
* @ptr_size: the number of bytes in the normal memory access
34
* @tag_access: the access to use for the tag memory
35
+ * @probe: true to merely probe, never taking an exception
36
* @ra: the return address for exception handling
37
*
38
* Our tag memory is formatted as a sequence of little-endian nibbles.
39
@@ -XXX,XX +XXX,XX @@ static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude)
40
* for the higher addr.
41
*
42
* Here, resolve the physical address from the virtual address, and return
43
- * a pointer to the corresponding tag byte. Exit with exception if the
44
- * virtual address is not accessible for @ptr_access.
45
+ * a pointer to the corresponding tag byte.
46
*
47
* If there is no tag storage corresponding to @ptr, return NULL.
48
+ *
49
+ * If the page is inaccessible for @ptr_access, or has a watchpoint, there are
50
+ * three options:
51
+ * (1) probe = true, ra = 0 : pure probe -- we return NULL if the page is not
52
+ * accessible, and do not take watchpoint traps. The calling code must
53
+ * handle those cases in the right priority compared to MTE traps.
54
+ * (2) probe = false, ra = 0 : probe, no fault expected -- the caller guarantees
55
+ * that the page is going to be accessible. We will take watchpoint traps.
56
+ * (3) probe = false, ra != 0 : non-probe -- we will take both memory access
57
+ * traps and watchpoint traps.
58
+ * (probe = true, ra != 0 is invalid and will assert.)
59
*/
60
-static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx,
61
- uint64_t ptr, MMUAccessType ptr_access,
62
- int ptr_size, MMUAccessType tag_access,
63
- uintptr_t ra)
64
+static uint8_t *allocation_tag_mem_probe(CPUARMState *env, int ptr_mmu_idx,
65
+ uint64_t ptr, MMUAccessType ptr_access,
66
+ int ptr_size, MMUAccessType tag_access,
67
+ bool probe, uintptr_t ra)
68
{
69
#ifdef CONFIG_USER_ONLY
70
uint64_t clean_ptr = useronly_clean_ptr(ptr);
71
@@ -XXX,XX +XXX,XX @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx,
72
uint8_t *tags;
73
uintptr_t index;
74
75
+ assert(!(probe && ra));
76
+
77
if (!(flags & (ptr_access == MMU_DATA_STORE ? PAGE_WRITE_ORG : PAGE_READ))) {
78
cpu_loop_exit_sigsegv(env_cpu(env), ptr, ptr_access,
79
!(flags & PAGE_VALID), ra);
80
@@ -XXX,XX +XXX,XX @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx,
81
* exception for inaccessible pages, and resolves the virtual address
82
* into the softmmu tlb.
83
*
84
- * When RA == 0, this is for mte_probe. The page is expected to be
85
- * valid. Indicate to probe_access_flags no-fault, then assert that
86
- * we received a valid page.
87
+ * When RA == 0, this is either a pure probe or a no-fault-expected probe.
88
+ * Indicate to probe_access_flags no-fault, then either return NULL
89
+ * for the pure probe, or assert that we received a valid page for the
90
+ * no-fault-expected probe.
91
*/
92
flags = probe_access_full(env, ptr, 0, ptr_access, ptr_mmu_idx,
93
ra == 0, &host, &full, ra);
94
+ if (probe && (flags & TLB_INVALID_MASK)) {
95
+ return NULL;
96
+ }
97
assert(!(flags & TLB_INVALID_MASK));
98
99
/* If the virtual page MemAttr != Tagged, access unchecked. */
100
@@ -XXX,XX +XXX,XX @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx,
101
}
102
103
/* Any debug exception has priority over a tag check exception. */
104
- if (unlikely(flags & TLB_WATCHPOINT)) {
105
+ if (!probe && unlikely(flags & TLB_WATCHPOINT)) {
106
int wp = ptr_access == MMU_DATA_LOAD ? BP_MEM_READ : BP_MEM_WRITE;
107
assert(ra != 0);
108
cpu_check_watchpoint(env_cpu(env), ptr, ptr_size, attrs, wp, ra);
109
@@ -XXX,XX +XXX,XX @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx,
110
#endif
111
}
112
113
+static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx,
114
+ uint64_t ptr, MMUAccessType ptr_access,
115
+ int ptr_size, MMUAccessType tag_access,
116
+ uintptr_t ra)
117
+{
118
+ return allocation_tag_mem_probe(env, ptr_mmu_idx, ptr, ptr_access,
119
+ ptr_size, tag_access, false, ra);
120
+}
121
+
122
uint64_t HELPER(irg)(CPUARMState *env, uint64_t rn, uint64_t rm)
123
{
124
uint16_t exclude = extract32(rm | env->cp15.gcr_el1, 0, 16);
125
--
126
2.34.1
diff view generated by jsdifflib
Deleted patch
1
The FEAT_MOPS instructions need a couple of helper routines that
2
check for MTE tag failures:
3
* mte_mops_probe() checks whether there is going to be a tag
4
error in the next up-to-a-page worth of data
5
* mte_check_fail() is an existing function to record the fact
6
of a tag failure, which we need to make global so we can
7
call it from helper-a64.c
8
1
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 20230912140434.1333369-7-peter.maydell@linaro.org
12
---
13
target/arm/internals.h | 28 +++++++++++++++++++
14
target/arm/tcg/mte_helper.c | 54 +++++++++++++++++++++++++++++++++++--
15
2 files changed, 80 insertions(+), 2 deletions(-)
16
17
diff --git a/target/arm/internals.h b/target/arm/internals.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/target/arm/internals.h
20
+++ b/target/arm/internals.h
21
@@ -XXX,XX +XXX,XX @@ FIELD(MTEDESC, SIZEM1, 12, SIMD_DATA_BITS - 12) /* size - 1 */
22
bool mte_probe(CPUARMState *env, uint32_t desc, uint64_t ptr);
23
uint64_t mte_check(CPUARMState *env, uint32_t desc, uint64_t ptr, uintptr_t ra);
24
25
+/**
26
+ * mte_mops_probe: Check where the next MTE failure is for a FEAT_MOPS operation
27
+ * @env: CPU env
28
+ * @ptr: start address of memory region (dirty pointer)
29
+ * @size: length of region (guaranteed not to cross a page boundary)
30
+ * @desc: MTEDESC descriptor word (0 means no MTE checks)
31
+ * Returns: the size of the region that can be copied without hitting
32
+ * an MTE tag failure
33
+ *
34
+ * Note that we assume that the caller has already checked the TBI
35
+ * and TCMA bits with mte_checks_needed() and an MTE check is definitely
36
+ * required.
37
+ */
38
+uint64_t mte_mops_probe(CPUARMState *env, uint64_t ptr, uint64_t size,
39
+ uint32_t desc);
40
+
41
+/**
42
+ * mte_check_fail: Record an MTE tag check failure
43
+ * @env: CPU env
44
+ * @desc: MTEDESC descriptor word
45
+ * @dirty_ptr: Failing dirty address
46
+ * @ra: TCG retaddr
47
+ *
48
+ * This may never return (if the MTE tag checks are configured to fault).
49
+ */
50
+void mte_check_fail(CPUARMState *env, uint32_t desc,
51
+ uint64_t dirty_ptr, uintptr_t ra);
52
+
53
static inline int allocation_tag_from_addr(uint64_t ptr)
54
{
55
return extract64(ptr, 56, 4);
56
diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c
57
index XXXXXXX..XXXXXXX 100644
58
--- a/target/arm/tcg/mte_helper.c
59
+++ b/target/arm/tcg/mte_helper.c
60
@@ -XXX,XX +XXX,XX @@ static void mte_async_check_fail(CPUARMState *env, uint64_t dirty_ptr,
61
}
62
63
/* Record a tag check failure. */
64
-static void mte_check_fail(CPUARMState *env, uint32_t desc,
65
- uint64_t dirty_ptr, uintptr_t ra)
66
+void mte_check_fail(CPUARMState *env, uint32_t desc,
67
+ uint64_t dirty_ptr, uintptr_t ra)
68
{
69
int mmu_idx = FIELD_EX32(desc, MTEDESC, MIDX);
70
ARMMMUIdx arm_mmu_idx = core_to_aa64_mmu_idx(mmu_idx);
71
@@ -XXX,XX +XXX,XX @@ uint64_t HELPER(mte_check_zva)(CPUARMState *env, uint32_t desc, uint64_t ptr)
72
done:
73
return useronly_clean_ptr(ptr);
74
}
75
+
76
+uint64_t mte_mops_probe(CPUARMState *env, uint64_t ptr, uint64_t size,
77
+ uint32_t desc)
78
+{
79
+ int mmu_idx, tag_count;
80
+ uint64_t ptr_tag, tag_first, tag_last;
81
+ void *mem;
82
+ bool w = FIELD_EX32(desc, MTEDESC, WRITE);
83
+ uint32_t n;
84
+
85
+ mmu_idx = FIELD_EX32(desc, MTEDESC, MIDX);
86
+ /* True probe; this will never fault */
87
+ mem = allocation_tag_mem_probe(env, mmu_idx, ptr,
88
+ w ? MMU_DATA_STORE : MMU_DATA_LOAD,
89
+ size, MMU_DATA_LOAD, true, 0);
90
+ if (!mem) {
91
+ return size;
92
+ }
93
+
94
+ /*
95
+ * TODO: checkN() is not designed for checks of the size we expect
96
+ * for FEAT_MOPS operations, so we should implement this differently.
97
+ * Maybe we should do something like
98
+ * if (region start and size are aligned nicely) {
99
+ * do direct loads of 64 tag bits at a time;
100
+ * } else {
101
+ * call checkN()
102
+ * }
103
+ */
104
+ /* Round the bounds to the tag granule, and compute the number of tags. */
105
+ ptr_tag = allocation_tag_from_addr(ptr);
106
+ tag_first = QEMU_ALIGN_DOWN(ptr, TAG_GRANULE);
107
+ tag_last = QEMU_ALIGN_DOWN(ptr + size - 1, TAG_GRANULE);
108
+ tag_count = ((tag_last - tag_first) / TAG_GRANULE) + 1;
109
+ n = checkN(mem, ptr & TAG_GRANULE, ptr_tag, tag_count);
110
+ if (likely(n == tag_count)) {
111
+ return size;
112
+ }
113
+
114
+ /*
115
+ * Failure; for the first granule, it's at @ptr. Otherwise
116
+ * it's at the first byte of the nth granule. Calculate how
117
+ * many bytes we can access without hitting that failure.
118
+ */
119
+ if (n == 0) {
120
+ return 0;
121
+ } else {
122
+ return n * TAG_GRANULE - (ptr - tag_first);
123
+ }
124
+}
125
--
126
2.34.1
diff view generated by jsdifflib
Deleted patch
1
Implement the SET* instructions which collectively implement a
2
"memset" operation. These come in a set of three, eg SETP
3
(prologue), SETM (main), SETE (epilogue), and each of those has
4
different flavours to indicate whether memory accesses should be
5
unpriv or non-temporal.
6
1
7
This commit does not include the "memset with tag setting"
8
SETG* instructions.
9
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20230912140434.1333369-8-peter.maydell@linaro.org
13
---
14
target/arm/tcg/helper-a64.h | 4 +
15
target/arm/tcg/a64.decode | 16 ++
16
target/arm/tcg/helper-a64.c | 344 +++++++++++++++++++++++++++++++++
17
target/arm/tcg/translate-a64.c | 49 +++++
18
4 files changed, 413 insertions(+)
19
20
diff --git a/target/arm/tcg/helper-a64.h b/target/arm/tcg/helper-a64.h
21
index XXXXXXX..XXXXXXX 100644
22
--- a/target/arm/tcg/helper-a64.h
23
+++ b/target/arm/tcg/helper-a64.h
24
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(stzgm_tags, TCG_CALL_NO_WG, void, env, i64, i64)
25
26
DEF_HELPER_FLAGS_4(unaligned_access, TCG_CALL_NO_WG,
27
noreturn, env, i64, i32, i32)
28
+
29
+DEF_HELPER_3(setp, void, env, i32, i32)
30
+DEF_HELPER_3(setm, void, env, i32, i32)
31
+DEF_HELPER_3(sete, void, env, i32, i32)
32
diff --git a/target/arm/tcg/a64.decode b/target/arm/tcg/a64.decode
33
index XXXXXXX..XXXXXXX 100644
34
--- a/target/arm/tcg/a64.decode
35
+++ b/target/arm/tcg/a64.decode
36
@@ -XXX,XX +XXX,XX @@ LDGM 11011001 11 1 ......... 00 ..... ..... @ldst_tag_mult p=0 w=0
37
STZ2G 11011001 11 1 ......... 01 ..... ..... @ldst_tag p=1 w=1
38
STZ2G 11011001 11 1 ......... 10 ..... ..... @ldst_tag p=0 w=0
39
STZ2G 11011001 11 1 ......... 11 ..... ..... @ldst_tag p=0 w=1
40
+
41
+# Memory operations (memset, memcpy, memmove)
42
+# Each of these comes in a set of three, eg SETP (prologue), SETM (main),
43
+# SETE (epilogue), and each of those has different flavours to
44
+# indicate whether memory accesses should be unpriv or non-temporal.
45
+# We don't distinguish temporal and non-temporal accesses, but we
46
+# do need to report it in syndrome register values.
47
+
48
+# Memset
49
+&set rs rn rd unpriv nontemp
50
+# op2 bit 1 is nontemporal bit
51
+@set .. ......... rs:5 .. nontemp:1 unpriv:1 .. rn:5 rd:5 &set
52
+
53
+SETP 00 011001110 ..... 00 . . 01 ..... ..... @set
54
+SETM 00 011001110 ..... 01 . . 01 ..... ..... @set
55
+SETE 00 011001110 ..... 10 . . 01 ..... ..... @set
56
diff --git a/target/arm/tcg/helper-a64.c b/target/arm/tcg/helper-a64.c
57
index XXXXXXX..XXXXXXX 100644
58
--- a/target/arm/tcg/helper-a64.c
59
+++ b/target/arm/tcg/helper-a64.c
60
@@ -XXX,XX +XXX,XX @@ void HELPER(unaligned_access)(CPUARMState *env, uint64_t addr,
61
arm_cpu_do_unaligned_access(env_cpu(env), addr, access_type,
62
mmu_idx, GETPC());
63
}
64
+
65
+/* Memory operations (memset, memmove, memcpy) */
66
+
67
+/*
68
+ * Return true if the CPY* and SET* insns can execute; compare
69
+ * pseudocode CheckMOPSEnabled(), though we refactor it a little.
70
+ */
71
+static bool mops_enabled(CPUARMState *env)
72
+{
73
+ int el = arm_current_el(env);
74
+
75
+ if (el < 2 &&
76
+ (arm_hcr_el2_eff(env) & (HCR_E2H | HCR_TGE)) != (HCR_E2H | HCR_TGE) &&
77
+ !(arm_hcrx_el2_eff(env) & HCRX_MSCEN)) {
78
+ return false;
79
+ }
80
+
81
+ if (el == 0) {
82
+ if (!el_is_in_host(env, 0)) {
83
+ return env->cp15.sctlr_el[1] & SCTLR_MSCEN;
84
+ } else {
85
+ return env->cp15.sctlr_el[2] & SCTLR_MSCEN;
86
+ }
87
+ }
88
+ return true;
89
+}
90
+
91
+static void check_mops_enabled(CPUARMState *env, uintptr_t ra)
92
+{
93
+ if (!mops_enabled(env)) {
94
+ raise_exception_ra(env, EXCP_UDEF, syn_uncategorized(),
95
+ exception_target_el(env), ra);
96
+ }
97
+}
98
+
99
+/*
100
+ * Return the target exception level for an exception due
101
+ * to mismatched arguments in a FEAT_MOPS copy or set.
102
+ * Compare pseudocode MismatchedCpySetTargetEL()
103
+ */
104
+static int mops_mismatch_exception_target_el(CPUARMState *env)
105
+{
106
+ int el = arm_current_el(env);
107
+
108
+ if (el > 1) {
109
+ return el;
110
+ }
111
+ if (el == 0 && (arm_hcr_el2_eff(env) & HCR_TGE)) {
112
+ return 2;
113
+ }
114
+ if (el == 1 && (arm_hcrx_el2_eff(env) & HCRX_MCE2)) {
115
+ return 2;
116
+ }
117
+ return 1;
118
+}
119
+
120
+/*
121
+ * Check whether an M or E instruction was executed with a CF value
122
+ * indicating the wrong option for this implementation.
123
+ * Assumes we are always Option A.
124
+ */
125
+static void check_mops_wrong_option(CPUARMState *env, uint32_t syndrome,
126
+ uintptr_t ra)
127
+{
128
+ if (env->CF != 0) {
129
+ syndrome |= 1 << 17; /* Set the wrong-option bit */
130
+ raise_exception_ra(env, EXCP_UDEF, syndrome,
131
+ mops_mismatch_exception_target_el(env), ra);
132
+ }
133
+}
134
+
135
+/*
136
+ * Return the maximum number of bytes we can transfer starting at addr
137
+ * without crossing a page boundary.
138
+ */
139
+static uint64_t page_limit(uint64_t addr)
140
+{
141
+ return TARGET_PAGE_ALIGN(addr + 1) - addr;
142
+}
143
+
144
+/*
145
+ * Perform part of a memory set on an area of guest memory starting at
146
+ * toaddr (a dirty address) and extending for setsize bytes.
147
+ *
148
+ * Returns the number of bytes actually set, which might be less than
149
+ * setsize; the caller should loop until the whole set has been done.
150
+ * The caller should ensure that the guest registers are correct
151
+ * for the possibility that the first byte of the set encounters
152
+ * an exception or watchpoint. We guarantee not to take any faults
153
+ * for bytes other than the first.
154
+ */
155
+static uint64_t set_step(CPUARMState *env, uint64_t toaddr,
156
+ uint64_t setsize, uint32_t data, int memidx,
157
+ uint32_t *mtedesc, uintptr_t ra)
158
+{
159
+ void *mem;
160
+
161
+ setsize = MIN(setsize, page_limit(toaddr));
162
+ if (*mtedesc) {
163
+ uint64_t mtesize = mte_mops_probe(env, toaddr, setsize, *mtedesc);
164
+ if (mtesize == 0) {
165
+ /* Trap, or not. All CPU state is up to date */
166
+ mte_check_fail(env, *mtedesc, toaddr, ra);
167
+ /* Continue, with no further MTE checks required */
168
+ *mtedesc = 0;
169
+ } else {
170
+ /* Advance to the end, or to the tag mismatch */
171
+ setsize = MIN(setsize, mtesize);
172
+ }
173
+ }
174
+
175
+ toaddr = useronly_clean_ptr(toaddr);
176
+ /*
177
+ * Trapless lookup: returns NULL for invalid page, I/O,
178
+ * watchpoints, clean pages, etc.
179
+ */
180
+ mem = tlb_vaddr_to_host(env, toaddr, MMU_DATA_STORE, memidx);
181
+
182
+#ifndef CONFIG_USER_ONLY
183
+ if (unlikely(!mem)) {
184
+ /*
185
+ * Slow-path: just do one byte write. This will handle the
186
+ * watchpoint, invalid page, etc handling correctly.
187
+ * For clean code pages, the next iteration will see
188
+ * the page dirty and will use the fast path.
189
+ */
190
+ cpu_stb_mmuidx_ra(env, toaddr, data, memidx, ra);
191
+ return 1;
192
+ }
193
+#endif
194
+ /* Easy case: just memset the host memory */
195
+ memset(mem, data, setsize);
196
+ return setsize;
197
+}
198
+
199
+typedef uint64_t StepFn(CPUARMState *env, uint64_t toaddr,
200
+ uint64_t setsize, uint32_t data,
201
+ int memidx, uint32_t *mtedesc, uintptr_t ra);
202
+
203
+/* Extract register numbers from a MOPS exception syndrome value */
204
+static int mops_destreg(uint32_t syndrome)
205
+{
206
+ return extract32(syndrome, 10, 5);
207
+}
208
+
209
+static int mops_srcreg(uint32_t syndrome)
210
+{
211
+ return extract32(syndrome, 5, 5);
212
+}
213
+
214
+static int mops_sizereg(uint32_t syndrome)
215
+{
216
+ return extract32(syndrome, 0, 5);
217
+}
218
+
219
+/*
220
+ * Return true if TCMA and TBI bits mean we need to do MTE checks.
221
+ * We only need to do this once per MOPS insn, not for every page.
222
+ */
223
+static bool mte_checks_needed(uint64_t ptr, uint32_t desc)
224
+{
225
+ int bit55 = extract64(ptr, 55, 1);
226
+
227
+ /*
228
+ * Note that tbi_check() returns true for "access checked" but
229
+ * tcma_check() returns true for "access unchecked".
230
+ */
231
+ if (!tbi_check(desc, bit55)) {
232
+ return false;
233
+ }
234
+ return !tcma_check(desc, bit55, allocation_tag_from_addr(ptr));
235
+}
236
+
237
+/*
238
+ * For the Memory Set operation, our implementation chooses
239
+ * always to use "option A", where we update Xd to the final
240
+ * address in the SETP insn, and set Xn to be -(bytes remaining).
241
+ * On SETM and SETE insns we only need update Xn.
242
+ *
243
+ * @env: CPU
244
+ * @syndrome: syndrome value for mismatch exceptions
245
+ * (also contains the register numbers we need to use)
246
+ * @mtedesc: MTE descriptor word
247
+ * @stepfn: function which does a single part of the set operation
248
+ * @is_setg: true if this is the tag-setting SETG variant
249
+ */
250
+static void do_setp(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
251
+ StepFn *stepfn, bool is_setg, uintptr_t ra)
252
+{
253
+ /* Prologue: we choose to do up to the next page boundary */
254
+ int rd = mops_destreg(syndrome);
255
+ int rs = mops_srcreg(syndrome);
256
+ int rn = mops_sizereg(syndrome);
257
+ uint8_t data = env->xregs[rs];
258
+ uint32_t memidx = FIELD_EX32(mtedesc, MTEDESC, MIDX);
259
+ uint64_t toaddr = env->xregs[rd];
260
+ uint64_t setsize = env->xregs[rn];
261
+ uint64_t stagesetsize, step;
262
+
263
+ check_mops_enabled(env, ra);
264
+
265
+ if (setsize > INT64_MAX) {
266
+ setsize = INT64_MAX;
267
+ }
268
+
269
+ if (!mte_checks_needed(toaddr, mtedesc)) {
270
+ mtedesc = 0;
271
+ }
272
+
273
+ stagesetsize = MIN(setsize, page_limit(toaddr));
274
+ while (stagesetsize) {
275
+ env->xregs[rd] = toaddr;
276
+ env->xregs[rn] = setsize;
277
+ step = stepfn(env, toaddr, stagesetsize, data, memidx, &mtedesc, ra);
278
+ toaddr += step;
279
+ setsize -= step;
280
+ stagesetsize -= step;
281
+ }
282
+ /* Insn completed, so update registers to the Option A format */
283
+ env->xregs[rd] = toaddr + setsize;
284
+ env->xregs[rn] = -setsize;
285
+
286
+ /* Set NZCV = 0000 to indicate we are an Option A implementation */
287
+ env->NF = 0;
288
+ env->ZF = 1; /* our env->ZF encoding is inverted */
289
+ env->CF = 0;
290
+ env->VF = 0;
291
+ return;
292
+}
293
+
294
+void HELPER(setp)(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc)
295
+{
296
+ do_setp(env, syndrome, mtedesc, set_step, false, GETPC());
297
+}
298
+
299
+static void do_setm(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
300
+ StepFn *stepfn, bool is_setg, uintptr_t ra)
301
+{
302
+ /* Main: we choose to do all the full-page chunks */
303
+ CPUState *cs = env_cpu(env);
304
+ int rd = mops_destreg(syndrome);
305
+ int rs = mops_srcreg(syndrome);
306
+ int rn = mops_sizereg(syndrome);
307
+ uint8_t data = env->xregs[rs];
308
+ uint64_t toaddr = env->xregs[rd] + env->xregs[rn];
309
+ uint64_t setsize = -env->xregs[rn];
310
+ uint32_t memidx = FIELD_EX32(mtedesc, MTEDESC, MIDX);
311
+ uint64_t step, stagesetsize;
312
+
313
+ check_mops_enabled(env, ra);
314
+
315
+ /*
316
+ * We're allowed to NOP out "no data to copy" before the consistency
317
+ * checks; we choose to do so.
318
+ */
319
+ if (env->xregs[rn] == 0) {
320
+ return;
321
+ }
322
+
323
+ check_mops_wrong_option(env, syndrome, ra);
324
+
325
+ /*
326
+ * Our implementation will work fine even if we have an unaligned
327
+ * destination address, and because we update Xn every time around
328
+ * the loop below and the return value from stepfn() may be less
329
+ * than requested, we might find toaddr is unaligned. So we don't
330
+ * have an IMPDEF check for alignment here.
331
+ */
332
+
333
+ if (!mte_checks_needed(toaddr, mtedesc)) {
334
+ mtedesc = 0;
335
+ }
336
+
337
+ /* Do the actual memset: we leave the last partial page to SETE */
338
+ stagesetsize = setsize & TARGET_PAGE_MASK;
339
+ while (stagesetsize > 0) {
340
+ step = stepfn(env, toaddr, setsize, data, memidx, &mtedesc, ra);
341
+ toaddr += step;
342
+ setsize -= step;
343
+ stagesetsize -= step;
344
+ env->xregs[rn] = -setsize;
345
+ if (stagesetsize > 0 && unlikely(cpu_loop_exit_requested(cs))) {
346
+ cpu_loop_exit_restore(cs, ra);
347
+ }
348
+ }
349
+}
350
+
351
+void HELPER(setm)(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc)
352
+{
353
+ do_setm(env, syndrome, mtedesc, set_step, false, GETPC());
354
+}
355
+
356
+static void do_sete(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
357
+ StepFn *stepfn, bool is_setg, uintptr_t ra)
358
+{
359
+ /* Epilogue: do the last partial page */
360
+ int rd = mops_destreg(syndrome);
361
+ int rs = mops_srcreg(syndrome);
362
+ int rn = mops_sizereg(syndrome);
363
+ uint8_t data = env->xregs[rs];
364
+ uint64_t toaddr = env->xregs[rd] + env->xregs[rn];
365
+ uint64_t setsize = -env->xregs[rn];
366
+ uint32_t memidx = FIELD_EX32(mtedesc, MTEDESC, MIDX);
367
+ uint64_t step;
368
+
369
+ check_mops_enabled(env, ra);
370
+
371
+ /*
372
+ * We're allowed to NOP out "no data to copy" before the consistency
373
+ * checks; we choose to do so.
374
+ */
375
+ if (setsize == 0) {
376
+ return;
377
+ }
378
+
379
+ check_mops_wrong_option(env, syndrome, ra);
380
+
381
+ /*
382
+ * Our implementation has no address alignment requirements, but
383
+ * we do want to enforce the "less than a page" size requirement,
384
+ * so we don't need to have the "check for interrupts" here.
385
+ */
386
+ if (setsize >= TARGET_PAGE_SIZE) {
387
+ raise_exception_ra(env, EXCP_UDEF, syndrome,
388
+ mops_mismatch_exception_target_el(env), ra);
389
+ }
390
+
391
+ if (!mte_checks_needed(toaddr, mtedesc)) {
392
+ mtedesc = 0;
393
+ }
394
+
395
+ /* Do the actual memset */
396
+ while (setsize > 0) {
397
+ step = stepfn(env, toaddr, setsize, data, memidx, &mtedesc, ra);
398
+ toaddr += step;
399
+ setsize -= step;
400
+ env->xregs[rn] = -setsize;
401
+ }
402
+}
403
+
404
+void HELPER(sete)(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc)
405
+{
406
+ do_sete(env, syndrome, mtedesc, set_step, false, GETPC());
407
+}
408
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
409
index XXXXXXX..XXXXXXX 100644
410
--- a/target/arm/tcg/translate-a64.c
411
+++ b/target/arm/tcg/translate-a64.c
412
@@ -XXX,XX +XXX,XX @@ TRANS_FEAT(STZG, aa64_mte_insn_reg, do_STG, a, true, false)
413
TRANS_FEAT(ST2G, aa64_mte_insn_reg, do_STG, a, false, true)
414
TRANS_FEAT(STZ2G, aa64_mte_insn_reg, do_STG, a, true, true)
415
416
+typedef void SetFn(TCGv_env, TCGv_i32, TCGv_i32);
417
+
418
+static bool do_SET(DisasContext *s, arg_set *a, bool is_epilogue, SetFn fn)
419
+{
420
+ int memidx;
421
+ uint32_t syndrome, desc = 0;
422
+
423
+ /*
424
+ * UNPREDICTABLE cases: we choose to UNDEF, which allows
425
+ * us to pull this check before the CheckMOPSEnabled() test
426
+ * (which we do in the helper function)
427
+ */
428
+ if (a->rs == a->rn || a->rs == a->rd || a->rn == a->rd ||
429
+ a->rd == 31 || a->rn == 31) {
430
+ return false;
431
+ }
432
+
433
+ memidx = get_a64_user_mem_index(s, a->unpriv);
434
+
435
+ /*
436
+ * We pass option_a == true, matching our implementation;
437
+ * we pass wrong_option == false: helper function may set that bit.
438
+ */
439
+ syndrome = syn_mop(true, false, (a->nontemp << 1) | a->unpriv,
440
+ is_epilogue, false, true, a->rd, a->rs, a->rn);
441
+
442
+ if (s->mte_active[a->unpriv]) {
443
+ /* We may need to do MTE tag checking, so assemble the descriptor */
444
+ desc = FIELD_DP32(desc, MTEDESC, TBI, s->tbid);
445
+ desc = FIELD_DP32(desc, MTEDESC, TCMA, s->tcma);
446
+ desc = FIELD_DP32(desc, MTEDESC, WRITE, true);
447
+ /* SIZEM1 and ALIGN we leave 0 (byte write) */
448
+ }
449
+ /* The helper function always needs the memidx even with MTE disabled */
450
+ desc = FIELD_DP32(desc, MTEDESC, MIDX, memidx);
451
+
452
+ /*
453
+ * The helper needs the register numbers, but since they're in
454
+ * the syndrome anyway, we let it extract them from there rather
455
+ * than passing in an extra three integer arguments.
456
+ */
457
+ fn(cpu_env, tcg_constant_i32(syndrome), tcg_constant_i32(desc));
458
+ return true;
459
+}
460
+
461
+TRANS_FEAT(SETP, aa64_mops, do_SET, a, false, gen_helper_setp)
462
+TRANS_FEAT(SETM, aa64_mops, do_SET, a, false, gen_helper_setm)
463
+TRANS_FEAT(SETE, aa64_mops, do_SET, a, true, gen_helper_sete)
464
+
465
typedef void ArithTwoOp(TCGv_i64, TCGv_i64, TCGv_i64);
466
467
static bool gen_rri(DisasContext *s, arg_rri_sf *a,
468
--
469
2.34.1
diff view generated by jsdifflib
Deleted patch
1
Currently the only tag-setting instructions always do so in the
2
context of the current EL, and so we only need one ATA bit in the TB
3
flags. The FEAT_MOPS SETG instructions include ones which set tags
4
for a non-privileged access, so we now also need the equivalent "are
5
tags enabled?" information for EL0.
6
1
7
Add the new TB flag, and convert the existing 'bool ata' field in
8
DisasContext to a 'bool ata[2]' that can be indexed by the is_unpriv
9
bit in an instruction, similarly to mte[2].
10
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Message-id: 20230912140434.1333369-9-peter.maydell@linaro.org
14
---
15
target/arm/cpu.h | 1 +
16
target/arm/tcg/translate.h | 4 ++--
17
target/arm/tcg/hflags.c | 12 ++++++++++++
18
target/arm/tcg/translate-a64.c | 23 ++++++++++++-----------
19
4 files changed, 27 insertions(+), 13 deletions(-)
20
21
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
22
index XXXXXXX..XXXXXXX 100644
23
--- a/target/arm/cpu.h
24
+++ b/target/arm/cpu.h
25
@@ -XXX,XX +XXX,XX @@ FIELD(TBFLAG_A64, SVL, 24, 4)
26
FIELD(TBFLAG_A64, SME_TRAP_NONSTREAMING, 28, 1)
27
FIELD(TBFLAG_A64, FGT_ERET, 29, 1)
28
FIELD(TBFLAG_A64, NAA, 30, 1)
29
+FIELD(TBFLAG_A64, ATA0, 31, 1)
30
31
/*
32
* Helpers for using the above.
33
diff --git a/target/arm/tcg/translate.h b/target/arm/tcg/translate.h
34
index XXXXXXX..XXXXXXX 100644
35
--- a/target/arm/tcg/translate.h
36
+++ b/target/arm/tcg/translate.h
37
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
38
bool unpriv;
39
/* True if v8.3-PAuth is active. */
40
bool pauth_active;
41
- /* True if v8.5-MTE access to tags is enabled. */
42
- bool ata;
43
+ /* True if v8.5-MTE access to tags is enabled; index with is_unpriv. */
44
+ bool ata[2];
45
/* True if v8.5-MTE tag checks affect the PE; index with is_unpriv. */
46
bool mte_active[2];
47
/* True with v8.5-BTI and SCTLR_ELx.BT* set. */
48
diff --git a/target/arm/tcg/hflags.c b/target/arm/tcg/hflags.c
49
index XXXXXXX..XXXXXXX 100644
50
--- a/target/arm/tcg/hflags.c
51
+++ b/target/arm/tcg/hflags.c
52
@@ -XXX,XX +XXX,XX @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el,
53
&& allocation_tag_access_enabled(env, 0, sctlr)) {
54
DP_TBFLAG_A64(flags, MTE0_ACTIVE, 1);
55
}
56
+ /*
57
+ * For unpriv tag-setting accesses we alse need ATA0. Again, in
58
+ * contexts where unpriv and normal insns are the same we
59
+ * duplicate the ATA bit to save effort for translate-a64.c.
60
+ */
61
+ if (EX_TBFLAG_A64(flags, UNPRIV)) {
62
+ if (allocation_tag_access_enabled(env, 0, sctlr)) {
63
+ DP_TBFLAG_A64(flags, ATA0, 1);
64
+ }
65
+ } else {
66
+ DP_TBFLAG_A64(flags, ATA0, EX_TBFLAG_A64(flags, ATA));
67
+ }
68
/* Cache TCMA as well as TBI. */
69
DP_TBFLAG_A64(flags, TCMA, aa64_va_parameter_tcma(tcr, mmu_idx));
70
}
71
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
72
index XXXXXXX..XXXXXXX 100644
73
--- a/target/arm/tcg/translate-a64.c
74
+++ b/target/arm/tcg/translate-a64.c
75
@@ -XXX,XX +XXX,XX @@ static void handle_sys(DisasContext *s, bool isread,
76
clean_addr = clean_data_tbi(s, tcg_rt);
77
gen_probe_access(s, clean_addr, MMU_DATA_STORE, MO_8);
78
79
- if (s->ata) {
80
+ if (s->ata[0]) {
81
/* Extract the tag from the register to match STZGM. */
82
tag = tcg_temp_new_i64();
83
tcg_gen_shri_i64(tag, tcg_rt, 56);
84
@@ -XXX,XX +XXX,XX @@ static void handle_sys(DisasContext *s, bool isread,
85
clean_addr = clean_data_tbi(s, tcg_rt);
86
gen_helper_dc_zva(cpu_env, clean_addr);
87
88
- if (s->ata) {
89
+ if (s->ata[0]) {
90
/* Extract the tag from the register to match STZGM. */
91
tag = tcg_temp_new_i64();
92
tcg_gen_shri_i64(tag, tcg_rt, 56);
93
@@ -XXX,XX +XXX,XX @@ static bool trans_STGP(DisasContext *s, arg_ldstpair *a)
94
tcg_gen_qemu_st_i128(tmp, clean_addr, get_mem_index(s), mop);
95
96
/* Perform the tag store, if tag access enabled. */
97
- if (s->ata) {
98
+ if (s->ata[0]) {
99
if (tb_cflags(s->base.tb) & CF_PARALLEL) {
100
gen_helper_stg_parallel(cpu_env, dirty_addr, dirty_addr);
101
} else {
102
@@ -XXX,XX +XXX,XX @@ static bool trans_STZGM(DisasContext *s, arg_ldst_tag *a)
103
tcg_gen_addi_i64(addr, addr, a->imm);
104
tcg_rt = cpu_reg(s, a->rt);
105
106
- if (s->ata) {
107
+ if (s->ata[0]) {
108
gen_helper_stzgm_tags(cpu_env, addr, tcg_rt);
109
}
110
/*
111
@@ -XXX,XX +XXX,XX @@ static bool trans_STGM(DisasContext *s, arg_ldst_tag *a)
112
tcg_gen_addi_i64(addr, addr, a->imm);
113
tcg_rt = cpu_reg(s, a->rt);
114
115
- if (s->ata) {
116
+ if (s->ata[0]) {
117
gen_helper_stgm(cpu_env, addr, tcg_rt);
118
} else {
119
MMUAccessType acc = MMU_DATA_STORE;
120
@@ -XXX,XX +XXX,XX @@ static bool trans_LDGM(DisasContext *s, arg_ldst_tag *a)
121
tcg_gen_addi_i64(addr, addr, a->imm);
122
tcg_rt = cpu_reg(s, a->rt);
123
124
- if (s->ata) {
125
+ if (s->ata[0]) {
126
gen_helper_ldgm(tcg_rt, cpu_env, addr);
127
} else {
128
MMUAccessType acc = MMU_DATA_LOAD;
129
@@ -XXX,XX +XXX,XX @@ static bool trans_LDG(DisasContext *s, arg_ldst_tag *a)
130
131
tcg_gen_andi_i64(addr, addr, -TAG_GRANULE);
132
tcg_rt = cpu_reg(s, a->rt);
133
- if (s->ata) {
134
+ if (s->ata[0]) {
135
gen_helper_ldg(tcg_rt, cpu_env, addr, tcg_rt);
136
} else {
137
/*
138
@@ -XXX,XX +XXX,XX @@ static bool do_STG(DisasContext *s, arg_ldst_tag *a, bool is_zero, bool is_pair)
139
tcg_gen_addi_i64(addr, addr, a->imm);
140
}
141
tcg_rt = cpu_reg_sp(s, a->rt);
142
- if (!s->ata) {
143
+ if (!s->ata[0]) {
144
/*
145
* For STG and ST2G, we need to check alignment and probe memory.
146
* TODO: For STZG and STZ2G, we could rely on the stores below,
147
@@ -XXX,XX +XXX,XX @@ static bool gen_add_sub_imm_with_tags(DisasContext *s, arg_rri_tag *a,
148
tcg_rn = cpu_reg_sp(s, a->rn);
149
tcg_rd = cpu_reg_sp(s, a->rd);
150
151
- if (s->ata) {
152
+ if (s->ata[0]) {
153
gen_helper_addsubg(tcg_rd, cpu_env, tcg_rn,
154
tcg_constant_i32(imm),
155
tcg_constant_i32(a->uimm4));
156
@@ -XXX,XX +XXX,XX @@ static void disas_data_proc_2src(DisasContext *s, uint32_t insn)
157
if (sf == 0 || !dc_isar_feature(aa64_mte_insn_reg, s)) {
158
goto do_unallocated;
159
}
160
- if (s->ata) {
161
+ if (s->ata[0]) {
162
gen_helper_irg(cpu_reg_sp(s, rd), cpu_env,
163
cpu_reg_sp(s, rn), cpu_reg(s, rm));
164
} else {
165
@@ -XXX,XX +XXX,XX @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase,
166
dc->bt = EX_TBFLAG_A64(tb_flags, BT);
167
dc->btype = EX_TBFLAG_A64(tb_flags, BTYPE);
168
dc->unpriv = EX_TBFLAG_A64(tb_flags, UNPRIV);
169
- dc->ata = EX_TBFLAG_A64(tb_flags, ATA);
170
+ dc->ata[0] = EX_TBFLAG_A64(tb_flags, ATA);
171
+ dc->ata[1] = EX_TBFLAG_A64(tb_flags, ATA0);
172
dc->mte_active[0] = EX_TBFLAG_A64(tb_flags, MTE_ACTIVE);
173
dc->mte_active[1] = EX_TBFLAG_A64(tb_flags, MTE0_ACTIVE);
174
dc->pstate_sm = EX_TBFLAG_A64(tb_flags, PSTATE_SM);
175
--
176
2.34.1
diff view generated by jsdifflib
Deleted patch
1
The FEAT_MOPS SETG* instructions are very similar to the SET*
2
instructions, but as well as setting memory contents they also
3
set the MTE tags. They are architecturally required to operate
4
on tag-granule aligned regions only.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20230912140434.1333369-10-peter.maydell@linaro.org
9
---
10
target/arm/internals.h | 10 ++++
11
target/arm/tcg/helper-a64.h | 3 ++
12
target/arm/tcg/a64.decode | 5 ++
13
target/arm/tcg/helper-a64.c | 86 ++++++++++++++++++++++++++++++++--
14
target/arm/tcg/mte_helper.c | 40 ++++++++++++++++
15
target/arm/tcg/translate-a64.c | 20 +++++---
16
6 files changed, 155 insertions(+), 9 deletions(-)
17
18
diff --git a/target/arm/internals.h b/target/arm/internals.h
19
index XXXXXXX..XXXXXXX 100644
20
--- a/target/arm/internals.h
21
+++ b/target/arm/internals.h
22
@@ -XXX,XX +XXX,XX @@ uint64_t mte_mops_probe(CPUARMState *env, uint64_t ptr, uint64_t size,
23
void mte_check_fail(CPUARMState *env, uint32_t desc,
24
uint64_t dirty_ptr, uintptr_t ra);
25
26
+/**
27
+ * mte_mops_set_tags: Set MTE tags for a portion of a FEAT_MOPS operation
28
+ * @env: CPU env
29
+ * @dirty_ptr: Start address of memory region (dirty pointer)
30
+ * @size: length of region (guaranteed not to cross page boundary)
31
+ * @desc: MTEDESC descriptor word
32
+ */
33
+void mte_mops_set_tags(CPUARMState *env, uint64_t dirty_ptr, uint64_t size,
34
+ uint32_t desc);
35
+
36
static inline int allocation_tag_from_addr(uint64_t ptr)
37
{
38
return extract64(ptr, 56, 4);
39
diff --git a/target/arm/tcg/helper-a64.h b/target/arm/tcg/helper-a64.h
40
index XXXXXXX..XXXXXXX 100644
41
--- a/target/arm/tcg/helper-a64.h
42
+++ b/target/arm/tcg/helper-a64.h
43
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(unaligned_access, TCG_CALL_NO_WG,
44
DEF_HELPER_3(setp, void, env, i32, i32)
45
DEF_HELPER_3(setm, void, env, i32, i32)
46
DEF_HELPER_3(sete, void, env, i32, i32)
47
+DEF_HELPER_3(setgp, void, env, i32, i32)
48
+DEF_HELPER_3(setgm, void, env, i32, i32)
49
+DEF_HELPER_3(setge, void, env, i32, i32)
50
diff --git a/target/arm/tcg/a64.decode b/target/arm/tcg/a64.decode
51
index XXXXXXX..XXXXXXX 100644
52
--- a/target/arm/tcg/a64.decode
53
+++ b/target/arm/tcg/a64.decode
54
@@ -XXX,XX +XXX,XX @@ STZ2G 11011001 11 1 ......... 11 ..... ..... @ldst_tag p=0 w=1
55
SETP 00 011001110 ..... 00 . . 01 ..... ..... @set
56
SETM 00 011001110 ..... 01 . . 01 ..... ..... @set
57
SETE 00 011001110 ..... 10 . . 01 ..... ..... @set
58
+
59
+# Like SET, but also setting MTE tags
60
+SETGP 00 011101110 ..... 00 . . 01 ..... ..... @set
61
+SETGM 00 011101110 ..... 01 . . 01 ..... ..... @set
62
+SETGE 00 011101110 ..... 10 . . 01 ..... ..... @set
63
diff --git a/target/arm/tcg/helper-a64.c b/target/arm/tcg/helper-a64.c
64
index XXXXXXX..XXXXXXX 100644
65
--- a/target/arm/tcg/helper-a64.c
66
+++ b/target/arm/tcg/helper-a64.c
67
@@ -XXX,XX +XXX,XX @@ static uint64_t set_step(CPUARMState *env, uint64_t toaddr,
68
return setsize;
69
}
70
71
+/*
72
+ * Similar, but setting tags. The architecture requires us to do this
73
+ * in 16-byte chunks. SETP accesses are not tag checked; they set
74
+ * the tags.
75
+ */
76
+static uint64_t set_step_tags(CPUARMState *env, uint64_t toaddr,
77
+ uint64_t setsize, uint32_t data, int memidx,
78
+ uint32_t *mtedesc, uintptr_t ra)
79
+{
80
+ void *mem;
81
+ uint64_t cleanaddr;
82
+
83
+ setsize = MIN(setsize, page_limit(toaddr));
84
+
85
+ cleanaddr = useronly_clean_ptr(toaddr);
86
+ /*
87
+ * Trapless lookup: returns NULL for invalid page, I/O,
88
+ * watchpoints, clean pages, etc.
89
+ */
90
+ mem = tlb_vaddr_to_host(env, cleanaddr, MMU_DATA_STORE, memidx);
91
+
92
+#ifndef CONFIG_USER_ONLY
93
+ if (unlikely(!mem)) {
94
+ /*
95
+ * Slow-path: just do one write. This will handle the
96
+ * watchpoint, invalid page, etc handling correctly.
97
+ * The architecture requires that we do 16 bytes at a time,
98
+ * and we know both ptr and size are 16 byte aligned.
99
+ * For clean code pages, the next iteration will see
100
+ * the page dirty and will use the fast path.
101
+ */
102
+ uint64_t repldata = data * 0x0101010101010101ULL;
103
+ MemOpIdx oi16 = make_memop_idx(MO_TE | MO_128, memidx);
104
+ cpu_st16_mmu(env, toaddr, int128_make128(repldata, repldata), oi16, ra);
105
+ mte_mops_set_tags(env, toaddr, 16, *mtedesc);
106
+ return 16;
107
+ }
108
+#endif
109
+ /* Easy case: just memset the host memory */
110
+ memset(mem, data, setsize);
111
+ mte_mops_set_tags(env, toaddr, setsize, *mtedesc);
112
+ return setsize;
113
+}
114
+
115
typedef uint64_t StepFn(CPUARMState *env, uint64_t toaddr,
116
uint64_t setsize, uint32_t data,
117
int memidx, uint32_t *mtedesc, uintptr_t ra);
118
@@ -XXX,XX +XXX,XX @@ static bool mte_checks_needed(uint64_t ptr, uint32_t desc)
119
return !tcma_check(desc, bit55, allocation_tag_from_addr(ptr));
120
}
121
122
+/* Take an exception if the SETG addr/size are not granule aligned */
123
+static void check_setg_alignment(CPUARMState *env, uint64_t ptr, uint64_t size,
124
+ uint32_t memidx, uintptr_t ra)
125
+{
126
+ if ((size != 0 && !QEMU_IS_ALIGNED(ptr, TAG_GRANULE)) ||
127
+ !QEMU_IS_ALIGNED(size, TAG_GRANULE)) {
128
+ arm_cpu_do_unaligned_access(env_cpu(env), ptr, MMU_DATA_STORE,
129
+ memidx, ra);
130
+
131
+ }
132
+}
133
+
134
/*
135
* For the Memory Set operation, our implementation chooses
136
* always to use "option A", where we update Xd to the final
137
@@ -XXX,XX +XXX,XX @@ static void do_setp(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
138
139
if (setsize > INT64_MAX) {
140
setsize = INT64_MAX;
141
+ if (is_setg) {
142
+ setsize &= ~0xf;
143
+ }
144
}
145
146
- if (!mte_checks_needed(toaddr, mtedesc)) {
147
+ if (unlikely(is_setg)) {
148
+ check_setg_alignment(env, toaddr, setsize, memidx, ra);
149
+ } else if (!mte_checks_needed(toaddr, mtedesc)) {
150
mtedesc = 0;
151
}
152
153
@@ -XXX,XX +XXX,XX @@ void HELPER(setp)(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc)
154
do_setp(env, syndrome, mtedesc, set_step, false, GETPC());
155
}
156
157
+void HELPER(setgp)(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc)
158
+{
159
+ do_setp(env, syndrome, mtedesc, set_step_tags, true, GETPC());
160
+}
161
+
162
static void do_setm(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
163
StepFn *stepfn, bool is_setg, uintptr_t ra)
164
{
165
@@ -XXX,XX +XXX,XX @@ static void do_setm(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
166
* have an IMPDEF check for alignment here.
167
*/
168
169
- if (!mte_checks_needed(toaddr, mtedesc)) {
170
+ if (unlikely(is_setg)) {
171
+ check_setg_alignment(env, toaddr, setsize, memidx, ra);
172
+ } else if (!mte_checks_needed(toaddr, mtedesc)) {
173
mtedesc = 0;
174
}
175
176
@@ -XXX,XX +XXX,XX @@ void HELPER(setm)(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc)
177
do_setm(env, syndrome, mtedesc, set_step, false, GETPC());
178
}
179
180
+void HELPER(setgm)(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc)
181
+{
182
+ do_setm(env, syndrome, mtedesc, set_step_tags, true, GETPC());
183
+}
184
+
185
static void do_sete(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
186
StepFn *stepfn, bool is_setg, uintptr_t ra)
187
{
188
@@ -XXX,XX +XXX,XX @@ static void do_sete(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
189
mops_mismatch_exception_target_el(env), ra);
190
}
191
192
- if (!mte_checks_needed(toaddr, mtedesc)) {
193
+ if (unlikely(is_setg)) {
194
+ check_setg_alignment(env, toaddr, setsize, memidx, ra);
195
+ } else if (!mte_checks_needed(toaddr, mtedesc)) {
196
mtedesc = 0;
197
}
198
199
@@ -XXX,XX +XXX,XX @@ void HELPER(sete)(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc)
200
{
201
do_sete(env, syndrome, mtedesc, set_step, false, GETPC());
202
}
203
+
204
+void HELPER(setge)(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc)
205
+{
206
+ do_sete(env, syndrome, mtedesc, set_step_tags, true, GETPC());
207
+}
208
diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c
209
index XXXXXXX..XXXXXXX 100644
210
--- a/target/arm/tcg/mte_helper.c
211
+++ b/target/arm/tcg/mte_helper.c
212
@@ -XXX,XX +XXX,XX @@ uint64_t mte_mops_probe(CPUARMState *env, uint64_t ptr, uint64_t size,
213
return n * TAG_GRANULE - (ptr - tag_first);
214
}
215
}
216
+
217
+void mte_mops_set_tags(CPUARMState *env, uint64_t ptr, uint64_t size,
218
+ uint32_t desc)
219
+{
220
+ int mmu_idx, tag_count;
221
+ uint64_t ptr_tag;
222
+ void *mem;
223
+
224
+ if (!desc) {
225
+ /* Tags not actually enabled */
226
+ return;
227
+ }
228
+
229
+ mmu_idx = FIELD_EX32(desc, MTEDESC, MIDX);
230
+ /* True probe: this will never fault */
231
+ mem = allocation_tag_mem_probe(env, mmu_idx, ptr, MMU_DATA_STORE, size,
232
+ MMU_DATA_STORE, true, 0);
233
+ if (!mem) {
234
+ return;
235
+ }
236
+
237
+ /*
238
+ * We know that ptr and size are both TAG_GRANULE aligned; store
239
+ * the tag from the pointer value into the tag memory.
240
+ */
241
+ ptr_tag = allocation_tag_from_addr(ptr);
242
+ tag_count = size / TAG_GRANULE;
243
+ if (ptr & TAG_GRANULE) {
244
+ /* Not 2*TAG_GRANULE-aligned: store tag to first nibble */
245
+ store_tag1_parallel(TAG_GRANULE, mem, ptr_tag);
246
+ mem++;
247
+ tag_count--;
248
+ }
249
+ memset(mem, ptr_tag | (ptr_tag << 4), tag_count / 2);
250
+ if (tag_count & 1) {
251
+ /* Final trailing unaligned nibble */
252
+ mem += tag_count / 2;
253
+ store_tag1_parallel(0, mem, ptr_tag);
254
+ }
255
+}
256
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
257
index XXXXXXX..XXXXXXX 100644
258
--- a/target/arm/tcg/translate-a64.c
259
+++ b/target/arm/tcg/translate-a64.c
260
@@ -XXX,XX +XXX,XX @@ TRANS_FEAT(STZ2G, aa64_mte_insn_reg, do_STG, a, true, true)
261
262
typedef void SetFn(TCGv_env, TCGv_i32, TCGv_i32);
263
264
-static bool do_SET(DisasContext *s, arg_set *a, bool is_epilogue, SetFn fn)
265
+static bool do_SET(DisasContext *s, arg_set *a, bool is_epilogue,
266
+ bool is_setg, SetFn fn)
267
{
268
int memidx;
269
uint32_t syndrome, desc = 0;
270
271
+ if (is_setg && !dc_isar_feature(aa64_mte, s)) {
272
+ return false;
273
+ }
274
+
275
/*
276
* UNPREDICTABLE cases: we choose to UNDEF, which allows
277
* us to pull this check before the CheckMOPSEnabled() test
278
@@ -XXX,XX +XXX,XX @@ static bool do_SET(DisasContext *s, arg_set *a, bool is_epilogue, SetFn fn)
279
* We pass option_a == true, matching our implementation;
280
* we pass wrong_option == false: helper function may set that bit.
281
*/
282
- syndrome = syn_mop(true, false, (a->nontemp << 1) | a->unpriv,
283
+ syndrome = syn_mop(true, is_setg, (a->nontemp << 1) | a->unpriv,
284
is_epilogue, false, true, a->rd, a->rs, a->rn);
285
286
- if (s->mte_active[a->unpriv]) {
287
+ if (is_setg ? s->ata[a->unpriv] : s->mte_active[a->unpriv]) {
288
/* We may need to do MTE tag checking, so assemble the descriptor */
289
desc = FIELD_DP32(desc, MTEDESC, TBI, s->tbid);
290
desc = FIELD_DP32(desc, MTEDESC, TCMA, s->tcma);
291
@@ -XXX,XX +XXX,XX @@ static bool do_SET(DisasContext *s, arg_set *a, bool is_epilogue, SetFn fn)
292
return true;
293
}
294
295
-TRANS_FEAT(SETP, aa64_mops, do_SET, a, false, gen_helper_setp)
296
-TRANS_FEAT(SETM, aa64_mops, do_SET, a, false, gen_helper_setm)
297
-TRANS_FEAT(SETE, aa64_mops, do_SET, a, true, gen_helper_sete)
298
+TRANS_FEAT(SETP, aa64_mops, do_SET, a, false, false, gen_helper_setp)
299
+TRANS_FEAT(SETM, aa64_mops, do_SET, a, false, false, gen_helper_setm)
300
+TRANS_FEAT(SETE, aa64_mops, do_SET, a, true, false, gen_helper_sete)
301
+TRANS_FEAT(SETGP, aa64_mops, do_SET, a, false, true, gen_helper_setgp)
302
+TRANS_FEAT(SETGM, aa64_mops, do_SET, a, false, true, gen_helper_setgm)
303
+TRANS_FEAT(SETGE, aa64_mops, do_SET, a, true, true, gen_helper_setge)
304
305
typedef void ArithTwoOp(TCGv_i64, TCGv_i64, TCGv_i64);
306
307
--
308
2.34.1
diff view generated by jsdifflib
Deleted patch
1
The FEAT_MOPS memory copy operations need an extra helper routine
2
for checking for MTE tag checking failures beyond the ones we
3
already added for memory set operations:
4
* mte_mops_probe_rev() does the same job as mte_mops_probe(), but
5
it checks tags starting at the provided address and working
6
backwards, rather than forwards
7
1
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20230912140434.1333369-11-peter.maydell@linaro.org
11
---
12
target/arm/internals.h | 17 +++++++
13
target/arm/tcg/mte_helper.c | 99 +++++++++++++++++++++++++++++++++++++
14
2 files changed, 116 insertions(+)
15
16
diff --git a/target/arm/internals.h b/target/arm/internals.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/internals.h
19
+++ b/target/arm/internals.h
20
@@ -XXX,XX +XXX,XX @@ uint64_t mte_check(CPUARMState *env, uint32_t desc, uint64_t ptr, uintptr_t ra);
21
uint64_t mte_mops_probe(CPUARMState *env, uint64_t ptr, uint64_t size,
22
uint32_t desc);
23
24
+/**
25
+ * mte_mops_probe_rev: Check where the next MTE failure is for a FEAT_MOPS
26
+ * operation going in the reverse direction
27
+ * @env: CPU env
28
+ * @ptr: *end* address of memory region (dirty pointer)
29
+ * @size: length of region (guaranteed not to cross a page boundary)
30
+ * @desc: MTEDESC descriptor word (0 means no MTE checks)
31
+ * Returns: the size of the region that can be copied without hitting
32
+ * an MTE tag failure
33
+ *
34
+ * Note that we assume that the caller has already checked the TBI
35
+ * and TCMA bits with mte_checks_needed() and an MTE check is definitely
36
+ * required.
37
+ */
38
+uint64_t mte_mops_probe_rev(CPUARMState *env, uint64_t ptr, uint64_t size,
39
+ uint32_t desc);
40
+
41
/**
42
* mte_check_fail: Record an MTE tag check failure
43
* @env: CPU env
44
diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c
45
index XXXXXXX..XXXXXXX 100644
46
--- a/target/arm/tcg/mte_helper.c
47
+++ b/target/arm/tcg/mte_helper.c
48
@@ -XXX,XX +XXX,XX @@ static int checkN(uint8_t *mem, int odd, int cmp, int count)
49
return n;
50
}
51
52
+/**
53
+ * checkNrev:
54
+ * @tag: tag memory to test
55
+ * @odd: true to begin testing at tags at odd nibble
56
+ * @cmp: the tag to compare against
57
+ * @count: number of tags to test
58
+ *
59
+ * Return the number of successful tests.
60
+ * Thus a return value < @count indicates a failure.
61
+ *
62
+ * This is like checkN, but it runs backwards, checking the
63
+ * tags starting with @tag and then the tags preceding it.
64
+ * This is needed by the backwards-memory-copying operations.
65
+ */
66
+static int checkNrev(uint8_t *mem, int odd, int cmp, int count)
67
+{
68
+ int n = 0, diff;
69
+
70
+ /* Replicate the test tag and compare. */
71
+ cmp *= 0x11;
72
+ diff = *mem-- ^ cmp;
73
+
74
+ if (!odd) {
75
+ goto start_even;
76
+ }
77
+
78
+ while (1) {
79
+ /* Test odd tag. */
80
+ if (unlikely((diff) & 0xf0)) {
81
+ break;
82
+ }
83
+ if (++n == count) {
84
+ break;
85
+ }
86
+
87
+ start_even:
88
+ /* Test even tag. */
89
+ if (unlikely((diff) & 0x0f)) {
90
+ break;
91
+ }
92
+ if (++n == count) {
93
+ break;
94
+ }
95
+
96
+ diff = *mem-- ^ cmp;
97
+ }
98
+ return n;
99
+}
100
+
101
/**
102
* mte_probe_int() - helper for mte_probe and mte_check
103
* @env: CPU environment
104
@@ -XXX,XX +XXX,XX @@ uint64_t mte_mops_probe(CPUARMState *env, uint64_t ptr, uint64_t size,
105
}
106
}
107
108
+uint64_t mte_mops_probe_rev(CPUARMState *env, uint64_t ptr, uint64_t size,
109
+ uint32_t desc)
110
+{
111
+ int mmu_idx, tag_count;
112
+ uint64_t ptr_tag, tag_first, tag_last;
113
+ void *mem;
114
+ bool w = FIELD_EX32(desc, MTEDESC, WRITE);
115
+ uint32_t n;
116
+
117
+ mmu_idx = FIELD_EX32(desc, MTEDESC, MIDX);
118
+ /* True probe; this will never fault */
119
+ mem = allocation_tag_mem_probe(env, mmu_idx, ptr,
120
+ w ? MMU_DATA_STORE : MMU_DATA_LOAD,
121
+ size, MMU_DATA_LOAD, true, 0);
122
+ if (!mem) {
123
+ return size;
124
+ }
125
+
126
+ /*
127
+ * TODO: checkNrev() is not designed for checks of the size we expect
128
+ * for FEAT_MOPS operations, so we should implement this differently.
129
+ * Maybe we should do something like
130
+ * if (region start and size are aligned nicely) {
131
+ * do direct loads of 64 tag bits at a time;
132
+ * } else {
133
+ * call checkN()
134
+ * }
135
+ */
136
+ /* Round the bounds to the tag granule, and compute the number of tags. */
137
+ ptr_tag = allocation_tag_from_addr(ptr);
138
+ tag_first = QEMU_ALIGN_DOWN(ptr - (size - 1), TAG_GRANULE);
139
+ tag_last = QEMU_ALIGN_DOWN(ptr, TAG_GRANULE);
140
+ tag_count = ((tag_last - tag_first) / TAG_GRANULE) + 1;
141
+ n = checkNrev(mem, ptr & TAG_GRANULE, ptr_tag, tag_count);
142
+ if (likely(n == tag_count)) {
143
+ return size;
144
+ }
145
+
146
+ /*
147
+ * Failure; for the first granule, it's at @ptr. Otherwise
148
+ * it's at the last byte of the nth granule. Calculate how
149
+ * many bytes we can access without hitting that failure.
150
+ */
151
+ if (n == 0) {
152
+ return 0;
153
+ } else {
154
+ return (n - 1) * TAG_GRANULE + ((ptr + 1) - tag_last);
155
+ }
156
+}
157
+
158
void mte_mops_set_tags(CPUARMState *env, uint64_t ptr, uint64_t size,
159
uint32_t desc)
160
{
161
--
162
2.34.1
diff view generated by jsdifflib
Deleted patch
1
The FEAT_MOPS CPY* instructions implement memory copies. These
2
come in both "always forwards" (memcpy-style) and "overlap OK"
3
(memmove-style) flavours.
4
1
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20230912140434.1333369-12-peter.maydell@linaro.org
8
---
9
target/arm/tcg/helper-a64.h | 7 +
10
target/arm/tcg/a64.decode | 14 +
11
target/arm/tcg/helper-a64.c | 454 +++++++++++++++++++++++++++++++++
12
target/arm/tcg/translate-a64.c | 60 +++++
13
4 files changed, 535 insertions(+)
14
15
diff --git a/target/arm/tcg/helper-a64.h b/target/arm/tcg/helper-a64.h
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/tcg/helper-a64.h
18
+++ b/target/arm/tcg/helper-a64.h
19
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(sete, void, env, i32, i32)
20
DEF_HELPER_3(setgp, void, env, i32, i32)
21
DEF_HELPER_3(setgm, void, env, i32, i32)
22
DEF_HELPER_3(setge, void, env, i32, i32)
23
+
24
+DEF_HELPER_4(cpyp, void, env, i32, i32, i32)
25
+DEF_HELPER_4(cpym, void, env, i32, i32, i32)
26
+DEF_HELPER_4(cpye, void, env, i32, i32, i32)
27
+DEF_HELPER_4(cpyfp, void, env, i32, i32, i32)
28
+DEF_HELPER_4(cpyfm, void, env, i32, i32, i32)
29
+DEF_HELPER_4(cpyfe, void, env, i32, i32, i32)
30
diff --git a/target/arm/tcg/a64.decode b/target/arm/tcg/a64.decode
31
index XXXXXXX..XXXXXXX 100644
32
--- a/target/arm/tcg/a64.decode
33
+++ b/target/arm/tcg/a64.decode
34
@@ -XXX,XX +XXX,XX @@ SETE 00 011001110 ..... 10 . . 01 ..... ..... @set
35
SETGP 00 011101110 ..... 00 . . 01 ..... ..... @set
36
SETGM 00 011101110 ..... 01 . . 01 ..... ..... @set
37
SETGE 00 011101110 ..... 10 . . 01 ..... ..... @set
38
+
39
+# Memmove/Memcopy: the CPY insns allow overlapping src/dest and
40
+# copy in the correct direction; the CPYF insns always copy forwards.
41
+#
42
+# options has the nontemporal and unpriv bits for src and dest
43
+&cpy rs rn rd options
44
+@cpy .. ... . ..... rs:5 options:4 .. rn:5 rd:5 &cpy
45
+
46
+CPYFP 00 011 0 01000 ..... .... 01 ..... ..... @cpy
47
+CPYFM 00 011 0 01010 ..... .... 01 ..... ..... @cpy
48
+CPYFE 00 011 0 01100 ..... .... 01 ..... ..... @cpy
49
+CPYP 00 011 1 01000 ..... .... 01 ..... ..... @cpy
50
+CPYM 00 011 1 01010 ..... .... 01 ..... ..... @cpy
51
+CPYE 00 011 1 01100 ..... .... 01 ..... ..... @cpy
52
diff --git a/target/arm/tcg/helper-a64.c b/target/arm/tcg/helper-a64.c
53
index XXXXXXX..XXXXXXX 100644
54
--- a/target/arm/tcg/helper-a64.c
55
+++ b/target/arm/tcg/helper-a64.c
56
@@ -XXX,XX +XXX,XX @@ static uint64_t page_limit(uint64_t addr)
57
return TARGET_PAGE_ALIGN(addr + 1) - addr;
58
}
59
60
+/*
61
+ * Return the number of bytes we can copy starting from addr and working
62
+ * backwards without crossing a page boundary.
63
+ */
64
+static uint64_t page_limit_rev(uint64_t addr)
65
+{
66
+ return (addr & ~TARGET_PAGE_MASK) + 1;
67
+}
68
+
69
/*
70
* Perform part of a memory set on an area of guest memory starting at
71
* toaddr (a dirty address) and extending for setsize bytes.
72
@@ -XXX,XX +XXX,XX @@ void HELPER(setge)(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc)
73
{
74
do_sete(env, syndrome, mtedesc, set_step_tags, true, GETPC());
75
}
76
+
77
+/*
78
+ * Perform part of a memory copy from the guest memory at fromaddr
79
+ * and extending for copysize bytes, to the guest memory at
80
+ * toaddr. Both addreses are dirty.
81
+ *
82
+ * Returns the number of bytes actually set, which might be less than
83
+ * copysize; the caller should loop until the whole copy has been done.
84
+ * The caller should ensure that the guest registers are correct
85
+ * for the possibility that the first byte of the copy encounters
86
+ * an exception or watchpoint. We guarantee not to take any faults
87
+ * for bytes other than the first.
88
+ */
89
+static uint64_t copy_step(CPUARMState *env, uint64_t toaddr, uint64_t fromaddr,
90
+ uint64_t copysize, int wmemidx, int rmemidx,
91
+ uint32_t *wdesc, uint32_t *rdesc, uintptr_t ra)
92
+{
93
+ void *rmem;
94
+ void *wmem;
95
+
96
+ /* Don't cross a page boundary on either source or destination */
97
+ copysize = MIN(copysize, page_limit(toaddr));
98
+ copysize = MIN(copysize, page_limit(fromaddr));
99
+ /*
100
+ * Handle MTE tag checks: either handle the tag mismatch for byte 0,
101
+ * or else copy up to but not including the byte with the mismatch.
102
+ */
103
+ if (*rdesc) {
104
+ uint64_t mtesize = mte_mops_probe(env, fromaddr, copysize, *rdesc);
105
+ if (mtesize == 0) {
106
+ mte_check_fail(env, *rdesc, fromaddr, ra);
107
+ *rdesc = 0;
108
+ } else {
109
+ copysize = MIN(copysize, mtesize);
110
+ }
111
+ }
112
+ if (*wdesc) {
113
+ uint64_t mtesize = mte_mops_probe(env, toaddr, copysize, *wdesc);
114
+ if (mtesize == 0) {
115
+ mte_check_fail(env, *wdesc, toaddr, ra);
116
+ *wdesc = 0;
117
+ } else {
118
+ copysize = MIN(copysize, mtesize);
119
+ }
120
+ }
121
+
122
+ toaddr = useronly_clean_ptr(toaddr);
123
+ fromaddr = useronly_clean_ptr(fromaddr);
124
+ /* Trapless lookup of whether we can get a host memory pointer */
125
+ wmem = tlb_vaddr_to_host(env, toaddr, MMU_DATA_STORE, wmemidx);
126
+ rmem = tlb_vaddr_to_host(env, fromaddr, MMU_DATA_LOAD, rmemidx);
127
+
128
+#ifndef CONFIG_USER_ONLY
129
+ /*
130
+ * If we don't have host memory for both source and dest then just
131
+ * do a single byte copy. This will handle watchpoints, invalid pages,
132
+ * etc correctly. For clean code pages, the next iteration will see
133
+ * the page dirty and will use the fast path.
134
+ */
135
+ if (unlikely(!rmem || !wmem)) {
136
+ uint8_t byte;
137
+ if (rmem) {
138
+ byte = *(uint8_t *)rmem;
139
+ } else {
140
+ byte = cpu_ldub_mmuidx_ra(env, fromaddr, rmemidx, ra);
141
+ }
142
+ if (wmem) {
143
+ *(uint8_t *)wmem = byte;
144
+ } else {
145
+ cpu_stb_mmuidx_ra(env, toaddr, byte, wmemidx, ra);
146
+ }
147
+ return 1;
148
+ }
149
+#endif
150
+ /* Easy case: just memmove the host memory */
151
+ memmove(wmem, rmem, copysize);
152
+ return copysize;
153
+}
154
+
155
+/*
156
+ * Do part of a backwards memory copy. Here toaddr and fromaddr point
157
+ * to the *last* byte to be copied.
158
+ */
159
+static uint64_t copy_step_rev(CPUARMState *env, uint64_t toaddr,
160
+ uint64_t fromaddr,
161
+ uint64_t copysize, int wmemidx, int rmemidx,
162
+ uint32_t *wdesc, uint32_t *rdesc, uintptr_t ra)
163
+{
164
+ void *rmem;
165
+ void *wmem;
166
+
167
+ /* Don't cross a page boundary on either source or destination */
168
+ copysize = MIN(copysize, page_limit_rev(toaddr));
169
+ copysize = MIN(copysize, page_limit_rev(fromaddr));
170
+
171
+ /*
172
+ * Handle MTE tag checks: either handle the tag mismatch for byte 0,
173
+ * or else copy up to but not including the byte with the mismatch.
174
+ */
175
+ if (*rdesc) {
176
+ uint64_t mtesize = mte_mops_probe_rev(env, fromaddr, copysize, *rdesc);
177
+ if (mtesize == 0) {
178
+ mte_check_fail(env, *rdesc, fromaddr, ra);
179
+ *rdesc = 0;
180
+ } else {
181
+ copysize = MIN(copysize, mtesize);
182
+ }
183
+ }
184
+ if (*wdesc) {
185
+ uint64_t mtesize = mte_mops_probe_rev(env, toaddr, copysize, *wdesc);
186
+ if (mtesize == 0) {
187
+ mte_check_fail(env, *wdesc, toaddr, ra);
188
+ *wdesc = 0;
189
+ } else {
190
+ copysize = MIN(copysize, mtesize);
191
+ }
192
+ }
193
+
194
+ toaddr = useronly_clean_ptr(toaddr);
195
+ fromaddr = useronly_clean_ptr(fromaddr);
196
+ /* Trapless lookup of whether we can get a host memory pointer */
197
+ wmem = tlb_vaddr_to_host(env, toaddr, MMU_DATA_STORE, wmemidx);
198
+ rmem = tlb_vaddr_to_host(env, fromaddr, MMU_DATA_LOAD, rmemidx);
199
+
200
+#ifndef CONFIG_USER_ONLY
201
+ /*
202
+ * If we don't have host memory for both source and dest then just
203
+ * do a single byte copy. This will handle watchpoints, invalid pages,
204
+ * etc correctly. For clean code pages, the next iteration will see
205
+ * the page dirty and will use the fast path.
206
+ */
207
+ if (unlikely(!rmem || !wmem)) {
208
+ uint8_t byte;
209
+ if (rmem) {
210
+ byte = *(uint8_t *)rmem;
211
+ } else {
212
+ byte = cpu_ldub_mmuidx_ra(env, fromaddr, rmemidx, ra);
213
+ }
214
+ if (wmem) {
215
+ *(uint8_t *)wmem = byte;
216
+ } else {
217
+ cpu_stb_mmuidx_ra(env, toaddr, byte, wmemidx, ra);
218
+ }
219
+ return 1;
220
+ }
221
+#endif
222
+ /*
223
+ * Easy case: just memmove the host memory. Note that wmem and
224
+ * rmem here point to the *last* byte to copy.
225
+ */
226
+ memmove(wmem - (copysize - 1), rmem - (copysize - 1), copysize);
227
+ return copysize;
228
+}
229
+
230
+/*
231
+ * for the Memory Copy operation, our implementation chooses always
232
+ * to use "option A", where we update Xd and Xs to the final addresses
233
+ * in the CPYP insn, and then in CPYM and CPYE only need to update Xn.
234
+ *
235
+ * @env: CPU
236
+ * @syndrome: syndrome value for mismatch exceptions
237
+ * (also contains the register numbers we need to use)
238
+ * @wdesc: MTE descriptor for the writes (destination)
239
+ * @rdesc: MTE descriptor for the reads (source)
240
+ * @move: true if this is CPY (memmove), false for CPYF (memcpy forwards)
241
+ */
242
+static void do_cpyp(CPUARMState *env, uint32_t syndrome, uint32_t wdesc,
243
+ uint32_t rdesc, uint32_t move, uintptr_t ra)
244
+{
245
+ int rd = mops_destreg(syndrome);
246
+ int rs = mops_srcreg(syndrome);
247
+ int rn = mops_sizereg(syndrome);
248
+ uint32_t rmemidx = FIELD_EX32(rdesc, MTEDESC, MIDX);
249
+ uint32_t wmemidx = FIELD_EX32(wdesc, MTEDESC, MIDX);
250
+ bool forwards = true;
251
+ uint64_t toaddr = env->xregs[rd];
252
+ uint64_t fromaddr = env->xregs[rs];
253
+ uint64_t copysize = env->xregs[rn];
254
+ uint64_t stagecopysize, step;
255
+
256
+ check_mops_enabled(env, ra);
257
+
258
+
259
+ if (move) {
260
+ /*
261
+ * Copy backwards if necessary. The direction for a non-overlapping
262
+ * copy is IMPDEF; we choose forwards.
263
+ */
264
+ if (copysize > 0x007FFFFFFFFFFFFFULL) {
265
+ copysize = 0x007FFFFFFFFFFFFFULL;
266
+ }
267
+ uint64_t fs = extract64(fromaddr, 0, 56);
268
+ uint64_t ts = extract64(toaddr, 0, 56);
269
+ uint64_t fe = extract64(fromaddr + copysize, 0, 56);
270
+
271
+ if (fs < ts && fe > ts) {
272
+ forwards = false;
273
+ }
274
+ } else {
275
+ if (copysize > INT64_MAX) {
276
+ copysize = INT64_MAX;
277
+ }
278
+ }
279
+
280
+ if (!mte_checks_needed(fromaddr, rdesc)) {
281
+ rdesc = 0;
282
+ }
283
+ if (!mte_checks_needed(toaddr, wdesc)) {
284
+ wdesc = 0;
285
+ }
286
+
287
+ if (forwards) {
288
+ stagecopysize = MIN(copysize, page_limit(toaddr));
289
+ stagecopysize = MIN(stagecopysize, page_limit(fromaddr));
290
+ while (stagecopysize) {
291
+ env->xregs[rd] = toaddr;
292
+ env->xregs[rs] = fromaddr;
293
+ env->xregs[rn] = copysize;
294
+ step = copy_step(env, toaddr, fromaddr, stagecopysize,
295
+ wmemidx, rmemidx, &wdesc, &rdesc, ra);
296
+ toaddr += step;
297
+ fromaddr += step;
298
+ copysize -= step;
299
+ stagecopysize -= step;
300
+ }
301
+ /* Insn completed, so update registers to the Option A format */
302
+ env->xregs[rd] = toaddr + copysize;
303
+ env->xregs[rs] = fromaddr + copysize;
304
+ env->xregs[rn] = -copysize;
305
+ } else {
306
+ /*
307
+ * In a reverse copy the to and from addrs in Xs and Xd are the start
308
+ * of the range, but it's more convenient for us to work with pointers
309
+ * to the last byte being copied.
310
+ */
311
+ toaddr += copysize - 1;
312
+ fromaddr += copysize - 1;
313
+ stagecopysize = MIN(copysize, page_limit_rev(toaddr));
314
+ stagecopysize = MIN(stagecopysize, page_limit_rev(fromaddr));
315
+ while (stagecopysize) {
316
+ env->xregs[rn] = copysize;
317
+ step = copy_step_rev(env, toaddr, fromaddr, stagecopysize,
318
+ wmemidx, rmemidx, &wdesc, &rdesc, ra);
319
+ copysize -= step;
320
+ stagecopysize -= step;
321
+ toaddr -= step;
322
+ fromaddr -= step;
323
+ }
324
+ /*
325
+ * Insn completed, so update registers to the Option A format.
326
+ * For a reverse copy this is no different to the CPYP input format.
327
+ */
328
+ env->xregs[rn] = copysize;
329
+ }
330
+
331
+ /* Set NZCV = 0000 to indicate we are an Option A implementation */
332
+ env->NF = 0;
333
+ env->ZF = 1; /* our env->ZF encoding is inverted */
334
+ env->CF = 0;
335
+ env->VF = 0;
336
+ return;
337
+}
338
+
339
+void HELPER(cpyp)(CPUARMState *env, uint32_t syndrome, uint32_t wdesc,
340
+ uint32_t rdesc)
341
+{
342
+ do_cpyp(env, syndrome, wdesc, rdesc, true, GETPC());
343
+}
344
+
345
+void HELPER(cpyfp)(CPUARMState *env, uint32_t syndrome, uint32_t wdesc,
346
+ uint32_t rdesc)
347
+{
348
+ do_cpyp(env, syndrome, wdesc, rdesc, false, GETPC());
349
+}
350
+
351
+static void do_cpym(CPUARMState *env, uint32_t syndrome, uint32_t wdesc,
352
+ uint32_t rdesc, uint32_t move, uintptr_t ra)
353
+{
354
+ /* Main: we choose to copy until less than a page remaining */
355
+ CPUState *cs = env_cpu(env);
356
+ int rd = mops_destreg(syndrome);
357
+ int rs = mops_srcreg(syndrome);
358
+ int rn = mops_sizereg(syndrome);
359
+ uint32_t rmemidx = FIELD_EX32(rdesc, MTEDESC, MIDX);
360
+ uint32_t wmemidx = FIELD_EX32(wdesc, MTEDESC, MIDX);
361
+ bool forwards = true;
362
+ uint64_t toaddr, fromaddr, copysize, step;
363
+
364
+ check_mops_enabled(env, ra);
365
+
366
+ /* We choose to NOP out "no data to copy" before consistency checks */
367
+ if (env->xregs[rn] == 0) {
368
+ return;
369
+ }
370
+
371
+ check_mops_wrong_option(env, syndrome, ra);
372
+
373
+ if (move) {
374
+ forwards = (int64_t)env->xregs[rn] < 0;
375
+ }
376
+
377
+ if (forwards) {
378
+ toaddr = env->xregs[rd] + env->xregs[rn];
379
+ fromaddr = env->xregs[rs] + env->xregs[rn];
380
+ copysize = -env->xregs[rn];
381
+ } else {
382
+ copysize = env->xregs[rn];
383
+ /* This toaddr and fromaddr point to the *last* byte to copy */
384
+ toaddr = env->xregs[rd] + copysize - 1;
385
+ fromaddr = env->xregs[rs] + copysize - 1;
386
+ }
387
+
388
+ if (!mte_checks_needed(fromaddr, rdesc)) {
389
+ rdesc = 0;
390
+ }
391
+ if (!mte_checks_needed(toaddr, wdesc)) {
392
+ wdesc = 0;
393
+ }
394
+
395
+ /* Our implementation has no particular parameter requirements for CPYM */
396
+
397
+ /* Do the actual memmove */
398
+ if (forwards) {
399
+ while (copysize >= TARGET_PAGE_SIZE) {
400
+ step = copy_step(env, toaddr, fromaddr, copysize,
401
+ wmemidx, rmemidx, &wdesc, &rdesc, ra);
402
+ toaddr += step;
403
+ fromaddr += step;
404
+ copysize -= step;
405
+ env->xregs[rn] = -copysize;
406
+ if (copysize >= TARGET_PAGE_SIZE &&
407
+ unlikely(cpu_loop_exit_requested(cs))) {
408
+ cpu_loop_exit_restore(cs, ra);
409
+ }
410
+ }
411
+ } else {
412
+ while (copysize >= TARGET_PAGE_SIZE) {
413
+ step = copy_step_rev(env, toaddr, fromaddr, copysize,
414
+ wmemidx, rmemidx, &wdesc, &rdesc, ra);
415
+ toaddr -= step;
416
+ fromaddr -= step;
417
+ copysize -= step;
418
+ env->xregs[rn] = copysize;
419
+ if (copysize >= TARGET_PAGE_SIZE &&
420
+ unlikely(cpu_loop_exit_requested(cs))) {
421
+ cpu_loop_exit_restore(cs, ra);
422
+ }
423
+ }
424
+ }
425
+}
426
+
427
+void HELPER(cpym)(CPUARMState *env, uint32_t syndrome, uint32_t wdesc,
428
+ uint32_t rdesc)
429
+{
430
+ do_cpym(env, syndrome, wdesc, rdesc, true, GETPC());
431
+}
432
+
433
+void HELPER(cpyfm)(CPUARMState *env, uint32_t syndrome, uint32_t wdesc,
434
+ uint32_t rdesc)
435
+{
436
+ do_cpym(env, syndrome, wdesc, rdesc, false, GETPC());
437
+}
438
+
439
+static void do_cpye(CPUARMState *env, uint32_t syndrome, uint32_t wdesc,
440
+ uint32_t rdesc, uint32_t move, uintptr_t ra)
441
+{
442
+ /* Epilogue: do the last partial page */
443
+ int rd = mops_destreg(syndrome);
444
+ int rs = mops_srcreg(syndrome);
445
+ int rn = mops_sizereg(syndrome);
446
+ uint32_t rmemidx = FIELD_EX32(rdesc, MTEDESC, MIDX);
447
+ uint32_t wmemidx = FIELD_EX32(wdesc, MTEDESC, MIDX);
448
+ bool forwards = true;
449
+ uint64_t toaddr, fromaddr, copysize, step;
450
+
451
+ check_mops_enabled(env, ra);
452
+
453
+ /* We choose to NOP out "no data to copy" before consistency checks */
454
+ if (env->xregs[rn] == 0) {
455
+ return;
456
+ }
457
+
458
+ check_mops_wrong_option(env, syndrome, ra);
459
+
460
+ if (move) {
461
+ forwards = (int64_t)env->xregs[rn] < 0;
462
+ }
463
+
464
+ if (forwards) {
465
+ toaddr = env->xregs[rd] + env->xregs[rn];
466
+ fromaddr = env->xregs[rs] + env->xregs[rn];
467
+ copysize = -env->xregs[rn];
468
+ } else {
469
+ copysize = env->xregs[rn];
470
+ /* This toaddr and fromaddr point to the *last* byte to copy */
471
+ toaddr = env->xregs[rd] + copysize - 1;
472
+ fromaddr = env->xregs[rs] + copysize - 1;
473
+ }
474
+
475
+ if (!mte_checks_needed(fromaddr, rdesc)) {
476
+ rdesc = 0;
477
+ }
478
+ if (!mte_checks_needed(toaddr, wdesc)) {
479
+ wdesc = 0;
480
+ }
481
+
482
+ /* Check the size; we don't want to have do a check-for-interrupts */
483
+ if (copysize >= TARGET_PAGE_SIZE) {
484
+ raise_exception_ra(env, EXCP_UDEF, syndrome,
485
+ mops_mismatch_exception_target_el(env), ra);
486
+ }
487
+
488
+ /* Do the actual memmove */
489
+ if (forwards) {
490
+ while (copysize > 0) {
491
+ step = copy_step(env, toaddr, fromaddr, copysize,
492
+ wmemidx, rmemidx, &wdesc, &rdesc, ra);
493
+ toaddr += step;
494
+ fromaddr += step;
495
+ copysize -= step;
496
+ env->xregs[rn] = -copysize;
497
+ }
498
+ } else {
499
+ while (copysize > 0) {
500
+ step = copy_step_rev(env, toaddr, fromaddr, copysize,
501
+ wmemidx, rmemidx, &wdesc, &rdesc, ra);
502
+ toaddr -= step;
503
+ fromaddr -= step;
504
+ copysize -= step;
505
+ env->xregs[rn] = copysize;
506
+ }
507
+ }
508
+}
509
+
510
+void HELPER(cpye)(CPUARMState *env, uint32_t syndrome, uint32_t wdesc,
511
+ uint32_t rdesc)
512
+{
513
+ do_cpye(env, syndrome, wdesc, rdesc, true, GETPC());
514
+}
515
+
516
+void HELPER(cpyfe)(CPUARMState *env, uint32_t syndrome, uint32_t wdesc,
517
+ uint32_t rdesc)
518
+{
519
+ do_cpye(env, syndrome, wdesc, rdesc, false, GETPC());
520
+}
521
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
522
index XXXXXXX..XXXXXXX 100644
523
--- a/target/arm/tcg/translate-a64.c
524
+++ b/target/arm/tcg/translate-a64.c
525
@@ -XXX,XX +XXX,XX @@ TRANS_FEAT(SETGP, aa64_mops, do_SET, a, false, true, gen_helper_setgp)
526
TRANS_FEAT(SETGM, aa64_mops, do_SET, a, false, true, gen_helper_setgm)
527
TRANS_FEAT(SETGE, aa64_mops, do_SET, a, true, true, gen_helper_setge)
528
529
+typedef void CpyFn(TCGv_env, TCGv_i32, TCGv_i32, TCGv_i32);
530
+
531
+static bool do_CPY(DisasContext *s, arg_cpy *a, bool is_epilogue, CpyFn fn)
532
+{
533
+ int rmemidx, wmemidx;
534
+ uint32_t syndrome, rdesc = 0, wdesc = 0;
535
+ bool wunpriv = extract32(a->options, 0, 1);
536
+ bool runpriv = extract32(a->options, 1, 1);
537
+
538
+ /*
539
+ * UNPREDICTABLE cases: we choose to UNDEF, which allows
540
+ * us to pull this check before the CheckMOPSEnabled() test
541
+ * (which we do in the helper function)
542
+ */
543
+ if (a->rs == a->rn || a->rs == a->rd || a->rn == a->rd ||
544
+ a->rd == 31 || a->rs == 31 || a->rn == 31) {
545
+ return false;
546
+ }
547
+
548
+ rmemidx = get_a64_user_mem_index(s, runpriv);
549
+ wmemidx = get_a64_user_mem_index(s, wunpriv);
550
+
551
+ /*
552
+ * We pass option_a == true, matching our implementation;
553
+ * we pass wrong_option == false: helper function may set that bit.
554
+ */
555
+ syndrome = syn_mop(false, false, a->options, is_epilogue,
556
+ false, true, a->rd, a->rs, a->rn);
557
+
558
+ /* If we need to do MTE tag checking, assemble the descriptors */
559
+ if (s->mte_active[runpriv]) {
560
+ rdesc = FIELD_DP32(rdesc, MTEDESC, TBI, s->tbid);
561
+ rdesc = FIELD_DP32(rdesc, MTEDESC, TCMA, s->tcma);
562
+ }
563
+ if (s->mte_active[wunpriv]) {
564
+ wdesc = FIELD_DP32(wdesc, MTEDESC, TBI, s->tbid);
565
+ wdesc = FIELD_DP32(wdesc, MTEDESC, TCMA, s->tcma);
566
+ wdesc = FIELD_DP32(wdesc, MTEDESC, WRITE, true);
567
+ }
568
+ /* The helper function needs these parts of the descriptor regardless */
569
+ rdesc = FIELD_DP32(rdesc, MTEDESC, MIDX, rmemidx);
570
+ wdesc = FIELD_DP32(wdesc, MTEDESC, MIDX, wmemidx);
571
+
572
+ /*
573
+ * The helper needs the register numbers, but since they're in
574
+ * the syndrome anyway, we let it extract them from there rather
575
+ * than passing in an extra three integer arguments.
576
+ */
577
+ fn(cpu_env, tcg_constant_i32(syndrome), tcg_constant_i32(wdesc),
578
+ tcg_constant_i32(rdesc));
579
+ return true;
580
+}
581
+
582
+TRANS_FEAT(CPYP, aa64_mops, do_CPY, a, false, gen_helper_cpyp)
583
+TRANS_FEAT(CPYM, aa64_mops, do_CPY, a, false, gen_helper_cpym)
584
+TRANS_FEAT(CPYE, aa64_mops, do_CPY, a, true, gen_helper_cpye)
585
+TRANS_FEAT(CPYFP, aa64_mops, do_CPY, a, false, gen_helper_cpyfp)
586
+TRANS_FEAT(CPYFM, aa64_mops, do_CPY, a, false, gen_helper_cpyfm)
587
+TRANS_FEAT(CPYFE, aa64_mops, do_CPY, a, true, gen_helper_cpyfe)
588
+
589
typedef void ArithTwoOp(TCGv_i64, TCGv_i64, TCGv_i64);
590
591
static bool gen_rri(DisasContext *s, arg_rri_sf *a,
592
--
593
2.34.1
diff view generated by jsdifflib
Deleted patch
1
Enable FEAT_MOPS on the AArch64 'max' CPU, and add it to
2
the list of features we implement.
3
1
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20230912140434.1333369-13-peter.maydell@linaro.org
7
---
8
docs/system/arm/emulation.rst | 1 +
9
linux-user/elfload.c | 1 +
10
target/arm/tcg/cpu64.c | 1 +
11
3 files changed, 3 insertions(+)
12
13
diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst
14
index XXXXXXX..XXXXXXX 100644
15
--- a/docs/system/arm/emulation.rst
16
+++ b/docs/system/arm/emulation.rst
17
@@ -XXX,XX +XXX,XX @@ the following architecture extensions:
18
- FEAT_LSE (Large System Extensions)
19
- FEAT_LSE2 (Large System Extensions v2)
20
- FEAT_LVA (Large Virtual Address space)
21
+- FEAT_MOPS (Standardization of memory operations)
22
- FEAT_MTE (Memory Tagging Extension)
23
- FEAT_MTE2 (Memory Tagging Extension)
24
- FEAT_MTE3 (MTE Asymmetric Fault Handling)
25
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
26
index XXXXXXX..XXXXXXX 100644
27
--- a/linux-user/elfload.c
28
+++ b/linux-user/elfload.c
29
@@ -XXX,XX +XXX,XX @@ uint32_t get_elf_hwcap2(void)
30
GET_FEATURE_ID(aa64_sme_i16i64, ARM_HWCAP2_A64_SME_I16I64);
31
GET_FEATURE_ID(aa64_sme_fa64, ARM_HWCAP2_A64_SME_FA64);
32
GET_FEATURE_ID(aa64_hbc, ARM_HWCAP2_A64_HBC);
33
+ GET_FEATURE_ID(aa64_mops, ARM_HWCAP2_A64_MOPS);
34
35
return hwcaps;
36
}
37
diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c
38
index XXXXXXX..XXXXXXX 100644
39
--- a/target/arm/tcg/cpu64.c
40
+++ b/target/arm/tcg/cpu64.c
41
@@ -XXX,XX +XXX,XX @@ void aarch64_max_tcg_initfn(Object *obj)
42
cpu->isar.id_aa64isar1 = t;
43
44
t = cpu->isar.id_aa64isar2;
45
+ t = FIELD_DP64(t, ID_AA64ISAR2, MOPS, 1); /* FEAT_MOPS */
46
t = FIELD_DP64(t, ID_AA64ISAR2, BC, 1); /* FEAT_HBC */
47
cpu->isar.id_aa64isar2 = t;
48
49
--
50
2.34.1
diff view generated by jsdifflib
Deleted patch
1
Avoid a dynamic stack allocation in qjack_client_init(), by using
2
a g_autofree heap allocation instead.
3
1
4
(We stick with allocate + snprintf() because the JACK API requires
5
the name to be no more than its maximum size, so g_strdup_printf()
6
would require an extra truncation step.)
7
8
The codebase has very few VLAs, and if we can get rid of them all we
9
can make the compiler error on new additions. This is a defensive
10
measure against security bugs where an on-stack dynamic allocation
11
isn't correctly size-checked (e.g. CVE-2021-3527).
12
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
15
Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com>
16
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
17
Message-id: 20230818155846.1651287-2-peter.maydell@linaro.org
18
---
19
audio/jackaudio.c | 5 +++--
20
1 file changed, 3 insertions(+), 2 deletions(-)
21
22
diff --git a/audio/jackaudio.c b/audio/jackaudio.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/audio/jackaudio.c
25
+++ b/audio/jackaudio.c
26
@@ -XXX,XX +XXX,XX @@ static void qjack_client_connect_ports(QJackClient *c)
27
static int qjack_client_init(QJackClient *c)
28
{
29
jack_status_t status;
30
- char client_name[jack_client_name_size()];
31
+ int client_name_len = jack_client_name_size(); /* includes NUL */
32
+ g_autofree char *client_name = g_new(char, client_name_len);
33
jack_options_t options = JackNullOption;
34
35
if (c->state == QJACK_STATE_RUNNING) {
36
@@ -XXX,XX +XXX,XX @@ static int qjack_client_init(QJackClient *c)
37
38
c->connect_ports = true;
39
40
- snprintf(client_name, sizeof(client_name), "%s-%s",
41
+ snprintf(client_name, client_name_len, "%s-%s",
42
c->out ? "out" : "in",
43
c->opt->client_name ? c->opt->client_name : audio_application_name());
44
45
--
46
2.34.1
47
48
diff view generated by jsdifflib
Deleted patch
1
Avoid a dynamic stack allocation in qjack_process(). Since this
2
function is a JACK process callback, we are not permitted to malloc()
3
here, so we allocate a working buffer in qjack_client_init() instead.
4
1
5
The codebase has very few VLAs, and if we can get rid of them all we
6
can make the compiler error on new additions. This is a defensive
7
measure against security bugs where an on-stack dynamic allocation
8
isn't correctly size-checked (e.g. CVE-2021-3527).
9
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
12
Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com>
13
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
14
Message-id: 20230818155846.1651287-3-peter.maydell@linaro.org
15
---
16
audio/jackaudio.c | 16 +++++++++++-----
17
1 file changed, 11 insertions(+), 5 deletions(-)
18
19
diff --git a/audio/jackaudio.c b/audio/jackaudio.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/audio/jackaudio.c
22
+++ b/audio/jackaudio.c
23
@@ -XXX,XX +XXX,XX @@ typedef struct QJackClient {
24
int buffersize;
25
jack_port_t **port;
26
QJackBuffer fifo;
27
+
28
+ /* Used as workspace by qjack_process() */
29
+ float **process_buffers;
30
}
31
QJackClient;
32
33
@@ -XXX,XX +XXX,XX @@ static int qjack_process(jack_nframes_t nframes, void *arg)
34
}
35
36
/* get the buffers for the ports */
37
- float *buffers[c->nchannels];
38
for (int i = 0; i < c->nchannels; ++i) {
39
- buffers[i] = jack_port_get_buffer(c->port[i], nframes);
40
+ c->process_buffers[i] = jack_port_get_buffer(c->port[i], nframes);
41
}
42
43
if (c->out) {
44
if (likely(c->enabled)) {
45
- qjack_buffer_read_l(&c->fifo, buffers, nframes);
46
+ qjack_buffer_read_l(&c->fifo, c->process_buffers, nframes);
47
} else {
48
for (int i = 0; i < c->nchannels; ++i) {
49
- memset(buffers[i], 0, nframes * sizeof(float));
50
+ memset(c->process_buffers[i], 0, nframes * sizeof(float));
51
}
52
}
53
} else {
54
if (likely(c->enabled)) {
55
- qjack_buffer_write_l(&c->fifo, buffers, nframes);
56
+ qjack_buffer_write_l(&c->fifo, c->process_buffers, nframes);
57
}
58
}
59
60
@@ -XXX,XX +XXX,XX @@ static int qjack_client_init(QJackClient *c)
61
jack_get_client_name(c->client));
62
}
63
64
+ /* Allocate working buffer for process callback */
65
+ c->process_buffers = g_new(float *, c->nchannels);
66
+
67
jack_set_process_callback(c->client, qjack_process , c);
68
jack_set_port_registration_callback(c->client, qjack_port_registration, c);
69
jack_set_xrun_callback(c->client, qjack_xrun, c);
70
@@ -XXX,XX +XXX,XX @@ static void qjack_client_fini_locked(QJackClient *c)
71
72
qjack_buffer_free(&c->fifo);
73
g_free(c->port);
74
+ g_free(c->process_buffers);
75
76
c->state = QJACK_STATE_DISCONNECTED;
77
/* fallthrough */
78
--
79
2.34.1
80
81
diff view generated by jsdifflib
Deleted patch
1
From: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
2
1
3
Armv8.1+ cpus have Virtual Host Extension (VHE) which added non-secure
4
EL2 virtual timer.
5
6
This change adds it to fullfil Arm BSA (Base System Architecture)
7
requirements.
8
9
Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
10
Message-id: 20230913140610.214893-2-marcin.juszkiewicz@linaro.org
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
14
hw/arm/sbsa-ref.c | 2 ++
15
1 file changed, 2 insertions(+)
16
17
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/arm/sbsa-ref.c
20
+++ b/hw/arm/sbsa-ref.c
21
@@ -XXX,XX +XXX,XX @@
22
#define ARCH_TIMER_S_EL1_IRQ 13
23
#define ARCH_TIMER_NS_EL1_IRQ 14
24
#define ARCH_TIMER_NS_EL2_IRQ 10
25
+#define ARCH_TIMER_NS_EL2_VIRT_IRQ 12
26
27
enum {
28
SBSA_FLASH,
29
@@ -XXX,XX +XXX,XX @@ static void create_gic(SBSAMachineState *sms, MemoryRegion *mem)
30
[GTIMER_VIRT] = ARCH_TIMER_VIRT_IRQ,
31
[GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ,
32
[GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ,
33
+ [GTIMER_HYPVIRT] = ARCH_TIMER_NS_EL2_VIRT_IRQ,
34
};
35
36
for (irq = 0; irq < ARRAY_SIZE(timer_irq); irq++) {
37
--
38
2.34.1
diff view generated by jsdifflib
Deleted patch
1
From: Viktor Prutyanov <viktor@daynix.com>
2
1
3
PE export name check introduced in d399d6b179 isn't reliable enough,
4
because a page with the export directory may be not present for some
5
reason. On the other hand, elf2dmp retrieves the PDB name in any case.
6
It can be also used to check that a PE image is the kernel image. So,
7
check PDB name when searching for Windows kernel image.
8
9
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2165917
10
11
Signed-off-by: Viktor Prutyanov <viktor@daynix.com>
12
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
13
Message-id: 20230915170153.10959-2-viktor@daynix.com
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
---
16
contrib/elf2dmp/main.c | 93 +++++++++++++++---------------------------
17
1 file changed, 33 insertions(+), 60 deletions(-)
18
19
diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/contrib/elf2dmp/main.c
22
+++ b/contrib/elf2dmp/main.c
23
@@ -XXX,XX +XXX,XX @@ static int write_dump(struct pa_space *ps,
24
return fclose(dmp_file);
25
}
26
27
-static bool pe_check_export_name(uint64_t base, void *start_addr,
28
- struct va_space *vs)
29
-{
30
- IMAGE_EXPORT_DIRECTORY export_dir;
31
- const char *pe_name;
32
-
33
- if (pe_get_data_dir_entry(base, start_addr, IMAGE_FILE_EXPORT_DIRECTORY,
34
- &export_dir, sizeof(export_dir), vs)) {
35
- return false;
36
- }
37
-
38
- pe_name = va_space_resolve(vs, base + export_dir.Name);
39
- if (!pe_name) {
40
- return false;
41
- }
42
-
43
- return !strcmp(pe_name, PE_NAME);
44
-}
45
-
46
-static int pe_get_pdb_symstore_hash(uint64_t base, void *start_addr,
47
- char *hash, struct va_space *vs)
48
+static bool pe_check_pdb_name(uint64_t base, void *start_addr,
49
+ struct va_space *vs, OMFSignatureRSDS *rsds)
50
{
51
const char sign_rsds[4] = "RSDS";
52
IMAGE_DEBUG_DIRECTORY debug_dir;
53
- OMFSignatureRSDS rsds;
54
- char *pdb_name;
55
- size_t pdb_name_sz;
56
- size_t i;
57
+ char pdb_name[sizeof(PDB_NAME)];
58
59
if (pe_get_data_dir_entry(base, start_addr, IMAGE_FILE_DEBUG_DIRECTORY,
60
&debug_dir, sizeof(debug_dir), vs)) {
61
eprintf("Failed to get Debug Directory\n");
62
- return 1;
63
+ return false;
64
}
65
66
if (debug_dir.Type != IMAGE_DEBUG_TYPE_CODEVIEW) {
67
- return 1;
68
+ eprintf("Debug Directory type is not CodeView\n");
69
+ return false;
70
}
71
72
if (va_space_rw(vs,
73
base + debug_dir.AddressOfRawData,
74
- &rsds, sizeof(rsds), 0)) {
75
- return 1;
76
+ rsds, sizeof(*rsds), 0)) {
77
+ eprintf("Failed to resolve OMFSignatureRSDS\n");
78
+ return false;
79
}
80
81
- printf("CodeView signature is \'%.4s\'\n", rsds.Signature);
82
-
83
- if (memcmp(&rsds.Signature, sign_rsds, sizeof(sign_rsds))) {
84
- return 1;
85
+ if (memcmp(&rsds->Signature, sign_rsds, sizeof(sign_rsds))) {
86
+ eprintf("CodeView signature is \'%.4s\', \'%s\' expected\n",
87
+ rsds->Signature, sign_rsds);
88
+ return false;
89
}
90
91
- pdb_name_sz = debug_dir.SizeOfData - sizeof(rsds);
92
- pdb_name = malloc(pdb_name_sz);
93
- if (!pdb_name) {
94
- return 1;
95
+ if (debug_dir.SizeOfData - sizeof(*rsds) != sizeof(PDB_NAME)) {
96
+ eprintf("PDB name size doesn't match\n");
97
+ return false;
98
}
99
100
if (va_space_rw(vs, base + debug_dir.AddressOfRawData +
101
- offsetof(OMFSignatureRSDS, name), pdb_name, pdb_name_sz, 0)) {
102
- free(pdb_name);
103
- return 1;
104
+ offsetof(OMFSignatureRSDS, name), pdb_name, sizeof(PDB_NAME),
105
+ 0)) {
106
+ eprintf("Failed to resolve PDB name\n");
107
+ return false;
108
}
109
110
printf("PDB name is \'%s\', \'%s\' expected\n", pdb_name, PDB_NAME);
111
112
- if (strcmp(pdb_name, PDB_NAME)) {
113
- eprintf("Unexpected PDB name, it seems the kernel isn't found\n");
114
- free(pdb_name);
115
- return 1;
116
- }
117
+ return !strcmp(pdb_name, PDB_NAME);
118
+}
119
120
- free(pdb_name);
121
-
122
- sprintf(hash, "%.08x%.04x%.04x%.02x%.02x", rsds.guid.a, rsds.guid.b,
123
- rsds.guid.c, rsds.guid.d[0], rsds.guid.d[1]);
124
+static void pe_get_pdb_symstore_hash(OMFSignatureRSDS *rsds, char *hash)
125
+{
126
+ sprintf(hash, "%.08x%.04x%.04x%.02x%.02x", rsds->guid.a, rsds->guid.b,
127
+ rsds->guid.c, rsds->guid.d[0], rsds->guid.d[1]);
128
hash += 20;
129
- for (i = 0; i < 6; i++, hash += 2) {
130
- sprintf(hash, "%.02x", rsds.guid.e[i]);
131
+ for (unsigned int i = 0; i < 6; i++, hash += 2) {
132
+ sprintf(hash, "%.02x", rsds->guid.e[i]);
133
}
134
135
- sprintf(hash, "%.01x", rsds.age);
136
-
137
- return 0;
138
+ sprintf(hash, "%.01x", rsds->age);
139
}
140
141
int main(int argc, char *argv[])
142
@@ -XXX,XX +XXX,XX @@ int main(int argc, char *argv[])
143
KDDEBUGGER_DATA64 *kdbg;
144
uint64_t KdVersionBlock;
145
bool kernel_found = false;
146
+ OMFSignatureRSDS rsds;
147
148
if (argc != 3) {
149
eprintf("usage:\n\t%s elf_file dmp_file\n", argv[0]);
150
@@ -XXX,XX +XXX,XX @@ int main(int argc, char *argv[])
151
}
152
153
if (*(uint16_t *)nt_start_addr == 0x5a4d) { /* MZ */
154
- if (pe_check_export_name(KernBase, nt_start_addr, &vs)) {
155
+ printf("Checking candidate KernBase = 0x%016"PRIx64"\n", KernBase);
156
+ if (pe_check_pdb_name(KernBase, nt_start_addr, &vs, &rsds)) {
157
kernel_found = true;
158
break;
159
}
160
@@ -XXX,XX +XXX,XX @@ int main(int argc, char *argv[])
161
printf("KernBase = 0x%016"PRIx64", signature is \'%.2s\'\n", KernBase,
162
(char *)nt_start_addr);
163
164
- if (pe_get_pdb_symstore_hash(KernBase, nt_start_addr, pdb_hash, &vs)) {
165
- eprintf("Failed to get PDB symbol store hash\n");
166
- err = 1;
167
- goto out_ps;
168
- }
169
+ pe_get_pdb_symstore_hash(&rsds, pdb_hash);
170
171
sprintf(pdb_url, "%s%s/%s/%s", SYM_URL_BASE, PDB_NAME, pdb_hash, PDB_NAME);
172
printf("PDB URL is %s\n", pdb_url);
173
--
174
2.34.1
diff view generated by jsdifflib
Deleted patch
1
From: Viktor Prutyanov <viktor@daynix.com>
2
1
3
Physical memory ranges may not be aligned to page size in QEMU ELF, but
4
DMP can only contain page-aligned runs. So, align them.
5
6
Signed-off-by: Viktor Prutyanov <viktor@daynix.com>
7
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
8
Message-id: 20230915170153.10959-3-viktor@daynix.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
contrib/elf2dmp/addrspace.h | 1 +
12
contrib/elf2dmp/addrspace.c | 31 +++++++++++++++++++++++++++++--
13
contrib/elf2dmp/main.c | 5 +++--
14
3 files changed, 33 insertions(+), 4 deletions(-)
15
16
diff --git a/contrib/elf2dmp/addrspace.h b/contrib/elf2dmp/addrspace.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/contrib/elf2dmp/addrspace.h
19
+++ b/contrib/elf2dmp/addrspace.h
20
@@ -XXX,XX +XXX,XX @@
21
22
#define ELF2DMP_PAGE_BITS 12
23
#define ELF2DMP_PAGE_SIZE (1ULL << ELF2DMP_PAGE_BITS)
24
+#define ELF2DMP_PAGE_MASK (ELF2DMP_PAGE_SIZE - 1)
25
#define ELF2DMP_PFN_MASK (~(ELF2DMP_PAGE_SIZE - 1))
26
27
#define INVALID_PA UINT64_MAX
28
diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/contrib/elf2dmp/addrspace.c
31
+++ b/contrib/elf2dmp/addrspace.c
32
@@ -XXX,XX +XXX,XX @@ static struct pa_block *pa_space_find_block(struct pa_space *ps, uint64_t pa)
33
34
for (i = 0; i < ps->block_nr; i++) {
35
if (ps->block[i].paddr <= pa &&
36
- pa <= ps->block[i].paddr + ps->block[i].size) {
37
+ pa < ps->block[i].paddr + ps->block[i].size) {
38
return ps->block + i;
39
}
40
}
41
@@ -XXX,XX +XXX,XX @@ static uint8_t *pa_space_resolve(struct pa_space *ps, uint64_t pa)
42
return block->addr + (pa - block->paddr);
43
}
44
45
+static void pa_block_align(struct pa_block *b)
46
+{
47
+ uint64_t low_align = ((b->paddr - 1) | ELF2DMP_PAGE_MASK) + 1 - b->paddr;
48
+ uint64_t high_align = (b->paddr + b->size) & ELF2DMP_PAGE_MASK;
49
+
50
+ if (low_align == 0 && high_align == 0) {
51
+ return;
52
+ }
53
+
54
+ if (low_align + high_align < b->size) {
55
+ printf("Block 0x%"PRIx64"+:0x%"PRIx64" will be aligned to "
56
+ "0x%"PRIx64"+:0x%"PRIx64"\n", b->paddr, b->size,
57
+ b->paddr + low_align, b->size - low_align - high_align);
58
+ b->size -= low_align + high_align;
59
+ } else {
60
+ printf("Block 0x%"PRIx64"+:0x%"PRIx64" is too small to align\n",
61
+ b->paddr, b->size);
62
+ b->size = 0;
63
+ }
64
+
65
+ b->addr += low_align;
66
+ b->paddr += low_align;
67
+}
68
+
69
int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf)
70
{
71
Elf64_Half phdr_nr = elf_getphdrnum(qemu_elf->map);
72
@@ -XXX,XX +XXX,XX @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf)
73
.paddr = phdr[i].p_paddr,
74
.size = phdr[i].p_filesz,
75
};
76
- block_i++;
77
+ pa_block_align(&ps->block[block_i]);
78
+ block_i = ps->block[block_i].size ? (block_i + 1) : block_i;
79
}
80
}
81
82
+ ps->block_nr = block_i;
83
+
84
return 0;
85
}
86
87
diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
88
index XXXXXXX..XXXXXXX 100644
89
--- a/contrib/elf2dmp/main.c
90
+++ b/contrib/elf2dmp/main.c
91
@@ -XXX,XX +XXX,XX @@ static int write_dump(struct pa_space *ps,
92
for (i = 0; i < ps->block_nr; i++) {
93
struct pa_block *b = &ps->block[i];
94
95
- printf("Writing block #%zu/%zu to file...\n", i, ps->block_nr);
96
+ printf("Writing block #%zu/%zu of %"PRIu64" bytes to file...\n", i,
97
+ ps->block_nr, b->size);
98
if (fwrite(b->addr, b->size, 1, dmp_file) != 1) {
99
- eprintf("Failed to write dump header\n");
100
+ eprintf("Failed to write block\n");
101
fclose(dmp_file);
102
return 1;
103
}
104
--
105
2.34.1
diff view generated by jsdifflib
Deleted patch
1
From: Viktor Prutyanov <viktor@daynix.com>
2
1
3
DMP supports 42 physical memory runs at most. So, merge adjacent
4
physical memory ranges from QEMU ELF when possible to minimize total
5
number of runs.
6
7
Signed-off-by: Viktor Prutyanov <viktor@daynix.com>
8
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
9
Message-id: 20230915170153.10959-4-viktor@daynix.com
10
[PMM: fixed format string for printing size_t values]
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
13
contrib/elf2dmp/main.c | 56 ++++++++++++++++++++++++++++++++++++------
14
1 file changed, 48 insertions(+), 8 deletions(-)
15
16
diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/contrib/elf2dmp/main.c
19
+++ b/contrib/elf2dmp/main.c
20
@@ -XXX,XX +XXX,XX @@
21
#define PE_NAME "ntoskrnl.exe"
22
23
#define INITIAL_MXCSR 0x1f80
24
+#define MAX_NUMBER_OF_RUNS 42
25
26
typedef struct idt_desc {
27
uint16_t offset1; /* offset bits 0..15 */
28
@@ -XXX,XX +XXX,XX @@ static int fix_dtb(struct va_space *vs, QEMU_Elf *qe)
29
return 1;
30
}
31
32
+static void try_merge_runs(struct pa_space *ps,
33
+ WinDumpPhyMemDesc64 *PhysicalMemoryBlock)
34
+{
35
+ unsigned int merge_cnt = 0, run_idx = 0;
36
+
37
+ PhysicalMemoryBlock->NumberOfRuns = 0;
38
+
39
+ for (size_t idx = 0; idx < ps->block_nr; idx++) {
40
+ struct pa_block *blk = ps->block + idx;
41
+ struct pa_block *next = blk + 1;
42
+
43
+ PhysicalMemoryBlock->NumberOfPages += blk->size / ELF2DMP_PAGE_SIZE;
44
+
45
+ if (idx + 1 != ps->block_nr && blk->paddr + blk->size == next->paddr) {
46
+ printf("Block #%zu 0x%"PRIx64"+:0x%"PRIx64" and %u previous will be"
47
+ " merged\n", idx, blk->paddr, blk->size, merge_cnt);
48
+ merge_cnt++;
49
+ } else {
50
+ struct pa_block *first_merged = blk - merge_cnt;
51
+
52
+ printf("Block #%zu 0x%"PRIx64"+:0x%"PRIx64" and %u previous will be"
53
+ " merged to 0x%"PRIx64"+:0x%"PRIx64" (run #%u)\n",
54
+ idx, blk->paddr, blk->size, merge_cnt, first_merged->paddr,
55
+ blk->paddr + blk->size - first_merged->paddr, run_idx);
56
+ PhysicalMemoryBlock->Run[run_idx] = (WinDumpPhyMemRun64) {
57
+ .BasePage = first_merged->paddr / ELF2DMP_PAGE_SIZE,
58
+ .PageCount = (blk->paddr + blk->size - first_merged->paddr) /
59
+ ELF2DMP_PAGE_SIZE,
60
+ };
61
+ PhysicalMemoryBlock->NumberOfRuns++;
62
+ run_idx++;
63
+ merge_cnt = 0;
64
+ }
65
+ }
66
+}
67
+
68
static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps,
69
struct va_space *vs, uint64_t KdDebuggerDataBlock,
70
KDDEBUGGER_DATA64 *kdbg, uint64_t KdVersionBlock, int nr_cpus)
71
@@ -XXX,XX +XXX,XX @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps,
72
KUSD_OFFSET_PRODUCT_TYPE);
73
DBGKD_GET_VERSION64 kvb;
74
WinDumpHeader64 h;
75
- size_t i;
76
77
QEMU_BUILD_BUG_ON(KUSD_OFFSET_SUITE_MASK >= ELF2DMP_PAGE_SIZE);
78
QEMU_BUILD_BUG_ON(KUSD_OFFSET_PRODUCT_TYPE >= ELF2DMP_PAGE_SIZE);
79
@@ -XXX,XX +XXX,XX @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps,
80
.RequiredDumpSpace = sizeof(h),
81
};
82
83
- for (i = 0; i < ps->block_nr; i++) {
84
- h.PhysicalMemoryBlock.NumberOfPages +=
85
- ps->block[i].size / ELF2DMP_PAGE_SIZE;
86
- h.PhysicalMemoryBlock.Run[i] = (WinDumpPhyMemRun64) {
87
- .BasePage = ps->block[i].paddr / ELF2DMP_PAGE_SIZE,
88
- .PageCount = ps->block[i].size / ELF2DMP_PAGE_SIZE,
89
- };
90
+ if (h.PhysicalMemoryBlock.NumberOfRuns <= MAX_NUMBER_OF_RUNS) {
91
+ for (size_t idx = 0; idx < ps->block_nr; idx++) {
92
+ h.PhysicalMemoryBlock.NumberOfPages +=
93
+ ps->block[idx].size / ELF2DMP_PAGE_SIZE;
94
+ h.PhysicalMemoryBlock.Run[idx] = (WinDumpPhyMemRun64) {
95
+ .BasePage = ps->block[idx].paddr / ELF2DMP_PAGE_SIZE,
96
+ .PageCount = ps->block[idx].size / ELF2DMP_PAGE_SIZE,
97
+ };
98
+ }
99
+ } else {
100
+ try_merge_runs(ps, &h.PhysicalMemoryBlock);
101
}
102
103
h.RequiredDumpSpace +=
104
--
105
2.34.1
diff view generated by jsdifflib
Deleted patch
1
From: Viktor Prutyanov <viktor@daynix.com>
2
1
3
Glib's g_mapped_file_new maps file with PROT_READ|PROT_WRITE and
4
MAP_PRIVATE. This leads to premature physical memory allocation of dump
5
file size on Linux hosts and may fail. On Linux, mapping the file with
6
MAP_NORESERVE limits the allocation by available memory.
7
8
Signed-off-by: Viktor Prutyanov <viktor@daynix.com>
9
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
10
Message-id: 20230915170153.10959-5-viktor@daynix.com
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
13
contrib/elf2dmp/qemu_elf.h | 2 ++
14
contrib/elf2dmp/qemu_elf.c | 68 +++++++++++++++++++++++++++++++-------
15
2 files changed, 58 insertions(+), 12 deletions(-)
16
17
diff --git a/contrib/elf2dmp/qemu_elf.h b/contrib/elf2dmp/qemu_elf.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/contrib/elf2dmp/qemu_elf.h
20
+++ b/contrib/elf2dmp/qemu_elf.h
21
@@ -XXX,XX +XXX,XX @@ typedef struct QEMUCPUState {
22
int is_system(QEMUCPUState *s);
23
24
typedef struct QEMU_Elf {
25
+#ifndef CONFIG_LINUX
26
GMappedFile *gmf;
27
+#endif
28
size_t size;
29
void *map;
30
QEMUCPUState **state;
31
diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/contrib/elf2dmp/qemu_elf.c
34
+++ b/contrib/elf2dmp/qemu_elf.c
35
@@ -XXX,XX +XXX,XX @@ static bool check_ehdr(QEMU_Elf *qe)
36
return true;
37
}
38
39
-int QEMU_Elf_init(QEMU_Elf *qe, const char *filename)
40
+static int QEMU_Elf_map(QEMU_Elf *qe, const char *filename)
41
{
42
+#ifdef CONFIG_LINUX
43
+ struct stat st;
44
+ int fd;
45
+
46
+ printf("Using Linux mmap\n");
47
+
48
+ fd = open(filename, O_RDONLY, 0);
49
+ if (fd == -1) {
50
+ eprintf("Failed to open ELF dump file \'%s\'\n", filename);
51
+ return 1;
52
+ }
53
+
54
+ if (fstat(fd, &st)) {
55
+ eprintf("Failed to get size of ELF dump file\n");
56
+ close(fd);
57
+ return 1;
58
+ }
59
+ qe->size = st.st_size;
60
+
61
+ qe->map = mmap(NULL, qe->size, PROT_READ | PROT_WRITE,
62
+ MAP_PRIVATE | MAP_NORESERVE, fd, 0);
63
+ if (qe->map == MAP_FAILED) {
64
+ eprintf("Failed to map ELF file\n");
65
+ close(fd);
66
+ return 1;
67
+ }
68
+
69
+ close(fd);
70
+#else
71
GError *gerr = NULL;
72
- int err = 0;
73
+
74
+ printf("Using GLib mmap\n");
75
76
qe->gmf = g_mapped_file_new(filename, TRUE, &gerr);
77
if (gerr) {
78
@@ -XXX,XX +XXX,XX @@ int QEMU_Elf_init(QEMU_Elf *qe, const char *filename)
79
80
qe->map = g_mapped_file_get_contents(qe->gmf);
81
qe->size = g_mapped_file_get_length(qe->gmf);
82
+#endif
83
+
84
+ return 0;
85
+}
86
+
87
+static void QEMU_Elf_unmap(QEMU_Elf *qe)
88
+{
89
+#ifdef CONFIG_LINUX
90
+ munmap(qe->map, qe->size);
91
+#else
92
+ g_mapped_file_unref(qe->gmf);
93
+#endif
94
+}
95
+
96
+int QEMU_Elf_init(QEMU_Elf *qe, const char *filename)
97
+{
98
+ if (QEMU_Elf_map(qe, filename)) {
99
+ return 1;
100
+ }
101
102
if (!check_ehdr(qe)) {
103
eprintf("Input file has the wrong format\n");
104
- err = 1;
105
- goto out_unmap;
106
+ QEMU_Elf_unmap(qe);
107
+ return 1;
108
}
109
110
if (init_states(qe)) {
111
eprintf("Failed to extract QEMU CPU states\n");
112
- err = 1;
113
- goto out_unmap;
114
+ QEMU_Elf_unmap(qe);
115
+ return 1;
116
}
117
118
return 0;
119
-
120
-out_unmap:
121
- g_mapped_file_unref(qe->gmf);
122
-
123
- return err;
124
}
125
126
void QEMU_Elf_exit(QEMU_Elf *qe)
127
{
128
exit_states(qe);
129
- g_mapped_file_unref(qe->gmf);
130
+ QEMU_Elf_unmap(qe);
131
}
132
--
133
2.34.1
diff view generated by jsdifflib
Deleted patch
1
From: Viktor Prutyanov <viktor@daynix.com>
2
1
3
PDB for Windows 11 kernel has slightly different structure compared to
4
previous versions. Since elf2dmp don't use the other fields, copy only
5
'segments' field from PDB_STREAM_INDEXES.
6
7
Signed-off-by: Viktor Prutyanov <viktor@daynix.com>
8
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
9
Message-id: 20230915170153.10959-6-viktor@daynix.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
12
contrib/elf2dmp/pdb.h | 2 +-
13
contrib/elf2dmp/pdb.c | 15 ++++-----------
14
2 files changed, 5 insertions(+), 12 deletions(-)
15
16
diff --git a/contrib/elf2dmp/pdb.h b/contrib/elf2dmp/pdb.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/contrib/elf2dmp/pdb.h
19
+++ b/contrib/elf2dmp/pdb.h
20
@@ -XXX,XX +XXX,XX @@ struct pdb_reader {
21
} ds;
22
uint32_t file_used[1024];
23
PDB_SYMBOLS *symbols;
24
- PDB_STREAM_INDEXES sidx;
25
+ uint16_t segments;
26
uint8_t *modimage;
27
char *segs;
28
size_t segs_size;
29
diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c
30
index XXXXXXX..XXXXXXX 100644
31
--- a/contrib/elf2dmp/pdb.c
32
+++ b/contrib/elf2dmp/pdb.c
33
@@ -XXX,XX +XXX,XX @@ static void *pdb_ds_read_file(struct pdb_reader* r, uint32_t file_number)
34
static int pdb_init_segments(struct pdb_reader *r)
35
{
36
char *segs;
37
- unsigned stream_idx = r->sidx.segments;
38
+ unsigned stream_idx = r->segments;
39
40
segs = pdb_ds_read_file(r, stream_idx);
41
if (!segs) {
42
@@ -XXX,XX +XXX,XX @@ static int pdb_init_symbols(struct pdb_reader *r)
43
{
44
int err = 0;
45
PDB_SYMBOLS *symbols;
46
- PDB_STREAM_INDEXES *sidx = &r->sidx;
47
-
48
- memset(sidx, -1, sizeof(*sidx));
49
50
symbols = pdb_ds_read_file(r, 3);
51
if (!symbols) {
52
@@ -XXX,XX +XXX,XX @@ static int pdb_init_symbols(struct pdb_reader *r)
53
54
r->symbols = symbols;
55
56
- if (symbols->stream_index_size != sizeof(PDB_STREAM_INDEXES)) {
57
- err = 1;
58
- goto out_symbols;
59
- }
60
-
61
- memcpy(sidx, (const char *)symbols + sizeof(PDB_SYMBOLS) +
62
+ r->segments = *(uint16_t *)((const char *)symbols + sizeof(PDB_SYMBOLS) +
63
symbols->module_size + symbols->offset_size +
64
symbols->hash_size + symbols->srcmodule_size +
65
- symbols->pdbimport_size + symbols->unknown2_size, sizeof(*sidx));
66
+ symbols->pdbimport_size + symbols->unknown2_size +
67
+ offsetof(PDB_STREAM_INDEXES, segments));
68
69
/* Read global symbol table */
70
r->modimage = pdb_ds_read_file(r, symbols->gsym_file);
71
--
72
2.34.1
diff view generated by jsdifflib