genirq: procfs: Make smp_affinity read-only for interrupts marked with IRQD_AFFINITY_MANAGED flag
PATCH 1/1 genirq: procfs: Make smp_affinity read-only for interrupts marked with IRQD_AFFINITY_MANAGED flag
Currently, due to the interrupt subsystem introduced this commit 9c2555835bb3 ("genirq: Introduce IRQD_AFFINITY_MANAGED flag"), an error is reported when a system administrator modifies the smp_affinity for the virtio_blk driver. For example:
jeff-labs:/proc/irq/26 # echo 2 > ./smp_affinity
-bash: echo: write error: Input/output error
However, checking the permissions of smp_affinity/smp_affinity_list shows that they are set to rw. System administrators are strongly complaining about this issue.
jeff-labs:/proc/irq/26 # ls -l
total 0
-r--r--r-- 1 root root 0 Aug 20 01:32 affinity_hint -r--r--r-- 1 root root 0 Aug 20 01:32 effective_affinity -r--r--r-- 1 root root 0 Aug 20 01:32 effective_affinity_list -r--r--r-- 1 root root 0 Aug 20 01:32 node -rw-r--r-- 1 root root 0 Aug 20 01:32 smp_affinity -rw-r--r-- 1 root root 0 Aug 20 01:32 smp_affinity_list -r--r--r-- 1 root root 0 Aug 20 01:32 spurious dr-xr-xr-x 2 root root 0 Aug 20 01:32 virtio3-req.0
Therefore, the permissions of smp_affinity/smp_affinity_list should be changed to read-only.
--- kernel/irq/proc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/irq/proc.c +10 -2
@@ -363,7 +363,11 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)#ifdef CONFIG_SMP /* create /proc/irq/<irq>/smp_affinity */ -proc_create_data ("smp_affinity" ,0644 , desc->dir, +if (unlikely (irqd_affinity_is_managed (&desc->irq_data))) +proc_create_data ("smp_affinity" ,0444 , desc->dir, + &irq_affinity_proc_ops, irqp); +else +proc_create_data ("smp_affinity" ,0644 , desc->dir, &irq_affinity_proc_ops, irqp);/* create /proc/irq/<irq>/affinity_hint */
@@ -371,7 +375,11 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc) irq_affinity_hint_proc_show, irqp);/* create /proc/irq/<irq>/smp_affinity_list */ -proc_create_data ("smp_affinity_list" ,0644 , desc->dir, +if (unlikely (irqd_affinity_is_managed (&desc->irq_data))) +proc_create_data ("smp_affinity_list" ,0444 , desc->dir, + &irq_affinity_list_proc_ops, irqp); +else +proc_create_data ("smp_affinity_list" ,0644 , desc->dir, &irq_affinity_list_proc_ops, irqp); proc_create_single_data("node", 0444, desc->dir, irq_node_proc_show,
--
2.34.1
Quoted 2 lines · Jeff Xie
Currently, due to the interrupt subsystem introduced this commit
9c2555835bb3("genirq: IntroduceIRQD_AFFINITY_MANAGEDflag"),
This is not really a proper sentence.
Quoted 6 lines
an error is reported when a
system administrator modifies thesmp_affinityfor thevirtio_blkdriver. For example:jeff-labs:/proc/irq/26 # echo 2 > ./smp_affinity
-bash: echo: write error: Input/output error
That should obviously return -EPERM for managed interrupts.
Quoted 2 lines
However, checking the permissions of smp_affinity/smp_affinity_list shows that they are set to rw. System administrators are strongly complaining about this issue.
System administrators complain strongly about a lot of things. Such complaints are not necessarily a technical reason to change the code.
A proper reason is to argue, that the kernel already knows at the time of interrupt allocation that the affinity cannot be controlled by userspace and therefore creating the file with write permissions is wrong.
Quoted 10 lines
jeff-labs:/proc/irq/26 # ls -l
total 0(quoted diff) +0
-7-r--r--r-- 1 root root 0 Aug 20 01:32 affinity_hint -r--r--r-- 1 root root 0 Aug 20 01:32 effective_affinity -r--r--r-- 1 root root 0 Aug 20 01:32 effective_affinity_list -r--r--r-- 1 root root 0 Aug 20 01:32 node -rw-r--r-- 1 root root 0 Aug 20 01:32 smp_affinity -rw-r--r-- 1 root root 0 Aug 20 01:32 smp_affinity_list -r--r--r-- 1 root root 0 Aug 20 01:32 spuriousdr-xr-xr-x 2 root root 0 Aug 20 01:32 virtio3-req.0
We can see that from the code, no?
Quoted 1 line
Therefore, the permissions of smp_affinity/smp_affinity_list should be changed to read-only.
Should? Tell what the solution is:
Therefore set the file permissions to read-only for such interrupts.
And please format you change log so that it has linebreaks around 75 characters.
kernel/irq/proc.c void register_irq_proc(unsigned int irq, struct irq_desc *desc) · line 366
Quoted 5 lines
#ifdef
CONFIG_SMPkernel/irq/proc.c +1
-1/* create /proc/irq/<irq>/smp_affinity */ - proc_create_data("smp_affinity", 0644, desc->dir, +if (unlikely (irqd_affinity_is_managed (&desc->irq_data)))
This unlikely is a pointless exercise as this is not a hotpath operation. Also please switch to S_IRUGO / S_IWUSR and simplify the whole thing to:
umode_t umode = S_IRUGO;
if (!irqd_affinity_is_managed(&desc->irq_data))
umode |= S_IWUSR;
proc_create_data("smp_affinity", umode, desc->dir, &irq_affinity_proc_ops, irqp);Thanks,
tglx
August 24, 2024 at 3:16 AM, "Thomas Gleixner" <[email protected]> wrote:
Hi tglx,
Thank you for your very patient review, I’ve learned a lot from it.
Quoted 10 lines · Jeff Xie
Quoted 6 lines
Currently, due to the interrupt subsystem introduced this commit
9c2555835bb3("genirq: Introduce
IRQD_AFFINITY_MANAGEDflag"),This is not really a proper sentence.
Thanks for pointing this out, I see.
The introduced IRQD_AFFINITY_MANAGED is not the reason, I will delete the description.
Quoted 6 lines
Quoted 6 lines
an error is reported when a
system administrator modifies the
smp_affinityfor thevirtio_blkdriver.
Quoted 8 lines
Quoted 6 lines
For example:
jeff-labs:/proc/irq/26 # echo 2 > ./smp_affinity
-bash: echo: write error: Input/output error
That should obviously return
-EPERMfor managed interrupts.'
Got it, I will fix it.
Quoted 11 lines
Quoted 6 lines
However, checking the permissions of smp_affinity/smp_affinity_list shows that
they are set to rw. System administrators are strongly complaining about this issue.
System administrators complain strongly about a lot of things. Such
complaints are not necessarily a technical reason to change the code.
Quoted 7 lines
A proper reason is to argue, that the kernel already knows at the time
of interrupt allocation that the affinity cannot be controlled by
userspace and therefore creating the file with write permissions is
wrong.
Thanks, I will use the description.
Quoted 16 lines
Quoted 16 lines
jeff-labs:/proc/irq/26 # ls -l
total 0
-r--r--r-- 1 root root 0 Aug 20 01:32
affinity_hint-r--r--r-- 1 root root 0 Aug 20 01:32
effective_affinity-r--r--r-- 1 root root 0 Aug 20 01:32
effective_affinity_list-r--r--r-- 1 root root 0 Aug 20 01:32 node
-rw-r--r-- 1 root root 0 Aug 20 01:32
smp_affinity
Quoted 8 lines
Quoted 6 lines
-rw-r--r-- 1 root root 0 Aug 20 01:32
smp_affinity_list-r--r--r-- 1 root root 0 Aug 20 01:32 spurious
dr-xr-xr-x 2 root root 0 Aug 20 01:32 virtio3-req.0
We can see that from the code, no?
Yes, we can see that from the code, I will delete it.
Quoted 8 lines
Quoted 4 lines
Therefore, the permissions of smp_affinity/smp_affinity_list should be changed to read-only.
Should? Tell what the solution is:
Therefore set the file permissions to read-only for such interrupts.
Thanks, That's indeed a better description.
Quoted 4 lines
And please format you change log so that it has linebreaks around 75
characters.
Thanks for you reminder, I will change it.
Quoted 13 lines
Quoted 10 lines
#ifdef
CONFIG_SMP/* create /proc/irq/<irq>/smp_affinity */
- proc_create_data("smp_affinity", 0644,
desc->dir,+ if (unlikely(irqd_affinity_is_managed(&desc->irq_data)))
This unlikely is a pointless exercise as this is not a hotpath
Quoted 7 lines
operation. Also please switch to
S_IRUGO/S_IWUSRand simplify thewhole thing to:
umode_tumode =S_IRUGO;if (!irqd_affinity_is_managed(&desc->irq_data))
Okay, I will delete the unlikely.
After thoroughly analyzing the code, I think it would be better to replace irqd_affinity_is_managed() with irq_can_set_affinity_usr() like below. What do you think?
if (irq_can_set_affinity_usr(desc->irq_data.irq))
umode |= S_IWUSR;Quoted 9 lines
umode |=
S_IWUSR;
proc_create_data("smp_affinity", umode, desc->dir, &irq_affinity_proc_ops, irqp);Thanks,
tglx
Quoted 8 lines · jeff xie
Quoted 7 lines
This unlikely is a pointless exercise as this is not a hotpath operation. Also please switch to
S_IRUGO/S_IWUSRand simplify the whole thing to:
umode_tumode =S_IRUGO;if (!irqd_affinity_is_managed(&desc->irq_data))
Quoted 8 lines
Okay, I will delete the unlikely.
After thoroughly analyzing the code, I think it would be better to replace
irqd_affinity_is_managed()withirq_can_set_affinity_usr()like below. What do you think?if (irq_can_set_affinity_usr(desc->irq_data.irq)) umode |= S_IWUSR;
Makes sense