base: soc: Export soc_device_to_device API
Subsystems (2)
PATCH 1/1 base: soc: Export soc_device_to_device API
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.
--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)
drivers/base/soc.c +1 -0
@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device); static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Greg KH
maintainerQuoted 16 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +0
-0
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 7 lines
drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device); static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,
What in-kernel driver needs this?
Is linux-next breaking without this?
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
thanks,
greg k-h
Bjorn Andersson
Reviewed-byQuoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);
Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
So:
Regards,
Bjorn
Greg KH
maintainerQuoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
thanks,
greg k-h
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into soc_device_register() and registered together with the common attributes...
It sounds like it's worth a prototype.
Regards,
Bjorn
Greg KH
maintainerQuoted 76 lines · Bjorn Andersson
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
Quoted 6 lines
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into
soc_device_register()and registered together with the common attributes...It sounds like it's worth a prototype.
Do you have an in-kernel example I can look at to get an idea of what is needed here?
thanks,
greg k-h
Quoted 82 lines · Greg KH
Quoted 81 lines · Bjorn Andersson
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into
soc_device_register()and registered together with the common attributes...
Quoted 5 lines
Quoted 1 line
It sounds like it's worth a prototype.
Do you have an in-kernel example I can look at to get an idea of what is needed here?
realview_soc_probe(), in drivers/soc/versatile/soc-realview.c, implements the current mechanism of acquiring the soc's struct device and then issuing a few device_create_file calls on that.
Regards,
Bjorn
Greg KH
maintainerQuoted 86 lines · Bjorn Andersson
Quoted 84 lines · Greg KH
Quoted 82 lines · Bjorn Andersson
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into
soc_device_register()and registered together with the common attributes...It sounds like it's worth a prototype.
Quoted 7 lines
Quoted 3 lines
Do you have an in-kernel example I can look at to get an idea of what is needed here?
realview_soc_probe(), indrivers/soc/versatile/soc-realview.c, implements the current mechanism of acquiring the soc's struct device and then issuing a fewdevice_create_filecalls on that.
That looks to be a trivial driver to fix up. Look at 6d03c140db2e ("USB: phy: fsl-usb: convert platform driver to use dev_groups") as an example of how to do this.
Also gotta love the total lack of error checking when calling device_create_file() in that driver :(
thanks,
greg k-h
Quoted 99 lines · Greg KH
Quoted 86 lines · Bjorn Andersson
Quoted 84 lines · Greg KH
Quoted 82 lines · Bjorn Andersson
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into
soc_device_register()and registered together with the common attributes...It sounds like it's worth a prototype.
Quoted 7 lines
Quoted 3 lines
Do you have an in-kernel example I can look at to get an idea of what is needed here?
realview_soc_probe(), indrivers/soc/versatile/soc-realview.c, implements the current mechanism of acquiring the soc's struct device and then issuing a fewdevice_create_filecalls on that.That looks to be a trivial driver to fix up. Look at
6d03c140db2e("USB: phy: fsl-usb: convert platform driver to usedev_groups") as an example of how to do this.
Quoted 6 lines
Also gotta love the total lack of error checking when calling
device_create_file()in that driver :(thanks,
greg k-h
You can see example here https://android.googlesource.com/kernel/msm/+/android-7.1.0_r0.2/drivers/soc/qcom/socinfo.c#1356
I want to add the custom entries to "soc" device path. This can be achieved if i go with "dev_groups"?
sys/devices/soc0 # ls -l
total 0
-r--r--r-- 1 root 0 4096 Jan 1 00:01 family -r--r--r-- 1 root 0 4096 Jan 1 00:01 machine drwxr-xr-x 2 root 0 0 Jan 1 00:01 power -r--r--r-- 1 root 0 4096 Jan 1 00:01 revision -r--r--r-- 1 root 0 4096 Jan 1 00:01 serial_number lrwxrwxrwx 1 root 0 0 Jan 1 00:01 subsystem -> ../../bus/soc -rw-r--r-- 1 root 0 4096 Jan 1 00:01 uevent
Quoted 91 lines · Greg KH
Quoted 90 lines · Bjorn Andersson
Quoted 87 lines · Greg KH
Quoted 76 lines · Bjorn Andersson
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
Quoted 6 lines
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into
soc_device_register()and registered together with the common attributes...It sounds like it's worth a prototype.
Do you have an in-kernel example I can look at to get an idea of what is needed here?
Quoted 8 lines
Quoted 3 lines
realview_soc_probe(), indrivers/soc/versatile/soc-realview.c, implements the current mechanism of acquiring the soc's struct device and then issuing a fewdevice_create_filecalls on that.That looks to be a trivial driver to fix up. Look at
6d03c140db2e("USB: phy: fsl-usb: convert platform driver to usedev_groups") as an example of how to do this.
The difference between the two cases is that in the fsl-usb case it's attributes of the device itself, while in the soc case the realview-soc driver (or the others doing this) calls soc_device_register() to register a new (dangling) soc device, which it then adds its attributes onto.
We can't use dev_groups, because the soc_device (soc.c) isn't actually a driver and the list of attributes is a combination of things from soc.c and e.g. soc-realview.c.
But if we pass a struct attribute_group into soc_device_register() and then have that register both groups using dev.groups, this should be much cleaner at least.
Quoted 3 lines
Also gotta love the total lack of error checking when calling
device_create_file()in that driver :(
That's how we roll in the shire...
Regards,
Bjorn
Greg KH
maintainerQuoted 102 lines · Bjorn Andersson
Quoted 91 lines · Greg KH
Quoted 90 lines · Bjorn Andersson
Quoted 87 lines · Greg KH
Quoted 76 lines · Bjorn Andersson
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
Quoted 6 lines
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into
soc_device_register()and registered together with the common attributes...It sounds like it's worth a prototype.
Do you have an in-kernel example I can look at to get an idea of what is needed here?
Quoted 8 lines
Quoted 3 lines
realview_soc_probe(), indrivers/soc/versatile/soc-realview.c, implements the current mechanism of acquiring the soc's struct device and then issuing a fewdevice_create_filecalls on that.That looks to be a trivial driver to fix up. Look at
6d03c140db2e("USB: phy: fsl-usb: convert platform driver to usedev_groups") as an example of how to do this.
Quoted 5 lines
The difference between the two cases is that in the fsl-usb case it's attributes of the device itself, while in the soc case the realview-soc driver (or the others doing this) calls
soc_device_register()to register a new (dangling) soc device, which it then adds its attributes onto.
That sounds really really odd. Why can't the soc device do the creation "automatically" when the device is registered? The soc core should handle this for the soc "drivers", that's what it is there for.
Quoted 7 lines
We can't use
dev_groups, because thesoc_device(soc.c) isn't actually a driver and the list of attributes is a combination of things fromsoc.cand e.g.soc-realview.c.But if we pass a struct
attribute_groupintosoc_device_register()and then have that register both groups using dev.groups, this should be much cleaner at least.
Don't you have a structure you can store these in as well?
thanks,
greg k-h
Quoted 109 lines · Greg KH
Quoted 102 lines · Bjorn Andersson
Quoted 91 lines · Greg KH
Quoted 90 lines · Bjorn Andersson
Quoted 87 lines · Greg KH
Quoted 76 lines · Bjorn Andersson
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
Quoted 6 lines
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into
soc_device_register()and registered together with the common attributes...It sounds like it's worth a prototype.
Do you have an in-kernel example I can look at to get an idea of what is needed here?
Quoted 8 lines
Quoted 3 lines
realview_soc_probe(), indrivers/soc/versatile/soc-realview.c, implements the current mechanism of acquiring the soc's struct device and then issuing a fewdevice_create_filecalls on that.That looks to be a trivial driver to fix up. Look at
6d03c140db2e("USB: phy: fsl-usb: convert platform driver to usedev_groups") as an example of how to do this.Quoted 5 lines
The difference between the two cases is that in the fsl-usb case it's attributes of the device itself, while in the soc case the realview-soc driver (or the others doing this) calls
soc_device_register()to register a new (dangling) soc device, which it then adds its attributes onto.
Quoted 4 lines
That sounds really really odd. Why can't the soc device do the creation "automatically" when the device is registered? The soc core should handle this for the soc "drivers", that's what it is there for.
Clients are registering to soc framework using "soce_device_register()" with "soc_device_attribute". This attribute structure does not have all the sysfs fields what client are interested. Hence clients are handling their required sysfs fields in their drivers.
https://elixir.bootlin.com/linux/v5.3/source/drivers/base/soc.c#L114
Quoted 9 lines
Quoted 7 lines
We can't use
dev_groups, because thesoc_device(soc.c) isn't actually a driver and the list of attributes is a combination of things fromsoc.cand e.g.soc-realview.c.But if we pass a struct
attribute_groupintosoc_device_register()and then have that register both groups using dev.groups, this should be much cleaner at least.Don't you have a structure you can store these in as well?
At present client is populating entries one-by-one
https://android.googlesource.com/kernel/msm/+/android-7.1.0_r0.2/drivers/soc/qcom/socinfo.c#1254
Quoted 4 lines
thanks,
greg k-h
Greg KH
maintainerQuoted 116 lines · On Mon, Sep 23, 2019 at 02:35:33PM -0700, [email protected] wrote:
Quoted 111 lines · Greg KH
Quoted 102 lines · Bjorn Andersson
Quoted 91 lines · Greg KH
Quoted 90 lines · Bjorn Andersson
Quoted 87 lines · Greg KH
Quoted 76 lines · Bjorn Andersson
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
Quoted 6 lines
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into
soc_device_register()and registered together with the common attributes...It sounds like it's worth a prototype.
Do you have an in-kernel example I can look at to get an idea of what is needed here?
Quoted 8 lines
Quoted 3 lines
realview_soc_probe(), indrivers/soc/versatile/soc-realview.c, implements the current mechanism of acquiring the soc's struct device and then issuing a fewdevice_create_filecalls on that.That looks to be a trivial driver to fix up. Look at
6d03c140db2e("USB: phy: fsl-usb: convert platform driver to usedev_groups") as an example of how to do this.Quoted 7 lines
The difference between the two cases is that in the fsl-usb case it's attributes of the device itself, while in the soc case the realview-soc
driver (or the others doing this) callssoc_device_register()to register a new (dangling) soc device, which it then adds its attributes
onto.Quoted 4 lines
That sounds really really odd. Why can't the soc device do the creation "automatically" when the device is registered? The soc core should handle this for the soc "drivers", that's what it is there for.
Quoted 5 lines
Clients are registering to soc framework using "
soce_device_register()" with "soc_device_attribute". This attribute structure does not have all the sysfs fields what client are interested. Hence clients are handling their required sysfs fields in their drivers.
https://elixir.bootlin.com/linux/v5.3/source/drivers/base/soc.c#L114
Then you should fix that :)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
We can't use
dev_groups, because thesoc_device(soc.c) isn't actually a
driver and the list of attributes is a combination of things fromsoc.c
and e.g.soc-realview.c.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
But if we pass a struct
attribute_groupintosoc_device_register()and then have that register both groups using dev.groups, this should be much cleaner at least.Don't you have a structure you can store these in as well?
At present client is populating entries one-by-one
https://android.googlesource.com/kernel/msm/+/android-7.1.0_r0.2/drivers/soc/qcom/socinfo.c#1254
And that is known to be broken and racy and will cause problems with userspace. This should be fixed...
thanks,
greg k-h
Quoted 117 lines · Greg KH
Quoted 116 lines · On Mon, Sep 23, 2019 at 02:35:33PM -0700, [email protected] wrote:
Quoted 115 lines · Greg KH
Quoted 102 lines · Bjorn Andersson
Quoted 91 lines · Greg KH
Quoted 90 lines · Bjorn Andersson
Quoted 87 lines · Greg KH
Quoted 76 lines · Bjorn Andersson
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
Quoted 6 lines
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into
soc_device_register()and registered together with the common attributes...It sounds like it's worth a prototype.
Do you have an in-kernel example I can look at to get an idea of what is needed here?
Quoted 8 lines
Quoted 3 lines
realview_soc_probe(), indrivers/soc/versatile/soc-realview.c, implements the current mechanism of acquiring the soc's struct device and then issuing a fewdevice_create_filecalls on that.That looks to be a trivial driver to fix up. Look at
6d03c140db2e("USB: phy: fsl-usb: convert platform driver to usedev_groups") as an example of how to do this.Quoted 7 lines
The difference between the two cases is that in the fsl-usb case it's attributes of the device itself, while in the soc case the realview-soc
driver (or the others doing this) callssoc_device_register()to register a new (dangling) soc device, which it then adds its attributes
onto.That sounds really really odd. Why can't the soc device do the creation "automatically" when the device is registered? The soc core should handle this for the soc "drivers", that's what it is there for.
Quoted 7 lines
Quoted 5 lines
Clients are registering to soc framework using "
soce_device_register()" with "soc_device_attribute". This attribute structure does not have all the sysfs fields what client are interested. Hence clients are handling their required sysfs fields in their drivers.
https://elixir.bootlin.com/linux/v5.3/source/drivers/base/soc.c#L114Then you should fix that :)
If i understand, you are asking me to address additional sysfs entries from the client side using "default attribute" groups. I saw your patches about "dev_groups" usage which might be part of 5.4-rc1.
If i go with above approach, i end up seeing the soc information at two different sysfs paths i.e.
Is this my understanding correct?
1. /sys/devices/soc0/*
2. /sys/bus/platform/drivers/msm-socinfo/*
Couple of things which i can think of addressing this issue is:
1. Modify the soc framework APIs to pass the client side sysfs attributes. This will ensure all the soc information fall under /sys/devices/soc0/*
2. Modify "struct soc_device_attribute" and add more entries. So that we do not need to change any soc framework.
Problem here is others might have a different requirement which will not be full fill if i do this.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
We can't use
dev_groups, because thesoc_device(soc.c) isn't actually a
driver and the list of attributes is a combination of things fromsoc.c
and e.g.soc-realview.c.But if we pass a struct
attribute_groupintosoc_device_register()and then have that register both groups using dev.groups, this should be much cleaner at least.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Don't you have a structure you can store these in as well?
At present client is populating entries one-by-one
https://android.googlesource.com/kernel/msm/+/android-7.1.0_r0.2/drivers/soc/qcom/socinfo.c#1254And that is known to be broken and racy and will cause problems with userspace. This should be fixed...
I saw your explanation here about race http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/
Quoted 4 lines
thanks,
greg k-h
Greg KH
maintainerQuoted 135 lines · On Thu, Sep 26, 2019 at 07:33:21AM -0700, [email protected] wrote:
Quoted 126 lines · Greg KH
Quoted 116 lines · On Mon, Sep 23, 2019 at 02:35:33PM -0700, [email protected] wrote:
Quoted 111 lines · Greg KH
Quoted 102 lines · Bjorn Andersson
Quoted 91 lines · Greg KH
Quoted 90 lines · Bjorn Andersson
Quoted 87 lines · Greg KH
Quoted 76 lines · Bjorn Andersson
Quoted 64 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to
access "dev" field in "struct soc_device". This can be achieved
by "soc_device_to_device" API. Soc drivers which are built as a
module they need above API to be exported. Otherwise one can
observe compilation issues.Signed-off-by: Murali Nalajala <[email protected]>
---
drivers/base/soc.c | 1 +
1 file changed, 1 insertion(+)diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 7c0c5ca..4ad52f6 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev)
{
return &soc_dev->dev;
}
+EXPORT_SYMBOL_GPL(soc_device_to_device);Quoted 5 lines
Quoted 2 lines
static umode_t soc_attribute_mode(struct kobject *kobj,
struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 9 lines
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
Quoted 6 lines
The custom attributes that these drivers want to add to the common ones are known in advance, so I presume we could have them passed into
soc_device_register()and registered together with the common attributes...It sounds like it's worth a prototype.
Do you have an in-kernel example I can look at to get an idea of what is needed here?
Quoted 8 lines
Quoted 3 lines
realview_soc_probe(), indrivers/soc/versatile/soc-realview.c, implements the current mechanism of acquiring the soc's struct device and then issuing a fewdevice_create_filecalls on that.That looks to be a trivial driver to fix up. Look at
6d03c140db2e("USB: phy: fsl-usb: convert platform driver to usedev_groups") as an example of how to do this.Quoted 7 lines
The difference between the two cases is that in the fsl-usb case it's attributes of the device itself, while in the soc case the realview-soc
driver (or the others doing this) callssoc_device_register()to register a new (dangling) soc device, which it then adds its attributes
onto.Quoted 4 lines
That sounds really really odd. Why can't the soc device do the creation "automatically" when the device is registered? The soc core should handle this for the soc "drivers", that's what it is there for.
Quoted 8 lines
Clients are registering to soc framework using "
soce_device_register()"
with "soc_device_attribute". This attribute structure does not have all
the sysfs fields what client are interested. Hence clients are handling
their required sysfs fields in their drivers.
https://elixir.bootlin.com/linux/v5.3/source/drivers/base/soc.c#L114Quoted 1 line
Then you should fix that :)
If i understand, you are asking me to address additional sysfs entries from the client side using "default attribute" groups.
I saw your patches about "dev_groups" usage which might be part of 5.4-rc1. If i go with above approach, i end up seeing the soc information at two different sysfs paths i.e.
Is this my understanding correct?
Quoted 2 lines
1.
/sys/devices/soc0/*
2./sys/bus/platform/drivers/msm-socinfo/*
Ah!
Ugh.
Ok, if the soc "core" wants devices to put sysfs files under the "socX" device, then it needs to provide for a way to do this in a sane manner. Exposing the "struct device" of the device here is NOT the sane way to do this.
So we are back to the original request I made here, the SOC "core" needs to be able to create these files for you, so an attribute group list must be available for the soc "driver" to set.
What it is doing now is not ok.
Quoted 3 lines
Couple of things which i can think of addressing this issue is:
1. Modify the soc framework APIs to pass the client side sysfs attributes. This will ensure all the soc information fall under/sys/devices/soc0/*
"pass"? You mean "create", right?
Quoted 4 lines
2. Modify "struct
soc_device_attribute" and add more entries. So that we do not need to change any soc framework.
Problem here is others might have a different requirement which will not be full fill if i do this.
I don't understand what you mean by this second option, sorry.
See my suggestion above, what we have now is just not ok.
thanks,
greg k-h
Quoted 68 lines · Greg KH
Quoted 63 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So there's no way to do platform specific attributes the right way.
Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Quoted 8 lines
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
thanks,
greg k-h
Current soc framework is allowing the soc info drivers to create very limited soc information as sysfs entries like machine name, family, revision and soc_id. Sometimes it become a limited information for the clients to know more about soc information. In this scenario soc info drivers are adding their own sysfs entries on top of what soc framework is doing like hw_platform, hw_platform_subtype etc. I believe this will be an issue for the other soc vendors as well. It is good that if we could add these into the soc framework rather than individual clients defining and adding them as per their requirement.
Greg KH
maintainerQuoted 79 lines · On Thu, Sep 19, 2019 at 03:27:45PM -0700, [email protected] wrote:
Quoted 69 lines · Greg KH
Quoted 64 lines · Bjorn Andersson
Quoted 22 lines · Greg KH
Quoted 21 lines · Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to access "dev" field in "struct
soc_device". This can be achieved by "soc_device_to_device" API. Soc drivers which are built as a module they need above API to be exported. Otherwise one can observe compilation issues.Signed-off-by Murali Nalajala <[email protected]>--- drivers/base/soc.c | 1 + 1 file changed, 1 insertion(+)drivers/base/soc.c +1
-0@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) {return &soc_dev->dev; } +EXPORT_SYMBOL_GPL (soc_device_to_device);Quoted 5 lines
drivers/base/soc.c struct device *soc_device_to_device(struct soc_device *soc_dev) · line 47
Quoted 2 lines
drivers/base/soc.c +0
-0static umode_t soc_attribute_mode(struct kobject *kobj, struct attribute *attr,What in-kernel driver needs this?
Half of the drivers interacting with the soc driver calls this API, several of these I see no reason for being builtin (e.g. ux500 andversatile). So I think this patch makes sense to allow us to build these as modules.
Quoted 2 lines
Is linux-next breaking without this?
No, we postponed the addition of any sysfs attributes in the Qualcomm socinfo driver.
Quoted 11 lines
We don't export things unless we have a user of the export.
Also, adding "custom" sysfs attributes is almost always not the correct thing to do at all. The driver should be doing it, by setting up the attribute group properly so that the driver core can do it automatically for it.
No driver should be doing individual add/remove of sysfs files. If it does so, it is almost guaranteed to be doing it incorrectly and racing userspace.
The problem here is that the attributes are expected to be attached to the soc driver, which is separate from the platform-specific drivers. So
there's no way to do platform specific attributes the right way.Quoted 5 lines
And yes, there's loads of in-kernel examples of doing this wrong, I've been working on fixing that up, look at the patches now in Linus's tree for platform and USB drivers that do this as examples of how to do it right.
Quoted 3 lines
Agreed, this patch should not be used as an approval for any crazy attributes; but it's necessary in order to extend the soc device's attributes, per the current design.
Quoted 8 lines
Wait, no, let's not let the "current design" remain if it is broken!
Why can't the soc driver handle the attributes properly so that the individual driver doesn't have to do the create/remove?
thanks,
greg k-h
Quoted 15 lines
Current soc framework is allowing the soc info drivers to create very limited
soc information as sysfs entries like machine name, family, revision andsoc_id.
Sometimes it become a limited information for the clients to know more about soc
information. In this scenario soc info drivers are adding their own sysfs entries
on top of what soc framework is doing likehw_platform,hw_platform_subtypeetc.
I believe this will be an issue for the other soc vendors as well. It is good that
if we could add these into the soc framework rather than individual clients defining
and adding them as per their requirement.
It's fine to add sysfs files (as long as you document them in Documentation/ABI/) but don't do so file-by-file in a driver as that is racy and will not work. See 6d03c140db2e ("USB: phy: fsl-usb: convert platform driver to use dev_groups") as an example of how to do this in a simple way to have the driver core do all of the work for you automatically.
thanks,
greg k-h