The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Florian Bezdeka" <florian.bezdeka@siemens.com>
Cc: linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH RFC 2/3] genirq: Honor existing IRQ affinities when setting affinity hints
Date: Thu, 20 Aug 2026 14:30:47 +0000	[thread overview]
Message-ID: <20260820143047.9381A1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260819-flo-net-7-2-make-stmmac-default-affinity-aware-v1-2-3f79a99cadaf@siemens.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] irq_set_affinity_and_hint() permanently locks out subsequent affinity updates by the driver itself, breaking dynamic IRQ rebalancing.
- [Medium] __irq_apply_affinity_hint checks IRQD_AFFINITY_SET inside a lock but applies the affinity outside the lock, introducing a TOCTOU race that can overwrite user-defined affinities.
--

--- Patch [2]: [PATCH RFC 2/3] genirq: Honor existing IRQ affinities when setting affinity hints ---
commit c1f8b98c1dbbe4fae2975bbf7872df3c7c3662b6
Author: Florian Bezdeka <florian.bezdeka@siemens.com>

genirq: Honor existing IRQ affinities when setting affinity hints

This commit modifies __irq_apply_affinity_hint to prevent overwriting an
already configured IRQ affinity. It checks if the affinity has been set
previously before allowing the affinity to be updated by a hint.

> diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
> index 7eb07e3bdb4c2..3937ba24df6d6 100644
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -503,11 +503,21 @@ EXPORT_SYMBOL_GPL(irq_force_affinity);
>  
>  int __irq_apply_affinity_hint(unsigned int irq, const struct cpumask *m, bool setaffinity)
>  {
> +	struct irq_data *irq_data;
>  	int ret = -EINVAL;
>  
>  	scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {
>  		scoped_irqdesc->affinity_hint = m;
> +		irq_data = irq_desc_get_irq_data(scoped_irqdesc);
>  		ret = 0;
> +
> +		/*
> +		 * Do not overwrite the affinity in case an affinity for this
> +		 * IRQ has already been requested, e.g. by writing to
> +		 * /proc/irq/<n>/smp_affinity
> +		 */
> +		if (irqd_affinity_was_set(irq_data))
> +			setaffinity = false;

[Severity: High]
Will this prevent drivers from dynamically rebalancing their own IRQ
affinities after the initial setup?

If a driver calls irq_set_affinity_and_hint(), it inherently results in the
IRQD_AFFINITY_SET flag being set. On any subsequent call by the same driver
to update the affinity (for example, during CPU hotplug or queue
reconfiguration), the irqd_affinity_was_set() check will evaluate to true
and clear the setaffinity flag.

Does this unintentionally lock out future driver-initiated affinity updates,
leaving interrupts routed to suboptimal or offline CPUs?

>  	}
>  
>  	if (!ret && m && setaffinity)

[Severity: Medium]
Could this introduce a time-of-check to time-of-use race condition?

The irqd_affinity_was_set() check happens inside the scoped block while the
lock is held. However, the lock is dropped when the scoped block ends, right
before the actual affinity update is performed.

If userspace writes to /proc/irq/<n>/smp_affinity exactly after the scoped
block drops the lock but before __irq_set_affinity() runs, won't the driver
blindly overwrite the newly configured user affinity?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260819-flo-net-7-2-make-stmmac-default-affinity-aware-v1-0-3f79a99cadaf@siemens.com?part=2

  reply	other threads:[~2026-08-20 14:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 14:30 [PATCH RFC 0/3] genirq: Allow drivers to respect userspace IRQ affinities Florian Bezdeka
2026-08-19 14:30 ` [PATCH RFC 1/3] cpumask: Honor irq_default_affinity in cpumask_local_spread() Florian Bezdeka
2026-08-19 18:38   ` Yury Norov
2026-08-20 16:09     ` Sebastian Andrzej Siewior
2026-08-20 14:30   ` sashiko-bot
2026-08-19 14:30 ` [PATCH RFC 2/3] genirq: Honor existing IRQ affinities when setting affinity hints Florian Bezdeka
2026-08-20 14:30   ` sashiko-bot [this message]
2026-08-20 16:41   ` Jakub Kicinski
2026-08-19 14:30 ` [PATCH RFC 3/3] net: stmmac: Migrate IRQ balancing to cpumask_local_spread() Florian Bezdeka
2026-08-19 18:45   ` Yury Norov
2026-08-20 14:30   ` sashiko-bot
2026-08-19 18:28 ` [PATCH RFC 0/3] genirq: Allow drivers to respect userspace IRQ affinities Yury Norov
2026-08-19 23:54 ` Andrew Lunn
2026-08-20  0:10   ` Andrew Lunn
2026-08-20 15:12 ` Sebastian Andrzej Siewior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260820143047.9381A1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=florian.bezdeka@siemens.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox