Skip to contentSkip to conversation

target/riscv: Minor fixes and improvements for Virtual IRQs

PATCH Applied Rajnesh Kanwal 3 participants 7 messages May 20, 2024 – Jun 4, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

v2 cover target/riscv: Minor fixes and improvements for Virtual IRQs

This series contains few miscellaneous fixes related to Virtual IRQs and related code. The first patch changes CSR mask widths to 64bit as AIA introduces half CSRs in case of 32bit systems.

Second patch fixes guest and core local IRQ overlap. Qemu creates a single IRQ range which is shared between core local interrupts and guests in riscv_cpu_init(). Even though, in the current state there is no device generating interrupts in the 13:63 range, and virtual IRQ logic in Qemu also doesn't go through riscv_cpu_set_irq() path, it's better to keep local and guest range separate to avoid confusion and any future issues.

Patches can be found here on github [0] and v1 of the series can be found here [1].

Patches are based on alistair/riscv-to-apply.next.

[0] https://github.com/rajnesh-kanwal/qemu/tree/dev/rkanwal/irq_fixes_v2
[1] https://lore.kernel.org/all/[email protected]/

Changes from v1->v2:
1. Check patch fixes.
2. Removed commit title split from Fixes tags.

Rajnesh Kanwal (2):
target/riscv: Extend virtual irq csrs masks to be 64 bit wide. target/riscv: Move Guest irqs out of the core local irqs range.

 target/riscv/cpu_bits.h |  3 ++-
 target/riscv/csr.c      | 23 +++++++++++++++--------
 2 files changed, 17 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 target/riscv: Extend virtual irq csrs masks to be 64 bit wide.

AIA extends the width of all IRQ CSRs to 64bit even in 32bit systems by adding missing half CSRs.

This seems to be missed while adding support for
virtual IRQs. The whole logic seems to be correct
except the width of the masks.

Fixes 1697837ed9 ("target/riscv: Add M-mode virtual interrupt and IRQ filtering support.")
Fixes 40336d5b1d ("target/riscv: Add HS-mode virtual interrupt and IRQ filtering support.")
---
 target/riscv/csr.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
target/riscv/csr.c +7 -7
index 6b460ee0e8..152796ebc0 100644
@@ -1200,18 +1200,18 @@ static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE |
  */
 
 /* Bit STIP can be an alias of mip.STIP that's why it's writable in mvip. */
-static const target_ulong mvip_writable_mask = MIP_SSIP | MIP_STIP | MIP_SEIP |
+static const uint64_t mvip_writable_mask = MIP_SSIP | MIP_STIP | MIP_SEIP |
                                     LOCAL_INTERRUPTS;
-static const target_ulong mvien_writable_mask = MIP_SSIP | MIP_SEIP |
+static const uint64_t mvien_writable_mask = MIP_SSIP | MIP_SEIP |
                                     LOCAL_INTERRUPTS;
 
-static const target_ulong sip_writable_mask = SIP_SSIP | LOCAL_INTERRUPTS;
-static const target_ulong hip_writable_mask = MIP_VSSIP;
-static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP |
+static const uint64_t sip_writable_mask = SIP_SSIP | LOCAL_INTERRUPTS;
+static const uint64_t hip_writable_mask = MIP_VSSIP;
+static const uint64_t hvip_writable_mask = MIP_VSSIP | MIP_VSTIP |
                                     MIP_VSEIP | LOCAL_INTERRUPTS;
-static const target_ulong hvien_writable_mask = LOCAL_INTERRUPTS;
+static const uint64_t hvien_writable_mask = LOCAL_INTERRUPTS;
 
-static const target_ulong vsip_writable_mask = MIP_VSSIP | LOCAL_INTERRUPTS;
+static const uint64_t vsip_writable_mask = MIP_VSSIP | LOCAL_INTERRUPTS;
 
 const bool valid_vm_1_10_32[16] = {
     [VM_1_10_MBARE] = true,
Signature · 1 line
2.34.1
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] target/riscv: Extend virtual irq csrs masks to be 64 bit wide.

Quoted 8 lines · Rajnesh Kanwal

AIA extends the width of all IRQ CSRs to 64bit even in 32bit systems by adding missing half CSRs.

This seems to be missed while adding support for
virtual IRQs. The whole logic seems to be correct
except the width of the masks.

Quoted 5 lines
Fixes 1697837ed9 ("target/riscv: Add M-mode virtual interrupt and IRQ filtering support.")
Fixes 40336d5b1d ("target/riscv: Add HS-mode virtual interrupt and IRQ filtering support.")

Alistair

Quoted 38 lines
---
 target/riscv/csr.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
target/riscv/csr.c +7 -8
index 6b460ee0e8..152796ebc0 100644
@@ -1200,18 +1200,18 @@ static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE |
  */
 
 /* Bit STIP can be an alias of mip.STIP that's why it's writable in mvip. */
-static const target_ulong mvip_writable_mask = MIP_SSIP | MIP_STIP | MIP_SEIP |
+static const uint64_t mvip_writable_mask = MIP_SSIP | MIP_STIP | MIP_SEIP |
                                     LOCAL_INTERRUPTS;
-static const target_ulong mvien_writable_mask = MIP_SSIP | MIP_SEIP |
+static const uint64_t mvien_writable_mask = MIP_SSIP | MIP_SEIP |
                                     LOCAL_INTERRUPTS;
 
-static const target_ulong sip_writable_mask = SIP_SSIP | LOCAL_INTERRUPTS;
-static const target_ulong hip_writable_mask = MIP_VSSIP;
-static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP |
+static const uint64_t sip_writable_mask = SIP_SSIP | LOCAL_INTERRUPTS;
+static const uint64_t hip_writable_mask = MIP_VSSIP;
+static const uint64_t hvip_writable_mask = MIP_VSSIP | MIP_VSTIP |
                                     MIP_VSEIP | LOCAL_INTERRUPTS;
-static const target_ulong hvien_writable_mask = LOCAL_INTERRUPTS;
+static const uint64_t hvien_writable_mask = LOCAL_INTERRUPTS;
 
-static const target_ulong vsip_writable_mask = MIP_VSSIP | LOCAL_INTERRUPTS;
+static const uint64_t vsip_writable_mask = MIP_VSSIP | LOCAL_INTERRUPTS;
 
 const bool valid_vm_1_10_32[16] = {
     [VM_1_10_MBARE] = true,
--

2.34.1

#3 lore raw

PATCH v2 2/2 target/riscv: Move Guest irqs out of the core local irqs range.

In reply to Rajnesh Kanwal

Qemu maps IRQs 0:15 for core interrupts and 16 onward for guest interrupts which are later translated to hgiep in riscv_cpu_set_irq() function.

With virtual IRQ support added, software now can fully use the whole local interrupt range without any actual hardware attached.

This change moves the guest interrupt range after the core local interrupt range to avoid clash.

Fixes 1697837ed9 ("target/riscv: Add M-mode virtual interrupt and IRQ filtering support.")
Fixes 40336d5b1d ("target/riscv: Add HS-mode virtual interrupt and IRQ filtering support.")
---
 target/riscv/cpu_bits.h | 3 ++-
 target/riscv/csr.c      | 9 ++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
target/riscv/cpu_bits.h +2 -1
index 74318a925c..a470fda9be 100644
@@ -695,7 +695,8 @@ typedef enum RISCVException {
 #define IRQ_M_EXT                          11
 #define IRQ_S_GEXT                         12
 #define IRQ_PMU_OVF                        13
-#define IRQ_LOCAL_MAX                      16
+#define IRQ_LOCAL_MAX                      64
+/* -1 is due to bit zero of hgeip and hgeie being ROZ. */
 #define IRQ_LOCAL_GUEST_MAX                (TARGET_LONG_BITS - 1)
 
 /* mip masks */
target/riscv/csr.c +8 -1
index 152796ebc0..464e0e57a3 100644
@@ -1148,7 +1148,14 @@ static RISCVException write_stimecmph(CPURISCVState *env, int csrno,
 
 #define VSTOPI_NUM_SRCS 5
 
-#define LOCAL_INTERRUPTS (~0x1FFF)
+/*
+ * All core local interrupts except the fixed ones 0:12. This macro is for
+ * virtual interrupts logic so please don't change this to avoid messing up
+ * the whole support, For reference see AIA spec: `5.3 Interrupt filtering and
+ * virtual interrupts for supervisor level` and `6.3.2 Virtual interrupts for
+ * VS level`.
+ */
+#define LOCAL_INTERRUPTS   (~0x1FFFULL)
 
 static const uint64_t delegable_ints =
     S_MODE_INTERRUPTS | VS_MODE_INTERRUPTS | MIP_LCOFIP;
Signature · 1 line
2.34.1
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] target/riscv: Move Guest irqs out of the core local irqs range.

Quoted 8 lines · Rajnesh Kanwal

Qemu maps IRQs 0:15 for core interrupts and 16 onward for guest interrupts which are later translated to hgiep in riscv_cpu_set_irq() function.

With virtual IRQ support added, software now can fully use the whole local interrupt range without any actual hardware attached.

Quoted 8 lines

This change moves the guest interrupt range after the core local interrupt range to avoid clash.

Fixes 1697837ed9 ("target/riscv: Add M-mode virtual interrupt and IRQ filtering support.")
Fixes 40336d5b1d ("target/riscv: Add HS-mode virtual interrupt and IRQ filtering support.")

---

Quoted 38 lines
  target/riscv/cpu_bits.h | 3 ++-
  target/riscv/csr.c      | 9 ++++++++-
  2 files changed, 10 insertions(+), 2 deletions(-)
target/riscv/cpu_bits.h +2 -1
index 74318a925c..a470fda9be 100644
@@ -695,7 +695,8 @@ typedef enum RISCVException {
  #define IRQ_M_EXT                          11
  #define IRQ_S_GEXT                         12
  #define IRQ_PMU_OVF                        13
-#define IRQ_LOCAL_MAX                      16
+#define IRQ_LOCAL_MAX                      64
+/* -1 is due to bit zero of hgeip and hgeie being ROZ. */
  #define IRQ_LOCAL_GUEST_MAX                (TARGET_LONG_BITS - 1)
 
  /* mip masks */
target/riscv/csr.c +8 -1
index 152796ebc0..464e0e57a3 100644
@@ -1148,7 +1148,14 @@ static RISCVException write_stimecmph(CPURISCVState *env, int csrno,
 
  #define VSTOPI_NUM_SRCS 5
 
-#define LOCAL_INTERRUPTS (~0x1FFF)
+/*
+ * All core local interrupts except the fixed ones 0:12. This macro is for
+ * virtual interrupts logic so please don't change this to avoid messing up
+ * the whole support, For reference see AIA spec: `5.3 Interrupt filtering and
+ * virtual interrupts for supervisor level` and `6.3.2 Virtual interrupts for
+ * VS level`.
+ */
+#define LOCAL_INTERRUPTS   (~0x1FFFULL)
 
  static const uint64_t delegable_ints =
      S_MODE_INTERRUPTS | VS_MODE_INTERRUPTS | MIP_LCOFIP;
Acked-by on v2 2/2
#5 lore raw

Re: [PATCH v2 2/2] target/riscv: Move Guest irqs out of the core local irqs range.

In reply to Rajnesh Kanwal
Quoted 9 lines · Rajnesh Kanwal

Qemu maps IRQs 0:15 for core interrupts and 16 onward for guest interrupts which are later translated to hgiep in riscv_cpu_set_irq() function.

With virtual IRQ support added, software now can fully use the whole local interrupt range without any actual hardware attached.

Quoted 7 lines

This change moves the guest interrupt range after the core local interrupt range to avoid clash.

Fixes 1697837ed9 ("target/riscv: Add M-mode virtual interrupt and IRQ filtering support.")
Fixes 40336d5b1d ("target/riscv: Add HS-mode virtual interrupt and IRQ filtering support.")

Alistair

Quoted 43 lines
---
 target/riscv/cpu_bits.h | 3 ++-
 target/riscv/csr.c      | 9 ++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
target/riscv/cpu_bits.h +2 -1
index 74318a925c..a470fda9be 100644
@@ -695,7 +695,8 @@ typedef enum RISCVException {
 #define IRQ_M_EXT                          11
 #define IRQ_S_GEXT                         12
 #define IRQ_PMU_OVF                        13
-#define IRQ_LOCAL_MAX                      16
+#define IRQ_LOCAL_MAX                      64
+/* -1 is due to bit zero of hgeip and hgeie being ROZ. */
 #define IRQ_LOCAL_GUEST_MAX                (TARGET_LONG_BITS - 1)
 
 /* mip masks */
target/riscv/csr.c +8 -2
index 152796ebc0..464e0e57a3 100644
@@ -1148,7 +1148,14 @@ static RISCVException write_stimecmph(CPURISCVState *env, int csrno,
 
 #define VSTOPI_NUM_SRCS 5
 
-#define LOCAL_INTERRUPTS (~0x1FFF)
+/*
+ * All core local interrupts except the fixed ones 0:12. This macro is for
+ * virtual interrupts logic so please don't change this to avoid messing up
+ * the whole support, For reference see AIA spec: `5.3 Interrupt filtering and
+ * virtual interrupts for supervisor level` and `6.3.2 Virtual interrupts for
+ * VS level`.
+ */
+#define LOCAL_INTERRUPTS   (~0x1FFFULL)
 
 static const uint64_t delegable_ints =
     S_MODE_INTERRUPTS | VS_MODE_INTERRUPTS | MIP_LCOFIP;
--

2.34.1

#6 lore raw
In reply to Rajnesh Kanwal
Quoted 21 lines · Rajnesh Kanwal

This series contains few miscellaneous fixes related to Virtual IRQs and related code. The first patch changes CSR mask widths to 64bit as AIA introduces half CSRs in case of 32bit systems.

Second patch fixes guest and core local IRQ overlap. Qemu creates a single IRQ range which is shared between core local interrupts and guests in riscv_cpu_init(). Even though, in the current state there is no device generating interrupts in the 13:63 range, and virtual IRQ logic in Qemu also doesn't go through riscv_cpu_set_irq() path, it's better to keep local and guest range separate to avoid confusion and any future issues.

Patches can be found here on github [0] and v1 of the series can be found here [1].

Patches are based on alistair/riscv-to-apply.next.

[0] https://github.com/rajnesh-kanwal/qemu/tree/dev/rkanwal/irq_fixes_v2
[1] https://lore.kernel.org/all/[email protected]/

Quoted 7 lines

Changes from v1->v2:
1. Check patch fixes.
2. Removed commit title split from Fixes tags.

Rajnesh Kanwal (2):
target/riscv: Extend virtual irq csrs masks to be 64 bit wide. target/riscv: Move Guest irqs out of the core local irqs range.

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 9 lines
 target/riscv/cpu_bits.h |  3 ++-
 target/riscv/csr.c      | 23 +++++++++++++++--------
 2 files changed, 17 insertions(+), 9 deletions(-)

--
2.34.1