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

Upgrade to OPTEE 3.11.0&3.12.0 #24

Merged
merged 4 commits into from
Feb 23, 2021
Merged

Upgrade to OPTEE 3.11.0&3.12.0 #24

merged 4 commits into from
Feb 23, 2021

Conversation

DemesneGH
Copy link
Contributor

Hi @mssun ,
As we discussed before, we have upgraded the sdk to OPTEE 3.11.0 and it passed the ci test locally.

The changes we made are:

  1. Upgrade optee submodules to 3.11.0(in optee/)
  2. Modify some code in optee-utee:
    1)change name of utee syscalls(in tee_api_defines.rs,utee_syscalls.rs,trace.rs).
    2)add -O0 in .cargo/config to avoid generating ta elf with nbuckets==0(which causes ldelf panic).
    3)add definition of __ta_entry(in user_ta_header.rs,tee_api_private.rs,.cargo/config,examples/xxx/ta/ta_static.rs).
    4)change examples/xxx/ta/ta_aarch64.lds to ensure GOT is writable.
  3. Modify some code in these examples:
    •authentication
    •diffie_hellman
    •random
    •secure_storage

The new sdk is compatible with OPTEE 3.11.0&3.12.0.Built TAs can run on OPTEE OS 3.8.0,3.11.0 and 3.12.0.Other versions have not been tested.

Contributors are Rong Fan@fanrong1992 and Yuan Zhuang@DemesneGH.

Best regards,
Yuan Zhuang

.cargo/config Outdated Show resolved Hide resolved
.cargo/config Outdated Show resolved Hide resolved
examples/diffie_hellman/host/src/main.rs Outdated Show resolved Hide resolved
examples/diffie_hellman/ta/src/main.rs Outdated Show resolved Hide resolved
examples/random/host/src/main.rs Outdated Show resolved Hide resolved
examples/secure_storage/ta/src/main.rs Outdated Show resolved Hide resolved
examples/authentication/ta/src/main.rs Outdated Show resolved Hide resolved
examples/authentication/ta/src/main.rs Outdated Show resolved Hide resolved
examples/authentication/ta/src/main.rs Outdated Show resolved Hide resolved
examples/random/ta/src/main.rs Outdated Show resolved Hide resolved
@mssun
Copy link
Member

mssun commented Feb 22, 2021

Thanks for your contributions. @xiangmy, can you help to review this PR? Thanks.

@xiangmy
Copy link

xiangmy commented Feb 23, 2021

Hi @DemesneGH @mssun

Thanks for the work! The __ta_entry and __utee_return are diverging functions, so I think we should reflect that. The reset changes look good to me.

BTW, I also add "-C", "link-arg=max-page-size=4096" in the .cargo/config to force the TA to align at 4 KB. But, I guess the -O0 flag solves this problem as well as the ldelf panic which I don't know how to deal with. I suppose there would be some better options instead of removing the optimization.

Anyway, thanks for the good work!
Mingyuan

@DemesneGH
Copy link
Contributor Author

Hi @xiangmy

But, I guess the -O0 flag solves this problem as well as the ldelf panic which I don't know how to deal with. I suppose there would be some better options instead of removing the optimization.

The -O0 flag has the same effect as setting opt-level=1 in examples/xxx/ta/Cargo.toml.Since the default value is opt-level=3 for rust release binaries, it will add a -O1 when linking the TA elf.Maybe there is a bug of ld which leads invalid nbuckets under some circumstances, or OPTEE OS should check the value of nbuckets.
Since the link.mk for TA in OPTEE examples written in C doesn't have the optimization too, we removed the optimization to solve the problem.If there are better solutions we will update then.

Best Regards,
Yuan

@xiangmy
Copy link

xiangmy commented Feb 23, 2021

Hi @DemesneGH ,

The -O0 gives no optimization, and it's corresponding to opt-level=0. The OPTEE uses -Os by default (see here). I'm not sure about the default opt-level for this sdk. Maybe @mssun can help clarify this.

Thanks,
Mingyuan

@DemesneGH
Copy link
Contributor Author

Hi @xiangmy
We printed link args by add "-Z", "print-link-args" then found this sdk uses opt-level=3 for release binaries defaultly(same as default profiles here), which leads adding -O1.When setting opt-level=1(or opt-level=0) there are no -Ox arguments,which is same as -O0.
I didn't see -Os in printed link args, but I'll try to add -Os to find the difference.

Best regards,
Yuan

@DemesneGH
Copy link
Contributor Author

Hi @xiangmy

The OPTEE uses -Os by default (see here).

This mk file is probably for OPTEE OS binaries(such as tee.elf), not for TAs.Link.mk for TA is in here,which is a part of ta_dev_kit(imported when building TAs),and it seems not having -Os.

Best Regards
Yuan

@DemesneGH
Copy link
Contributor Author

Hi @mssun
Thanks for your review.I've updated the code.

Best Regards,
Yuan

@xiangmy
Copy link

xiangmy commented Feb 23, 2021

Hi @xiangmy

The OPTEE uses -Os by default (see here).

This mk file is probably for OPTEE OS binaries(such as tee.elf), not for TAs.Link.mk for TA is in here,which is a part of ta_dev_kit(imported when building TAs),and it seems not having -Os.

Best Regards
Yuan

Hi @DemesneGH ,

TAs have the same optimization level as the OS. The flow of passing the -Os flag is (for aarch64):
platform-cflags-optimization -> ta_arm64-platform-cflags -> ta-mk-file-export-vars-ta_arm64 -> ta.mk

Would adding -Os (instead of -O0) and opt-level = "s" work in our case?

Thanks,
Mingyuan

@DemesneGH
Copy link
Contributor Author

Hi @xiangmy

Would adding -Os (instead of -O0) and opt-level = "s" work in our case?

Yes.Adding -Os instead of -O0 works, and set opt-level="s"will also add -Os in link arguments.
I‘ve tried several cases and the results are:

  1. Setting opt-level="s" will add -Os,builds elf of nbuckets == 1
  2. Setting opt-level=3 will add -O1,builds elf of nbuckets == 0
  3. Setting opt-level=2 will add -O1,builds elf of nbuckets == 0
  4. Setting opt-level=1 will not add -Ox(-O0 by default),builds elf of nbuckets == 1
  5. Setting opt-level=0 will not add -Ox(-O0 by default),builds elf of nbuckets == 1

This man page says :

-Os enables all -O2 optimizations except those that often increase code size:
-falign-functions -falign-jumps
-falign-labels -falign-loops
-fprefetch-loop-arrays -freorder-blocks-algorithm=stc

But it's still unclear what the optimizations do and what leads illegal nbuckets.
Anyway,thanks for your advice.I'll update -O0 to -Os.

Best regards,
Yuan

@mssun mssun merged commit 2ff2322 into apache:master Feb 23, 2021
@mssun
Copy link
Member

mssun commented Feb 23, 2021

Merged. Thank you all!

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