genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 2 API rework
Subsystems (11)
v3 cover genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 2 API rework
This is V3 of the second part of the effort to provide support for per device MSI interrupt domains.
Version 2 of this second part can be found here:
https://lore.kernel.org/all/[email protected]
The first part is available here:
https://lore.kernel.org/all/[email protected]
and has been merged into:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/core
This part on top of the tip irq/core branch is also available here:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git devmsi-v3-part2
This part is the main preparation step for per device MSI domains:
1) Introduce irqdomain pointer storage space in device::msi::data and related helpers.
2) Convert interfaces to handle multiple per device MSI domains based on a domain ID
3) Provide new interfaces for allocation/free which are domain ID based and provide range allocation/free which is a prerequisite for post MSI-X enable alloc/free.
4) Switch all existing call sites of msi allocation/free interfaces over to the new interfaces
5) Remove the old interfaces
Changes vs. V2:
- Rework the xarray storage into per domain storage (Marc)
@Kevin: I did not pick up your Reviewed-by tag due to these changes.
The delta patch vs. V2 is attached below.
Thanks,
tglx
---
include/linux/msi.h +16 -8
@@ -174,24 +174,31 @@ enum msi_desc_filter { MSI_DESC_ASSOCIATED, }; + +/** +* struct msi_dev_domain - The internals of MSI domain info per device +* @store: Xarray for storing MSI descriptor pointers +* @irqdomain: Pointer to a per device interrupt domain +*/ +struct msi_dev_domain { +struct xarray store; +struct irq_domain *domain; +}; +/** * msi_device_data - MSI per device data * @properties: MSI properties which are interesting to drivers * @platform_data: Platform-MSI specific data * @mutex: Mutex protecting the MSI descriptor store -* @__store: Xarray for storing MSI descriptor pointers +* @__domains: Internal data for per device MSI domains * @__iter_idx: Index to search the next entry for iterators -* @__iter_max: Index to limit the search -* @__irqdomains: Per device interrupt domains */ struct msi_device_data {unsigned long properties;struct platform_msi_priv_data *platform_data;struct mutex mutex; -struct xarray __store; +struct msi_dev_domain __domains[MSI_MAX_DEVICE_IRQDOMAINS ];unsigned long __iter_idx; -unsigned long __iter_max; -struct irq_domain *__irqdomains[MSI_MAX_DEVICE_IRQDOMAINS ]; };int msi_setup_device_data (struct device *dev);
@@ -219,7 +226,8 @@ static inline struct msi_desc *msi_first_desc(struct device *dev,return msi_domain_first_desc (dev,MSI_DEFAULT_DOMAIN , filter); } -struct msi_desc *msi_next_desc (struct device *dev,enum msi_desc_filter filter); +struct msi_desc *msi_next_desc (struct device *dev,unsigned int domid, +enum msi_desc_filter filter);/** * msi_domain_for_each_desc - Iterate the MSI descriptors in a specific domain
@@ -236,7 +244,7 @@ struct msi_desc *msi_next_desc(struct device *dev, enum msi_desc_filter filter);*/ #define msi_domain_for_each_desc (desc, dev, domid, filter) \ for ((desc) = msi_domain_first_desc((dev), (domid), (filter)); (desc); \ - (desc) = msi_next_desc((dev), (filter))) + (desc) = msi_next_desc((dev), (domid), (filter)))/** * msi_for_each_desc - Iterate the MSI descriptors in the default irqdomain
kernel/irq/msi.c +68 -105
375 lines not on this page · raw message
PATCH v3 1/22 genirq/msi: Move IRQ_DOMAIN_MSI_NOMASK_QUIRK to MSI flags
It's truly a MSI only flag and for the upcoming per device MSI domains this must be in the MSI flags so it can be set during domain setup without exposing this quirk outside of x86.
--- arch/x86/kernel/apic/msi.c | 5 ++--- include/linux/irqdomain.h | 9 +-------- include/linux/msi.h | 6 ++++++ kernel/irq/msi.c | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-)
arch/x86/kernel/apic/msi.c +2 -3
@@ -176,7 +176,8 @@ static struct msi_domain_ops pci_msi_domstatic struct msi_domain_info pci_msi_domain_info = { .flags =MSI_FLAG_USE_DEF_DOM_OPS |MSI_FLAG_USE_DEF_CHIP_OPS | -MSI_FLAG_PCI_MSIX , +MSI_FLAG_PCI_MSIX |MSI_FLAG_NOMASK_QUIRK , + .ops = &pci_msi_domain_ops, .chip = &pci_msi_controller, .handler = handle_edge_irq,
@@ -200,8 +201,6 @@ struct irq_domain * __init native_createif (!d) {irq_domain_free_fwnode (fn);pr_warn ("Failed to initialize PCI-MSI irqdomain.\n" ); - }else { - d->flags |=IRQ_DOMAIN_MSI_NOMASK_QUIRK ; }return d; }
include/linux/irqdomain.h +1 -8
@@ -186,15 +186,8 @@ enum {/* Irq domain implements MSI remapping */ IRQ_DOMAIN_FLAG_MSI_REMAP = (1 <<5 ), -/* -* Quirk to handle MSI implementations which do not provide -* masking. Currently known to affect x86, but partially -* handled in core code. -*/ -IRQ_DOMAIN_MSI_NOMASK_QUIRK = (1 <<6 ), -/* Irq domain doesn't translate anything */ - IRQ_DOMAIN_FLAG_NO_MAP = (1 << 7), + IRQ_DOMAIN_FLAG_NO_MAP = (1 << 6),/* * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved
include/linux/msi.h +6 -0
@@ -399,6 +399,12 @@ enum {MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS = (1 <<9 ),/* Free MSI descriptors */ MSI_FLAG_FREE_MSI_DESCS = (1 <<10 ), +/* +* Quirk to handle MSI implementations which do not provide +* masking. Currently known to affect x86, but has to be partially +* handled in the core MSI code. +*/ + MSI_FLAG_NOMASK_QUIRK = (1 << 11), }; int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask,
kernel/irq/msi.c +1 -1
@@ -875,7 +875,7 @@ static int __msi_domain_alloc_irqs(struc* MSI affinity setting requires a special quirk (X86) when * reservation mode is active. */ -if (domain->flags &IRQ_DOMAIN_MSI_NOMASK_QUIRK ) +if (info->flags &MSI_FLAG_NOMASK_QUIRK ) vflags |=VIRQ_NOMASK_QUIRK ; }
[tip: irq/core] genirq/msi: Move IRQ_DOMAIN_MSI_NOMASK_QUIRK to MSI flags
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 3dad5f9ad99b77dfd234d31e2ea3d77f620efc09 Gitweb: https://git.kernel.org/tip/3dad5f9ad99b77dfd234d31e2ea3d77f620efc09 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:08 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:58 +01:00
genirq/msi: Move IRQ_DOMAIN_MSI_NOMASK_QUIRK to MSI flags
It's truly a MSI only flag and for the upcoming per device MSI domains this must be in the MSI flags so it can be set during domain setup without exposing this quirk outside of x86.
--- arch/x86/kernel/apic/msi.c | 5 ++--- include/linux/irqdomain.h | 9 +-------- include/linux/msi.h | 6 ++++++ kernel/irq/msi.c | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-)
arch/x86/kernel/apic/msi.c +2 -3
@@ -176,7 +176,8 @@ static struct msi_domain_ops pci_msi_domain_ops = {static struct msi_domain_info pci_msi_domain_info = { .flags =MSI_FLAG_USE_DEF_DOM_OPS |MSI_FLAG_USE_DEF_CHIP_OPS | -MSI_FLAG_PCI_MSIX , +MSI_FLAG_PCI_MSIX |MSI_FLAG_NOMASK_QUIRK , + .ops = &pci_msi_domain_ops, .chip = &pci_msi_controller, .handler = handle_edge_irq,
@@ -200,8 +201,6 @@ struct irq_domain * __init native_create_pci_msi_domain(void)if (!d) {irq_domain_free_fwnode (fn);pr_warn ("Failed to initialize PCI-MSI irqdomain.\n" ); - }else { - d->flags |=IRQ_DOMAIN_MSI_NOMASK_QUIRK ; }return d; }
include/linux/irqdomain.h +1 -8
@@ -186,15 +186,8 @@ enum {/* Irq domain implements MSI remapping */ IRQ_DOMAIN_FLAG_MSI_REMAP = (1 <<5 ), -/* -* Quirk to handle MSI implementations which do not provide -* masking. Currently known to affect x86, but partially -* handled in core code. -*/ -IRQ_DOMAIN_MSI_NOMASK_QUIRK = (1 <<6 ), -/* Irq domain doesn't translate anything */ - IRQ_DOMAIN_FLAG_NO_MAP = (1 << 7), + IRQ_DOMAIN_FLAG_NO_MAP = (1 << 6),/* * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved
include/linux/msi.h +6 -0
@@ -399,6 +399,12 @@ enum {MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS = (1 <<9 ),/* Free MSI descriptors */ MSI_FLAG_FREE_MSI_DESCS = (1 <<10 ), +/* +* Quirk to handle MSI implementations which do not provide +* masking. Currently known to affect x86, but has to be partially +* handled in the core MSI code. +*/ + MSI_FLAG_NOMASK_QUIRK = (1 << 11), }; int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask,
kernel/irq/msi.c +1 -1
@@ -875,7 +875,7 @@ static int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev* MSI affinity setting requires a special quirk (X86) when * reservation mode is active. */ -if (domain->flags &IRQ_DOMAIN_MSI_NOMASK_QUIRK ) +if (info->flags &MSI_FLAG_NOMASK_QUIRK ) vflags |=VIRQ_NOMASK_QUIRK ; }
PATCH v3 2/22 genirq/irqdomain: Make struct irqdomain readable
In reply to Thomas GleixnerTabular alignment of both kernel-doc and the actual struct declaration make visual parsing way more conveniant.
No functional change.
---
V2: Split out from the irqdomain::dev rename patch (Jason)
--- include/linux/irqdomain.h | 74 +++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 37 deletions(-)
include/linux/irqdomain.h +37 -37
@@ -117,53 +117,53 @@ struct irq_domain_chip_generic;/** * struct irq_domain - Hardware interrupt number translation object -* @link: Element in global irq_domain list. -* @name: Name of interrupt domain -* @ops: pointer to irq_domain methods -* @host_data: private data pointer for use by owner. Not touched by irq_domain -* core code. -* @flags: host per irq_domain flags -* @mapcount: The number of mapped interrupts +* @link: Element in global irq_domain list. +* @name: Name of interrupt domain +* @ops: Pointer to irq_domain methods +* @host_data: Private data pointer for use by owner. Not touched by irq_domain +* core code. +* @flags: Per irq_domain flags +* @mapcount: The number of mapped interrupts * -* Optional elements -* @fwnode: Pointer to firmware node associated with the irq_domain. Pretty easy -* to swap it for the of_node via the irq_domain_get_of_node accessor -* @gc: Pointer to a list of generic chips. There is a helper function for -* setting up one or more generic chips for interrupt controllers -* drivers using the generic chip library which uses this pointer. -* @dev: Pointer to a device that the domain represent, and that will be -* used for power management purposes. -* @parent: Pointer to parent irq_domain to support hierarchy irq_domains +* Optional elements: +* @fwnode: Pointer to firmware node associated with the irq_domain. Pretty easy +* to swap it for the of_node via the irq_domain_get_of_node accessor +* @gc: Pointer to a list of generic chips. There is a helper function for +* setting up one or more generic chips for interrupt controllers +* drivers using the generic chip library which uses this pointer. +* @dev: Pointer to a device that can be utilized for power management +* purposes related to the irq domain. +* @parent: Pointer to parent irq_domain to support hierarchy irq_domains * -* Revmap data, used internally by irq_domain -* @revmap_size: Size of the linear map table @revmap[] -* @revmap_tree: Radix map tree for hwirqs that don't fit in the linear map -* @revmap_mutex: Lock for the revmap -* @revmap: Linear table of irq_data pointers +* Revmap data, used internally by the irq domain code: +* @revmap_size: Size of the linear map table @revmap[] +* @revmap_tree: Radix map tree for hwirqs that don't fit in the linear map +* @revmap_mutex: Lock for the revmap +* @revmap: Linear table of irq_data pointers */ struct irq_domain { -struct list_head link; -const char *name; -const struct irq_domain_ops *ops; -void *host_data; -unsigned int flags; -unsigned int mapcount; +struct list_head link; +const char *name; +const struct irq_domain_ops *ops; +void *host_data; +unsigned int flags; +unsigned int mapcount;/* Optional data */ -struct fwnode_handle *fwnode; -enum irq_domain_bus_token bus_token; -struct irq_domain_chip_generic *gc; -struct device *dev; +struct fwnode_handle *fwnode; +enum irq_domain_bus_token bus_token; +struct irq_domain_chip_generic *gc; +struct device *dev;#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY -struct irq_domain *parent; +struct irq_domain *parent;#endif /* reverse map data. The linear map gets appended to the irq_domain */ -irq_hw_number_t hwirq_max; -unsigned int revmap_size; -struct radix_tree_root revmap_tree; -struct mutex revmap_mutex; -struct irq_data __rcu *revmap[]; +irq_hw_number_t hwirq_max; +unsigned int revmap_size; +struct radix_tree_root revmap_tree; +struct mutex revmap_mutex; +struct irq_data __rcu *revmap[]; };/* Irq domain flags */
[tip: irq/core] genirq/irqdomain: Make struct irqdomain readable
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: f876ea3b7969329d6472ae4126496bb03c89d89a Gitweb: https://git.kernel.org/tip/f876ea3b7969329d6472ae4126496bb03c89d89a Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:10 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:58 +01:00
genirq/irqdomain: Make struct irqdomain readable
Tabular alignment of both kernel-doc and the actual struct declaration make visual parsing way more conveniant.
No functional change.
--- include/linux/irqdomain.h | 74 +++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 37 deletions(-)
include/linux/irqdomain.h +37 -37
@@ -117,53 +117,53 @@ struct irq_domain_chip_generic;/** * struct irq_domain - Hardware interrupt number translation object -* @link: Element in global irq_domain list. -* @name: Name of interrupt domain -* @ops: pointer to irq_domain methods -* @host_data: private data pointer for use by owner. Not touched by irq_domain -* core code. -* @flags: host per irq_domain flags -* @mapcount: The number of mapped interrupts +* @link: Element in global irq_domain list. +* @name: Name of interrupt domain +* @ops: Pointer to irq_domain methods +* @host_data: Private data pointer for use by owner. Not touched by irq_domain +* core code. +* @flags: Per irq_domain flags +* @mapcount: The number of mapped interrupts * -* Optional elements -* @fwnode: Pointer to firmware node associated with the irq_domain. Pretty easy -* to swap it for the of_node via the irq_domain_get_of_node accessor -* @gc: Pointer to a list of generic chips. There is a helper function for -* setting up one or more generic chips for interrupt controllers -* drivers using the generic chip library which uses this pointer. -* @dev: Pointer to a device that the domain represent, and that will be -* used for power management purposes. -* @parent: Pointer to parent irq_domain to support hierarchy irq_domains +* Optional elements: +* @fwnode: Pointer to firmware node associated with the irq_domain. Pretty easy +* to swap it for the of_node via the irq_domain_get_of_node accessor +* @gc: Pointer to a list of generic chips. There is a helper function for +* setting up one or more generic chips for interrupt controllers +* drivers using the generic chip library which uses this pointer. +* @dev: Pointer to a device that can be utilized for power management +* purposes related to the irq domain. +* @parent: Pointer to parent irq_domain to support hierarchy irq_domains * -* Revmap data, used internally by irq_domain -* @revmap_size: Size of the linear map table @revmap[] -* @revmap_tree: Radix map tree for hwirqs that don't fit in the linear map -* @revmap_mutex: Lock for the revmap -* @revmap: Linear table of irq_data pointers +* Revmap data, used internally by the irq domain code: +* @revmap_size: Size of the linear map table @revmap[] +* @revmap_tree: Radix map tree for hwirqs that don't fit in the linear map +* @revmap_mutex: Lock for the revmap +* @revmap: Linear table of irq_data pointers */ struct irq_domain { -struct list_head link; -const char *name; -const struct irq_domain_ops *ops; -void *host_data; -unsigned int flags; -unsigned int mapcount; +struct list_head link; +const char *name; +const struct irq_domain_ops *ops; +void *host_data; +unsigned int flags; +unsigned int mapcount;/* Optional data */ -struct fwnode_handle *fwnode; -enum irq_domain_bus_token bus_token; -struct irq_domain_chip_generic *gc; -struct device *dev; +struct fwnode_handle *fwnode; +enum irq_domain_bus_token bus_token; +struct irq_domain_chip_generic *gc; +struct device *dev;#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY -struct irq_domain *parent; +struct irq_domain *parent;#endif /* reverse map data. The linear map gets appended to the irq_domain */ -irq_hw_number_t hwirq_max; -unsigned int revmap_size; -struct radix_tree_root revmap_tree; -struct mutex revmap_mutex; -struct irq_data __rcu *revmap[]; +irq_hw_number_t hwirq_max; +unsigned int revmap_size; +struct radix_tree_root revmap_tree; +struct mutex revmap_mutex; +struct irq_data __rcu *revmap[]; };/* Irq domain flags */
PATCH v3 3/22 genirq/irqdomain: Rename irq_domain::dev to irq_domain::pm_dev
In reply to Thomas Gleixnerirq_domain::dev is a misnomer as it's usually the rule that a device pointer points to something which is directly related to the instance.
irq_domain::dev can point to some other device for power management to ensure that this underlying device is not powered down when an interrupt is allocated.
The upcoming per device MSI domains really require a pointer to the device which instantiated the irq domain and not to some random other device which is required for power management down the chain.
Rename irq_domain::dev to irq_domain::pm_dev and fixup the few sites which use that pointer.
Conversion was done with the help of coccinelle.
--- drivers/irqchip/irq-gic.c | 4 ++-- include/linux/irqdomain.h | 6 +++--- kernel/irq/chip.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/irqchip/irq-gic.c +2 -2
@@ -401,8 +401,8 @@ static void gic_irq_print_chip(struct ir {struct gic_chip_data *gic =irq_data_get_irq_chip_data (d); -if (gic->domain->dev) -seq_printf (p, gic->domain->dev->of_node->name); +if (gic->domain->pm_dev) +seq_printf (p, gic->domain->pm_dev->of_node->name);else seq_printf (p,"GIC-%d" , (int )(gic - &gic_data[0 ])); }
include/linux/irqdomain.h +3 -3
@@ -131,7 +131,7 @@ struct irq_domain_chip_generic;* @gc: Pointer to a list of generic chips. There is a helper function for * setting up one or more generic chips for interrupt controllers * drivers using the generic chip library which uses this pointer. -* @dev: Pointer to a device that can be utilized for power management +* @pm_dev: Pointer to a device that can be utilized for power management * purposes related to the irq domain. * @parent: Pointer to parent irq_domain to support hierarchy irq_domains *
@@ -153,7 +153,7 @@ struct irq_domain {struct fwnode_handle *fwnode;enum irq_domain_bus_token bus_token;struct irq_domain_chip_generic *gc; -struct device *dev; +struct device *pm_dev;#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY struct irq_domain *parent;#endif
@@ -206,7 +206,7 @@ static inline void irq_domain_set_pm_dev struct device *dev) {if (d) - d->dev = dev; + d->pm_dev = dev; }#ifdef CONFIG_IRQ_DOMAIN
kernel/irq/chip.c +4 -4
@@ -1561,10 +1561,10 @@ int irq_chip_compose_msi_msg(struct irq_return 0 ; } -static struct device *irq_get_parent_device (struct irq_data *data) +static struct device *irq_get_pm_device (struct irq_data *data) {if (data->domain) -return data->domain->dev; +return data->domain->pm_dev;return NULL ; }
@@ -1578,7 +1578,7 @@ static struct device *irq_get_parent_dev*/ int irq_chip_pm_get (struct irq_data *data) { -struct device *dev =irq_get_parent_device (data); +struct device *dev =irq_get_pm_device (data);int retval =0 ;if (IS_ENABLED (CONFIG_PM ) && dev)
@@ -1597,7 +1597,7 @@ int irq_chip_pm_get(struct irq_data *dat*/ int irq_chip_pm_put (struct irq_data *data) { -struct device *dev =irq_get_parent_device (data); +struct device *dev =irq_get_pm_device (data);int retval =0 ;if (IS_ENABLED (CONFIG_PM ) && dev)
[tip: irq/core] genirq/irqdomain: Rename irq_domain::dev to irq_domain:: Pm_dev
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 6a9fc4190ca23fcf327de666e1a98dbdcdd2d210 Gitweb: https://git.kernel.org/tip/6a9fc4190ca23fcf327de666e1a98dbdcdd2d210 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:12 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:58 +01:00
genirq/irqdomain: Rename irq_domain::dev to irq_domain:: Pm_dev
irq_domain::dev is a misnomer as it's usually the rule that a device pointer points to something which is directly related to the instance.
irq_domain::dev can point to some other device for power management to ensure that this underlying device is not powered down when an interrupt is allocated.
The upcoming per device MSI domains really require a pointer to the device which instantiated the irq domain and not to some random other device which is required for power management down the chain.
Rename irq_domain::dev to irq_domain::pm_dev and fixup the few sites which use that pointer.
Conversion was done with the help of coccinelle.
--- drivers/irqchip/irq-gic.c | 4 ++-- include/linux/irqdomain.h | 6 +++--- kernel/irq/chip.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/irqchip/irq-gic.c +2 -2
@@ -401,8 +401,8 @@ static void gic_irq_print_chip(struct irq_data *d, struct seq_file *p) {struct gic_chip_data *gic =irq_data_get_irq_chip_data (d); -if (gic->domain->dev) -seq_printf (p, gic->domain->dev->of_node->name); +if (gic->domain->pm_dev) +seq_printf (p, gic->domain->pm_dev->of_node->name);else seq_printf (p,"GIC-%d" , (int )(gic - &gic_data[0 ])); }
include/linux/irqdomain.h +3 -3
@@ -131,7 +131,7 @@ struct irq_domain_chip_generic;* @gc: Pointer to a list of generic chips. There is a helper function for * setting up one or more generic chips for interrupt controllers * drivers using the generic chip library which uses this pointer. -* @dev: Pointer to a device that can be utilized for power management +* @pm_dev: Pointer to a device that can be utilized for power management * purposes related to the irq domain. * @parent: Pointer to parent irq_domain to support hierarchy irq_domains *
@@ -153,7 +153,7 @@ struct irq_domain {struct fwnode_handle *fwnode;enum irq_domain_bus_token bus_token;struct irq_domain_chip_generic *gc; -struct device *dev; +struct device *pm_dev;#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY struct irq_domain *parent;#endif
@@ -206,7 +206,7 @@ static inline void irq_domain_set_pm_device(struct irq_domain *d, struct device *dev) {if (d) - d->dev = dev; + d->pm_dev = dev; }#ifdef CONFIG_IRQ_DOMAIN
kernel/irq/chip.c +4 -4
@@ -1561,10 +1561,10 @@ int irq_chip_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)return 0 ; } -static struct device *irq_get_parent_device (struct irq_data *data) +static struct device *irq_get_pm_device (struct irq_data *data) {if (data->domain) -return data->domain->dev; +return data->domain->pm_dev;return NULL ; }
@@ -1578,7 +1578,7 @@ static struct device *irq_get_parent_device(struct irq_data *data)*/ int irq_chip_pm_get (struct irq_data *data) { -struct device *dev =irq_get_parent_device (data); +struct device *dev =irq_get_pm_device (data);int retval =0 ;if (IS_ENABLED (CONFIG_PM ) && dev)
@@ -1597,7 +1597,7 @@ int irq_chip_pm_get(struct irq_data *data)*/ int irq_chip_pm_put (struct irq_data *data) { -struct device *dev =irq_get_parent_device (data); +struct device *dev =irq_get_pm_device (data);int retval =0 ;if (IS_ENABLED (CONFIG_PM ) && dev)
PATCH v3 4/22 genirq/msi: Create msi_api.h
In reply to Thomas GleixnerCreate a API header for MSI specific functions which are relevant to device drivers.
--- include/linux/msi.h | 6 ++++-- include/linux/msi_api.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-)
include/linux/msi.h +4 -2
@@ -13,11 +13,14 @@* * Regular device drivers have no business with any of these functions and * especially storing MSI descriptor pointers in random code is considered -* abuse. The only function which is relevant for drivers is msi_get_virq(). +* abuse. +* +* Device driver relevant functions are available in <linux/msi_api.h> */ #include <linux/irqdomain_defs.h> #include <linux/cpumask.h> +#include <linux/msi_api.h> #include <linux/xarray.h> #include <linux/mutex.h> #include <linux/list.h>
@@ -188,7 +191,6 @@ struct msi_device_data {int msi_setup_device_data (struct device *dev); -unsigned int msi_get_virq (struct device *dev,unsigned int index);void msi_lock_descs (struct device *dev);void msi_unlock_descs (struct device *dev);
include/linux/msi_api.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef LINUX_MSI_API_H +#define LINUX_MSI_API_H + +/* +* APIs which are relevant for device driver code for allocating and +* freeing MSI interrupts and querying the associations between +* hardware/software MSI indices and the Linux interrupt number. +*/ + +struct device ; + +unsigned int msi_get_virq (struct device *dev,unsigned int index); + +#endif
[tip: irq/core] genirq/msi: Create msi_api.h
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 6b6941f6653ec8017e3822b55bb9eae245f0ed99 Gitweb: https://git.kernel.org/tip/6b6941f6653ec8017e3822b55bb9eae245f0ed99 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:14 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:58 +01:00
genirq/msi: Create msi_api.h
Create a API header for MSI specific functions which are relevant to device drivers.
--- include/linux/msi.h | 6 ++++-- include/linux/msi_api.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 include/linux/msi_api.h
include/linux/msi.h +4 -2
@@ -13,11 +13,14 @@* * Regular device drivers have no business with any of these functions and * especially storing MSI descriptor pointers in random code is considered -* abuse. The only function which is relevant for drivers is msi_get_virq(). +* abuse. +* +* Device driver relevant functions are available in <linux/msi_api.h> */ #include <linux/irqdomain_defs.h> #include <linux/cpumask.h> +#include <linux/msi_api.h> #include <linux/xarray.h> #include <linux/mutex.h> #include <linux/list.h>
@@ -188,7 +191,6 @@ struct msi_device_data {int msi_setup_device_data (struct device *dev); -unsigned int msi_get_virq (struct device *dev,unsigned int index);void msi_lock_descs (struct device *dev);void msi_unlock_descs (struct device *dev);
include/linux/msi_api.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef LINUX_MSI_API_H +#define LINUX_MSI_API_H + +/* +* APIs which are relevant for device driver code for allocating and +* freeing MSI interrupts and querying the associations between +* hardware/software MSI indices and the Linux interrupt number. +*/ + +struct device ; + +unsigned int msi_get_virq (struct device *dev,unsigned int index); + +#endif
PATCH v3 5/22 genirq/irqdomain: Provide IRQ_DOMAIN_FLAG_MSI_PARENT
In reply to Thomas GleixnerThe new PCI/IMS (Interrupt Message Store) functionality is allowing hardware vendors to provide implementation specific storage for the MSI messages. This can be device memory and also host/guest memory, e.g. in queue memory which is shared with the hardware.
This requires device specific MSI interrupt domains, which cannot be achieved by expanding the existing PCI/MSI interrupt domain concept which is a global interrupt domain shared by all PCI devices on a particular (IOMMU) segment:
|--- device 1
[Vector]---[Remapping]---[PCI/MSI]--|...
|--- device NThis works because the PCI/MSI[-X] space is uniform, but falls apart with PCI/IMS which is implementation defined and must be available along with PCI/MSI[-X] on the same device.
To support PCI/MSI[-X] plus PCI/IMS on the same device it is required to rework the PCI/MSI interrupt domain hierarchy concept in the following way:
|--- [PCI/MSI] device 1
[Vector]---[Remapping]---|...
|--- [PCI/MSI] device NThat allows in the next step to create multiple interrupt domains per device:
|--- [PCI/MSI] device 1
|--- [PCI/IMS] device 1
[Vector]---[Remapping]---|...
|--- [PCI/MSI] device N
|--- [PCI/IMS] device NSo the domain which previously created the global PCI/MSI domain must now act as parent domain for the per device domains.
The hierarchy depth is the same as before, but the PCI/MSI domains are then device specific and not longer global.
Provide IRQ_DOMAIN_FLAG_MSI_PARENT, which allows to identify these parent domains, along with helpers to query it.
--- include/linux/irqdomain.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/linux/irqdomain.h +14 -0
@@ -189,6 +189,9 @@ enum {/* Irq domain doesn't translate anything */ IRQ_DOMAIN_FLAG_NO_MAP = (1 <<6 ), +/* Irq domain is a MSI parent domain */ + IRQ_DOMAIN_FLAG_MSI_PARENT = (1 << 8), +/* * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved * for implementation specific purposes and ignored by the
@@ -551,6 +554,11 @@ static inline bool irq_domain_is_msi_remextern bool irq_domain_hierarchical_is_msi_remap (struct irq_domain *domain); +static inline bool irq_domain_is_msi_parent (struct irq_domain *domain) +{ +return domain->flags &IRQ_DOMAIN_FLAG_MSI_PARENT ; +} +#else /* CONFIG_IRQ_DOMAIN_HIERARCHY */ static inline int irq_domain_alloc_irqs (struct irq_domain *domain,unsigned int nr_irqs,int node,void *arg)
@@ -596,6 +604,12 @@ irq_domain_hierarchical_is_msi_remap(str {return false; } + +static inline bool irq_domain_is_msi_parent (struct irq_domain *domain) +{ +return false; +} +#endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ #else /* CONFIG_IRQ_DOMAIN */
[tip: irq/core] genirq/irqdomain: Provide IRQ_DOMAIN_FLAG_MSI_PARENT
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: b749e6d31c88cff2202b968aaba246e5d7379038 Gitweb: https://git.kernel.org/tip/b749e6d31c88cff2202b968aaba246e5d7379038 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:15 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:58 +01:00
genirq/irqdomain: Provide IRQ_DOMAIN_FLAG_MSI_PARENT
The new PCI/IMS (Interrupt Message Store) functionality is allowing hardware vendors to provide implementation specific storage for the MSI messages. This can be device memory and also host/guest memory, e.g. in queue memory which is shared with the hardware.
This requires device specific MSI interrupt domains, which cannot be achieved by expanding the existing PCI/MSI interrupt domain concept which is a global interrupt domain shared by all PCI devices on a particular (IOMMU) segment:
|--- device 1
[Vector]---[Remapping]---[PCI/MSI]--|...
|--- device NThis works because the PCI/MSI[-X] space is uniform, but falls apart with PCI/IMS which is implementation defined and must be available along with PCI/MSI[-X] on the same device.
To support PCI/MSI[-X] plus PCI/IMS on the same device it is required to rework the PCI/MSI interrupt domain hierarchy concept in the following way:
|--- [PCI/MSI] device 1
[Vector]---[Remapping]---|...
|--- [PCI/MSI] device NThat allows in the next step to create multiple interrupt domains per device:
|--- [PCI/MSI] device 1
|--- [PCI/IMS] device 1
[Vector]---[Remapping]---|...
|--- [PCI/MSI] device N
|--- [PCI/IMS] device NSo the domain which previously created the global PCI/MSI domain must now act as parent domain for the per device domains.
The hierarchy depth is the same as before, but the PCI/MSI domains are then device specific and not longer global.
Provide IRQ_DOMAIN_FLAG_MSI_PARENT, which allows to identify these parent domains, along with helpers to query it.
--- include/linux/irqdomain.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/linux/irqdomain.h +14 -0
@@ -189,6 +189,9 @@ enum {/* Irq domain doesn't translate anything */ IRQ_DOMAIN_FLAG_NO_MAP = (1 <<6 ), +/* Irq domain is a MSI parent domain */ + IRQ_DOMAIN_FLAG_MSI_PARENT = (1 << 8), +/* * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved * for implementation specific purposes and ignored by the
@@ -551,6 +554,11 @@ static inline bool irq_domain_is_msi_remap(struct irq_domain *domain)extern bool irq_domain_hierarchical_is_msi_remap (struct irq_domain *domain); +static inline bool irq_domain_is_msi_parent (struct irq_domain *domain) +{ +return domain->flags &IRQ_DOMAIN_FLAG_MSI_PARENT ; +} +#else /* CONFIG_IRQ_DOMAIN_HIERARCHY */ static inline int irq_domain_alloc_irqs (struct irq_domain *domain,unsigned int nr_irqs,int node,void *arg)
@@ -596,6 +604,12 @@ irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain) {return false; } + +static inline bool irq_domain_is_msi_parent (struct irq_domain *domain) +{ +return false; +} +#endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ #else /* CONFIG_IRQ_DOMAIN */
PATCH v3 6/22 genirq/irqdomain: Provide IRQ_DOMAIN_FLAG_MSI_DEVICE
In reply to Thomas GleixnerSimilar to marking parent MSI domains it's required to identify per device domains. Add flag and helpers.
--- include/linux/irqdomain.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/irqdomain.h +13 -0
@@ -192,6 +192,9 @@ enum {/* Irq domain is a MSI parent domain */ IRQ_DOMAIN_FLAG_MSI_PARENT = (1 <<8 ), +/* Irq domain is a MSI device domain */ + IRQ_DOMAIN_FLAG_MSI_DEVICE = (1 << 9), +/* * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved * for implementation specific purposes and ignored by the
@@ -559,6 +562,11 @@ static inline bool irq_domain_is_msi_par return domain->flags & IRQ_DOMAIN_FLAG_MSI_PARENT; } +static inline bool irq_domain_is_msi_device (struct irq_domain *domain) +{ +return domain->flags &IRQ_DOMAIN_FLAG_MSI_DEVICE ; +} +#else /* CONFIG_IRQ_DOMAIN_HIERARCHY */ static inline int irq_domain_alloc_irqs (struct irq_domain *domain,unsigned int nr_irqs,int node,void *arg)
@@ -609,6 +617,11 @@ static inline bool irq_domain_is_msi_par {return false; } + +static inline bool irq_domain_is_msi_device (struct irq_domain *domain) +{ +return false; +}#endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */
[tip: irq/core] genirq/irqdomain: Provide IRQ_DOMAIN_FLAG_MSI_DEVICE
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: e71c5d0bb1885b73c746b634895b85d135ce2c87 Gitweb: https://git.kernel.org/tip/e71c5d0bb1885b73c746b634895b85d135ce2c87 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:17 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:58 +01:00
genirq/irqdomain: Provide IRQ_DOMAIN_FLAG_MSI_DEVICE
Similar to marking parent MSI domains it's required to identify per device domains. Add flag and helpers.
--- include/linux/irqdomain.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/irqdomain.h +13 -0
@@ -192,6 +192,9 @@ enum {/* Irq domain is a MSI parent domain */ IRQ_DOMAIN_FLAG_MSI_PARENT = (1 <<8 ), +/* Irq domain is a MSI device domain */ + IRQ_DOMAIN_FLAG_MSI_DEVICE = (1 << 9), +/* * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved * for implementation specific purposes and ignored by the
@@ -559,6 +562,11 @@ static inline bool irq_domain_is_msi_parent(struct irq_domain *domain) return domain->flags & IRQ_DOMAIN_FLAG_MSI_PARENT; } +static inline bool irq_domain_is_msi_device (struct irq_domain *domain) +{ +return domain->flags &IRQ_DOMAIN_FLAG_MSI_DEVICE ; +} +#else /* CONFIG_IRQ_DOMAIN_HIERARCHY */ static inline int irq_domain_alloc_irqs (struct irq_domain *domain,unsigned int nr_irqs,int node,void *arg)
@@ -610,6 +618,11 @@ static inline bool irq_domain_is_msi_parent(struct irq_domain *domain) return false; } +static inline bool irq_domain_is_msi_device (struct irq_domain *domain) +{ +return false; +} +#endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ #else /* CONFIG_IRQ_DOMAIN */
PATCH v3 7/22 genirq/msi: Check for invalid MSI parent domain usage
In reply to Thomas GleixnerIn the upcoming per device MSI domain concept the MSI parent domains are not allowed to be used as regular MSI domains where the MSI allocation/free operations are applicable.
Add appropriate checks.
---
V2: Made the error return understandable. (Kevin)
--- kernel/irq/msi.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
kernel/irq/msi.c +14 -3
@@ -937,13 +937,21 @@ int msi_domain_alloc_irqs_descs_locked(slockdep_assert_held (&dev->msi.data->mutex); +if (WARN_ON_ONCE (irq_domain_is_msi_parent (domain))) { + ret = -EINVAL ; + goto free; + } + +/* Frees allocated descriptors in case of failure. */ ret =msi_domain_add_simple_msi_descs (info, dev, nvec);if (ret) -return ret; + goto free; ret = ops->domain_alloc_irqs (domain, dev, nvec); -if (ret) -msi_domain_free_irqs_descs_locked (domain, dev); +if (!ret) +return 0 ; +free: +msi_domain_free_irqs_descs_locked (domain, dev);return ret; }
@@ -1013,6 +1021,9 @@ void msi_domain_free_irqs_descs_locked(slockdep_assert_held (&dev->msi.data->mutex); +if (WARN_ON_ONCE (irq_domain_is_msi_parent (domain))) +return ; + ops->domain_free_irqs (domain, dev);if (ops->msi_post_free) ops->msi_post_free (domain, dev);
[tip: irq/core] genirq/msi: Check for invalid MSI parent domain usage
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 3e86a3a3ed031dd498e614db0fa082a58d700df9 Gitweb: https://git.kernel.org/tip/3e86a3a3ed031dd498e614db0fa082a58d700df9 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:19 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:59 +01:00
genirq/msi: Check for invalid MSI parent domain usage
In the upcoming per device MSI domain concept the MSI parent domains are not allowed to be used as regular MSI domains where the MSI allocation/free operations are applicable.
Add appropriate checks.
--- kernel/irq/msi.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
kernel/irq/msi.c +14 -3
@@ -937,13 +937,21 @@ int msi_domain_alloc_irqs_descs_locked(struct irq_domain *domain, struct devicelockdep_assert_held (&dev->msi.data->mutex); +if (WARN_ON_ONCE (irq_domain_is_msi_parent (domain))) { + ret = -EINVAL ; + goto free; + } + +/* Frees allocated descriptors in case of failure. */ ret =msi_domain_add_simple_msi_descs (info, dev, nvec);if (ret) -return ret; + goto free; ret = ops->domain_alloc_irqs (domain, dev, nvec); -if (ret) -msi_domain_free_irqs_descs_locked (domain, dev); +if (!ret) +return 0 ; +free: +msi_domain_free_irqs_descs_locked (domain, dev);return ret; }
@@ -1013,6 +1021,9 @@ void msi_domain_free_irqs_descs_locked(struct irq_domain *domain, struct devicelockdep_assert_held (&dev->msi.data->mutex); +if (WARN_ON_ONCE (irq_domain_is_msi_parent (domain))) +return ; + ops->domain_free_irqs (domain, dev);if (ops->msi_post_free) ops->msi_post_free (domain, dev);
PATCH v3 8/22 genirq/msi: Move xarray into a separate struct and create an array
In reply to Thomas GleixnerThe upcoming support for multiple MSI domains per device requires storage for the MSI descriptors and in a second step storage for the irqdomain pointers.
Move the xarray into a separate data structure msi_dev_domain and create an array with size 1 in msi_device_data, which can be expanded later when the support for per device domains is implemented.
---
V3: New patch to avoid the segmentation of the xarray (Marc)
--- include/linux/msi.h | 13 +++++++++++-- include/linux/msi_api.h | 8 ++++++++ kernel/irq/msi.c | 32 ++++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 12 deletions(-)
include/linux/msi.h +11 -2
@@ -173,19 +173,28 @@ enum msi_desc_filter { MSI_DESC_ASSOCIATED, }; + +/** +* struct msi_dev_domain - The internals of MSI domain info per device +* @store: Xarray for storing MSI descriptor pointers +*/ +struct msi_dev_domain { +struct xarray store; +}; +/** * msi_device_data - MSI per device data * @properties: MSI properties which are interesting to drivers * @platform_data: Platform-MSI specific data * @mutex: Mutex protecting the MSI descriptor store -* @__store: Xarray for storing MSI descriptor pointers +* @__domains: Internal data for per device MSI domains * @__iter_idx: Index to search the next entry for iterators */ struct msi_device_data {unsigned long properties;struct platform_msi_priv_data *platform_data;struct mutex mutex; -struct xarray __store; +struct msi_dev_domain __domains[MSI_MAX_DEVICE_IRQDOMAINS ];unsigned long __iter_idx; };
include/linux/msi_api.h +8 -0
@@ -10,6 +10,14 @@struct device ; +/* +* Per device interrupt domain related constants. +*/ +enum msi_domain_ids { +MSI_DEFAULT_DOMAIN , +MSI_MAX_DEVICE_IRQDOMAINS , +}; +unsigned int msi_get_virq (struct device *dev,unsigned int index);#endif
kernel/irq/msi.c +22 -10
@@ -60,10 +60,11 @@ static void msi_free_desc(struct msi_desstatic int msi_insert_desc (struct msi_device_data *md,struct msi_desc *desc,unsigned int index) { +struct xarray *xa = &md->__domains[MSI_DEFAULT_DOMAIN ].store;int ret; desc->msi_index = index; - ret =xa_insert (&md->__store, index, desc,GFP_KERNEL ); + ret =xa_insert (xa, index, desc,GFP_KERNEL );if (ret)msi_free_desc (desc);return ret;
@@ -147,7 +148,7 @@ static bool msi_desc_match(struct msi_devoid msi_free_msi_descs_range (struct device *dev,unsigned int first_index,unsigned int last_index) { -struct xarray *xa = &dev->msi.data->__store; +struct xarray *xa = &dev->msi.data->__domains[MSI_DEFAULT_DOMAIN ].store;struct msi_desc *desc;unsigned long idx;
@@ -179,9 +180,12 @@ EXPORT_SYMBOL_GPL(get_cached_msi_msg);static void msi_device_data_release (struct device *dev,void *res) {struct msi_device_data *md = res; +int i; -WARN_ON_ONCE (!xa_empty (&md->__store)); -xa_destroy (&md->__store); +for (i =0 ; i <MSI_MAX_DEVICE_IRQDOMAINS ; i++) { +WARN_ON_ONCE (!xa_empty (&md->__domains[i].store)); +xa_destroy (&md->__domains[i].store); + } dev->msi.data =NULL ; }
@@ -198,7 +202,7 @@ static void msi_device_data_release(struint msi_setup_device_data (struct device *dev) {struct msi_device_data *md; -int ret; +int ret, i;if (dev->msi.data)return 0 ;
@@ -213,7 +217,9 @@ int msi_setup_device_data(struct devicereturn ret; } -xa_init (&md->__store); +for (i =0 ; i <MSI_MAX_DEVICE_IRQDOMAINS ; i++) +xa_init (&md->__domains[i].store); +mutex_init (&md->mutex); dev->msi.data = md;devres_add (dev, md);
@@ -236,7 +242,7 @@ EXPORT_SYMBOL_GPL(msi_lock_descs);*/ void msi_unlock_descs (struct device *dev) { -/* Invalidate the index wich was cached by the iterator */ +/* Invalidate the index which was cached by the iterator */ dev->msi.data->__iter_idx =MSI_MAX_INDEX ;mutex_unlock (&dev->msi.data->mutex); }
@@ -244,9 +250,10 @@ EXPORT_SYMBOL_GPL(msi_unlock_descs);static struct msi_desc *msi_find_desc (struct msi_device_data *md,enum msi_desc_filter filter) { +struct xarray *xa = &md->__domains[MSI_DEFAULT_DOMAIN ].store;struct msi_desc *desc; -xa_for_each_start (&md->__store, md->__iter_idx, desc, md->__iter_idx) { +xa_for_each_start (xa, md->__iter_idx, desc, md->__iter_idx) {if (msi_desc_match (desc, filter))return desc; }
@@ -320,6 +327,7 @@ unsigned int msi_get_virq(struct device {struct msi_desc *desc;unsigned int ret =0 ; +struct xarray *xa;bool pcimsi;if (!dev->msi.data)
@@ -328,7 +336,8 @@ unsigned int msi_get_virq(struct device pcimsi =dev_is_pci (dev) ?to_pci_dev (dev)->msi_enabled : false;msi_lock_descs (dev); - desc =xa_load (&dev->msi.data->__store, pcimsi ?0 : index); + xa = &dev->msi.data->__domains[MSI_DEFAULT_DOMAIN ].store; + desc =xa_load (xa, pcimsi ?0 : index);if (desc && desc->irq) {/* * PCI-MSI has only one descriptor for multiple interrupts.
@@ -707,6 +716,7 @@ int msi_domain_populate_irqs(struct irq_struct msi_domain_info *info = domain->host_data;struct msi_domain_ops *ops = info->ops;struct msi_desc *desc; +struct xarray *xa;int ret, virq;msi_lock_descs (dev);
@@ -714,8 +724,10 @@ int msi_domain_populate_irqs(struct irq_if (ret) goto unlock; + xa = &dev->msi.data->__domains[MSI_DEFAULT_DOMAIN ].store; +for (virq = virq_base; virq < virq_base + nvec; virq++) { - desc =xa_load (&dev->msi.data->__store, virq); + desc =xa_load (xa, virq); desc->irq = virq; ops->set_desc (arg, desc);
[tip: irq/core] genirq/msi: Move xarray into a separate struct and create an array
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: f1139f905bd2d8bec59be0c1404b592279ae0ac9 Gitweb: https://git.kernel.org/tip/f1139f905bd2d8bec59be0c1404b592279ae0ac9 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:20 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:59 +01:00
genirq/msi: Move xarray into a separate struct and create an array
The upcoming support for multiple MSI domains per device requires storage for the MSI descriptors and in a second step storage for the irqdomain pointers.
Move the xarray into a separate data structure msi_dev_domain and create an array with size 1 in msi_device_data, which can be expanded later when the support for per device domains is implemented.
--- include/linux/msi.h | 13 +++++++++++-- include/linux/msi_api.h | 8 ++++++++ kernel/irq/msi.c | 32 ++++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 12 deletions(-)
include/linux/msi.h +11 -2
@@ -173,19 +173,28 @@ enum msi_desc_filter { MSI_DESC_ASSOCIATED, }; + +/** +* struct msi_dev_domain - The internals of MSI domain info per device +* @store: Xarray for storing MSI descriptor pointers +*/ +struct msi_dev_domain { +struct xarray store; +}; +/** * msi_device_data - MSI per device data * @properties: MSI properties which are interesting to drivers * @platform_data: Platform-MSI specific data * @mutex: Mutex protecting the MSI descriptor store -* @__store: Xarray for storing MSI descriptor pointers +* @__domains: Internal data for per device MSI domains * @__iter_idx: Index to search the next entry for iterators */ struct msi_device_data {unsigned long properties;struct platform_msi_priv_data *platform_data;struct mutex mutex; -struct xarray __store; +struct msi_dev_domain __domains[MSI_MAX_DEVICE_IRQDOMAINS ];unsigned long __iter_idx; };
include/linux/msi_api.h +8 -0
@@ -10,6 +10,14 @@struct device ; +/* +* Per device interrupt domain related constants. +*/ +enum msi_domain_ids { +MSI_DEFAULT_DOMAIN , +MSI_MAX_DEVICE_IRQDOMAINS , +}; +unsigned int msi_get_virq (struct device *dev,unsigned int index);#endif
kernel/irq/msi.c +22 -10
@@ -60,10 +60,11 @@ static void msi_free_desc(struct msi_desc *desc)static int msi_insert_desc (struct msi_device_data *md,struct msi_desc *desc,unsigned int index) { +struct xarray *xa = &md->__domains[MSI_DEFAULT_DOMAIN ].store;int ret; desc->msi_index = index; - ret =xa_insert (&md->__store, index, desc,GFP_KERNEL ); + ret =xa_insert (xa, index, desc,GFP_KERNEL );if (ret)msi_free_desc (desc);return ret;
@@ -147,7 +148,7 @@ static bool msi_desc_match(struct msi_desc *desc, enum msi_desc_filter filter)void msi_free_msi_descs_range (struct device *dev,unsigned int first_index,unsigned int last_index) { -struct xarray *xa = &dev->msi.data->__store; +struct xarray *xa = &dev->msi.data->__domains[MSI_DEFAULT_DOMAIN ].store;struct msi_desc *desc;unsigned long idx;
@@ -179,9 +180,12 @@ EXPORT_SYMBOL_GPL(get_cached_msi_msg);static void msi_device_data_release (struct device *dev,void *res) {struct msi_device_data *md = res; +int i; -WARN_ON_ONCE (!xa_empty (&md->__store)); -xa_destroy (&md->__store); +for (i =0 ; i <MSI_MAX_DEVICE_IRQDOMAINS ; i++) { +WARN_ON_ONCE (!xa_empty (&md->__domains[i].store)); +xa_destroy (&md->__domains[i].store); + } dev->msi.data =NULL ; }
@@ -198,7 +202,7 @@ static void msi_device_data_release(struct device *dev, void *res)int msi_setup_device_data (struct device *dev) {struct msi_device_data *md; -int ret; +int ret, i;if (dev->msi.data)return 0 ;
@@ -213,7 +217,9 @@ int msi_setup_device_data(struct device *dev)return ret; } -xa_init (&md->__store); +for (i =0 ; i <MSI_MAX_DEVICE_IRQDOMAINS ; i++) +xa_init (&md->__domains[i].store); +mutex_init (&md->mutex); dev->msi.data = md;devres_add (dev, md);
@@ -236,7 +242,7 @@ EXPORT_SYMBOL_GPL(msi_lock_descs);*/ void msi_unlock_descs (struct device *dev) { -/* Invalidate the index wich was cached by the iterator */ +/* Invalidate the index which was cached by the iterator */ dev->msi.data->__iter_idx =MSI_MAX_INDEX ;mutex_unlock (&dev->msi.data->mutex); }
@@ -244,9 +250,10 @@ EXPORT_SYMBOL_GPL(msi_unlock_descs);static struct msi_desc *msi_find_desc (struct msi_device_data *md,enum msi_desc_filter filter) { +struct xarray *xa = &md->__domains[MSI_DEFAULT_DOMAIN ].store;struct msi_desc *desc; -xa_for_each_start (&md->__store, md->__iter_idx, desc, md->__iter_idx) { +xa_for_each_start (xa, md->__iter_idx, desc, md->__iter_idx) {if (msi_desc_match (desc, filter))return desc; }
@@ -320,6 +327,7 @@ unsigned int msi_get_virq(struct device *dev, unsigned int index) {struct msi_desc *desc;unsigned int ret =0 ; +struct xarray *xa;bool pcimsi;if (!dev->msi.data)
@@ -328,7 +336,8 @@ unsigned int msi_get_virq(struct device *dev, unsigned int index) pcimsi =dev_is_pci (dev) ?to_pci_dev (dev)->msi_enabled : false;msi_lock_descs (dev); - desc =xa_load (&dev->msi.data->__store, pcimsi ?0 : index); + xa = &dev->msi.data->__domains[MSI_DEFAULT_DOMAIN ].store; + desc =xa_load (xa, pcimsi ?0 : index);if (desc && desc->irq) {/* * PCI-MSI has only one descriptor for multiple interrupts.
@@ -707,6 +716,7 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev,struct msi_domain_info *info = domain->host_data;struct msi_domain_ops *ops = info->ops;struct msi_desc *desc; +struct xarray *xa;int ret, virq;msi_lock_descs (dev);
@@ -714,8 +724,10 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev,if (ret) goto unlock; + xa = &dev->msi.data->__domains[MSI_DEFAULT_DOMAIN ].store; +for (virq = virq_base; virq < virq_base + nvec; virq++) { - desc =xa_load (&dev->msi.data->__store, virq); + desc =xa_load (xa, virq); desc->irq = virq; ops->set_desc (arg, desc);
PATCH v3 9/22 genirq/msi: Add pointers for per device irq domains
In reply to Thomas GleixnerWith the upcoming per device MSI interrupt domain support it is necessary to store the domain pointers per device.
Instead of delegating that storage to device drivers or subsystems add a domain pointer to the msi_dev_domain array in struct msi_device_data.
This pointer is also used to take care of tearing down the irq domains when msi_device_data is cleaned up via devres.
The interfaces into the MSI core will be changed from irqdomain pointer based interfaces to domain id based interfaces to support multiple MSI domains on a single device (e.g. PCI/MSI[-X] and PCI/IMS.
Once the per device domain support is complete the irq domain pointer in struct device::msi.domain will not longer contain a pointer to the "global" MSI domain. It will contain a pointer to the MSI parent domain instead.
It would be a horrible maze of conditionals to evaluate all over the place which domain pointer should be used, i.e. the "global" one in device::msi::domain or one from the internal pointer array.
To avoid this evaluate in msi_setup_device_data() whether the irq domain which is associated to a device is a "global" or a parent MSI domain. If it is global then copy the pointer into the first entry of the msi_dev_domain array.
This allows to convert interfaces and implementation to domain ids while keeping everything existing working.
---
V3: Adopt to the domain/xarray storage change
--- include/linux/msi.h | 3 +++ kernel/irq/msi.c | 9 +++++++++ 2 files changed, 12 insertions(+)
include/linux/msi.h +3 -0
@@ -77,6 +77,7 @@ struct msi_desc;struct pci_dev ;struct platform_msi_priv_data ;struct device_attribute ; +struct irq_domain ;void __get_cached_msi_msg (struct msi_desc *entry,struct msi_msg *msg);#ifdef CONFIG_GENERIC_MSI_IRQ
@@ -177,9 +178,11 @@ enum msi_desc_filter {/** * struct msi_dev_domain - The internals of MSI domain info per device * @store: Xarray for storing MSI descriptor pointers +* @irqdomain: Pointer to a per device interrupt domain */ struct msi_dev_domain {struct xarray store; +struct irq_domain *domain; };/**
kernel/irq/msi.c +9 -0
@@ -220,6 +220,15 @@ int msi_setup_device_data(struct devicefor (i =0 ; i <MSI_MAX_DEVICE_IRQDOMAINS ; i++)xa_init (&md->__domains[i].store); +/* +* If @dev::msi::domain is set and is a global MSI domain, copy the +* pointer into the domain array so all code can operate on domain +* ids. The NULL pointer check is required to keep the legacy +* architecture specific PCI/MSI support working. +*/ +if (dev->msi.domain && !irq_domain_is_msi_parent (dev->msi.domain)) + md->__domains[MSI_DEFAULT_DOMAIN ].domain = dev->msi.domain; +mutex_init (&md->mutex); dev->msi.data = md;devres_add (dev, md);
[tip: irq/core] genirq/msi: Add pointers for per device irq domains
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 64258eaa442b0b7d7eac8942cf27863ad9e6028e Gitweb: https://git.kernel.org/tip/64258eaa442b0b7d7eac8942cf27863ad9e6028e Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:22 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:59 +01:00
genirq/msi: Add pointers for per device irq domains
With the upcoming per device MSI interrupt domain support it is necessary to store the domain pointers per device.
Instead of delegating that storage to device drivers or subsystems add a domain pointer to the msi_dev_domain array in struct msi_device_data.
This pointer is also used to take care of tearing down the irq domains when msi_device_data is cleaned up via devres.
The interfaces into the MSI core will be changed from irqdomain pointer based interfaces to domain id based interfaces to support multiple MSI domains on a single device (e.g. PCI/MSI[-X] and PCI/IMS.
Once the per device domain support is complete the irq domain pointer in struct device::msi.domain will not longer contain a pointer to the "global" MSI domain. It will contain a pointer to the MSI parent domain instead.
It would be a horrible maze of conditionals to evaluate all over the place which domain pointer should be used, i.e. the "global" one in device::msi::domain or one from the internal pointer array.
To avoid this evaluate in msi_setup_device_data() whether the irq domain which is associated to a device is a "global" or a parent MSI domain. If it is global then copy the pointer into the first entry of the msi_dev_domain array.
This allows to convert interfaces and implementation to domain ids while keeping everything existing working.
--- include/linux/msi.h | 3 +++ kernel/irq/msi.c | 9 +++++++++ 2 files changed, 12 insertions(+)
include/linux/msi.h +3 -0
@@ -77,6 +77,7 @@ struct msi_desc;struct pci_dev ;struct platform_msi_priv_data ;struct device_attribute ; +struct irq_domain ;void __get_cached_msi_msg (struct msi_desc *entry,struct msi_msg *msg);#ifdef CONFIG_GENERIC_MSI_IRQ
@@ -177,9 +178,11 @@ enum msi_desc_filter {/** * struct msi_dev_domain - The internals of MSI domain info per device * @store: Xarray for storing MSI descriptor pointers +* @irqdomain: Pointer to a per device interrupt domain */ struct msi_dev_domain {struct xarray store; +struct irq_domain *domain; };/**
kernel/irq/msi.c +9 -0
@@ -220,6 +220,15 @@ int msi_setup_device_data(struct device *dev)for (i =0 ; i <MSI_MAX_DEVICE_IRQDOMAINS ; i++)xa_init (&md->__domains[i].store); +/* +* If @dev::msi::domain is set and is a global MSI domain, copy the +* pointer into the domain array so all code can operate on domain +* ids. The NULL pointer check is required to keep the legacy +* architecture specific PCI/MSI support working. +*/ +if (dev->msi.domain && !irq_domain_is_msi_parent (dev->msi.domain)) + md->__domains[MSI_DEFAULT_DOMAIN ].domain = dev->msi.domain; +mutex_init (&md->mutex); dev->msi.data = md;devres_add (dev, md);
PATCH v3 10/22 genirq/msi: Make MSI descriptor iterators device domain aware
In reply to Thomas GleixnerTo support multiple MSI interrupt domains per device it is necessary to segment the xarray MSI descriptor storage. Each domain gets up to MSI_MAX_INDEX entries.
Change the iterators so they operate with domain ids and take the domain offsets into account.
The publicly available iterators which are mostly used in legacy implementations and the PCI/MSI core default to MSI_DEFAULT_DOMAIN (0) which is the id for the existing "global" domains.
No functional change.
---
V2: Fix the off by one so the index space is including MSI_MAX_INDEX (Kevin)
V3: Adopt to the domain/xarray storage change
--- include/linux/msi.h | 48 ++++++++++++++++++++++++++++++++++++++++++------ kernel/irq/msi.c | 35 +++++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 18 deletions(-)
include/linux/msi.h +42 -6
@@ -206,11 +206,48 @@ int msi_setup_device_data(struct devicevoid msi_lock_descs (struct device *dev);void msi_unlock_descs (struct device *dev); -struct msi_desc *msi_first_desc (struct device *dev,enum msi_desc_filter filter); -struct msi_desc *msi_next_desc (struct device *dev,enum msi_desc_filter filter); +struct msi_desc *msi_domain_first_desc (struct device *dev,unsigned int domid, +enum msi_desc_filter filter);/** -* msi_for_each_desc - Iterate the MSI descriptors +* msi_first_desc - Get the first MSI descriptor of the default irqdomain +* @dev: Device to operate on +* @filter: Descriptor state filter +* +* Must be called with the MSI descriptor mutex held, i.e. msi_lock_descs() +* must be invoked before the call. +* +* Return: Pointer to the first MSI descriptor matching the search +* criteria, NULL if none found. +*/ +static inline struct msi_desc *msi_first_desc (struct device *dev, +enum msi_desc_filter filter) +{ +return msi_domain_first_desc (dev,MSI_DEFAULT_DOMAIN , filter); +} + +struct msi_desc *msi_next_desc (struct device *dev,unsigned int domid, +enum msi_desc_filter filter); + +/** +* msi_domain_for_each_desc - Iterate the MSI descriptors in a specific domain +* +* @desc: struct msi_desc pointer used as iterator +* @dev: struct device pointer - device to iterate +* @domid: The id of the interrupt domain which should be walked. +* @filter: Filter for descriptor selection +* +* Notes: +* - The loop must be protected with a msi_lock_descs()/msi_unlock_descs() +* pair. +* - It is safe to remove a retrieved MSI descriptor in the loop. +*/ +#define msi_domain_for_each_desc (desc, dev, domid, filter) \ + for ((desc) = msi_domain_first_desc((dev), (domid), (filter)); (desc); \ + (desc) = msi_next_desc((dev), (domid), (filter))) + +/** +* msi_for_each_desc - Iterate the MSI descriptors in the default irqdomain * * @desc: struct msi_desc pointer used as iterator * @dev: struct device pointer - device to iterate
@@ -221,9 +258,8 @@ struct msi_desc *msi_next_desc(struct de* pair. * - It is safe to remove a retrieved MSI descriptor in the loop. */ -#define msi_for_each_desc (desc, dev, filter) \ - for ((desc) = msi_first_desc((dev), (filter)); (desc); \ - (desc) = msi_next_desc((dev), (filter))) +#define msi_for_each_desc (desc, dev, filter) \ + msi_domain_for_each_desc((desc), (dev), MSI_DEFAULT_DOMAIN, (filter))#define msi_desc_to_dev (desc) ((desc)->dev)
kernel/irq/msi.c +23 -12
@@ -19,8 +19,14 @@#include "internals.h" +/* Invalid Xarray index which is outside of any searchable range */ +#define MSI_XA_MAX_INDEX (ULONG_MAX - 1) +/* The maximum domain size */ +#define MSI_XA_DOMAIN_SIZE (MSI_MAX_INDEX + 1) +static inline int msi_sysfs_create_group (struct device *dev); +/** * msi_alloc_desc - Allocate an initialized msi_desc * @dev: Pointer to the device for which this is allocated
@@ -252,27 +258,29 @@ EXPORT_SYMBOL_GPL(msi_lock_descs);void msi_unlock_descs (struct device *dev) {/* Invalidate the index which was cached by the iterator */ - dev->msi.data->__iter_idx =MSI_MAX_INDEX ; + dev->msi.data->__iter_idx =MSI_XA_MAX_INDEX ;mutex_unlock (&dev->msi.data->mutex); }EXPORT_SYMBOL_GPL (msi_unlock_descs); -static struct msi_desc *msi_find_desc (struct msi_device_data *md,enum msi_desc_filter filter) +static struct msi_desc *msi_find_desc (struct msi_device_data *md,unsigned int domid, +enum msi_desc_filter filter) { -struct xarray *xa = &md->__domains[MSI_DEFAULT_DOMAIN ].store; +struct xarray *xa = &md->__domains[domid].store;struct msi_desc *desc;xa_for_each_start (xa, md->__iter_idx, desc, md->__iter_idx) {if (msi_desc_match (desc, filter))return desc; } - md->__iter_idx =MSI_MAX_INDEX ; + md->__iter_idx =MSI_XA_MAX_INDEX ;return NULL ; }/** -* msi_first_desc - Get the first MSI descriptor of a device +* msi_domain_first_desc - Get the first MSI descriptor of an irqdomain associated to a device * @dev: Device to operate on +* @domid: The id of the interrupt domain which should be walked. * @filter: Descriptor state filter * * Must be called with the MSI descriptor mutex held, i.e. msi_lock_descs()
@@ -281,23 +289,25 @@ static struct msi_desc *msi_find_desc(st* Return: Pointer to the first MSI descriptor matching the search * criteria, NULL if none found. */ -struct msi_desc *msi_first_desc (struct device *dev,enum msi_desc_filter filter) +struct msi_desc *msi_domain_first_desc (struct device *dev,unsigned int domid, +enum msi_desc_filter filter) {struct msi_device_data *md = dev->msi.data; -if (WARN_ON_ONCE (!md)) +if (WARN_ON_ONCE (!md || domid >=MSI_MAX_DEVICE_IRQDOMAINS ))return NULL ;lockdep_assert_held (&md->mutex); md->__iter_idx =0 ; -return msi_find_desc (md, filter); +return msi_find_desc (md, domid, filter); } -EXPORT_SYMBOL_GPL (msi_first_desc); +EXPORT_SYMBOL_GPL (msi_domain_first_desc);/** * msi_next_desc - Get the next MSI descriptor of a device * @dev: Device to operate on +* @domid: The id of the interrupt domain which should be walked. * @filter: Descriptor state filter * * The first invocation of msi_next_desc() has to be preceeded by a
@@ -308,11 +318,12 @@ EXPORT_SYMBOL_GPL(msi_first_desc);* Return: Pointer to the next MSI descriptor matching the search * criteria, NULL if none found. */ -struct msi_desc *msi_next_desc (struct device *dev,enum msi_desc_filter filter) +struct msi_desc *msi_next_desc (struct device *dev,unsigned int domid, +enum msi_desc_filter filter) {struct msi_device_data *md = dev->msi.data; -if (WARN_ON_ONCE (!md)) +if (WARN_ON_ONCE (!md || domid >=MSI_MAX_DEVICE_IRQDOMAINS ))return NULL ;lockdep_assert_held (&md->mutex);
@@ -321,7 +332,7 @@ struct msi_desc *msi_next_desc(struct dereturn NULL ; md->__iter_idx++; -return msi_find_desc (md, filter); +return msi_find_desc (md, domid, filter); }EXPORT_SYMBOL_GPL (msi_next_desc);
[tip: irq/core] genirq/msi: Make MSI descriptor iterators device domain aware
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 94ff94cfea2827e287a42781a47f37c9ef82186b Gitweb: https://git.kernel.org/tip/94ff94cfea2827e287a42781a47f37c9ef82186b Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:24 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:59 +01:00
genirq/msi: Make MSI descriptor iterators device domain aware
To support multiple MSI interrupt domains per device it is necessary to segment the xarray MSI descriptor storage. Each domain gets up to MSI_MAX_INDEX entries.
Change the iterators so they operate with domain ids and take the domain offsets into account.
The publicly available iterators which are mostly used in legacy implementations and the PCI/MSI core default to MSI_DEFAULT_DOMAIN (0) which is the id for the existing "global" domains.
No functional change.
--- include/linux/msi.h | 48 ++++++++++++++++++++++++++++++++++++++------ kernel/irq/msi.c | 35 +++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 18 deletions(-)
include/linux/msi.h +42 -6
@@ -206,11 +206,48 @@ int msi_setup_device_data(struct device *dev);void msi_lock_descs (struct device *dev);void msi_unlock_descs (struct device *dev); -struct msi_desc *msi_first_desc (struct device *dev,enum msi_desc_filter filter); -struct msi_desc *msi_next_desc (struct device *dev,enum msi_desc_filter filter); +struct msi_desc *msi_domain_first_desc (struct device *dev,unsigned int domid, +enum msi_desc_filter filter);/** -* msi_for_each_desc - Iterate the MSI descriptors +* msi_first_desc - Get the first MSI descriptor of the default irqdomain +* @dev: Device to operate on +* @filter: Descriptor state filter +* +* Must be called with the MSI descriptor mutex held, i.e. msi_lock_descs() +* must be invoked before the call. +* +* Return: Pointer to the first MSI descriptor matching the search +* criteria, NULL if none found. +*/ +static inline struct msi_desc *msi_first_desc (struct device *dev, +enum msi_desc_filter filter) +{ +return msi_domain_first_desc (dev,MSI_DEFAULT_DOMAIN , filter); +} + +struct msi_desc *msi_next_desc (struct device *dev,unsigned int domid, +enum msi_desc_filter filter); + +/** +* msi_domain_for_each_desc - Iterate the MSI descriptors in a specific domain +* +* @desc: struct msi_desc pointer used as iterator +* @dev: struct device pointer - device to iterate +* @domid: The id of the interrupt domain which should be walked. +* @filter: Filter for descriptor selection +* +* Notes: +* - The loop must be protected with a msi_lock_descs()/msi_unlock_descs() +* pair. +* - It is safe to remove a retrieved MSI descriptor in the loop. +*/ +#define msi_domain_for_each_desc (desc, dev, domid, filter) \ + for ((desc) = msi_domain_first_desc((dev), (domid), (filter)); (desc); \ + (desc) = msi_next_desc((dev), (domid), (filter))) + +/** +* msi_for_each_desc - Iterate the MSI descriptors in the default irqdomain * * @desc: struct msi_desc pointer used as iterator * @dev: struct device pointer - device to iterate
@@ -221,9 +258,8 @@ struct msi_desc *msi_next_desc(struct device *dev, enum msi_desc_filter filter);* pair. * - It is safe to remove a retrieved MSI descriptor in the loop. */ -#define msi_for_each_desc (desc, dev, filter) \ - for ((desc) = msi_first_desc((dev), (filter)); (desc); \ - (desc) = msi_next_desc((dev), (filter))) +#define msi_for_each_desc (desc, dev, filter) \ + msi_domain_for_each_desc((desc), (dev), MSI_DEFAULT_DOMAIN, (filter))#define msi_desc_to_dev (desc) ((desc)->dev)
kernel/irq/msi.c +23 -12
@@ -19,8 +19,14 @@#include "internals.h" +/* Invalid Xarray index which is outside of any searchable range */ +#define MSI_XA_MAX_INDEX (ULONG_MAX - 1) +/* The maximum domain size */ +#define MSI_XA_DOMAIN_SIZE (MSI_MAX_INDEX + 1) +static inline int msi_sysfs_create_group (struct device *dev); +/** * msi_alloc_desc - Allocate an initialized msi_desc * @dev: Pointer to the device for which this is allocated
@@ -252,27 +258,29 @@ EXPORT_SYMBOL_GPL(msi_lock_descs);void msi_unlock_descs (struct device *dev) {/* Invalidate the index which was cached by the iterator */ - dev->msi.data->__iter_idx =MSI_MAX_INDEX ; + dev->msi.data->__iter_idx =MSI_XA_MAX_INDEX ;mutex_unlock (&dev->msi.data->mutex); }EXPORT_SYMBOL_GPL (msi_unlock_descs); -static struct msi_desc *msi_find_desc (struct msi_device_data *md,enum msi_desc_filter filter) +static struct msi_desc *msi_find_desc (struct msi_device_data *md,unsigned int domid, +enum msi_desc_filter filter) { -struct xarray *xa = &md->__domains[MSI_DEFAULT_DOMAIN ].store; +struct xarray *xa = &md->__domains[domid].store;struct msi_desc *desc;xa_for_each_start (xa, md->__iter_idx, desc, md->__iter_idx) {if (msi_desc_match (desc, filter))return desc; } - md->__iter_idx =MSI_MAX_INDEX ; + md->__iter_idx =MSI_XA_MAX_INDEX ;return NULL ; }/** -* msi_first_desc - Get the first MSI descriptor of a device +* msi_domain_first_desc - Get the first MSI descriptor of an irqdomain associated to a device * @dev: Device to operate on +* @domid: The id of the interrupt domain which should be walked. * @filter: Descriptor state filter * * Must be called with the MSI descriptor mutex held, i.e. msi_lock_descs()
@@ -281,23 +289,25 @@ static struct msi_desc *msi_find_desc(struct msi_device_data *md, enum msi_desc_* Return: Pointer to the first MSI descriptor matching the search * criteria, NULL if none found. */ -struct msi_desc *msi_first_desc (struct device *dev,enum msi_desc_filter filter) +struct msi_desc *msi_domain_first_desc (struct device *dev,unsigned int domid, +enum msi_desc_filter filter) {struct msi_device_data *md = dev->msi.data; -if (WARN_ON_ONCE (!md)) +if (WARN_ON_ONCE (!md || domid >=MSI_MAX_DEVICE_IRQDOMAINS ))return NULL ;lockdep_assert_held (&md->mutex); md->__iter_idx =0 ; -return msi_find_desc (md, filter); +return msi_find_desc (md, domid, filter); } -EXPORT_SYMBOL_GPL (msi_first_desc); +EXPORT_SYMBOL_GPL (msi_domain_first_desc);/** * msi_next_desc - Get the next MSI descriptor of a device * @dev: Device to operate on +* @domid: The id of the interrupt domain which should be walked. * @filter: Descriptor state filter * * The first invocation of msi_next_desc() has to be preceeded by a
@@ -308,11 +318,12 @@ EXPORT_SYMBOL_GPL(msi_first_desc);* Return: Pointer to the next MSI descriptor matching the search * criteria, NULL if none found. */ -struct msi_desc *msi_next_desc (struct device *dev,enum msi_desc_filter filter) +struct msi_desc *msi_next_desc (struct device *dev,unsigned int domid, +enum msi_desc_filter filter) {struct msi_device_data *md = dev->msi.data; -if (WARN_ON_ONCE (!md)) +if (WARN_ON_ONCE (!md || domid >=MSI_MAX_DEVICE_IRQDOMAINS ))return NULL ;lockdep_assert_held (&md->mutex);
@@ -321,7 +332,7 @@ struct msi_desc *msi_next_desc(struct device *dev, enum msi_desc_filter filter)return NULL ; md->__iter_idx++; -return msi_find_desc (md, filter); +return msi_find_desc (md, domid, filter); }EXPORT_SYMBOL_GPL (msi_next_desc);
PATCH v3 11/22 genirq/msi: Make msi_get_virq() device domain aware
In reply to Thomas GleixnerFrom: Ahmed S. Darwish <[email protected]>
In preparation of the upcoming per device multi MSI domain support, change the interface to support lookups based on domain id and zero based index within the domain.
---
V2: Fix the locking leak and the operator precedence issue (kernel robot)
V3: Adopt to the domain/xarray storage change
--- include/linux/msi_api.h | 14 +++++++++++++- kernel/irq/msi.c | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-)
include/linux/msi_api.h +13 -1
@@ -18,6 +18,18 @@ enum msi_domain_ids { MSI_MAX_DEVICE_IRQDOMAINS, }; -unsigned int msi_get_virq (struct device *dev,unsigned int index); +unsigned int msi_domain_get_virq (struct device *dev,unsigned int domid,unsigned int index); + +/** +* msi_get_virq - Lookup the Linux interrupt number for a MSI index on the default interrupt domain +* @dev: Device for which the lookup happens +* @index: The MSI index to lookup +* +* Return: The Linux interrupt number on success (> 0), 0 if not found +*/ +static inline unsigned int msi_get_virq (struct device *dev,unsigned int index) +{ +return msi_domain_get_virq (dev,MSI_DEFAULT_DOMAIN , index); +}#endif
kernel/irq/msi.c +13 -6
@@ -338,26 +338,32 @@ struct msi_desc *msi_next_desc(struct deEXPORT_SYMBOL_GPL (msi_next_desc);/** -* msi_get_virq - Return Linux interrupt number of a MSI interrupt +* msi_domain_get_virq - Lookup the Linux interrupt number for a MSI index on a interrupt domain * @dev: Device to operate on +* @domid: Domain ID of the interrupt domain associated to the device * @index: MSI interrupt index to look for (0-based) * * Return: The Linux interrupt number on success (> 0), 0 if not found */ -unsigned int msi_get_virq (struct device *dev,unsigned int index) +unsigned int msi_domain_get_virq (struct device *dev,unsigned int domid,unsigned int index) {struct msi_desc *desc;unsigned int ret =0 ; +bool pcimsi = false;struct xarray *xa; -bool pcimsi;if (!dev->msi.data)return 0 ; - pcimsi =dev_is_pci (dev) ?to_pci_dev (dev)->msi_enabled : false; +if (WARN_ON_ONCE (index >MSI_MAX_INDEX || domid >=MSI_MAX_DEVICE_IRQDOMAINS )) +return 0 ; + +/* This check is only valid for the PCI default MSI domain */ +if (dev_is_pci (dev) && domid ==MSI_DEFAULT_DOMAIN ) + pcimsi =to_pci_dev (dev)->msi_enabled;msi_lock_descs (dev); - xa = &dev->msi.data->__domains[MSI_DEFAULT_DOMAIN ].store; + xa = &dev->msi.data->__domains[domid].store; desc =xa_load (xa, pcimsi ?0 : index);if (desc && desc->irq) {/*
@@ -372,10 +378,11 @@ unsigned int msi_get_virq(struct device ret = desc->irq; } } +msi_unlock_descs (dev);return ret; } -EXPORT_SYMBOL_GPL (msi_get_virq); +EXPORT_SYMBOL_GPL (msi_domain_get_virq);#ifdef CONFIG_SYSFS static struct attribute *msi_dev_attrs[] = {
[tip: irq/core] genirq/msi: Make msi_get_virq() device domain aware
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 98043704f375f63a47efeff123ab92fcf34b95e6 Gitweb: https://git.kernel.org/tip/98043704f375f63a47efeff123ab92fcf34b95e6 Author: Ahmed S. Darwish <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:25 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:59 +01:00
genirq/msi: Make msi_get_virq() device domain aware
In preparation of the upcoming per device multi MSI domain support, change the interface to support lookups based on domain id and zero based index within the domain.
--- include/linux/msi_api.h | 14 +++++++++++++- kernel/irq/msi.c | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-)
include/linux/msi_api.h +13 -1
@@ -18,6 +18,18 @@ enum msi_domain_ids { MSI_MAX_DEVICE_IRQDOMAINS, }; -unsigned int msi_get_virq (struct device *dev,unsigned int index); +unsigned int msi_domain_get_virq (struct device *dev,unsigned int domid,unsigned int index); + +/** +* msi_get_virq - Lookup the Linux interrupt number for a MSI index on the default interrupt domain +* @dev: Device for which the lookup happens +* @index: The MSI index to lookup +* +* Return: The Linux interrupt number on success (> 0), 0 if not found +*/ +static inline unsigned int msi_get_virq (struct device *dev,unsigned int index) +{ +return msi_domain_get_virq (dev,MSI_DEFAULT_DOMAIN , index); +}#endif
kernel/irq/msi.c +13 -6
@@ -337,26 +337,32 @@ struct msi_desc *msi_next_desc(struct device *dev, unsigned int domid,EXPORT_SYMBOL_GPL (msi_next_desc);/** -* msi_get_virq - Return Linux interrupt number of a MSI interrupt +* msi_domain_get_virq - Lookup the Linux interrupt number for a MSI index on a interrupt domain * @dev: Device to operate on +* @domid: Domain ID of the interrupt domain associated to the device * @index: MSI interrupt index to look for (0-based) * * Return: The Linux interrupt number on success (> 0), 0 if not found */ -unsigned int msi_get_virq (struct device *dev,unsigned int index) +unsigned int msi_domain_get_virq (struct device *dev,unsigned int domid,unsigned int index) {struct msi_desc *desc;unsigned int ret =0 ; +bool pcimsi = false;struct xarray *xa; -bool pcimsi;if (!dev->msi.data)return 0 ; - pcimsi =dev_is_pci (dev) ?to_pci_dev (dev)->msi_enabled : false; +if (WARN_ON_ONCE (index >MSI_MAX_INDEX || domid >=MSI_MAX_DEVICE_IRQDOMAINS )) +return 0 ; + +/* This check is only valid for the PCI default MSI domain */ +if (dev_is_pci (dev) && domid ==MSI_DEFAULT_DOMAIN ) + pcimsi =to_pci_dev (dev)->msi_enabled;msi_lock_descs (dev); - xa = &dev->msi.data->__domains[MSI_DEFAULT_DOMAIN ].store; + xa = &dev->msi.data->__domains[domid].store; desc =xa_load (xa, pcimsi ?0 : index);if (desc && desc->irq) {/*
@@ -371,10 +377,11 @@ unsigned int msi_get_virq(struct device *dev, unsigned int index) ret = desc->irq; } } +msi_unlock_descs (dev);return ret; } -EXPORT_SYMBOL_GPL (msi_get_virq); +EXPORT_SYMBOL_GPL (msi_domain_get_virq);#ifdef CONFIG_SYSFS static struct attribute *msi_dev_attrs[] = {
PATCH v3 12/22 genirq/msi: Rename msi_add_msi_desc() to msi_insert_msi_desc()
In reply to Thomas GleixnerThis reflects the functionality better. No functional change.
--- drivers/pci/msi/msi.c | 4 ++-- drivers/soc/ti/ti_sci_inta_msi.c | 4 ++-- include/linux/msi.h | 2 +- kernel/irq/msi.c | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-)
drivers/pci/msi/msi.c +2 -2
@@ -308,7 +308,7 @@ static int msi_setup_msi_desc(struct pciif (desc.pci.msi_attrib.can_mask)pci_read_config_dword (dev, desc.pci.mask_pos, &desc.pci.msi_mask); -return msi_add_msi_desc (&dev->dev, &desc); +return msi_insert_msi_desc (&dev->dev, &desc); }static int msi_verify_entries (struct pci_dev *dev)
@@ -591,7 +591,7 @@ static int msix_setup_msi_descs(struct p desc.pci.msix_ctrl =readl (addr +PCI_MSIX_ENTRY_VECTOR_CTRL ); } - ret =msi_add_msi_desc (&dev->dev, &desc); + ret =msi_insert_msi_desc (&dev->dev, &desc);if (ret)break ; }
drivers/soc/ti/ti_sci_inta_msi.c +2 -2
@@ -73,13 +73,13 @@ static int ti_sci_inta_msi_alloc_descs(sfor (set =0 ; set < res->sets; set++) {for (i =0 ; i < res->desc[set].num; i++, count++) { msi_desc.msi_index = res->desc[set].start + i; -if (msi_add_msi_desc (dev, &msi_desc)) +if (msi_insert_msi_desc (dev, &msi_desc)) goto fail; }for (i =0 ; i < res->desc[set].num_sec; i++, count++) { msi_desc.msi_index = res->desc[set].start_sec + i; -if (msi_add_msi_desc (dev, &msi_desc)) +if (msi_insert_msi_desc (dev, &msi_desc)) goto fail; } }
include/linux/msi.h +1 -1
@@ -286,7 +286,7 @@ static inline void msi_desc_set_iommu_co }#endif -int msi_add_msi_desc (struct device *dev,struct msi_desc *init_desc); +int msi_insert_msi_desc (struct device *dev,struct msi_desc *init_desc);void msi_free_msi_descs_range (struct device *dev,unsigned int first_index,unsigned int last_index);/**
kernel/irq/msi.c +4 -2
@@ -77,13 +77,15 @@ static int msi_insert_desc(struct msi_de }/** -* msi_add_msi_desc - Allocate and initialize a MSI descriptor +* msi_insert_msi_desc - Allocate and initialize a MSI descriptor and +* insert it at @init_desc->msi_index +* * @dev: Pointer to the device for which the descriptor is allocated * @init_desc: Pointer to an MSI descriptor to initialize the new descriptor * * Return: 0 on success or an appropriate failure code. */ -int msi_add_msi_desc (struct device *dev,struct msi_desc *init_desc) +int msi_insert_msi_desc (struct device *dev,struct msi_desc *init_desc) {struct msi_desc *desc;
[tip: irq/core] genirq/msi: Rename msi_add_msi_desc() to msi_insert_msi_desc()
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 1c89396300292da4e4a87db63bef45975461fa25 Gitweb: https://git.kernel.org/tip/1c89396300292da4e4a87db63bef45975461fa25 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:27 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:59 +01:00
genirq/msi: Rename msi_add_msi_desc() to msi_insert_msi_desc()
This reflects the functionality better. No functional change.
--- drivers/pci/msi/msi.c | 4 ++-- drivers/soc/ti/ti_sci_inta_msi.c | 4 ++-- include/linux/msi.h | 2 +- kernel/irq/msi.c | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-)
drivers/pci/msi/msi.c +2 -2
@@ -308,7 +308,7 @@ static int msi_setup_msi_desc(struct pci_dev *dev, int nvec,if (desc.pci.msi_attrib.can_mask)pci_read_config_dword (dev, desc.pci.mask_pos, &desc.pci.msi_mask); -return msi_add_msi_desc (&dev->dev, &desc); +return msi_insert_msi_desc (&dev->dev, &desc); }static int msi_verify_entries (struct pci_dev *dev)
@@ -591,7 +591,7 @@ static int msix_setup_msi_descs(struct pci_dev *dev, void __iomem *base, desc.pci.msix_ctrl =readl (addr +PCI_MSIX_ENTRY_VECTOR_CTRL ); } - ret =msi_add_msi_desc (&dev->dev, &desc); + ret =msi_insert_msi_desc (&dev->dev, &desc);if (ret)break ; }
drivers/soc/ti/ti_sci_inta_msi.c +2 -2
@@ -73,13 +73,13 @@ static int ti_sci_inta_msi_alloc_descs(struct device *dev,for (set =0 ; set < res->sets; set++) {for (i =0 ; i < res->desc[set].num; i++, count++) { msi_desc.msi_index = res->desc[set].start + i; -if (msi_add_msi_desc (dev, &msi_desc)) +if (msi_insert_msi_desc (dev, &msi_desc)) goto fail; }for (i =0 ; i < res->desc[set].num_sec; i++, count++) { msi_desc.msi_index = res->desc[set].start_sec + i; -if (msi_add_msi_desc (dev, &msi_desc)) +if (msi_insert_msi_desc (dev, &msi_desc)) goto fail; } }
include/linux/msi.h +1 -1
@@ -286,7 +286,7 @@ static inline void msi_desc_set_iommu_cookie(struct msi_desc *desc, }#endif -int msi_add_msi_desc (struct device *dev,struct msi_desc *init_desc); +int msi_insert_msi_desc (struct device *dev,struct msi_desc *init_desc);void msi_free_msi_descs_range (struct device *dev,unsigned int first_index,unsigned int last_index);/**
kernel/irq/msi.c +4 -2
@@ -77,13 +77,15 @@ static int msi_insert_desc(struct msi_device_data *md, struct msi_desc *desc, un }/** -* msi_add_msi_desc - Allocate and initialize a MSI descriptor +* msi_insert_msi_desc - Allocate and initialize a MSI descriptor and +* insert it at @init_desc->msi_index +* * @dev: Pointer to the device for which the descriptor is allocated * @init_desc: Pointer to an MSI descriptor to initialize the new descriptor * * Return: 0 on success or an appropriate failure code. */ -int msi_add_msi_desc (struct device *dev,struct msi_desc *init_desc) +int msi_insert_msi_desc (struct device *dev,struct msi_desc *init_desc) {struct msi_desc *desc;
PATCH v3 13/22 genirq/msi: Make descriptor allocation device domain aware
In reply to Thomas GleixnerChange the descriptor allocation and insertion functions to take a domain id to prepare for the upcoming multi MSI domain per device support.
---
V3: Adopt to the domain/xarray storage change
--- include/linux/msi.h | 16 +++++++++++++++- kernel/irq/msi.c | 20 ++++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-)
include/linux/msi.h +15 -1
@@ -286,7 +286,21 @@ static inline void msi_desc_set_iommu_co }#endif -int msi_insert_msi_desc (struct device *dev,struct msi_desc *init_desc); +int msi_domain_insert_msi_desc (struct device *dev,unsigned int domid, +struct msi_desc *init_desc); +/** +* msi_insert_msi_desc - Allocate and initialize a MSI descriptor in the +* default irqdomain and insert it at @init_desc->msi_index +* @dev: Pointer to the device for which the descriptor is allocated +* @init_desc: Pointer to an MSI descriptor to initialize the new descriptor +* +* Return: 0 on success or an appropriate failure code. +*/ +static inline int msi_insert_msi_desc (struct device *dev,struct msi_desc *init_desc) +{ +return msi_domain_insert_msi_desc (dev,MSI_DEFAULT_DOMAIN , init_desc); +} +void msi_free_msi_descs_range (struct device *dev,unsigned int first_index,unsigned int last_index);/**
kernel/irq/msi.c +12 -8
@@ -39,7 +39,7 @@ static inline int msi_sysfs_create_group* Return: pointer to allocated &msi_desc on success or %NULL on failure */ static struct msi_desc *msi_alloc_desc (struct device *dev,int nvec, -const struct irq_affinity_desc *affinity) +const struct irq_affinity_desc *affinity) {struct msi_desc *desc =kzalloc (sizeof (*desc),GFP_KERNEL );
@@ -64,9 +64,10 @@ static void msi_free_desc(struct msi_deskfree (desc); } -static int msi_insert_desc (struct msi_device_data *md,struct msi_desc *desc,unsigned int index) +static int msi_insert_desc (struct msi_device_data *md,struct msi_desc *desc, +unsigned int domid,unsigned int index) { -struct xarray *xa = &md->__domains[MSI_DEFAULT_DOMAIN ].store; +struct xarray *xa = &md->__domains[domid].store;int ret; desc->msi_index = index;
@@ -77,15 +78,17 @@ static int msi_insert_desc(struct msi_de }/** -* msi_insert_msi_desc - Allocate and initialize a MSI descriptor and -* insert it at @init_desc->msi_index +* msi_domain_insert_msi_desc - Allocate and initialize a MSI descriptor and +* insert it at @init_desc->msi_index * * @dev: Pointer to the device for which the descriptor is allocated +* @domid: The id of the interrupt domain to which the desriptor is added * @init_desc: Pointer to an MSI descriptor to initialize the new descriptor * * Return: 0 on success or an appropriate failure code. */ -int msi_insert_msi_desc (struct device *dev,struct msi_desc *init_desc) +int msi_domain_insert_msi_desc (struct device *dev,unsigned int domid, +struct msi_desc *init_desc) {struct msi_desc *desc;
@@ -97,7 +100,8 @@ int msi_insert_msi_desc(struct device *d/* Copy type specific data to the new descriptor. */ desc->pci = init_desc->pci; -return msi_insert_desc (dev->msi.data, desc, init_desc->msi_index); + +return msi_insert_desc (dev->msi.data, desc, domid, init_desc->msi_index); }/**
@@ -120,7 +124,7 @@ static int msi_add_simple_msi_descs(stru desc =msi_alloc_desc (dev,1 ,NULL );if (!desc) goto fail_mem; - ret =msi_insert_desc (dev->msi.data, desc, idx); + ret =msi_insert_desc (dev->msi.data, desc,MSI_DEFAULT_DOMAIN , idx);if (ret) goto fail; }
[tip: irq/core] genirq/msi: Make descriptor allocation device domain aware
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: fc8ab388325ddfd848d00f3a3383b4304594546a Gitweb: https://git.kernel.org/tip/fc8ab388325ddfd848d00f3a3383b4304594546a Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:29 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:59 +01:00
genirq/msi: Make descriptor allocation device domain aware
Change the descriptor allocation and insertion functions to take a domain id to prepare for the upcoming multi MSI domain per device support.
--- include/linux/msi.h | 16 +++++++++++++++- kernel/irq/msi.c | 20 ++++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-)
include/linux/msi.h +15 -1
@@ -286,7 +286,21 @@ static inline void msi_desc_set_iommu_cookie(struct msi_desc *desc, }#endif -int msi_insert_msi_desc (struct device *dev,struct msi_desc *init_desc); +int msi_domain_insert_msi_desc (struct device *dev,unsigned int domid, +struct msi_desc *init_desc); +/** +* msi_insert_msi_desc - Allocate and initialize a MSI descriptor in the +* default irqdomain and insert it at @init_desc->msi_index +* @dev: Pointer to the device for which the descriptor is allocated +* @init_desc: Pointer to an MSI descriptor to initialize the new descriptor +* +* Return: 0 on success or an appropriate failure code. +*/ +static inline int msi_insert_msi_desc (struct device *dev,struct msi_desc *init_desc) +{ +return msi_domain_insert_msi_desc (dev,MSI_DEFAULT_DOMAIN , init_desc); +} +void msi_free_msi_descs_range (struct device *dev,unsigned int first_index,unsigned int last_index);/**
kernel/irq/msi.c +12 -8
@@ -39,7 +39,7 @@ static inline int msi_sysfs_create_group(struct device *dev);* Return: pointer to allocated &msi_desc on success or %NULL on failure */ static struct msi_desc *msi_alloc_desc (struct device *dev,int nvec, -const struct irq_affinity_desc *affinity) +const struct irq_affinity_desc *affinity) {struct msi_desc *desc =kzalloc (sizeof (*desc),GFP_KERNEL );
@@ -64,9 +64,10 @@ static void msi_free_desc(struct msi_desc *desc)kfree (desc); } -static int msi_insert_desc (struct msi_device_data *md,struct msi_desc *desc,unsigned int index) +static int msi_insert_desc (struct msi_device_data *md,struct msi_desc *desc, +unsigned int domid,unsigned int index) { -struct xarray *xa = &md->__domains[MSI_DEFAULT_DOMAIN ].store; +struct xarray *xa = &md->__domains[domid].store;int ret; desc->msi_index = index;
@@ -77,15 +78,17 @@ static int msi_insert_desc(struct msi_device_data *md, struct msi_desc *desc, un }/** -* msi_insert_msi_desc - Allocate and initialize a MSI descriptor and -* insert it at @init_desc->msi_index +* msi_domain_insert_msi_desc - Allocate and initialize a MSI descriptor and +* insert it at @init_desc->msi_index * * @dev: Pointer to the device for which the descriptor is allocated +* @domid: The id of the interrupt domain to which the desriptor is added * @init_desc: Pointer to an MSI descriptor to initialize the new descriptor * * Return: 0 on success or an appropriate failure code. */ -int msi_insert_msi_desc (struct device *dev,struct msi_desc *init_desc) +int msi_domain_insert_msi_desc (struct device *dev,unsigned int domid, +struct msi_desc *init_desc) {struct msi_desc *desc;
@@ -97,7 +100,8 @@ int msi_insert_msi_desc(struct device *dev, struct msi_desc *init_desc)/* Copy type specific data to the new descriptor. */ desc->pci = init_desc->pci; -return msi_insert_desc (dev->msi.data, desc, init_desc->msi_index); + +return msi_insert_desc (dev->msi.data, desc, domid, init_desc->msi_index); }/**
@@ -120,7 +124,7 @@ static int msi_add_simple_msi_descs(struct device *dev, unsigned int index, unsi desc =msi_alloc_desc (dev,1 ,NULL );if (!desc) goto fail_mem; - ret =msi_insert_desc (dev->msi.data, desc, idx); + ret =msi_insert_desc (dev->msi.data, desc,MSI_DEFAULT_DOMAIN , idx);if (ret) goto fail; }
PATCH v3 14/22 genirq/msi: Make descriptor freeing domain aware
In reply to Thomas GleixnerChange the descriptor free functions to take a domain id to prepare for the upcoming multi MSI domain per device support.
To avoid changing and extending the interfaces over and over use an core internal control struct and hand the pointer through the various functions.
---
V3: Adopt to the domain/xarray storage change
--- include/linux/msi.h | 19 +++++++++++++++-- kernel/irq/msi.c | 58 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 12 deletions(-)
include/linux/msi.h +17 -2
@@ -301,10 +301,25 @@ static inline int msi_insert_msi_desc(streturn msi_domain_insert_msi_desc (dev,MSI_DEFAULT_DOMAIN , init_desc); } -void msi_free_msi_descs_range (struct device *dev,unsigned int first_index,unsigned int last_index); +void msi_domain_free_msi_descs_range (struct device *dev,unsigned int domid, +unsigned int first,unsigned int last);/** -* msi_free_msi_descs - Free MSI descriptors of a device +* msi_free_msi_descs_range - Free a range of MSI descriptors of a device +* in the default irqdomain +* +* @dev: Device for which to free the descriptors +* @first: Index to start freeing from (inclusive) +* @last: Last index to be freed (inclusive) +*/ +static inline void msi_free_msi_descs_range (struct device *dev,unsigned int first, +unsigned int last) +{ +msi_domain_free_msi_descs_range (dev,MSI_DEFAULT_DOMAIN , first, last); +} + +/** +* msi_free_msi_descs - Free all MSI descriptors of a device in the default irqdomain * @dev: Device to free the descriptors */ static inline void msi_free_msi_descs (struct device *dev)
kernel/irq/msi.c +48 -10
82 lines not on this page · raw message
[tip: irq/core] genirq/msi: Make descriptor freeing domain aware
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 377712c5a45f6de40bffef5ddc31b39cd86cf23f Gitweb: https://git.kernel.org/tip/377712c5a45f6de40bffef5ddc31b39cd86cf23f Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:30 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:20:59 +01:00
genirq/msi: Make descriptor freeing domain aware
Change the descriptor free functions to take a domain id to prepare for the upcoming multi MSI domain per device support.
To avoid changing and extending the interfaces over and over use an core internal control struct and hand the pointer through the various functions.
--- include/linux/msi.h | 19 ++++++++++++-- kernel/irq/msi.c | 58 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 65 insertions(+), 12 deletions(-)
include/linux/msi.h +17 -2
@@ -301,10 +301,25 @@ static inline int msi_insert_msi_desc(struct device *dev, struct msi_desc *init_return msi_domain_insert_msi_desc (dev,MSI_DEFAULT_DOMAIN , init_desc); } -void msi_free_msi_descs_range (struct device *dev,unsigned int first_index,unsigned int last_index); +void msi_domain_free_msi_descs_range (struct device *dev,unsigned int domid, +unsigned int first,unsigned int last);/** -* msi_free_msi_descs - Free MSI descriptors of a device +* msi_free_msi_descs_range - Free a range of MSI descriptors of a device +* in the default irqdomain +* +* @dev: Device for which to free the descriptors +* @first: Index to start freeing from (inclusive) +* @last: Last index to be freed (inclusive) +*/ +static inline void msi_free_msi_descs_range (struct device *dev,unsigned int first, +unsigned int last) +{ +msi_domain_free_msi_descs_range (dev,MSI_DEFAULT_DOMAIN , first, last); +} + +/** +* msi_free_msi_descs - Free all MSI descriptors of a device in the default irqdomain * @dev: Device to free the descriptors */ static inline void msi_free_msi_descs (struct device *dev)
kernel/irq/msi.c +48 -10
82 lines not on this page · raw message
PATCH v3 15/22 genirq/msi: Make msi_add_simple_msi_descs() device domain aware
In reply to Thomas GleixnerAllocating simple interrupt descriptors in the core code has to be multi device irqdomain aware for the upcoming PCI/IMS support.
Change the interfaces to take a domain id into account. Use the internal control struct for transport of arguments.
---
V3: Adopt to the domain/xarray storage change
--- kernel/irq/msi.c | 98 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 41 deletions(-)
kernel/irq/msi.c +57 -41
@@ -116,39 +116,6 @@ int msi_domain_insert_msi_desc(struct dereturn msi_insert_desc (dev->msi.data, desc, domid, init_desc->msi_index); } -/** -* msi_add_simple_msi_descs - Allocate and initialize MSI descriptors -* @dev: Pointer to the device for which the descriptors are allocated -* @index: Index for the first MSI descriptor -* @ndesc: Number of descriptors to allocate -* -* Return: 0 on success or an appropriate failure code. -*/ -static int msi_add_simple_msi_descs (struct device *dev,unsigned int index,unsigned int ndesc) -{ -unsigned int idx, last = index + ndesc -1 ; -struct msi_desc *desc; -int ret; - -lockdep_assert_held (&dev->msi.data->mutex); - -for (idx = index; idx <= last; idx++) { - desc =msi_alloc_desc (dev,1 ,NULL ); -if (!desc) - goto fail_mem; - ret =msi_insert_desc (dev->msi.data, desc,MSI_DEFAULT_DOMAIN , idx); -if (ret) - goto fail; - } -return 0 ; - -fail_mem: - ret = -ENOMEM ; -fail: -msi_free_msi_descs_range (dev, index, last); -return ret; -} -static bool msi_desc_match (struct msi_desc *desc,enum msi_desc_filter filter) {switch (filter) {
@@ -166,6 +133,7 @@ static bool msi_desc_match(struct msi_destatic bool msi_ctrl_valid (struct device *dev,struct msi_ctrl *ctrl) {if (WARN_ON_ONCE (ctrl->domid >=MSI_MAX_DEVICE_IRQDOMAINS || + !dev->msi.data->__domains[ctrl->domid].domain || ctrl->first > ctrl->last || ctrl->first >MSI_MAX_INDEX || ctrl->last >MSI_MAX_INDEX ))
@@ -214,6 +182,41 @@ void msi_domain_free_msi_descs_range(strmsi_domain_free_descs (dev, &ctrl); } +/** +* msi_domain_add_simple_msi_descs - Allocate and initialize MSI descriptors +* @dev: Pointer to the device for which the descriptors are allocated +* @ctrl: Allocation control struct +* +* Return: 0 on success or an appropriate failure code. +*/ +static int msi_domain_add_simple_msi_descs (struct device *dev,struct msi_ctrl *ctrl) +{ +struct msi_desc *desc; +unsigned int idx; +int ret; + +lockdep_assert_held (&dev->msi.data->mutex); + +if (!msi_ctrl_valid (dev, ctrl)) +return -EINVAL ; + +for (idx = ctrl->first; idx <= ctrl->last; idx++) { + desc =msi_alloc_desc (dev,1 ,NULL ); +if (!desc) + goto fail_mem; + ret =msi_insert_desc (dev->msi.data, desc, ctrl->domid, idx); +if (ret) + goto fail; + } +return 0 ; + +fail_mem: + ret = -ENOMEM ; +fail: +msi_domain_free_descs (dev, ctrl); +return ret; +} +void __get_cached_msi_msg (struct msi_desc *entry,struct msi_msg *msg) { *msg = entry->msg;
@@ -787,16 +790,24 @@ int msi_domain_populate_irqs(struct irq_ {struct msi_domain_info *info = domain->host_data;struct msi_domain_ops *ops = info->ops; +struct msi_ctrl ctrl = { + .domid =MSI_DEFAULT_DOMAIN , + .first = virq_base, + .last = virq_base + nvec -1 , + };struct msi_desc *desc;struct xarray *xa;int ret, virq; +if (!msi_ctrl_valid (dev, &ctrl)) +return -EINVAL ; +msi_lock_descs (dev); - ret =msi_add_simple_msi_descs (dev, virq_base, nvec); + ret =msi_domain_add_simple_msi_descs (dev, &ctrl);if (ret) goto unlock; - xa = &dev->msi.data->__domains[MSI_DEFAULT_DOMAIN ].store; + xa = &dev->msi.data->__domains[ctrl.domid].store;for (virq = virq_base; virq < virq_base + nvec; virq++) { desc =xa_load (xa, virq);
@@ -815,7 +826,7 @@ int msi_domain_populate_irqs(struct irq_ fail:for (--virq; virq >= virq_base; virq--)irq_domain_free_irqs_common (domain, virq,1 ); -msi_free_msi_descs_range (dev, virq_base, virq_base + nvec -1 ); +msi_domain_free_descs (dev, &ctrl); unlock:msi_unlock_descs (dev);return ret;
@@ -989,14 +1000,19 @@ static int __msi_domain_alloc_irqs(strucreturn 0 ; } -static int msi_domain_add_simple_msi_descs (struct msi_domain_info *info, -struct device *dev, -unsigned int num_descs) +static int msi_domain_alloc_simple_msi_descs (struct device *dev, +struct msi_domain_info *info, +unsigned int num_descs) { +struct msi_ctrl ctrl = { + .domid =MSI_DEFAULT_DOMAIN , + .last = num_descs -1 , + }; +if (!(info->flags &MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS ))return 0 ; -return msi_add_simple_msi_descs (dev,0 , num_descs); +return msi_domain_add_simple_msi_descs (dev, &ctrl); }/**
@@ -1027,7 +1043,7 @@ int msi_domain_alloc_irqs_descs_locked(s }/* Frees allocated descriptors in case of failure. */ - ret =msi_domain_add_simple_msi_descs (info, dev, nvec); + ret =msi_domain_alloc_simple_msi_descs (dev, info, nvec);if (ret) goto free;
[tip: irq/core] genirq/msi: Make msi_add_simple_msi_descs() device domain aware
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 40742716f294449549884421170ea18356a2abe8 Gitweb: https://git.kernel.org/tip/40742716f294449549884421170ea18356a2abe8 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:32 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:21:00 +01:00
genirq/msi: Make msi_add_simple_msi_descs() device domain aware
Allocating simple interrupt descriptors in the core code has to be multi device irqdomain aware for the upcoming PCI/IMS support.
Change the interfaces to take a domain id into account. Use the internal control struct for transport of arguments.
--- kernel/irq/msi.c | 98 +++++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 41 deletions(-)
kernel/irq/msi.c +57 -41
@@ -116,39 +116,6 @@ int msi_domain_insert_msi_desc(struct device *dev, unsigned int domid,return msi_insert_desc (dev->msi.data, desc, domid, init_desc->msi_index); } -/** -* msi_add_simple_msi_descs - Allocate and initialize MSI descriptors -* @dev: Pointer to the device for which the descriptors are allocated -* @index: Index for the first MSI descriptor -* @ndesc: Number of descriptors to allocate -* -* Return: 0 on success or an appropriate failure code. -*/ -static int msi_add_simple_msi_descs (struct device *dev,unsigned int index,unsigned int ndesc) -{ -unsigned int idx, last = index + ndesc -1 ; -struct msi_desc *desc; -int ret; - -lockdep_assert_held (&dev->msi.data->mutex); - -for (idx = index; idx <= last; idx++) { - desc =msi_alloc_desc (dev,1 ,NULL ); -if (!desc) - goto fail_mem; - ret =msi_insert_desc (dev->msi.data, desc,MSI_DEFAULT_DOMAIN , idx); -if (ret) - goto fail; - } -return 0 ; - -fail_mem: - ret = -ENOMEM ; -fail: -msi_free_msi_descs_range (dev, index, last); -return ret; -} -static bool msi_desc_match (struct msi_desc *desc,enum msi_desc_filter filter) {switch (filter) {
@@ -166,6 +133,7 @@ static bool msi_desc_match(struct msi_desc *desc, enum msi_desc_filter filter)static bool msi_ctrl_valid (struct device *dev,struct msi_ctrl *ctrl) {if (WARN_ON_ONCE (ctrl->domid >=MSI_MAX_DEVICE_IRQDOMAINS || + !dev->msi.data->__domains[ctrl->domid].domain || ctrl->first > ctrl->last || ctrl->first >MSI_MAX_INDEX || ctrl->last >MSI_MAX_INDEX ))
@@ -214,6 +182,41 @@ void msi_domain_free_msi_descs_range(struct device *dev, unsigned int domid,msi_domain_free_descs (dev, &ctrl); } +/** +* msi_domain_add_simple_msi_descs - Allocate and initialize MSI descriptors +* @dev: Pointer to the device for which the descriptors are allocated +* @ctrl: Allocation control struct +* +* Return: 0 on success or an appropriate failure code. +*/ +static int msi_domain_add_simple_msi_descs (struct device *dev,struct msi_ctrl *ctrl) +{ +struct msi_desc *desc; +unsigned int idx; +int ret; + +lockdep_assert_held (&dev->msi.data->mutex); + +if (!msi_ctrl_valid (dev, ctrl)) +return -EINVAL ; + +for (idx = ctrl->first; idx <= ctrl->last; idx++) { + desc =msi_alloc_desc (dev,1 ,NULL ); +if (!desc) + goto fail_mem; + ret =msi_insert_desc (dev->msi.data, desc, ctrl->domid, idx); +if (ret) + goto fail; + } +return 0 ; + +fail_mem: + ret = -ENOMEM ; +fail: +msi_domain_free_descs (dev, ctrl); +return ret; +} +void __get_cached_msi_msg (struct msi_desc *entry,struct msi_msg *msg) { *msg = entry->msg;
@@ -786,16 +789,24 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev, {struct msi_domain_info *info = domain->host_data;struct msi_domain_ops *ops = info->ops; +struct msi_ctrl ctrl = { + .domid =MSI_DEFAULT_DOMAIN , + .first = virq_base, + .last = virq_base + nvec -1 , + };struct msi_desc *desc;struct xarray *xa;int ret, virq; +if (!msi_ctrl_valid (dev, &ctrl)) +return -EINVAL ; +msi_lock_descs (dev); - ret =msi_add_simple_msi_descs (dev, virq_base, nvec); + ret =msi_domain_add_simple_msi_descs (dev, &ctrl);if (ret) goto unlock; - xa = &dev->msi.data->__domains[MSI_DEFAULT_DOMAIN ].store; + xa = &dev->msi.data->__domains[ctrl.domid].store;for (virq = virq_base; virq < virq_base + nvec; virq++) { desc =xa_load (xa, virq);
@@ -814,7 +825,7 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev, fail:for (--virq; virq >= virq_base; virq--)irq_domain_free_irqs_common (domain, virq,1 ); -msi_free_msi_descs_range (dev, virq_base, virq_base + nvec -1 ); +msi_domain_free_descs (dev, &ctrl); unlock:msi_unlock_descs (dev);return ret;
@@ -988,14 +999,19 @@ static int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *devreturn 0 ; } -static int msi_domain_add_simple_msi_descs (struct msi_domain_info *info, -struct device *dev, -unsigned int num_descs) +static int msi_domain_alloc_simple_msi_descs (struct device *dev, +struct msi_domain_info *info, +unsigned int num_descs) { +struct msi_ctrl ctrl = { + .domid =MSI_DEFAULT_DOMAIN , + .last = num_descs -1 , + }; +if (!(info->flags &MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS ))return 0 ; -return msi_add_simple_msi_descs (dev,0 , num_descs); +return msi_domain_add_simple_msi_descs (dev, &ctrl); }/**
@@ -1026,7 +1042,7 @@ int msi_domain_alloc_irqs_descs_locked(struct irq_domain *domain, struct device }/* Frees allocated descriptors in case of failure. */ - ret =msi_domain_add_simple_msi_descs (info, dev, nvec); + ret =msi_domain_alloc_simple_msi_descs (dev, info, nvec);if (ret) goto free;
PATCH v3 16/22 genirq/msi: Provide new domain id based interfaces for freeing interrupts
In reply to Thomas GleixnerProvide two sorts of interfaces to handle the different use cases:
- msi_domain_free_irqs_range():
Handles a caller defined precise range
- msi_domain_free_irqs_all():
Frees all interrupts associated to a domain
The latter is useful for device teardown and to handle the legacy MSI support which does not have any range information available.
---
V3: Adopt to the domain/xarray storage change
--- include/linux/msi.h | 9 +++ kernel/irq/msi.c | 142 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 129 insertions(+), 22 deletions(-)
include/linux/msi.h +9 -0
@@ -498,6 +498,15 @@ int msi_domain_alloc_irqs(struct irq_dom int nvec);void msi_domain_free_irqs_descs_locked (struct irq_domain *domain,struct device *dev);void msi_domain_free_irqs (struct irq_domain *domain,struct device *dev); + +void msi_domain_free_irqs_range_locked (struct device *dev,unsigned int domid, +unsigned int first,unsigned int last); +void msi_domain_free_irqs_range (struct device *dev,unsigned int domid, +unsigned int first,unsigned int last); + +void msi_domain_free_irqs_all_locked (struct device *dev,unsigned int domid); +void msi_domain_free_irqs_all (struct device *dev,unsigned int domid); +struct msi_domain_info *msi_get_domain_info (struct irq_domain *domain); struct irq_domain *platform_msi_create_irq_domain(struct fwnode_handle *fwnode,
kernel/irq/msi.c +120 -22
186 lines not on this page · raw message
[tip: irq/core] genirq/msi: Provide new domain id based interfaces for freeing interrupts
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 4cd5f4403f283766f73749c4c936801f58ffe77a Gitweb: https://git.kernel.org/tip/4cd5f4403f283766f73749c4c936801f58ffe77a Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:33 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:21:00 +01:00
genirq/msi: Provide new domain id based interfaces for freeing interrupts
Provide two sorts of interfaces to handle the different use cases:
- msi_domain_free_irqs_range():
Handles a caller defined precise range
- msi_domain_free_irqs_all():
Frees all interrupts associated to a domain
The latter is useful for device teardown and to handle the legacy MSI support which does not have any range information available.
--- include/linux/msi.h | 9 +++- kernel/irq/msi.c | 142 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 129 insertions(+), 22 deletions(-)
include/linux/msi.h +9 -0
@@ -498,6 +498,15 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, int nvec);void msi_domain_free_irqs_descs_locked (struct irq_domain *domain,struct device *dev);void msi_domain_free_irqs (struct irq_domain *domain,struct device *dev); + +void msi_domain_free_irqs_range_locked (struct device *dev,unsigned int domid, +unsigned int first,unsigned int last); +void msi_domain_free_irqs_range (struct device *dev,unsigned int domid, +unsigned int first,unsigned int last); + +void msi_domain_free_irqs_all_locked (struct device *dev,unsigned int domid); +void msi_domain_free_irqs_all (struct device *dev,unsigned int domid); +struct msi_domain_info *msi_get_domain_info (struct irq_domain *domain); struct irq_domain *platform_msi_create_irq_domain(struct fwnode_handle *fwnode,
kernel/irq/msi.c +120 -22
186 lines not on this page · raw message
Re: [patch V3 16/22] genirq/msi: Provide new domain id based interfaces for freeing interrupts
In reply to Thomas GleixnerQuoted 15 lines · Thomas Gleixner
Provide two sorts of interfaces to handle the different use cases:
-
msi_domain_free_irqs_range():Handles a caller defined precise range
-
msi_domain_free_irqs_all():Frees all interrupts associated to a domain
The latter is useful for device teardown and to handle the legacy MSI support which does not have any range information available.
Signed-off-by Thomas Gleixner <[email protected]>---
...
Quoted 8 lines
+static void
msi_domain_free_locked(struct device *dev, struct msi_ctrl *ctrl){
+ structmsi_domain_info*info;
+ structmsi_domain_ops*ops;
+ structirq_domain*domain;(quoted diff) +3
-0+ + if (!msi_ctrl_valid(dev, ctrl)) + return;
Review
Quoted 10 lines
(quoted diff) +10
-0+ + domain = msi_get_device_domain(dev, ctrl->domid); + if (!domain) + return; + + info = domain->host_data; + ops = info->ops; + + if (ops->domain_free_irqs) + ops->domain_free_irqs(domain, dev);
Do you want a call to msi_free_dev_descs(dev) here? In the case where the core code calls ops->domain_alloc_irqs() it *has* allocated the descriptors first... but it's expecting the irqdomain to free them?
However, it's not quite as simple as adding msi_free_dev_descs()...
Quoted 3 lines
+ else
+ __msi_domain_free_irqs(dev, domain, ctrl); +
The igb driver seems to set up a single MSI-X in its setup, then tear that down, then try again with more. Thus exercising the teardown path.
In 6.2-rc3 it fails under Xen (emulation in qemu) thus:
[ 1.491207] igb: Intel(R) Gigabit Ethernet Network Driver [ 1.494003] igb: Copyright (c) 2007-2014 Intel Corporation. [ 1.664907] ACPI: \_SB_.LNKA: Enabled at IRQ 10 [ 1.670837] ------------[ cut here ]------------ [ 1.672644] WARNING: CPU: 1 PID: 1 at drivers/xen/events/events_base.c:793 xen_free_irq+0x156/0x170 [ 1.676202] Modules linked in: [ 1.677638] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.2.0-rc3+ #1059 [ 1.680134] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.1-0-g3208b098f51a-prebuilt.qemu.org 04/01/2014 [ 1.684484] RIP: 0010:xen_free_irq+0x156/0x170 [ 1.686240] Code: 5c 41 5d 41 5e 41 5f e9 08 03 95 ff e8 a3 5b 95 ff 48 85 c0 74 14 48 8b 58 30 e9 df fe ff ff 31 f6 89 ef e8 6c 59 95 ff eb 94 <0f> 0b 5b 5d 41 5c 41 5d 41 5e 41 5f c3 cc cc cc cc 0f 0b eb 86 0f [ 1.692888] RSP: 0000:ffffc90000013ac8 EFLAGS: 00010246 [ 1.694705] RAX: 0000000000000000 RBX: 0000000000000026 RCX: 0000000000000000 [ 1.697113] RDX: 0000000000000028 RSI: ffff888001400490 RDI: 0000000000000026 [ 1.699498] RBP: 0000000000000026 R08: ffff8880014005e8 R09: ffffffff89c00240 [ 1.701917] R10: 0000000000000000 R11: 0000000000000000 R12: 00000000fffffffe [ 1.704520] R13: ffffffff89de6880 R14: 0000000000000000 R15: 0000000000000005 [ 1.707202] FS: 0000000000000000(0000) GS:ffff88803ed00000(0000) knlGS:0000000000000000 [ 1.709974] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1.711867] CR2: 0000000000000000 CR3: 000000003c812001 CR4: 0000000000170ee0 [ 1.714260] Call Trace: [ 1.715145] <TASK> [ 1.715897] xen_destroy_irq+0x64/0x120 [ 1.717181] ? msi_find_desc+0x41/0xb0 [ 1.718552] xen_teardown_msi_irqs+0x3d/0x70 [ 1.720064] msi_domain_free_locked.part.0+0x58/0x1c0 [ 1.721791] msi_domain_free_irqs_all_locked+0x6a/0x90 [ 1.723551] __pci_enable_msix_range+0x353/0x590 [ 1.725159] igb_set_interrupt_capability+0x90/0x1c0 [ 1.726879] igb_init_interrupt_scheme+0x2d/0x230 [ 1.728494] ? rcu_read_lock_sched_held+0x3f/0x80 [ 1.730361] igb_sw_init+0x1b3/0x260 [ 1.731797] igb_probe+0x3b6/0xf00 [ 1.733146] ? _raw_spin_unlock_irqrestore+0x40/0x60 [ 1.734834] local_pci_probe+0x41/0x80 [ 1.736164] pci_call_probe+0x54/0x160 [ 1.737441] pci_device_probe+0x7c/0x100 [ 1.738828] ? driver_sysfs_add+0x71/0xd0 [ 1.740229] really_probe+0xde/0x380 [ 1.741434] ? pm_runtime_barrier+0x50/0x90 [ 1.742873] __driver_probe_device+0x78/0x170 [ 1.744314] driver_probe_device+0x1f/0x90 [ 1.745689] __driver_attach+0xd2/0x1c0 [ 1.747035] ? __pfx___driver_attach+0x10/0x10 [ 1.748518] bus_for_each_dev+0x79/0xc0 [ 1.749859] bus_add_driver+0x1b1/0x200 [ 1.751182] driver_register+0x89/0xe0 [ 1.752472] ? __pfx_igb_init_module+0x10/0x10 [ 1.754054] do_one_initcall+0x5b/0x320 [ 1.755573] ? rcu_read_lock_sched_held+0x3f/0x80 [ 1.757375] kernel_init_freeable+0x1a6/0x1ec [ 1.759005] ? __pfx_kernel_init+0x10/0x10 [ 1.760375] kernel_init+0x16/0x130 [ 1.761554] ret_from_fork+0x2c/0x50 [ 1.762797] </TASK> [ 1.763590] irq event stamp: 1798623 [ 1.764869] hardirqs last enabled at (1798633): [<ffffffff8814aa8e>] __up_console_sem+0x5e/0x70 [ 1.767762] hardirqs last disabled at (1798642): [<ffffffff8814aa73>] __up_console_sem+0x43/0x70 [ 1.770715] softirqs last enabled at (1798570): [<ffffffff88d91f76>] __do_softirq+0x356/0x4da [ 1.773576] softirqs last disabled at (1798565): [<ffffffff880bb83d>] __irq_exit_rcu+0xdd/0x150 [ 1.776492] ---[ end trace 0000000000000000 ]--- [ 1.839462] igb 0000:00:04.0: added PHC on eth0 [ 1.843531] igb 0000:00:04.0: Intel(R) Gigabit Ethernet Network Connection [ 1.843541] igb 0000:00:04.0: eth0: (PCIe:5.0Gb/s:Width x4) 00:1e:67:cb:7a:93 [ 1.843620] igb 0000:00:04.0: eth0: PBA No: 006000-000 [ 1.849237] igb 0000:00:04.0: Using legacy interrupts. 1 rx queue(s), 1 tx queue(s)
If I add the missing call to msi_free_msi_descs() then it does work, but complains differently:
[ 1.563055] igb: Intel(R) Gigabit Ethernet Network Driver [ 1.566442] igb: Copyright (c) 2007-2014 Intel Corporation. [ 1.737236] ACPI: \_SB_.LNKA: Enabled at IRQ 10 [ 1.742162] ------------[ cut here ]------------ [ 1.744393] WARNING: CPU: 0 PID: 1 at kernel/irq/msi.c:196 msi_domain_free_descs+0xe1/0x110 [ 1.748248] Modules linked in: [ 1.749289] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.2.0-rc3+ #1057 [ 1.751466] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.1-0-g3208b098f51a-prebuilt.qemu.org 04/01/2014 [ 1.755187] RIP: 0010:msi_domain_free_descs+0xe1/0x110 [ 1.756875] Code: 00 48 89 e6 4c 89 e7 e8 ed f4 ba 00 48 89 c3 48 85 c0 0f 84 71 ff ff ff 48 8b 34 24 4c 89 e7 e8 a5 01 bb 00 8b 03 85 c0 74 be <0f> 0b eb cb 48 8b 87 70 03 00 00 be ff ff ff ff 48 8d 78 78 e8 26 [ 1.763060] RSP: 0000:ffffc90000013b78 EFLAGS: 00010202 [ 1.764804] RAX: 0000000000000026 RBX: ffff888001ac5f00 RCX: 0000000000000000 [ 1.767155] RDX: 0000000000000001 RSI: ffffffffa649808a RDI: 00000000ffffffff [ 1.769462] RBP: ffffc90000013ba8 R08: 0000000000000001 R09: 0000000000000000 [ 1.771934] R10: 000000006ac46bb1 R11: 00000000aee0433d R12: ffff888001a238c8 [ 1.774695] R13: ffffffffa6de6880 R14: ffff888001a51218 R15: ffff888001a50000 [ 1.777081] FS: 0000000000000000(0000) GS:ffff88803ec00000(0000) knlGS:0000000000000000 [ 1.779754] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1.781681] CR2: ffff888010801000 CR3: 000000000e812001 CR4: 0000000000170ef0 [ 1.784093] Call Trace: [ 1.784880] <TASK> [ 1.785640] msi_domain_free_msi_descs_range+0x34/0x60 [ 1.787370] msi_domain_free_locked.part.0+0x58/0x1c0 [ 1.789034] msi_domain_free_irqs_all_locked+0x6a/0x90 [ 1.790815] pci_free_msi_irqs+0xe/0x30 [ 1.792157] pci_disable_msix+0x48/0x60 [ 1.793413] igb_reset_interrupt_capability+0xa4/0xb0 [ 1.795077] igb_sw_init+0x13f/0x260 [ 1.796281] igb_probe+0x3b6/0xf00 [ 1.797421] ? _raw_spin_unlock_irqrestore+0x40/0x60 [ 1.799050] local_pci_probe+0x41/0x80 [ 1.800282] pci_call_probe+0x54/0x160 [ 1.801543] pci_device_probe+0x7c/0x100 [ 1.803393] ? driver_sysfs_add+0x71/0xd0 [ 1.804761] really_probe+0xde/0x380 [ 1.806021] ? pm_runtime_barrier+0x50/0x90 [ 1.807395] __driver_probe_device+0x78/0x170 [ 1.808877] driver_probe_device+0x1f/0x90 [ 1.810257] __driver_attach+0xd2/0x1c0 [ 1.811529] ? __pfx___driver_attach+0x10/0x10 [ 1.813251] bus_for_each_dev+0x79/0xc0 [ 1.814534] bus_add_driver+0x1b1/0x200 [ 1.816058] driver_register+0x89/0xe0 [ 1.817291] ? __pfx_igb_init_module+0x10/0x10 [ 1.818821] do_one_initcall+0x5b/0x320 [ 1.820133] ? rcu_read_lock_sched_held+0x3f/0x80 [ 1.821697] kernel_init_freeable+0x1a6/0x1ec [ 1.823150] ? __pfx_kernel_init+0x10/0x10 [ 1.824484] kernel_init+0x16/0x130 [ 1.825990] ret_from_fork+0x2c/0x50 [ 1.827757] </TASK> [ 1.828865] irq event stamp: 1797845 [ 1.830573] hardirqs last enabled at (1797855): [<ffffffffa514aa8e>] __up_console_sem+0x5e/0x70 [ 1.834809] hardirqs last disabled at (1797864): [<ffffffffa514aa73>] __up_console_sem+0x43/0x70 [ 1.838915] softirqs last enabled at (1797742): [<ffffffffa5d91f76>] __do_softirq+0x356/0x4da [ 1.842442] softirqs last disabled at (1797737): [<ffffffffa50bb83d>] __irq_exit_rcu+0xdd/0x150 [ 1.846094] ---[ end trace 0000000000000000 ]---
If I zero msidesc->irq in the loop in xen_teardown_msi_irqs(), *then* it both works and stops complaining. But I'm mostly just tampering empirically now...
I can provide a qemu tree which will let you test this easily with just qemu-system-x86_64 -kernel ... but you have to promise not to look at the way I've fixed some qemu deadlocks just by commenting out the lock on MSI delivery/translation :)
You'd also have to provide your own igb device as qemu doesn't emulate those; I'm testing it in passthrough. Or hack the e1000e driver to do a setup/teardown/setup... or perhaps just unload and reload its module?
I'll provide a SoB just in case it's actually the right way to fix it…
arch/x86/pci/xen.c +3 -1
@@ -390,8 +390,10 @@ static void xen_teardown_msi_irqs(struct pci_dev *dev)int i;msi_for_each_desc (msidesc, &dev->dev,MSI_DESC_ASSOCIATED ) { -for (i =0 ; i < msidesc->nvec_used; i++) +for (i =0 ; i < msidesc->nvec_used; i++) {xen_destroy_irq (msidesc->irq + i); + msidesc->irq =0 ; + } } }
kernel/irq/msi.c +3 -2
@@ -1533,9 +1533,10 @@ static void msi_domain_free_locked(struct device *dev, struct msi_ctrl *ctrl) info = domain->host_data; ops = info->ops; -if (ops->domain_free_irqs) +if (ops->domain_free_irqs) { ops->domain_free_irqs (domain, dev); -else +msi_free_msi_descs (dev); + }else __msi_domain_free_irqs (dev, domain, ctrl);if (ops->msi_post_free)
Re: [patch V3 16/22] genirq/msi: Provide new domain id based interfaces for freeing interrupts
Quoted 10 lines · David Woodhouse
msi_for_each_desc(msidesc, &dev->dev, MSI_DESC_ASSOCIATED){arch/x86/pci/xen.c +1
-1-for (i =0 ; i < msidesc->nvec_used; i++) +for (i =0 ; i < msidesc->nvec_used; i++) {
xen_destroy_irq(msidesc->irq + i);arch/x86/pci/xen.c +2
-0+ msidesc->irq =0 ; + }}
}
Der, setting it to zero wants to be in the msi_for_each_desc() loop and *not* in the 'for i' loop of course.
Re: [patch V3 16/22] genirq/msi: Provide new domain id based interfaces for freeing interrupts
In reply to David WoodhouseDavid!
Quoted 8 lines · David Woodhouse
Quoted 3 lines · Thomas Gleixner
+
+ if (ops->domain_free_irqs)
+ ops->domain_free_irqs(domain, dev);Do you want a call to
msi_free_dev_descs(dev)here? In the case where the core code callsops->domain_alloc_irqs()it *has* allocated the descriptors first... but it's expecting the irqdomain to free them?
No. Let me stare at it.
Quoted 1 line
However, it's not quite as simple as adding
msi_free_dev_descs()...
Correct.
kernel/irq/msi.c static void msi_domain_free_locked(struct device *dev, struct msi_ctrl *ctrl) · line 1538
Quoted 13 lines
kernel/irq/msi.c +2
-2@@ -1533,9 +1533,10 @@ static void msi_domain_free_locked(struct device *dev, struct msi_ctrl *ctrl) info = domain->host_data; ops = info->ops; -if (ops->domain_free_irqs) +if (ops->domain_free_irqs) { ops->domain_free_irqs (domain, dev); -else +msi_free_msi_descs (dev);
This is just wrong. I need to taxi my grandson. Will have a look afterwards.
Thanks,
tglx
Re: [patch V3 16/22] genirq/msi: Provide new domain id based interfaces for freeing interrupts
David!
Quoted 4 lines · Thomas Gleixner
On Mon, Jan 16 2023 at 09:56, David Woodhouse wrote:
This is just wrong. I need to taxi my grandson. Will have a look afterwards.
There are three 'tglx missed to fixup XEN' problems:
- b2bdda205c0c ("PCI/MSI: Let the MSI core free descriptors")
This requires the MSI_FLAG_FREE_MSI_DESCS flag to be set in the XEN MSI domain info
- 2f2940d16823 ("genirq/msi: Remove filter from msi_free_descs_free_range()")
This requires the 'desc->irq = 0' disassociation on teardown.
- ffd84485e6be ("PCI/MSI: Let the irq code handle sysfs groups")
Lacks a flag in the XEN MSI domain info as well.
Combo patch below.
Thanks,
tglx
---
arch/x86/pci/xen.c +2 -0
@@ -392,6 +392,7 @@ static void xen_teardown_msi_irqs(structmsi_for_each_desc (msidesc, &dev->dev,MSI_DESC_ASSOCIATED ) {for (i =0 ; i < msidesc->nvec_used; i++)xen_destroy_irq (msidesc->irq + i); + msidesc->irq =0 ; } }
@@ -434,6 +435,7 @@ static struct msi_domain_ops xen_pci_msistatic struct msi_domain_info xen_pci_msi_domain_info = { .ops = &xen_pci_msi_domain_ops, + .flags =MSI_FLAG_FREE_MSI_DESCS |MSI_FLAG_DEV_SYSFS , };/*
David Woodhouse
Tested-byRe: [patch V3 16/22] genirq/msi: Provide new domain id based interfaces for freeing interrupts
Quoted 1 line · Thomas Gleixner
+ .flags =
MSI_FLAG_FREE_MSI_DESCS|MSI_FLAG_DEV_SYSFS,
That doesn't apply on top of
https://lore.kernel.org/all/[email protected]/
and doesn't include the | MSI_FLAG_PCI_MSIX either.
With that remedied,
Albeit only under qemu with
https://git.infradead.org/users/dwmw2/qemu.git/shortlog/refs/heads/xenfv
and not under real Xen.
Re: [patch V3 16/22] genirq/msi: Provide new domain id based interfaces for freeing interrupts
David!
Quoted 6 lines · David Woodhouse
Quoted 1 line · Thomas Gleixner
+ .flags =
MSI_FLAG_FREE_MSI_DESCS|MSI_FLAG_DEV_SYSFS,
That doesn't apply on top of
https://lore.kernel.org/all/[email protected]/
and doesn't include the |MSI_FLAG_PCI_MSIXeither.
Indeed. I saw that patch after my reply. :)
Quoted 7 lines
With that remedied,
Tested-by David Woodhouse <[email protected]>Albeit only under qemu with
https://git.infradead.org/users/dwmw2/qemu.git/shortlog/refs/heads/xenfv
and not under real Xen.
Five levels of emulation. What could possibly go wrong?
Re: [patch V3 16/22] genirq/msi: Provide new domain id based interfaces for freeing interrupts
Quoted 7 lines · Thomas Gleixner
Quoted 5 lines
Tested-by David Woodhouse <[email protected]>Albeit only under qemu with
https://git.infradead.org/users/dwmw2/qemu.git/shortlog/refs/heads/xenfv
and not under real Xen.Five levels of emulation. What could possibly go wrong?
It's the opposite — this is what happened when I threw my toys out of the pram and said, "You're NOT doing that with nested virtualization!".
One level of emulation. We host guests that think they're running on Xen, directly in QEMU/KVM by handling the hypercalls and event channels, grant tables, etc.
We virtualised Xen itself :)
Now you have no more excuses for breaking Xen guest mode!
Re: [patch V3 16/22] genirq/msi: Provide new domain id based interfaces for freeing interrupts
David!
Quoted 9 lines · David Woodhouse
Quoted 7 lines · Thomas Gleixner
Quoted 5 lines
Tested-by David Woodhouse <[email protected]>Albeit only under qemu with
https://git.infradead.org/users/dwmw2/qemu.git/shortlog/refs/heads/xenfv
and not under real Xen.Five levels of emulation. What could possibly go wrong?
Quoted 8 lines
It's the opposite — this is what happened when I threw my toys out of the pram and said, "You're NOT doing that with nested virtualization!".
One level of emulation. We host guests that think they're running on Xen, directly in QEMU/KVM by handling the hypercalls and event channels, grant tables, etc.
We virtualised Xen itself :)
Groan. Can we please agree on *one* hypervisor instead of growing emulators for all other hypervisors in each of them :)
Quoted 1 line
Now you have no more excuses for breaking Xen guest mode!
No cookies, you spoilsport! :)
tglx
Re: [patch V3 16/22] genirq/msi: Provide new domain id based interfaces for freeing interrupts
Quoted 15 lines · Thomas Gleixner
David!
Quoted 12 lines · David Woodhouse
Quoted 7 lines · Thomas Gleixner
Quoted 5 lines
Tested-by David Woodhouse <[email protected]>Albeit only under qemu with
https://git.infradead.org/users/dwmw2/qemu.git/shortlog/refs/heads/xenfv
and not under real Xen.Five levels of emulation. What could possibly go wrong?
It's the opposite — this is what happened when I threw my toys out of the pram and said, "You're NOT doing that with nested virtualization!".
Quoted 8 lines
Quoted 5 lines
One level of emulation. We host guests that think they're running on Xen, directly in QEMU/KVM by handling the hypercalls and event channels, grant tables, etc.
We virtualised Xen itself :)
Groan. Can we please agree on *one* hypervisor instead of growing emulators for all other hypervisors in each of them :)
Hey, we did work across KVM, Xen and even Hyper-V to make sure the Extended Destination ID in MSI supports 32Ki vCPUs the *same* way on each guest. Be thankful for small mercies!
And the code to support Xen guests natively in KVM is *fairly* minimal; we allow userspace to catch hypercalls, and do a little bit of the fast path of IRQ delivery because we really don't want to be bouncing out to the userspace VMM for IPIs etc.
As for qemu, emulating environments that you may not have access to in real hardware is its raison d'être, isn't it?
And agreeing on one hypervisor — that's what we're doing. But the *administration* is the far more important part. We're allowing people to standardise on KVM, and to focus on the administration and security of only Linux and KVM.
But there are still huge numbers of of virtual machine images out there which are configured to run on Xen. Their root disk is /dev/xvda, the network device they have configured is vif0.
In some ways it's theoretically just as easy as telling all those folks "well, you just need to install an NVMe driver and a new network card driver". Except it isn't really, because that often ends up being "rebuild it on a newer kernel and/or OS". And if the intern who set this system up left three years ago and the company now depends on it as critical infrastructure without really knowing it yet...
It isn't practical to tell people, "screw you, you can't run that any more".
So we host them under Linux and they mostly look like native KVM guests to the kernel, you stop breaking Xen guest mode, and everybody wins.
Quoted 3 lines
Quoted 1 line
Now you have no more excuses for breaking Xen guest mode!
No cookies, you spoilsport! :)
:)
[tip: x86/urgent] x86/pci/xen: Fixup fallout from the PCI/MSI overhaul
In reply to Thomas GleixnerThe following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 6c796996ee7033bcbbc3cd733513eb43f8160f5e Gitweb: https://git.kernel.org/tip/6c796996ee7033bcbbc3cd733513eb43f8160f5e Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 16 Jan 2023 19:11:32 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 16 Jan 2023 20:40:44 +01:00
x86/pci/xen: Fixup fallout from the PCI/MSI overhaul
David reported that the recent PCI/MSI rework results in MSI descriptor leakage under XEN.
This is caused by:
1) The missing MSI_FLAG_FREE_MSI_DESCS flag in the XEN MSI domain info, which is required now that PCI/MSI delegates descriptor freeing to the core MSI code.
2) Not disassociating the interrupts on teardown, by setting the msi_desc::irq to 0. This was not required before because the teardown was unconditional and did not check whether a MSI descriptor was still connected to a Linux interrupt.
On further inspection it came to light that the MSI_FLAG_DEV_SYSFS is missing in the XEN MSI domain info as well to restore the pre 6.2 status quo.
Add the missing MSI flags and disassociate the MSI descriptor from the Linux interrupt in the XEN specific teardown function.
--- arch/x86/pci/xen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/pci/xen.c +2 -1
@@ -392,6 +392,7 @@ static void xen_teardown_msi_irqs(struct pci_dev *dev)msi_for_each_desc (msidesc, &dev->dev,MSI_DESC_ASSOCIATED ) {for (i =0 ; i < msidesc->nvec_used; i++)xen_destroy_irq (msidesc->irq + i); + msidesc->irq =0 ; } }
@@ -433,7 +434,7 @@ static struct msi_domain_ops xen_pci_msi_domain_ops = { };static struct msi_domain_info xen_pci_msi_domain_info = { - .flags =MSI_FLAG_PCI_MSIX , + .flags =MSI_FLAG_PCI_MSIX |MSI_FLAG_FREE_MSI_DESCS |MSI_FLAG_DEV_SYSFS , .ops = &xen_pci_msi_domain_ops, };
PATCH v3 17/22 genirq/msi: Provide new domain id allocation functions
In reply to Thomas GleixnerProvide two sorts of interfaces to handle the different use cases:
- msi_domain_alloc_irqs_range():
Handles a caller defined precise range
- msi_domain_alloc_irqs_all():
Allocates all interrupts associated to a domain by scanning the allocated MSI descriptors
The latter is useful for the existing PCI/MSI support which does not have range information available.
---
V3: Adopt to the domain/xarray storage change
--- include/linux/msi.h | 18 ++--- kernel/irq/msi.c | 179 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 149 insertions(+), 48 deletions(-)
include/linux/msi.h +10 -8
@@ -383,8 +383,8 @@ struct msi_domain_info;* @get_hwirq, @msi_init and @msi_free are callbacks used by the underlying * irqdomain. * -* @msi_check, @msi_prepare and @set_desc are callbacks used by -* msi_domain_alloc/free_irqs(). +* @msi_check, @msi_prepare and @set_desc are callbacks used by the +* msi_domain_alloc/free_irqs*() variants. * * @domain_alloc_irqs, @domain_free_irqs can be used to override the * default allocation/free functions (__msi_domain_alloc/free_irqs). This
@@ -392,11 +392,6 @@ struct msi_domain_info;* be wrapped into the regular irq domains concepts by mere mortals. This * allows to universally use msi_domain_alloc/free_irqs without having to * special case XEN all over the place. -* -* Contrary to other operations @domain_alloc_irqs and @domain_free_irqs -* are set to the default implementation if NULL and even when -* MSI_FLAG_USE_DEF_DOM_OPS is not set to avoid breaking existing users and -* because these callbacks are obviously mandatory. */ struct msi_domain_ops { irq_hw_number_t (*get_hwirq)(struct msi_domain_info *info,
@@ -496,14 +491,21 @@ int msi_domain_alloc_irqs_descs_locked(s int nvec);int msi_domain_alloc_irqs (struct irq_domain *domain,struct device *dev,int nvec); +void msi_domain_free_irqs_descs_locked (struct irq_domain *domain,struct device *dev);void msi_domain_free_irqs (struct irq_domain *domain,struct device *dev); +int msi_domain_alloc_irqs_range_locked (struct device *dev,unsigned int domid, +unsigned int first,unsigned int last); +int msi_domain_alloc_irqs_range (struct device *dev,unsigned int domid, +unsigned int first,unsigned int last); +int msi_domain_alloc_irqs_all_locked (struct device *dev,unsigned int domid,int nirqs); + +void msi_domain_free_irqs_range_locked (struct device *dev,unsigned int domid,unsigned int first,unsigned int last);void msi_domain_free_irqs_range (struct device *dev,unsigned int domid,unsigned int first,unsigned int last); -void msi_domain_free_irqs_all_locked (struct device *dev,unsigned int domid);void msi_domain_free_irqs_all (struct device *dev,unsigned int domid);
kernel/irq/msi.c +139 -40
250 lines not on this page · raw message
[tip: irq/core] genirq/msi: Provide new domain id allocation functions
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: f2480e7dacdcd9aab25641346ae53b7ff03777fc Gitweb: https://git.kernel.org/tip/f2480e7dacdcd9aab25641346ae53b7ff03777fc Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:35 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:21:00 +01:00
genirq/msi: Provide new domain id allocation functions
Provide two sorts of interfaces to handle the different use cases:
- msi_domain_alloc_irqs_range():
Handles a caller defined precise range
- msi_domain_alloc_irqs_all():
Allocates all interrupts associated to a domain by scanning the allocated MSI descriptors
The latter is useful for the existing PCI/MSI support which does not have range information available.
--- include/linux/msi.h | 18 ++-- kernel/irq/msi.c | 175 +++++++++++++++++++++++++++++++++---------- 2 files changed, 146 insertions(+), 47 deletions(-)
include/linux/msi.h +10 -8
@@ -383,8 +383,8 @@ struct msi_domain_info;* @get_hwirq, @msi_init and @msi_free are callbacks used by the underlying * irqdomain. * -* @msi_check, @msi_prepare and @set_desc are callbacks used by -* msi_domain_alloc/free_irqs(). +* @msi_check, @msi_prepare and @set_desc are callbacks used by the +* msi_domain_alloc/free_irqs*() variants. * * @domain_alloc_irqs, @domain_free_irqs can be used to override the * default allocation/free functions (__msi_domain_alloc/free_irqs). This
@@ -392,11 +392,6 @@ struct msi_domain_info;* be wrapped into the regular irq domains concepts by mere mortals. This * allows to universally use msi_domain_alloc/free_irqs without having to * special case XEN all over the place. -* -* Contrary to other operations @domain_alloc_irqs and @domain_free_irqs -* are set to the default implementation if NULL and even when -* MSI_FLAG_USE_DEF_DOM_OPS is not set to avoid breaking existing users and -* because these callbacks are obviously mandatory. */ struct msi_domain_ops { irq_hw_number_t (*get_hwirq)(struct msi_domain_info *info,
@@ -496,14 +491,21 @@ int msi_domain_alloc_irqs_descs_locked(struct irq_domain *domain, struct device int nvec);int msi_domain_alloc_irqs (struct irq_domain *domain,struct device *dev,int nvec); +void msi_domain_free_irqs_descs_locked (struct irq_domain *domain,struct device *dev);void msi_domain_free_irqs (struct irq_domain *domain,struct device *dev); +int msi_domain_alloc_irqs_range_locked (struct device *dev,unsigned int domid, +unsigned int first,unsigned int last); +int msi_domain_alloc_irqs_range (struct device *dev,unsigned int domid, +unsigned int first,unsigned int last); +int msi_domain_alloc_irqs_all_locked (struct device *dev,unsigned int domid,int nirqs); + +void msi_domain_free_irqs_range_locked (struct device *dev,unsigned int domid,unsigned int first,unsigned int last);void msi_domain_free_irqs_range (struct device *dev,unsigned int domid,unsigned int first,unsigned int last); -void msi_domain_free_irqs_all_locked (struct device *dev,unsigned int domid);void msi_domain_free_irqs_all (struct device *dev,unsigned int domid);
kernel/irq/msi.c +136 -39
247 lines not on this page · raw message
PATCH v3 18/22 PCI/MSI: Use msi_domain_alloc/free_irqs_all_locked()
In reply to Thomas GleixnerSwitch to the new domain id aware interfaces to phase out the previous ones. No functional change.
--- drivers/pci/msi/irqdomain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/msi/irqdomain.c +2 -2
@@ -14,7 +14,7 @@ int pci_msi_setup_msi_irqs(struct pci_de domain =dev_get_msi_domain (&dev->dev);if (domain &&irq_domain_is_hierarchy (domain)) -return msi_domain_alloc_irqs_descs_locked (domain, &dev->dev, nvec); +return msi_domain_alloc_irqs_all_locked (&dev->dev,MSI_DEFAULT_DOMAIN , nvec);return pci_msi_legacy_setup_msi_irqs (dev, nvec, type); }
@@ -25,7 +25,7 @@ void pci_msi_teardown_msi_irqs(struct pc domain =dev_get_msi_domain (&dev->dev);if (domain &&irq_domain_is_hierarchy (domain)) { -msi_domain_free_irqs_descs_locked (domain, &dev->dev); +msi_domain_free_irqs_all_locked (&dev->dev,MSI_DEFAULT_DOMAIN ); }else {pci_msi_legacy_teardown_msi_irqs (dev);msi_free_msi_descs (&dev->dev);
[tip: irq/core] PCI/MSI: Use msi_domain_alloc/free_irqs_all_locked()
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: d3a11dee9f946daa6e66aca1bf8db93e9d4e02ec Gitweb: https://git.kernel.org/tip/d3a11dee9f946daa6e66aca1bf8db93e9d4e02ec Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:36 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:21:00 +01:00
PCI/MSI: Use msi_domain_alloc/free_irqs_all_locked()
Switch to the new domain id aware interfaces to phase out the previous ones. No functional change.
--- drivers/pci/msi/irqdomain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/msi/irqdomain.c +2 -2
@@ -14,7 +14,7 @@ int pci_msi_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) domain =dev_get_msi_domain (&dev->dev);if (domain &&irq_domain_is_hierarchy (domain)) -return msi_domain_alloc_irqs_descs_locked (domain, &dev->dev, nvec); +return msi_domain_alloc_irqs_all_locked (&dev->dev,MSI_DEFAULT_DOMAIN , nvec);return pci_msi_legacy_setup_msi_irqs (dev, nvec, type); }
@@ -25,7 +25,7 @@ void pci_msi_teardown_msi_irqs(struct pci_dev *dev) domain =dev_get_msi_domain (&dev->dev);if (domain &&irq_domain_is_hierarchy (domain)) { -msi_domain_free_irqs_descs_locked (domain, &dev->dev); +msi_domain_free_irqs_all_locked (&dev->dev,MSI_DEFAULT_DOMAIN ); }else {pci_msi_legacy_teardown_msi_irqs (dev);msi_free_msi_descs (&dev->dev);
PATCH v3 19/22 platform-msi: Switch to the domain id aware MSI interfaces
In reply to Thomas GleixnerFrom: Ahmed S. Darwish <[email protected]>
Switch to the new domain id aware interfaces to phase out the previous ones. No functional change.
--- drivers/base/platform-msi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/platform-msi.c +2 -2
@@ -213,7 +213,7 @@ int platform_msi_domain_alloc_irqs(strucif (err)return err; - err =msi_domain_alloc_irqs (dev->msi.domain, dev, nvec); + err =msi_domain_alloc_irqs_range (dev,MSI_DEFAULT_DOMAIN ,0 , nvec -1 );if (err)platform_msi_free_priv_data (dev);
@@ -227,7 +227,7 @@ EXPORT_SYMBOL_GPL(platform_msi_domain_al*/ void platform_msi_domain_free_irqs (struct device *dev) { -msi_domain_free_irqs (dev->msi.domain, dev); +msi_domain_free_irqs_all (dev,MSI_DEFAULT_DOMAIN );platform_msi_free_priv_data (dev); }EXPORT_SYMBOL_GPL (platform_msi_domain_free_irqs);
[tip: irq/core] platform-msi: Switch to the domain id aware MSI interfaces
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: b330ff9f0b03d6107ee941240ef63cc95374ff3d Gitweb: https://git.kernel.org/tip/b330ff9f0b03d6107ee941240ef63cc95374ff3d Author: Ahmed S. Darwish <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:38 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:21:00 +01:00
platform-msi: Switch to the domain id aware MSI interfaces
Switch to the new domain id aware interfaces to phase out the previous ones. No functional change.
--- drivers/base/platform-msi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/platform-msi.c +2 -2
@@ -213,7 +213,7 @@ int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec,if (err)return err; - err =msi_domain_alloc_irqs (dev->msi.domain, dev, nvec); + err =msi_domain_alloc_irqs_range (dev,MSI_DEFAULT_DOMAIN ,0 , nvec -1 );if (err)platform_msi_free_priv_data (dev);
@@ -227,7 +227,7 @@ EXPORT_SYMBOL_GPL(platform_msi_domain_alloc_irqs);*/ void platform_msi_domain_free_irqs (struct device *dev) { -msi_domain_free_irqs (dev->msi.domain, dev); +msi_domain_free_irqs_all (dev,MSI_DEFAULT_DOMAIN );platform_msi_free_priv_data (dev); }EXPORT_SYMBOL_GPL (platform_msi_domain_free_irqs);
PATCH v3 20/22 bus: fsl-mc-msi: Switch to domain id aware interfaces
In reply to Thomas GleixnerSwitch to the new domain id aware interfaces to phase out the previous ones.
Get rid of the MSI descriptor and domain checks as the core code detects these issues anyway.
No functional change.
--- drivers/bus/fsl-mc/fsl-mc-msi.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-)
drivers/bus/fsl-mc/fsl-mc-msi.c +3 -22
@@ -213,21 +213,8 @@ struct irq_domain *fsl_mc_find_msi_domaiint fsl_mc_msi_domain_alloc_irqs (struct device *dev,unsigned int irq_count) { -struct irq_domain *msi_domain; -int error; +int error =msi_setup_device_data (dev); - msi_domain =dev_get_msi_domain (dev); -if (!msi_domain) -return -EINVAL ; - - error =msi_setup_device_data (dev); -if (error) -return error; - -msi_lock_descs (dev); -if (msi_first_desc (dev,MSI_DESC_ALL )) - error = -EINVAL ; -msi_unlock_descs (dev);if (error)return error;
@@ -235,7 +222,7 @@ int fsl_mc_msi_domain_alloc_irqs(struct* NOTE: Calling this function will trigger the invocation of the * its_fsl_mc_msi_prepare() callback */ - error =msi_domain_alloc_irqs (msi_domain, dev, irq_count); + error =msi_domain_alloc_irqs_range (dev,MSI_DEFAULT_DOMAIN ,0 , irq_count -1 );if (error)dev_err (dev,"Failed to allocate IRQs\n" );
@@ -244,11 +231,5 @@ int fsl_mc_msi_domain_alloc_irqs(structvoid fsl_mc_msi_domain_free_irqs (struct device *dev) { -struct irq_domain *msi_domain; - - msi_domain =dev_get_msi_domain (dev); -if (!msi_domain) -return ; - -msi_domain_free_irqs (msi_domain, dev); +msi_domain_free_irqs_all (dev,MSI_DEFAULT_DOMAIN ); }
[tip: irq/core] bus: fsl-mc-msi: Switch to domain id aware interfaces
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 46a2bc8c7092cf277fb486c0629894ed904984a4 Gitweb: https://git.kernel.org/tip/46a2bc8c7092cf277fb486c0629894ed904984a4 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:40 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:21:00 +01:00
bus: fsl-mc-msi: Switch to domain id aware interfaces
Switch to the new domain id aware interfaces to phase out the previous ones.
Get rid of the MSI descriptor and domain checks as the core code detects these issues anyway.
No functional change.
--- drivers/bus/fsl-mc/fsl-mc-msi.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-)
drivers/bus/fsl-mc/fsl-mc-msi.c +3 -22
@@ -213,21 +213,8 @@ struct irq_domain *fsl_mc_find_msi_domain(struct device *dev)int fsl_mc_msi_domain_alloc_irqs (struct device *dev,unsigned int irq_count) { -struct irq_domain *msi_domain; -int error; - - msi_domain =dev_get_msi_domain (dev); -if (!msi_domain) -return -EINVAL ; - - error =msi_setup_device_data (dev); -if (error) -return error; +int error =msi_setup_device_data (dev); -msi_lock_descs (dev); -if (msi_first_desc (dev,MSI_DESC_ALL )) - error = -EINVAL ; -msi_unlock_descs (dev);if (error)return error;
@@ -235,7 +222,7 @@ int fsl_mc_msi_domain_alloc_irqs(struct device *dev, unsigned int irq_count)* NOTE: Calling this function will trigger the invocation of the * its_fsl_mc_msi_prepare() callback */ - error =msi_domain_alloc_irqs (msi_domain, dev, irq_count); + error =msi_domain_alloc_irqs_range (dev,MSI_DEFAULT_DOMAIN ,0 , irq_count -1 );if (error)dev_err (dev,"Failed to allocate IRQs\n" );
@@ -244,11 +231,5 @@ int fsl_mc_msi_domain_alloc_irqs(struct device *dev, unsigned int irq_count)void fsl_mc_msi_domain_free_irqs (struct device *dev) { -struct irq_domain *msi_domain; - - msi_domain =dev_get_msi_domain (dev); -if (!msi_domain) -return ; - -msi_domain_free_irqs (msi_domain, dev); +msi_domain_free_irqs_all (dev,MSI_DEFAULT_DOMAIN ); }
PATCH v3 21/22 oc: ti: ti_sci_inta_msi: Switch to domain id aware MSI functions
In reply to Thomas GleixnerFrom: Ahmed S. Darwish <[email protected]>
Switch to the new domain id aware interfaces to phase out the previous ones. Remove the domain check as it happens in the core code now.
No functional change.
--- drivers/soc/ti/ti_sci_inta_msi.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/soc/ti/ti_sci_inta_msi.c +2 -6
@@ -93,13 +93,8 @@ int ti_sci_inta_msi_domain_alloc_irqs(st struct ti_sci_resource *res) {struct platform_device *pdev =to_platform_device (dev); -struct irq_domain *msi_domain;int ret, nvec; - msi_domain =dev_get_msi_domain (dev); -if (!msi_domain) -return -EINVAL ; -if (pdev->id <0 )return -ENODEV ;
@@ -114,7 +109,8 @@ int ti_sci_inta_msi_domain_alloc_irqs(st goto unlock; } - ret =msi_domain_alloc_irqs_descs_locked (msi_domain, dev, nvec); +/* Use alloc ALL as it's unclear whether there are gaps in the indices */ + ret =msi_domain_alloc_irqs_all_locked (dev,MSI_DEFAULT_DOMAIN , nvec);if (ret)dev_err (dev,"Failed to allocate IRQs %d\n" , ret); unlock:
[tip: irq/core] oc: ti: ti_sci_inta_msi: Switch to domain id aware MSI functions
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 811b32811fbd1a5d3a9eb089ff1d34fa04ef2144 Gitweb: https://git.kernel.org/tip/811b32811fbd1a5d3a9eb089ff1d34fa04ef2144 Author: Ahmed S. Darwish <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:41 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:21:00 +01:00
oc: ti: ti_sci_inta_msi: Switch to domain id aware MSI functions
Switch to the new domain id aware interfaces to phase out the previous ones. Remove the domain check as it happens in the core code now.
No functional change.
--- drivers/soc/ti/ti_sci_inta_msi.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/soc/ti/ti_sci_inta_msi.c +2 -6
@@ -93,13 +93,8 @@ int ti_sci_inta_msi_domain_alloc_irqs(struct device *dev, struct ti_sci_resource *res) {struct platform_device *pdev =to_platform_device (dev); -struct irq_domain *msi_domain;int ret, nvec; - msi_domain =dev_get_msi_domain (dev); -if (!msi_domain) -return -EINVAL ; -if (pdev->id <0 )return -ENODEV ;
@@ -114,7 +109,8 @@ int ti_sci_inta_msi_domain_alloc_irqs(struct device *dev, goto unlock; } - ret =msi_domain_alloc_irqs_descs_locked (msi_domain, dev, nvec); +/* Use alloc ALL as it's unclear whether there are gaps in the indices */ + ret =msi_domain_alloc_irqs_all_locked (dev,MSI_DEFAULT_DOMAIN , nvec);if (ret)dev_err (dev,"Failed to allocate IRQs %d\n" , ret); unlock:
PATCH v3 22/22 genirq/msi: Remove unused alloc/free interfaces
In reply to Thomas GleixnerNow that all users are converted remove the old interfaces.
--- include/linux/msi.h | 7 ---- kernel/irq/msi.c | 73 ---------------------------------------------------- 2 files changed, 80 deletions(-)
include/linux/msi.h +0 -7
@@ -487,13 +487,6 @@ int msi_domain_set_affinity(struct irq_dstruct irq_domain *msi_create_irq_domain (struct fwnode_handle *fwnode,struct msi_domain_info *info,struct irq_domain *parent); -int msi_domain_alloc_irqs_descs_locked (struct irq_domain *domain,struct device *dev, -int nvec); -int msi_domain_alloc_irqs (struct irq_domain *domain,struct device *dev, -int nvec); - -void msi_domain_free_irqs_descs_locked (struct irq_domain *domain,struct device *dev); -void msi_domain_free_irqs (struct irq_domain *domain,struct device *dev);int msi_domain_alloc_irqs_range_locked (struct device *dev,unsigned int domid,unsigned int first,unsigned int last);
kernel/irq/msi.c +0 -73
85 lines not on this page · raw message
[tip: irq/core] genirq/msi: Remove unused alloc/free interfaces
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: c459f11f32a022d0f97694030419d16816275a9d Gitweb: https://git.kernel.org/tip/c459f11f32a022d0f97694030419d16816275a9d Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 25 Nov 2022 00:24:43 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 05 Dec 2022 19:21:00 +01:00
genirq/msi: Remove unused alloc/free interfaces
Now that all users are converted remove the old interfaces.
--- include/linux/msi.h | 7 +---- kernel/irq/msi.c | 73 +-------------------------------------------- 2 files changed, 80 deletions(-)
include/linux/msi.h +0 -7
@@ -487,13 +487,6 @@ int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask,struct irq_domain *msi_create_irq_domain (struct fwnode_handle *fwnode,struct msi_domain_info *info,struct irq_domain *parent); -int msi_domain_alloc_irqs_descs_locked (struct irq_domain *domain,struct device *dev, -int nvec); -int msi_domain_alloc_irqs (struct irq_domain *domain,struct device *dev, -int nvec); - -void msi_domain_free_irqs_descs_locked (struct irq_domain *domain,struct device *dev); -void msi_domain_free_irqs (struct irq_domain *domain,struct device *dev);int msi_domain_alloc_irqs_range_locked (struct device *dev,unsigned int domid,unsigned int first,unsigned int last);
kernel/irq/msi.c +0 -73
85 lines not on this page · raw message
Quoted 9 lines
From: Thomas Gleixner <[email protected]>
Sent: Friday, November 25, 2022 7:24 AMChanges vs. V2:
- Rework the xarray storage into per domain storage (Marc)
@Kevin: I did not pick up your Reviewed-by tag due to these changes.
The incremental change looks good to me:
Just one nit.
kernel/irq/msi.c static bool msi_ctrl_range_valid(struct device *dev, struct msi_ctrl *ctrl) · line 159
Quoted 3 lines
kernel/irq/msi.c +1
-1-xa_for_each_range (xa, idx, desc, ctrl->first + base, ctrl->last + base) { + xa = &dev->msi.data->__domains[ctrl->domid].store;
Better to have a macro here given multiple references on the store in following lines.
Quoted 7 lines · Thomas Gleixner
This is V3 of the second part of the effort to provide support for per device MSI interrupt domains.
Version 2 of this second part can be found here:
Bandwidth is lacking to review such a series (let alone 3) in details, but the direction of travel is the right one (per-device, per-bus MSI domains are the natural way to deal with resources managed at the device level).
I'm sure we'll find issues along the way, but this code is better in the kernel than outside, so:
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.