Skip to content

Add pta self test for firmware handoff#7352

Merged
jforissier merged 3 commits into
OP-TEE:masterfrom
raymo200915:fw_handoff_ut
May 5, 2025
Merged

Add pta self test for firmware handoff#7352
jforissier merged 3 commits into
OP-TEE:masterfrom
raymo200915:fw_handoff_ut

Conversation

@raymo200915
Copy link
Copy Markdown
Contributor

@raymo200915 raymo200915 commented Apr 4, 2025

Fix a pointer casting bug in transfer_list_add().

Add self tests for transfer list.
Adapt CFG_TRANSFER_LIST with its dependencies and add CFG_TRANSFER_LIST_TEST.

Xtest entry is added at:
OP-TEE/optee_test#788

Build with Transfer List enabled is added at:
OP-TEE/build#821

Comment thread core/kernel/transfer_list.c Outdated
Comment thread mk/config.mk Outdated
Comment thread core/pta/tests/sub.mk Outdated
Comment thread core/pta/tests/transfer_list.c Outdated
Comment thread core/pta/tests/transfer_list.c Outdated
Comment thread core/pta/tests/transfer_list.c Outdated
Comment thread core/pta/tests/invoke.c Outdated
Comment thread core/pta/tests/transfer_list.c Outdated
@jforissier
Copy link
Copy Markdown
Contributor

For "core: kernel: fix bug in transfer_list_add" with the fixup:
Please add parentheses in the commit subject: transfer_list_add(), then:
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>

@jforissier
Copy link
Copy Markdown
Contributor

For commit "core: pta: add self tests for transfer list" with the fixups and Jens' comment addressed:
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>

Comment thread core/pta/tests/transfer_list.c Outdated
tl->alignment != TRANSFER_LIST_INIT_MAX_ALIGN ||
tl->size != sizeof(*tl) ||
tl->max_size != TEST_TL_MAX_SIZE ||
tl->flags != TL_FLAGS_HAS_CHECKSUM) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also check transfer_list_verify_checksum()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added.

Comment thread mk/config.mk Outdated
Comment thread mk/config.mk Outdated
$(eval $(call cfg-enable-all-depends,CFG_TRANSFER_LIST, \
CFG_DT CFG_EXTERNAL_DT CFG_MAP_EXT_DT_SECURE))

CFG_TRANSFER_LIST_TEST ?= $(CFG_TRANSFER_LIST)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A short description would be nice. Maybe tell that CFG_ENABLE_EMBEDDED_TESTS needs to be enabled to have the test embedded.

Copy link
Copy Markdown
Contributor Author

@raymo200915 raymo200915 Apr 9, 2025

Choose a reason for hiding this comment

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

I guess you mean CFG_TEE_CORE_EMBED_INTERNAL_TESTS?

I can replace it with:

CFG_TRANSFER_LIST_TEST ?= $(call cfg-all-enabled,CFG_TRANSFER_LIST \
			    CFG_TEE_CORE_EMBED_INTERNAL_TESTS)

and move it under the line:

# Enable core self tests and related pseudo TAs
CFG_TEE_CORE_EMBED_INTERNAL_TESTS ?= $(CFG_ENABLE_EMBEDDED_TESTS)

Then we don't need to add additional inline comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess you mean CFG_TEE_CORE_EMBED_INTERNAL_TESTS?

Yes, sorry.

I can replace it with:
(...)

Sound good to me, still with a short description for CFG_TRANSFER_LIST_TEST, like:
# Embed transfer list support self test when enabled

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@raymo200915
Copy link
Copy Markdown
Contributor Author

All comments are addressed.
All commits are squashed and rebased.
Added tag Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> to commit "core: kernel: fix bug in transfer_list_add()" and Acked-by: Jerome Forissier <jerome.forissier@linaro.org> to commit "core: pta: add self tests for transfer list"

Copy link
Copy Markdown
Contributor

@jenswikl jenswikl left a comment

Choose a reason for hiding this comment

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

Acked-by: Jens Wiklander <jens.wiklander@linaro.org>

Copy link
Copy Markdown
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com> for commit
"core: kernel: fix bug in transfer_list_add()".

Nitpicking comment/question for commit "core: pta: add self tests for transfer list". Otherwise LGTM.

tl_e = transfer_list_add(tl, tag_id, data_size, data);
else
tl_e = transfer_list_add_with_align(tl, tag_id, data_size, data,
align);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpicking: calling only transfer_list_add_with_align(..., align) should be enough.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here is just to test different API entries.

Comment thread core/pta/tests/transfer_list.c Outdated
new_te_next = transfer_list_next(tl, tl_e);

/* skip the inserted void entry if it exists */
if (new_te_next->tag_id == TL_TAG_EMPTY)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion in case there are several empty slot + in case there is no next entry:

-	if (new_te_next->tag_id == TL_TAG_EMPTY)
+	while (new_te_next && new_te_next->tag_id == TL_TAG_EMPTY)

Bythe way, how come new_te_next is not NULL when this function is called by transfer_list_tests() at line 215 to change TEST_TE3_ID data size.

Copy link
Copy Markdown
Contributor Author

@raymo200915 raymo200915 Apr 10, 2025

Choose a reason for hiding this comment

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

Good question. When expanding the data region of an entry, it tries to end up with the address that fits the potential 'next' entry with the data alignment required, even when it is the last entry - That is the case you see in line 215, a void entry was added at the tail.
It is not bad but I think it is fair enough to check if it is the last one and avoid to filling the gap with the void entry.
I will add a small fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Fix the missing cast on the target address when doing memmove.
Get the address of entry data via transfer_list_entry_data()
instead of adding offset.

Fixes: a122250 ("core: add transfer list API")
Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
@raymo200915
Copy link
Copy Markdown
Contributor Author

All comments are addressed.
Tags added.
All commits are squashed and rebased.

Copy link
Copy Markdown
Contributor

@jforissier jforissier left a comment

Choose a reason for hiding this comment

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

For commit "core: kernel: remove the last appended void transfer entry":

Acked-by: Jerome Forissier <jerome.forissier@linaro.org>

transfer_list_set_data_size() appends a void entry for the following
entries to meet the alignment requirement even when it is the last
one, thus add a check before appending.

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Add self tests for transfer list.
Adapt CFG_TRANSFER_LIST with its dependencies and add
CFG_TRANSFER_LIST_TEST.

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
@raymo200915
Copy link
Copy Markdown
Contributor Author

All tags are added.

@jforissier jforissier merged commit 76d920d into OP-TEE:master May 5, 2025
31 of 33 checks passed
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.

4 participants