Skip to contentSkip to conversation

hw/intc/arm_gicv5: Make IRS_IDR0 reads return actual value, not 0

PATCH In review Peter Maydell 3 participants 5 messages Oct 8 – Oct 9

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/intc/arm_gicv5: Make IRS_IDR0 reads return actual value, not 0

IN the code for handling reads of IRS_IDR0, we carefully construct the correct value starting with cs->irs_idr0 and adjusting it. However, we never actually write the final value into *data, so the guest will always see zero.

We didn't notice this before, because Linux happens to not care about this register value except to check for the presence of virtualization.

Fixes 405ad2e76f13254 ("hw/intc/arm_gicv5: Implement IRS ID regs")
---
 hw/intc/arm_gicv5.c | 1 +
 1 file changed, 1 insertion(+)
hw/intc/arm_gicv5.c +1 -0
index 08878193dfc..ebfb0878af3 100644
@@ -1433,6 +1433,7 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
             /* ...which means VIRT_ONE_N is also RES0 */
             v &= ~R_IRS_IDR0_VIRT_ONE_N_MASK;
         }
+        *data = v;
         return true;
 
     case A_IRS_IDR1:
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Peter Maydell

IN the code for handling reads of IRS_IDR0, we carefully construct the correct value starting with cs->irs_idr0 and adjusting it. However, we never actually write the final value into *data, so the guest will always see zero.

We didn't notice this before, because Linux happens to not care about this register value except to check for the presence of virtualization.

Fixes 405ad2e76f13254 ("hw/intc/arm_gicv5: Implement IRS ID regs")
---
  hw/intc/arm_gicv5.c | 1 +
  1 file changed, 1 insertion(+)
hw/intc/arm_gicv5.c +0 -0
index 08878193dfc..ebfb0878af3 100644

hw/intc/arm_gicv5.c static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 1435

Quoted 3 lines
hw/intc/arm_gicv5.c +0 -0
@@ -1433,6 +1433,7 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
              /* ...which means VIRT_ONE_N is also RES0 */
              v &= ~R_IRS_IDR0_VIRT_ONE_N_MASK;
          }

Looking at the code path it is obvious, I wonder why compilers or coverity didn't warned 'v' is set but not used...

hw/intc/arm_gicv5.c static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 1437

Quoted 2 lines
hw/intc/arm_gicv5.c +1 -0
+        *data = v;
          return true;
#2 lore raw
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Peter Maydell

IN the code for handling reads of IRS_IDR0, we carefully construct the correct value starting with cs->irs_idr0 and adjusting it. However, we never actually write the final value into *data, so the guest will always see zero.

We didn't notice this before, because Linux happens to not care about this register value except to check for the presence of virtualization.

Fixes 405ad2e76f13254 ("hw/intc/arm_gicv5: Implement IRS ID regs")
---
  hw/intc/arm_gicv5.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 11 lines

hw/intc/arm_gicv5.c static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 1435

Quoted 8 lines
hw/intc/arm_gicv5.c +0 -0
index 08878193dfc..ebfb0878af3 100644
@@ -1433,6 +1433,7 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
              /* ...which means VIRT_ONE_N is also RES0 */
              v &= ~R_IRS_IDR0_VIRT_ONE_N_MASK;
          }

Looking at the code path it is obvious, I wonder why compilers or coverity didn't warned 'v' is set but not used...

AFAICT, 'param @= RHS' counts as a use with -Wunused-but-set-variable in GCC up to version 15; GCC 16.1 adds an exception for this and should warn.

Jim

#3 lore raw
Quoted 30 lines · Jim MacArthur
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Peter Maydell

IN the code for handling reads of IRS_IDR0, we carefully construct the correct value starting with cs->irs_idr0 and adjusting it. However, we never actually write the final value into *data, so the guest will always see zero.

We didn't notice this before, because Linux happens to not care about this register value except to check for the presence of virtualization.

Fixes 405ad2e76f13254 ("hw/intc/arm_gicv5: Implement IRS ID regs")
---
   hw/intc/arm_gicv5.c | 1 +
   1 file changed, 1 insertion(+)
Quoted 11 lines

hw/intc/arm_gicv5.c static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 1435

Quoted 8 lines
hw/intc/arm_gicv5.c +0 -0
index 08878193dfc..ebfb0878af3 100644
@@ -1433,6 +1433,7 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
               /* ...which means VIRT_ONE_N is also RES0 */
               v &= ~R_IRS_IDR0_VIRT_ONE_N_MASK;
           }

Looking at the code path it is obvious, I wonder why compilers or coverity didn't warned 'v' is set but not used...

Quoted 1 line

AFAICT, 'param @= RHS' counts as a use with -Wunused-but-set-variable in GCC up to version 15; GCC 16.1 adds an exception for this and should warn.

Oh, thanks for the info!

Reviewed-by on v1 1/1
#4 lore raw
In reply to Peter Maydell
Quoted 21 lines · Peter Maydell

IN the code for handling reads of IRS_IDR0, we carefully construct the correct value starting with cs->irs_idr0 and adjusting it. However, we never actually write the final value into *data, so the guest will always see zero.

We didn't notice this before, because Linux happens to not care about this register value except to check for the presence of virtualization.

Fixes 405ad2e76f13254 ("hw/intc/arm_gicv5: Implement IRS ID regs")
---
 hw/intc/arm_gicv5.c | 1 +
 1 file changed, 1 insertion(+)
hw/intc/arm_gicv5.c +0 -0
index 08878193dfc..ebfb0878af3 100644

hw/intc/arm_gicv5.c static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 1439

Quoted 7 lines
hw/intc/arm_gicv5.c +1 -0
@@ -1433,6 +1433,7 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
             /* ...which means VIRT_ONE_N is also RES0 */
             v &= ~R_IRS_IDR0_VIRT_ONE_N_MASK;
         }
+        *data = v;
         return true;
 
     case A_IRS_IDR1: