diff mbox series

[v4,7/8] tpm: Guard irq related ops in case interrupts are disabled

Message ID 20200617142305.1198672-8-stefanb@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show
Series tpm: Enable usage of TPM TIS with interrupts | expand

Commit Message

Stefan Berger June 17, 2020, 2:23 p.m. UTC
Check for irq_num having the value of TPM_IRQ_DISABLED before calling any
IRQ related functions or allowing the user to try to enable interrupts.
Explicitly allow the value of TPM_IRQ_DISABLED in irq_num.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Message-id: 20200616205721.1191408-8-stefanb@linux.vnet.ibm.com
---
 hw/tpm/tpm_tis_common.c | 12 +++++++++++-
 hw/tpm/tpm_tis_isa.c    |  6 ++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

Comments

Eric Auger June 18, 2020, 7:22 a.m. UTC | #1
Hi,

On 6/17/20 4:23 PM, Stefan Berger wrote:
> Check for irq_num having the value of TPM_IRQ_DISABLED before calling any
> IRQ related functions or allowing the user to try to enable interrupts.
> Explicitly allow the value of TPM_IRQ_DISABLED in irq_num.
> 
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> Message-id: 20200616205721.1191408-8-stefanb@linux.vnet.ibm.com
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric
> ---
>  hw/tpm/tpm_tis_common.c | 12 +++++++++++-
>  hw/tpm/tpm_tis_isa.c    |  6 ++++--
>  2 files changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/tpm/tpm_tis_common.c b/hw/tpm/tpm_tis_common.c
> index 0f42696f1f..13b233309e 100644
> --- a/hw/tpm/tpm_tis_common.c
> +++ b/hw/tpm/tpm_tis_common.c
> @@ -359,7 +359,11 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
>          val = s->loc[locty].inte;
>          break;
>      case TPM_TIS_REG_INT_VECTOR:
> -        val = s->irq_num;
> +        if (s->irq_num != TPM_IRQ_DISABLED) {
> +            val = s->irq_num;
> +        } else {
> +            val = 0;
> +        }
>          break;
>      case TPM_TIS_REG_INT_STATUS:
>          val = s->loc[locty].ints;
> @@ -591,6 +595,9 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
>          if (s->active_locty != locty) {
>              break;
>          }
> +        if (s->irq_num == TPM_IRQ_DISABLED) {
> +            val &= ~TPM_TIS_INT_ENABLED;
> +        }
>  
>          s->loc[locty].inte &= mask;
>          s->loc[locty].inte |= (val & (TPM_TIS_INT_ENABLED |
> @@ -601,6 +608,9 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
>          /* hard wired -- ignore */
>          break;
>      case TPM_TIS_REG_INT_STATUS:
> +        if (s->irq_num == TPM_IRQ_DISABLED) {
> +            break;
> +        }
>          /* clearing of interrupt flags */
>          if (((val & TPM_TIS_INTERRUPTS_SUPPORTED)) &&
>              (s->loc[locty].ints & TPM_TIS_INTERRUPTS_SUPPORTED)) {
> diff --git a/hw/tpm/tpm_tis_isa.c b/hw/tpm/tpm_tis_isa.c
> index 27222a9a49..d72f733ead 100644
> --- a/hw/tpm/tpm_tis_isa.c
> +++ b/hw/tpm/tpm_tis_isa.c
> @@ -127,13 +127,15 @@ static void tpm_tis_isa_realizefn(DeviceState *dev, Error **errp)
>          error_setg(errp, "'tpmdev' property is required");
>          return;
>      }
> -    if (s->irq_num > 15) {
> +    if (s->irq_num > 15 && s->irq_num != TPM_IRQ_DISABLED) {
>          error_setg(errp, "IRQ %d is outside valid range of 0 to 15",
>                     s->irq_num);
>          return;
>      }
>  
> -    isa_init_irq(ISA_DEVICE(dev), &s->irq, s->irq_num);
> +    if (s->irq_num != TPM_IRQ_DISABLED) {
> +        isa_init_irq(ISA_DEVICE(dev), &s->irq, s->irq_num);
> +    }
>  
>      memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)),
>                                  TPM_TIS_ADDR_BASE, &s->mmio);
>
diff mbox series

Patch

diff --git a/hw/tpm/tpm_tis_common.c b/hw/tpm/tpm_tis_common.c
index 0f42696f1f..13b233309e 100644
--- a/hw/tpm/tpm_tis_common.c
+++ b/hw/tpm/tpm_tis_common.c
@@ -359,7 +359,11 @@  static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
         val = s->loc[locty].inte;
         break;
     case TPM_TIS_REG_INT_VECTOR:
-        val = s->irq_num;
+        if (s->irq_num != TPM_IRQ_DISABLED) {
+            val = s->irq_num;
+        } else {
+            val = 0;
+        }
         break;
     case TPM_TIS_REG_INT_STATUS:
         val = s->loc[locty].ints;
@@ -591,6 +595,9 @@  static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
         if (s->active_locty != locty) {
             break;
         }
+        if (s->irq_num == TPM_IRQ_DISABLED) {
+            val &= ~TPM_TIS_INT_ENABLED;
+        }
 
         s->loc[locty].inte &= mask;
         s->loc[locty].inte |= (val & (TPM_TIS_INT_ENABLED |
@@ -601,6 +608,9 @@  static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
         /* hard wired -- ignore */
         break;
     case TPM_TIS_REG_INT_STATUS:
+        if (s->irq_num == TPM_IRQ_DISABLED) {
+            break;
+        }
         /* clearing of interrupt flags */
         if (((val & TPM_TIS_INTERRUPTS_SUPPORTED)) &&
             (s->loc[locty].ints & TPM_TIS_INTERRUPTS_SUPPORTED)) {
diff --git a/hw/tpm/tpm_tis_isa.c b/hw/tpm/tpm_tis_isa.c
index 27222a9a49..d72f733ead 100644
--- a/hw/tpm/tpm_tis_isa.c
+++ b/hw/tpm/tpm_tis_isa.c
@@ -127,13 +127,15 @@  static void tpm_tis_isa_realizefn(DeviceState *dev, Error **errp)
         error_setg(errp, "'tpmdev' property is required");
         return;
     }
-    if (s->irq_num > 15) {
+    if (s->irq_num > 15 && s->irq_num != TPM_IRQ_DISABLED) {
         error_setg(errp, "IRQ %d is outside valid range of 0 to 15",
                    s->irq_num);
         return;
     }
 
-    isa_init_irq(ISA_DEVICE(dev), &s->irq, s->irq_num);
+    if (s->irq_num != TPM_IRQ_DISABLED) {
+        isa_init_irq(ISA_DEVICE(dev), &s->irq, s->irq_num);
+    }
 
     memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)),
                                 TPM_TIS_ADDR_BASE, &s->mmio);