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

Adds MBEDTLS_THREADING_C implementation for Windows using srwlock #7180

Open
wants to merge 9 commits into
base: development
Choose a base branch
from

Conversation

fwh-dc
Copy link

@fwh-dc fwh-dc commented Feb 27, 2023

Description

Adds default support for threading layer on Windows using srwlocks.

This work is based on a previous pull request #2306 and is rebased to the current tip of development and modified accordingly.

Gatekeeper checklist

  • changelog provided, or not required
  • backport done, or not required
  • tests provided, or not required

Notes for the submitter

Please refer to the contributing guidelines, especially the
checklist for PR contributors.

SergeySeroshtan and others added 4 commits February 27, 2023 10:57
Signed-off-by: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
…OCK by default

Signed-off-by: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
Signed-off-by: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
Signed-off-by: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
@davidhorstmann-arm davidhorstmann-arm added needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review size-s Estimated task size: small (~2d) labels Feb 28, 2023
@gilles-peskine-arm gilles-peskine-arm added needs-work and removed needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review labels Mar 2, 2023
@gilles-peskine-arm
Copy link
Contributor

There are many test failures. Please check the logs on Travis and "TF OpenCI: PR-7180-head" (the "Internal CI" jobs are duplicates of the OpenCI ones because we're in a transition, don't worry about those).

@fwh-dc
Copy link
Author

fwh-dc commented Mar 6, 2023

@gilles-peskine-arm
Thanks for pointing out where to look. I believe I have a fix. Is there a way to run the tests without pushing a new change to this PR? Or what is the preferred way?

…OCK for windows test build. And adds MBEDTLS_THREADING_SRWLOCK to the list of items that are excluded from a 'full config'.

Signed-off-by: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
@gilles-peskine-arm
Copy link
Contributor

@fwh-dc Most of the testing is done by running tests/scripts/all.sh on a Linux machine. Pass the name of the failing component, e.g. https://ci.staging.trustedfirmware.org/blue/organizations/jenkins/mbed-tls-pr-head/detail/PR-7180-head/1/pipeline/448 runs tests/scripts/all.sh build_arm_linux_gnueabi_gcc_arm5vte. For TLS testing you need specific versions of some tools, the easiest way is to use our Docker images. You don't need to test everything locally (we especially don't expect you to test with proprietary compilers).

@fwh-dc
Copy link
Author

fwh-dc commented Mar 9, 2023

@gilles-peskine-arm

Looked in to the remaining failures and seems to be:

  • all_u16-check_names: 'WIN32_LEAN_AND_MEAN' does not match the required pattern '^(MBEDTLS|PSA)[0-9A-Z]*[0-9A-Z]$'.
  • all_u18-build_mingw: several implicit declaration of function errors. Due to missing #define _WIN32_WINNT 0x0600 for syncapi.h header.
  • all_u18-check_code_style: Minor style fixes that are easily fixed.

WIN32_LEAN_AND_MEAN is only to make compilation faster so it could be removed.
But to use SRWLOCK I have to make sure that #define _WIN32_WINNT 0x0600 is defined before including syncapi.h and that would also fail the all_u16-check_names check. I assume.

Should I make an opaque type mbedtls_srwlock_t in the header and use that for a pointer?
Or make lock a void pointer?

Please let me know what you prefer. I'll fix the code style to fix the last bulletpoint.

Signed-off-by: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
/*
* Use spaces to pass the macroses name check.
*/
# define WIN32_LEAN_AND_MEAN
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add WIN32_LEAN_AND_MEAN and _WIN32_WINNT to the exclusions list in parse_macros in tests/scripts/check_names.py. That's how we deal with the similar case of _CRT_SECURE_NO_DEPRECATE.

/*
* Use spaces to pass the macroses name check.
*/
# define WIN32_LEAN_AND_MEAN
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment explaining why WIN32_LEAN_AND_MEAN is good to have. After 30 seconds on the web, I guess it's to avoid conflicts with some other headers?

(For _WIN32_WINNT, even without knowing anything about Windows programming, it's obvious to me that it specifies the API version that we're requesting, similar to #define _POSIX_C_SOURCE on Unix-like systems.)

@gilles-peskine-arm
Copy link
Contributor

Should I make an opaque type mbedtls_srwlock_t in the header and use that for a pointer?

That would require all mbedtls_srwlock_t objects to be heap-allocated. So mbedtls_threading_mutex_t would have to contain a pointer which would need to be allocated and freed. It's more convenient and less error-prone to keep the object directly in the structure. That requires knowing its size, so we do need the declaration of SRWLOCK.

See my other comment for how to deal with check_names.

…threading.h to enable srwlock api.

Signed-off-by: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
Signed-off-by: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
Signed-off-by: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
@fwh-dc
Copy link
Author

fwh-dc commented Mar 23, 2023

@gilles-peskine-arm
I believe I have fixed the remaining CI errors related to this PR. However there is one failing which seems to be related to a missing license? Can you please clarify if I have to do something to fix that?

Other than that, I'd like you to have a look at this and let me know if there's something more that needs fixing.

@gilles-peskine-arm gilles-peskine-arm added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Apr 9, 2023
@gilles-peskine-arm gilles-peskine-arm added needs-reviewer This PR needs someone to pick it up for review needs-work labels Apr 9, 2023
@gilles-peskine-arm
Copy link
Contributor

There was a temporary problem with the license server. I've restarted the job.

At first glance this seems to be in the right shape, but we'll need to do a full review.

Please add a changelog entry (see ChangeLog.d/00README.md) under “Features”.

We're only testing that the build works with MBEDTLS_THREADING_SRWLOCK enabled, and only with MinGW. We also do builds with Visual Studio; we only run selftest.exe, which isn't much (there's no concurrency) but is better than nothing (the RSA self-test takes a mutex if threading is enabled). The test script is in a separate repository. We should make it enable MBEDTLS_THREADING_C and MBEDTLS_THREADING_SRWLOCK, but we need to be careful because this repository is unversioned so it must work with versions of Mbed TLS that have MBEDTLS_THREADING_SRWLOCK as well as with versions that don't have it. I'm not sure if we should set this up before merging the code or after.

What testing have you done locally? With what compiler(s) version(s)?

@daverodgman daverodgman added historical-reviewing Currently reviewing (for legacy PR/issues) historical-reviewed Reviewed & agreed to keep legacy PR/issue and removed historical-reviewing Currently reviewing (for legacy PR/issues) labels Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
historical-reviewed Reviewed & agreed to keep legacy PR/issue needs-ci Needs to pass CI tests needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review needs-work size-s Estimated task size: small (~2d)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants