2022-11-25 00:34:54

by Thomas Gleixner

[permalink] [raw]
Subject: [patch V3 04/33] genirq/msi: Add size info to struct msi_domain_info

To allow proper range checking especially for dynamic allocations add a
size field to struct msi_domain_info. If the field is 0 then the size is
unknown or unlimited (up to MSI_MAX_INDEX) to provide backwards
compability.

Signed-off-by: Thomas Gleixner <[email protected]>
---
V3: Move the initialization into the common domain creation code
---
include/linux/msi.h | 5 +++++
kernel/irq/msi.c | 11 +++++++++++
2 files changed, 16 insertions(+)

--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -422,6 +422,10 @@ struct msi_domain_ops {
* struct msi_domain_info - MSI interrupt domain data
* @flags: Flags to decribe features and capabilities
* @bus_token: The domain bus token
+ * @hwsize: The hardware table size or the software index limit.
+ * If 0 then the size is considered unlimited and
+ * gets initialized to the maximum software index limit
+ * by the domain creation code.
* @ops: The callback data structure
* @chip: Optional: associated interrupt chip
* @chip_data: Optional: associated interrupt chip data
@@ -433,6 +437,7 @@ struct msi_domain_ops {
struct msi_domain_info {
u32 flags;
enum irq_domain_bus_token bus_token;
+ unsigned int hwsize;
struct msi_domain_ops *ops;
struct irq_chip *chip;
void *chip_data;
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -773,6 +773,17 @@ struct irq_domain *msi_create_irq_domain
{
struct irq_domain *domain;

+ if (info->hwsize > MSI_XA_DOMAIN_SIZE)
+ return NULL;
+
+ /*
+ * Hardware size 0 is valid for backwards compatibility and for
+ * domains which are not backed by a hardware table. Grant the
+ * maximum index space.
+ */
+ if (!info->hwsize)
+ info->hwsize = MSI_XA_DOMAIN_SIZE;
+
msi_domain_update_dom_ops(info);
if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS)
msi_domain_update_chip_ops(info);


Subject: [tip: irq/core] genirq/msi: Add size info to struct msi_domain_info

The following commit has been merged into the irq/core branch of tip:

Commit-ID: 61bf992fc618503c910416f28afa0b015838b72b
Gitweb: https://git.kernel.org/tip/61bf992fc618503c910416f28afa0b015838b72b
Author: Thomas Gleixner <[email protected]>
AuthorDate: Fri, 25 Nov 2022 00:25:51 +01:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Mon, 05 Dec 2022 19:21:01 +01:00

genirq/msi: Add size info to struct msi_domain_info

To allow proper range checking especially for dynamic allocations add a
size field to struct msi_domain_info. If the field is 0 then the size is
unknown or unlimited (up to MSI_MAX_INDEX) to provide backwards
compability.

Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: Kevin Tian <[email protected]>
Acked-by: Marc Zyngier <[email protected]>
Link: https://lore.kernel.org/r/[email protected]

---
include/linux/msi.h | 5 +++++
kernel/irq/msi.c | 11 +++++++++++
2 files changed, 16 insertions(+)

diff --git a/include/linux/msi.h b/include/linux/msi.h
index 7fb8737..08a0e2a 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -422,6 +422,10 @@ struct msi_domain_ops {
* struct msi_domain_info - MSI interrupt domain data
* @flags: Flags to decribe features and capabilities
* @bus_token: The domain bus token
+ * @hwsize: The hardware table size or the software index limit.
+ * If 0 then the size is considered unlimited and
+ * gets initialized to the maximum software index limit
+ * by the domain creation code.
* @ops: The callback data structure
* @chip: Optional: associated interrupt chip
* @chip_data: Optional: associated interrupt chip data
@@ -433,6 +437,7 @@ struct msi_domain_ops {
struct msi_domain_info {
u32 flags;
enum irq_domain_bus_token bus_token;
+ unsigned int hwsize;
struct msi_domain_ops *ops;
struct irq_chip *chip;
void *chip_data;
diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index c368116..0a38905 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -772,6 +772,17 @@ struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,
{
struct irq_domain *domain;

+ if (info->hwsize > MSI_XA_DOMAIN_SIZE)
+ return NULL;
+
+ /*
+ * Hardware size 0 is valid for backwards compatibility and for
+ * domains which are not backed by a hardware table. Grant the
+ * maximum index space.
+ */
+ if (!info->hwsize)
+ info->hwsize = MSI_XA_DOMAIN_SIZE;
+
msi_domain_update_dom_ops(info);
if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS)
msi_domain_update_chip_ops(info);