All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] configfs: Allow the registration of const struct configfs_attribute
@ 2026-07-16 17:09 Thomas Weißschuh
  2026-07-16 17:09 ` [PATCH 1/6] rust: configfs: remove mutability from some field initializers Thomas Weißschuh
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2026-07-16 17:09 UTC (permalink / raw)
  To: Andreas Hindborg, Breno Leitao, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Dan Williams, Rafael J. Wysocki, Len Brown
  Cc: rust-for-linux, linux-kernel, intel-xe, dri-devel, linux-coco,
	linux-acpi, Thomas Weißschuh

The attribute structure defined in driver code never need to be
modified. Allow them to be marked as const.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (6):
      rust: configfs: remove mutability from some field initializers
      configfs: Constify is_visible/is_visible_bin in configfs_group_operations
      configfs: Treat attribute structures as const internally
      configfs: Constify configfs_bin_attribute
      configfs: Allow the registration of const struct configfs_attribute
      samples: configfs: constify the configfs_attribute structures

 drivers/acpi/acpi_configfs.c       |  2 +-
 drivers/gpu/drm/xe/xe_configfs.c   |  4 +--
 drivers/virt/coco/guest/report.c   |  6 ++--
 fs/configfs/configfs_internal.h    | 10 +++---
 fs/configfs/dir.c                  | 10 +++---
 fs/configfs/file.c                 |  6 ++--
 fs/configfs/inode.c                |  2 +-
 include/linux/configfs.h           | 73 ++++++++++++++++++++------------------
 rust/kernel/configfs.rs            | 20 ++++++-----
 samples/configfs/configfs_sample.c | 16 ++++-----
 10 files changed, 78 insertions(+), 71 deletions(-)
---
base-commit: c8d07eca6270b3f41c0e528a470895f1bd42e2b7
change-id: 20260716-configfs-const-base-6955b043560b

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


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

* [PATCH 1/6] rust: configfs: remove mutability from some field initializers
  2026-07-16 17:09 [PATCH 0/6] configfs: Allow the registration of const struct configfs_attribute Thomas Weißschuh
@ 2026-07-16 17:09 ` Thomas Weißschuh
  2026-07-16 17:09 ` [PATCH 2/6] configfs: Constify is_visible/is_visible_bin in configfs_group_operations Thomas Weißschuh
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2026-07-16 17:09 UTC (permalink / raw)
  To: Andreas Hindborg, Breno Leitao, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Dan Williams, Rafael J. Wysocki, Len Brown
  Cc: rust-for-linux, linux-kernel, intel-xe, dri-devel, linux-coco,
	linux-acpi, Thomas Weißschuh

These fields do not require mutable pointers.

Use regular immutable ones.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 rust/kernel/configfs.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs
index 2339c6467325..b33fb2e9adf1 100644
--- a/rust/kernel/configfs.rs
+++ b/rust/kernel/configfs.rs
@@ -754,8 +754,8 @@ pub const fn new_with_child_ctor<const N: usize, Child>(
                 Self {
                     item_type: Opaque::new(bindings::config_item_type {
                         ct_owner: owner.as_ptr(),
-                        ct_group_ops: GroupOperationsVTable::<Data, Child>::vtable_ptr().cast_mut(),
-                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr().cast_mut(),
+                        ct_group_ops: GroupOperationsVTable::<Data, Child>::vtable_ptr(),
+                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(),
                         ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(),
                         ct_bin_attrs: core::ptr::null_mut(),
                     }),
@@ -771,8 +771,8 @@ pub const fn new<const N: usize>(
                 Self {
                     item_type: Opaque::new(bindings::config_item_type {
                         ct_owner: owner.as_ptr(),
-                        ct_group_ops: core::ptr::null_mut(),
-                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr().cast_mut(),
+                        ct_group_ops: core::ptr::null(),
+                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(),
                         ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(),
                         ct_bin_attrs: core::ptr::null_mut(),
                     }),

-- 
2.55.0


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

* [PATCH 2/6] configfs: Constify is_visible/is_visible_bin in configfs_group_operations
  2026-07-16 17:09 [PATCH 0/6] configfs: Allow the registration of const struct configfs_attribute Thomas Weißschuh
  2026-07-16 17:09 ` [PATCH 1/6] rust: configfs: remove mutability from some field initializers Thomas Weißschuh
@ 2026-07-16 17:09 ` Thomas Weißschuh
  2026-07-16 17:09 ` [PATCH 3/6] configfs: Treat attribute structures as const internally Thomas Weißschuh
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2026-07-16 17:09 UTC (permalink / raw)
  To: Andreas Hindborg, Breno Leitao, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Dan Williams, Rafael J. Wysocki, Len Brown
  Cc: rust-for-linux, linux-kernel, intel-xe, dri-devel, linux-coco,
	linux-acpi, Thomas Weißschuh

These callbacks are never meant to modify their configfs_attribute
structure. Enforce this in the type system.

As there are only two implementers of these callbacks, adapt them right
away, avoiding a phased transition.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/gpu/drm/xe/xe_configfs.c | 4 ++--
 drivers/virt/coco/guest/report.c | 4 ++--
 include/linux/configfs.h         | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_configfs.c b/drivers/gpu/drm/xe/xe_configfs.c
index 32102600a148..a5f696e7b329 100644
--- a/drivers/gpu/drm/xe/xe_configfs.c
+++ b/drivers/gpu/drm/xe/xe_configfs.c
@@ -843,7 +843,7 @@ static struct configfs_item_operations xe_config_device_ops = {
 };
 
 static bool xe_config_device_is_visible(struct config_item *item,
-					struct configfs_attribute *attr, int n)
+					const struct configfs_attribute *attr, int n)
 {
 	struct xe_config_group_device *dev = to_xe_config_group_device(item);
 
@@ -938,7 +938,7 @@ static struct configfs_attribute *xe_config_sriov_attrs[] = {
 };
 
 static bool xe_config_sriov_is_visible(struct config_item *item,
-				       struct configfs_attribute *attr, int n)
+				       const struct configfs_attribute *attr, int n)
 {
 	struct xe_config_group_device *dev = to_xe_config_group_device(item->ci_parent);
 
diff --git a/drivers/virt/coco/guest/report.c b/drivers/virt/coco/guest/report.c
index b254a1416286..96e89ddf4989 100644
--- a/drivers/virt/coco/guest/report.c
+++ b/drivers/virt/coco/guest/report.c
@@ -381,7 +381,7 @@ static struct configfs_item_operations tsm_report_item_ops = {
 };
 
 static bool tsm_report_is_visible(struct config_item *item,
-				  struct configfs_attribute *attr, int n)
+				  const struct configfs_attribute *attr, int n)
 {
 	guard(rwsem_read)(&tsm_rwsem);
 	if (!provider.ops)
@@ -394,7 +394,7 @@ static bool tsm_report_is_visible(struct config_item *item,
 }
 
 static bool tsm_report_is_bin_visible(struct config_item *item,
-				      struct configfs_bin_attribute *attr, int n)
+				      const struct configfs_bin_attribute *attr, int n)
 {
 	guard(rwsem_read)(&tsm_rwsem);
 	if (!provider.ops)
diff --git a/include/linux/configfs.h b/include/linux/configfs.h
index ef65c75beeaa..5d3fc8822a1d 100644
--- a/include/linux/configfs.h
+++ b/include/linux/configfs.h
@@ -220,8 +220,8 @@ struct configfs_group_operations {
 	struct config_group *(*make_group)(struct config_group *group, const char *name);
 	void (*disconnect_notify)(struct config_group *group, struct config_item *item);
 	void (*drop_item)(struct config_group *group, struct config_item *item);
-	bool (*is_visible)(struct config_item *item, struct configfs_attribute *attr, int n);
-	bool (*is_bin_visible)(struct config_item *item, struct configfs_bin_attribute *attr,
+	bool (*is_visible)(struct config_item *item, const struct configfs_attribute *attr, int n);
+	bool (*is_bin_visible)(struct config_item *item, const struct configfs_bin_attribute *attr,
 			       int n);
 };
 

-- 
2.55.0


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

* [PATCH 3/6] configfs: Treat attribute structures as const internally
  2026-07-16 17:09 [PATCH 0/6] configfs: Allow the registration of const struct configfs_attribute Thomas Weißschuh
  2026-07-16 17:09 ` [PATCH 1/6] rust: configfs: remove mutability from some field initializers Thomas Weißschuh
  2026-07-16 17:09 ` [PATCH 2/6] configfs: Constify is_visible/is_visible_bin in configfs_group_operations Thomas Weißschuh
@ 2026-07-16 17:09 ` Thomas Weißschuh
  2026-07-16 17:19   ` sashiko-bot
  2026-07-16 17:09 ` [PATCH 4/6] configfs: Constify configfs_bin_attribute Thomas Weißschuh
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Thomas Weißschuh @ 2026-07-16 17:09 UTC (permalink / raw)
  To: Andreas Hindborg, Breno Leitao, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Dan Williams, Rafael J. Wysocki, Len Brown
  Cc: rust-for-linux, linux-kernel, intel-xe, dri-devel, linux-coco,
	linux-acpi, Thomas Weißschuh

The configfs core never modifies the attribute structures defined in
driver core.

Reflect this in the types used internally in the configfs core.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 fs/configfs/configfs_internal.h | 10 +++++-----
 fs/configfs/dir.c               |  6 +++---
 fs/configfs/file.c              |  6 +++---
 fs/configfs/inode.c             |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/fs/configfs/configfs_internal.h b/fs/configfs/configfs_internal.h
index acdeea8e2d69..4bc19cd8d666 100644
--- a/fs/configfs/configfs_internal.h
+++ b/fs/configfs/configfs_internal.h
@@ -104,17 +104,17 @@ static inline struct config_item * to_item(struct dentry * dentry)
 	return ((struct config_item *) sd->s_element);
 }
 
-static inline struct configfs_attribute * to_attr(struct dentry * dentry)
+static inline const struct configfs_attribute * to_attr(struct dentry * dentry)
 {
 	struct configfs_dirent * sd = dentry->d_fsdata;
-	return ((struct configfs_attribute *) sd->s_element);
+	return ((const struct configfs_attribute *) sd->s_element);
 }
 
-static inline struct configfs_bin_attribute *to_bin_attr(struct dentry *dentry)
+static inline const struct configfs_bin_attribute *to_bin_attr(struct dentry *dentry)
 {
-	struct configfs_attribute *attr = to_attr(dentry);
+	const struct configfs_attribute *attr = to_attr(dentry);
 
-	return container_of(attr, struct configfs_bin_attribute, cb_attr);
+	return container_of_const(attr, struct configfs_bin_attribute, cb_attr);
 }
 
 static inline struct config_item *configfs_get_config_item(struct dentry *dentry)
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index 3c88f13f1ca2..9a5c2bc4065d 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -461,7 +461,7 @@ static struct dentry * configfs_lookup(struct inode *dir,
 		 */
 		if ((sd->s_type & CONFIGFS_NOT_PINNED) &&
 		    !strcmp(configfs_get_name(sd), dentry->d_name.name)) {
-			struct configfs_attribute *attr = sd->s_element;
+			const struct configfs_attribute *attr = sd->s_element;
 			umode_t mode = (attr->ca_mode & S_IALLUGO) | S_IFREG;
 
 			dentry->d_fsdata = configfs_get(sd);
@@ -622,8 +622,8 @@ static int populate_attrs(struct config_item *item)
 {
 	const struct config_item_type *t = item->ci_type;
 	const struct configfs_group_operations *ops;
-	struct configfs_attribute *attr;
-	struct configfs_bin_attribute *bin_attr;
+	const struct configfs_attribute *attr;
+	const struct configfs_bin_attribute *bin_attr;
 	int error = 0;
 	int i;
 
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index a48cece775a3..6460b000c593 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -41,8 +41,8 @@ struct configfs_buffer {
 	struct config_item	*item;
 	struct module		*owner;
 	union {
-		struct configfs_attribute	*attr;
-		struct configfs_bin_attribute	*bin_attr;
+		const struct configfs_attribute		*attr;
+		const struct configfs_bin_attribute	*bin_attr;
 	};
 };
 
@@ -291,7 +291,7 @@ static int __configfs_open_file(struct inode *inode, struct file *file, int type
 {
 	struct dentry *dentry = file->f_path.dentry;
 	struct configfs_fragment *frag = to_frag(file);
-	struct configfs_attribute *attr;
+	const struct configfs_attribute *attr;
 	struct configfs_buffer *buffer;
 	int error;
 
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c
index 68290fe0e374..69f1f24e890f 100644
--- a/fs/configfs/inode.c
+++ b/fs/configfs/inode.c
@@ -178,7 +178,7 @@ struct inode *configfs_create(struct dentry *dentry, umode_t mode)
  */
 const unsigned char * configfs_get_name(struct configfs_dirent *sd)
 {
-	struct configfs_attribute *attr;
+	const struct configfs_attribute *attr;
 
 	BUG_ON(!sd || !sd->s_element);
 

-- 
2.55.0


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

* [PATCH 4/6] configfs: Constify configfs_bin_attribute
  2026-07-16 17:09 [PATCH 0/6] configfs: Allow the registration of const struct configfs_attribute Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2026-07-16 17:09 ` [PATCH 3/6] configfs: Treat attribute structures as const internally Thomas Weißschuh
@ 2026-07-16 17:09 ` Thomas Weißschuh
  2026-07-16 17:24   ` sashiko-bot
  2026-07-16 17:09 ` [PATCH 5/6] configfs: Allow the registration of const struct configfs_attribute Thomas Weißschuh
  2026-07-16 17:09 ` [PATCH 6/6] samples: configfs: constify the configfs_attribute structures Thomas Weißschuh
  5 siblings, 1 reply; 9+ messages in thread
From: Thomas Weißschuh @ 2026-07-16 17:09 UTC (permalink / raw)
  To: Andreas Hindborg, Breno Leitao, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Dan Williams, Rafael J. Wysocki, Len Brown
  Cc: rust-for-linux, linux-kernel, intel-xe, dri-devel, linux-coco,
	linux-acpi, Thomas Weißschuh

The configfs_bin_attribute structures defined by driver are never
modified. Make them const.

As there are only two users of these attributes, adapt them in the same
commit to avoid a phased transition.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/acpi/acpi_configfs.c     |  2 +-
 drivers/virt/coco/guest/report.c |  2 +-
 include/linux/configfs.h         | 64 ++++++++++++++++++++--------------------
 rust/kernel/configfs.rs          |  4 +--
 4 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/drivers/acpi/acpi_configfs.c b/drivers/acpi/acpi_configfs.c
index 12ffec795803..6071699c7165 100644
--- a/drivers/acpi/acpi_configfs.c
+++ b/drivers/acpi/acpi_configfs.c
@@ -91,7 +91,7 @@ static ssize_t acpi_table_aml_read(struct config_item *cfg,
 
 CONFIGFS_BIN_ATTR(acpi_table_, aml, NULL, MAX_ACPI_TABLE_SIZE);
 
-static struct configfs_bin_attribute *acpi_table_bin_attrs[] = {
+static const struct configfs_bin_attribute *const acpi_table_bin_attrs[] = {
 	&acpi_table_attr_aml,
 	NULL,
 };
diff --git a/drivers/virt/coco/guest/report.c b/drivers/virt/coco/guest/report.c
index 96e89ddf4989..ad400fbe53f0 100644
--- a/drivers/virt/coco/guest/report.c
+++ b/drivers/virt/coco/guest/report.c
@@ -356,7 +356,7 @@ static struct configfs_attribute *tsm_report_attrs[] = {
 	NULL,
 };
 
-static struct configfs_bin_attribute *tsm_report_bin_attrs[] = {
+static const struct configfs_bin_attribute *const tsm_report_bin_attrs[] = {
 	[TSM_REPORT_INBLOB] = &tsm_report_attr_inblob,
 	[TSM_REPORT_OUTBLOB] = &tsm_report_attr_outblob,
 	[TSM_REPORT_AUXBLOB] = &tsm_report_attr_auxblob,
diff --git a/include/linux/configfs.h b/include/linux/configfs.h
index 5d3fc8822a1d..eff2fb22ab70 100644
--- a/include/linux/configfs.h
+++ b/include/linux/configfs.h
@@ -67,7 +67,7 @@ struct config_item_type {
 	const struct configfs_item_operations	*ct_item_ops;
 	const struct configfs_group_operations	*ct_group_ops;
 	struct configfs_attribute		**ct_attrs;
-	struct configfs_bin_attribute		**ct_bin_attrs;
+	const struct configfs_bin_attribute	*const *ct_bin_attrs;
 };
 
 /**
@@ -160,41 +160,41 @@ struct configfs_bin_attribute {
 	ssize_t (*write)(struct config_item *, const void *, size_t);
 };
 
-#define CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz)		\
-static struct configfs_bin_attribute _pfx##attr_##_name = {	\
-	.cb_attr = {						\
-		.ca_name	= __stringify(_name),		\
-		.ca_mode	= S_IRUGO | S_IWUSR,		\
-		.ca_owner	= THIS_MODULE,			\
-	},							\
-	.cb_private	= _priv,				\
-	.cb_max_size	= _maxsz,				\
-	.read		= _pfx##_name##_read,			\
-	.write		= _pfx##_name##_write,			\
+#define CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz)			\
+static const struct configfs_bin_attribute _pfx##attr_##_name = {	\
+	.cb_attr = {							\
+		.ca_name	= __stringify(_name),			\
+		.ca_mode	= S_IRUGO | S_IWUSR,			\
+		.ca_owner	= THIS_MODULE,				\
+	},								\
+	.cb_private	= _priv,					\
+	.cb_max_size	= _maxsz,					\
+	.read		= _pfx##_name##_read,				\
+	.write		= _pfx##_name##_write,				\
 }
 
-#define CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz)	\
-static struct configfs_bin_attribute _pfx##attr_##_name = {	\
-	.cb_attr = {						\
-		.ca_name	= __stringify(_name),		\
-		.ca_mode	= S_IRUGO,			\
-		.ca_owner	= THIS_MODULE,			\
-	},							\
-	.cb_private	= _priv,				\
-	.cb_max_size	= _maxsz,				\
-	.read		= _pfx##_name##_read,			\
+#define CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz)		\
+static const struct configfs_bin_attribute _pfx##attr_##_name = {	\
+	.cb_attr = {							\
+		.ca_name	= __stringify(_name),			\
+		.ca_mode	= S_IRUGO,				\
+		.ca_owner	= THIS_MODULE,				\
+	},								\
+	.cb_private	= _priv,					\
+	.cb_max_size	= _maxsz,					\
+	.read		= _pfx##_name##_read,				\
 }
 
-#define CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz)	\
-static struct configfs_bin_attribute _pfx##attr_##_name = {	\
-	.cb_attr = {						\
-		.ca_name	= __stringify(_name),		\
-		.ca_mode	= S_IWUSR,			\
-		.ca_owner	= THIS_MODULE,			\
-	},							\
-	.cb_private	= _priv,				\
-	.cb_max_size	= _maxsz,				\
-	.write		= _pfx##_name##_write,			\
+#define CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz)		\
+static const struct configfs_bin_attribute _pfx##attr_##_name = {	\
+	.cb_attr = {							\
+		.ca_name	= __stringify(_name),			\
+		.ca_mode	= S_IWUSR,				\
+		.ca_owner	= THIS_MODULE,				\
+	},								\
+	.cb_private	= _priv,					\
+	.cb_max_size	= _maxsz,					\
+	.write		= _pfx##_name##_write,				\
 }
 
 /*
diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs
index b33fb2e9adf1..f99a6e376fa3 100644
--- a/rust/kernel/configfs.rs
+++ b/rust/kernel/configfs.rs
@@ -757,7 +757,7 @@ pub const fn new_with_child_ctor<const N: usize, Child>(
                         ct_group_ops: GroupOperationsVTable::<Data, Child>::vtable_ptr(),
                         ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(),
                         ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(),
-                        ct_bin_attrs: core::ptr::null_mut(),
+                        ct_bin_attrs: core::ptr::null(),
                     }),
                     _p: PhantomData,
                 }
@@ -774,7 +774,7 @@ pub const fn new<const N: usize>(
                         ct_group_ops: core::ptr::null(),
                         ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(),
                         ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(),
-                        ct_bin_attrs: core::ptr::null_mut(),
+                        ct_bin_attrs: core::ptr::null(),
                     }),
                     _p: PhantomData,
                 }

-- 
2.55.0


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

* [PATCH 5/6] configfs: Allow the registration of const struct configfs_attribute
  2026-07-16 17:09 [PATCH 0/6] configfs: Allow the registration of const struct configfs_attribute Thomas Weißschuh
                   ` (3 preceding siblings ...)
  2026-07-16 17:09 ` [PATCH 4/6] configfs: Constify configfs_bin_attribute Thomas Weißschuh
@ 2026-07-16 17:09 ` Thomas Weißschuh
  2026-07-16 17:09 ` [PATCH 6/6] samples: configfs: constify the configfs_attribute structures Thomas Weißschuh
  5 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2026-07-16 17:09 UTC (permalink / raw)
  To: Andreas Hindborg, Breno Leitao, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Dan Williams, Rafael J. Wysocki, Len Brown
  Cc: rust-for-linux, linux-kernel, intel-xe, dri-devel, linux-coco,
	linux-acpi, Thomas Weißschuh

The attribute structure defined in driver code never need to be
modified. Allow them to be marked as const.

As there are many drivers which use these attributes, prepare for a
phased transition by using a union of const and non-const attributes.

After all drivers have been migrated to the const variant, the non-const
one can be replaced by the const one and the transition machinery will
be removed again.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 fs/configfs/dir.c        | 4 ++--
 include/linux/configfs.h | 5 ++++-
 rust/kernel/configfs.rs  | 8 ++++++--
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index 9a5c2bc4065d..c2152288517c 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -632,8 +632,8 @@ static int populate_attrs(struct config_item *item)
 
 	ops = t->ct_group_ops;
 
-	if (t->ct_attrs) {
-		for (i = 0; (attr = t->ct_attrs[i]) != NULL; i++) {
+	if (t->ct_attrs_const) {
+		for (i = 0; (attr = t->ct_attrs_const[i]) != NULL; i++) {
 			if (ops && ops->is_visible && !ops->is_visible(item, attr, i))
 				continue;
 
diff --git a/include/linux/configfs.h b/include/linux/configfs.h
index eff2fb22ab70..5bead9173ec1 100644
--- a/include/linux/configfs.h
+++ b/include/linux/configfs.h
@@ -66,7 +66,10 @@ struct config_item_type {
 	struct module				*ct_owner;
 	const struct configfs_item_operations	*ct_item_ops;
 	const struct configfs_group_operations	*ct_group_ops;
-	struct configfs_attribute		**ct_attrs;
+	union {
+		struct configfs_attribute		**ct_attrs;
+		const struct configfs_attribute		*const *ct_attrs_const;
+	};
 	const struct configfs_bin_attribute	*const *ct_bin_attrs;
 };
 
diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs
index f99a6e376fa3..2ef9cce693b9 100644
--- a/rust/kernel/configfs.rs
+++ b/rust/kernel/configfs.rs
@@ -756,7 +756,9 @@ pub const fn new_with_child_ctor<const N: usize, Child>(
                         ct_owner: owner.as_ptr(),
                         ct_group_ops: GroupOperationsVTable::<Data, Child>::vtable_ptr(),
                         ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(),
-                        ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(),
+                        __bindgen_anon_1: bindings::config_item_type__bindgen_ty_1 {
+                            ct_attrs_const: core::ptr::from_ref(attributes).cast(),
+                        },
                         ct_bin_attrs: core::ptr::null(),
                     }),
                     _p: PhantomData,
@@ -773,7 +775,9 @@ pub const fn new<const N: usize>(
                         ct_owner: owner.as_ptr(),
                         ct_group_ops: core::ptr::null(),
                         ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(),
-                        ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(),
+                        __bindgen_anon_1: bindings::config_item_type__bindgen_ty_1 {
+                            ct_attrs_const: core::ptr::from_ref(attributes).cast(),
+                        },
                         ct_bin_attrs: core::ptr::null(),
                     }),
                     _p: PhantomData,

-- 
2.55.0


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

* [PATCH 6/6] samples: configfs: constify the configfs_attribute structures
  2026-07-16 17:09 [PATCH 0/6] configfs: Allow the registration of const struct configfs_attribute Thomas Weißschuh
                   ` (4 preceding siblings ...)
  2026-07-16 17:09 ` [PATCH 5/6] configfs: Allow the registration of const struct configfs_attribute Thomas Weißschuh
@ 2026-07-16 17:09 ` Thomas Weißschuh
  5 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2026-07-16 17:09 UTC (permalink / raw)
  To: Andreas Hindborg, Breno Leitao, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Dan Williams, Rafael J. Wysocki, Len Brown
  Cc: rust-for-linux, linux-kernel, intel-xe, dri-devel, linux-coco,
	linux-acpi, Thomas Weißschuh

To show that the transition machinery works, constify the sample code.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 samples/configfs/configfs_sample.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c
index c1b108ec4ea0..9788ec9b8e30 100644
--- a/samples/configfs/configfs_sample.c
+++ b/samples/configfs/configfs_sample.c
@@ -84,7 +84,7 @@ CONFIGFS_ATTR_RO(childless_, showme);
 CONFIGFS_ATTR(childless_, storeme);
 CONFIGFS_ATTR_RO(childless_, description);
 
-static struct configfs_attribute *childless_attrs[] = {
+static const struct configfs_attribute *const childless_attrs[] = {
 	&childless_attr_showme,
 	&childless_attr_storeme,
 	&childless_attr_description,
@@ -92,7 +92,7 @@ static struct configfs_attribute *childless_attrs[] = {
 };
 
 static const struct config_item_type childless_type = {
-	.ct_attrs	= childless_attrs,
+	.ct_attrs_const	= childless_attrs,
 	.ct_owner	= THIS_MODULE,
 };
 
@@ -148,7 +148,7 @@ static ssize_t simple_child_storeme_store(struct config_item *item,
 
 CONFIGFS_ATTR(simple_child_, storeme);
 
-static struct configfs_attribute *simple_child_attrs[] = {
+static const struct configfs_attribute *const simple_child_attrs[] = {
 	&simple_child_attr_storeme,
 	NULL,
 };
@@ -164,7 +164,7 @@ static const struct configfs_item_operations simple_child_item_ops = {
 
 static const struct config_item_type simple_child_type = {
 	.ct_item_ops	= &simple_child_item_ops,
-	.ct_attrs	= simple_child_attrs,
+	.ct_attrs_const	= simple_child_attrs,
 	.ct_owner	= THIS_MODULE,
 };
 
@@ -205,7 +205,7 @@ static ssize_t simple_children_description_show(struct config_item *item,
 
 CONFIGFS_ATTR_RO(simple_children_, description);
 
-static struct configfs_attribute *simple_children_attrs[] = {
+static const struct configfs_attribute *const simple_children_attrs[] = {
 	&simple_children_attr_description,
 	NULL,
 };
@@ -230,7 +230,7 @@ static const struct configfs_group_operations simple_children_group_ops = {
 static const struct config_item_type simple_children_type = {
 	.ct_item_ops	= &simple_children_item_ops,
 	.ct_group_ops	= &simple_children_group_ops,
-	.ct_attrs	= simple_children_attrs,
+	.ct_attrs_const	= simple_children_attrs,
 	.ct_owner	= THIS_MODULE,
 };
 
@@ -283,7 +283,7 @@ static ssize_t group_children_description_show(struct config_item *item,
 
 CONFIGFS_ATTR_RO(group_children_, description);
 
-static struct configfs_attribute *group_children_attrs[] = {
+static const struct configfs_attribute *const group_children_attrs[] = {
 	&group_children_attr_description,
 	NULL,
 };
@@ -298,7 +298,7 @@ static const struct configfs_group_operations group_children_group_ops = {
 
 static const struct config_item_type group_children_type = {
 	.ct_group_ops	= &group_children_group_ops,
-	.ct_attrs	= group_children_attrs,
+	.ct_attrs_const	= group_children_attrs,
 	.ct_owner	= THIS_MODULE,
 };
 

-- 
2.55.0


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

* Re: [PATCH 3/6] configfs: Treat attribute structures as const internally
  2026-07-16 17:09 ` [PATCH 3/6] configfs: Treat attribute structures as const internally Thomas Weißschuh
@ 2026-07-16 17:19   ` sashiko-bot
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-07-16 17:19 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: ojeda, dri-devel

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] configfs_create_file() and configfs_create_bin_file() use I_MUTEX_NORMAL instead of I_MUTEX_PARENT when locking the parent directory.
- [High] Incorrect subclass used when re-acquiring parent directory lock during symlink creation.
--

--- Patch [3]: [PATCH 3/6] configfs: Treat attribute structures as const internally ---
commit 02ad2fb78e37ee44180095f15441af685e40f465
Author: Thomas Weißschuh <linux@weissschuh.net>

configfs: Treat attribute structures as const internally

The configfs core never modifies the attribute structures defined in
driver core. This commit reflects this by updating the types used
internally in the configfs core.

> diff --git a/fs/configfs/file.c b/fs/configfs/file.c
> index a48cece775a39..6460b000c5938 100644
> --- a/fs/configfs/file.c
> +++ b/fs/configfs/file.c

[ ... ]

This is a pre-existing issue, but looking at configfs_create_file() in
fs/configfs/file.c:

int configfs_create_file(struct config_item * item, const struct configfs_attribute * attr)
{
	struct dentry *dir = item->ci_dentry;
	struct configfs_dirent *parent_sd = dir->d_fsdata;
	umode_t mode = (attr->ca_mode & S_IALLUGO) | S_IFREG;
	int error = 0;

	inode_lock_nested(d_inode(dir), I_MUTEX_NORMAL);
	error = configfs_make_dirent(parent_sd, NULL, (void *) attr, mode,
				     CONFIGFS_ITEM_ATTR, parent_sd->s_frag);
	inode_unlock(d_inode(dir));

	return error;
}

[Severity: High]
This isn't a bug introduced by this patch, but should this use I_MUTEX_PARENT
instead of I_MUTEX_NORMAL when locking the parent directory?

Using the wrong lockdep subclass (I_MUTEX_NORMAL instead of I_MUTEX_PARENT)
for a parent directory violates core VFS locking rules.

This defeats lockdep's ability to detect parent-child ordering violations and
can hide real deadlocks until production.


This exact pattern also occurs in configfs_create_bin_file() in the same file:

int configfs_create_bin_file(struct config_item *item,
		const struct configfs_bin_attribute *bin_attr)
{
	struct dentry *dir = item->ci_dentry;
	struct configfs_dirent *parent_sd = dir->d_fsdata;
	umode_t mode = (bin_attr->cb_attr.ca_mode & S_IALLUGO) | S_IFREG;
	int error = 0;

	inode_lock_nested(dir->d_inode, I_MUTEX_NORMAL);
	error = configfs_make_dirent(parent_sd, NULL, (void *) bin_attr, mode,
				     CONFIGFS_ITEM_BIN_ATTR, parent_sd->s_frag);
	inode_unlock(dir->d_inode);

	return error;
}

[Severity: High]
This is a pre-existing issue, but should this also be updated to use
I_MUTEX_PARENT for the same reasons?


Additionally, looking at configfs_symlink() in fs/configfs/symlink.c:

	inode_unlock(dir);
	ret = get_target(symname, &target_item, dentry->d_sb);
	inode_lock(dir);
	if (ret)
		goto out_put;

[Severity: High]
This is a pre-existing issue, but when re-acquiring the parent directory
lock, should this use inode_lock_nested(dir, I_MUTEX_PARENT)?

Calling inode_lock(dir) re-acquires the lock using the default I_MUTEX_NORMAL
lockdep subclass.

As with the file creation paths, using the wrong subclass for a parent
directory defeats lockdep's checks and hides real deadlocks.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716-configfs-const-base-v1-0-c545a4053cb5@weissschuh.net?part=3

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

* Re: [PATCH 4/6] configfs: Constify configfs_bin_attribute
  2026-07-16 17:09 ` [PATCH 4/6] configfs: Constify configfs_bin_attribute Thomas Weißschuh
@ 2026-07-16 17:24   ` sashiko-bot
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-07-16 17:24 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: ojeda, dri-devel

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Low] The configfs documentation was not updated to reflect the new `const` signature of `ct_bin_attrs` in `struct config_item_type`.

Pre-existing issues:
- [High] acpi_table_aml_write lacks validation for minimum payload size and NULL data, leading to a NULL pointer dereference or heap out-of-bounds read.
- [High] tsm_report_inblob_write passes a NULL pointer to memcpy when handling a zero-length write.
--

--- Patch [4]: [PATCH 4/6] configfs: Constify configfs_bin_attribute ---
commit 8e0989136bf4a701a307f8ac9e6579f1dbe58c67
Author: Thomas Weißschuh <linux@weissschuh.net>

configfs: Constify configfs_bin_attribute

The configfs_bin_attribute structures defined by driver are never
modified. Make them const.

As there are only two users of these attributes, adapt them in the same
commit to avoid a phased transition.

> diff --git a/drivers/acpi/acpi_configfs.c b/drivers/acpi/acpi_configfs.c
> index 12ffec7958031..6071699c71655 100644
> --- a/drivers/acpi/acpi_configfs.c
> +++ b/drivers/acpi/acpi_configfs.c
> @@ -91,7 +91,7 @@ static ssize_t acpi_table_aml_read(struct config_item *cfg,
>  
>  CONFIGFS_BIN_ATTR(acpi_table_, aml, NULL, MAX_ACPI_TABLE_SIZE);
>  
> -static struct configfs_bin_attribute *acpi_table_bin_attrs[] = {
> +static const struct configfs_bin_attribute *const acpi_table_bin_attrs[] = {
>  	&acpi_table_attr_aml,

[Severity: High]
This isn't a bug introduced by this patch, but there is a pre-existing issue
in acpi_table_aml_write() which is associated with this attribute.

If a user with write access to the configfs aml attribute performs a 0-byte
write (e.g., write(fd, buf, 0)), configfs_bin_write_iter() sets
write_in_progress but leaves bin_buffer as NULL. On file close,
acpi_table_aml_write() is invoked with data = NULL and size = 0.

The function then immediately dereferences header->length:

	struct acpi_table_header *header = data;
	...
	if (header->length != size) {

This causes a NULL pointer dereference. Additionally, writing a crafted 8-byte
payload can bypass the header->length != size check (if the payload's length
field is 8), leading to an undersized allocation and out-of-bounds read.

Does acpi_table_aml_write() need validation for minimum payload size and NULL
data?

>  	NULL,
>  };

[ ... ]

> diff --git a/drivers/virt/coco/guest/report.c b/drivers/virt/coco/guest/report.c
> index 96e89ddf49896..ad400fbe53f01 100644
> --- a/drivers/virt/coco/guest/report.c
> +++ b/drivers/virt/coco/guest/report.c
> @@ -356,7 +356,7 @@ static struct configfs_attribute *tsm_report_attrs[] = {
>  	NULL,
>  };
>  
> -static struct configfs_bin_attribute *tsm_report_bin_attrs[] = {
> +static const struct configfs_bin_attribute *const tsm_report_bin_attrs[] = {
>  	[TSM_REPORT_INBLOB] = &tsm_report_attr_inblob,

[Severity: High]
This isn't a bug introduced by this patch, but there is a pre-existing issue
in tsm_report_inblob_write() which is associated with this attribute.

A zero-length write to the inblob attribute sets write_in_progress in
configfs without allocating bin_buffer. Upon file release,
tsm_report_inblob_write() is called with buf = NULL and count = 0.

The function then executes:

	memcpy(report->desc.inblob, buf, count);

which resolves to memcpy(..., NULL, 0). This is strictly undefined behavior
in C and can trigger a UBSAN trap, panicking the kernel if panic_on_warn is
enabled.

Does tsm_report_inblob_write() need to check for a zero-length write and NULL
buffer before calling memcpy()?

>  	[TSM_REPORT_OUTBLOB] = &tsm_report_attr_outblob,
>  	[TSM_REPORT_AUXBLOB] = &tsm_report_attr_auxblob,

[ ... ]

> diff --git a/include/linux/configfs.h b/include/linux/configfs.h
> index 5d3fc8822a1d3..eff2fb22ab700 100644
> --- a/include/linux/configfs.h
> +++ b/include/linux/configfs.h
> @@ -67,7 +67,7 @@ struct config_item_type {
>  	const struct configfs_item_operations	*ct_item_ops;
>  	const struct configfs_group_operations	*ct_group_ops;
>  	struct configfs_attribute		**ct_attrs;
> -	struct configfs_bin_attribute		**ct_bin_attrs;
> +	const struct configfs_bin_attribute	*const *ct_bin_attrs;
>  };

[Severity: Low]
Does Documentation/filesystems/configfs.rst need to be updated to reflect
the new const signature of ct_bin_attrs in struct config_item_type? It
currently documents the old non-const pointer array type.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716-configfs-const-base-v1-0-c545a4053cb5@weissschuh.net?part=4

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

end of thread, other threads:[~2026-07-16 17:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16 17:09 [PATCH 0/6] configfs: Allow the registration of const struct configfs_attribute Thomas Weißschuh
2026-07-16 17:09 ` [PATCH 1/6] rust: configfs: remove mutability from some field initializers Thomas Weißschuh
2026-07-16 17:09 ` [PATCH 2/6] configfs: Constify is_visible/is_visible_bin in configfs_group_operations Thomas Weißschuh
2026-07-16 17:09 ` [PATCH 3/6] configfs: Treat attribute structures as const internally Thomas Weißschuh
2026-07-16 17:19   ` sashiko-bot
2026-07-16 17:09 ` [PATCH 4/6] configfs: Constify configfs_bin_attribute Thomas Weißschuh
2026-07-16 17:24   ` sashiko-bot
2026-07-16 17:09 ` [PATCH 5/6] configfs: Allow the registration of const struct configfs_attribute Thomas Weißschuh
2026-07-16 17:09 ` [PATCH 6/6] samples: configfs: constify the configfs_attribute structures Thomas Weißschuh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.