All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tpm: Start the tpm2 before running a self test.
@ 2023-11-22  6:55 Hermin Anggawijaya
  2023-11-22  7:10 ` Paul Menzel
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Hermin Anggawijaya @ 2023-11-22  6:55 UTC (permalink / raw)
  To: peterhuewe, jarkko, jgg; +Cc: linux-integrity, linux-kernel, Hermin Anggawijaya

Before sending a command to attempt the self test, the TPM
may need to be started, otherwise the self test returns
TPM2_RC_INITIALIZE value causing a log as follows:
"tpm tpm0: A TPM error (256) occurred attempting the self test".

Signed-off-by: Hermin Anggawijaya <hermin.anggawijaya@alliedtelesis.co.nz>
---
 drivers/char/tpm/tpm2-cmd.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 93545be190a5..0530f3b5f86a 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -737,15 +737,15 @@ int tpm2_auto_startup(struct tpm_chip *chip)
 	if (rc)
 		goto out;
 
+	rc = tpm2_startup(chip);
+	if (rc && rc != TPM2_RC_INITIALIZE)
+		goto out;
+
 	rc = tpm2_do_selftest(chip);
 	if (rc && rc != TPM2_RC_INITIALIZE)
 		goto out;
 
 	if (rc == TPM2_RC_INITIALIZE) {
-		rc = tpm2_startup(chip);
-		if (rc)
-			goto out;
-
 		rc = tpm2_do_selftest(chip);
 		if (rc)
 			goto out;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] tpm: Start the tpm2 before running a self test.
  2023-11-22  6:55 [PATCH] tpm: Start the tpm2 before running a self test Hermin Anggawijaya
@ 2023-11-22  7:10 ` Paul Menzel
  2023-11-26 21:16   ` Angga
  2023-11-22 12:34 ` Stefan Berger
  2023-11-24  1:42 ` Jarkko Sakkinen
  2 siblings, 1 reply; 8+ messages in thread
From: Paul Menzel @ 2023-11-22  7:10 UTC (permalink / raw)
  To: Hermin Anggawijaya; +Cc: peterhuewe, jarkko, jgg, linux-integrity, linux-kernel


Dear Hermin,


Thank you for your patch.

It’d be great if you removed the dot/period from the end of the commit 
message summary/title.

Am 22.11.23 um 07:55 schrieb Hermin Anggawijaya:
> Before sending a command to attempt the self test, the TPM
> may need to be started, otherwise the self test returns
> TPM2_RC_INITIALIZE value causing a log as follows:
> "tpm tpm0: A TPM error (256) occurred attempting the self test".

Please document on what platform this happens.

> Signed-off-by: Hermin Anggawijaya <hermin.anggawijaya@alliedtelesis.co.nz>
> ---
>   drivers/char/tpm/tpm2-cmd.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 93545be190a5..0530f3b5f86a 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -737,15 +737,15 @@ int tpm2_auto_startup(struct tpm_chip *chip)
>   	if (rc)
>   		goto out;
>   
> +	rc = tpm2_startup(chip);
> +	if (rc && rc != TPM2_RC_INITIALIZE)
> +		goto out;
> +
>   	rc = tpm2_do_selftest(chip);
>   	if (rc && rc != TPM2_RC_INITIALIZE)
>   		goto out;
>   
>   	if (rc == TPM2_RC_INITIALIZE) {
> -		rc = tpm2_startup(chip);
> -		if (rc)
> -			goto out;
> -
>   		rc = tpm2_do_selftest(chip);
>   		if (rc)
>   			goto out;


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tpm: Start the tpm2 before running a self test.
  2023-11-22  6:55 [PATCH] tpm: Start the tpm2 before running a self test Hermin Anggawijaya
  2023-11-22  7:10 ` Paul Menzel
@ 2023-11-22 12:34 ` Stefan Berger
  2023-11-27  2:02   ` Angga
  2023-11-24  1:42 ` Jarkko Sakkinen
  2 siblings, 1 reply; 8+ messages in thread
From: Stefan Berger @ 2023-11-22 12:34 UTC (permalink / raw)
  To: Hermin Anggawijaya, peterhuewe, jarkko, jgg; +Cc: linux-integrity, linux-kernel



On 11/22/23 01:55, Hermin Anggawijaya wrote:
> Before sending a command to attempt the self test, the TPM
> may need to be started, otherwise the self test returns
> TPM2_RC_INITIALIZE value causing a log as follows:
> "tpm tpm0: A TPM error (256) occurred attempting the self test".
> 
> Signed-off-by: Hermin Anggawijaya <hermin.anggawijaya@alliedtelesis.co.nz>
> ---
>   drivers/char/tpm/tpm2-cmd.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 93545be190a5..0530f3b5f86a 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -737,15 +737,15 @@ int tpm2_auto_startup(struct tpm_chip *chip)
>   	if (rc)
>   		goto out;
>   
> +	rc = tpm2_startup(chip);
> +	if (rc && rc != TPM2_RC_INITIALIZE)
> +		goto out;
> +

Most platforms should have firmware initialize the TPM 2 these days. 
Therefore, a selftest should work and in case it doesn't work you fall 
back to the tpm2_startup below and if you get an error message in the 
log you at least know that you firmware is not up-to-date.

>   	rc = tpm2_do_selftest(chip);
>   	if (rc && rc != TPM2_RC_INITIALIZE)
>   		goto out;
>   
>   	if (rc == TPM2_RC_INITIALIZE) {
> -		rc = tpm2_startup(chip);
> -		if (rc)
> -			goto out;
> -
>   		rc = tpm2_do_selftest(chip);
>   		if (rc)
>   			goto out;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tpm: Start the tpm2 before running a self test.
  2023-11-22  6:55 [PATCH] tpm: Start the tpm2 before running a self test Hermin Anggawijaya
  2023-11-22  7:10 ` Paul Menzel
  2023-11-22 12:34 ` Stefan Berger
@ 2023-11-24  1:42 ` Jarkko Sakkinen
  2023-11-27  2:07   ` Angga
  2 siblings, 1 reply; 8+ messages in thread
From: Jarkko Sakkinen @ 2023-11-24  1:42 UTC (permalink / raw)
  To: Hermin Anggawijaya, peterhuewe, jgg; +Cc: linux-integrity, linux-kernel

On Wed Nov 22, 2023 at 8:55 AM EET, Hermin Anggawijaya wrote:
> Before sending a command to attempt the self test, the TPM
> may need to be started, otherwise the self test returns
> TPM2_RC_INITIALIZE value causing a log as follows:
> "tpm tpm0: A TPM error (256) occurred attempting the self test".
>
> Signed-off-by: Hermin Anggawijaya <hermin.anggawijaya@alliedtelesis.co.nz>

Firmware does TPM power on.

BR, Jarkko

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tpm: Start the tpm2 before running a self test.
  2023-11-22  7:10 ` Paul Menzel
@ 2023-11-26 21:16   ` Angga
  0 siblings, 0 replies; 8+ messages in thread
From: Angga @ 2023-11-26 21:16 UTC (permalink / raw)
  To: Paul Menzel; +Cc: peterhuewe, jarkko, jgg, linux-integrity, linux-kernel

On 22/11/2023 8:10 pm, Paul Menzel wrote:
>
> Dear Hermin,
>
>
> Thank you for your patch.
>
> It’d be great if you removed the dot/period from the end of the commit 
> message summary/title.
>
> Am 22.11.23 um 07:55 schrieb Hermin Anggawijaya:
>> Before sending a command to attempt the self test, the TPM
>> may need to be started, otherwise the self test returns
>> TPM2_RC_INITIALIZE value causing a log as follows:
>> "tpm tpm0: A TPM error (256) occurred attempting the self test".
>
> Please document on what platform this happens.
>
>> Signed-off-by: Hermin Anggawijaya 
>> <hermin.anggawijaya@alliedtelesis.co.nz>
>> ---
>>   drivers/char/tpm/tpm2-cmd.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>> index 93545be190a5..0530f3b5f86a 100644
>> --- a/drivers/char/tpm/tpm2-cmd.c
>> +++ b/drivers/char/tpm/tpm2-cmd.c
>> @@ -737,15 +737,15 @@ int tpm2_auto_startup(struct tpm_chip *chip)
>>       if (rc)
>>           goto out;
>>   +    rc = tpm2_startup(chip);
>> +    if (rc && rc != TPM2_RC_INITIALIZE)
>> +        goto out;
>> +
>>       rc = tpm2_do_selftest(chip);
>>       if (rc && rc != TPM2_RC_INITIALIZE)
>>           goto out;
>>         if (rc == TPM2_RC_INITIALIZE) {
>> -        rc = tpm2_startup(chip);
>> -        if (rc)
>> -            goto out;
>> -
>>           rc = tpm2_do_selftest(chip);
>>           if (rc)
>>               goto out;
>
>
> Kind regards,
>
> Paul

Hello Paul

Thank you for your comments.

 >Please document on what platform this happens.

The error log message is observed on a custom hardware design (a router) 
with an Infineon SLM 9670 TPM2.0.
The patch is useful for us, as the firmware (boot loader) of the router 
does not support TPM yet, thus the kernel
needs to start the TPM before starting the self test.

I will reply to Jarkko's and Stefan's comments separately, and if in 
principle, the patch is accepted, I will send the
second version of the patch with your comments addressed.

Kind regards

Hermin



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tpm: Start the tpm2 before running a self test.
  2023-11-22 12:34 ` Stefan Berger
@ 2023-11-27  2:02   ` Angga
  2023-12-04  2:36     ` Jarkko Sakkinen
  0 siblings, 1 reply; 8+ messages in thread
From: Angga @ 2023-11-27  2:02 UTC (permalink / raw)
  To: Stefan Berger, peterhuewe, jarkko, jgg; +Cc: linux-integrity, linux-kernel

On 23/11/2023 1:34 am, Stefan Berger wrote:
>
>
> On 11/22/23 01:55, Hermin Anggawijaya wrote:
>> Before sending a command to attempt the self test, the TPM
>> may need to be started, otherwise the self test returns
>> TPM2_RC_INITIALIZE value causing a log as follows:
>> "tpm tpm0: A TPM error (256) occurred attempting the self test".
>>
>> Signed-off-by: Hermin Anggawijaya 
>> <hermin.anggawijaya@alliedtelesis.co.nz>
>> ---
>>   drivers/char/tpm/tpm2-cmd.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>> index 93545be190a5..0530f3b5f86a 100644
>> --- a/drivers/char/tpm/tpm2-cmd.c
>> +++ b/drivers/char/tpm/tpm2-cmd.c
>> @@ -737,15 +737,15 @@ int tpm2_auto_startup(struct tpm_chip *chip)
>>       if (rc)
>>           goto out;
>>   +    rc = tpm2_startup(chip);
>> +    if (rc && rc != TPM2_RC_INITIALIZE)
>> +        goto out;
>> +
>
> Most platforms should have firmware initialize the TPM 2 these days. 
> Therefore, a selftest should work and in case it doesn't work you fall 
> back to the tpm2_startup below and if you get an error message in the 
> log you at least know that you firmware is not up-to-date.
>
>>       rc = tpm2_do_selftest(chip);
>>       if (rc && rc != TPM2_RC_INITIALIZE)
>>           goto out;
>>         if (rc == TPM2_RC_INITIALIZE) {
>> -        rc = tpm2_startup(chip);
>> -        if (rc)
>> -            goto out;
>> -
>>           rc = tpm2_do_selftest(chip);
>>           if (rc)
>>               goto out;

Hello Stefan

Thank you for your comments.

Unfortunately our platforms (custom hardware design) are the ones which 
do not initialize/start the TPM2 from boot loader yet, and because of 
that the
self test in tpm2_auto_startup always produce a log error message on the 
platform start up.

While I understand your point about the log being useful for "pointing 
out not up-to-date firmware", but it might also generate unnecessary support
queries from some users on such platforms ? And maybe the kernel being 
able to deal with TPM being started more than once is better ?

If wanted, I have the second version of the patch which consist of code 
changes as in v1, plus ability for tpm2_transmit_cmd to handle multiple
attempts to start up the TPM silently, for example, once by the firmware 
and another by the kernel during tpm2 auto-startup.

Kind regards

Hermin Anggawijaya


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tpm: Start the tpm2 before running a self test.
  2023-11-24  1:42 ` Jarkko Sakkinen
@ 2023-11-27  2:07   ` Angga
  0 siblings, 0 replies; 8+ messages in thread
From: Angga @ 2023-11-27  2:07 UTC (permalink / raw)
  To: Jarkko Sakkinen, peterhuewe, jgg; +Cc: linux-integrity, linux-kernel

On 24/11/2023 2:42 pm, Jarkko Sakkinen wrote:
> On Wed Nov 22, 2023 at 8:55 AM EET, Hermin Anggawijaya wrote:
>> Before sending a command to attempt the self test, the TPM
>> may need to be started, otherwise the self test returns
>> TPM2_RC_INITIALIZE value causing a log as follows:
>> "tpm tpm0: A TPM error (256) occurred attempting the self test".
>>
>> Signed-off-by: Hermin Anggawijaya <hermin.anggawijaya@alliedtelesis.co.nz>
> Firmware does TPM power on.
>
> BR, Jarkko

Hello Jarkko

Thank you for your comment on the patch. As indicated in my previous 
reply to Stefan's comment,
I have v2 version of the patch which also deals with multiple attempts 
to start up the TPM gracefully,
for example, once by the firmware and another by the kernel during tpm2 
auto-startup.

If you think the idea is OK, I can send the v2 of the patch.


Kind regards

Hermin



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tpm: Start the tpm2 before running a self test.
  2023-11-27  2:02   ` Angga
@ 2023-12-04  2:36     ` Jarkko Sakkinen
  0 siblings, 0 replies; 8+ messages in thread
From: Jarkko Sakkinen @ 2023-12-04  2:36 UTC (permalink / raw)
  To: Angga, Stefan Berger, peterhuewe, jgg; +Cc: linux-integrity, linux-kernel

On Mon Nov 27, 2023 at 4:02 AM EET, Angga wrote:
> On 23/11/2023 1:34 am, Stefan Berger wrote:
> >
> >
> > On 11/22/23 01:55, Hermin Anggawijaya wrote:
> >> Before sending a command to attempt the self test, the TPM
> >> may need to be started, otherwise the self test returns
> >> TPM2_RC_INITIALIZE value causing a log as follows:
> >> "tpm tpm0: A TPM error (256) occurred attempting the self test".
> >>
> >> Signed-off-by: Hermin Anggawijaya 
> >> <hermin.anggawijaya@alliedtelesis.co.nz>
> >> ---
> >>   drivers/char/tpm/tpm2-cmd.c | 8 ++++----
> >>   1 file changed, 4 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> >> index 93545be190a5..0530f3b5f86a 100644
> >> --- a/drivers/char/tpm/tpm2-cmd.c
> >> +++ b/drivers/char/tpm/tpm2-cmd.c
> >> @@ -737,15 +737,15 @@ int tpm2_auto_startup(struct tpm_chip *chip)
> >>       if (rc)
> >>           goto out;
> >>   +    rc = tpm2_startup(chip);
> >> +    if (rc && rc != TPM2_RC_INITIALIZE)
> >> +        goto out;
> >> +
> >
> > Most platforms should have firmware initialize the TPM 2 these days. 
> > Therefore, a selftest should work and in case it doesn't work you fall 
> > back to the tpm2_startup below and if you get an error message in the 
> > log you at least know that you firmware is not up-to-date.
> >
> >>       rc = tpm2_do_selftest(chip);
> >>       if (rc && rc != TPM2_RC_INITIALIZE)
> >>           goto out;
> >>         if (rc == TPM2_RC_INITIALIZE) {
> >> -        rc = tpm2_startup(chip);
> >> -        if (rc)
> >> -            goto out;
> >> -
> >>           rc = tpm2_do_selftest(chip);
> >>           if (rc)
> >>               goto out;
>
> Hello Stefan
>
> Thank you for your comments.
>
> Unfortunately our platforms (custom hardware design) are the ones which 
> do not initialize/start the TPM2 from boot loader yet, and because of 
> that the
> self test in tpm2_auto_startup always produce a log error message on the 
> platform start up.
>
> While I understand your point about the log being useful for "pointing 
> out not up-to-date firmware", but it might also generate unnecessary support
> queries from some users on such platforms ? And maybe the kernel being 
> able to deal with TPM being started more than once is better ?
>
> If wanted, I have the second version of the patch which consist of code 
> changes as in v1, plus ability for tpm2_transmit_cmd to handle multiple
> attempts to start up the TPM silently, for example, once by the firmware 
> and another by the kernel during tpm2 auto-startup.

To save your time: no.

Mainline kernel is not modified based hardware prototypes.

You have freedom to maintain your own kernel tree for whatever changes
you need but this is totally wrong place for these type of patches.

>
> Kind regards
>
> Hermin Anggawijaya

BR, Jarkko

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-12-04  2:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-22  6:55 [PATCH] tpm: Start the tpm2 before running a self test Hermin Anggawijaya
2023-11-22  7:10 ` Paul Menzel
2023-11-26 21:16   ` Angga
2023-11-22 12:34 ` Stefan Berger
2023-11-27  2:02   ` Angga
2023-12-04  2:36     ` Jarkko Sakkinen
2023-11-24  1:42 ` Jarkko Sakkinen
2023-11-27  2:07   ` Angga

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.