Skip to contentSkip to conversation

vTPM: Fix Atmel timeout bug.

PATCH In review Emil Condrea 5 participants 10 messages Oct 30, 2014 – Nov 14, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vTPM: Fix Atmel timeout bug.

Some versions of Atmel TPMs provide invalid values for TPM_CAP_PROP_TIS_TIMEOUT query. Because timeouts are invalid, every other command after tpm_get_timeouts will fail. It is a known issue and it was fixed recently in linux kernel tpm_tis.c on 2014-07-29. This patch does not allow timeouts to be less than standard values.
I tested it on a Dell Latitude E5520 and after making the changes I was able to start vtpmmgr-stubdom.

---
 extras/mini-os/tpm_tis.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
extras/mini-os/tpm_tis.c +12 -0
index b067cb7..81d426a 100644
@@ -33,6 +33,11 @@
 #ifndef min
 	#define min( a, b ) ( ((a) < (b)) ? (a) : (b) )
 #endif
+#define ADJUST_TIMEOUTS_TO_STANDARD(initial,standard,timeout_no)			\
+	if((initial) < (standard)){							\
+		(initial) = (standard);							\
+		printk("Timeout %c was adjusted to standard value.\n",timeout_no);	\
+	}
 
 #define TPM_HEADER_SIZE 10
 
@@ -997,15 +1002,22 @@ int tpm_get_timeouts(struct tpm_chip *chip)
    }
    if (timeout)
       chip->timeout_a = MICROSECS(timeout * scale); /*Convert to msec */
+   ADJUST_TIMEOUTS_TO_STANDARD(chip->timeout_a,MILLISECS(TIS_SHORT_TIMEOUT),'a');
+   
    timeout = be32_to_cpu(timeout_cap->b);
    if (timeout)
       chip->timeout_b = MICROSECS(timeout * scale); /*Convert to msec */
+   ADJUST_TIMEOUTS_TO_STANDARD(chip->timeout_b,MILLISECS(TIS_LONG_TIMEOUT),'b');
+
    timeout = be32_to_cpu(timeout_cap->c);
    if (timeout)
       chip->timeout_c = MICROSECS(timeout * scale); /*Convert to msec */
+   ADJUST_TIMEOUTS_TO_STANDARD(chip->timeout_c,MILLISECS(TIS_SHORT_TIMEOUT),'c');
+
    timeout = be32_to_cpu(timeout_cap->d);
    if (timeout)
       chip->timeout_d = MICROSECS(timeout * scale); /*Convert to msec */
+   ADJUST_TIMEOUTS_TO_STANDARD(chip->timeout_d,MILLISECS(TIS_SHORT_TIMEOUT),'d');
 
 duration:
    tpm_cmd.header.in = tpm_getcap_header;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 28 lines · Emil Condrea

Some versions of Atmel TPMs provide invalid values for TPM_CAP_PROP_TIS_TIMEOUT query. Because timeouts are invalid, every other command after tpm_get_timeouts will fail. It is a known issue and it was fixed recently in linux kernel tpm_tis.c on 2014-07-29. This patch does not allow timeouts to be less than standard values.
I tested it on a Dell Latitude E5520 and after making the changes I was able to start vtpmmgr-stubdom.

---
 extras/mini-os/tpm_tis.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
extras/mini-os/tpm_tis.c +5 -0
index b067cb7..81d426a 100644
@@ -33,6 +33,11 @@
 #ifndef min
 	#define min( a, b ) ( ((a) < (b)) ? (a) : (b) )
 #endif
+#define ADJUST_TIMEOUTS_TO_STANDARD(initial,standard,timeout_no)			\
+	if((initial) < (standard)){							\
+		(initial) = (standard);							\
+		printk("Timeout %c was adjusted to standard value.\n",timeout_no);	\
+	}
 
 #define TPM_HEADER_SIZE 10
 

extras/mini-os/tpm_tis.c int tpm_get_timeouts(struct tpm_chip *chip) · line 1005

Quoted 4 lines
extras/mini-os/tpm_tis.c +1 -0
@@ -997,15 +1002,22 @@ int tpm_get_timeouts(struct tpm_chip *chip)
    }
    if (timeout)
       chip->timeout_a = MICROSECS(timeout * scale); /*Convert to msec */
+   ADJUST_TIMEOUTS_TO_STANDARD(chip->timeout_a,MILLISECS(TIS_SHORT_TIMEOUT),'a');

Surely each of these are just

chip->timeout_a = max(MICROSECS(timeout * scale),
MILLISECS(TIS_SHORT_TIMEOUT))

Also, are you certain that the units here are correct? The micro vs milli seconds looks odd.

~Andrew

#2 lore raw

Of course we can use max, but I thought that it might be useful to have a prink to inform the user that the timeout was adjusted.
In init_tpm_tis the default timeouts are set using:
/* Set default timeouts */ tpm->timeout_a = MILLISECS(TIS_SHORT_TIMEOUT);//750*1000000UL tpm->timeout_b = MILLISECS(TIS_LONG_TIMEOUT);//2000*1000000UL tpm->timeout_c = MILLISECS(TIS_SHORT_TIMEOUT); tpm->timeout_d = MILLISECS(TIS_SHORT_TIMEOUT);

But in kernel fix they are set as 750*1000 instead of 750*1000000UL :
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n381
So if we want to integrate kernel changes I think we should use MICROSECS(TIS_SHORT_TIMEOUT) which is 750000
Also in kernel the default timeouts are initialized using msecs_to_jiffies which is different from MILLISECS macro.:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n548
Is there a certain reason for not using msecs_to_jiffies ?

Quoted 45 lines · Andrew Cooper
Quoted 1 line · Emil Condrea

Some versions of Atmel TPMs provide invalid values for

TPM_CAP_PROP_TIS_TIMEOUT query.

Quoted 1 line

Because timeouts are invalid, every other command after tpm_get_timeouts

will fail.

Quoted 1 line

It is a known issue and it was fixed recently in linux kernel tpm_tis.c

on 2014-07-29.

Quoted 2 lines

This patch does not allow timeouts to be less than standard values. I tested it on a Dell Latitude E5520 and after making the changes I was

able to start vtpmmgr-stubdom.

Quoted 11 lines
---
 extras/mini-os/tpm_tis.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
extras/mini-os/tpm_tis.c +0 -0
index b067cb7..81d426a 100644

extras/mini-os/tpm_tis.c line 36

Quoted 4 lines
extras/mini-os/tpm_tis.c +1 -0
@@ -33,6 +33,11 @@
 #ifndef min
      #define min( a, b ) ( ((a) < (b)) ? (a) : (b) )
 #endif
+#define ADJUST_TIMEOUTS_TO_STANDARD(initial,standard,timeout_no)
             \

extras/mini-os/tpm_tis.c line 37

Quoted 1 line
extras/mini-os/tpm_tis.c +1 -0
+     if((initial) < (standard)){
             \

extras/mini-os/tpm_tis.c line 38

Quoted 1 line
extras/mini-os/tpm_tis.c +1 -0
+             (initial) = (standard);
             \

extras/mini-os/tpm_tis.c line 39

Quoted 1 line
extras/mini-os/tpm_tis.c +1 -0
+             printk("Timeout %c was adjusted to standard

value.\n",timeout_no); \

extras/mini-os/tpm_tis.c int tpm_get_timeouts(struct tpm_chip *chip) · line 1005

Quoted 9 lines
extras/mini-os/tpm_tis.c +2 -0
+     }
 
 #define TPM_HEADER_SIZE 10
 
@@ -997,15 +1002,22 @@ int tpm_get_timeouts(struct tpm_chip *chip)
    }
    if (timeout)
       chip->timeout_a = MICROSECS(timeout * scale); /*Convert to msec */
+

ADJUST_TIMEOUTS_TO_STANDARD(chip->timeout_a,MILLISECS(TIS_SHORT_TIMEOUT),'a');

Surely each of these are just

Quoted 9 lines

chip->timeout_a = max(MICROSECS(timeout * scale),
MILLISECS(TIS_SHORT_TIMEOUT))

Also, are you certain that the units here are correct? The micro vs milli seconds looks odd.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 11 lines · Emil Condrea

Of course we can use max, but I thought that it might be useful to have a prink to inform the user that the timeout was adjusted. In init_tpm_tis the default timeouts are set using:
/* Set default timeouts */ tpm->timeout_a = MILLISECS(TIS_SHORT_TIMEOUT);//750*1000000UL tpm->timeout_b = MILLISECS(TIS_LONG_TIMEOUT);//2000*1000000UL tpm->timeout_c = MILLISECS(TIS_SHORT_TIMEOUT); tpm->timeout_d = MILLISECS(TIS_SHORT_TIMEOUT);

Quoted 8 lines

But in kernel fix they are set as 750*1000 instead of 750*1000000UL :
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n381
So if we want to integrate kernel changes I think we should use MICROSECS(TIS_SHORT_TIMEOUT) which is 750000
Also in kernel the default timeouts are initialized using
msecs_to_jiffies which is different from MILLISECS
macro.: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n548
Is there a certain reason for not using msecs_to_jiffies ?

jiffies are a Linux specific concept which mini-os doesn't share.

Daniel, do you have any opinion on this patch?

It seems like the Linux fix is made only for the specifically broken platform. That seems to make sense to me since presumably other systems report short timeouts which they can indeed cope with. It's only Atmel which brokenly reports something it cannot handle.

Ian.

#4 lore raw
Quoted 23 lines · Ian Campbell
Quoted 11 lines · Emil Condrea

Of course we can use max, but I thought that it might be useful to have a prink to inform the user that the timeout was adjusted. In init_tpm_tis the default timeouts are set using:
/* Set default timeouts */ tpm->timeout_a = MILLISECS(TIS_SHORT_TIMEOUT);//750*1000000UL tpm->timeout_b = MILLISECS(TIS_LONG_TIMEOUT);//2000*1000000UL tpm->timeout_c = MILLISECS(TIS_SHORT_TIMEOUT); tpm->timeout_d = MILLISECS(TIS_SHORT_TIMEOUT);

Quoted 8 lines

But in kernel fix they are set as 750*1000 instead of 750*1000000UL :
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n381
So if we want to integrate kernel changes I think we should use MICROSECS(TIS_SHORT_TIMEOUT) which is 750000
Also in kernel the default timeouts are initialized using
msecs_to_jiffies which is different from MILLISECS
macro.: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n548
Is there a certain reason for not using msecs_to_jiffies ?

jiffies are a Linux specific concept which mini-os doesn't share.

Quoted 8 lines

Daniel, do you have any opinion on this patch?

It seems like the Linux fix is made only for the specifically broken platform. That seems to make sense to me since presumably other systems report short timeouts which they can indeed cope with. It's only Atmel which brokenly reports something it cannot handle.

Ian.

I agree that an adjustment is needed when values are too short. Adjusting in all cases is not quite as nice as only fixing the broken TPMs, but it is a lot simpler. It also doesn't seem harmful to have the timeouts be too large in the driver: a properly functioning TPM will not time out its requests in any case, so the user won't notice normally, and the default short timeout is 0.75 seconds - very few people will complain if they have to wait that long to get a timeout instead of what their TPM actually uses.

Signature · 2 lines
Daniel De Graaf
National Security Agency
#5 lore raw

Daniel,
So, is the patch going to be approved(adjusting all short timeouts) or it needs to be modified?

Quoted 47 lines · Daniel De Graaf
Quoted 27 lines · Ian Campbell
Quoted 11 lines · Emil Condrea

Of course we can use max, but I thought that it might be useful to have a prink to inform the user that the timeout was adjusted. In init_tpm_tis the default timeouts are set using:
/* Set default timeouts */ tpm->timeout_a = MILLISECS(TIS_SHORT_TIMEOUT);//750*1000000UL tpm->timeout_b = MILLISECS(TIS_LONG_TIMEOUT);//2000*1000000UL tpm->timeout_c = MILLISECS(TIS_SHORT_TIMEOUT); tpm->timeout_d = MILLISECS(TIS_SHORT_TIMEOUT);

Quoted 11 lines

But in kernel fix they are set as 750*1000 instead of 750*1000000UL :
https://git.kernel.org/cgit/linux/kernel/git/torvalds/
linux.git/tree/drivers/char/tpm/tpm_tis.c#n381
So if we want to integrate kernel changes I think we should use MICROSECS(TIS_SHORT_TIMEOUT) which is 750000
Also in kernel the default timeouts are initialized using msecs_to_jiffies which is different from MILLISECS
macro.: https://git.kernel.org/cgit/linux/kernel/git/torvalds/
linux.git/tree/drivers/char/tpm/tpm_tis.c#n548
Is there a certain reason for not using msecs_to_jiffies ?

jiffies are a Linux specific concept which mini-os doesn't share.

Quoted 9 lines

Daniel, do you have any opinion on this patch?

It seems like the Linux fix is made only for the specifically broken platform. That seems to make sense to me since presumably other systems report short timeouts which they can indeed cope with. It's only Atmel which brokenly reports something it cannot handle.

Ian.

I agree that an adjustment is needed when values are too short. Adjusting in all cases is not quite as nice as only fixing the broken TPMs, but it is a lot simpler. It also doesn't seem harmful to have the timeouts be too large in the driver: a properly functioning TPM will not time out its requests in any case, so the user won't notice normally, and the default short timeout is 0.75 seconds - very few people will complain if they have to wait that long to get a timeout instead of what their TPM actually uses.

Quoted 4 lines

--
Daniel De Graaf
National Security Agency

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#6 lore raw
In reply to Daniel De Graaf
Quoted 33 lines · Daniel De Graaf
Quoted 23 lines · Ian Campbell
Quoted 11 lines · Emil Condrea

Of course we can use max, but I thought that it might be useful to have a prink to inform the user that the timeout was adjusted. In init_tpm_tis the default timeouts are set using:
/* Set default timeouts */ tpm->timeout_a = MILLISECS(TIS_SHORT_TIMEOUT);//750*1000000UL tpm->timeout_b = MILLISECS(TIS_LONG_TIMEOUT);//2000*1000000UL tpm->timeout_c = MILLISECS(TIS_SHORT_TIMEOUT); tpm->timeout_d = MILLISECS(TIS_SHORT_TIMEOUT);

Quoted 8 lines

But in kernel fix they are set as 750*1000 instead of 750*1000000UL :
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n381
So if we want to integrate kernel changes I think we should use MICROSECS(TIS_SHORT_TIMEOUT) which is 750000
Also in kernel the default timeouts are initialized using
msecs_to_jiffies which is different from MILLISECS
macro.: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n548
Is there a certain reason for not using msecs_to_jiffies ?

jiffies are a Linux specific concept which mini-os doesn't share.

Quoted 8 lines

Daniel, do you have any opinion on this patch?

It seems like the Linux fix is made only for the specifically broken platform. That seems to make sense to me since presumably other systems report short timeouts which they can indeed cope with. It's only Atmel which brokenly reports something it cannot handle.

Ian.

Quoted 7 lines

I agree that an adjustment is needed when values are too short. Adjusting in all cases is not quite as nice as only fixing the broken TPMs, but it is a lot simpler. It also doesn't seem harmful to have the timeouts be too large in the driver: a properly functioning TPM will not time out its requests in any case, so the user won't notice normally, and the default short timeout is 0.75 seconds - very few people will complain if they have to wait that long to get a timeout instead of what their TPM actually uses.

Can we take that as an ack?

Also needs the ok from Konrad as release manager. AIUI this is a bugfix for a particular piece of h/w and as Daniel explains above the downside is that sometimes someone might need to wait 0.75s for a timeout instead of something shorter.

#7 lore raw
Quoted 42 lines · Ian Campbell
Quoted 33 lines · Daniel De Graaf
Quoted 23 lines · Ian Campbell
Quoted 11 lines · Emil Condrea

Of course we can use max, but I thought that it might be useful to have a prink to inform the user that the timeout was adjusted. In init_tpm_tis the default timeouts are set using:
/* Set default timeouts */ tpm->timeout_a = MILLISECS(TIS_SHORT_TIMEOUT);//750*1000000UL tpm->timeout_b = MILLISECS(TIS_LONG_TIMEOUT);//2000*1000000UL tpm->timeout_c = MILLISECS(TIS_SHORT_TIMEOUT); tpm->timeout_d = MILLISECS(TIS_SHORT_TIMEOUT);

Quoted 8 lines

But in kernel fix they are set as 750*1000 instead of 750*1000000UL :
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n381
So if we want to integrate kernel changes I think we should use MICROSECS(TIS_SHORT_TIMEOUT) which is 750000
Also in kernel the default timeouts are initialized using
msecs_to_jiffies which is different from MILLISECS
macro.: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n548
Is there a certain reason for not using msecs_to_jiffies ?

jiffies are a Linux specific concept which mini-os doesn't share.

Quoted 8 lines

Daniel, do you have any opinion on this patch?

It seems like the Linux fix is made only for the specifically broken platform. That seems to make sense to me since presumably other systems report short timeouts which they can indeed cope with. It's only Atmel which brokenly reports something it cannot handle.

Ian.

Quoted 7 lines

I agree that an adjustment is needed when values are too short. Adjusting in all cases is not quite as nice as only fixing the broken TPMs, but it is a lot simpler. It also doesn't seem harmful to have the timeouts be too large in the driver: a properly functioning TPM will not time out its requests in any case, so the user won't notice normally, and the default short timeout is 0.75 seconds - very few people will complain if they have to wait that long to get a timeout instead of what their TPM actually uses.

Quoted 6 lines

Can we take that as an ack?

Also needs the ok from Konrad as release manager. AIUI this is a bugfix for a particular piece of h/w and as Daniel explains above the downside is that sometimes someone might need to wait 0.75s for a timeout instead of something shorter.

Quoted 1 line
#9 lore raw
In reply to Ian Campbell
Quoted 42 lines · Ian Campbell
Quoted 33 lines · Daniel De Graaf
Quoted 23 lines · Ian Campbell
Quoted 11 lines · Emil Condrea

Of course we can use max, but I thought that it might be useful to have a prink to inform the user that the timeout was adjusted. In init_tpm_tis the default timeouts are set using:
/* Set default timeouts */ tpm->timeout_a = MILLISECS(TIS_SHORT_TIMEOUT);//750*1000000UL tpm->timeout_b = MILLISECS(TIS_LONG_TIMEOUT);//2000*1000000UL tpm->timeout_c = MILLISECS(TIS_SHORT_TIMEOUT); tpm->timeout_d = MILLISECS(TIS_SHORT_TIMEOUT);

Quoted 8 lines

But in kernel fix they are set as 750*1000 instead of 750*1000000UL :
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n381
So if we want to integrate kernel changes I think we should use MICROSECS(TIS_SHORT_TIMEOUT) which is 750000
Also in kernel the default timeouts are initialized using
msecs_to_jiffies which is different from MILLISECS
macro.: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/char/tpm/tpm_tis.c#n548
Is there a certain reason for not using msecs_to_jiffies ?

jiffies are a Linux specific concept which mini-os doesn't share.

Quoted 8 lines

Daniel, do you have any opinion on this patch?

It seems like the Linux fix is made only for the specifically broken platform. That seems to make sense to me since presumably other systems report short timeouts which they can indeed cope with. It's only Atmel which brokenly reports something it cannot handle.

Ian.

Quoted 7 lines

I agree that an adjustment is needed when values are too short. Adjusting in all cases is not quite as nice as only fixing the broken TPMs, but it is a lot simpler. It also doesn't seem harmful to have the timeouts be too large in the driver: a properly functioning TPM will not time out its requests in any case, so the user won't notice normally, and the default short timeout is 0.75 seconds - very few people will complain if they have to wait that long to get a timeout instead of what their TPM actually uses.

Quoted 1 line

Can we take that as an ack?

Yes. I was going to check to see if the printks would cause people to see problems where the timeouts were already reasonable, but since the mini-os driver is already quite verbose, this should not be a problem. It might be nice to output the old/new value of the timeout, but that's mostly for the curious rather than actually necessary.

Quoted 4 lines

Also needs the ok from Konrad as release manager. AIUI this is a bugfix for a particular piece of h/w and as Daniel explains above the downside is that sometimes someone might need to wait 0.75s for a timeout instead of something shorter.

Signature · 2 lines
Daniel De Graaf
National Security Agency