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

Codesize exclude psa wrappers #7980

Merged
merged 26 commits into from
Sep 26, 2023

Conversation

xkqian
Copy link
Contributor

@xkqian xkqian commented Jul 25, 2023

Description

When psa_crypto_driver_wrappers.c is created from psa_crypto_driver_wrappers.c.jinja but neither PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT nor PSA_CRYPTO_DRIVER_TEST are set, it should be possible to omit the entire wrapper function.
This PR will provide one prototype which can omit some wrapper functions, such as 2~3 functions.

PR checklist

Please tick as appropriate and edit the reasons (e.g.: "backport: not needed because this is a new feature")

  • changelog provided, or not required (Part of the epic code size)
  • backport done, or not required (Refine of code, 2.28 no needed)
  • tests provided, or not required(current test cases are enough)

@xkqian xkqian added enhancement needs-work component-crypto Crypto primitives and low-level interfaces needs-ci Needs to pass CI tests priority-high High priority - will be reviewed soon labels Jul 25, 2023
@xkqian xkqian linked an issue Jul 25, 2023 that may be closed by this pull request
@xkqian xkqian force-pushed the codesize_exclude_psa_wrappers branch from 7a15203 to 02cc720 Compare August 1, 2023 02:52
@xkqian xkqian force-pushed the codesize_exclude_psa_wrappers branch 3 times, most recently from bd1d633 to 69d361f Compare August 21, 2023 10:42
@tom-cosgrove-arm
Copy link
Contributor

@bensze01 The ABI-API checker is (reasonably) complaining that the driver wrapper API functions are no longer visible. However, they are internal, and this is an expected outcome from this PR.

Unfortunately, that causes the CI to fail. Will we just have to bypass merge queues when it comes time to merge this PR, or can we make the ABI-API check "not fatal"?

@gilles-peskine-arm
Copy link
Contributor

@tom-cosgrove-arm The ABi-API check is not fatal. The checks that have to pass for the merge queue are the ones that have the “Required” annotation.

@xkqian xkqian force-pushed the codesize_exclude_psa_wrappers branch from 5313e2e to 0633620 Compare September 5, 2023 01:43
Makefile Outdated
@@ -14,7 +14,7 @@ no_test: programs
programs: lib mbedtls_test
$(MAKE) -C programs

lib:
lib: generated_files
Copy link
Contributor

Choose a reason for hiding this comment

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

In principle, this is a good thing: it's good to ensure that the generated files are up-to-date. However this is likely to cause problems for users who work in an environment where they can't re-generate the files (no python, or not the required python modules, or no host C compiler), and where the timestamps on the generated files aren't newer than the primary sources (because the timestamps is in the random order in which the files were copied).

This is more or less went wrong in https://jenkins-mbedtls.oss.arm.com/blue/organizations/jenkins/mbed-tls-pr-head/detail/PR-7980-head/12/pipeline/582 : in this case, the build environment doesn't support make generated_files (although that's actually a bug in the makefile). Nothing would need to actually be rebuilt since the timestamps of generated files are newer than primary sources, but in this case, the failure happens before make can check this.

I think the main issue (if make runs ok but the code to generate the files might fail) can be resolved with order-only prerequisites. But it would have to be on generated_files in the sub-makefiles: an order-only prerequisite doesn't make sense when the prerequisite is phony.

This is a rather complicated makefile change which should be done in its own pull request. Do you really need it here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, not in scope for this PR (but also agreed it's potentially a nice improvement for a separate PR, if you have some spare background time for it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. I will revert it and file one issue #8163 about this case: https://jenkins-mbedtls.oss.arm.com/blue/organizations/jenkins/mbed-tls-pr-head/detail/PR-7980-head/12/pipeline/582 , in case we need one new PR to solve this.

@daverodgman
Copy link
Contributor

@xkqian is this ready for review? Please mark as needs-review and needs-reviewer if it is

@xkqian
Copy link
Contributor Author

xkqian commented Sep 6, 2023

@xkqian is this ready for review? Please mark as needs-review and needs-reviewer if it is

I will put it in review once it pass the CI.

Copy link
Contributor

@yuhaoth yuhaoth left a comment

Choose a reason for hiding this comment

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

psa_crypto_driver_wrappers.c should renamed to header file(.h) . It is included in another file now, it might confuse others with .c

library/CMakeLists.txt Show resolved Hide resolved
/*
* Functions to delegate cryptographic operations to an available
* and appropriate accelerator.
* Warning: This file is now auto-generated.
Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently this file is not generated? I don't understand why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Originally I find only there are 3 functions in this file, so just put them in the .c file, If we want to generate automatically, we should change the generate script and the the json schema, and maybe the document, that will be one big change. Anyway, I will re-work and try to generate it.

@xkqian xkqian force-pushed the codesize_exclude_psa_wrappers branch 6 times, most recently from 9c44da9 to a7a247c Compare September 12, 2023 03:50
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
@xkqian xkqian force-pushed the codesize_exclude_psa_wrappers branch from ca444b3 to db3035b Compare September 26, 2023 09:10
@xkqian
Copy link
Contributor Author

xkqian commented Sep 26, 2023

@xkqian please rebase onto development to pick up the CI fixes and hopefully get a clean CI run

Rebase done and wait for the CI result.

Copy link
Contributor

@yuhaoth yuhaoth left a comment

Choose a reason for hiding this comment

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

LGTM

@daverodgman daverodgman added needs-ci Needs to pass CI tests approved Design and code approved - may be waiting for CI or backports and removed needs-ci Needs to pass CI tests needs-review Every commit must be reviewed by at least two team members, labels Sep 26, 2023
@daverodgman daverodgman merged commit d472a8f into Mbed-TLS:development Sep 26, 2023
4 of 6 checks passed
@xkqian xkqian linked an issue Sep 27, 2023 that may be closed by this pull request
Comment on lines +359 to +361
$(GENERATED_WRAPPER_FILES): ../scripts/generate_driver_wrappers.py
$(GENERATED_WRAPPER_FILES): ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja
$(GENERATED_WRAPPER_FILES): ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja
Copy link
Contributor

Choose a reason for hiding this comment

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

$(gen_file_dep) got lost here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports component-crypto Crypto primitives and low-level interfaces enhancement priority-very-high Highest priority - prioritise this over other review work size-optimisation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code Size: Driver Wrappers: Implementation Code Size: Driver Wrappers: Prototype mechanism
7 participants