Skip to contentSkip to conversation

Allow for qcom-pdc, pinctrl-msm and qcom-scm drivers to be loadable as modules

PATCH Superseded John Stultz 7 participants 29 messages Jun 25, 2020 – Oct 31, 2020

Subsystems (9)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Allow for qcom-pdc, pinctrl-msm and qcom-scm drivers to be loadable as modules

This patch series provides exports and config tweaks to allow the qcom-pdc, pinctrl-msm and qcom-scm drivers to be able to be configured as permement modules (particularlly useful for the Android Generic Kernel Image efforts).

Feedback would be appreciated!

New in v2:
* Fix up MSM_PINCTRL Kconfig dependency logic so we match QCOM_SCM.
* Minor tweaks and corrections suggested by Bjorn and Maulik

thanks
-john

Cc Andy Gross <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jason Cooper <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Lina Iyer <[email protected]>
Cc Maulik Shah <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

John Stultz (5):
irq: irqdomain: Export irq_domain_update_bus_token
irq: irqchip: Export irq_chip_retrigger_hierarchy and
irq_chip_set_vcpu_affinity_parent
irqchip: Allow QCOM_PDC to be loadable as a permanent module
pinctrl: qcom: Allow pinctrl-msm code to be loadable as a module
firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a
permenent module

 drivers/firmware/Kconfig           |  2 +-
 drivers/firmware/Makefile          |  3 ++-
 drivers/firmware/qcom_scm.c        |  4 ++++
 drivers/iommu/Kconfig              |  2 ++
 drivers/irqchip/Kconfig            |  2 +-
 drivers/irqchip/qcom-pdc.c         | 31 ++++++++++++++++++++++++++++++
 drivers/pinctrl/qcom/Kconfig       | 24 ++++++++++++++++++++++-
 drivers/pinctrl/qcom/pinctrl-msm.c |  2 ++
 kernel/irq/chip.c                  |  3 ++-
 kernel/irq/irqdomain.c             |  1 +
 10 files changed, 69 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/5 irq: irqdomain: Export irq_domain_update_bus_token

Add export for irq_domain_update_bus_token() so that we can allow drivers like the qcom-pdc driver to be loadable as a module.

Cc Andy Gross <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jason Cooper <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Maulik Shah <[email protected]>
Cc Lina Iyer <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 kernel/irq/irqdomain.c | 1 +
 1 file changed, 1 insertion(+)
kernel/irq/irqdomain.c +1 -0
index a4c2c915511d..ca974d965fda 100644
@@ -281,6 +281,7 @@ void irq_domain_update_bus_token(struct irq_domain *domain,
 
 	mutex_unlock(&irq_domain_mutex);
 }
+EXPORT_SYMBOL_GPL(irq_domain_update_bus_token);
 
 /**
  * irq_domain_add_simple() - Register an irq_domain and optionally map a range of irqs
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/5 irq: irqchip: Export irq_chip_retrigger_hierarchy and irq_chip_set_vcpu_affinity_parent

In reply to John Stultz

Add EXPORT_SYMBOL_GPL entries for irq_chip_retrigger_hierarchy() and irq_chip_set_vcpu_affinity_parent() so that we can allow drivers like the qcom-pdc driver to be loadable as a module.

Cc Andy Gross <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jason Cooper <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Maulik Shah <[email protected]>
Cc Lina Iyer <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 kernel/irq/chip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/irq/chip.c +2 -1
index 41e7e37a0928..ba6ce66d7ed6 100644
@@ -1478,6 +1478,7 @@ int irq_chip_retrigger_hierarchy(struct irq_data *data)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(irq_chip_retrigger_hierarchy);
 
 /**
  * irq_chip_set_vcpu_affinity_parent - Set vcpu affinity on the parent interrupt
@@ -1492,7 +1493,7 @@ int irq_chip_set_vcpu_affinity_parent(struct irq_data *data, void *vcpu_info)
 
 	return -ENOSYS;
 }
-
+EXPORT_SYMBOL_GPL(irq_chip_set_vcpu_affinity_parent);
 /**
  * irq_chip_set_wake_parent - Set/reset wake-up on the parent interrupt
  * @data:	Pointer to interrupt specific data
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 3/5 irqchip: Allow QCOM_PDC to be loadable as a permanent module

In reply to John Stultz

Allows qcom-pdc driver to be loaded as a permanent module

Also, due to the fact that IRQCHIP_DECLARE becomes a no-op when building as a module, we have to add the platform driver hooks explicitly.

Thanks to Saravana for his help on pointing out the IRQCHIP_DECLARE issue and guidance on a solution.

Cc Andy Gross <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jason Cooper <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Maulik Shah <[email protected]>
Cc Lina Iyer <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---
v2: Fix spelling, include order and set suppress_bind_attrs
suggested by Maulik Shah

---
 drivers/irqchip/Kconfig    |  2 +-
 drivers/irqchip/qcom-pdc.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
drivers/irqchip/Kconfig +1 -1
index 29fead208cad..12765bed08f9 100644
@@ -425,7 +425,7 @@ config GOLDFISH_PIC
          for Goldfish based virtual platforms.
 
 config QCOM_PDC
-	bool "QCOM PDC"
+	tristate "QCOM PDC"
 	depends on ARCH_QCOM
 	select IRQ_DOMAIN_HIERARCHY
 	help
drivers/irqchip/qcom-pdc.c +31 -0
index 6ae9e1f0819d..3fee8b655da1 100644
@@ -11,9 +11,11 @@
 #include <linux/irqdomain.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/of_device.h>
+#include <linux/of_irq.h>
 #include <linux/soc/qcom/irq.h>
 #include <linux/spinlock.h>
 #include <linux/slab.h>
@@ -430,4 +432,33 @@ static int qcom_pdc_init(struct device_node *node, struct device_node *parent)
 	return ret;
 }
 
+#ifdef MODULE
+static int qcom_pdc_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct device_node *parent = of_irq_find_parent(np);
+
+	return qcom_pdc_init(np, parent);
+}
+
+static const struct of_device_id qcom_pdc_match_table[] = {
+	{ .compatible = "qcom,pdc" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, qcom_pdc_match_table);
+
+static struct platform_driver qcom_pdc_driver = {
+	.probe = qcom_pdc_probe,
+	.driver = {
+		.name = "qcom-pdc",
+		.of_match_table = qcom_pdc_match_table,
+		.suppress_bind_attrs = true,
+	},
+};
+module_platform_driver(qcom_pdc_driver);
+#else
 IRQCHIP_DECLARE(qcom_pdc, "qcom,pdc", qcom_pdc_init);
+#endif
+
+MODULE_DESCRIPTION("Qualcomm Technologies, Inc. Power Domain Controller");
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH v2 3/5] irqchip: Allow QCOM_PDC to be loadable as a permanent module

Quoting John Stultz (2020-06-24 17:10:37)

Quoted 24 lines
drivers/irqchip/qcom-pdc.c +16 -0
index 6ae9e1f0819d..3fee8b655da1 100644
@@ -430,4 +432,33 @@ static int qcom_pdc_init(struct device_node *node, struct device_node *parent)
        return ret;
 }
 
+#ifdef MODULE
+static int qcom_pdc_probe(struct platform_device *pdev)
+{
+       struct device_node *np = pdev->dev.of_node;
+       struct device_node *parent = of_irq_find_parent(np);
+
+       return qcom_pdc_init(np, parent);
+}
+
+static const struct of_device_id qcom_pdc_match_table[] = {
+       { .compatible = "qcom,pdc" },
+       {}
+};
+MODULE_DEVICE_TABLE(of, qcom_pdc_match_table);
+
+static struct platform_driver qcom_pdc_driver = {

drivers/irqchip/qcom-pdc.c static int qcom_pdc_init(struct device_node *node, struct device_node *parent) · line 460

Quoted 10 lines
drivers/irqchip/qcom-pdc.c +9 -0
+       .probe = qcom_pdc_probe,
+       .driver = {
+               .name = "qcom-pdc",
+               .of_match_table = qcom_pdc_match_table,
+               .suppress_bind_attrs = true,
+       },
+};
+module_platform_driver(qcom_pdc_driver);
+#else
 IRQCHIP_DECLARE(qcom_pdc, "qcom,pdc", qcom_pdc_init);

Is there any reason to use IRQCHIP_DECLARE if this can work as a platform device driver?

Quoted 4 lines
drivers/irqchip/qcom-pdc.c +4 -0
+#endif
+
+MODULE_DESCRIPTION("Qualcomm Technologies, Inc. Power Domain Controller");
+MODULE_LICENSE("GPL v2");
#5 lore raw

Re: [PATCH v2 3/5] irqchip: Allow QCOM_PDC to be loadable as a permanent module

Quoted 31 lines · Stephen Boyd

Quoting John Stultz (2020-06-24 17:10:37)

Quoted 29 lines
drivers/irqchip/qcom-pdc.c +21 -0
index 6ae9e1f0819d..3fee8b655da1 100644
@@ -430,4 +432,33 @@ static int qcom_pdc_init(struct device_node *node, struct device_node *parent)
        return ret;
 }
 
+#ifdef MODULE
+static int qcom_pdc_probe(struct platform_device *pdev)
+{
+       struct device_node *np = pdev->dev.of_node;
+       struct device_node *parent = of_irq_find_parent(np);
+
+       return qcom_pdc_init(np, parent);
+}
+
+static const struct of_device_id qcom_pdc_match_table[] = {
+       { .compatible = "qcom,pdc" },
+       {}
+};
+MODULE_DEVICE_TABLE(of, qcom_pdc_match_table);
+
+static struct platform_driver qcom_pdc_driver = {
+       .probe = qcom_pdc_probe,
+       .driver = {
+               .name = "qcom-pdc",
+               .of_match_table = qcom_pdc_match_table,
+               .suppress_bind_attrs = true,
Quoted 9 lines

drivers/irqchip/qcom-pdc.c static int qcom_pdc_init(struct device_node *node, struct device_node *parent) · line 460

Quoted 5 lines
drivers/irqchip/qcom-pdc.c +4 -0
+       },
+};
+module_platform_driver(qcom_pdc_driver);
+#else
 IRQCHIP_DECLARE(qcom_pdc, "qcom,pdc", qcom_pdc_init);

Is there any reason to use IRQCHIP_DECLARE if this can work as a platform device driver?

Hey! Thanks so much for the review!

Mostly it was done this way to minimize the change in the non-module case. But if you'd rather avoid the #ifdefery I'll respin it without.

thanks
-john

#6 lore raw

Re: [PATCH v2 3/5] irqchip: Allow QCOM_PDC to be loadable as a permanent module

Quoted 43 lines · John Stultz
Quoted 31 lines · Stephen Boyd

Quoting John Stultz (2020-06-24 17:10:37)

Quoted 29 lines
drivers/irqchip/qcom-pdc.c +21 -0
index 6ae9e1f0819d..3fee8b655da1 100644
@@ -430,4 +432,33 @@ static int qcom_pdc_init(struct device_node *node, struct device_node *parent)
        return ret;
 }
 
+#ifdef MODULE
+static int qcom_pdc_probe(struct platform_device *pdev)
+{
+       struct device_node *np = pdev->dev.of_node;
+       struct device_node *parent = of_irq_find_parent(np);
+
+       return qcom_pdc_init(np, parent);
+}
+
+static const struct of_device_id qcom_pdc_match_table[] = {
+       { .compatible = "qcom,pdc" },
+       {}
+};
+MODULE_DEVICE_TABLE(of, qcom_pdc_match_table);
+
+static struct platform_driver qcom_pdc_driver = {
+       .probe = qcom_pdc_probe,
+       .driver = {
+               .name = "qcom-pdc",
+               .of_match_table = qcom_pdc_match_table,
+               .suppress_bind_attrs = true,
Quoted 9 lines

drivers/irqchip/qcom-pdc.c static int qcom_pdc_init(struct device_node *node, struct device_node *parent) · line 460

Quoted 5 lines
drivers/irqchip/qcom-pdc.c +4 -0
+       },
+};
+module_platform_driver(qcom_pdc_driver);
+#else
 IRQCHIP_DECLARE(qcom_pdc, "qcom,pdc", qcom_pdc_init);

Is there any reason to use IRQCHIP_DECLARE if this can work as a platform device driver?

Quoted 4 lines

Hey! Thanks so much for the review!

Mostly it was done this way to minimize the change in the non-module case. But if you'd rather avoid the #ifdefery I'll respin it without.

That would certainly be my own preference. In general, IRQCHIP_DECLARE and platform drivers should be mutually exclusive in the same driver:
if you can delay the probing and have it as a proper platform device, then this should be the one true way.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#7 lore raw

Re: [PATCH v2 3/5] irqchip: Allow QCOM_PDC to be loadable as a permanent module

Quoting Marc Zyngier (2020-06-27 02:37:47)

Quoted 12 lines
Quoted 10 lines · John Stultz
Quoted 5 lines · Stephen Boyd

Is there any reason to use IRQCHIP_DECLARE if this can work as a platform device driver?

Hey! Thanks so much for the review!

Quoted 8 lines
Quoted 2 lines

Mostly it was done this way to minimize the change in the non-module case. But if you'd rather avoid the #ifdefery I'll respin it without.

That would certainly be my own preference. In general, IRQCHIP_DECLARE and platform drivers should be mutually exclusive in the same driver:
if you can delay the probing and have it as a proper platform device, then this should be the one true way.

Does it work? I haven't looked in detail but I worry that the child irqdomain (i.e. pinctrl-msm) would need to delay probing until this parent irqdomain is registered. Or has the hierarchical irqdomain code been updated to handle the parent child relationship and wait for things to probe or be loaded?

#8 lore raw

Re: [PATCH v2 3/5] irqchip: Allow QCOM_PDC to be loadable as a permanent module

Quoted 22 lines · Stephen Boyd

Quoting Marc Zyngier (2020-06-27 02:37:47)

Quoted 12 lines
Quoted 10 lines · John Stultz
Quoted 5 lines · Stephen Boyd

Is there any reason to use IRQCHIP_DECLARE if this can work as a platform device driver?

Hey! Thanks so much for the review!

Quoted 8 lines
Quoted 2 lines

Mostly it was done this way to minimize the change in the non-module case. But if you'd rather avoid the #ifdefery I'll respin it without.

That would certainly be my own preference. In general, IRQCHIP_DECLARE and platform drivers should be mutually exclusive in the same driver:
if you can delay the probing and have it as a proper platform device, then this should be the one true way.

Quoted 5 lines

Does it work? I haven't looked in detail but I worry that the child irqdomain (i.e. pinctrl-msm) would need to delay probing until this parent irqdomain is registered. Or has the hierarchical irqdomain code been updated to handle the parent child relationship and wait for things to probe or be loaded?

So I can't say I know the underlying hardware particularly well, but I've been using this successfully on the Dragonboard 845c with both static builds as well as module enabled builds.
And the same patch has been in the android-mainline and android-5.4 kernels for a while without objections from QCOM.

As to the probe ordering question, Saravana can maybe speak in more detail if it's involved in this case but the fw_devlink code has addressed many of these sorts of ordering issues.
However, I'm not sure if I'm lucking into the right probe order, as we have been able to boot android-mainline w/ both fw_devlink=on and fw_devlink=off (though in the =off case, we need deferred_probe_timeout=30 to give us a bit more time for modules to load after init starts).

thanks
-john

#9 lore raw

Re: [PATCH v2 3/5] irqchip: Allow QCOM_PDC to be loadable as a permanent module

Quoting John Stultz (2020-07-10 15:44:18)

Quoted 14 lines · Stephen Boyd
Quoted 6 lines

Does it work? I haven't looked in detail but I worry that the child irqdomain (i.e. pinctrl-msm) would need to delay probing until this parent irqdomain is registered. Or has the hierarchical irqdomain code been updated to handle the parent child relationship and wait for things to probe or be loaded?

So I can't say I know the underlying hardware particularly well, but I've been using this successfully on the Dragonboard 845c with both static builds as well as module enabled builds.
And the same patch has been in the android-mainline and android-5.4 kernels for a while without objections from QCOM.

Quoted 9 lines

As to the probe ordering question, Saravana can maybe speak in more detail if it's involved in this case but the fw_devlink code has addressed many of these sorts of ordering issues.
However, I'm not sure if I'm lucking into the right probe order, as we have been able to boot android-mainline w/ both fw_devlink=on and fw_devlink=off (though in the =off case, we need deferred_probe_timeout=30 to give us a bit more time for modules to load after init starts).

Ok I looked at the code (sorry for not checking earlier) and I see this in msm_gpio_init()

        np = of_parse_phandle(pctrl->dev->of_node, "wakeup-parent", 0);
        if (np) {
                chip->irq.parent_domain = irq_find_matching_host(np,
                                                 DOMAIN_BUS_WAKEUP);
                of_node_put(np);
                if (!chip->irq.parent_domain)
                        return -EPROBE_DEFER;

so it looks like we'll probe defer the pinctrl driver until the pdc module loads. Meaning it should work to have pinctrl builtin and pdc as a module.

#10 lore raw

Re: [PATCH v2 3/5] irqchip: Allow QCOM_PDC to be loadable as a permanent module

Quoted 37 lines · Stephen Boyd

Quoting John Stultz (2020-07-10 15:44:18)

Quoted 14 lines · Stephen Boyd
Quoted 6 lines

Does it work? I haven't looked in detail but I worry that the child irqdomain (i.e. pinctrl-msm) would need to delay probing until this parent irqdomain is registered. Or has the hierarchical irqdomain code been updated to handle the parent child relationship and wait for things to probe or be loaded?

So I can't say I know the underlying hardware particularly well, but I've been using this successfully on the Dragonboard 845c with both static builds as well as module enabled builds.
And the same patch has been in the android-mainline and android-5.4 kernels for a while without objections from QCOM.

Quoted 9 lines

As to the probe ordering question, Saravana can maybe speak in more detail if it's involved in this case but the fw_devlink code has addressed many of these sorts of ordering issues.
However, I'm not sure if I'm lucking into the right probe order, as we have been able to boot android-mainline w/ both fw_devlink=on and fw_devlink=off (though in the =off case, we need deferred_probe_timeout=30 to give us a bit more time for modules to load after init starts).

Ok I looked at the code (sorry for not checking earlier) and I see this in msm_gpio_init()

        np = of_parse_phandle(pctrl->dev->of_node, "wakeup-parent", 0);
        if (np) {
                chip->irq.parent_domain = irq_find_matching_host(np,
                                                 DOMAIN_BUS_WAKEUP);
                of_node_put(np);
                if (!chip->irq.parent_domain)
                        return -EPROBE_DEFER;
Quoted 2 lines

so it looks like we'll probe defer the pinctrl driver until the pdc module loads. Meaning it should work to have pinctrl builtin and pdc as a module.

What I hope is that eventually fw_devlink will become the norm (on by default), and that probe deferral will become a thing of the past.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#11 lore raw

PATCH v2 4/5 pinctrl: qcom: Allow pinctrl-msm code to be loadable as a module

In reply to John Stultz

Tweaks to allow pinctrl-msm code to be loadable as a module. This is needed in order to support having the qcom-scm driver, which pinctrl-msm calls into, configured as a module.

This requires that we tweak Kconfigs selecting PINCTRL_MSM to also depend on QCOM_SCM || QCOM_SCM=n so that we match the module setting of QCOM_SCM.

Cc Andy Gross <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jason Cooper <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Maulik Shah <[email protected]>
Cc Lina Iyer <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---
v2:
* Module description and whitespace fixes suggested by Bjorn
* Added QCOM_SCM || QCOM_SCM=n bits on Kconfigs selecting PINCTRL_MSM. Reported by both Todd and Bjorn.

---
 drivers/pinctrl/qcom/Kconfig       | 24 +++++++++++++++++++++++-
 drivers/pinctrl/qcom/pinctrl-msm.c |  2 ++
 2 files changed, 25 insertions(+), 1 deletion(-)
drivers/pinctrl/qcom/Kconfig +23 -1
index ff1ee159dca2..11228ae3d826 100644
@@ -2,7 +2,7 @@
 if (ARCH_QCOM || COMPILE_TEST)
 
 config PINCTRL_MSM
-	bool
+	tristate
 	select PINMUX
 	select PINCONF
 	select GENERIC_PINCONF
@@ -11,6 +11,7 @@ config PINCTRL_MSM
 config PINCTRL_APQ8064
 	tristate "Qualcomm APQ8064 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -19,6 +20,7 @@ config PINCTRL_APQ8064
 config PINCTRL_APQ8084
 	tristate "Qualcomm APQ8084 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -27,6 +29,7 @@ config PINCTRL_APQ8084
 config PINCTRL_IPQ4019
 	tristate "Qualcomm IPQ4019 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -35,6 +38,7 @@ config PINCTRL_IPQ4019
 config PINCTRL_IPQ8064
 	tristate "Qualcomm IPQ8064 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -43,6 +47,7 @@ config PINCTRL_IPQ8064
 config PINCTRL_IPQ8074
 	tristate "Qualcomm Technologies, Inc. IPQ8074 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for
@@ -53,6 +58,7 @@ config PINCTRL_IPQ8074
 config PINCTRL_IPQ6018
 	tristate "Qualcomm Technologies, Inc. IPQ6018 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for
@@ -63,6 +69,7 @@ config PINCTRL_IPQ6018
 config PINCTRL_MSM8660
 	tristate "Qualcomm 8660 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -71,6 +78,7 @@ config PINCTRL_MSM8660
 config PINCTRL_MSM8960
 	tristate "Qualcomm 8960 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -79,6 +87,7 @@ config PINCTRL_MSM8960
 config PINCTRL_MDM9615
 	tristate "Qualcomm 9615 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -87,6 +96,7 @@ config PINCTRL_MDM9615
 config PINCTRL_MSM8X74
 	tristate "Qualcomm 8x74 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -95,6 +105,7 @@ config PINCTRL_MSM8X74
 config PINCTRL_MSM8916
 	tristate "Qualcomm 8916 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -103,6 +114,7 @@ config PINCTRL_MSM8916
 config PINCTRL_MSM8976
 	tristate "Qualcomm 8976 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -113,6 +125,7 @@ config PINCTRL_MSM8976
 config PINCTRL_MSM8994
 	tristate "Qualcomm 8994 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -122,6 +135,7 @@ config PINCTRL_MSM8994
 config PINCTRL_MSM8996
 	tristate "Qualcomm MSM8996 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -130,6 +144,7 @@ config PINCTRL_MSM8996
 config PINCTRL_MSM8998
 	tristate "Qualcomm MSM8998 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -138,6 +153,7 @@ config PINCTRL_MSM8998
 config PINCTRL_QCS404
 	tristate "Qualcomm QCS404 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -146,6 +162,7 @@ config PINCTRL_QCS404
 config PINCTRL_QDF2XXX
 	tristate "Qualcomm Technologies QDF2xxx pin controller driver"
 	depends on GPIOLIB && ACPI
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the GPIO driver for the TLMM block found on the
@@ -183,6 +200,7 @@ config PINCTRL_QCOM_SSBI_PMIC
 config PINCTRL_SC7180
 	tristate "Qualcomm Technologies Inc SC7180 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -192,6 +210,7 @@ config PINCTRL_SC7180
 config PINCTRL_SDM660
 	tristate "Qualcomm Technologies Inc SDM660 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	 This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -201,6 +220,7 @@ config PINCTRL_SDM660
 config PINCTRL_SDM845
 	tristate "Qualcomm Technologies Inc SDM845 pin controller driver"
 	depends on GPIOLIB && (OF || ACPI)
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	 This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -210,6 +230,7 @@ config PINCTRL_SDM845
 config PINCTRL_SM8150
 	tristate "Qualcomm Technologies Inc SM8150 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	 This is the pinctrl, pinmux, pinconf and gpiolib driver for the
@@ -219,6 +240,7 @@ config PINCTRL_SM8150
 config PINCTRL_SM8250
 	tristate "Qualcomm Technologies Inc SM8250 pin controller driver"
 	depends on GPIOLIB && OF
+	depends on QCOM_SCM || !QCOM_SCM
 	select PINCTRL_MSM
 	help
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
drivers/pinctrl/qcom/pinctrl-msm.c +2 -0
index 83b7d64bc4c1..e8e3ba8207af 100644
@@ -1355,3 +1355,5 @@ int msm_pinctrl_remove(struct platform_device *pdev)
 }
 EXPORT_SYMBOL(msm_pinctrl_remove);
 
+MODULE_DESCRIPTION("Qualcomm Technologies, Inc. TLMM driver");
+MODULE_LICENSE("GPL v2");
Signature · 6 lines
2.17.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#12 lore raw

PATCH v2 5/5 firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

In reply to John Stultz

Allow the qcom_scm driver to be loadable as a permenent module.

Cc Andy Gross <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jason Cooper <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Maulik Shah <[email protected]>
Cc Lina Iyer <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/firmware/Kconfig    | 2 +-
 drivers/firmware/Makefile   | 3 ++-
 drivers/firmware/qcom_scm.c | 4 ++++
 drivers/iommu/Kconfig       | 2 ++
 4 files changed, 9 insertions(+), 2 deletions(-)
drivers/firmware/Kconfig +1 -1
index fbd785dd0513..9e533a462bf4 100644
@@ -236,7 +236,7 @@ config INTEL_STRATIX10_RSU
 	  Say Y here if you want Intel RSU support.
 
 config QCOM_SCM
-	bool
+	tristate "Qcom SCM driver"
 	depends on ARM || ARM64
 	select RESET_CONTROLLER
 
drivers/firmware/Makefile +2 -1
index 99510be9f5ed..cf24d674216b 100644
@@ -17,7 +17,8 @@ obj-$(CONFIG_ISCSI_IBFT)	+= iscsi_ibft.o
 obj-$(CONFIG_FIRMWARE_MEMMAP)	+= memmap.o
 obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o
 obj-$(CONFIG_FW_CFG_SYSFS)	+= qemu_fw_cfg.o
-obj-$(CONFIG_QCOM_SCM)		+= qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o
+obj-$(CONFIG_QCOM_SCM)		+= qcom-scm.o
+qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o
 obj-$(CONFIG_TI_SCI_PROTOCOL)	+= ti_sci.o
 obj-$(CONFIG_TRUSTED_FOUNDATIONS) += trusted_foundations.o
 obj-$(CONFIG_TURRIS_MOX_RWTM)	+= turris-mox-rwtm.o
drivers/firmware/qcom_scm.c +4 -0
index 0e7233a20f34..b5e88bf66975 100644
@@ -1155,6 +1155,7 @@ static const struct of_device_id qcom_scm_dt_match[] = {
 	{ .compatible = "qcom,scm" },
 	{}
 };
+MODULE_DEVICE_TABLE(of, qcom_scm_dt_match);
 
 static struct platform_driver qcom_scm_driver = {
 	.driver = {
@@ -1170,3 +1171,6 @@ static int __init qcom_scm_init(void)
 	return platform_driver_register(&qcom_scm_driver);
 }
 subsys_initcall(qcom_scm_init);
+
+MODULE_DESCRIPTION("Qualcomm Technologies, Inc. SCM driver");
+MODULE_LICENSE("GPL v2");
drivers/iommu/Kconfig +2 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
 config ARM_SMMU
 	tristate "ARM Ltd. System MMU (SMMU) Support"
 	depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+	depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
 	select IOMMU_API
 	select IOMMU_IO_PGTABLE_LPAE
 	select ARM_DMA_USE_IOMMU if ARM
@@ -500,6 +501,7 @@ config QCOM_IOMMU
 	# Note: iommu drivers cannot (yet?) be built as modules
 	bool "Qualcomm IOMMU Support"
 	depends on ARCH_QCOM || (COMPILE_TEST && !GENERIC_ATOMIC64)
+	depends on QCOM_SCM=y
 	select IOMMU_API
 	select IOMMU_IO_PGTABLE_LPAE
 	select ARM_DMA_USE_IOMMU
Signature · 1 line
2.17.1
#13 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

I love your patch! Yet something to improve:

Hi John,

I love your patch! Yet something to improve:

[auto build test ERROR on pinctrl/devel]
[also build test ERROR on linux/master linus/master v5.8-rc2 next-20200626] [cannot apply to tip/irq/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/John-Stultz/Allow-for-qcom-pdc-pinctrl-msm-and-qcom-scm-drivers-to-be-loadable-as-modules/20200625-081326
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel
config: arm-randconfig-r002-20200628 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project a43b99a1e38e2beffb68a6db93f216f511e7fd41)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "__arm_smccc_smc" [drivers/firmware/qcom-scm.ko] undefined!

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

Acked-by on v2 5/5
#14 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

In reply to John Stultz
Quoted 19 lines · John Stultz

Allow the qcom_scm driver to be loadable as a permenent module.

Cc Andy Gross <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jason Cooper <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Maulik Shah <[email protected]>
Cc Lina Iyer <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
maintainer
#15 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

In reply to John Stultz

drivers/iommu/Kconfig config SPAPR_TCE_IOMMU · line 387

Quoted 12 lines · John Stultz
drivers/iommu/Kconfig +1 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
 config ARM_SMMU
 	tristate "ARM Ltd. System MMU (SMMU) Support"
 	depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+	depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
 	select IOMMU_API
 	select IOMMU_IO_PGTABLE_LPAE
 	select ARM_DMA_USE_IOMMU if ARM

This looks like a giant hack. Is there another way to handle this?

Will

#16 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 15 lines · Will Deacon

drivers/iommu/Kconfig config SPAPR_TCE_IOMMU · line 387

Quoted 12 lines · John Stultz
drivers/iommu/Kconfig +1 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
 config ARM_SMMU
      tristate "ARM Ltd. System MMU (SMMU) Support"
      depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+     depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
      select IOMMU_API
      select IOMMU_IO_PGTABLE_LPAE
      select ARM_DMA_USE_IOMMU if ARM

This looks like a giant hack. Is there another way to handle this?

Sorry for the slow response here.

So, I agree the syntax looks strange (requiring a comment obviously isn't a good sign), but it's a fairly common way to ensure drivers don't get built in if they optionally depend on another driver that can be built as a module.
See "RFKILL || !RFKILL", "EXTCON || !EXTCON", or "USB_GADGET ||
!USB_GADGET" in various Kconfig files.

I'm open to using a different method, and in a different thread you suggested using something like symbol_get(). I need to look into it more, but that approach looks even more messy and prone to runtime failures. Blocking the unwanted case at build time seems a bit cleaner to me, even if the syntax is odd.

thanks
-john

maintainer
#17 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 26 lines · John Stultz
Quoted 15 lines · Will Deacon

drivers/iommu/Kconfig config SPAPR_TCE_IOMMU · line 387

Quoted 12 lines · John Stultz
drivers/iommu/Kconfig +1 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
 config ARM_SMMU
      tristate "ARM Ltd. System MMU (SMMU) Support"
      depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+     depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
      select IOMMU_API
      select IOMMU_IO_PGTABLE_LPAE
      select ARM_DMA_USE_IOMMU if ARM

This looks like a giant hack. Is there another way to handle this?

Sorry for the slow response here.

So, I agree the syntax looks strange (requiring a comment obviously isn't a good sign), but it's a fairly common way to ensure drivers don't get built in if they optionally depend on another driver that can be built as a module.
See "RFKILL || !RFKILL", "EXTCON || !EXTCON", or "USB_GADGET ||
!USB_GADGET" in various Kconfig files.

Quoted 5 lines

I'm open to using a different method, and in a different thread you suggested using something like symbol_get(). I need to look into it more, but that approach looks even more messy and prone to runtime failures. Blocking the unwanted case at build time seems a bit cleaner to me, even if the syntax is odd.

Maybe just split it out then, so that the ARM_SMMU entry doesn't have this, as that driver _really_ doesn't care about SoC details like this. In other words, add a new entry along the lines of:

	config ARM_SMMU_QCOM_IMPL
	default y
	#if QCOM_SCM=m this can't be =y
	depends on ARM_SMMU & (QCOM_SCM || !QCOM_SCM)

and then have arm-smmu.h provide a static inline qcom_smmu_impl_init() which returns -ENODEV if CONFIG_ARM_SMMU_QCOM_IMPL=n and hack the Makefile so that we don't bother to compile arm-smmu-qcom.o in that case.

Would that work?

Will

#18 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 42 lines · Will Deacon
Quoted 26 lines · John Stultz
Quoted 15 lines · Will Deacon

drivers/iommu/Kconfig config SPAPR_TCE_IOMMU · line 387

Quoted 12 lines · John Stultz
drivers/iommu/Kconfig +1 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
 config ARM_SMMU
      tristate "ARM Ltd. System MMU (SMMU) Support"
      depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+     depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
      select IOMMU_API
      select IOMMU_IO_PGTABLE_LPAE
      select ARM_DMA_USE_IOMMU if ARM

This looks like a giant hack. Is there another way to handle this?

Sorry for the slow response here.

So, I agree the syntax looks strange (requiring a comment obviously isn't a good sign), but it's a fairly common way to ensure drivers don't get built in if they optionally depend on another driver that can be built as a module.
See "RFKILL || !RFKILL", "EXTCON || !EXTCON", or "USB_GADGET ||
!USB_GADGET" in various Kconfig files.

Quoted 5 lines

I'm open to using a different method, and in a different thread you suggested using something like symbol_get(). I need to look into it more, but that approach looks even more messy and prone to runtime failures. Blocking the unwanted case at build time seems a bit cleaner to me, even if the syntax is odd.

Maybe just split it out then, so that the ARM_SMMU entry doesn't have this, as that driver _really_ doesn't care about SoC details like this. In other words, add a new entry along the lines of:

        config ARM_SMMU_QCOM_IMPL
        default y
        #if QCOM_SCM=m this can't be =y
        depends on ARM_SMMU & (QCOM_SCM || !QCOM_SCM)
Quoted 5 lines

and then have arm-smmu.h provide a static inline qcom_smmu_impl_init() which returns -ENODEV if CONFIG_ARM_SMMU_QCOM_IMPL=n and hack the Makefile so that we don't bother to compile arm-smmu-qcom.o in that case.

Would that work?

I think this proposal still has problems with the directionality of the call.

The arm-smmu-impl.o calls to arm-smmu-qcom.o which calls qcom_scm.o So if qcom_scm.o is part of a module, the calling code in arm-smmu-qcom.o also needs to be a module, which means CONFIG_ARM_SMMU needs to be a module.

I know you said the arm-smmu driver doesn't care about SoC details, but the trouble is that currently the arm-smmu driver does directly call the qcom-scm code. So it is a real dependency. However, if QCOM_SCM is not configured, it calls stubs and that's ok. In that way, the "depends on QCOM_SCM || !QCOM_SCM" line actually makes sense. It looks terrible because we're used to boolean logic, but it's ternary.

Maybe can have the ARM_SMMU_QCOM_IMPL approach you suggest above, but that just holds the issue out at arms length, because we're still going to need to have:
depends on ARM_SMMU_QCOM_IMPL || !ARM_SMMU_QCOM_IMPL
in the ARM_SMMU definition, which I suspect you're wanting to avoid.

Otherwise the only thing I can think of is a deeper reworking of the arm-smmu-impl code so that the arm-smmu-qcom code probes itself and registers its hooks with the arm-smmu core.
That way the arm-smmu driver would not directly call any SoC specific code (and thus have no dependencies outward). But it's probably a fair amount of churn vs the extra depends string.

thanks
-john

maintainer
#19 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 56 lines · John Stultz
Quoted 42 lines · Will Deacon
Quoted 26 lines · John Stultz
Quoted 15 lines · Will Deacon

drivers/iommu/Kconfig config SPAPR_TCE_IOMMU · line 387

Quoted 12 lines · John Stultz
drivers/iommu/Kconfig +1 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
 config ARM_SMMU
      tristate "ARM Ltd. System MMU (SMMU) Support"
      depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+     depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
      select IOMMU_API
      select IOMMU_IO_PGTABLE_LPAE
      select ARM_DMA_USE_IOMMU if ARM

This looks like a giant hack. Is there another way to handle this?

Sorry for the slow response here.

So, I agree the syntax looks strange (requiring a comment obviously isn't a good sign), but it's a fairly common way to ensure drivers don't get built in if they optionally depend on another driver that can be built as a module.
See "RFKILL || !RFKILL", "EXTCON || !EXTCON", or "USB_GADGET ||
!USB_GADGET" in various Kconfig files.

Quoted 5 lines

I'm open to using a different method, and in a different thread you suggested using something like symbol_get(). I need to look into it more, but that approach looks even more messy and prone to runtime failures. Blocking the unwanted case at build time seems a bit cleaner to me, even if the syntax is odd.

Maybe just split it out then, so that the ARM_SMMU entry doesn't have this, as that driver _really_ doesn't care about SoC details like this. In other words, add a new entry along the lines of:

        config ARM_SMMU_QCOM_IMPL
        default y
        #if QCOM_SCM=m this can't be =y
        depends on ARM_SMMU & (QCOM_SCM || !QCOM_SCM)
Quoted 5 lines

and then have arm-smmu.h provide a static inline qcom_smmu_impl_init() which returns -ENODEV if CONFIG_ARM_SMMU_QCOM_IMPL=n and hack the Makefile so that we don't bother to compile arm-smmu-qcom.o in that case.

Would that work?

I think this proposal still has problems with the directionality of the call.

The arm-smmu-impl.o calls to arm-smmu-qcom.o which calls qcom_scm.o So if qcom_scm.o is part of a module, the calling code in arm-smmu-qcom.o also needs to be a module, which means CONFIG_ARM_SMMU needs to be a module.

Quoted 7 lines

I know you said the arm-smmu driver doesn't care about SoC details, but the trouble is that currently the arm-smmu driver does directly call the qcom-scm code. So it is a real dependency. However, if QCOM_SCM is not configured, it calls stubs and that's ok. In that way, the "depends on QCOM_SCM || !QCOM_SCM" line actually makes sense. It looks terrible because we're used to boolean logic, but it's ternary.

Yes, it looks ugly, but the part I really have issues with is that building QCOM_SCM=m and ARM_SMMU=y is perfectly fine if you don't run on an SoC with the qcom implementation. I don't see why we need to enforce things here beyond making sure that all selectable permutations _build_ and fail gracefully at runtime on the qcom SoC if SCM isn't available.

Will

#20 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 66 lines · Will Deacon
Quoted 56 lines · John Stultz
Quoted 42 lines · Will Deacon
Quoted 26 lines · John Stultz
Quoted 15 lines · Will Deacon

drivers/iommu/Kconfig config SPAPR_TCE_IOMMU · line 387

Quoted 12 lines · John Stultz
drivers/iommu/Kconfig +1 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
 config ARM_SMMU
      tristate "ARM Ltd. System MMU (SMMU) Support"
      depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+     depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
      select IOMMU_API
      select IOMMU_IO_PGTABLE_LPAE
      select ARM_DMA_USE_IOMMU if ARM

This looks like a giant hack. Is there another way to handle this?

Sorry for the slow response here.

So, I agree the syntax looks strange (requiring a comment obviously isn't a good sign), but it's a fairly common way to ensure drivers don't get built in if they optionally depend on another driver that can be built as a module.
See "RFKILL || !RFKILL", "EXTCON || !EXTCON", or "USB_GADGET ||
!USB_GADGET" in various Kconfig files.

Quoted 5 lines

I'm open to using a different method, and in a different thread you suggested using something like symbol_get(). I need to look into it more, but that approach looks even more messy and prone to runtime failures. Blocking the unwanted case at build time seems a bit cleaner to me, even if the syntax is odd.

Maybe just split it out then, so that the ARM_SMMU entry doesn't have this, as that driver _really_ doesn't care about SoC details like this. In other words, add a new entry along the lines of:

        config ARM_SMMU_QCOM_IMPL
        default y
        #if QCOM_SCM=m this can't be =y
        depends on ARM_SMMU & (QCOM_SCM || !QCOM_SCM)
Quoted 5 lines

and then have arm-smmu.h provide a static inline qcom_smmu_impl_init() which returns -ENODEV if CONFIG_ARM_SMMU_QCOM_IMPL=n and hack the Makefile so that we don't bother to compile arm-smmu-qcom.o in that case.

Would that work?

I think this proposal still has problems with the directionality of the call.

The arm-smmu-impl.o calls to arm-smmu-qcom.o which calls qcom_scm.o So if qcom_scm.o is part of a module, the calling code in arm-smmu-qcom.o also needs to be a module, which means CONFIG_ARM_SMMU needs to be a module.

Quoted 7 lines

I know you said the arm-smmu driver doesn't care about SoC details, but the trouble is that currently the arm-smmu driver does directly call the qcom-scm code. So it is a real dependency. However, if QCOM_SCM is not configured, it calls stubs and that's ok. In that way, the "depends on QCOM_SCM || !QCOM_SCM" line actually makes sense. It looks terrible because we're used to boolean logic, but it's ternary.

Quoted 5 lines

Yes, it looks ugly, but the part I really have issues with is that building QCOM_SCM=m and ARM_SMMU=y is perfectly fine if you don't run on an SoC with the qcom implementation. I don't see why we need to enforce things here beyond making sure that all selectable permutations _build_ and fail gracefully at runtime on the qcom SoC if SCM isn't available.

Ok. Thanks, that context/rationale makes sense to me now! I'll dig in and see if I can figure out the runtime get_symbol handling you suggested for the scm callout.

Thanks again for the feedback!
-john

maintainer
#21 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 72 lines · John Stultz
Quoted 65 lines · Will Deacon
Quoted 56 lines · John Stultz
Quoted 42 lines · Will Deacon
Quoted 26 lines · John Stultz
Quoted 15 lines · Will Deacon

drivers/iommu/Kconfig config SPAPR_TCE_IOMMU · line 387

Quoted 12 lines · John Stultz
drivers/iommu/Kconfig +1 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
 config ARM_SMMU
      tristate "ARM Ltd. System MMU (SMMU) Support"
      depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+     depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
      select IOMMU_API
      select IOMMU_IO_PGTABLE_LPAE
      select ARM_DMA_USE_IOMMU if ARM

This looks like a giant hack. Is there another way to handle this?

Sorry for the slow response here.

So, I agree the syntax looks strange (requiring a comment obviously isn't a good sign), but it's a fairly common way to ensure drivers don't get built in if they optionally depend on another driver that can be built as a module.
See "RFKILL || !RFKILL", "EXTCON || !EXTCON", or "USB_GADGET ||
!USB_GADGET" in various Kconfig files.

Quoted 5 lines

I'm open to using a different method, and in a different thread you suggested using something like symbol_get(). I need to look into it more, but that approach looks even more messy and prone to runtime failures. Blocking the unwanted case at build time seems a bit cleaner to me, even if the syntax is odd.

Maybe just split it out then, so that the ARM_SMMU entry doesn't have this, as that driver _really_ doesn't care about SoC details like this. In other words, add a new entry along the lines of:

        config ARM_SMMU_QCOM_IMPL
        default y
        #if QCOM_SCM=m this can't be =y
        depends on ARM_SMMU & (QCOM_SCM || !QCOM_SCM)
Quoted 5 lines

and then have arm-smmu.h provide a static inline qcom_smmu_impl_init() which returns -ENODEV if CONFIG_ARM_SMMU_QCOM_IMPL=n and hack the Makefile so that we don't bother to compile arm-smmu-qcom.o in that case.

Would that work?

I think this proposal still has problems with the directionality of the call.

The arm-smmu-impl.o calls to arm-smmu-qcom.o which calls qcom_scm.o So if qcom_scm.o is part of a module, the calling code in arm-smmu-qcom.o also needs to be a module, which means CONFIG_ARM_SMMU needs to be a module.

Quoted 7 lines

I know you said the arm-smmu driver doesn't care about SoC details, but the trouble is that currently the arm-smmu driver does directly call the qcom-scm code. So it is a real dependency. However, if QCOM_SCM is not configured, it calls stubs and that's ok. In that way, the "depends on QCOM_SCM || !QCOM_SCM" line actually makes sense. It looks terrible because we're used to boolean logic, but it's ternary.

Quoted 5 lines

Yes, it looks ugly, but the part I really have issues with is that building QCOM_SCM=m and ARM_SMMU=y is perfectly fine if you don't run on an SoC with the qcom implementation. I don't see why we need to enforce things here beyond making sure that all selectable permutations _build_ and fail gracefully at runtime on the qcom SoC if SCM isn't available.

Quoted 3 lines

Ok. Thanks, that context/rationale makes sense to me now! I'll dig in and see if I can figure out the runtime get_symbol handling you suggested for the scm callout.

Cheers, but in the interest of not being a massive pain in the bum, please yell if it ends up being tonnes of work and I'll close my eyes while applying your original patch.

Will

#22 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

In reply to Will Deacon
Quoted 65 lines · Will Deacon
Quoted 56 lines · John Stultz
Quoted 42 lines · Will Deacon
Quoted 26 lines · John Stultz
Quoted 15 lines · Will Deacon

drivers/iommu/Kconfig config SPAPR_TCE_IOMMU · line 387

Quoted 12 lines · John Stultz
drivers/iommu/Kconfig +1 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
 config ARM_SMMU
      tristate "ARM Ltd. System MMU (SMMU) Support"
      depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+     depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
      select IOMMU_API
      select IOMMU_IO_PGTABLE_LPAE
      select ARM_DMA_USE_IOMMU if ARM

This looks like a giant hack. Is there another way to handle this?

Sorry for the slow response here.

So, I agree the syntax looks strange (requiring a comment obviously isn't a good sign), but it's a fairly common way to ensure drivers don't get built in if they optionally depend on another driver that can be built as a module.
See "RFKILL || !RFKILL", "EXTCON || !EXTCON", or "USB_GADGET ||
!USB_GADGET" in various Kconfig files.

Quoted 5 lines

I'm open to using a different method, and in a different thread you suggested using something like symbol_get(). I need to look into it more, but that approach looks even more messy and prone to runtime failures. Blocking the unwanted case at build time seems a bit cleaner to me, even if the syntax is odd.

Maybe just split it out then, so that the ARM_SMMU entry doesn't have this, as that driver _really_ doesn't care about SoC details like this. In other words, add a new entry along the lines of:

        config ARM_SMMU_QCOM_IMPL
        default y
        #if QCOM_SCM=m this can't be =y
        depends on ARM_SMMU & (QCOM_SCM || !QCOM_SCM)
Quoted 5 lines

and then have arm-smmu.h provide a static inline qcom_smmu_impl_init() which returns -ENODEV if CONFIG_ARM_SMMU_QCOM_IMPL=n and hack the Makefile so that we don't bother to compile arm-smmu-qcom.o in that case.

Would that work?

I think this proposal still has problems with the directionality of the call.

The arm-smmu-impl.o calls to arm-smmu-qcom.o which calls qcom_scm.o So if qcom_scm.o is part of a module, the calling code in arm-smmu-qcom.o also needs to be a module, which means CONFIG_ARM_SMMU needs to be a module.

Quoted 7 lines

I know you said the arm-smmu driver doesn't care about SoC details, but the trouble is that currently the arm-smmu driver does directly call the qcom-scm code. So it is a real dependency. However, if QCOM_SCM is not configured, it calls stubs and that's ok. In that way, the "depends on QCOM_SCM || !QCOM_SCM" line actually makes sense. It looks terrible because we're used to boolean logic, but it's ternary.

Quoted 5 lines

Yes, it looks ugly, but the part I really have issues with is that building QCOM_SCM=m and ARM_SMMU=y is perfectly fine if you don't run on an SoC with the qcom implementation. I don't see why we need to enforce things here beyond making sure that all selectable permutations _build_ and fail gracefully at runtime on the qcom SoC if SCM isn't available.

Hey Will,
Sorry to dredge up this old thread. I've been off busy with other
things and didn't get around to trying to rework this until now.

Unfortunately I'm still having some trouble coming up with a better solution. Initially I figured I'd rework the qcom_scm driver to, so that we have the various qcom_scm_* as inline functions, which call out to function pointers that the qcom_scm driver would register when the module loaded (Oof, and unfortunately there are a *ton* qcom_scm_* functions so its a bunch of churn).

The trouble I realized with that approach is that if the ARM_SMMU code is built in, then it may try to use the qcom_scm code before the module loads and sets those function pointers. So while it would build ok, the issue would be when the arm_smmu_device_reset() is done by done on arm_smmu_device_probe(), it wouldn't actually call the right code. There isn't a really good way to deal with the module loading at some random time after arm_smmu_device_probe() completes.

This is the benefit of the module symbol dependency tracking: If the arm_smmu.ko calls symbols in qcom_scm.ko then qcom_scm.ko has to load first.
But if arm_smmu is built in, I haven't found a clear mechanism to force qcom_scm to load before we probe, if it's configured as a module.

I also looked into the idea of reworking the arm-smmu-impl code to be modular instead, and while it does provide a similar method of using function pointers to minimize the amount of symbols the arm-smmu code needs to know about, the initialization call path is arm_smmu_device_probe -> arm_smmu_impl_init -> qcom_smmu_impl_init. So it doesn't really allow for dynamic registration of implementation modules at runtime.

So I'm sort of stewing on maybe trying to rework the directionality, so the arm-smmu-qcom.o code probes and calls arm_smmu_impl_init and that is what initializes the arm_smmu_device_probe logic?

Alternatively, I'm considering trying to switch the module dependency annotation so that the CONFIG_QCOM_SCM modularity depends on ARM_SMMU being a module. But that is sort of putting the restriction on the callee instead of the caller (sort of flipping the meaning of the depends), which feels prone to later trouble (and with multiple users of CONFIG_QCOM_SCM needing similar treatment, it would make it difficult to discover the right combination of configs needed to allow it to be a module).

Anyway, I wanted to reach out to see if you had any further ideas here. Sorry for letting such a large time gap pass!

thanks
-john
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

maintainer
#23 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 119 lines · John Stultz
Quoted 65 lines · Will Deacon
Quoted 56 lines · John Stultz
Quoted 42 lines · Will Deacon
Quoted 26 lines · John Stultz
Quoted 15 lines · Will Deacon

drivers/iommu/Kconfig config SPAPR_TCE_IOMMU · line 387

Quoted 12 lines · John Stultz
drivers/iommu/Kconfig +1 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
 config ARM_SMMU
      tristate "ARM Ltd. System MMU (SMMU) Support"
      depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+     depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
      select IOMMU_API
      select IOMMU_IO_PGTABLE_LPAE
      select ARM_DMA_USE_IOMMU if ARM

This looks like a giant hack. Is there another way to handle this?

Sorry for the slow response here.

So, I agree the syntax looks strange (requiring a comment obviously isn't a good sign), but it's a fairly common way to ensure drivers don't get built in if they optionally depend on another driver that can be built as a module.
See "RFKILL || !RFKILL", "EXTCON || !EXTCON", or "USB_GADGET ||
!USB_GADGET" in various Kconfig files.

Quoted 5 lines

I'm open to using a different method, and in a different thread you suggested using something like symbol_get(). I need to look into it more, but that approach looks even more messy and prone to runtime failures. Blocking the unwanted case at build time seems a bit cleaner to me, even if the syntax is odd.

Maybe just split it out then, so that the ARM_SMMU entry doesn't have this, as that driver _really_ doesn't care about SoC details like this. In other words, add a new entry along the lines of:

        config ARM_SMMU_QCOM_IMPL
        default y
        #if QCOM_SCM=m this can't be =y
        depends on ARM_SMMU & (QCOM_SCM || !QCOM_SCM)
Quoted 5 lines

and then have arm-smmu.h provide a static inline qcom_smmu_impl_init() which returns -ENODEV if CONFIG_ARM_SMMU_QCOM_IMPL=n and hack the Makefile so that we don't bother to compile arm-smmu-qcom.o in that case.

Would that work?

I think this proposal still has problems with the directionality of the call.

The arm-smmu-impl.o calls to arm-smmu-qcom.o which calls qcom_scm.o So if qcom_scm.o is part of a module, the calling code in arm-smmu-qcom.o also needs to be a module, which means CONFIG_ARM_SMMU needs to be a module.

Quoted 7 lines

I know you said the arm-smmu driver doesn't care about SoC details, but the trouble is that currently the arm-smmu driver does directly call the qcom-scm code. So it is a real dependency. However, if QCOM_SCM is not configured, it calls stubs and that's ok. In that way, the "depends on QCOM_SCM || !QCOM_SCM" line actually makes sense. It looks terrible because we're used to boolean logic, but it's ternary.

Quoted 5 lines

Yes, it looks ugly, but the part I really have issues with is that building QCOM_SCM=m and ARM_SMMU=y is perfectly fine if you don't run on an SoC with the qcom implementation. I don't see why we need to enforce things here beyond making sure that all selectable permutations _build_ and fail gracefully at runtime on the qcom SoC if SCM isn't available.

Hey Will,
Sorry to dredge up this old thread. I've been off busy with other
things and didn't get around to trying to rework this until now.

Unfortunately I'm still having some trouble coming up with a better solution. Initially I figured I'd rework the qcom_scm driver to, so that we have the various qcom_scm_* as inline functions, which call out to function pointers that the qcom_scm driver would register when the module loaded (Oof, and unfortunately there are a *ton* qcom_scm_* functions so its a bunch of churn).

The trouble I realized with that approach is that if the ARM_SMMU code is built in, then it may try to use the qcom_scm code before the module loads and sets those function pointers. So while it would build ok, the issue would be when the arm_smmu_device_reset() is done by done on arm_smmu_device_probe(), it wouldn't actually call the right code. There isn't a really good way to deal with the module loading at some random time after arm_smmu_device_probe() completes.

This is the benefit of the module symbol dependency tracking: If the arm_smmu.ko calls symbols in qcom_scm.ko then qcom_scm.ko has to load first.
But if arm_smmu is built in, I haven't found a clear mechanism to force qcom_scm to load before we probe, if it's configured as a module.

I also looked into the idea of reworking the arm-smmu-impl code to be modular instead, and while it does provide a similar method of using function pointers to minimize the amount of symbols the arm-smmu code needs to know about, the initialization call path is arm_smmu_device_probe -> arm_smmu_impl_init -> qcom_smmu_impl_init. So it doesn't really allow for dynamic registration of implementation modules at runtime.

So I'm sort of stewing on maybe trying to rework the directionality, so the arm-smmu-qcom.o code probes and calls arm_smmu_impl_init and that is what initializes the arm_smmu_device_probe logic?

Alternatively, I'm considering trying to switch the module dependency annotation so that the CONFIG_QCOM_SCM modularity depends on ARM_SMMU being a module. But that is sort of putting the restriction on the callee instead of the caller (sort of flipping the meaning of the depends), which feels prone to later trouble (and with multiple users of CONFIG_QCOM_SCM needing similar treatment, it would make it difficult to discover the right combination of configs needed to allow it to be a module).

Quoted 2 lines

Anyway, I wanted to reach out to see if you had any further ideas here. Sorry for letting such a large time gap pass!

Well we can always go with your original hack, if it helps?

https://lore.kernel.org/linux-iommu/20200714075603.GE4277@willie-the-truck/

Will
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

reviewer
#24 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 120 lines · Will Deacon
Quoted 119 lines · John Stultz
Quoted 65 lines · Will Deacon
Quoted 56 lines · John Stultz
Quoted 42 lines · Will Deacon
Quoted 26 lines · John Stultz
Quoted 15 lines · Will Deacon

drivers/iommu/Kconfig config SPAPR_TCE_IOMMU · line 387

Quoted 12 lines · John Stultz
drivers/iommu/Kconfig +1 -0
index b510f67dfa49..714893535dd2 100644
@@ -381,6 +381,7 @@ config SPAPR_TCE_IOMMU
  config ARM_SMMU
       tristate "ARM Ltd. System MMU (SMMU) Support"
       depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU
+     depends on QCOM_SCM || !QCOM_SCM #if QCOM_SCM=m this can't be =y
       select IOMMU_API
       select IOMMU_IO_PGTABLE_LPAE
       select ARM_DMA_USE_IOMMU if ARM

This looks like a giant hack. Is there another way to handle this?

Sorry for the slow response here.

So, I agree the syntax looks strange (requiring a comment obviously isn't a good sign), but it's a fairly common way to ensure drivers don't get built in if they optionally depend on another driver that can be built as a module.
See "RFKILL || !RFKILL", "EXTCON || !EXTCON", or "USB_GADGET ||
!USB_GADGET" in various Kconfig files.

Quoted 5 lines

I'm open to using a different method, and in a different thread you suggested using something like symbol_get(). I need to look into it more, but that approach looks even more messy and prone to runtime failures. Blocking the unwanted case at build time seems a bit cleaner to me, even if the syntax is odd.

Maybe just split it out then, so that the ARM_SMMU entry doesn't have this, as that driver _really_ doesn't care about SoC details like this. In other words, add a new entry along the lines of:

         config ARM_SMMU_QCOM_IMPL
         default y
         #if QCOM_SCM=m this can't be =y
         depends on ARM_SMMU & (QCOM_SCM || !QCOM_SCM)
Quoted 5 lines

and then have arm-smmu.h provide a static inline qcom_smmu_impl_init() which returns -ENODEV if CONFIG_ARM_SMMU_QCOM_IMPL=n and hack the Makefile so that we don't bother to compile arm-smmu-qcom.o in that case.

Would that work?

I think this proposal still has problems with the directionality of the call.

The arm-smmu-impl.o calls to arm-smmu-qcom.o which calls qcom_scm.o So if qcom_scm.o is part of a module, the calling code in arm-smmu-qcom.o also needs to be a module, which means CONFIG_ARM_SMMU needs to be a module.

Quoted 7 lines

I know you said the arm-smmu driver doesn't care about SoC details, but the trouble is that currently the arm-smmu driver does directly call the qcom-scm code. So it is a real dependency. However, if QCOM_SCM is not configured, it calls stubs and that's ok. In that way, the "depends on QCOM_SCM || !QCOM_SCM" line actually makes sense. It looks terrible because we're used to boolean logic, but it's ternary.

Quoted 5 lines

Yes, it looks ugly, but the part I really have issues with is that building QCOM_SCM=m and ARM_SMMU=y is perfectly fine if you don't run on an SoC with the qcom implementation. I don't see why we need to enforce things here beyond making sure that all selectable permutations _build_ and fail gracefully at runtime on the qcom SoC if SCM isn't available.

Hey Will,
Sorry to dredge up this old thread. I've been off busy with other
things and didn't get around to trying to rework this until now.

Unfortunately I'm still having some trouble coming up with a better solution. Initially I figured I'd rework the qcom_scm driver to, so that we have the various qcom_scm_* as inline functions, which call out to function pointers that the qcom_scm driver would register when the module loaded (Oof, and unfortunately there are a *ton* qcom_scm_* functions so its a bunch of churn).

The trouble I realized with that approach is that if the ARM_SMMU code is built in, then it may try to use the qcom_scm code before the module loads and sets those function pointers. So while it would build ok, the issue would be when the arm_smmu_device_reset() is done by done on arm_smmu_device_probe(), it wouldn't actually call the right code. There isn't a really good way to deal with the module loading at some random time after arm_smmu_device_probe() completes.

This is the benefit of the module symbol dependency tracking: If the arm_smmu.ko calls symbols in qcom_scm.ko then qcom_scm.ko has to load first.
But if arm_smmu is built in, I haven't found a clear mechanism to force qcom_scm to load before we probe, if it's configured as a module.

I also looked into the idea of reworking the arm-smmu-impl code to be modular instead, and while it does provide a similar method of using function pointers to minimize the amount of symbols the arm-smmu code needs to know about, the initialization call path is arm_smmu_device_probe -> arm_smmu_impl_init -> qcom_smmu_impl_init. So it doesn't really allow for dynamic registration of implementation modules at runtime.

So I'm sort of stewing on maybe trying to rework the directionality, so the arm-smmu-qcom.o code probes and calls arm_smmu_impl_init and that is what initializes the arm_smmu_device_probe logic?

Alternatively, I'm considering trying to switch the module dependency annotation so that the CONFIG_QCOM_SCM modularity depends on ARM_SMMU being a module. But that is sort of putting the restriction on the callee instead of the caller (sort of flipping the meaning of the depends), which feels prone to later trouble (and with multiple users of CONFIG_QCOM_SCM needing similar treatment, it would make it difficult to discover the right combination of configs needed to allow it to be a module).

Quoted 6 lines
Quoted 2 lines

Anyway, I wanted to reach out to see if you had any further ideas here. Sorry for letting such a large time gap pass!

Well we can always go with your original hack, if it helps?

https://lore.kernel.org/linux-iommu/20200714075603.GE4277@willie-the-truck/

Hmm, perhaps I'm missing something here, but even if the config options *do* line up, what prevents arm-smmu probing before qcom-scm and dereferencing NULL in qcom_scm_qsmmu500_wait_safe_toggle() before __scm is initialised?

Robin.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#25 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 4 lines · Robin Murphy

Hmm, perhaps I'm missing something here, but even if the config options *do* line up, what prevents arm-smmu probing before qcom-scm and dereferencing NULL in qcom_scm_qsmmu500_wait_safe_toggle() before __scm is initialised?

Oh man, this spun me on a "wait, but how does it all work!" trip. :)

So in the non-module case, the qcom_scm driver is a subsys_initcall and the arm-smmu is a module_platform_driver, so the ordering works out.

In the module case, the arm-smmu code isn't loaded until the qcom_scm driver finishes probing due to the symbol dependency handling.

To double check this, I added a big msleep at the top of the qcom_scm_probe to try to open the race window you described, but the arm_smmu_device_probe() doesn't run until after qcom_scm_probe completes.

So at least as a built in / built in, or a module/module case its ok. And in the case where arm-smmu is a module and qcom_scm is built in that's ok too.

Its just the case my patch is trying to prevent is where arm-smmu is built in, but qcom_scm is a module that it can't work (due to build errors in missing symbols, or if we tried to use function pointers to plug in the qcom_scm - the lack of initialization ordering).

Hopefully that addresses your concern? Let me know if I'm still missing something.

thanks
-john
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

reviewer
#26 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 6 lines · John Stultz
Quoted 4 lines · Robin Murphy

Hmm, perhaps I'm missing something here, but even if the config options *do* line up, what prevents arm-smmu probing before qcom-scm and dereferencing NULL in qcom_scm_qsmmu500_wait_safe_toggle() before __scm is initialised?

Quoted 8 lines

Oh man, this spun me on a "wait, but how does it all work!" trip. :)

So in the non-module case, the qcom_scm driver is a subsys_initcall and the arm-smmu is a module_platform_driver, so the ordering works out.

In the module case, the arm-smmu code isn't loaded until the qcom_scm driver finishes probing due to the symbol dependency handling.

My point is that module load != driver probe. AFAICS you could disable drivers_autoprobe, load both modules, bind the SMMU to its driver first, and boom!

Quoted 4 lines

To double check this, I added a big msleep at the top of the qcom_scm_probe to try to open the race window you described, but the arm_smmu_device_probe() doesn't run until after qcom_scm_probe completes.

I don't think asynchronous probing is enabled by default, so indeed I would expect that to still happen to work ;)

Quoted 3 lines

So at least as a built in / built in, or a module/module case its ok. And in the case where arm-smmu is a module and qcom_scm is built in that's ok too.

In the built-in case, I'm sure it happens to work out similarly because the order of nodes in the DTB tends to be the order in which devices are autoprobed. Again, async probe might be enough to break things; manually binding drivers definitely should; moving the firmware node to the end of the DTB probably would as well.

Quoted 7 lines

Its just the case my patch is trying to prevent is where arm-smmu is built in, but qcom_scm is a module that it can't work (due to build errors in missing symbols, or if we tried to use function pointers to plug in the qcom_scm - the lack of initialization ordering).

Hopefully that addresses your concern? Let me know if I'm still missing something.

What I was dancing around is that the SCM API (and/or its users) appears to need a general way to tell whether SCM is ready or not, because the initialisation ordering problem is there anyway. Neither Kconfig nor the module loader can solve that.

One possible self-contained workaround would be to see if an SCM DT node exists, see if a corresponding device exists, and see if that device has a driver bound. It's a little ugly, and strictly it still doesn't tell you that the _right_ driver is bound, but at least it's a lot more robust than implicitly relying on DT order, default probing behaviours, and hope.

Robin.

#27 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

Quoted 32 lines · Robin Murphy
Quoted 6 lines · John Stultz
Quoted 4 lines · Robin Murphy

Hmm, perhaps I'm missing something here, but even if the config options *do* line up, what prevents arm-smmu probing before qcom-scm and dereferencing NULL in qcom_scm_qsmmu500_wait_safe_toggle() before __scm is initialised?

Quoted 8 lines

Oh man, this spun me on a "wait, but how does it all work!" trip. :)

So in the non-module case, the qcom_scm driver is a subsys_initcall and the arm-smmu is a module_platform_driver, so the ordering works out.

In the module case, the arm-smmu code isn't loaded until the qcom_scm driver finishes probing due to the symbol dependency handling.

My point is that module load != driver probe. AFAICS you could disable drivers_autoprobe, load both modules, bind the SMMU to its driver first, and boom!

Quoted 4 lines

To double check this, I added a big msleep at the top of the qcom_scm_probe to try to open the race window you described, but the arm_smmu_device_probe() doesn't run until after qcom_scm_probe completes.

I don't think asynchronous probing is enabled by default, so indeed I would expect that to still happen to work ;)

Quoted 3 lines

So at least as a built in / built in, or a module/module case its ok. And in the case where arm-smmu is a module and qcom_scm is built in that's ok too.

Quoted 5 lines

In the built-in case, I'm sure it happens to work out similarly because the order of nodes in the DTB tends to be the order in which devices are autoprobed. Again, async probe might be enough to break things; manually binding drivers definitely should; moving the firmware node to the end of the DTB probably would as well.

So, with modules, I turned on async probing for the two drivers, as well as moved the firmware node to the end of the dtb, and couldn't manage to trip it up even with a 6 second delay in the qcom_scm probe function.

It was only when doing the same with everything built in that I did manage to trigger the issue. So yes, you're right! And it is an issue more easily tripped with everything built in statically (and not really connected to this patch series).

Quoted 5 lines
Quoted 5 lines

Its just the case my patch is trying to prevent is where arm-smmu is built in, but qcom_scm is a module that it can't work (due to build errors in missing symbols, or if we tried to use function pointers to plug in the qcom_scm - the lack of initialization ordering).

Quoted 7 lines
Quoted 2 lines

Hopefully that addresses your concern? Let me know if I'm still missing something.

What I was dancing around is that the SCM API (and/or its users) appears to need a general way to tell whether SCM is ready or not, because the initialisation ordering problem is there anyway. Neither Kconfig nor the module loader can solve that.

Hrm... There is qcom_scm_is_available(). I tried adding a check for that in qcom_smmu_impl_init() and return EPROBE_DEFER if it fails, but I then hit a separate crash (tripping in iommu_group_remove_device on a null dev->iommu_group value). But after adding a check for that, it seems to be working...

I'll try to spin up a separate patch here for that in a second.

thanks
-john

#28 lore raw

Re: [PATCH v2 5/5] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

In reply to Will Deacon
Quoted 10 lines · Will Deacon
Quoted 9 lines · John Stultz

Alternatively, I'm considering trying to switch the module dependency annotation so that the CONFIG_QCOM_SCM modularity depends on ARM_SMMU being a module. But that is sort of putting the restriction on the callee instead of the caller (sort of flipping the meaning of the depends), which feels prone to later trouble (and with multiple users of CONFIG_QCOM_SCM needing similar treatment, it would make it difficult to discover the right combination of configs needed to allow it to be a module).

Quoted 6 lines
Quoted 2 lines

Anyway, I wanted to reach out to see if you had any further ideas here. Sorry for letting such a large time gap pass!

Well we can always go with your original hack, if it helps?

https://lore.kernel.org/linux-iommu/20200714075603.GE4277@willie-the-truck/

Yea. After trying a few more ideas that didn't pan out, I think I'm going to fall back to that. :(

thanks
-john