Skip to content

Some tweaks to the SME lazy save scheme - #325

Merged
smithp35 merged 1 commit into
ARM-software:mainfrom
rsandifo-arm:sme-lazy-save-tweaks
May 12, 2025
Merged

smithp35 merged 1 commit into
ARM-software:mainfrom
rsandifo-arm:sme-lazy-save-tweaks

Conversation

@rsandifo-arm

@rsandifo-arm rsandifo-arm commented Apr 23, 2025 •

Copy link
Copy Markdown
Contributor

This patch does four things:

  • Explicitly document that ZT0 is a temporary register.

  • Clarify that __arm_sme_save and __arm_sme_restore treat both ZA
    and ZT0 specially.

  • Add a general note about how platforms should handle asynchronous control
    flow (such as POSIX signals). The specific details are out of scope
    for the AAPCS64, which is why this wasn't mentioned before. However,
    for the sake of an example, we can at least sketch the approach that
    linux will use.

  • Change the notes around setjmp and longjmp to recommend that both
    routines turn ZA off. Just turning ZA off in longjmp isn't enough
    when jumping out of a linux-style signal handler, since longjmp
    would not be able to see any ZA save buffer that was in use when the
    signal was raised, nor the ZA contents that should be saved to it.

    The previous recommendation to turn ZA off only in longjmp was chosen
    by analogy with exception unwinding; it seemed to make sense in both
    cases to commit a lazy save once it was known that some frames would
    be unwound. However, the two cases are not analogous for asynchronous
    signals, since exception unwinders can examine each intermediate frame
    and see the point at which a signal handler was entered, whereas
    longjmp (in general) cannot.

    It may not be strictly necessary for longjmp to commit a lazy save
    if setjmp does; it might be enough for it to force PSTATE.ZA and
    TPIDR2_EL0 to zero. However, that would be a novel state transition
    and it would be optimising for what should be a vanishingly rare case
    (the one where there is an in-progress SME routine between a setjmp
    and a longjmp). It seems safer to use the standard transition instead.

@smithp35 smithp35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotted a typo in the change history.

Comment thread aapcs64/aapcs64.rst Outdated
@rsandifo-arm
rsandifo-arm force-pushed the sme-lazy-save-tweaks branch 2 times, most recently from 078b381 to 2cf2bcc Compare April 23, 2025 18:19
@yury-khrustalev

Copy link
Copy Markdown
Contributor

Acked-by: @yury-khrustalev

Comment thread aapcs64/aapcs64.rst Outdated

@smithp35 smithp35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Agreed to approve with stakeholders in Arm's libraries and kernel team. Will merge at end of the UK working day.

This patch does four things:

- Explicitly document that ZT0 is a temporary register.

- Clarify that __arm_sme_save and __arm_sme_restore treat both ZA
  and ZT0 specially.

- Add a general note about how platforms should handle asynchronous control
  flow (such as POSIX signals).  The specific details are out of scope
  for the AAPCS64, which is why this wasn't mentioned before.  However,
  for the sake of an example, we can at least sketch the approach that
  linux will use.

- Change the notes around setjmp and longjmp to recommend that both
  routines turn ZA off.  Just turning ZA off in longjmp isn't enough
  when jumping out of a linux-style signal handler, since longjmp
  would not be able to see any ZA save buffer that was in use when the
  signal was raised, nor the ZA contents that should be saved to it.

  The previous recommendation to turn ZA off only in longjmp was chosen
  by analogy with exception unwinding; it seemed to make sense in both
  cases to commit a lazy save once it was known that some frames would
  be unwound.  However, the two cases are not analogous for asynchronous
  signals, since exception unwinders can examine each intermediate frame
  and see the point at which a signal handler was entered, whereas
  longjmp (in general) cannot.

  It may not be strictly necessary for longjmp to commit a lazy save
  if setjmp does; it might be enough for it to force PSTATE.ZA and
  TPIDR2_EL0 to zero.  However, that would be a novel state transition
  and it would be optimising for what should be a vanishingly rare case
  (the one where there is an in-progress SME routine between a setjmp
  and a longjmp).  It seems safer to use the standard transition instead.
@rsandifo-arm
rsandifo-arm force-pushed the sme-lazy-save-tweaks branch from 2cf2bcc to 6e05fdd Compare April 30, 2025 09:01

@sdesmalen-arm sdesmalen-arm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the rewording @rsandifo-arm. LGTM!

@smithp35

Copy link
Copy Markdown
Contributor

PR has been approved. Merging into main.

@smithp35
smithp35 merged commit 3952cfb into ARM-software:main May 12, 2025

@sallyarmneale sallyarmneale left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants