Skip to content
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

[FMV] Unify memtag and memtag2. #351

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

labrinea
Copy link
Contributor

If we split these features in the compiler (see relevant pull request llvm/llvm-project#109299), we would only be able to hand-write a 'memtag2' version using inline assembly since the compiler cannot generate the instructions that become available with FEAT_MTE2. On top of that these instructions only work at Exception Level 1, so they would be unusable since FMV is a user space facility. I am therefore unifying them in the ACLE specification.


name: Pull request
about: Technical issues, document format problems, bugs in scripts or feature proposal.


Thank you for submitting a pull request!

If this PR is about a bugfix:

Please use the bugfix label and make sure to go through the checklist below.

If this PR is about a proposal:

We are looking forward to evaluate your proposal, and if possible to
make it part of the Arm C Language Extension (ACLE) specifications.

We would like to encourage you reading through the contribution
guidelines
, in particular the section on submitting
a proposal
.

Please use the proposal label.

As for any pull request, please make sure to go through the below
checklist.

Checklist: (mark with X those which apply)

  • If an issue reporting the bug exists, I have mentioned it in the
    PR (do not bother creating the issue if all you want to do is
    fixing the bug yourself).
  • I have added/updated the SPDX-FileCopyrightText lines on top
    of any file I have edited. Format is SPDX-FileCopyrightText: Copyright {year} {entity or name} <{contact informations}>
    (Please update existing copyright lines if applicable. You can
    specify year ranges with hyphen , as in 2017-2019, and use
    commas to separate gaps, as in 2018-2020, 2022).
  • I have updated the Copyright section of the sources of the
    specification I have edited (this will show up in the text
    rendered in the PDF and other output format supported). The
    format is the same described in the previous item.
  • I have run the CI scripts (if applicable, as they might be
    tricky to set up on non-*nix machines). The sequence can be
    found in the contribution
    guidelines
    . Don't
    worry if you cannot run these scripts on your machine, your
    patch will be automatically checked in the Actions of the pull
    request.
  • I have added an item that describes the changes I have
    introduced in this PR in the section Changes for next
    release
    of the section Change Control/Document history
    of the document. Create Changes for next release if it does
    not exist. Notice that changes that are not modifying the
    content and rendering of the specifications (both HTML and PDF)
    do not need to be listed.
  • When modifying content and/or its rendering, I have checked the
    correctness of the result in the PDF output (please refer to the
    instructions on how to build the PDFs
    locally
    ).
  • The variable draftversion is set to true in the YAML header
    of the sources of the specifications I have modified.
  • Please DO NOT add my GitHub profile to the list of contributors
    in the README page of the project.

If we split these features in the compiler (see relevant pull request
llvm/llvm-project#109299), we would only be
able to hand-write a 'memtag2' version using inline assembly since the
compiler cannot generate the instructions that become available with
FEAT_MTE2. On top of that these instructions only work at Exception
Level 1, so they would be unusable since FMV is a user space facility.
I am therefore unifying them in the ACLE specification.
@labrinea
Copy link
Contributor Author

@andrewcarlotti
Copy link

Ok, here's a suggestion that might seem to go against stuff I've previously said. How about we call the FMV feature "memtag2" to deliberately distinguish it from the "memtag" command line option? The justification for this is:

  • As a command line feature, "memtag" is enabled for cpus that might only support FEAT_MTE (and not FEAT_MTE2, depending upon configuration).
  • If we're using HWCAPS to control FMV feature gating, then the available HWCAP corresponds to FEAT_MTE2.
  • If we don't have FEAT_MTE2 at runtime, then the only benefit to using FEAT_MTE instructions would be to avoid runtime dispatch. But using FMV implies that we're already doing runtime dispatch, so there's no benefit to having FMV enable usage of the FEAT_MTE instructions on a system without FEAT_MTE2.

So the FMV feature "memtag2" would deliberately have a slightly different definition to the command line option "memtag". Internally the compiler may choose to handle this by mapping the FMV feature directly to the command line option, with the caveat that enabling the command line option does not necessarily imply that the FMV feature will be enabled at runtime.

(Adding @Wilco1 as well)

@tmatheson-arm
Copy link
Contributor

My understanding of FEAT_MTE vs FEAT_MTE2 is that (excepting the small number of EL1 instructions that are FEAT_MTE2 only) they offer the same set of instructions, which

  • on a system with FEAT_MTE2, perform tagging operations and checks
  • on a system with only FEAT_MTE, are effectively NOPS
  • on a system with neither, are undefined.

As far as the compiler is concerned, there is no difference between FEAT_MTE and FEAT_MTE2. The codegen should be identical. This is probably why they were historically combined into +memtag. This means that you can compile with +memtag, and if you have FEAT_MTE, your code will not crash but you won't get any checking, and with FEAT_MTE2 you will get checking. This is also why you can usually configure FEAT_MTE2 at boot, but FEAT_MTE is always on.

FMV complicates the situation because it is for runtime dispatch, and there is a difference between systems that implement FEAT_MTE and FEAT_MTE2. This is why it introduced +memtag and +memtag2. The codegen should be the same, but you can do dispatch on them. It's not clear whether that's important.

You might want to detect whether you have FEAT_MTE2 rather than FEAT_MTE in order to use the EL1 instructions. However, apparently FMV targets EL0 which would mean there is no need to support that in FMV.

Since we have gone down the path of keeping FMV names in sync with command line names, I think it would be silly to deviate from that at this point. I suggest we keep memtag == FEAT_MTE2.

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.

3 participants