mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/5] platform/x86: Constify 'struct bin_attribute'
@ 2024-12-02 19:38 Thomas Weißschuh
  2024-12-02 19:38 ` [PATCH 1/5] platform/x86: dell: dcdbas: " Thomas Weißschuh
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-12-02 19:38 UTC (permalink / raw)
  To: Stuart Hayes, Hans de Goede, Ilpo Järvinen, David E. Box,
	Naveen Krishna Chatradhi, Carlos Bilbao
  Cc: platform-driver-x86, linux-kernel, Thomas Weißschuh

The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.

The usage of read_new/write_new/bin_attrs_new is a transition mechanism
and will be removed after the tree-wide transition to
const struct bin_attribute.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (5):
      platform/x86: dell: dcdbas: Constify 'struct bin_attribute'
      platform/x86: dell_rbu: Constify 'struct bin_attribute'
      platform/x86/intel/sdsi: Constify 'struct bin_attribute'
      platform/x86/intel/pmt: Constify 'struct bin_attribute'
      platform/x86/amd/hsmp: Constify 'struct bin_attribute'

 drivers/platform/x86/amd/hsmp/acpi.c   | 12 ++++++------
 drivers/platform/x86/amd/hsmp/plat.c   | 12 ++++++------
 drivers/platform/x86/dell/dcdbas.c     | 10 +++++-----
 drivers/platform/x86/dell/dcdbas.h     |  8 --------
 drivers/platform/x86/dell/dell_rbu.c   | 20 ++++++++++----------
 drivers/platform/x86/intel/pmt/class.c |  4 ++--
 drivers/platform/x86/intel/sdsi.c      | 34 +++++++++++++++++-----------------
 7 files changed, 46 insertions(+), 54 deletions(-)
---
base-commit: e70140ba0d2b1a30467d4af6bcfe761327b9ec95
change-id: 20241202-sysfs-const-bin_attr-pdx86-c16ca5d376ca

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/5] platform/x86: dell: dcdbas: Constify 'struct bin_attribute'
  2024-12-02 19:38 [PATCH 0/5] platform/x86: Constify 'struct bin_attribute' Thomas Weißschuh
@ 2024-12-02 19:38 ` Thomas Weißschuh
  2024-12-02 19:38 ` [PATCH 2/5] platform/x86: dell_rbu: " Thomas Weißschuh
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-12-02 19:38 UTC (permalink / raw)
  To: Stuart Hayes, Hans de Goede, Ilpo Järvinen, David E. Box,
	Naveen Krishna Chatradhi, Carlos Bilbao
  Cc: platform-driver-x86, linux-kernel, Thomas Weißschuh

The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.

While at it switch from the custom DCDBAS_BIN_ATTR_RW() to the identical
BIN_ATTR_RW() macro.
---
 drivers/platform/x86/dell/dcdbas.c | 10 +++++-----
 drivers/platform/x86/dell/dcdbas.h |  8 --------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/platform/x86/dell/dcdbas.c b/drivers/platform/x86/dell/dcdbas.c
index 0aeb8149c16bfcb5df3cad77b69d7e5978ce6536..8149be25fa267ca027d809c45fe1c3f47fcfd453 100644
--- a/drivers/platform/x86/dell/dcdbas.c
+++ b/drivers/platform/x86/dell/dcdbas.c
@@ -163,7 +163,7 @@ static ssize_t smi_data_buf_size_store(struct device *dev,
 }
 
 static ssize_t smi_data_read(struct file *filp, struct kobject *kobj,
-			     struct bin_attribute *bin_attr,
+			     const struct bin_attribute *bin_attr,
 			     char *buf, loff_t pos, size_t count)
 {
 	ssize_t ret;
@@ -176,7 +176,7 @@ static ssize_t smi_data_read(struct file *filp, struct kobject *kobj,
 }
 
 static ssize_t smi_data_write(struct file *filp, struct kobject *kobj,
-			      struct bin_attribute *bin_attr,
+			      const struct bin_attribute *bin_attr,
 			      char *buf, loff_t pos, size_t count)
 {
 	ssize_t ret;
@@ -636,9 +636,9 @@ static struct notifier_block dcdbas_reboot_nb = {
 	.priority = INT_MIN
 };
 
-static DCDBAS_BIN_ATTR_RW(smi_data);
+static const BIN_ATTR_ADMIN_RW(smi_data, 0);
 
-static struct bin_attribute *dcdbas_bin_attrs[] = {
+static const struct bin_attribute *const dcdbas_bin_attrs[] = {
 	&bin_attr_smi_data,
 	NULL
 };
@@ -662,7 +662,7 @@ static struct attribute *dcdbas_dev_attrs[] = {
 
 static const struct attribute_group dcdbas_attr_group = {
 	.attrs = dcdbas_dev_attrs,
-	.bin_attrs = dcdbas_bin_attrs,
+	.bin_attrs_new = dcdbas_bin_attrs,
 };
 
 static int dcdbas_probe(struct platform_device *dev)
diff --git a/drivers/platform/x86/dell/dcdbas.h b/drivers/platform/x86/dell/dcdbas.h
index 942a23ddded0592d2279da2dfee05113e8f4dbff..a05d7f667586310e379e38601309acdfad25645a 100644
--- a/drivers/platform/x86/dell/dcdbas.h
+++ b/drivers/platform/x86/dell/dcdbas.h
@@ -56,14 +56,6 @@
 #define DCDBAS_DEV_ATTR_WO(_name) \
 	DEVICE_ATTR(_name,0200,NULL,_name##_store);
 
-#define DCDBAS_BIN_ATTR_RW(_name) \
-struct bin_attribute bin_attr_##_name = { \
-	.attr =  { .name = __stringify(_name), \
-		   .mode = 0600 }, \
-	.read =  _name##_read, \
-	.write = _name##_write, \
-}
-
 struct smi_cmd {
 	__u32 magic;
 	__u32 ebx;

-- 
2.47.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/5] platform/x86: dell_rbu: Constify 'struct bin_attribute'
  2024-12-02 19:38 [PATCH 0/5] platform/x86: Constify 'struct bin_attribute' Thomas Weißschuh
  2024-12-02 19:38 ` [PATCH 1/5] platform/x86: dell: dcdbas: " Thomas Weißschuh
@ 2024-12-02 19:38 ` Thomas Weißschuh
  2024-12-02 19:38 ` [PATCH 3/5] platform/x86/intel/sdsi: " Thomas Weißschuh
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-12-02 19:38 UTC (permalink / raw)
  To: Stuart Hayes, Hans de Goede, Ilpo Järvinen, David E. Box,
	Naveen Krishna Chatradhi, Carlos Bilbao
  Cc: platform-driver-x86, linux-kernel, Thomas Weißschuh

The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/platform/x86/dell/dell_rbu.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/platform/x86/dell/dell_rbu.c b/drivers/platform/x86/dell/dell_rbu.c
index 9f51e0fcab04e1c61ce68b90b754b6b43a741b58..e30ca325938cb604560a810e7d63f65b4b70964b 100644
--- a/drivers/platform/x86/dell/dell_rbu.c
+++ b/drivers/platform/x86/dell/dell_rbu.c
@@ -475,7 +475,7 @@ static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
 }
 
 static ssize_t data_read(struct file *filp, struct kobject *kobj,
-			 struct bin_attribute *bin_attr,
+			 const struct bin_attribute *bin_attr,
 			 char *buffer, loff_t pos, size_t count)
 {
 	ssize_t ret_count = 0;
@@ -492,7 +492,7 @@ static ssize_t data_read(struct file *filp, struct kobject *kobj,
 	spin_unlock(&rbu_data.lock);
 	return ret_count;
 }
-static BIN_ATTR_RO(data, 0);
+static const BIN_ATTR_RO(data, 0);
 
 static void callbackfn_rbu(const struct firmware *fw, void *context)
 {
@@ -530,7 +530,7 @@ static void callbackfn_rbu(const struct firmware *fw, void *context)
 }
 
 static ssize_t image_type_read(struct file *filp, struct kobject *kobj,
-			       struct bin_attribute *bin_attr,
+			       const struct bin_attribute *bin_attr,
 			       char *buffer, loff_t pos, size_t count)
 {
 	int size = 0;
@@ -540,7 +540,7 @@ static ssize_t image_type_read(struct file *filp, struct kobject *kobj,
 }
 
 static ssize_t image_type_write(struct file *filp, struct kobject *kobj,
-				struct bin_attribute *bin_attr,
+				const struct bin_attribute *bin_attr,
 				char *buffer, loff_t pos, size_t count)
 {
 	int rc = count;
@@ -597,10 +597,10 @@ static ssize_t image_type_write(struct file *filp, struct kobject *kobj,
 
 	return rc;
 }
-static BIN_ATTR_RW(image_type, 0);
+static const BIN_ATTR_RW(image_type, 0);
 
 static ssize_t packet_size_read(struct file *filp, struct kobject *kobj,
-				struct bin_attribute *bin_attr,
+				const struct bin_attribute *bin_attr,
 				char *buffer, loff_t pos, size_t count)
 {
 	int size = 0;
@@ -613,7 +613,7 @@ static ssize_t packet_size_read(struct file *filp, struct kobject *kobj,
 }
 
 static ssize_t packet_size_write(struct file *filp, struct kobject *kobj,
-				 struct bin_attribute *bin_attr,
+				 const struct bin_attribute *bin_attr,
 				 char *buffer, loff_t pos, size_t count)
 {
 	unsigned long temp;
@@ -626,9 +626,9 @@ static ssize_t packet_size_write(struct file *filp, struct kobject *kobj,
 	spin_unlock(&rbu_data.lock);
 	return count;
 }
-static BIN_ATTR_RW(packet_size, 0);
+static const BIN_ATTR_RW(packet_size, 0);
 
-static struct bin_attribute *rbu_bin_attrs[] = {
+static const struct bin_attribute *const rbu_bin_attrs[] = {
 	&bin_attr_data,
 	&bin_attr_image_type,
 	&bin_attr_packet_size,
@@ -636,7 +636,7 @@ static struct bin_attribute *rbu_bin_attrs[] = {
 };
 
 static const struct attribute_group rbu_group = {
-	.bin_attrs = rbu_bin_attrs,
+	.bin_attrs_new = rbu_bin_attrs,
 };
 
 static int __init dcdrbu_init(void)

-- 
2.47.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/5] platform/x86/intel/sdsi: Constify 'struct bin_attribute'
  2024-12-02 19:38 [PATCH 0/5] platform/x86: Constify 'struct bin_attribute' Thomas Weißschuh
  2024-12-02 19:38 ` [PATCH 1/5] platform/x86: dell: dcdbas: " Thomas Weißschuh
  2024-12-02 19:38 ` [PATCH 2/5] platform/x86: dell_rbu: " Thomas Weißschuh
@ 2024-12-02 19:38 ` Thomas Weißschuh
  2024-12-02 19:38 ` [PATCH 4/5] platform/x86/intel/pmt: " Thomas Weißschuh
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-12-02 19:38 UTC (permalink / raw)
  To: Stuart Hayes, Hans de Goede, Ilpo Järvinen, David E. Box,
	Naveen Krishna Chatradhi, Carlos Bilbao
  Cc: platform-driver-x86, linux-kernel, Thomas Weißschuh

The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/platform/x86/intel/sdsi.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/platform/x86/intel/sdsi.c b/drivers/platform/x86/intel/sdsi.c
index 33f33b1070fdc949c1373251c3bca4234d9da119..30d1c2caf9842dbc355e7dea19f6446c56421228 100644
--- a/drivers/platform/x86/intel/sdsi.c
+++ b/drivers/platform/x86/intel/sdsi.c
@@ -398,8 +398,8 @@ static ssize_t sdsi_provision(struct sdsi_priv *priv, char *buf, size_t count,
 }
 
 static ssize_t provision_akc_write(struct file *filp, struct kobject *kobj,
-				   struct bin_attribute *attr, char *buf, loff_t off,
-				   size_t count)
+				   const struct bin_attribute *attr, char *buf,
+				   loff_t off, size_t count)
 {
 	struct device *dev = kobj_to_dev(kobj);
 	struct sdsi_priv *priv = dev_get_drvdata(dev);
@@ -409,11 +409,11 @@ static ssize_t provision_akc_write(struct file *filp, struct kobject *kobj,
 
 	return sdsi_provision(priv, buf, count, SDSI_CMD_PROVISION_AKC);
 }
-static BIN_ATTR_WO(provision_akc, SDSI_SIZE_WRITE_MSG);
+static const BIN_ATTR_WO(provision_akc, SDSI_SIZE_WRITE_MSG);
 
 static ssize_t provision_cap_write(struct file *filp, struct kobject *kobj,
-				   struct bin_attribute *attr, char *buf, loff_t off,
-				   size_t count)
+				   const struct bin_attribute *attr, char *buf,
+				   loff_t off, size_t count)
 {
 	struct device *dev = kobj_to_dev(kobj);
 	struct sdsi_priv *priv = dev_get_drvdata(dev);
@@ -423,7 +423,7 @@ static ssize_t provision_cap_write(struct file *filp, struct kobject *kobj,
 
 	return sdsi_provision(priv, buf, count, SDSI_CMD_PROVISION_CAP);
 }
-static BIN_ATTR_WO(provision_cap, SDSI_SIZE_WRITE_MSG);
+static const BIN_ATTR_WO(provision_cap, SDSI_SIZE_WRITE_MSG);
 
 static ssize_t
 certificate_read(u64 command, u64 control_flags, struct sdsi_priv *priv,
@@ -469,7 +469,7 @@ certificate_read(u64 command, u64 control_flags, struct sdsi_priv *priv,
 
 static ssize_t
 state_certificate_read(struct file *filp, struct kobject *kobj,
-		       struct bin_attribute *attr, char *buf, loff_t off,
+		       const struct bin_attribute *attr, char *buf, loff_t off,
 		       size_t count)
 {
 	struct device *dev = kobj_to_dev(kobj);
@@ -477,11 +477,11 @@ state_certificate_read(struct file *filp, struct kobject *kobj,
 
 	return certificate_read(SDSI_CMD_READ_STATE, 0, priv, buf, off, count);
 }
-static BIN_ATTR_ADMIN_RO(state_certificate, SDSI_SIZE_READ_MSG);
+static const BIN_ATTR_ADMIN_RO(state_certificate, SDSI_SIZE_READ_MSG);
 
 static ssize_t
 meter_certificate_read(struct file *filp, struct kobject *kobj,
-		       struct bin_attribute *attr, char *buf, loff_t off,
+		       const struct bin_attribute *attr, char *buf, loff_t off,
 		       size_t count)
 {
 	struct device *dev = kobj_to_dev(kobj);
@@ -489,11 +489,11 @@ meter_certificate_read(struct file *filp, struct kobject *kobj,
 
 	return certificate_read(SDSI_CMD_READ_METER, 0, priv, buf, off, count);
 }
-static BIN_ATTR_ADMIN_RO(meter_certificate, SDSI_SIZE_READ_MSG);
+static const BIN_ATTR_ADMIN_RO(meter_certificate, SDSI_SIZE_READ_MSG);
 
 static ssize_t
 meter_current_read(struct file *filp, struct kobject *kobj,
-		   struct bin_attribute *attr, char *buf, loff_t off,
+		   const struct bin_attribute *attr, char *buf, loff_t off,
 		   size_t count)
 {
 	struct device *dev = kobj_to_dev(kobj);
@@ -502,11 +502,11 @@ meter_current_read(struct file *filp, struct kobject *kobj,
 	return certificate_read(SDSI_CMD_READ_METER, CTRL_METER_ENABLE_DRAM,
 				priv, buf, off, count);
 }
-static BIN_ATTR_ADMIN_RO(meter_current, SDSI_SIZE_READ_MSG);
+static const BIN_ATTR_ADMIN_RO(meter_current, SDSI_SIZE_READ_MSG);
 
 static ssize_t registers_read(struct file *filp, struct kobject *kobj,
-			      struct bin_attribute *attr, char *buf, loff_t off,
-			      size_t count)
+			      const struct bin_attribute *attr, char *buf,
+			      loff_t off, size_t count)
 {
 	struct device *dev = kobj_to_dev(kobj);
 	struct sdsi_priv *priv = dev_get_drvdata(dev);
@@ -528,9 +528,9 @@ static ssize_t registers_read(struct file *filp, struct kobject *kobj,
 
 	return count;
 }
-static BIN_ATTR_ADMIN_RO(registers, SDSI_SIZE_REGS);
+static const BIN_ATTR_ADMIN_RO(registers, SDSI_SIZE_REGS);
 
-static struct bin_attribute *sdsi_bin_attrs[] = {
+static const struct bin_attribute *const sdsi_bin_attrs[] = {
 	&bin_attr_registers,
 	&bin_attr_state_certificate,
 	&bin_attr_meter_certificate,
@@ -576,7 +576,7 @@ static struct attribute *sdsi_attrs[] = {
 
 static const struct attribute_group sdsi_group = {
 	.attrs = sdsi_attrs,
-	.bin_attrs = sdsi_bin_attrs,
+	.bin_attrs_new = sdsi_bin_attrs,
 	.is_bin_visible = sdsi_battr_is_visible,
 };
 __ATTRIBUTE_GROUPS(sdsi);

-- 
2.47.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/5] platform/x86/intel/pmt: Constify 'struct bin_attribute'
  2024-12-02 19:38 [PATCH 0/5] platform/x86: Constify 'struct bin_attribute' Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2024-12-02 19:38 ` [PATCH 3/5] platform/x86/intel/sdsi: " Thomas Weißschuh
@ 2024-12-02 19:38 ` Thomas Weißschuh
  2024-12-02 19:38 ` [PATCH 5/5] platform/x86/amd/hsmp: " Thomas Weißschuh
  2024-12-12 14:47 ` [PATCH 0/5] platform/x86: " Ilpo Järvinen
  5 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-12-02 19:38 UTC (permalink / raw)
  To: Stuart Hayes, Hans de Goede, Ilpo Järvinen, David E. Box,
	Naveen Krishna Chatradhi, Carlos Bilbao
  Cc: platform-driver-x86, linux-kernel, Thomas Weißschuh

The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/platform/x86/intel/pmt/class.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/intel/pmt/class.c
index 3c53cab033277bccc981310389f7dc47737825f4..65f26267ff49c39e3e143fa7eedb8df23d3ddc1d 100644
--- a/drivers/platform/x86/intel/pmt/class.c
+++ b/drivers/platform/x86/intel/pmt/class.c
@@ -81,7 +81,7 @@ EXPORT_SYMBOL_NS_GPL(pmt_telem_read_mmio, INTEL_PMT);
  */
 static ssize_t
 intel_pmt_read(struct file *filp, struct kobject *kobj,
-	       struct bin_attribute *attr, char *buf, loff_t off,
+	       const struct bin_attribute *attr, char *buf, loff_t off,
 	       size_t count)
 {
 	struct intel_pmt_entry *entry = container_of(attr,
@@ -308,7 +308,7 @@ static int intel_pmt_dev_register(struct intel_pmt_entry *entry,
 	entry->pmt_bin_attr.attr.name = ns->name;
 	entry->pmt_bin_attr.attr.mode = 0440;
 	entry->pmt_bin_attr.mmap = intel_pmt_mmap;
-	entry->pmt_bin_attr.read = intel_pmt_read;
+	entry->pmt_bin_attr.read_new = intel_pmt_read;
 	entry->pmt_bin_attr.size = entry->size;
 
 	ret = sysfs_create_bin_file(&dev->kobj, &entry->pmt_bin_attr);

-- 
2.47.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/5] platform/x86/amd/hsmp: Constify 'struct bin_attribute'
  2024-12-02 19:38 [PATCH 0/5] platform/x86: Constify 'struct bin_attribute' Thomas Weißschuh
                   ` (3 preceding siblings ...)
  2024-12-02 19:38 ` [PATCH 4/5] platform/x86/intel/pmt: " Thomas Weißschuh
@ 2024-12-02 19:38 ` Thomas Weißschuh
  2024-12-19 14:59   ` Chatradhi, Naveen Krishna
  2025-01-02 21:36   ` Carlos Bilbao
  2024-12-12 14:47 ` [PATCH 0/5] platform/x86: " Ilpo Järvinen
  5 siblings, 2 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-12-02 19:38 UTC (permalink / raw)
  To: Stuart Hayes, Hans de Goede, Ilpo Järvinen, David E. Box,
	Naveen Krishna Chatradhi, Carlos Bilbao
  Cc: platform-driver-x86, linux-kernel, Thomas Weißschuh

The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/platform/x86/amd/hsmp/acpi.c | 12 ++++++------
 drivers/platform/x86/amd/hsmp/plat.c | 12 ++++++------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index dd5b5773328a9aff376a389cbd0109cb8cf0e385..7d802bfe206c73a4570dcd3752faee853bb81485 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -226,7 +226,7 @@ static int hsmp_parse_acpi_table(struct device *dev, u16 sock_ind)
 }
 
 static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj,
-					 struct bin_attribute *bin_attr, char *buf,
+					 const struct bin_attribute *bin_attr, char *buf,
 					 loff_t off, size_t count)
 {
 	struct device *dev = container_of(kobj, struct device, kobj);
@@ -285,19 +285,19 @@ static int init_acpi(struct device *dev)
 	return ret;
 }
 
-static struct bin_attribute  hsmp_metric_tbl_attr = {
+static const struct bin_attribute  hsmp_metric_tbl_attr = {
 	.attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},
-	.read = hsmp_metric_tbl_acpi_read,
+	.read_new = hsmp_metric_tbl_acpi_read,
 	.size = sizeof(struct hsmp_metric_table),
 };
 
-static struct bin_attribute *hsmp_attr_list[] = {
+static const struct bin_attribute *hsmp_attr_list[] = {
 	&hsmp_metric_tbl_attr,
 	NULL
 };
 
-static struct attribute_group hsmp_attr_grp = {
-	.bin_attrs = hsmp_attr_list,
+static const struct attribute_group hsmp_attr_grp = {
+	.bin_attrs_new = hsmp_attr_list,
 	.is_bin_visible = hsmp_is_sock_attr_visible,
 };
 
diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
index 748bbc35648474370275a80daf2c26e5d732f6ad..1fdcd65d398e6ceca154b804074cbba083f4b7f1 100644
--- a/drivers/platform/x86/amd/hsmp/plat.c
+++ b/drivers/platform/x86/amd/hsmp/plat.c
@@ -59,7 +59,7 @@ static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset,
 }
 
 static ssize_t hsmp_metric_tbl_plat_read(struct file *filp, struct kobject *kobj,
-					 struct bin_attribute *bin_attr, char *buf,
+					 const struct bin_attribute *bin_attr, char *buf,
 					 loff_t off, size_t count)
 {
 	struct hsmp_socket *sock;
@@ -97,13 +97,13 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
  * is_bin_visible function is used to show / hide the necessary groups.
  */
 #define HSMP_BIN_ATTR(index, _list)					\
-static struct bin_attribute attr##index = {				\
+static const struct bin_attribute attr##index = {			\
 	.attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},	\
 	.private = (void *)index,					\
-	.read = hsmp_metric_tbl_plat_read,					\
+	.read_new = hsmp_metric_tbl_plat_read,				\
 	.size = sizeof(struct hsmp_metric_table),			\
 };									\
-static struct bin_attribute _list[] = {					\
+static const struct bin_attribute _list[] = {				\
 	&attr##index,							\
 	NULL								\
 }
@@ -118,8 +118,8 @@ HSMP_BIN_ATTR(6, *sock6_attr_list);
 HSMP_BIN_ATTR(7, *sock7_attr_list);
 
 #define HSMP_BIN_ATTR_GRP(index, _list, _name)			\
-static struct attribute_group sock##index##_attr_grp = {	\
-	.bin_attrs = _list,					\
+static const struct attribute_group sock##index##_attr_grp = {	\
+	.bin_attrs_new = _list,					\
 	.is_bin_visible = hsmp_is_sock_attr_visible,		\
 	.name = #_name,						\
 }

-- 
2.47.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/5] platform/x86: Constify 'struct bin_attribute'
  2024-12-02 19:38 [PATCH 0/5] platform/x86: Constify 'struct bin_attribute' Thomas Weißschuh
                   ` (4 preceding siblings ...)
  2024-12-02 19:38 ` [PATCH 5/5] platform/x86/amd/hsmp: " Thomas Weißschuh
@ 2024-12-12 14:47 ` Ilpo Järvinen
  5 siblings, 0 replies; 9+ messages in thread
From: Ilpo Järvinen @ 2024-12-12 14:47 UTC (permalink / raw)
  To: Stuart Hayes, Hans de Goede, David E. Box,
	Naveen Krishna Chatradhi, Carlos Bilbao, Thomas Weißschuh
  Cc: platform-driver-x86, linux-kernel

On Mon, 02 Dec 2024 20:38:31 +0100, Thomas Weißschuh wrote:

> The sysfs core now allows instances of 'struct bin_attribute' to be
> moved into read-only memory. Make use of that to protect them against
> accidental or malicious modifications.
> 
> The usage of read_new/write_new/bin_attrs_new is a transition mechanism
> and will be removed after the tree-wide transition to
> const struct bin_attribute.
> 
> [...]


Thank you for your contribution, it has been applied to my local
review-ilpo-next branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-next branch only once I've pushed my
local branch there, which might take a while.

The list of commits applied:
[1/5] platform/x86: dell: dcdbas: Constify 'struct bin_attribute'
      commit: f05a99b0d5f16bb82d91f602ade9a2f199c5abde
[2/5] platform/x86: dell_rbu: Constify 'struct bin_attribute'
      commit: e7bcc60c87369c22dfd5e3f13c0aac58a7a3e1d9
[3/5] platform/x86/intel/sdsi: Constify 'struct bin_attribute'
      commit: b5a3e35615948ab5faf773d4e5a0206020403538
[4/5] platform/x86/intel/pmt: Constify 'struct bin_attribute'
      commit: 75e76075f2df25ed4e726b722aeb3ed1afd4b12a
[5/5] platform/x86/amd/hsmp: Constify 'struct bin_attribute'
      commit: 2c62a6ed6fe5e084d3ef47d07087088c2e718290

--
 i.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 5/5] platform/x86/amd/hsmp: Constify 'struct bin_attribute'
  2024-12-02 19:38 ` [PATCH 5/5] platform/x86/amd/hsmp: " Thomas Weißschuh
@ 2024-12-19 14:59   ` Chatradhi, Naveen Krishna
  2025-01-02 21:36   ` Carlos Bilbao
  1 sibling, 0 replies; 9+ messages in thread
From: Chatradhi, Naveen Krishna @ 2024-12-19 14:59 UTC (permalink / raw)
  To: Thomas Weißschuh, Stuart Hayes, Hans de Goede,
	Ilpo Järvinen, David E. Box, Carlos Bilbao
  Cc: platform-driver-x86, linux-kernel


On 12/3/2024 1:08 AM, Thomas Weißschuh wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
>
>
> The sysfs core now allows instances of 'struct bin_attribute' to be
> moved into read-only memory. Make use of that to protect them against
> accidental or malicious modifications.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Thanks for the patch

Acked-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>

> ---
>   drivers/platform/x86/amd/hsmp/acpi.c | 12 ++++++------
>   drivers/platform/x86/amd/hsmp/plat.c | 12 ++++++------
>   2 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
> index dd5b5773328a9aff376a389cbd0109cb8cf0e385..7d802bfe206c73a4570dcd3752faee853bb81485 100644
> --- a/drivers/platform/x86/amd/hsmp/acpi.c
> +++ b/drivers/platform/x86/amd/hsmp/acpi.c
> @@ -226,7 +226,7 @@ static int hsmp_parse_acpi_table(struct device *dev, u16 sock_ind)
>   }
>
>   static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj,
> -                                        struct bin_attribute *bin_attr, char *buf,
> +                                        const struct bin_attribute *bin_attr, char *buf,
>                                           loff_t off, size_t count)
>   {
>          struct device *dev = container_of(kobj, struct device, kobj);
> @@ -285,19 +285,19 @@ static int init_acpi(struct device *dev)
>          return ret;
>   }
>
> -static struct bin_attribute  hsmp_metric_tbl_attr = {
> +static const struct bin_attribute  hsmp_metric_tbl_attr = {
>          .attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},
> -       .read = hsmp_metric_tbl_acpi_read,
> +       .read_new = hsmp_metric_tbl_acpi_read,
>          .size = sizeof(struct hsmp_metric_table),
>   };
>
> -static struct bin_attribute *hsmp_attr_list[] = {
> +static const struct bin_attribute *hsmp_attr_list[] = {
>          &hsmp_metric_tbl_attr,
>          NULL
>   };
>
> -static struct attribute_group hsmp_attr_grp = {
> -       .bin_attrs = hsmp_attr_list,
> +static const struct attribute_group hsmp_attr_grp = {
> +       .bin_attrs_new = hsmp_attr_list,
>          .is_bin_visible = hsmp_is_sock_attr_visible,
>   };
>
> diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
> index 748bbc35648474370275a80daf2c26e5d732f6ad..1fdcd65d398e6ceca154b804074cbba083f4b7f1 100644
> --- a/drivers/platform/x86/amd/hsmp/plat.c
> +++ b/drivers/platform/x86/amd/hsmp/plat.c
> @@ -59,7 +59,7 @@ static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset,
>   }
>
>   static ssize_t hsmp_metric_tbl_plat_read(struct file *filp, struct kobject *kobj,
> -                                        struct bin_attribute *bin_attr, char *buf,
> +                                        const struct bin_attribute *bin_attr, char *buf,
>                                           loff_t off, size_t count)
>   {
>          struct hsmp_socket *sock;
> @@ -97,13 +97,13 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
>    * is_bin_visible function is used to show / hide the necessary groups.
>    */
>   #define HSMP_BIN_ATTR(index, _list)                                    \
> -static struct bin_attribute attr##index = {                            \
> +static const struct bin_attribute attr##index = {                      \
>          .attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},       \
>          .private = (void *)index,                                       \
> -       .read = hsmp_metric_tbl_plat_read,                                      \
> +       .read_new = hsmp_metric_tbl_plat_read,                          \
>          .size = sizeof(struct hsmp_metric_table),                       \
>   };                                                                     \
> -static struct bin_attribute _list[] = {                                        \
> +static const struct bin_attribute _list[] = {                          \
>          &attr##index,                                                   \
>          NULL                                                            \
>   }
> @@ -118,8 +118,8 @@ HSMP_BIN_ATTR(6, *sock6_attr_list);
>   HSMP_BIN_ATTR(7, *sock7_attr_list);
>
>   #define HSMP_BIN_ATTR_GRP(index, _list, _name)                 \
> -static struct attribute_group sock##index##_attr_grp = {       \
> -       .bin_attrs = _list,                                     \
> +static const struct attribute_group sock##index##_attr_grp = { \
> +       .bin_attrs_new = _list,                                 \
>          .is_bin_visible = hsmp_is_sock_attr_visible,            \
>          .name = #_name,                                         \
>   }
>
> --
> 2.47.1
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 5/5] platform/x86/amd/hsmp: Constify 'struct bin_attribute'
  2024-12-02 19:38 ` [PATCH 5/5] platform/x86/amd/hsmp: " Thomas Weißschuh
  2024-12-19 14:59   ` Chatradhi, Naveen Krishna
@ 2025-01-02 21:36   ` Carlos Bilbao
  1 sibling, 0 replies; 9+ messages in thread
From: Carlos Bilbao @ 2025-01-02 21:36 UTC (permalink / raw)
  To: Thomas Weißschuh, Stuart Hayes, Hans de Goede,
	Ilpo Järvinen, David E. Box, Naveen Krishna Chatradhi
  Cc: platform-driver-x86, linux-kernel

On 12/2/24 13:38, Thomas Weißschuh wrote:

> The sysfs core now allows instances of 'struct bin_attribute' to be
> moved into read-only memory. Make use of that to protect them against
> accidental or malicious modifications.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
>  drivers/platform/x86/amd/hsmp/acpi.c | 12 ++++++------
>  drivers/platform/x86/amd/hsmp/plat.c | 12 ++++++------
>  2 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
> index dd5b5773328a9aff376a389cbd0109cb8cf0e385..7d802bfe206c73a4570dcd3752faee853bb81485 100644
> --- a/drivers/platform/x86/amd/hsmp/acpi.c
> +++ b/drivers/platform/x86/amd/hsmp/acpi.c
> @@ -226,7 +226,7 @@ static int hsmp_parse_acpi_table(struct device *dev, u16 sock_ind)
>  }
>  
>  static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj,
> -					 struct bin_attribute *bin_attr, char *buf,
> +					 const struct bin_attribute *bin_attr, char *buf,
>  					 loff_t off, size_t count)
>  {
>  	struct device *dev = container_of(kobj, struct device, kobj);
> @@ -285,19 +285,19 @@ static int init_acpi(struct device *dev)
>  	return ret;
>  }
>  
> -static struct bin_attribute  hsmp_metric_tbl_attr = {
> +static const struct bin_attribute  hsmp_metric_tbl_attr = {
>  	.attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},
> -	.read = hsmp_metric_tbl_acpi_read,
> +	.read_new = hsmp_metric_tbl_acpi_read,
>  	.size = sizeof(struct hsmp_metric_table),
>  };
>  
> -static struct bin_attribute *hsmp_attr_list[] = {
> +static const struct bin_attribute *hsmp_attr_list[] = {
>  	&hsmp_metric_tbl_attr,
>  	NULL
>  };
>  
> -static struct attribute_group hsmp_attr_grp = {
> -	.bin_attrs = hsmp_attr_list,
> +static const struct attribute_group hsmp_attr_grp = {
> +	.bin_attrs_new = hsmp_attr_list,
>  	.is_bin_visible = hsmp_is_sock_attr_visible,
>  };
>  
> diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
> index 748bbc35648474370275a80daf2c26e5d732f6ad..1fdcd65d398e6ceca154b804074cbba083f4b7f1 100644
> --- a/drivers/platform/x86/amd/hsmp/plat.c
> +++ b/drivers/platform/x86/amd/hsmp/plat.c
> @@ -59,7 +59,7 @@ static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset,
>  }
>  
>  static ssize_t hsmp_metric_tbl_plat_read(struct file *filp, struct kobject *kobj,
> -					 struct bin_attribute *bin_attr, char *buf,
> +					 const struct bin_attribute *bin_attr, char *buf,
>  					 loff_t off, size_t count)
>  {
>  	struct hsmp_socket *sock;
> @@ -97,13 +97,13 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
>   * is_bin_visible function is used to show / hide the necessary groups.
>   */
>  #define HSMP_BIN_ATTR(index, _list)					\
> -static struct bin_attribute attr##index = {				\
> +static const struct bin_attribute attr##index = {			\
>  	.attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},	\
>  	.private = (void *)index,					\
> -	.read = hsmp_metric_tbl_plat_read,					\
> +	.read_new = hsmp_metric_tbl_plat_read,				\
>  	.size = sizeof(struct hsmp_metric_table),			\
>  };									\
> -static struct bin_attribute _list[] = {					\
> +static const struct bin_attribute _list[] = {				\
>  	&attr##index,							\
>  	NULL								\
>  }
> @@ -118,8 +118,8 @@ HSMP_BIN_ATTR(6, *sock6_attr_list);
>  HSMP_BIN_ATTR(7, *sock7_attr_list);
>  
>  #define HSMP_BIN_ATTR_GRP(index, _list, _name)			\
> -static struct attribute_group sock##index##_attr_grp = {	\
> -	.bin_attrs = _list,					\
> +static const struct attribute_group sock##index##_attr_grp = {	\
> +	.bin_attrs_new = _list,					\
>  	.is_bin_visible = hsmp_is_sock_attr_visible,		\
>  	.name = #_name,						\
>  }


Acked-by: Carlos Bilbao <carlos.bilbao.osdev@gmail.com>


>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-01-02 21:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-02 19:38 [PATCH 0/5] platform/x86: Constify 'struct bin_attribute' Thomas Weißschuh
2024-12-02 19:38 ` [PATCH 1/5] platform/x86: dell: dcdbas: " Thomas Weißschuh
2024-12-02 19:38 ` [PATCH 2/5] platform/x86: dell_rbu: " Thomas Weißschuh
2024-12-02 19:38 ` [PATCH 3/5] platform/x86/intel/sdsi: " Thomas Weißschuh
2024-12-02 19:38 ` [PATCH 4/5] platform/x86/intel/pmt: " Thomas Weißschuh
2024-12-02 19:38 ` [PATCH 5/5] platform/x86/amd/hsmp: " Thomas Weißschuh
2024-12-19 14:59   ` Chatradhi, Naveen Krishna
2025-01-02 21:36   ` Carlos Bilbao
2024-12-12 14:47 ` [PATCH 0/5] platform/x86: " Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome