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

Should OP-TEE revision be printed as "string" in linux OP-TEE driver ? #7141

Closed
sahilnxp opened this issue Nov 20, 2024 · 18 comments
Closed
Labels

Comments

@sahilnxp
Copy link
Contributor

Since we have moved to 16bit sha1 len for OP-TEE revision in case of 64 bit architecture.

Should we print the revision as string in place of long int here

Observed one issue on 64 bit architectures, if the commit id is starting with 0 like 04d1c612ec7beaede073b8cad0f33a1f5ab9e2bc

It is printing revision as below removing leading 0.
2024-11-15T02:29:51.469317 [ 2.019585] optee: revision 4.4 (4d1c612ec7beaed)

@jforissier
Copy link
Contributor

Hi @sahilnxp,

Should we print the revision as string in place of long int here

I think the format simply needs adjusting to cater to the size of the unsigned long:

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
	res.result.minor, sizeof(res.result.build_id) * 2,
	res.result.build_id);

@sahilnxp
Copy link
Contributor Author

Hi @sahilnxp,

Should we print the revision as string in place of long int here

I think the format simply needs adjusting to cater to the size of the unsigned long:

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
	res.result.minor, sizeof(res.result.build_id) * 2,
	res.result.build_id);

Yes, that will work, but we need to pass the size like (16) too in this case like below:

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
	res.result.minor, sizeof(res.result.build_id) * 2,
	16, res.result.build_id);

and how to decide on this size ? Otherwise, it is giving the following warning.

                 from drivers/tee/optee/smc_abi.c:12:
drivers/tee/optee/smc_abi.c: In function ‘optee_msg_get_os_revision’:
./include/linux/kern_levels.h:5:25: warning: field width specifier ‘*’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
    5 | #define KERN_SOH        "\001"          /* ASCII Start Of Header */
      |                         ^~~~~~

@jenswi-linaro
Copy link
Contributor

Casting the size argument to int should work.

@sahilnxp
Copy link
Contributor Author

sahilnxp commented Nov 21, 2024

Sorry for confusion here.

There is no compilation warning in case of following code:

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
	res.result.minor, sizeof(res.result.build_id) * 2,
	16, res.result.build_id);

But how we can decide if we should give the size as 8 (for 32bit arch) and 16 (for 64 bit arch) ?

@jforissier
Copy link
Contributor

Sorry for confusion here.

There is no compilation warning in case of following code:

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
	res.result.minor, sizeof(res.result.build_id) * 2,
	16, res.result.build_id);

But how we can decide if we should give the size as 8 (for 32bit arch) and 16 (for 64 bit arch) ?

res.result.build_id is unsigned long. 32-bit arch have sizeof(unsigned long) == 4 while 64-bit arch have sizeof(unsigned long) == 8.

@sahilnxp
Copy link
Contributor Author

So it should be like this, right ?

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
             res.result.minor, (int)sizeof(unsigned long),
             res.result.build_id);

@jforissier
Copy link
Contributor

No, because in the Linux (and OP-TEE) coding style, the argument of sizeof() should be the variable rather than the type. This makes sense to make maintenance easier in case the type is changed for instance.

@sahilnxp
Copy link
Contributor Author

In that case, it should be like below ?

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
             res.result.minor, (int)sizeof(res.result.build_id),
             res.result.build_id);

@jforissier
Copy link
Contributor

In that case, it should be like below ?

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
             res.result.minor, (int)sizeof(res.result.build_id),
             res.result.build_id);

No. The * 2 is missing. Here is exactly how the code should be:

	if (res.result.build_id)
		pr_info("revision %lu.%lu (%08lx)", res.result.major,
			res.result.minor, (int)sizeof(res.result.build_id) * 2,
			res.result.build_id);
	else
		pr_info("revision %lu.%lu", res.result.major, res.result.minor);

@sahilnxp
Copy link
Contributor Author

@jforissier Sorry, I am confused, why we want to double the size?

@jforissier
Copy link
Contributor

Because for each byte of data, two characters are printed in hex

@sahilnxp
Copy link
Contributor Author

Because for each byte of data, two characters are printed in hex

ohh, yeah. Thats right. I missed that part. Thanks.
I will send a patch for this on Linux kernel and update link here.

@sahilnxp
Copy link
Contributor Author

Patch has been sent upstream: https://lore.kernel.org/linux-kernel/[email protected]/

@sahilnxp
Copy link
Contributor Author

sahilnxp commented Dec 2, 2024

https://lore.kernel.org/linux-kernel/[email protected]/

@jforissier Do I need to update the tags in this one too ?

@jforissier
Copy link
Contributor

https://lore.kernel.org/linux-kernel/[email protected]/

@jforissier Do I need to update the tags in this one too ?

I don't think one needs to re-send patches to the LKML just for the tags because the maintainers have different means to collect them. @jenswi-linaro is this correct?

@jenswi-linaro
Copy link
Contributor

That's right, I'll apply all tags (and add my Signed-off-by) when I pick it up. It's a few weeks until the next merge window opens so there's no rush.

@sahilnxp
Copy link
Contributor Author

sahilnxp commented Dec 2, 2024

Thanks @jenswi-linaro @jforissier for your inputs.

Copy link

github-actions bot commented Jan 2, 2025

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

@github-actions github-actions bot added the Stale label Jan 2, 2025
@github-actions github-actions bot closed this as completed Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants