Skip to content

[lldb][AArch64] Invalidate SVG prior to reconfiguring ZA regdef #66768

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
Oct 25, 2023

Conversation

DavidSpickett
Copy link
Collaborator

@DavidSpickett DavidSpickett commented Sep 19, 2023

This fixes a bug where writing vg during streaming mode
could prevent you reading za directly afterwards.

vg is invalidated just prior to us reading it in AArch64Reconfigure,
but svg was not. This lead to some situations where vg would be
updated or cleared and re-read, but svg would not be.

This meant it had some undefined value which lead to errors
that prevented us reading ZA. Likely we received a lot more
data than we were expecting.

There are at least 2 ways to get into this situation:

  • Explicit write by the user to vg.
  • We have just stopped and need to get the potentially new svg and vg.

The first is handled by invalidating svg client side before fetching the new one. This also
covers some but not all of the second scenario. For the second, I've made writes to vg
invalidate svg by noting this in the register information.

Whichever one of those kicks in, we'll get the latest value of svg.

The bug may depend on timing, I could not find a consistent way
to trigger it. I originally found it when checking whether za
is disabled after a vg change, so I've added checks for that
to TestZAThreadedDynamic.

The SVE VG version of the bug did show up on the buildbot,
but not consistently. So it's possible that TestZAThreadedDynamic
does in fact cover this, but I haven't run it enough times to know.

@DavidSpickett DavidSpickett requested review from omjavaid and a team September 19, 2023 12:32
@DavidSpickett
Copy link
Collaborator Author

Replaces https://reviews.llvm.org/D158514.

@llvmbot llvmbot added the lldb label Sep 19, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2023

@llvm/pr-subscribers-lldb

Changes

This fixes a bug where writing vg during streaming mode could prevent you reading za directly afterwards.

vg is invalided when the write happens. SVE is reconfigured by reading back the new value from the remote. So far so good.

For SME, we read SVG which in some situations appeared to remain valid but have a value of 0 (perhaps it had never been read). This meant lldb expected the size of za to be 0 bytes and rejected the remote's response.

To fix this, invalidate svg before reconfiguring. This ensures that the value used is the latest one from the remote.

The bug may depend on timing, I could not find a consistent way to trigger it. I originally found it when checking whether za is disabled after a vg change, so I've added checks for that to TestZAThreadedDynamic.

Differential Revision: https://reviews.llvm.org/D158514


Full diff: https://github.com/llvm/llvm-project/pull/66768.diff

2 Files Affected:

  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp (+5)
  • (modified) lldb/test/API/commands/register/register/aarch64_za_register/za_dynamic_resize/TestZAThreadedDynamic.py (+2)
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index 16dde28f6ee5396..13365dc312f5b66 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -781,6 +781,11 @@ void GDBRemoteRegisterContext::AArch64Reconfigure() {
   std::optional<uint64_t> svg_reg_value;
   const RegisterInfo *svg_reg_info = m_reg_info_sp->GetRegisterInfo("svg");
   if (svg_reg_info) {
+    // When vg is written it is automatically made invalid. Writing vg will also
+    // change svg if we're in streaming mode but it will not be made invalid
+    // so do this manually so the following read gets the latest svg value.
+    SetRegisterIsValid(svg_reg_info, false);
+
     uint32_t svg_reg_num = svg_reg_info->kinds[eRegisterKindLLDB];
     uint64_t reg_value = ReadRegisterAsUnsigned(svg_reg_num, fail_value);
     if (reg_value != fail_value && reg_value <= 32)
diff --git a/lldb/test/API/commands/register/register/aarch64_za_register/za_dynamic_resize/TestZAThreadedDynamic.py b/lldb/test/API/commands/register/register/aarch64_za_register/za_dynamic_resize/TestZAThreadedDynamic.py
index 65d1071c26b2a34..d2a26ce71bde1d8 100644
--- a/lldb/test/API/commands/register/register/aarch64_za_register/za_dynamic_resize/TestZAThreadedDynamic.py
+++ b/lldb/test/API/commands/register/register/aarch64_za_register/za_dynamic_resize/TestZAThreadedDynamic.py
@@ -125,11 +125,13 @@ def za_test_impl(self, enable_za):
                 self.runCmd("thread select %d" % (idx + 1))
                 self.check_za_register(4, 2)
                 self.runCmd("register write vg 2")
+                self.check_disabled_za_register(2)
 
             elif stopped_at_line_number == thY_break_line1:
                 self.runCmd("thread select %d" % (idx + 1))
                 self.check_za_register(2, 3)
                 self.runCmd("register write vg 4")
+                self.check_disabled_za_register(4)
 
         self.runCmd("thread continue 2")
         self.runCmd("thread continue 3")

@DavidSpickett
Copy link
Collaborator Author

I've just pushed a similar fix for SVE's VG (fdc265b). Fixes some test flakiness so I've pushed it directly.

@DavidSpickett
Copy link
Collaborator Author

ping!

This fixes a bug where writing vg during streaming mode
could prevent you reading za directly afterwards.

vg is invalidated just prior to us reading it in AArch64Reconfigure,
but svg was not. This lead to some situations where vg would be
updated or read from fresh, but svg would not be.

This meant it had some undefined value which lead to errors
that prevented us reading ZA. Likely we receieved a lot more
data than we were expecting.

To fix this, invalidate svg before reconfiguring. This ensures
that the value used is the latest one from the remote and matches
the procedure for SVE's VG.

The bug may depend on timing, I could not find a consistent way
to trigger it. I originally found it when checking whether za
is disabled after a vg change, so I've added checks for that
to TestZAThreadedDynamic.

The SVE VG version of the bug did show up on the buildbot,
but not consistently. So it's possible that TestZAThreadedDynamic
does in fact cover this, but I haven't run it enough times to know.
@DavidSpickett
Copy link
Collaborator Author

ping!

I know you're very busy at the moment, but if you have time to review this week this is the most important patch I've got queued.

@DavidSpickett DavidSpickett removed the request for review from JDevlieghere October 24, 2023 13:18
@DavidSpickett DavidSpickett merged commit f2c09e5 into llvm:main Oct 25, 2023
@DavidSpickett DavidSpickett deleted the lldb-sme-fix branch October 25, 2023 08:17
DavidSpickett added a commit that referenced this pull request Oct 25, 2023
…ef (#66768)"

This reverts commit f2c09e5, due to compilation
failures on buildbots.
DavidSpickett added a commit that referenced this pull request Oct 25, 2023
…ef (#66768)""

This reverts commit 8d80a45.

The pointer to the invalidates lists needs to be non-const. Though in this case
I don't think it's ever modified.

Also I realised that the invalidate list was being set on svg not vg.
Should be the other way around.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants