Skip to contentSkip to conversation

Not to clear all the bits of mip

PATCH New Nick Hu 3 participants 7 messages Jan 17, 2023 – Feb 8, 2023 1 message not in the archive

lore
Share & tools
lore

Nick Hu

author
#0 lore raw

cover Not to clear all the bits of mip

In generic behavior of QEMU, if we clear the mip.SEIP and the pendings of PLIC still exist, the QEMU may not set the mip.SEIP back immediately. So interrupts won't be handled anymore until the next new device interrupt arrived. We should only clear the SSIP and STIP which set by SW. The rest of the bits should be decided by HW.

Nick Hu (2):
firmware: Not to clear all the MIP
lib: sbi_hsm: Use csr_set to restore the MIP

 firmware/fw_base.S | 10 ++++++++--
 lib/sbi/sbi_hsm.c  |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 firmware: Not to clear all the MIP

In generic behavior of QEMU, if the pending bits of PLIC are still set and we clear the SEIP, the QEMU may not set the SEIP back immediately and the interrupt may not be handled anymore until the new interrupts arrived and QEMU set the SEIP back which is a generic behavior in QEMU.

---
 firmware/fw_base.S | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
firmware/fw_base.S +8 -2
index 3f622b3..50f284e 100644
@@ -422,9 +422,15 @@ _start_warm:
 	li	ra, 0
 	call	_reset_regs
 
-	/* Disable and clear all interrupts */
+	/* Disable all interrupts */
 	csrw	CSR_MIE, zero
-	csrw	CSR_MIP, zero
+	/*
+	 * Only clear the MIP_SSIP and MIP_STIP. For the platform like QEMU,
+	 * If we clear other interrupts like MIP_SEIP and the pendings of
+	 * PLIC still exist, the QEMU may not set it back immediately.
+	 */
+	li	t0, (MIP_SSIP | MIP_STIP)
+	csrc	CSR_MIP, t0
 
 	/* Find HART count and HART stack size */
 	lla	a4, platform
Signature · 1 line
2.34.1
#2 lore raw

PATCH 1/2 firmware: Not to clear all the MIP

Quoted 8 lines · Nick Hu

In generic behavior of QEMU, if the pending bits of PLIC are still set and we clear the SEIP, the QEMU may not set the SEIP back immediately and the interrupt may not be handled anymore until the new interrupts arrived and QEMU set the SEIP back which is a generic behavior in QEMU.

Looks good to me.

Regards,
Anup

Quoted 34 lines
---
 firmware/fw_base.S | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
firmware/fw_base.S +8 -3
index 3f622b3..50f284e 100644
@@ -422,9 +422,15 @@ _start_warm:
        li      ra, 0
        call    _reset_regs
 
-       /* Disable and clear all interrupts */
+       /* Disable all interrupts */
        csrw    CSR_MIE, zero
-       csrw    CSR_MIP, zero
+       /*
+        * Only clear the MIP_SSIP and MIP_STIP. For the platform like QEMU,
+        * If we clear other interrupts like MIP_SEIP and the pendings of
+        * PLIC still exist, the QEMU may not set it back immediately.
+        */
+       li      t0, (MIP_SSIP | MIP_STIP)
+       csrc    CSR_MIP, t0
 
        /* Find HART count and HART stack size */
        lla     a4, platform
--

2.34.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

author
#3 lore raw

PATCH 2/2 lib: sbi_hsm: Use csr_set to restore the MIP

In reply to Nick Hu

If we use the csr_write to restore the MIP, we may clear the SEIP. In generic behavior of QEMU, if the pending bits of PLIC are set and we clear the SEIP, the QEMU may not set it back immediately. It may cause the interrupts won't be handled anymore until the new interrupts arrived and QEMU set the bits back.

---
 lib/sbi/sbi_hsm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_hsm.c +1 -1
index c0a5505..39cd1ab 100644
@@ -358,7 +358,7 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
 							    hart_data_offset);
 
 	csr_write(CSR_MIE, hdata->saved_mie);
-	csr_write(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
+	csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
 }
 
 void sbi_hsm_hart_resume_start(struct sbi_scratch *scratch)
Signature · 1 line
2.34.1
#4 lore raw

PATCH 2/2 lib: sbi_hsm: Use csr_set to restore the MIP

Quoted 9 lines · Nick Hu

If we use the csr_write to restore the MIP, we may clear the SEIP. In generic behavior of QEMU, if the pending bits of PLIC are set and we clear the SEIP, the QEMU may not set it back immediately. It may cause the interrupts won't be handled anymore until the new interrupts arrived and QEMU set the bits back.

Looks good to me.

Regards,
Anup

Quoted 25 lines
---
 lib/sbi/sbi_hsm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_hsm.c +1 -2
index c0a5505..39cd1ab 100644
@@ -358,7 +358,7 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
                                                            hart_data_offset);
 
        csr_write(CSR_MIE, hdata->saved_mie);
-       csr_write(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
+       csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
 }
 
 void sbi_hsm_hart_resume_start(struct sbi_scratch *scratch)
--

2.34.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

A message that is not in the archive (sent off-list or not yet received): CAKddAkDtLOwsT9XTOPY3zpO+h78zGVFx=PtEn-+jafab69ON_Q@mail.gmail.com

#6 lore raw

cover Not to clear all the bits of mip

Quoted 17 lines · Nick Hu
Quoted 15 lines · Nick Hu

In generic behavior of QEMU, if we clear the mip.SEIP and the pendings of PLIC still exist, the QEMU may not set the mip.SEIP back immediately. So interrupts won't be handled anymore until the next new device interrupt arrived. We should only clear the SSIP and STIP which set by SW. The rest of the bits should be decided by HW.

Nick Hu (2):
firmware: Not to clear all the MIP
lib: sbi_hsm: Use csr_set to restore the MIP

 firmware/fw_base.S | 10 ++++++++--
 lib/sbi/sbi_hsm.c  |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)
Quoted 6 lines
Quoted 3 lines

--
2.34.1

Hi Anup,

Do you have any suggestions on the patches?

This is next on my list. I will review it soon.

Regards,
Anup

Applied
#7 lore raw

cover Not to clear all the bits of mip

In reply to Nick Hu
Quoted 10 lines · Nick Hu

In generic behavior of QEMU, if we clear the mip.SEIP and the pendings of PLIC still exist, the QEMU may not set the mip.SEIP back immediately. So interrupts won't be handled anymore until the next new device interrupt arrived. We should only clear the SSIP and STIP which set by SW. The rest of the bits should be decided by HW.

Nick Hu (2):
firmware: Not to clear all the MIP
lib: sbi_hsm: Use csr_set to restore the MIP

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 13 lines
 firmware/fw_base.S | 10 ++++++++--
 lib/sbi/sbi_hsm.c  |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

--
2.34.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi