Skip to content

[lldb][AArch64][Linux] Show MTE store only setting in mte_ctrl #145033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lldb/packages/Python/lldbsuite/test/lldbtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,9 @@ def isAArch64SMEFA64(self):
def isAArch64MTE(self):
return self.isAArch64() and "mte" in self.getCPUInfo()

def isAArch64MTEStoreOnly(self):
return self.isAArch64() and "mtestoreonly" in self.getCPUInfo()

def isAArch64GCS(self):
return self.isAArch64() and "gcs" in self.getCPUInfo()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#define HWCAP2_EBF16 (1ULL << 32)
#define HWCAP2_FPMR (1ULL << 48)

#define HWCAP3_MTE_STORE_ONLY (1ULL << 1)

using namespace lldb_private;

Arm64RegisterFlagsDetector::Fields
Expand Down Expand Up @@ -92,7 +94,6 @@ Arm64RegisterFlagsDetector::Fields
Arm64RegisterFlagsDetector::DetectMTECtrlFields(uint64_t hwcap, uint64_t hwcap2,
uint64_t hwcap3) {
(void)hwcap;
(void)hwcap3;

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

std::vector<RegisterFlags::Field> fields;
fields.reserve(4);
if (hwcap3 & HWCAP3_MTE_STORE_ONLY)
fields.push_back({"STORE_ONLY", 19});

static const FieldEnum tcf_enum(
"tcf_enum",
{{0, "TCF_NONE"}, {1, "TCF_SYNC"}, {2, "TCF_ASYNC"}, {3, "TCF_ASYMM"}});
return {{"TAGS", 3, 18}, // 16 bit bitfield shifted up by PR_MTE_TAG_SHIFT.
{"TCF", 1, 2, &tcf_enum},
{"TAGGED_ADDR_ENABLE", 0}};

fields.insert(
std::end(fields),
{{"TAGS", 3, 18}, // 16 bit bitfield shifted up by PR_MTE_TAG_SHIFT.
{"TCF", 1, 2, &tcf_enum},
{"TAGGED_ADDR_ENABLE", 0}});

return fields;
}

Arm64RegisterFlagsDetector::Fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,41 @@ def test_mte_ctrl_register(self):
substrs=["stop reason = breakpoint 1."],
)

def check_mte_ctrl(async_err, sync_err):
has_store_only = self.isAArch64MTEStoreOnly()

def check_mte_ctrl(async_err, sync_err, store_only):
# Bit 0 = tagged addressing enabled
# Bit 1 = synchronous faults
# Bit 2 = asynchronous faults
value = "0x{:016x}".format((async_err << 2) | (sync_err << 1) | 1)
# Bit 19 = store only checking mode
value = "0x{:016x}".format(
(store_only << 19) | (async_err << 2) | (sync_err << 1) | 1
)
expected = [value]

if self.hasXMLSupport():
fields = "("
if has_store_only:
fields += f"STORE_ONLY = {store_only}, "

tfc_modes = ["NONE", "SYNC", "ASYNC", "ASYMM"]
expected.append(
f"(TAGS = 0, TCF = TCF_{tfc_modes[async_err << 1 | sync_err]}, TAGGED_ADDR_ENABLE = 1)".format(
async_err, sync_err
)
)
fields += f"TAGS = 0, TCF = TCF_{tfc_modes[async_err << 1 | sync_err]}, TAGGED_ADDR_ENABLE = 1)"

expected.append(fields)

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

# We start enabled with synchronous faults.
check_mte_ctrl(0, 1)
check_mte_ctrl(0, 1, 0)
# Change to asynchronous faults.
self.runCmd("register write mte_ctrl 5")
check_mte_ctrl(1, 0)
check_mte_ctrl(1, 0, 0)
# This would return to synchronous faults if we did not restore the
# previous value.
self.expect("expression setup_mte()", substrs=["= 0"])
check_mte_ctrl(1, 0)
check_mte_ctrl(1, 0, 0)

# Store only checking requires FEAT_MTE_STORE_ONLY.
if has_store_only:
self.runCmd(f"register write mte_ctrl {1 | (1 << 19)}")
check_mte_ctrl(0, 0, 1)
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
class AArch64LinuxMTEMemoryTagCoreFileTestCase(TestBase):
NO_DEBUG_INFO_TESTCASE = True

MTE_BUF_ADDR = hex(0xFFFF82C74000)
BUF_ADDR = hex(0xFFFF82C73000)
MTE_BUF_ADDR = hex(0xFFFFA733B000)
BUF_ADDR = hex(0xFFFFA733A000)

@skipIfLLVMTargetMissing("AArch64")
def test_mte_tag_core_file_memory_region(self):
Expand Down Expand Up @@ -215,7 +215,7 @@ def test_mte_tag_fault_reason(self):
self.expect(
"bt",
substrs=[
"* thread #1, name = 'a.out.mte', stop reason = SIGSEGV: sync tag check fault (fault address=0xffff82c74010)"
"* thread #1, name = 'a.out.mte', stop reason = SIGSEGV: sync tag check fault (fault address=0xffffa733b010)"
],
)

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

if self.hasXMLSupport():
expected.append("(TAGS = 65535, TCF = TCF_SYNC, TAGGED_ADDR_ENABLE = 1)")
expected.append(
"(STORE_ONLY = 0, TAGS = 65535, TCF = TCF_SYNC, TAGGED_ADDR_ENABLE = 1)"
)

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

Expand Down
Binary file modified lldb/test/API/linux/aarch64/mte_core_file/core.mte
Binary file not shown.
Binary file modified lldb/test/API/linux/aarch64/mte_core_file/core.nomte
Binary file not shown.
2 changes: 1 addition & 1 deletion lldb/test/API/linux/aarch64/mte_core_file/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

int main(int argc, char const *argv[]) {
#ifdef NO_MTE
*(char *)(0) = 0;
__builtin_trap();
#endif

if (prctl(PR_SET_TAGGED_ADDR_CTRL,
Expand Down
Loading