irqdomain/debugfs: Fix uses of irq_domain_alloc_fwnode
Subsystems (9)
Marc Zyngier
maintainercover irqdomain/debugfs: Fix uses of irq_domain_alloc_fwnode
I recently noticed that all irq_domain_alloc_fwnode were passing a VA to it, which is unfortunate as this is designed to appear in debugfs (and we don't like to leak VAs). Disaster was avoided thanks to our ____ptrval____ friend, but it remains that the whole thing is pretty useless if you have more than a single domain (they all have the same name and creation fails).
In order to sort it out, change all users of irq_domain_alloc_fwnode to pass the PA of the irqchip the domain will be associated with. One notable exception is the HyperV PCI controller driver which has no PA to associate with. This is solved by using a named fwnode instead, using the device GUID.
Finally, irq_domain_alloc_fwnode() is changed to pa a pionter to a PA, which can be safely advertised in debugfs.
Marc Zyngier (8):
irqchip/gic-v3: Register the distributor's PA instead of its VA in
fwnode
irqchip/gic-v3-its: Register the ITS' PA instead of its VA in fwnode irqchip/gic: Register the distributor's PA instead of its VA in fwnode irqchip/gic-v2m: Register the frame's PA instead of its VA in fwnode irqchip/ixp4xx: Register the base PA instead of its VA in fwnode gpio/ixp4xx: Register the base PA instead of its VA in fwnode
PCI: hv: Allocate a named fwnode instead of an address-based one irqdomain/debugfs: Use PAs to generate fwnode names
drivers/gpio/gpio-ixp4xx.c | 2 +- drivers/irqchip/irq-gic-v2m.c | 2 +- drivers/irqchip/irq-gic-v3-its.c | 2 +- drivers/irqchip/irq-gic-v3.c | 2 +- drivers/irqchip/irq-gic.c | 2 +- drivers/irqchip/irq-ixp4xx.c | 2 +- drivers/pci/controller/pci-hyperv.c | 10 +++++++++- include/linux/irqdomain.h | 6 +++--- kernel/irq/irqdomain.c | 9 +++++---- 9 files changed, 23 insertions(+), 14 deletions(-)
Signature · 1 line
2.20.1
Marc Zyngier
maintainerPATCH 1/8 irqchip/gic-v3: Register the distributor's PA instead of its VA in fwnode
Do not expose the distributor's VA (it appears in debugfs). Instead, record the PA, which at least can be used to precisely identify the associated irqchip and domain.
--- drivers/irqchip/irq-gic-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +1 -1
@@ -1845,7 +1845,7 @@ gic_acpi_init(struct acpi_subtable_header *header, const unsigned long end)if (err) goto out_redist_unmap; - domain_handle =irq_domain_alloc_fwnode (acpi_data.dist_base); + domain_handle =irq_domain_alloc_fwnode (&dist->base_address);if (!domain_handle) { err = -ENOMEM ; goto out_redist_unmap;
Signature · 1 line
2.20.1
Marc Zyngier
maintainerPATCH 2/8 irqchip/gic-v3-its: Register the ITS' PA instead of its VA in fwnode
In reply to Marc ZyngierDo not expose the ITS' VA (it appears in debugfs). Instead, record the PA, which at least can be used to precisely identify the associated irqchip and domain.
--- drivers/irqchip/irq-gic-v3-its.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +1 -1
@@ -3921,7 +3921,7 @@ static int __init gic_acpi_parse_madt_its(union acpi_subtable_headers *header, res.end = its_entry->base_address +ACPI_GICV3_ITS_MEM_SIZE -1 ; res.flags =IORESOURCE_MEM ; - dom_handle =irq_domain_alloc_fwnode ((void *)its_entry->base_address); + dom_handle =irq_domain_alloc_fwnode (&res.start);if (!dom_handle) {pr_err ("ITS@%pa: Unable to allocate GICv3 ITS domain token\n" , &res.start);
Signature · 1 line
2.20.1
Marc Zyngier
maintainerPATCH 3/8 irqchip/gic: Register the distributor's PA instead of its VA in fwnode
In reply to Marc ZyngierDo not expose the distributor's VA (it appears in debugfs). Instead, record the PA, which at least can be used to precisely identify the associated irqchip and domain.
--- drivers/irqchip/irq-gic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic.c +1 -1
@@ -1627,7 +1627,7 @@ static int __init gic_v2_acpi_init(struct acpi_subtable_header *header,/* * Initialize GIC instance zero (no multi-GIC support). */ - domain_handle =irq_domain_alloc_fwnode (gic->raw_dist_base); + domain_handle =irq_domain_alloc_fwnode (&dist->base_address);if (!domain_handle) {pr_err ("Unable to allocate domain handle\n" );gic_teardown (gic);
Signature · 1 line
2.20.1
Marc Zyngier
maintainerPATCH 4/8 irqchip/gic-v2m: Register the frame's PA instead of its VA in fwnode
In reply to Marc ZyngierDo not expose the frame's VA (it appears in debugfs). Instead, record the PA, which at least can be used to precisely identify the associated irqchip and domain.
--- drivers/irqchip/irq-gic-v2m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v2m.c +1 -1
@@ -525,7 +525,7 @@ acpi_parse_madt_msi(union acpi_subtable_headers *header, spi_start, nr_spis); } - fwnode =irq_domain_alloc_fwnode ((void *)m->base_address); + fwnode =irq_domain_alloc_fwnode (&res.start);if (!fwnode) {pr_err ("Unable to allocate GICv2m domain token\n" );return -EINVAL ;
Signature · 1 line
2.20.1
Marc Zyngier
maintainerPATCH 5/8 irqchip/ixp4xx: Register the base PA instead of its VA in fwnode
In reply to Marc ZyngierDo not expose the base VA (it appears in debugfs). Instead, record the PA, which at least can be used to precisely identify the associated irqchip and domain.
--- drivers/irqchip/irq-ixp4xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-ixp4xx.c +1 -1
@@ -319,7 +319,7 @@ void __init ixp4xx_irq_init(resource_size_t irqbase,pr_crit ("IXP4XX: could not ioremap interrupt controller\n" );return ; } - fwnode =irq_domain_alloc_fwnode (base); + fwnode =irq_domain_alloc_fwnode (&irqbase);if (!fwnode) {pr_crit ("IXP4XX: no domain handle\n" );return ;
Signature · 1 line
2.20.1
Marc Zyngier
maintainerPATCH 6/8 gpio/ixp4xx: Register the base PA instead of its VA in fwnode
In reply to Marc ZyngierDo not expose the base VA (it appears in debugfs). Instead, record the PA, which at least can be used to precisely identify the associated irqchip and domain.
--- drivers/gpio/gpio-ixp4xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-ixp4xx.c +1 -1
@@ -400,7 +400,7 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev) g->fwnode =of_node_to_fwnode (np); }else { parent =ixp4xx_get_irq_domain (); - g->fwnode =irq_domain_alloc_fwnode (g->base); + g->fwnode =irq_domain_alloc_fwnode (&res->start);if (!g->fwnode) {dev_err (dev,"no domain base\n" );return -ENODEV ;
Signature · 1 line
2.20.1
Re: [PATCH 6/8] gpio/ixp4xx: Register the base PA instead of its VA in fwnode
Quoted 5 lines · Marc Zyngier
Do not expose the base VA (it appears in debugfs). Instead, record the PA, which at least can be used to precisely identify the associated irqchip and domain.
Signed-off-by Marc Zyngier <[email protected]>
Please apply this directly to the irq subsystem tree with the rest of the fixes.
Yours,
Linus Walleij
Marc Zyngier
maintainerPATCH 7/8 PCI: hv: Allocate a named fwnode instead of an address-based one
In reply to Marc ZyngierTo allocate its fwnode that is then used to allocate an irqdomain, the driver uses irq_domain_alloc_fwnode(), passing it a VA as an identifier. This is a rather bad idea, as this address ends up published in debugfs (and we want to move away from VAs there anyway).
Instead, let's allocate a named fwnode by using the device GUID as an identifier. It is allegedly unique, and can be traced back to the original device.
--- drivers/pci/controller/pci-hyperv.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/pci/controller/pci-hyperv.c +9 -1
@@ -2521,6 +2521,7 @@ static int hv_pci_probe(struct hv_device *hdev, const struct hv_vmbus_device_id *dev_id) {struct hv_pcibus_device *hbus; +char *name;int ret;/*
@@ -2589,7 +2590,14 @@ static int hv_pci_probe(struct hv_device *hdev, goto free_config; } - hbus->sysdata.fwnode =irq_domain_alloc_fwnode (hbus); + name =kasprintf ("%pUL" , &hdev->dev_instance); +if (!name) { + ret = -ENOMEM ; + goto unmap; + } + + hbus->sysdata.fwnode =irq_domain_alloc_named_fwnode (name); +kfree (name);if (!hbus->sysdata.fwnode) { ret = -ENOMEM ; goto unmap;
Signature · 1 line
2.20.1
Marc Zyngier
maintainerRe: [PATCH 7/8] PCI: hv: Allocate a named fwnode instead of an address-based one
Quoted 28 lines · Marc Zyngier
To allocate its fwnode that is then used to allocate an irqdomain, the driver uses
irq_domain_alloc_fwnode(), passing it a VA as an identifier. This is a rather bad idea, as this address ends up published in debugfs (and we want to move away from VAs there anyway).Instead, let's allocate a named fwnode by using the device GUID as an identifier. It is allegedly unique, and can be traced back to the original device.
Signed-off-by Marc Zyngier <[email protected]>--- drivers/pci/controller/pci-hyperv.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/pci/controller/pci-hyperv.c +1
-0@@ -2521,6 +2521,7 @@ static int hv_pci_probe(struct hv_device *hdev, const struct hv_vmbus_device_id *dev_id) {struct hv_pcibus_device *hbus; +char *name;int ret;/*
drivers/pci/controller/pci-hyperv.c static int hv_pci_probe(struct hv_device *hdev, · line 2593
Quoted 5 lines
drivers/pci/controller/pci-hyperv.c +1
-1@@ -2589,7 +2590,14 @@ static int hv_pci_probe(struct hv_device *hdev, goto free_config; } - hbus->sysdata.fwnode =irq_domain_alloc_fwnode (hbus); + name =kasprintf ("%pUL" , &hdev->dev_instance);
Of course, this is bogus. It needs a GFP_KERNEL as the first parameter.
/me adds HYPERV to .config, and fixes it locally.
M.
Signature · 1 line
Jazz is not dead, it just smells funny...
Marc Zyngier
maintainerPATCH 8/8 irqdomain/debugfs: Use PAs to generate fwnode names
In reply to Marc ZyngierBooting a large arm64 server (HiSi D05) leads to the following shouting at boot time:
[ 20.722132] debugfs: File 'irqchip@(____ptrval____)-3' in directory 'domains' already present! [ 20.730851] debugfs: File 'irqchip@(____ptrval____)-3' in directory 'domains' already present! [ 20.739560] debugfs: File 'irqchip@(____ptrval____)-3' in directory 'domains' already present! [ 20.748267] debugfs: File 'irqchip@(____ptrval____)-3' in directory 'domains' already present! [ 20.756975] debugfs: File 'irqchip@(____ptrval____)-3' in directory 'domains' already present! [ 20.765683] debugfs: File 'irqchip@(____ptrval____)-3' in directory 'domains' already present! [ 20.774391] debugfs: File 'irqchip@(____ptrval____)-3' in directory 'domains' already present!
and many more... Evidently, we expect something a bit more informative than ____ptrval____, and certainly we want all of our domains, not just the first one.
For that, turn the %p used to generate the fwnode name into something that won't be repainted (%pa). Given that we've now fixed all users to pass a pointer to a PA, it will actually do the right thing.
--- include/linux/irqdomain.h | 6 +++--- kernel/irq/irqdomain.c | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-)
include/linux/irqdomain.h +3 -3
@@ -220,7 +220,7 @@ static inline struct device_node *irq_domain_get_of_node(struct irq_domain *d)#ifdef CONFIG_IRQ_DOMAIN struct fwnode_handle *__irq_domain_alloc_fwnode (unsigned int type,int id, -const char *name,void *data); +const char *name,phys_addr_t *pa);enum { IRQCHIP_FWNODE_REAL,
@@ -241,9 +241,9 @@ struct fwnode_handle *irq_domain_alloc_named_id_fwnode(const char *name, int id) NULL); } -static inline struct fwnode_handle *irq_domain_alloc_fwnode (void *data) +static inline struct fwnode_handle *irq_domain_alloc_fwnode (phys_addr_t *pa) { -return __irq_domain_alloc_fwnode (IRQCHIP_FWNODE_REAL ,0 ,NULL , data); +return __irq_domain_alloc_fwnode (IRQCHIP_FWNODE_REAL ,0 ,NULL , pa); }void irq_domain_free_fwnode (struct fwnode_handle *fwnode);
kernel/irq/irqdomain.c +5 -4
@@ -31,7 +31,7 @@ struct irqchip_fwid {struct fwnode_handle fwnode;unsigned int type;char *name; -void *data; +phys_addr_t *pa; };#ifdef CONFIG_GENERIC_IRQ_DEBUGFS
@@ -62,7 +62,8 @@ EXPORT_SYMBOL_GPL(irqchip_fwnode_ops);* domain struct. */ struct fwnode_handle *__irq_domain_alloc_fwnode (unsigned int type,int id, -const char *name,void *data) +const char *name, +phys_addr_t *pa) {struct irqchip_fwid *fwid;char *n;
@@ -77,7 +78,7 @@ struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id, n =kasprintf (GFP_KERNEL ,"%s-%d" , name, id);break ;default : - n =kasprintf (GFP_KERNEL ,"irqchip@%p" , data); + n =kasprintf (GFP_KERNEL ,"irqchip@%pa" , pa);break ; }
@@ -89,7 +90,7 @@ struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id, fwid->type = type; fwid->name = n; - fwid->data = data; + fwid->pa = pa; fwid->fwnode.ops = &irqchip_fwnode_ops;return &fwid->fwnode; }
Signature · 1 line
2.20.1
Quoted 7 lines · Marc Zyngier
I recently noticed that all
irq_domain_alloc_fwnodewere passing a VA to it, which is unfortunate as this is designed to appear in debugfs (and we don't like to leak VAs). Disaster was avoided thanks to our____ptrval____friend, but it remains that the whole thing is pretty useless if you have more than a single domain (they all have the same name and creation fails).
Quoted 8 lines
In order to sort it out, change all users of
irq_domain_alloc_fwnodeto pass the PA of the irqchip the domain will be associated with. One notable exception is the HyperV PCI controller driver which has no PA to associate with. This is solved by using a named fwnode instead, using the device GUID.Finally,
irq_domain_alloc_fwnode()is changed to pa a pionter to a PA, which can be safely advertised in debugfs.