8374755: ML-KEM's 12-bit decompression can be simplified on aarch64#29141
8374755: ML-KEM's 12-bit decompression can be simplified on aarch64#29141ferakocz wants to merge 3 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back ferakocz! A progress list of the required criteria for merging this PR into |
|
@ferakocz This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 169 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@adinn) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
Webrevs
|
|
Changes look good. What testing have you run? |
Thank you for your review. I've ran the ACVP tests for ML-KEM, which have all passed (default and intrinsics (aarch64)). |
| assert ((parsed.length >= n * 128) && | ||
| (condensed.length >= index + n * 192)); |
There was a problem hiding this comment.
Given the comments, can this be simplified to just:
- int n = (parsedLength + 127) / 128;
- assert ((parsed.length >= n * 128) &&
- (condensed.length >= index + n * 192));
+ assert((parsed.length % 128) == 0) && (condensed.length % 192 == 0));
If the length is smaller than the constant then the remainder will be non-zero.
There was a problem hiding this comment.
These are the exact conditions that the most demanding intrinsic (the AVX-512 one) requires. If we would rely on that the callers satisfy these, we wouldn't need the assert :-) . The loop in the intrinsic will read n * 192 bytes and write n * 128 shorts, your suggestion would not ensure that the arrays have at least that much space.
There was a problem hiding this comment.
Ah, I see that now. Maybe an update to the comments would alleviate my confusion?:
NEW:
// An intrinsic implementation assumes that the input and output buffers
// are such that condensed can be read in n-multiples of 192 bytes and
// parsed can be written in n-multiples of 128 shorts, so callers should allocate
// the condensed and parsed arrays to at least these amounts, see the assert()
| __ sub(parsedLength, parsedLength, 64); | ||
| __ cmp(parsedLength, (u1)64); | ||
| __ cmp(parsedLength, (u1)0); | ||
| __ br(Assembler::GE, L_loop); |
There was a problem hiding this comment.
Yes, I believe it should. That makes me wonder why the test did not fail. I would have expected it to loop back to the top and try to consume an extra 96 bytes of non-existent input and write it to 64 bytes of of non-existent output buffer? Did this erroneous computation not happen? or was the error simply not manifest?
There was a problem hiding this comment.
It is a buffer overflow, so if the memory after the arrays is there, it would be read/written, if you are lucky, it doesn't overwrite anything that is used later, so it might be able to pass a test program (which definitely had happened here).
There was a problem hiding this comment.
Yes, it should. Fixed.
| // byte[] condensed, int index, short[] parsed, int parsedLength) {} | ||
| // | ||
| // (parsedLength or (parsedLength - 48) must be divisible by 64.) | ||
| // it is assumed that parsed and condensed are allocated such that for |
There was a problem hiding this comment.
By whom? :-)
| // it is assumed that parsed and condensed are allocated such that for | |
| // we assume that parsed and condensed are allocated such that for |
| vs_st2_post(vs_front(va), __ T8H, parsed); | ||
| vs_st2_post(vs_front(vs_front(vb)), __ T8H, parsed); | ||
|
|
||
| __ BIND(L_end); |
There was a problem hiding this comment.
This is a substantial change, not a mere matter of "incorrect assertions". Perhaps this PR needs a more appropriate title.
There was a problem hiding this comment.
Also, the description in the JIRA and the opening comment in this PR should mention that the intrinsic can be simplified in response to the stricter preconditions maintained by the Java client.
adinn
left a comment
There was a problem hiding this comment.
This looks good now, thank you.
I'm a little unhappy that the initial test did not detect the reads and writes that overflowed the end of, respectively, the input and output arrays. That may indeed be fixed now but it would have been nicer it the test had been able to catch the error. However, I understand that it is hard to achieve that when driving the VM from Java. So, let's hope we don't need any more changes or, if we do, we do our best to ensure (by eyeball) that we don't overshoot the end of the arrays.
|
/approve yes |
|
@smemery Only integrators for this repository are allowed to issue the |
|
Thanks! @adinn would you be so kind as to /sponsor the integration? |
|
/integrate |
|
I believe this needs a second sign-off. @theRealAph can you do the honours? |
|
/sponsor |
|
Going to push as commit 9911959.
Your commit was automatically rebased without conflicts. |
|
@wangweij Thanks for sponsoring. While that probably counts implicitly as a review I think you are supposed to actually click the 'reviewed' button to acknowledge that you have reviewed the code. n.b. Although the PR says only one review is required a Hotspot change actually needs two reviews with at least one (big R) 'Reviewer'. |
|
Didn't notice the reviewer count. Maybe the Skara bot hasn't enforced it. Otherwise, it should not add the I typed |
The preconditions for the aarch64 and the AVX-512 intrinsic implementations of the implKyber12To16() method of com.sun.crypto.provider.ML_KEM are different and the AVX-512 one has stricter preconditions on the input, which was not recorded in the assert() before calling the function (although they were satisfied by all calling code). Now the assert() is corrected, and with these preconditions, the aarch64 implementation is simplified.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/29141/head:pull/29141$ git checkout pull/29141Update a local copy of the PR:
$ git checkout pull/29141$ git pull https://git.openjdk.org/jdk.git pull/29141/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 29141View PR using the GUI difftool:
$ git pr show -t 29141Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/29141.diff
Using Webrev
Link to Webrev Comment