-
Notifications
You must be signed in to change notification settings - Fork 62
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
[herd] Implement Aarch64 instruction stz2g #763
Conversation
0fa1147
to
051c3f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very good thanks Luc! I've done a quick review added a couple of comments and I will try and test it tomorrow as well.
STZG X2,[X1] ; | ||
MOV W0,#7 ; | ||
STR W0,[X2] ; | ||
STR W0,[X1,#20] ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little weird that we allow an unchecked STR to x
when previously we had a checked STR x
. It makes sense to allow unchecked locations and checked locations but mixed uses of the same location is not very realistic. But this might not be in the scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at L02 did you mean this to be:
STR W0,[X1,#20] ; | |
STR W0,[X2,#20] ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand your remark on "unchecked" STR. Which STR are checked or unchecked ?
As to STR W0,[X1,#20]
, this is what I intended. As I understand it, both STR
succeeds the first one STR W0,[X2]
stores into the granule whose color has changed to :red
, while the second STR W0,[X1,#20]
stores into the next granule, whose color has not changed and hence stayed :green
. Assuming a granule size of 16 bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, do we assume a default tag (color) for symbolic addresses as well? Meaning x is assumed to be x:green? I was under the impression we only had default values for tag locations (tag(x)).
MTE doesn’t require that all memory instructions perform a tag check. There are cases where the instruction doesn’t perform a tag check (for example stg doesn't check or a load y where y is mapped as Normal Memory and not TaggedNormal doesn’t check either). So I thought, so without checking the code, that if a symbolic address didn’t specify a colour it would signal to herd to slide the tag check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, all locations have a tag and this tag is green by default. In other words, all locations have the TaggedNormal attribute. Do we understand each other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I think I understand now. In -variant mte
:
- If tag(x) is not explicitly initialised then,
herd7
will initialise to `:green" - If a register is initialised with a symbolic location which doesn't specify a tag (for example
0:X0=x
),herd7
will assume that a default tag:green
for this symbolic address (i.e.0:X0=x:green
). - All locations are assumed to be mapped as
TaggedNormal
and now I also understand why L03
is correctly specified.
@@ -0,0 +1,16 @@ | |||
AArch64 L05 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be really good if herd7 could ignore the size of STZG for L03 but throw an error for L05. But I am not sure this is possible. So I guess you're suggesting that STZG should require mixed mode don't you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean throw an error when the target location of STZG
is an array in non-mixed mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so yes. I think it would be useful to allow herd7 to work without enabling -variant mixed
in cases like L03
after all, L03
is not incorrect (the user didn't check x[1]
they're only checking x
aka x[0]
). But L05
is wrong so they can't trust the result and they should enable -variant mixed
. What do you think? Is it possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your solution implies looking at several places in the execution: (1) apply STZG
to an array location and (2) reading some array cell different from the first.
I'd favor a solution that would look at the STZG
write only. Then if we can check that STZG base address is an array address, we can:
- Fail with a message that suggests using
-variant mixed
, or - Fill all the array cells with zero, (up to granule size ?)
Also, if the address is not known (ie not read from a register initial state) 1. applies systematically.
A more simple but less expressive solution would be to fail, still suggesting -variant mixed
when we both have some array and STZG
instruction in the same test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more simple but less expressive solution would be to fail, still suggesting -variant mixed when we both have some array and STZG instruction in the same test.
I think that's a very good middle ground. But in any case don't worry too much if it's too hard we can fix in a subsequent PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have finally implemented this middle ground, as it is relatively straightforward.
051c3f5
to
14d916f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Very nice change, looking forward to see it merged!
14d916f
to
07a0380
Compare
Adding this instruction revealed some shortcomings of the current MTE implementation. In particular it is no longer realistic to assume that a complete array will never span over more than one granule, as the STZ2G instruction sets two granules. The STZG instruction writes zero into one granule and updates its tag location, while the STG2Z instruction writes zero into two granules and updates two tag locations, some changes are required. To account for STZ2G write of two tag locations, we change the previous hypothesis that every location reside in one granule. 1. An array can now span over several granules 2. We accept size mismatches for the write of zero of STGZ. As a consequence, in non-mixed size (default) mode, STGZ will zero any non-array location, whatever its size., which is correct as long as the size of the location is less than one granule. For arrays, only the first item would be zero-ed. Thus, having both arrays and STGZ in the same test triggers a "user error" failure. However, the instruction operates as expected in mixed-size mode (`-variant mixed`). 3. Mixed-size mode is mandatory for executing STZ2G, and for executing tests with some array location and some STZG instruction. Notice: granule size is currently fixed at G=16 bytes. If necessary, command-line configuration can be implemented in the future. Notation: For a base address x, successive tag addresses are written tag(x), tag(x+G) , tag(x+2G), etc. Said otherwise, the tag address of (byte) location x+o is tag(x+(o*G)/G). Notice: In vmsa mode, since PR #695, tag addresses are based upon physical addresses and will appear as tag(PA(x)), tag(PA(x)+G),...
07a0380
to
993e8af
Compare
@relokin, merging on its way. Thanks for your review. |
Adding the instruction revealed some shortcomings of the current MTE implementation. In particular, it is no longer realistic to assume that a complete array will never span over more than one granule, as the STZ2G instruction sets two granules.
The implementation is correct only in mixed-size mode, it is then an error to execute STZG (resp. STZ2G) on a memory location whose size is strictly less than one (resp. two) granules.
For instance, with the current granule size of 16 bytes, herd will fail on the following test:
We have:
To reach granule size one has to declare an array:
Now, the test is accepted, yielding the final values of zero for
x[0]
andx[1]
.For backward compatibility
STZG
still operates in non-mixed mode, with the expected result of zeroing non-array locations, which is correct assuming that:Finally, herd will fail, flagging an error, on tests that both have some array location and some S
TZG
instruction, regardless of whetherSTZG
touches some array or not.