Skip to contentSkip to conversation

pl031: Expose RTCICR as proper WC register

PATCH In review Alexander Graf 2 participants 7 messages Nov 4, 2019 – Nov 14, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pl031: Expose RTCICR as proper WC register

The current pl031 RTCICR register implementation always clears the IRQ pending status on a register write, regardless of the value it writes.

To justify that behavior, it references the arm926e documentation (DDI0287B) and indicates that said document states that any write clears the internal IRQ state. I could however not find any text in that document backing the statement. In fact, it explicitly says:

"Writing 1 to bit 0 of RTCICR clears the RTCINTR flag."

which describes it as much as a write-to-clear register as the PL031 spec (DDI0224) does:

"Writing 1 to bit position 0 clears the corresponding interrupt.
Writing 0 has no effect."

Let's remove the bogus comment and instead follow both specs to what they say.

---
 hw/rtc/pl031.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
hw/rtc/pl031.c +1 -5
index 3a982752a2..c57cf83165 100644
@@ -149,11 +149,7 @@ static void pl031_write(void * opaque, hwaddr offset,
         pl031_update(s);
         break;
     case RTC_ICR:
-        /* The PL031 documentation (DDI0224B) states that the interrupt is
-           cleared when bit 0 of the written value is set.  However the
-           arm926e documentation (DDI0287B) states that the interrupt is
-           cleared when any value is written.  */
-        s->is = 0;
+        s->is &= ~value;
         pl031_update(s);
         break;
     case RTC_CR:
Signature · 12 lines
2.17.1




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
#1 lore raw
Quoted 9 lines · Alexander Graf

The current pl031 RTCICR register implementation always clears the IRQ pending status on a register write, regardless of the value it writes.

To justify that behavior, it references the arm926e documentation (DDI0287B) and indicates that said document states that any write clears the internal IRQ state. I could however not find any text in that document backing the statement. In fact, it explicitly says:

Quoted 7 lines

"Writing 1 to bit 0 of RTCICR clears the RTCINTR flag."

which describes it as much as a write-to-clear register as the PL031 spec (DDI0224) does:

"Writing 1 to bit position 0 clears the corresponding interrupt.
Writing 0 has no effect."

DDI0287B page 11-2 section 11.1 says
"The interrupt is cleared by writing any data value to the interrupt clear register RTCICR". As you note, this contradicts what it says later on in section 11.2.2.

(Interestingly, the PL030 does have a "write any value to clear the interrupt" register, RTCEOI.)

I'm fairly sure this patch is right and the DDI0287B document has an error, since it isn't internally consistent and doesn't match the proper PL031 TRM.

Did you find this because you had a guest that assumed the other behaviour? This bug has been in QEMU for a very long time, and it seems odd for a guest to deliberately perform an action (writing 0) which is documented to have no effect on the device...

Quoted 27 lines

Let's remove the bogus comment and instead follow both specs to what they say.

---
 hw/rtc/pl031.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
hw/rtc/pl031.c +1 -6
index 3a982752a2..c57cf83165 100644
@@ -149,11 +149,7 @@ static void pl031_write(void * opaque, hwaddr offset,
         pl031_update(s);
         break;
     case RTC_ICR:
-        /* The PL031 documentation (DDI0224B) states that the interrupt is
-           cleared when bit 0 of the written value is set.  However the
-           arm926e documentation (DDI0287B) states that the interrupt is
-           cleared when any value is written.  */
-        s->is = 0;
+        s->is &= ~value;
         pl031_update(s);
         break;
     case RTC_CR:
--
Quoted 1 line

2.17.1

thanks
-- PMM

#2 lore raw

Hey Peter,

Quoted 26 lines · Peter Maydell
Quoted 9 lines · Alexander Graf

The current pl031 RTCICR register implementation always clears the IRQ pending status on a register write, regardless of the value it writes.

To justify that behavior, it references the arm926e documentation (DDI0287B) and indicates that said document states that any write clears the internal IRQ state. I could however not find any text in that document backing the statement. In fact, it explicitly says:

Quoted 7 lines

"Writing 1 to bit 0 of RTCICR clears the RTCINTR flag."

which describes it as much as a write-to-clear register as the PL031 spec (DDI0224) does:

"Writing 1 to bit position 0 clears the corresponding interrupt.
Writing 0 has no effect."

DDI0287B page 11-2 section 11.1 says
"The interrupt is cleared by writing any data value to the interrupt clear register RTCICR". As you note, this contradicts what it says later on in section 11.2.2.

(Interestingly, the PL030 does have a "write any value to clear the interrupt" register, RTCEOI.)

Quoted 8 lines

I'm fairly sure this patch is right and the DDI0287B document has an error, since it isn't internally consistent and doesn't match the proper PL031 TRM.

Did you find this because you had a guest that assumed the other behaviour? This bug has been in QEMU for a very long time, and it seems odd for a guest to deliberately perform an action (writing 0) which is documented to have no effect on the device...

We found this bug by trying to find justification for the behavior in the spec and apparently my spec reading skills were lacking. I could not find the reference you cited above.

So no, I did not see any guest breakage.

I still think that being consistent with the actual PL031 spec is preferable though. If any real world guest breaks because of this, we can still revert this patch and document the exact breakage in the comment instead.

Alex

Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879

#3 lore raw
Quoted 13 lines · Alexander Graf

Hey Peter,

Quoted 4 lines · Peter Maydell

Did you find this because you had a guest that assumed the other behaviour? This bug has been in QEMU for a very long time, and it seems odd for a guest to deliberately perform an action (writing 0) which is documented to have no effect on the device...

We found this bug by trying to find justification for the behavior in the spec and apparently my spec reading skills were lacking. I could not find the reference you cited above.

Quoted 6 lines

So no, I did not see any guest breakage.

I still think that being consistent with the actual PL031 spec is preferable though. If any real world guest breaks because of this, we can still revert this patch and document the exact breakage in the comment instead.

Yeah, I agree; I'm essentially just gathering material for the commit message here. (The gold standard would be to go find some hardware with a real pl031 and prod it to confirm behaviour, but that's more effort than really seems justified to me.)

thanks
-- PMM

#4 lore raw
Quoted 11 lines · Peter Maydell
Quoted 4 lines · Alexander Graf

I still think that being consistent with the actual PL031 spec is preferable though. If any real world guest breaks because of this, we can still revert this patch and document the exact breakage in the comment instead.

Yeah, I agree; I'm essentially just gathering material for the commit message here. (The gold standard would be to go find some hardware with a real pl031 and prod it to confirm behaviour, but that's more effort than really seems justified to me.)

I propose to put this in for 4.2 with an updated commit message:

===begin===
pl031: Expose RTCICR as proper WC register

The current PL031 RTCICR register implementation always clears the IRQ pending status on a register write, regardless of the value the guest writes.

To justify that behavior, it references the ARM926EJ-S Development Chip Reference Manual (DDI0287B) and indicates that said document states that any write clears the internal IRQ state. It is indeed true that in section 11.1 this document says:

"The interrupt is cleared by writing any data value to the
interrupt clear register RTCICR".

However, later in section 11.2.2 it contradicts itself by saying:

"Writing 1 to bit 0 of RTCICR clears the RTCINTR flag."

The latter statement matches the PL031 TRM (DDI0224C), which says:

"Writing 1 to bit position 0 clears the corresponding interrupt.
Writing 0 has no effect."

Let's assume that the self-contradictory DDI0287B is in error, and follow the reference manual for the device itself, by making the register write-one-to-clear.
===endit===

Is that OK?

thanks
-- PMM

#5 lore raw
Quoted 39 lines · Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 4 lines · Alexander Graf

I still think that being consistent with the actual PL031 spec is preferable though. If any real world guest breaks because of this, we can still revert this patch and document the exact breakage in the comment instead.

Yeah, I agree; I'm essentially just gathering material for the commit message here. (The gold standard would be to go find some hardware with a real pl031 and prod it to confirm behaviour, but that's more effort than really seems justified to me.)

I propose to put this in for 4.2 with an updated commit message:

===begin===
pl031: Expose RTCICR as proper WC register

The current PL031 RTCICR register implementation always clears the IRQ pending status on a register write, regardless of the value the guest writes.

To justify that behavior, it references the ARM926EJ-S Development Chip Reference Manual (DDI0287B) and indicates that said document states that any write clears the internal IRQ state. It is indeed true that in section 11.1 this document says:

"The interrupt is cleared by writing any data value to the
interrupt clear register RTCICR".

However, later in section 11.2.2 it contradicts itself by saying:

"Writing 1 to bit 0 of RTCICR clears the RTCINTR flag."

The latter statement matches the PL031 TRM (DDI0224C), which says:

"Writing 1 to bit position 0 clears the corresponding interrupt.
Writing 0 has no effect."

Quoted 6 lines

Let's assume that the self-contradictory DDI0287B is in error, and follow the reference manual for the device itself, by making the register write-one-to-clear.
===endit===

Is that OK?

It's much better. Will you just fix it up inline for me please? :)

Thanks,

Alex

Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879

#6 lore raw
Quoted 4 lines · Alexander Graf
Quoted 1 line · Peter Maydell

Is that OK?

It's much better. Will you just fix it up inline for me please? :)

Sure :-)

-- PMM