[PATCH RFC 10/27] genirq/proc: let procfs copy in the affinity masks

From: Christian Brauner

Date: Mon Nov 02 2026 - 11:42:29 EST


Implement ->proc_write_buf() for smp_affinity, smp_affinity_list and
default_smp_affinity so procfs copies in what is written before it pins
the entry, and parse the masks from that copy. A list of CPUs can be
longer than a page on large machines, so the files take as much as
memdup_user_nul() could copy in before. Anything larger fails with
-EINVAL instead of -ENOMEM.

Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
---
kernel/irq/proc.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
index aa3d5544cfc1..fe683457a088 100644
--- a/kernel/irq/proc.c
+++ b/kernel/irq/proc.c
@@ -9,6 +9,7 @@
#include <linux/gfp.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
+#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/kernel_stat.h>
@@ -134,8 +135,11 @@ static inline int irq_select_affinity_usr(unsigned int irq)
}
#endif

+/* lists of CPUs can outgrow a page, take what memdup_user_nul() took */
+#define IRQ_AFFINITY_WRITE_SIZE (KMALLOC_MAX_SIZE - 1)
+
static ssize_t write_irq_affinity(int type, struct file *file,
- const char __user *buffer, size_t count, loff_t *pos)
+ char *buffer, size_t count, loff_t *pos)
{
unsigned int irq = (int)(long)pde_data(file_inode(file));
cpumask_var_t new_value;
@@ -148,9 +152,9 @@ static ssize_t write_irq_affinity(int type, struct file *file,
return -ENOMEM;

if (type)
- err = cpumask_parselist_user(buffer, count, new_value);
+ err = cpulist_parse(buffer, new_value);
else
- err = cpumask_parse_user(buffer, count, new_value);
+ err = cpumask_parse(buffer, new_value);
if (err)
goto free_cpumask;

@@ -177,25 +181,27 @@ free_cpumask:
}

static ssize_t irq_affinity_proc_write(struct file *file,
- const char __user *buffer, size_t count, loff_t *pos)
+ char *buffer, size_t count, loff_t *pos)
{
return write_irq_affinity(0, file, buffer, count, pos);
}

static ssize_t irq_affinity_list_proc_write(struct file *file,
- const char __user *buffer, size_t count, loff_t *pos)
+ char *buffer, size_t count, loff_t *pos)
{
return write_irq_affinity(1, file, buffer, count, pos);
}

static const struct proc_ops irq_affinity_proc_ops = {
.proc_show = irq_affinity_proc_show,
- .proc_write = irq_affinity_proc_write,
+ .proc_write_buf = irq_affinity_proc_write,
+ .proc_write_size = IRQ_AFFINITY_WRITE_SIZE,
};

static const struct proc_ops irq_affinity_list_proc_ops = {
.proc_show = irq_affinity_list_proc_show,
- .proc_write = irq_affinity_list_proc_write,
+ .proc_write_buf = irq_affinity_list_proc_write,
+ .proc_write_size = IRQ_AFFINITY_WRITE_SIZE,
};

#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
@@ -217,7 +223,7 @@ static int default_affinity_show(struct seq_file *m, void *v)
}

static ssize_t default_affinity_write(struct file *file,
- const char __user *buffer, size_t count, loff_t *ppos)
+ char *buffer, size_t count, loff_t *ppos)
{
cpumask_var_t new_value;
int err;
@@ -225,7 +231,7 @@ static ssize_t default_affinity_write(struct file *file,
if (!zalloc_cpumask_var(&new_value, GFP_KERNEL))
return -ENOMEM;

- err = cpumask_parse_user(buffer, count, new_value);
+ err = cpumask_parse(buffer, new_value);
if (err)
goto out;

@@ -249,7 +255,8 @@ out:

static const struct proc_ops default_affinity_proc_ops = {
.proc_show = default_affinity_show,
- .proc_write = default_affinity_write,
+ .proc_write_buf = default_affinity_write,
+ .proc_write_size = IRQ_AFFINITY_WRITE_SIZE,
};

static int irq_node_proc_show(struct seq_file *m, void *v)

--
2.53.0