Skip to contentSkip to conversation

perf/smmuv3: Add platform id table for module auto loading

PATCH Superseded Yicong Yang 3 participants 9 messages Aug 7, 2023 – Aug 14, 2023 Arm PMU profiling and debugging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/smmuv3: Add platform id table for module auto loading

From: Yicong Yang <[email protected]>

On ACPI based system the device is probed by the name directly. If the driver is configured as module it can only be loaded manually. Add the platform id table as well as the module alias then the driver will be loaded automatically by the udev or others once the device added.

---
 drivers/perf/arm_smmuv3_pmu.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/perf/arm_smmuv3_pmu.c +7 -0
index 25a269d431e4..f27c5f585524 100644
@@ -946,7 +946,14 @@ static const struct of_device_id smmu_pmu_of_match[] = {
 MODULE_DEVICE_TABLE(of, smmu_pmu_of_match);
 #endif
 
+static const struct platform_device_id smmu_pmu_platform_match[] = {
+	{ "arm-smmu-v3-pmcg", 0 },
+	{}
+};
+MODULE_DEVICE_TABLE(platform, smmu_pmu_platform_match);
+
 static struct platform_driver smmu_pmu_driver = {
+	.id_table = smmu_pmu_platform_match,
 	.driver = {
 		.name = "arm-smmu-v3-pmcg",
 		.of_match_table = of_match_ptr(smmu_pmu_of_match),
Signature · 1 line
2.24.0
#1 lore raw
Quoted 7 lines · Yicong Yang

From: Yicong Yang <[email protected]>

On ACPI based system the device is probed by the name directly. If the driver is configured as module it can only be loaded manually. Add the platform id table as well as the module alias then the driver will be loaded automatically by the udev or others once the device added.

Please consider revise the long log to clearly express the purpose of the changes in this patch:

- What's the exact issue the patch is addressing
- Why the changes in this patch can fix the issue or make something working
- Consider impact of the changes introduced by this patch

These info may help reviewers and maintainers .. and yourself on code merge.

Regards.

#2 lore raw
Quoted 10 lines · Liang Li
Quoted 7 lines · Yicong Yang

From: Yicong Yang <[email protected]>

On ACPI based system the device is probed by the name directly. If the driver is configured as module it can only be loaded manually. Add the platform id table as well as the module alias then the driver will be loaded automatically by the udev or others once the device added.

Quoted 8 lines

Please consider revise the long log to clearly express the purpose of the changes in this patch:

- What's the exact issue the patch is addressing
- Why the changes in this patch can fix the issue or make something working
- Consider impact of the changes introduced by this patch

These info may help reviewers and maintainers .. and yourself on code merge.

years ago, i found a good doc regarding this,
https://wiki.archlinux.org/title/Modalias

guess it is because /lib/modules/$(uname -r)/modules.alias fails to contain smmu driver without the MODULE_DEVICE_TABLE, isn't it, yicong?

Quoted 3 lines

Regards.

Thanks
Barry

#3 lore raw

Hi Barry, Liang,

Quoted 18 lines · Barry Song
Quoted 17 lines · Liang Li
Quoted 7 lines · Yicong Yang

From: Yicong Yang <[email protected]>

On ACPI based system the device is probed by the name directly. If the driver is configured as module it can only be loaded manually. Add the platform id table as well as the module alias then the driver will be loaded automatically by the udev or others once the device added.

Please consider revise the long log to clearly express the purpose of the changes in this patch:

- What's the exact issue the patch is addressing
- Why the changes in this patch can fix the issue or make something working
- Consider impact of the changes introduced by this patch

Quoted 7 lines
Quoted 1 line

These info may help reviewers and maintainers .. and yourself on code merge.

years ago, i found a good doc regarding this,
https://wiki.archlinux.org/title/Modalias

guess it is because /lib/modules/$(uname -r)/modules.alias fails to contain smmu driver without the MODULE_DEVICE_TABLE, isn't it, yicong?

Yes I think it's the reason. I didn't find summary in kernel docs for the modalias as well as the uevent mechanism. Arch wiki has a well illustration for the modalias and suse[1] describes how this is used by the udev for module auto loading.

For my case I'm using a ACPI based arm64 server and after booting the arm_smmuv3_pmu.ko is not auto loaded by the udevd since we aren't providing this information. In order to support this we need to provide this MODULE_DEVICE_TABLE() when the smmu pmu added as a platform device, then the userspace udev can know which module to load after the device is added.

[1] https://documentation.suse.com/sles/15-SP1/html/SLES-all/cha-udev.html#sec-udev-drivers

Thanks.

#4 lore raw

Hi Yicong,

Thanks for your reply,

Quoted 33 lines · Yicong Yang

Hi Barry, Liang,

Quoted 18 lines · Barry Song
Quoted 17 lines · Liang Li
Quoted 7 lines · Yicong Yang

From: Yicong Yang <[email protected]>

On ACPI based system the device is probed by the name directly. If the driver is configured as module it can only be loaded manually. Add the platform id table as well as the module alias then the driver will be loaded automatically by the udev or others once the device added.

Please consider revise the long log to clearly express the purpose of the changes in this patch:

- What's the exact issue the patch is addressing
- Why the changes in this patch can fix the issue or make something working
- Consider impact of the changes introduced by this patch

Quoted 7 lines
Quoted 1 line

These info may help reviewers and maintainers .. and yourself on code merge.

years ago, i found a good doc regarding this,
https://wiki.archlinux.org/title/Modalias

guess it is because /lib/modules/$(uname -r)/modules.alias fails to contain smmu driver without the MODULE_DEVICE_TABLE, isn't it, yicong?

Yes I think it's the reason. I didn't find summary in kernel docs for the modalias as well as the uevent mechanism. Arch wiki has a well illustration for the modalias and suse[1] describes how this is used by the udev for module auto loading.

Quoted 6 lines

For my case I'm using a ACPI based arm64 server and after booting the arm_smmuv3_pmu.ko is not auto loaded by the udevd since we aren't providing this information. In order to support this we need to provide this MODULE_DEVICE_TABLE() when the smmu pmu added as a platform device, then the userspace udev can know which module to load after the device is added.

Then what's the purpose of the added '.id_table = ...' line in the previous patch ?
<We lost the patch context in this thread.>

Based on above clarification, the updated DEVICE_TABLE would update modalias as expected, right ?

Quoted 3 lines

[1] https://documentation.suse.com/sles/15-SP1/html/SLES-all/cha-udev.html#sec-udev-drivers

Thanks.

Regards.
Liang Li

#5 lore raw
Quoted 45 lines · Liang Li

Hi Yicong,

Thanks for your reply,

Quoted 33 lines · Yicong Yang

Hi Barry, Liang,

Quoted 18 lines · Barry Song
Quoted 17 lines · Liang Li
Quoted 7 lines · Yicong Yang

From: Yicong Yang <[email protected]>

On ACPI based system the device is probed by the name directly. If the driver is configured as module it can only be loaded manually. Add the platform id table as well as the module alias then the driver will be loaded automatically by the udev or others once the device added.

Please consider revise the long log to clearly express the purpose of the changes in this patch:

- What's the exact issue the patch is addressing
- Why the changes in this patch can fix the issue or make something working
- Consider impact of the changes introduced by this patch

Quoted 7 lines
Quoted 1 line

These info may help reviewers and maintainers .. and yourself on code merge.

years ago, i found a good doc regarding this,
https://wiki.archlinux.org/title/Modalias

guess it is because /lib/modules/$(uname -r)/modules.alias fails to contain smmu driver without the MODULE_DEVICE_TABLE, isn't it, yicong?

Yes I think it's the reason. I didn't find summary in kernel docs for the modalias as well as the uevent mechanism. Arch wiki has a well illustration for the modalias and suse[1] describes how this is used by the udev for module auto loading.

Quoted 6 lines

For my case I'm using a ACPI based arm64 server and after booting the arm_smmuv3_pmu.ko is not auto loaded by the udevd since we aren't providing this information. In order to support this we need to provide this MODULE_DEVICE_TABLE() when the smmu pmu added as a platform device, then the userspace udev can know which module to load after the device is added.

Quoted 6 lines

Then what's the purpose of the added '.id_table = ...' line in the previous patch ?
<We lost the patch context in this thread.>

Based on above clarification, the updated DEVICE_TABLE would update modalias as expected, right ?

ok, it's lack of illustration in the commit. If we're going to use MODULE_DEVICE_TABLE we need a platform id table. So I add it and I found it weired if we have a id table but not use it for probing, so I also initialize .id_table.

I found there's also an another way to implement this by used MODULE_ALIAS(), and no need to add an id table. Maybe this way is less controversial.

drivers/perf/arm_smmuv3_pmu.c +1 -0
index 25a269d431e4..4c32b6dbfe76 100644
@@ -984,6 +984,7 @@ static void __exit arm_smmu_pmu_exit(void)
 
 module_exit(arm_smmu_pmu_exit);
 
+MODULE_ALIAS("platform:arm-smmu-v3-pmcg");
 MODULE_DESCRIPTION("PMU driver for ARM SMMUv3 Performance Monitors Extension");
 MODULE_AUTHOR("Neil Leeder <[email protected]>");
 MODULE_AUTHOR("Shameer Kolothum <[email protected]>");

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#6 lore raw
Quoted 54 lines · Yicong Yang
Quoted 45 lines · Liang Li

Hi Yicong,

Thanks for your reply,

Quoted 33 lines · Yicong Yang

Hi Barry, Liang,

Quoted 18 lines · Barry Song
Quoted 17 lines · Liang Li
Quoted 7 lines · Yicong Yang

From: Yicong Yang <[email protected]>

On ACPI based system the device is probed by the name directly. If the driver is configured as module it can only be loaded manually. Add the platform id table as well as the module alias then the driver will be loaded automatically by the udev or others once the device added.

Please consider revise the long log to clearly express the purpose of the changes in this patch:

- What's the exact issue the patch is addressing
- Why the changes in this patch can fix the issue or make something working
- Consider impact of the changes introduced by this patch

Quoted 7 lines
Quoted 1 line

These info may help reviewers and maintainers .. and yourself on code merge.

years ago, i found a good doc regarding this,
https://wiki.archlinux.org/title/Modalias

guess it is because /lib/modules/$(uname -r)/modules.alias fails to contain smmu driver without the MODULE_DEVICE_TABLE, isn't it, yicong?

Yes I think it's the reason. I didn't find summary in kernel docs for the modalias as well as the uevent mechanism. Arch wiki has a well illustration for the modalias and suse[1] describes how this is used by the udev for module auto loading.

Quoted 6 lines

For my case I'm using a ACPI based arm64 server and after booting the arm_smmuv3_pmu.ko is not auto loaded by the udevd since we aren't providing this information. In order to support this we need to provide this MODULE_DEVICE_TABLE() when the smmu pmu added as a platform device, then the userspace udev can know which module to load after the device is added.

Quoted 6 lines

Then what's the purpose of the added '.id_table = ...' line in the previous patch ?
<We lost the patch context in this thread.>

Based on above clarification, the updated DEVICE_TABLE would update modalias as expected, right ?

Quoted 6 lines

ok, it's lack of illustration in the commit. If we're going to use MODULE_DEVICE_TABLE we need a platform id table. So I add it and I found it weired if we have a id table but not use it for probing, so I also initialize .id_table.

I found there's also an another way to implement this by used MODULE_ALIAS(), and no need to add an id table. Maybe this way is less controversial.

right, how is your driver matching with your device?

acpi_driver_match_device() or strcmp(pdev->name, drv->name) == 0 ?

static int platform_match(struct device *dev, struct device_driver *drv)

{
        struct platform_device *pdev = to_platform_device(dev);
        struct platform_driver *pdrv = to_platform_driver(drv);

        /* When driver_override is set, only bind to the matching driver */
        if (pdev->driver_override)
                return !strcmp(pdev->driver_override, drv->name);

        /* Attempt an OF style match first */
        if (of_driver_match_device(dev, drv))
                return 1;

        /* Then try ACPI style match */
        if (acpi_driver_match_device(dev, drv))
                return 1;

        /* Then try to match against the id table */
        if (pdrv->id_table)
                return platform_match_id(pdrv->id_table, pdev) != NULL;

        /* fall-back to driver name match */
        return (strcmp(pdev->name, drv->name) == 0);
}

In both cases, it seems we don't need id_table. id_table can support two or above device names, so that one driver can support multiple device IDs usually with different specific device data.

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +0 -0
index 25a269d431e4..4c32b6dbfe76 100644

drivers/perf/arm_smmuv3_pmu.c static void __exit arm_smmu_pmu_exit(void) · line 990

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +1 -0
@@ -984,6 +984,7 @@ static void __exit arm_smmu_pmu_exit(void)
 
 module_exit(arm_smmu_pmu_exit);
 
+MODULE_ALIAS("platform:arm-smmu-v3-pmcg");
 MODULE_DESCRIPTION("PMU driver for ARM SMMUv3 Performance Monitors Extension");
 MODULE_AUTHOR("Neil Leeder <[email protected]>");
 MODULE_AUTHOR("Shameer Kolothum <[email protected]>");

Thanks
Barry

#7 lore raw
Quoted 60 lines · Barry Song
Quoted 58 lines · Yicong Yang
Quoted 45 lines · Liang Li

Hi Yicong,

Thanks for your reply,

Quoted 33 lines · Yicong Yang

Hi Barry, Liang,

Quoted 18 lines · Barry Song
Quoted 17 lines · Liang Li
Quoted 7 lines · Yicong Yang

From: Yicong Yang <[email protected]>

On ACPI based system the device is probed by the name directly. If the driver is configured as module it can only be loaded manually. Add the platform id table as well as the module alias then the driver will be loaded automatically by the udev or others once the device added.

Please consider revise the long log to clearly express the purpose of the changes in this patch:

- What's the exact issue the patch is addressing
- Why the changes in this patch can fix the issue or make something working
- Consider impact of the changes introduced by this patch

Quoted 7 lines
Quoted 1 line

These info may help reviewers and maintainers .. and yourself on code merge.

years ago, i found a good doc regarding this,
https://wiki.archlinux.org/title/Modalias

guess it is because /lib/modules/$(uname -r)/modules.alias fails to contain smmu driver without the MODULE_DEVICE_TABLE, isn't it, yicong?

Yes I think it's the reason. I didn't find summary in kernel docs for the modalias as well as the uevent mechanism. Arch wiki has a well illustration for the modalias and suse[1] describes how this is used by the udev for module auto loading.

Quoted 6 lines

For my case I'm using a ACPI based arm64 server and after booting the arm_smmuv3_pmu.ko is not auto loaded by the udevd since we aren't providing this information. In order to support this we need to provide this MODULE_DEVICE_TABLE() when the smmu pmu added as a platform device, then the userspace udev can know which module to load after the device is added.

Quoted 6 lines

Then what's the purpose of the added '.id_table = ...' line in the previous patch ?
<We lost the patch context in this thread.>

Based on above clarification, the updated DEVICE_TABLE would update modalias as expected, right ?

ok, it's lack of illustration in the commit. If we're going to use MODULE_DEVICE_TABLE we need a platform id table. So I add it and I found it weired if we have a id table but not use it for probing, so I also initialize .id_table.

Quoted 6 lines
Quoted 2 lines

I found there's also an another way to implement this by used MODULE_ALIAS(), and no need to add an id table. Maybe this way is less controversial.

right, how is your driver matching with your device?

acpi_driver_match_device() or strcmp(pdev->name, drv->name) == 0 ?

btw, those drivers supporting acpi probe usually have a acpi table

#if IS_ENABLED(CONFIG_ACPI)
static const struct acpi_device_id hidma_acpi_ids[] = { {"QCOM8061"},
{"QCOM8062", HIDMA_MSI_CAP},
{"QCOM8063", (HIDMA_MSI_CAP | HIDMA_IDENTITY_CAP)}, {},
};
MODULE_DEVICE_TABLE(acpi, hidma_acpi_ids); #endif

Quoted 47 lines

static int platform_match(struct device *dev, struct device_driver *drv)

{
        struct platform_device *pdev = to_platform_device(dev);
        struct platform_driver *pdrv = to_platform_driver(drv);

        /* When driver_override is set, only bind to the matching driver */
        if (pdev->driver_override)
                return !strcmp(pdev->driver_override, drv->name);

        /* Attempt an OF style match first */
        if (of_driver_match_device(dev, drv))
                return 1;

        /* Then try ACPI style match */
        if (acpi_driver_match_device(dev, drv))
                return 1;

        /* Then try to match against the id table */
        if (pdrv->id_table)
                return platform_match_id(pdrv->id_table, pdev) != NULL;

        /* fall-back to driver name match */
        return (strcmp(pdev->name, drv->name) == 0);
}

In both cases, it seems we don't need id_table. id_table can support two or above device names, so that one driver can support multiple device IDs usually with different specific device data.

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +0 -0
index 25a269d431e4..4c32b6dbfe76 100644

drivers/perf/arm_smmuv3_pmu.c static void __exit arm_smmu_pmu_exit(void) · line 990

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +1 -0
@@ -984,6 +984,7 @@ static void __exit arm_smmu_pmu_exit(void)
 
 module_exit(arm_smmu_pmu_exit);
 
+MODULE_ALIAS("platform:arm-smmu-v3-pmcg");
 MODULE_DESCRIPTION("PMU driver for ARM SMMUv3 Performance Monitors Extension");
 MODULE_AUTHOR("Neil Leeder <[email protected]>");
 MODULE_AUTHOR("Shameer Kolothum <[email protected]>");

Thanks
Barry

#8 lore raw
Quoted 61 lines · Barry Song
Quoted 60 lines · Barry Song
Quoted 58 lines · Yicong Yang
Quoted 45 lines · Liang Li

Hi Yicong,

Thanks for your reply,

Quoted 33 lines · Yicong Yang

Hi Barry, Liang,

Quoted 18 lines · Barry Song
Quoted 17 lines · Liang Li
Quoted 7 lines · Yicong Yang

From: Yicong Yang <[email protected]>

On ACPI based system the device is probed by the name directly. If the driver is configured as module it can only be loaded manually. Add the platform id table as well as the module alias then the driver will be loaded automatically by the udev or others once the device added.

Please consider revise the long log to clearly express the purpose of the changes in this patch:

- What's the exact issue the patch is addressing
- Why the changes in this patch can fix the issue or make something working
- Consider impact of the changes introduced by this patch

Quoted 7 lines
Quoted 1 line

These info may help reviewers and maintainers .. and yourself on code merge.

years ago, i found a good doc regarding this,
https://wiki.archlinux.org/title/Modalias

guess it is because /lib/modules/$(uname -r)/modules.alias fails to contain smmu driver without the MODULE_DEVICE_TABLE, isn't it, yicong?

Yes I think it's the reason. I didn't find summary in kernel docs for the modalias as well as the uevent mechanism. Arch wiki has a well illustration for the modalias and suse[1] describes how this is used by the udev for module auto loading.

Quoted 6 lines

For my case I'm using a ACPI based arm64 server and after booting the arm_smmuv3_pmu.ko is not auto loaded by the udevd since we aren't providing this information. In order to support this we need to provide this MODULE_DEVICE_TABLE() when the smmu pmu added as a platform device, then the userspace udev can know which module to load after the device is added.

Quoted 6 lines

Then what's the purpose of the added '.id_table = ...' line in the previous patch ?
<We lost the patch context in this thread.>

Based on above clarification, the updated DEVICE_TABLE would update modalias as expected, right ?

ok, it's lack of illustration in the commit. If we're going to use MODULE_DEVICE_TABLE we need a platform id table. So I add it and I found it weired if we have a id table but not use it for probing, so I also initialize .id_table.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

I found there's also an another way to implement this by used MODULE_ALIAS(), and no need to add an id table. Maybe this way is less controversial.

right, how is your driver matching with your device?

acpi_driver_match_device() or strcmp(pdev->name, drv->name) == 0 ?

The latter. The smmu pmu platform device is created when parsing the IORT so probed by matching the device and driver name directly.

Quoted 42 lines

btw, those drivers supporting acpi probe usually have a acpi table

#if IS_ENABLED(CONFIG_ACPI)
static const struct acpi_device_id hidma_acpi_ids[] = { {"QCOM8061"},
{"QCOM8062", HIDMA_MSI_CAP},
{"QCOM8063", (HIDMA_MSI_CAP | HIDMA_IDENTITY_CAP)}, {},
};
MODULE_DEVICE_TABLE(acpi, hidma_acpi_ids); #endif

Quoted 30 lines

static int platform_match(struct device *dev, struct device_driver *drv)

{
        struct platform_device *pdev = to_platform_device(dev);
        struct platform_driver *pdrv = to_platform_driver(drv);

        /* When driver_override is set, only bind to the matching driver */
        if (pdev->driver_override)
                return !strcmp(pdev->driver_override, drv->name);

        /* Attempt an OF style match first */
        if (of_driver_match_device(dev, drv))
                return 1;

        /* Then try ACPI style match */
        if (acpi_driver_match_device(dev, drv))
                return 1;

        /* Then try to match against the id table */
        if (pdrv->id_table)
                return platform_match_id(pdrv->id_table, pdev) != NULL;

        /* fall-back to driver name match */
        return (strcmp(pdev->name, drv->name) == 0);
}

In both cases, it seems we don't need id_table. id_table can support two or above device names, so that one driver can support multiple device IDs usually with different specific device data.

yes I think you're right. For my case use MODULE_ALIAS is enough. Will respin a v2.

Thanks!

Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
drivers/perf/arm_smmuv3_pmu.c +0 -0
index 25a269d431e4..4c32b6dbfe76 100644
@@ -984,6 +984,7 @@ static void __exit arm_smmu_pmu_exit(void)
 
 module_exit(arm_smmu_pmu_exit);
 
Quoted 8 lines

drivers/perf/arm_smmuv3_pmu.c static void __exit arm_smmu_pmu_exit(void) · line 990

Quoted 5 lines
drivers/perf/arm_smmuv3_pmu.c +1 -0
+MODULE_ALIAS("platform:arm-smmu-v3-pmcg");
 MODULE_DESCRIPTION("PMU driver for ARM SMMUv3 Performance Monitors Extension");
 MODULE_AUTHOR("Neil Leeder <[email protected]>");
 MODULE_AUTHOR("Shameer Kolothum <[email protected]>");

Thanks
Barry

Quoted 2 lines

.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel