jdk icon indicating copy to clipboard operation
jdk copied to clipboard

8334999: RISC-V: implement AES single block encryption/decryption intrinsics

Open ArsenyBochkarev opened this issue 1 year ago • 13 comments

Hello everyone! Please review this port of vector AES single block encryption/decryption intrinsics. On my QEMU with Zvkned extension enabled the test/hotspot/jtreg/compiler/codegen/aes/TestAESMain.java test is OK. I know that currently hardware implementing this extension is not available on the market but I suppose this PR can be a good starting point on supporting AES intrinsics for RISC-V in OpenJDK.


Progress

  • [ ] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • [x] Change must not contain extraneous whitespace
  • [x] Commit message must refer to an issue

Issue

  • JDK-8334999: RISC-V: implement AES single block encryption/decryption intrinsics (Sub-task - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19960/head:pull/19960
$ git checkout pull/19960

Update a local copy of the PR:
$ git checkout pull/19960
$ git pull https://git.openjdk.org/jdk.git pull/19960/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19960

View PR using the GUI difftool:
$ git pr show -t 19960

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19960.diff

Webrev

Link to Webrev Comment

ArsenyBochkarev avatar Jun 30 '24 14:06 ArsenyBochkarev

:wave: Welcome back ArsenyBochkarev! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

bridgekeeper[bot] avatar Jun 30 '24 14:06 bridgekeeper[bot]

@ArsenyBochkarev 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:

8334999: RISC-V: implement AES single block encryption/decryption intrinsics

Reviewed-by: fyang, rehn, yzhu

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 76 new commits pushed to the master branch:

  • c40bb7621c0e49581dac587b6900b6d281572813: 8343296: IGV: Show pre/main/post at CountedLoopNodes
  • dee0982c603b389148a2e615c10c1276c3c589ae: 8343132: Remove temporary transitions from Virtual thread implementation
  • 2f1ba5ef09441ed9e505fe2e17c57ccb1771f777: 8343307: Throw ZipException instead of IAE in ZipFile.Source::initCEN
  • 388d44fbf0126f253860edc88c2efd57f86e5a2b: 8342156: C2: Compilation failure with fewer arguments after JDK-8329032
  • 688e92e7f5febddd2935cb7f500dd3f10fbd9401: 8342642: Class loading failure due to archived map issue in ModuleLoaderMap.Mapper
  • f340ab2d360b5dfd375095ac053e9f4fc22a98de: 8342181: Update tests to use stronger Key and Salt size
  • cc2fb4d3bd52a0f0b2c92e0b5490e003f9ba55ee: 8337276: jcmd man page update for PID in output filenames
  • 02ea4b548ea1d5e96b9e59e2aa916d7728844116: 8342635: javax/swing/JFileChooser/FileSystemView/WindowsDefaultIconSizeTest.java creates tmp file in src dir
  • 7461dfe9c652542ef4e8f8fe36ac601ebd345492: 8341788: Fix ExceptionOccurred in hotspot
  • 9a9ac1d0059438d33fe69ef51265dc7cff6ad2bd: 8341927: Replace hardcoded security providers with new test.provider.name system property
  • ... and 66 more: https://git.openjdk.org/jdk/compare/d1540e2a49c7a41eb771fc9896c367187d070dec...master

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 (@robehn, @RealFYang) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

openjdk[bot] avatar Jun 30 '24 14:06 openjdk[bot]

@ArsenyBochkarev The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

openjdk[bot] avatar Jun 30 '24 14:06 openjdk[bot]

As for comparison with the openssl version: first of all, thanks for the sources, @RealFYang! The main difference that I see is that they introduced three different different versions of encryption depending on the key sizes, which allows them to skip a couple of instructions, like when I did vaesem_vv(res, vzero) followed by vxor_vv(res, res, vtemp1). So I thought it'll be more efficient to replace the current version by something openssl-lookalike. The only problem I see is increasing code size a bit. Please let me know if we are not interested in this change for some reason

ArsenyBochkarev avatar Jul 14 '24 14:07 ArsenyBochkarev

As for comparison with the openssl version: first of all, thanks for the sources, @RealFYang! The main difference that I see is that they introduced three different different versions of encryption depending on the key sizes, which allows them to skip a couple of instructions, like when I did vaesem_vv(res, vzero) followed by vxor_vv(res, res, vtemp1). So I thought it'll be more efficient to replace the current version by something openssl-lookalike. The only problem I see is increasing code size a bit. Please let me know if we are not interested in this change for some reason

Does vaesz_vs help in anyway? And what about the generate_aescrypt_decryptBlock? [1]

[1] https://github.com/openssl/openssl/blob/master/crypto/aes/asm/aes-riscv64-zvkned.pl#L451

RealFYang avatar Jul 18 '24 08:07 RealFYang

@ArsenyBochkarev This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

bridgekeeper[bot] avatar Aug 15 '24 12:08 bridgekeeper[bot]

Hello @RealFYang! Sorry for such a late reply.

Does vaesz_vs help in anyway?

As far as I know, the vaesz_vs instruction is just an alias for vxor, so it was already utilized in this patch.

generate_aescrypt_decryptBlock

I missed this case in initial multiversioning commit, so I multiversioned the decrypt intrisic also, thanks for pointing it out!

ArsenyBochkarev avatar Sep 08 '24 13:09 ArsenyBochkarev

@RealFYang following up on your questions. I would love to see this one go through as it promises some pretty significant gains on compatible hardware! Thanks again

luhenry avatar Sep 19 '24 08:09 luhenry

@RealFYang following up on your questions. I would love to see this one go through as it promises some pretty significant gains on compatible hardware! Thanks again

Yeah, will take another look. Have you tried this on real hardware? Interesting to see the numbers.

RealFYang avatar Sep 19 '24 08:09 RealFYang

Yeah, will take another look. Have you tried this on real hardware? Interesting to see the numbers.

There is no real hardware that I know of that have vector crypto just yet. I expect it's one of these that we'll want to test as soon as hardware is available, and even possibly enable by default then

luhenry avatar Sep 20 '24 09:09 luhenry

Hi all! I'm sorry for such a late replies. I was able to optimize decryption sequence by using keys from encryption stage with reversed rounds order

ArsenyBochkarev avatar Oct 17 '24 22:10 ArsenyBochkarev

Thanks for the update. Do you mind several more minor cleanups? Looks good to me otherwise. Thanks. addon-cleanup.diff.txt

yhzhu20 avatar Oct 22 '24 05:10 yhzhu20

@yhzhu20 Done!

ArsenyBochkarev avatar Oct 24 '24 21:10 ArsenyBochkarev

@ArsenyBochkarev Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

openjdk[bot] avatar Oct 24 '24 22:10 openjdk[bot]

@yhzhu20 Done!

Thank you. Approved.

yhzhu20 avatar Oct 25 '24 03:10 yhzhu20

Thanks everyone for all the comments and reviews!

ArsenyBochkarev avatar Oct 31 '24 12:10 ArsenyBochkarev

/integrate

ArsenyBochkarev avatar Oct 31 '24 12:10 ArsenyBochkarev

@ArsenyBochkarev Your change (at version a620b6a939ef9fd3eb14a0cf9d5dcf8c88c8a6a1) is now ready to be sponsored by a Committer.

openjdk[bot] avatar Oct 31 '24 12:10 openjdk[bot]

/sponsor

VladimirKempik avatar Oct 31 '24 12:10 VladimirKempik

Going to push as commit e5bbad059d5dc293288ac415c9f7d0fa89c64b74. Since your change was applied there have been 76 commits pushed to the master branch:

  • c40bb7621c0e49581dac587b6900b6d281572813: 8343296: IGV: Show pre/main/post at CountedLoopNodes
  • dee0982c603b389148a2e615c10c1276c3c589ae: 8343132: Remove temporary transitions from Virtual thread implementation
  • 2f1ba5ef09441ed9e505fe2e17c57ccb1771f777: 8343307: Throw ZipException instead of IAE in ZipFile.Source::initCEN
  • 388d44fbf0126f253860edc88c2efd57f86e5a2b: 8342156: C2: Compilation failure with fewer arguments after JDK-8329032
  • 688e92e7f5febddd2935cb7f500dd3f10fbd9401: 8342642: Class loading failure due to archived map issue in ModuleLoaderMap.Mapper
  • f340ab2d360b5dfd375095ac053e9f4fc22a98de: 8342181: Update tests to use stronger Key and Salt size
  • cc2fb4d3bd52a0f0b2c92e0b5490e003f9ba55ee: 8337276: jcmd man page update for PID in output filenames
  • 02ea4b548ea1d5e96b9e59e2aa916d7728844116: 8342635: javax/swing/JFileChooser/FileSystemView/WindowsDefaultIconSizeTest.java creates tmp file in src dir
  • 7461dfe9c652542ef4e8f8fe36ac601ebd345492: 8341788: Fix ExceptionOccurred in hotspot
  • 9a9ac1d0059438d33fe69ef51265dc7cff6ad2bd: 8341927: Replace hardcoded security providers with new test.provider.name system property
  • ... and 66 more: https://git.openjdk.org/jdk/compare/d1540e2a49c7a41eb771fc9896c367187d070dec...master

Your commit was automatically rebased without conflicts.

openjdk[bot] avatar Oct 31 '24 12:10 openjdk[bot]

@VladimirKempik @ArsenyBochkarev Pushed as commit e5bbad059d5dc293288ac415c9f7d0fa89c64b74.

:bulb: You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

openjdk[bot] avatar Oct 31 '24 12:10 openjdk[bot]