* [PATCH] irqchip/riscv-imsic: Use GENMASK for base address masks
@ 2026-07-18 4:34 Pengpeng Hou
2026-07-20 3:34 ` Anup Patel
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Pengpeng Hou @ 2026-07-18 4:34 UTC (permalink / raw)
To: Anup Patel
Cc: Pengpeng Hou, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Björn Töpel, linux-riscv,
linux-kernel
The IMSIC DT binding allows riscv,guest-index-bits up to 7 and
riscv,hart-index-bits up to 15. On RV32, guest-index-bits=7 and
hart-index-bits=13, together with the 12-bit IMSIC page offset, is a
binding-valid layout that consumes a 32-bit low-address mask.
The parser accepts this equality case because it rejects only values
larger than the remaining bit budget. The base address canonicalization
then builds the low-address mask with BIT(sum) - 1. When sum is 32 on
RV32, that expression shifts an unsigned long by its full width.
Keep the legal equality layout and express the mask with GENMASK(sum - 1,
0) instead. The existing parser bounds guarantee that sum - 1 is below
BITS_PER_LONG at both mask sites.
Fixes: 21a8f8a0eb35 ("irqchip: Add RISC-V incoming MSI controller early driver")
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
drivers/irqchip/irq-riscv-imsic-state.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
index b8d1bbbf42f73..9505ddbd9eec9 100644
--- a/drivers/irqchip/irq-riscv-imsic-state.c
+++ b/drivers/irqchip/irq-riscv-imsic-state.c
@@ -7,6 +7,7 @@
#define pr_fmt(fmt) "riscv-imsic: " fmt
#include <linux/acpi.h>
#include <linux/cpu.h>
+#include <linux/bits.h>
#include <linux/bitmap.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
@@ -769,9 +770,9 @@ static int __init imsic_parse_fwnode(struct fwnode_handle *fwnode,
return -EINVAL;
}
global->base_addr = res.start;
- global->base_addr &= ~(BIT(global->guest_index_bits +
- global->hart_index_bits +
- IMSIC_MMIO_PAGE_SHIFT) - 1);
+ global->base_addr &= ~GENMASK(global->guest_index_bits +
+ global->hart_index_bits +
+ IMSIC_MMIO_PAGE_SHIFT - 1, 0);
global->base_addr &= ~((BIT(global->group_index_bits) - 1) <<
global->group_index_shift);
@@ -850,9 +851,9 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
}
base_addr = mmios[i].start;
- base_addr &= ~(BIT(global->guest_index_bits +
- global->hart_index_bits +
- IMSIC_MMIO_PAGE_SHIFT) - 1);
+ base_addr &= ~GENMASK(global->guest_index_bits +
+ global->hart_index_bits +
+ IMSIC_MMIO_PAGE_SHIFT - 1, 0);
base_addr &= ~((BIT(global->group_index_bits) - 1) <<
global->group_index_shift);
if (base_addr != global->base_addr) {
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] irqchip/riscv-imsic: Use GENMASK for base address masks
2026-07-18 4:34 [PATCH] irqchip/riscv-imsic: Use GENMASK for base address masks Pengpeng Hou
@ 2026-07-20 3:34 ` Anup Patel
2026-09-02 2:02 ` Pengpeng Hou
2026-09-04 13:40 ` [tip: irq/drivers] " tip-bot2 for Pengpeng Hou
2026-11-01 22:16 ` [PATCH] " patchwork-bot+linux-riscv
2 siblings, 1 reply; 5+ messages in thread
From: Anup Patel @ 2026-07-20 3:34 UTC (permalink / raw)
To: Pengpeng Hou
Cc: Thomas Gleixner, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Björn Töpel, linux-riscv,
linux-kernel
On Sat, Jul 18, 2026 at 10:04 AM Pengpeng Hou <pengpeng@iscas.ac.cn> wrote:
>
> The IMSIC DT binding allows riscv,guest-index-bits up to 7 and
> riscv,hart-index-bits up to 15. On RV32, guest-index-bits=7 and
> hart-index-bits=13, together with the 12-bit IMSIC page offset, is a
> binding-valid layout that consumes a 32-bit low-address mask.
>
> The parser accepts this equality case because it rejects only values
> larger than the remaining bit budget. The base address canonicalization
> then builds the low-address mask with BIT(sum) - 1. When sum is 32 on
> RV32, that expression shifts an unsigned long by its full width.
>
> Keep the legal equality layout and express the mask with GENMASK(sum - 1,
> 0) instead. The existing parser bounds guarantee that sum - 1 is below
> BITS_PER_LONG at both mask sites.
>
> Fixes: 21a8f8a0eb35 ("irqchip: Add RISC-V incoming MSI controller early driver")
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Thanks,
Anup
> ---
> drivers/irqchip/irq-riscv-imsic-state.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
> index b8d1bbbf42f73..9505ddbd9eec9 100644
> --- a/drivers/irqchip/irq-riscv-imsic-state.c
> +++ b/drivers/irqchip/irq-riscv-imsic-state.c
> @@ -7,6 +7,7 @@
> #define pr_fmt(fmt) "riscv-imsic: " fmt
> #include <linux/acpi.h>
> #include <linux/cpu.h>
> +#include <linux/bits.h>
> #include <linux/bitmap.h>
> #include <linux/interrupt.h>
> #include <linux/irq.h>
> @@ -769,9 +770,9 @@ static int __init imsic_parse_fwnode(struct fwnode_handle *fwnode,
> return -EINVAL;
> }
> global->base_addr = res.start;
> - global->base_addr &= ~(BIT(global->guest_index_bits +
> - global->hart_index_bits +
> - IMSIC_MMIO_PAGE_SHIFT) - 1);
> + global->base_addr &= ~GENMASK(global->guest_index_bits +
> + global->hart_index_bits +
> + IMSIC_MMIO_PAGE_SHIFT - 1, 0);
> global->base_addr &= ~((BIT(global->group_index_bits) - 1) <<
> global->group_index_shift);
>
> @@ -850,9 +851,9 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
> }
>
> base_addr = mmios[i].start;
> - base_addr &= ~(BIT(global->guest_index_bits +
> - global->hart_index_bits +
> - IMSIC_MMIO_PAGE_SHIFT) - 1);
> + base_addr &= ~GENMASK(global->guest_index_bits +
> + global->hart_index_bits +
> + IMSIC_MMIO_PAGE_SHIFT - 1, 0);
> base_addr &= ~((BIT(global->group_index_bits) - 1) <<
> global->group_index_shift);
> if (base_addr != global->base_addr) {
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] irqchip/riscv-imsic: Use GENMASK for base address masks
2026-07-20 3:34 ` Anup Patel
@ 2026-09-02 2:02 ` Pengpeng Hou
0 siblings, 0 replies; 5+ messages in thread
From: Pengpeng Hou @ 2026-09-02 2:02 UTC (permalink / raw)
To: Anup Patel
Cc: Pengpeng Hou, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Bjorn Topel, linux-riscv,
linux-kernel
Hi Anup,
This patch received your Reviewed-by on July 20. It is still marked New
in Patchwork, and I do not see it in the current tip/irq/core branch or
mainline.
Should I keep waiting, or would you prefer a resend rebased on the current
irq/core branch?
Thanks,
Pengpeng
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip: irq/drivers] irqchip/riscv-imsic: Use GENMASK for base address masks
2026-07-18 4:34 [PATCH] irqchip/riscv-imsic: Use GENMASK for base address masks Pengpeng Hou
2026-07-20 3:34 ` Anup Patel
@ 2026-09-04 13:40 ` tip-bot2 for Pengpeng Hou
2026-11-01 22:16 ` [PATCH] " patchwork-bot+linux-riscv
2 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Pengpeng Hou @ 2026-09-04 13:40 UTC (permalink / raw)
To: linux-tip-commits
Cc: Pengpeng Hou, Thomas Gleixner, Anup Patel, x86, linux-kernel
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: bd7d57a03c4b0fa3b0291ec64d688ebfed5edffc
Gitweb: https://git.kernel.org/tip/bd7d57a03c4b0fa3b0291ec64d688ebfed5edffc
Author: Pengpeng Hou <pengpeng@iscas.ac.cn>
AuthorDate: Sat, 18 Jul 2026 12:34:36 +08:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Fri, 04 Sep 2026 15:34:33 +02:00
irqchip/riscv-imsic: Use GENMASK for base address masks
The IMSIC DT binding allows riscv,guest-index-bits up to 7 and
riscv,hart-index-bits up to 15. On RV32, guest-index-bits=7 and
hart-index-bits=13, together with the 12-bit IMSIC page offset, is a
binding-valid layout that consumes a 32-bit low-address mask.
The parser accepts this equality case because it rejects only values
larger than the remaining bit budget. The base address canonicalization
then builds the low-address mask with BIT(sum) - 1. When sum is 32 on
RV32, that expression shifts an unsigned long by its full width.
Keep the legal equality layout and express the mask with GENMASK(sum - 1,
0) instead. The existing parser bounds guarantee that sum - 1 is below
BITS_PER_LONG at both mask sites.
Fixes: 21a8f8a0eb35 ("irqchip: Add RISC-V incoming MSI controller early driver")
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://patch.msgid.link/20260718040000.004.929c1ef2-caplitmus-rv@iscas.ac.cn
---
drivers/irqchip/irq-riscv-imsic-state.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
index b8d1bbb..9505ddb 100644
--- a/drivers/irqchip/irq-riscv-imsic-state.c
+++ b/drivers/irqchip/irq-riscv-imsic-state.c
@@ -7,6 +7,7 @@
#define pr_fmt(fmt) "riscv-imsic: " fmt
#include <linux/acpi.h>
#include <linux/cpu.h>
+#include <linux/bits.h>
#include <linux/bitmap.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
@@ -769,9 +770,9 @@ static int __init imsic_parse_fwnode(struct fwnode_handle *fwnode,
return -EINVAL;
}
global->base_addr = res.start;
- global->base_addr &= ~(BIT(global->guest_index_bits +
- global->hart_index_bits +
- IMSIC_MMIO_PAGE_SHIFT) - 1);
+ global->base_addr &= ~GENMASK(global->guest_index_bits +
+ global->hart_index_bits +
+ IMSIC_MMIO_PAGE_SHIFT - 1, 0);
global->base_addr &= ~((BIT(global->group_index_bits) - 1) <<
global->group_index_shift);
@@ -850,9 +851,9 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
}
base_addr = mmios[i].start;
- base_addr &= ~(BIT(global->guest_index_bits +
- global->hart_index_bits +
- IMSIC_MMIO_PAGE_SHIFT) - 1);
+ base_addr &= ~GENMASK(global->guest_index_bits +
+ global->hart_index_bits +
+ IMSIC_MMIO_PAGE_SHIFT - 1, 0);
base_addr &= ~((BIT(global->group_index_bits) - 1) <<
global->group_index_shift);
if (base_addr != global->base_addr) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] irqchip/riscv-imsic: Use GENMASK for base address masks
2026-07-18 4:34 [PATCH] irqchip/riscv-imsic: Use GENMASK for base address masks Pengpeng Hou
2026-07-20 3:34 ` Anup Patel
2026-09-04 13:40 ` [tip: irq/drivers] " tip-bot2 for Pengpeng Hou
@ 2026-11-01 22:16 ` patchwork-bot+linux-riscv
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+linux-riscv @ 2026-11-01 22:16 UTC (permalink / raw)
To: Pengpeng Hou
Cc: linux-riscv, anup, tglx, pjw, palmer, aou, alex, bjorn, linux-kernel
Hello:
This patch was applied to riscv/linux.git (fixes)
by Thomas Gleixner <tglx@kernel.org>:
On Sat, 18 Jul 2026 12:34:36 +0800 you wrote:
> The IMSIC DT binding allows riscv,guest-index-bits up to 7 and
> riscv,hart-index-bits up to 15. On RV32, guest-index-bits=7 and
> hart-index-bits=13, together with the 12-bit IMSIC page offset, is a
> binding-valid layout that consumes a 32-bit low-address mask.
>
> The parser accepts this equality case because it rejects only values
> larger than the remaining bit budget. The base address canonicalization
> then builds the low-address mask with BIT(sum) - 1. When sum is 32 on
> RV32, that expression shifts an unsigned long by its full width.
>
> [...]
Here is the summary with links:
- irqchip/riscv-imsic: Use GENMASK for base address masks
https://git.kernel.org/riscv/c/bd7d57a03c4b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-01 22:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-18 4:34 [PATCH] irqchip/riscv-imsic: Use GENMASK for base address masks Pengpeng Hou
2026-07-20 3:34 ` Anup Patel
2026-09-02 2:02 ` Pengpeng Hou
2026-09-04 13:40 ` [tip: irq/drivers] " tip-bot2 for Pengpeng Hou
2026-11-01 22:16 ` [PATCH] " patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®