This is an archive of the discontinued LLVM Phabricator instance.

[lldb][AArch64] Add SME's streaming vector control register
ClosedPublic

Authored by DavidSpickett on Jul 11 2023, 1:10 AM.

Details

Summary

Software can tell if it is in streaming SVE mode by checking
the Streaming Vector Control Register (SVCR).

"E3.1.9 SVCR, Streaming Vector Control Register" in
"Arm® Architecture Reference Manual Supplement, The Scalable Matrix
Extension (SME), for Armv9-A"

https://developer.arm.com/documentation/ddi0616/latest/

This is especially useful for debug because the names of the
SVE registers are the same betweeen non-streaming and streaming mode.

The Linux Kernel chose to not put this register behind ptrace,
and it can be read from EL0. However, this would mean running code
in process to read it. That can be done but we already know all
the information just from ptrace.

So this is a pseudo register that matches the architectural
content. The name is just "svcr", which aligns with GDB's proposed naming,
and it's added to the existing SME register set.

The SVCR register contains two bits:
0 : Whether streaming SVE mode is enabled (SM)
1 : Whether the array storage is enabled (ZA)

Array storage can be active when streaming mode is not, so this register
can have any permutation of those bits.

This register is currently read only. We can emulate the result of
writing to it, using ptrace. However at this point the utility of that
is not obvious.

Existing tests have been updated to check for appropriate SVCR values
at various points.

Given that this register is a read only pseudo, there is no need
to save and restore it around expressions.

Diff Detail

Event Timeline

DavidSpickett created this revision.Jul 11 2023, 1:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2023, 1:10 AM
DavidSpickett requested review of this revision.Jul 11 2023, 1:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2023, 1:10 AM
Matt added a subscriber: Matt.Jul 11 2023, 10:42 AM
omjavaid added inline comments.Jul 16 2023, 9:28 PM
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
325

typo: pseudo register?

1003

is there a need here to check if m_sve_state is valid?

Rebase, fix typo.

DavidSpickett marked an inline comment as done.Jul 18 2023, 8:02 AM
DavidSpickett marked an inline comment as done.Jul 18 2023, 8:06 AM
DavidSpickett added inline comments.
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
1003

The only "invalid" state we can check at the moment is SVEState::Unknown. Which would translate here to a value of 0 in the register, which isn't incorrect, it's just pesimistic.

By the time you're printing this register you'd likely have checked the state fully. Maybe it would come back as SVEState::Disabled, but in that case you wouldn't have SME anyway so this register isn't available to you.

DavidSpickett marked an inline comment as done.

Add missing newline.

lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/TestSVERegisters.py
30

This is the check promised in the previous patch. It ensures that when we return from evaluating the expression we do restore the previous operating mode.

I guess there is not much gain from telling the user between sve/ssve mode for the moment. Can we defer this patch till SME registers are implemented?

DavidSpickett planned changes to this revision.Jul 21 2023, 7:26 AM

In some sense it already is, it'll go in after the streaming mode SVE registers. Should we wait until we can show the full content including the ZA bit? Yeah, why not, we're in no rush.

I have a patch locally for ZA support that I'm working on. I'll reorder this to after that and when I update this, it will have the full SVCR contents.

Rebase and reimplement this on top of ZA/SVG.

DavidSpickett edited the summary of this revision. (Show Details)Aug 14 2023, 8:09 AM

Correct regiter -> register in comment.

ZA is now part of the SME set so SVCR is stuck in before SVG.

SVCR
SVG
ZA

Updated the various indexes to reflect that.

Format with black.

Rebase, use new sme_pseudo_regs naming.

Are

lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
1012

Shouldnt we build a relevant error message here incase ReadSMEControl fails on ReadZAHeader

lldb/test/API/commands/register/register/aarch64_za_register/za_save_restore/TestZARegisterSaveRestore.py
183 ↗(On Diff #557011)

should we also add a svcr write test here?

DavidSpickett added inline comments.Sep 20 2023, 12:55 AM
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
1012

I think this should be return error in fact, let me check what that does.

lldb/test/API/commands/register/register/aarch64_za_register/za_save_restore/TestZARegisterSaveRestore.py
183 ↗(On Diff #557011)

It's read only. We could allow writes but it introduces a lot more ways to change state, most of which aren't obviously useful for the user. If someone really wants it, it can be added.

I will note this in a comment here.

  • Return error in SVCR read.
  • Note absence of write tests of SVCR because it's read only.
DavidSpickett marked 2 inline comments as done.Sep 20 2023, 1:16 AM
DavidSpickett added inline comments.
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
1012

I now return the underlying error so it won't fail silently.

lldb/test/API/commands/register/register/aarch64_za_register/za_save_restore/TestZARegisterSaveRestore.py
183 ↗(On Diff #557011)

I've actually added comments to the other file, where it makes more sense that you might be writing to svcr.

Here the whole test is about having the program setup the registers, and modify them. So there's less expectation that you'd check writing here.

The fact that SVCR is read only (as is SVG) will be documented in fully https://github.com/llvm/llvm-project/pull/66767.

omjavaid accepted this revision.Sep 20 2023, 2:12 AM

This is good too. Thanks!!!

This revision is now accepted and ready to land.Sep 20 2023, 2:12 AM