Skip to content

Conversation

jarvisDang
Copy link

…ss reboots #4577

fix open issue 4577, Link: #4577

Copy link
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.

This looks a nice step into TA persistent storage support.

The commit message should be refined, e.g.:

core: tee: persistent storage of TA time offset

Implement persistent storage of TA time offset in OP-TEE
private secure storage. TA time offset value is stored in TA
stroage space under file name "ta_time_offs".

Fixes: #4577
Signed-off-by: ...

For TEE_SetTAPersistentTime() to be atomic, I think the mutex should cover both update in RAM and in persistent storage.

#include <utee_defines.h>
#include <tee/tee_fs.h>
#include <tee/tee_pobj.h>

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking: sort in alphabetical order (and by the way swap string.h/stdlib.h ordering) and remove the last empty line.

#include <kernel/mutex.h>
#include <kernel/panic.h>
#include <kernel/tee_time.h>
#include <stdlib.h>
#include <string.h>
#include <tee/tee_fs.h>
#include <tee/tee_pobj.h>
#include <utee_defines.h>

Comment on lines 31 to 32
size_t n;
struct tee_ta_time_offs *o;
Copy link
Contributor

Choose a reason for hiding this comment

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

As per OP-TEE coding style, these require a initialization value:

Suggested change
size_t n;
struct tee_ta_time_offs *o;
size_t n = 0;
struct tee_ta_time_offs *o = NULL;

size_t n;
struct tee_ta_time_offs *o;

mutex_lock(&tee_time_mtx);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use tabulations instead of space chars for indenation?


TEE_Time o;
bool pos = false;
TEE_Result res = tee_time_ta_storage_read(uuid, &o, &pos);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please define all local variables at instruction block entry (and provide them with an initialization value).

static size_t tee_time_num_offs;
static struct mutex tee_time_mtx = MUTEX_INITIALIZER;

#define TA_TIME_OFFS_ID "ta_time_offs"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking: could you define this macro at source file entry, before struct tee_ta_time_offs definition?

size_t n;
struct tee_ta_time_offs *o;
size_t idx = 0;
TEE_Result res = tee_time_ta_set_offs_mem(uuid, offs, positive, &idx);
Copy link
Contributor

Choose a reason for hiding this comment

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

Need an empty line between local variable definitions and instructions. Suggestion:

	TEE_Result res = TEE_ERROR_GENERIC;
	size_t idx = 0;

	res = tee_time_ta_set_offs_mem(uuid, offs, positive, &idx);

NULL, 0,
NULL, 0,
&o, NULL, sizeof(o),
&fh);
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer:

	res = fops->create(po, true, NULL, 0, NULL, 0, &o, NULL, sizeof(o),
			   &fh);

if (!fops)
return TEE_ERROR_TIME_NOT_SET; /* storage unavailable: treat as not set */

res = tee_pobj_get((TEE_UUID *)uuid, TA_TIME_OFFS_ID,
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a (void *) cast to discard const qualifier, as reported by CI make tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or perhaps even better, fix tee_pobj_get() in a separate patch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, adding const to the few first arguments of tee_pobj_get() would help.

@jarvisDang
Copy link
Author

thanks for @etienne-lms @jenswi-linaro 's detailed comments, I'm working on it.

@jenswi-linaro
Copy link
Contributor

Please fix the checkpatch issues.

@jarvisDang
Copy link
Author

Please fix the checkpatch issues.

working on it

@jarvisDang
Copy link
Author

the checkpatch passed from my forked repo https://github.com/jarvisDang/optee_os/actions/runs/17115078518

@jarvisDang
Copy link
Author

why the code style check issues showed in the log not match my latest source code?

@jforissier
Copy link
Contributor

the checkpatch passed from my forked repo https://github.com/jarvisDang/optee_os/actions/runs/17115078518

In the forked repo, only one commit is checked (the topmost in the branch). Here we can see that the global diff is OK (see the "checkdiff" line), but some commits are not (see the the "checkpatch" lines). Please squash all the commits into one.

@jarvisDang
Copy link
Author

@jforissier thanks for explanation, I will squash all the fixup commits and try again

@jenswi-linaro
Copy link
Contributor

You can run checkpatch locally with, for instance, ./scripts/checkpatch.sh github/master.., depending on the base of your branch.

@jarvisDang
Copy link
Author

You can run checkpatch locally with, for instance, ./scripts/checkpatch.sh github/master.., depending on the base of your branch.

glad to know that, thanks.

Implement persistent storage of TA time offset in OP-TEE
private secure storage. TA time offset value is stored in TA
storage space under file name "ta_time_offs".

Fixes: OP-TEE#4577

Signed-off-by: Jarvis Dang <[email protected]>
if (!fops)
return TEE_ERROR_NOT_SUPPORTED;

res = tee_pobj_get((TEE_UUID *)uuid, (void *)TA_TIME_OFFS_ID,
Copy link
Contributor

Choose a reason for hiding this comment

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

The object will be created in the object namespace for the TA/UUID in question. What if a TA has an object with this name?

I think we can manage with a dummy pobj like in check_update_version() instead. This will allow us to create an object outside the normal namespace. However, we must still be careful to avoid conflicts.

o.positive = positive;

res = fops->create(po, true, NULL, 0, NULL, 0, &o, NULL, sizeof(o),
&fh);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please align with the opening (.

res = tee_time_ta_set_offs_mem(uuid, offs, positive, &idx);
if (res)
return res;
return tee_time_ta_storage_write(uuid, offs, positive);
Copy link
Contributor

Choose a reason for hiding this comment

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

What if tee_time_ta_storage_write() fails? Then we have an inconsistent state.


mutex_lock(&tee_time_mtx);
for (n = 0; n < tee_time_num_offs; n++) {
if (memcmp(uuid, &tee_time_offs[n].uuid, sizeof(TEE_UUID))
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer if (!memcmp...).

static TEE_Result tee_time_ta_storage_read(const TEE_UUID *uuid,
TEE_Time *offs, bool *positive)
{
const struct tee_file_operations *fops =
Copy link
Contributor

Choose a reason for hiding this comment

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

Please initialize with NULL here and assign it below for cleaner code flow.

@jarvisDang
Copy link
Author

jarvisDang commented Aug 25, 2025

@jenswi-linaro sounds good suggestion, I will push more fixup commits soon.

Copy link

This pull request has been marked as a stale pull request because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment, otherwise this pull request will automatically be closed in 5 days. Note, that you can always re-open a closed issue at any time.

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