diff mbox series

[09/16] irq: don't copy cpu affinity mask if source is equal to destination

Message ID 20220718192844.1805158-10-yury.norov@gmail.com (mailing list archive)
State New
Headers show
Series Introduce DEBUG_BITMAP config option and bitmap_check_params() | expand

Commit Message

Yury Norov July 18, 2022, 7:28 p.m. UTC
irq_do_set_affinity() may be called with
	mask == irq_data_to_desc()->irq_common_data.affinity

Copying in that case is useless.

Caught with CONFIG_DEBUG_BITMAP:
[    1.089177]  __bitmap_check_params+0x144/0x250
[    1.089238]  irq_do_set_affinity+0x120/0x470
[    1.089298]  irq_startup+0x140/0x16c
[    1.089350]  __setup_irq+0x668/0x760
[    1.089402]  request_threaded_irq+0xe8/0x1b0
[    1.089474]  vp_find_vqs_msix+0x270/0x410
[    1.089532]  vp_find_vqs+0x48/0x1b4
[    1.089584]  vp_modern_find_vqs+0x1c/0x70
[    1.089641]  init_vq+0x2dc/0x34c
[    1.089690]  virtblk_probe+0xdc/0x710
[    1.089745]  virtio_dev_probe+0x19c/0x270
[    1.089802]  really_probe.part.0+0x9c/0x2ac
[    1.089863]  __driver_probe_device+0x98/0x144
[    1.089923]  driver_probe_device+0xac/0x140
[    1.089985]  __driver_attach+0xf8/0x1a0
[    1.090047]  bus_for_each_dev+0x70/0xd0
[    1.090101]  driver_attach+0x24/0x30
[    1.090153]  bus_add_driver+0x150/0x200
[    1.090208]  driver_register+0x78/0x130
[    1.090266]  register_virtio_driver+0x28/0x40
[    1.090329]  virtio_blk_init+0x68/0xa4
[    1.090400]  do_one_initcall+0x50/0x1c0
[    1.090471]  kernel_init_freeable+0x208/0x28c
[    1.090538]  kernel_init+0x28/0x13c
[    1.090590]  ret_from_fork+0x10/0x20
[    1.090642] ---[ end trace 0000000000000000 ]---
[    1.090705] b1:	ffff2ec742b85e18
[    1.090710] b2:	ffff2ec742b85e18
[    1.090715] b3:	0
[    1.090719] nbits:	256
[    1.090723] start:	0
[    1.090727] off:	0

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 kernel/irq/manage.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Peter Zijlstra July 18, 2022, 9:30 p.m. UTC | #1
On Mon, Jul 18, 2022 at 12:28:37PM -0700, Yury Norov wrote:

>  kernel/irq/manage.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
> index 8c396319d5ac..f9c1b21584ec 100644
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -284,7 +284,8 @@ int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask,
>  	switch (ret) {
>  	case IRQ_SET_MASK_OK:
>  	case IRQ_SET_MASK_OK_DONE:
> -		cpumask_copy(desc->irq_common_data.affinity, mask);
> +		if (desc->irq_common_data.affinity != mask)
> +			cpumask_copy(desc->irq_common_data.affinity, mask);

Seems like mostly pointless logic at this point. This is not a
performance senstive operation afaik.

>  		fallthrough;
>  	case IRQ_SET_MASK_OK_NOCOPY:
>  		irq_validate_effective_affinity(data);
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 8c396319d5ac..f9c1b21584ec 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -284,7 +284,8 @@  int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask,
 	switch (ret) {
 	case IRQ_SET_MASK_OK:
 	case IRQ_SET_MASK_OK_DONE:
-		cpumask_copy(desc->irq_common_data.affinity, mask);
+		if (desc->irq_common_data.affinity != mask)
+			cpumask_copy(desc->irq_common_data.affinity, mask);
 		fallthrough;
 	case IRQ_SET_MASK_OK_NOCOPY:
 		irq_validate_effective_affinity(data);