All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tobias Schumacher" <ts@linux.ibm.com>
To: <sashiko-reviews@lists.linux.dev>,
	"Tobias Schumacher" <ts@linux.ibm.com>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	<linux-s390@vger.kernel.org>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH 3/7] s390/pci: fix resource leak in zpci MSI setup
Date: Thu, 20 Aug 2026 09:43:51 +0200	[thread overview]
Message-ID: <DKTLPWZ1MPXE.1DT0YM08L0LQP@linux.ibm.com> (raw)
In-Reply-To: <20260819090550.8B3EF1F00A3A@smtp.kernel.org>

On Wed Aug 19, 2026 at 11:05 AM CEST, sashiko-bot wrote:

-- snip --

> --- Patch [3]: [PATCH 3/7] s390/pci: fix resource leak in zpci MSI setup ---
> commit ac232ab92e1500cdc9f0a1a221f03f9be96fffe4
> Author: Tobias Schumacher <ts@linux.ibm.com>
>
> s390/pci: fix resource leak in zpci MSI setup
>
> If airq_iv_create() fails in __alloc_airq(), the zpci_sbv bit allocated
> by airq_iv_alloc_bit() is never freed. This permanently leaks one of the
> ZPCI_NR_DEVICES summary bits (~128 total), reducing system capacity with
> each failed device hotplug.
>
>> diff --git a/arch/s390/pci/pci_irq.c b/arch/s390/pci/pci_irq.c
>> index 94b03d16006ba..5e934ac990ac1 100644
>> --- a/arch/s390/pci/pci_irq.c
>> +++ b/arch/s390/pci/pci_irq.c
>> @@ -320,8 +320,11 @@ static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs,
>>  		zdev->aibv = airq_iv_create(msi_vecs,
>>  					    AIRQ_IV_PTR | AIRQ_IV_DATA | AIRQ_IV_BITLOCK,
>>  					    NULL);
>> -		if (!zdev->aibv)
>> +		if (!zdev->aibv) {
>> +			airq_iv_free_bit(zpci_sbv, *bit);
>> +			zdev->aisb = -1UL;
>>  			return -ENOMEM;
>> +		}
>>
>>  		/* Wire up shortcut pointer */
>>  		zpci_ibv[*bit] = zdev->aibv;
>
> [Severity: High]
> This isn't a bug introduced by this patch, but does this direct assignment
> need a memory barrier?
>
> This pointer is published to the globally visible zpci_ibv array.
> Concurrently, the asynchronous hardware interrupt handler
> zpci_floating_irq_handler() locklessly reads this array using
> rcu_dereference(zpci_ibv[si]).
>
> Without an rcu_assign_pointer() or equivalent release barrier, could the
> reader observe the aibv pointer before its internal memory regions are
> globally visible, leading to an invalid pointer dereference?

Duplicate finding already answered for Patch 2, yes, will fix this.

> [Severity: High]
> This is a pre-existing issue, but does zpci_msi_teardown_directed() free
> vectors owned by unrelated PCI devices?
>
> When a driver requests fewer IRQs than its maximum capability, __alloc_airq()
> dynamically allocates exactly msi_vecs bits. However, the teardown blindly
> frees max_msi bits:
>
> arch/s390/pci/pci_irq.c:zpci_msi_teardown_directed() {
>     ...
> 	airq_iv_free(zpci_ibv[0], zdev->msi_first_bit, zdev->max_msi);
>     ...
> }
>
> Will this cause memory corruption by freeing trailing vectors that might have
> been allocated to another device? Should this free zdev->msi_nr_irqs instead?

This is what Patch 4 addresses.

> [Severity: High]
> This is a pre-existing issue, but does zpci_msi_clear_airq() double-count
> the iteration index and write out of bounds?
>
> In zpci_msi_domain_free(), it iterates over nr_irqs and passes the loop index
> i to zpci_msi_clear_airq():
>
> arch/s390/pci/pci_irq.c:zpci_msi_domain_free() {
>     ...
> 	for (i = 0; i < nr_irqs; i++) {
> 		d = irq_domain_get_irq_data(domain, virq + i);
> 		zpci_msi_clear_airq(d, i);
>     ...
> }
>
> Inside zpci_msi_clear_airq(), the hwirq already reflects the correct index.
> The bit is calculated, but then i is added again:
>
> arch/s390/pci/pci_irq.c:zpci_msi_clear_airq() {
>     ...
> 	msi_index = zpci_decode_hwirq_msi_index(d->hwirq);
> 	bit = zdev->msi_first_bit + msi_index;
>     ...
> 		airq_iv_set_ptr(zdev->aibv, bit + i, 0);
>     ...
> }
>
> If nr_irqs is greater than 1, doesn't this skip the intended elements and
> corrupt pointers in unrelated active IRQs while failing to clear the
> target vectors?

Good catch, will fix this.

Tobias


  reply	other threads:[~2026-08-20  7:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19  8:50 [PATCH 0/7] s390/pci: Fix multiple bugs in IRQ domain migration Tobias Schumacher
2026-08-19  8:50 ` [PATCH 1/7] s390/pci: fix double-free in zpci MSI cleanup Tobias Schumacher
2026-08-19  9:03   ` sashiko-bot
2026-08-20  7:20     ` Tobias Schumacher
2026-08-19  8:50 ` [PATCH 2/7] s390/pci: fix use-after-free race in zpci floating interrupt cleanup Tobias Schumacher
2026-08-19  9:20   ` sashiko-bot
2026-08-20  7:29     ` Tobias Schumacher
2026-08-19  8:50 ` [PATCH 3/7] s390/pci: fix resource leak in zpci MSI setup Tobias Schumacher
2026-08-19  9:05   ` sashiko-bot
2026-08-20  7:43     ` Tobias Schumacher [this message]
2026-08-19  8:50 ` [PATCH 4/7] s390/pci: fix MSI directed-mode teardown IRQ bit count Tobias Schumacher
2026-08-19  9:07   ` sashiko-bot
2026-08-20  8:30     ` Tobias Schumacher
2026-08-19  8:50 ` [PATCH 5/7] s390/pci: add NULL check in zpci_msi_clear_airq() Tobias Schumacher
2026-08-19  9:14   ` sashiko-bot
2026-08-20  8:41     ` Tobias Schumacher
2026-08-19  8:50 ` [PATCH 6/7] s390/pci: add error cleanup in zpci_directed_irq_init Tobias Schumacher
2026-08-19  9:02   ` sashiko-bot
2026-08-20  9:01     ` Tobias Schumacher
2026-08-19  8:51 ` [PATCH 7/7] s390/pci: move MSI affinity flag initialization to boot time Tobias Schumacher
2026-08-19  9:06   ` sashiko-bot
2026-08-19  9:24 ` [PATCH 0/7] s390/pci: Fix multiple bugs in IRQ domain migration Niklas Schnelle

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=DKTLPWZ1MPXE.1DT0YM08L0LQP@linux.ibm.com \
    --to=ts@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --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 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.