Skip to contentSkip to conversation

hw/misc/iotkit-secctl: Fix writing to 'PPC Interrupt Clear' register

PATCH Superseded Philippe Mathieu-Daudé 2 participants 3 messages Feb 15, 2020 – Feb 17, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/misc/iotkit-secctl: Fix writing to 'PPC Interrupt Clear' register

Fix warning reported by Clang static code analyzer:

CC hw/misc/iotkit-secctl.o
hw/misc/iotkit-secctl.c:343:9: warning: Value stored to 'value' is never read

          value &= 0x00f000f3;
          ^        ~~~~~~~~~~
Fixes b3717c23e1c
Reported-by Clang Static Analyzer
---
 hw/misc/iotkit-secctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/iotkit-secctl.c +1 -1
index 609869821a..0d5556dd17 100644
@@ -340,7 +340,7 @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
         qemu_set_irq(s->sec_resp_cfg, s->secrespcfg);
         break;
     case A_SECPPCINTCLR:
-        value &= 0x00f000f3;
+        s->secppcintstat = ~value & 0x00f000f3;
         foreach_ppc(s, iotkit_secctl_ppc_update_irq_clear);
         break;
     case A_SECPPCINTEN:
Signature · 1 line
2.21.1
#1 lore raw
Quoted 20 lines · Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

CC hw/misc/iotkit-secctl.o
hw/misc/iotkit-secctl.c:343:9: warning: Value stored to 'value' is never read

          value &= 0x00f000f3;
          ^        ~~~~~~~~~~
Fixes b3717c23e1c
Reported-by Clang Static Analyzer
---
 hw/misc/iotkit-secctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/iotkit-secctl.c +0 -0
index 609869821a..0d5556dd17 100644

hw/misc/iotkit-secctl.c static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr, · line 343

Quoted 5 lines
hw/misc/iotkit-secctl.c +1 -1
@@ -340,7 +340,7 @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
         qemu_set_irq(s->sec_resp_cfg, s->secrespcfg);
         break;
     case A_SECPPCINTCLR:
-        value &= 0x00f000f3;
+        s->secppcintstat = ~value & 0x00f000f3;

This is (obviously) a bug, but I don't think your fix is right. This register has bits which are write-one-to-clear, (plus some other bits that are reserved and RAZ/WI) so we want:
s->secppcintstat &= ~(value & 0x00f000f3);

(In particular bitwise-not has higher precedence than bitwise-and, so your expression will end up writing zero to s->specppcintstat for any valid guest write.)

My guess is that when I originally wrote the code I meant to write something like
value &= 0x00f000f3;
s->secppcintstat &= ~value;
and forgot the second line.

thanks
-- PMM

#2 lore raw
Quoted 34 lines · Peter Maydell
Quoted 20 lines · Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

CC hw/misc/iotkit-secctl.o
hw/misc/iotkit-secctl.c:343:9: warning: Value stored to 'value' is never read

          value &= 0x00f000f3;
          ^        ~~~~~~~~~~
Fixes b3717c23e1c
Reported-by Clang Static Analyzer
---
 hw/misc/iotkit-secctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/iotkit-secctl.c +0 -0
index 609869821a..0d5556dd17 100644

hw/misc/iotkit-secctl.c static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr, · line 343

Quoted 5 lines
hw/misc/iotkit-secctl.c +1 -1
@@ -340,7 +340,7 @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
         qemu_set_irq(s->sec_resp_cfg, s->secrespcfg);
         break;
     case A_SECPPCINTCLR:
-        value &= 0x00f000f3;
+        s->secppcintstat = ~value & 0x00f000f3;

This is (obviously) a bug, but I don't think your fix is right. This register has bits which are write-one-to-clear, (plus some other bits that are reserved and RAZ/WI) so we want:
s->secppcintstat &= ~(value & 0x00f000f3);

Quoted 3 lines

(In particular bitwise-not has higher precedence than bitwise-and, so your expression will end up writing zero to s->specppcintstat for any valid guest write.)

Oops indeed :)

Quoted 8 lines

My guess is that when I originally wrote the code I meant to write something like

   value &= 0x00f000f3;
   s->secppcintstat &= ~value;

and forgot the second line.

thanks
-- PMM