Skip to contentSkip to conversation

tpm: Handle failure mode of backend device better

PATCH In review Stefan Berger 2 participants 7 messages Nov 11, 2017 – Dec 13, 2017

lore
Share & tools
lore
#0 lore raw

cover tpm: Handle failure mode of backend device better

The following two patches fix the case that the backend device, e.g., tpm_emulator, could not be initialized and the TIS frontend needs to go into failure mode.

Stefan

Stefan Berger (2):
tpm_tis: Return TPM_VERSION_UNSPEC in case of BE failure
tpm_tis: Return 0 for every register in case of failure mode

 hw/tpm/tpm_tis.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.5.5
#4 lore raw

PATCH 2/2 tpm_tis: Return 0 for every register in case of failure mode

Rather than returning ~0, return 0 for every register in case of failure mode. The '0' is better to indicate that there's no device there.

---
 hw/tpm/tpm_tis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/tpm/tpm_tis.c +1 -1
index eca3374..d0bdd96 100644
@@ -519,7 +519,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
     uint8_t v;
 
     if (tpm_backend_had_startup_error(s->be_driver)) {
-        return val;
+        return 0;
     }
 
     switch (offset) {
Signature · 1 line
2.5.5
#1 lore raw

PATCH 1/2 tpm_tis: Return TPM_VERSION_UNSPEC in case of BE failure

In reply to Stefan Berger

In case the backend has a failure, such as the tpm_emulator's CMD_INIT failing, the TIS goes into failure mode and does not respond to reads or writes to MMIO registers. In this case we need to prevent the ACPI table from being added and the straight-forward way is to indicate that there's no known TPM version being used.

---
 hw/tpm/tpm_tis.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/tpm/tpm_tis.c +4 -0
index c0a0204..eca3374 100644
@@ -970,6 +970,10 @@ static enum TPMVersion tpm_tis_get_tpm_version(TPMIf *ti)
 {
     TPMState *s = TPM(ti);
 
+    if (tpm_backend_had_startup_error(s->be_driver)) {
+        return TPM_VERSION_UNSPEC;
+    }
+
     return tpm_backend_get_tpm_version(s->be_driver);
 }
 
Signature · 1 line
2.5.5
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] tpm_tis: Return TPM_VERSION_UNSPEC in case of BE failure

Quoted 7 lines · Stefan Berger

In case the backend has a failure, such as the tpm_emulator's CMD_INIT failing, the TIS goes into failure mode and does not respond to reads or writes to MMIO registers. In this case we need to prevent the ACPI table from being added and the straight-forward way is to indicate that there's no known TPM version being used.

Quoted 23 lines
---
 hw/tpm/tpm_tis.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/tpm/tpm_tis.c +4 -1
index c0a0204..eca3374 100644
@@ -970,6 +970,10 @@ static enum TPMVersion tpm_tis_get_tpm_version(TPMIf *ti)
 {
     TPMState *s = TPM(ti);
 
+    if (tpm_backend_had_startup_error(s->be_driver)) {
+        return TPM_VERSION_UNSPEC;
+    }
+
     return tpm_backend_get_tpm_version(s->be_driver);
 }
 
--

2.5.5

Signature · 1 line
Marc-André Lureau
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] tpm_tis: Return 0 for every register in case of failure mode

In reply to Stefan Berger

Hi Stefan

Quoted 14 lines · Stefan Berger

Rather than returning ~0, return 0 for every register in case of failure mode. The '0' is better to indicate that there's no device there.

---
 hw/tpm/tpm_tis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/tpm/tpm_tis.c +0 -0
index eca3374..d0bdd96 100644

hw/tpm/tpm_tis.c static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr, · line 523

Quoted 6 lines
hw/tpm/tpm_tis.c +1 -1
@@ -519,7 +519,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
     uint8_t v;
 
     if (tpm_backend_had_startup_error(s->be_driver)) {
-        return val;
+        return 0;
     }

it's not obvious to me why it's better. Could you detail a bit more the reason?

why not change the initialization of val instead?

Quoted 6 lines
hw/tpm/tpm_tis.c +0 -1
     switch (offset) {
--

2.5.5

Signature · 1 line
Marc-André Lureau
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] tpm_tis: Return TPM_VERSION_UNSPEC in case of BE failure

In reply to Marc-André Lureau
Quoted 10 lines · Marc-André Lureau
Quoted 7 lines · Stefan Berger

In case the backend has a failure, such as the tpm_emulator's CMD_INIT failing, the TIS goes into failure mode and does not respond to reads or writes to MMIO registers. In this case we need to prevent the ACPI table from being added and the straight-forward way is to indicate that there's no known TPM version being used.

Resending an old response?

https://patchwork.kernel.org/patch/10058405/

Quoted 27 lines
Quoted 25 lines

---
  hw/tpm/tpm_tis.c | 4 ++++
  1 file changed, 4 insertions(+)
hw/tpm/tpm_tis.c +4 -1
index c0a0204..eca3374 100644
@@ -970,6 +970,10 @@ static enum TPMVersion tpm_tis_get_tpm_version(TPMIf *ti)
  {
      TPMState *s = TPM(ti);
 
+    if (tpm_backend_had_startup_error(s->be_driver)) {
+        return TPM_VERSION_UNSPEC;
+    }
+
      return tpm_backend_get_tpm_version(s->be_driver);
  }
 
--

2.5.5

#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] tpm_tis: Return 0 for every register in case of failure mode

In reply to Marc-André Lureau
Quoted 20 lines · Marc-André Lureau

Hi Stefan

Quoted 16 lines · Stefan Berger

Rather than returning ~0, return 0 for every register in case of failure mode. The '0' is better to indicate that there's no device there.

---
  hw/tpm/tpm_tis.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/tpm/tpm_tis.c +0 -0
index eca3374..d0bdd96 100644
@@ -519,7 +519,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
      uint8_t v;
 
Quoted 7 lines

hw/tpm/tpm_tis.c static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr, · line 523

Quoted 4 lines
hw/tpm/tpm_tis.c +1 -1
      if (tpm_backend_had_startup_error(s->be_driver)) {
-        return val;
+        return 0;
      }

it's not obvious to me why it's better. Could you detail a bit more the reason?

why not change the initialization of val instead?

http://patchwork.ozlabs.org/patch/838042/