Skip to content

[herd] Load-reserve Store-Conditional may pair on different addresses#1896

Open
maranget wants to merge 2 commits into
masterfrom
lxsx-diff
Open

[herd] Load-reserve Store-Conditional may pair on different addresses#1896
maranget wants to merge 2 commits into
masterfrom
lxsx-diff

Conversation

@maranget

@maranget maranget commented Jul 3, 2026

Copy link
Copy Markdown
Member

The following test may succeed:

AArch64 L020
(* Observed on many systems with `-mode presi` or `-s 4` *)
{
 0:X0=x; 0:X2=y;
}
 P0              ;
 LDXR W1,[X0]    ;
 MOV W3,#1       ;
 STXR W4,W3,[X2] ;
exists([y]=1)

@maranget

maranget commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

Draft, for comments and -variant vmsa,asl still following the old semantics.

@maranget maranget force-pushed the lxsx-diff branch 3 times, most recently from 3fee515 to 4e75239 Compare July 3, 2026 10:34

@relokin relokin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks good to me but I have a couple of comments about the tests.

Comment thread herd/tests/instructions/AArch64/L106.litmus
Comment thread herd/tests/instructions/AArch64/L020.litmus Outdated
@maranget

maranget commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

Hi @relokin. What this PR basically does is changing the test that controls performing the store conditional.

First observe that the reservation (a.k.a exclusive monitor) is implemented by using a unique register RES (for AArch64, VMSA and ASL. VMSA+ASL uses an additional flag). Schematic behaviour is a follows

  1. Initially this register holds the null pointer (i.e. 0).
  2. LDXR sets RES to its effective address.
  3. STRX perform a check on RES : (a) old check compare STXR effective address with RES; or (b) new check , checks that the contents of RES is different from null. Perform store when the check passes. Always reset RES to null.

See also the tests L020 (LDXR and STXR to different addresses, store was always failing now it may succeed) and L021 (LDXR followed by two STXR, all to the same address, the second STXR never succeeds).

Finally an new test L106 consists in a simple STXR, without LDXR, the store normally always fails but may succeed when -variant ConstrainedUnredictable is specified.

@maranget maranget force-pushed the lxsx-diff branch 2 times, most recently from 832dc8d to eaecbf6 Compare July 6, 2026 12:58
@maranget

maranget commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

I have also added L107 (L021 with -variant CU). The current implementation of this PR can perform the second STXR. I am not sure at all that the result is correct, as the description of the local monitor does suggest that this variant have no impact on the local monitor being cleared (here).

AArch64 L107
(* Can the second STXR succeed? *)
Variant=CU
{
int x=1;
0:X0=x;
}
 P0               ;
 MOV W3,#2        ;
 MOV W5,#3        ;
 LDXR W1,[X0]     ;
 STXR W4,W3,[X0]  ;
 STXR W6,W5,[X0]  ;
exists 0:X4=1 /\ 0:X6=0 /\ x=3

@relokin

relokin commented Jul 7, 2026

Copy link
Copy Markdown
Member

Looks good to me. Perhaps one concern I have is that for AArch64 -variant CU is not modelling any architecturally valid behaviours. In other words, it shouldn't be used by most users.

@maranget

maranget commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Looks good to me. Perhaps one concern I have is that for AArch64 -variant CU is not modelling any architecturally valid behaviours. In other words, it shouldn't be used by most users.

Thanks @relokin. I'll delay considering merging until PR #1889 is merged.

maranget added 2 commits July 10, 2026 10:13
Given x and y that are different addresses `LDXR x; ...; STXR y`,
STXR to y can succeed.

Hence, the only situation when STXR always fail is
when there is no reservation, which we implement by the reservation
address being null.

Detailed changes:
 + The new semantics is also implemented for AArch64 ASL and ASL+VMSA
   modes
 + With `-variant ConstrainedUnpredictable`, STXR can succeed even in
   the absence of a reservation (non-ASL only, no access to variant in ASL).
 + Same semantics of LR/SC pairs for RISCV
   Notice that this semantics (SC can succeed event with a reservation
   to a different address) was activated by the  variant `LrScDiffOk`.
   This behaviour now being the default, we suppress the variant.
 + Add constrained unpredictable tests
   Note that these tests are disabled in ASL mode.
   (No access to the ConstrainedUnpredicable variant)

 + Add "LDXR x; LDXR y, STXR x" tests.
@maranget maranget marked this pull request as ready for review July 10, 2026 08:24
@maranget

Copy link
Copy Markdown
Member Author

Hi @relokin and @HadrienRenaud. Rebased on master since prerequisite PR #1889 is merged, all commits squashed into two commits, ready for review.

@HadrienRenaud HadrienRenaud left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks ok to me but I think the handling of reserved addresses in ASL could be cleaner.

Comment thread herd/AArch64ASLSem.ml
| _ ->
if setzero then
state_add loc ASLS.V.zero st
else st

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't really understand why this is needed. In both physmem-*.asl, the address is initialised to Zeros{_}

Also the initial environment would not be correctly typed checked: this is an integer and we expect a 56 or 64 bits bitvector (depending on whether VMSA is activated, i.e. whether RESADDR stores a physical or virtual address)


if SuccessVA then
CheckEq(address, reserved);
CheckProp(reserved != 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

reserved has type bits(64) here

Suggested change
CheckProp(reserved != 0);
CheckProp(!IsZeros(reserved));

or

Suggested change
CheckProp(reserved != 0);
CheckProp(reserved != Zeros{64});


if SuccessPA then
CheckEq(paddress.address, reserved);
CheckProp(reserved != 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

reserved has type bits(56) here

Suggested change
CheckProp(reserved != 0);
CheckProp(!IsZeros(reserved));

Or

Suggested change
CheckProp(reserved != 0);
CheckProp(reserved != Zeros{56});

@maranget maranget Jul 11, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Consider two STXR in a row. The first STXR sets the RES register to zero (integer zero) and this value is seen as zero (integer) by the next STXR. In the case we have no LDXR nor STXR before an exclusive instruction, RES is not initialised, hence the setzero flag above...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @maranget, I think there was a misunderstanding for what I was suggesting, so I implemented it in #1914. Please consider merging it in this branch before merging this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I no longer have time to do this in a safe manner, I leave it to you.

@relokin

relokin commented Jul 10, 2026

Copy link
Copy Markdown
Member

Not really the point of this PR so you can go ahead and merge as soon as @HadrienRenaud is happy but I don't understand why we support -variant cu in AArch64. -variant cu models behaviours which are architecturally forbidden. If the point of -variant cu is to enable forbidden behaviours then I think we need to change the name of this variant. CONSTRAINED UNPREDICTABLE has a specific meaning for the AArch64 architecture and the behavious of -variant cu are not CONSTRAINED UNPREDICTABLE. Perhaps these should have been behaviours one would expect from -through all?

@maranget

Copy link
Copy Markdown
Member Author

I do not understand the intent of -variant CU. I'd gladly keep it out of LR/SC if you think this is the thing to do. As far as I remember, some usage of this variant in mixed-size mode was less problematic.

@maranget

Copy link
Copy Markdown
Member Author

some usage of this variant in mixed-size mode was less problematic.

My bad, this usage is for generators... Hence we can suppress -variant CU in herd7, having STXR to succeed whatever the context is being the only occurrence of this variant.

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