Skip to content

Commit b1c834f

Browse files
DavidSpicketttru
authored andcommitted
[lldb][AArch64][Linux] Show MTE store only setting in mte_ctrl (#145033)
This controls whether tag checking is performed for loads and stores, or stores only. It requires a specific architecture feature which we detect with a HWCAP3 and cpuinfo feature. Live process tests look for this and adjust expectations accordingly, core file tests are using an updated file with this feature enabled. The size of the core file has increased and there's nothing I can do about that. Could be the presence of new architecure features or kernel changes since I last generated them. I can generate a smaller file that has the tag segment, but that segment does not actually contain tag data. So that's no use. (cherry picked from commit 0209e76)
1 parent 9ad630f commit b1c834f

File tree

7 files changed

+48
-19
lines changed

7 files changed

+48
-19
lines changed

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,9 @@ def isAArch64SMEFA64(self):
13801380
def isAArch64MTE(self):
13811381
return self.isAArch64() and "mte" in self.getCPUInfo()
13821382

1383+
def isAArch64MTEStoreOnly(self):
1384+
return self.isAArch64() and "mtestoreonly" in self.getCPUInfo()
1385+
13831386
def isAArch64GCS(self):
13841387
return self.isAArch64() and "gcs" in self.getCPUInfo()
13851388

lldb/source/Plugins/Process/Utility/RegisterFlagsDetector_arm64.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define HWCAP2_EBF16 (1ULL << 32)
2727
#define HWCAP2_FPMR (1ULL << 48)
2828

29+
#define HWCAP3_MTE_STORE_ONLY (1ULL << 1)
30+
2931
using namespace lldb_private;
3032

3133
Arm64RegisterFlagsDetector::Fields
@@ -92,7 +94,6 @@ Arm64RegisterFlagsDetector::Fields
9294
Arm64RegisterFlagsDetector::DetectMTECtrlFields(uint64_t hwcap, uint64_t hwcap2,
9395
uint64_t hwcap3) {
9496
(void)hwcap;
95-
(void)hwcap3;
9697

9798
if (!(hwcap2 & HWCAP2_MTE))
9899
return {};
@@ -101,12 +102,22 @@ Arm64RegisterFlagsDetector::DetectMTECtrlFields(uint64_t hwcap, uint64_t hwcap2,
101102
// to prctl(PR_TAGGED_ADDR_CTRL...). Fields are derived from the defines
102103
// used to build the value.
103104

105+
std::vector<RegisterFlags::Field> fields;
106+
fields.reserve(4);
107+
if (hwcap3 & HWCAP3_MTE_STORE_ONLY)
108+
fields.push_back({"STORE_ONLY", 19});
109+
104110
static const FieldEnum tcf_enum(
105111
"tcf_enum",
106112
{{0, "TCF_NONE"}, {1, "TCF_SYNC"}, {2, "TCF_ASYNC"}, {3, "TCF_ASYMM"}});
107-
return {{"TAGS", 3, 18}, // 16 bit bitfield shifted up by PR_MTE_TAG_SHIFT.
108-
{"TCF", 1, 2, &tcf_enum},
109-
{"TAGGED_ADDR_ENABLE", 0}};
113+
114+
fields.insert(
115+
std::end(fields),
116+
{{"TAGS", 3, 18}, // 16 bit bitfield shifted up by PR_MTE_TAG_SHIFT.
117+
{"TCF", 1, 2, &tcf_enum},
118+
{"TAGGED_ADDR_ENABLE", 0}});
119+
120+
return fields;
110121
}
111122

112123
Arm64RegisterFlagsDetector::Fields

lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,41 @@ def test_mte_ctrl_register(self):
3434
substrs=["stop reason = breakpoint 1."],
3535
)
3636

37-
def check_mte_ctrl(async_err, sync_err):
37+
has_store_only = self.isAArch64MTEStoreOnly()
38+
39+
def check_mte_ctrl(async_err, sync_err, store_only):
3840
# Bit 0 = tagged addressing enabled
3941
# Bit 1 = synchronous faults
4042
# Bit 2 = asynchronous faults
41-
value = "0x{:016x}".format((async_err << 2) | (sync_err << 1) | 1)
43+
# Bit 19 = store only checking mode
44+
value = "0x{:016x}".format(
45+
(store_only << 19) | (async_err << 2) | (sync_err << 1) | 1
46+
)
4247
expected = [value]
4348

4449
if self.hasXMLSupport():
50+
fields = "("
51+
if has_store_only:
52+
fields += f"STORE_ONLY = {store_only}, "
53+
4554
tfc_modes = ["NONE", "SYNC", "ASYNC", "ASYMM"]
46-
expected.append(
47-
f"(TAGS = 0, TCF = TCF_{tfc_modes[async_err << 1 | sync_err]}, TAGGED_ADDR_ENABLE = 1)".format(
48-
async_err, sync_err
49-
)
50-
)
55+
fields += f"TAGS = 0, TCF = TCF_{tfc_modes[async_err << 1 | sync_err]}, TAGGED_ADDR_ENABLE = 1)"
56+
57+
expected.append(fields)
5158

5259
self.expect("register read mte_ctrl", substrs=expected)
5360

5461
# We start enabled with synchronous faults.
55-
check_mte_ctrl(0, 1)
62+
check_mte_ctrl(0, 1, 0)
5663
# Change to asynchronous faults.
5764
self.runCmd("register write mte_ctrl 5")
58-
check_mte_ctrl(1, 0)
65+
check_mte_ctrl(1, 0, 0)
5966
# This would return to synchronous faults if we did not restore the
6067
# previous value.
6168
self.expect("expression setup_mte()", substrs=["= 0"])
62-
check_mte_ctrl(1, 0)
69+
check_mte_ctrl(1, 0, 0)
70+
71+
# Store only checking requires FEAT_MTE_STORE_ONLY.
72+
if has_store_only:
73+
self.runCmd(f"register write mte_ctrl {1 | (1 << 19)}")
74+
check_mte_ctrl(0, 0, 1)

lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
class AArch64LinuxMTEMemoryTagCoreFileTestCase(TestBase):
1111
NO_DEBUG_INFO_TESTCASE = True
1212

13-
MTE_BUF_ADDR = hex(0xFFFF82C74000)
14-
BUF_ADDR = hex(0xFFFF82C73000)
13+
MTE_BUF_ADDR = hex(0xFFFFA733B000)
14+
BUF_ADDR = hex(0xFFFFA733A000)
1515

1616
@skipIfLLVMTargetMissing("AArch64")
1717
def test_mte_tag_core_file_memory_region(self):
@@ -215,7 +215,7 @@ def test_mte_tag_fault_reason(self):
215215
self.expect(
216216
"bt",
217217
substrs=[
218-
"* thread #1, name = 'a.out.mte', stop reason = SIGSEGV: sync tag check fault (fault address=0xffff82c74010)"
218+
"* thread #1, name = 'a.out.mte', stop reason = SIGSEGV: sync tag check fault (fault address=0xffffa733b010)"
219219
],
220220
)
221221

@@ -231,12 +231,15 @@ def test_mte_ctrl_register(self):
231231
self.runCmd("target create --core core.mte")
232232
# The expected value is:
233233
# * Allowed tags value of 0xFFFF, shifted up by 3 resulting in 0x7fff8.
234+
# * Bit 19 set to 0, which means that store only checking is disabled.
234235
# * Bit 1 set to enable synchronous tag faults.
235236
# * Bit 0 set to enable the tagged address ABI.
236237
expected = ["mte_ctrl = 0x000000000007fffb"]
237238

238239
if self.hasXMLSupport():
239-
expected.append("(TAGS = 65535, TCF = TCF_SYNC, TAGGED_ADDR_ENABLE = 1)")
240+
expected.append(
241+
"(STORE_ONLY = 0, TAGS = 65535, TCF = TCF_SYNC, TAGGED_ADDR_ENABLE = 1)"
242+
)
240243

241244
self.expect("register read mte_ctrl", substrs=expected)
242245

Binary file not shown.
Binary file not shown.

lldb/test/API/linux/aarch64/mte_core_file/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
int main(int argc, char const *argv[]) {
2525
#ifdef NO_MTE
26-
*(char *)(0) = 0;
26+
__builtin_trap();
2727
#endif
2828

2929
if (prctl(PR_SET_TAGGED_ADDR_CTRL,

0 commit comments

Comments
 (0)