From: sashiko-bot@kernel.org
To: "Omar Elghoul" <oelghoul@linux.ibm.com>,
linux-s390@vger.kernel.org, kvm@vger.kernel.org
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH v11 3/5] s390/pci: Reuse FMB buffer across enable and disable cycles
Date: Wed, 28 Oct 2026 15:59:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-188110@kernel.org> (raw)
In-Reply-To: <20261028154352.15108-4-oelghoul@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] s390/pci: stale FMB enabled state when zpci_fmb_enable() fails
--
commit ab819cd022e48fbcb2d517d97710539b98750e98
Author: Omar Elghoul <oelghoul@linux.ibm.com>
s390/pci: Reuse FMB buffer across enable and disable cycles
This commit allocates the FMB buffer once on first enable and reuses it across
disable and enable cycles for the lifetime of the zdev, deferring deallocation
until zpci_release_device().
> diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
> index 5889dd227009b..a7e548a83bc15 100644
> --- a/arch/s390/pci/pci.c
> +++ b/arch/s390/pci/pci.c
> @@ -211,13 +211,17 @@ int zpci_fmb_enable(struct zpci_dev *zdev)
>
> lockdep_assert_held(&zdev->fmb_lock);
>
> - if (zdev->fmb || sizeof(*zdev->fmb) < zdev->fmb_length)
> + if (sizeof(*zdev->fmb) < zdev->fmb_length)
> return -EINVAL;
>
> - zdev->fmb = kmem_cache_zalloc(zdev_fmb_cache, GFP_KERNEL);
> - if (!zdev->fmb)
> - return -ENOMEM;
> - WARN_ON((u64) zdev->fmb & 0xf);
> + if (!zdev->fmb) {
> + zdev->fmb = kmem_cache_zalloc(zdev_fmb_cache, GFP_KERNEL);
> + if (!zdev->fmb)
> + return -ENOMEM;
> + } else {
> + /* reuse the same FMB buffer for as long as the zdev lives */
> + memset(zdev->fmb, 0, sizeof(*zdev->fmb));
> + }
>
> /* reset software counters */
> spin_lock_irqsave(&zdev->dom_lock, flags);
> @@ -235,10 +239,6 @@ int zpci_fmb_enable(struct zpci_dev *zdev)
> fib.fmb_addr = virt_to_phys(zdev->fmb);
> fib.gd = zdev->gisa;
> cc = zpci_mod_fc(req, &fib, &status);
> - if (cc) {
> - kmem_cache_free(zdev_fmb_cache, zdev->fmb);
> - zdev->fmb = NULL;
> - }
> return cc ? -EIO : 0;
> }
[Severity: Medium]
Can keeping zdev->fmb non-NULL when zpci_mod_fc() fails in zpci_fmb_enable()
leave the FMB enablement state inconsistent?
zdev->statistics_on is initialized to true in zpci_create_device(). When
pcibios_enable_device() or zpci_reenable_device() calls zpci_fmb_enable(),
the return value is ignored and zdev->statistics_on remains true:
arch/s390/pci/pci.c:pcibios_enable_device() {
...
mutex_lock(&zdev->fmb_lock);
if (zdev->statistics_on)
zpci_fmb_enable(zdev);
mutex_unlock(&zdev->fmb_lock);
...
}
arch/s390/pci/pci.c:zpci_reenable_device() {
...
guard(mutex)(&zdev->fmb_lock);
if (zdev->statistics_on)
zpci_fmb_enable(zdev);
...
}
Previously, zpci_fmb_enable() freed zdev->fmb and reset it to NULL on
zpci_mod_fc() failure, and zpci_fmb_disable() reset zdev->fmb to NULL on
disable. With zdev->fmb kept allocated both across disable/re-enable cycles
and when zpci_mod_fc() fails (or if zpci_reenable_device() returns early on an
error after a prior allocation), both zdev->statistics_on and zdev->fmb remain
non-zero even though hardware measurement is not active.
In arch/s390/pci/pci_debug.c, pci_perf_show() checks whether FMB is disabled
using both fields:
arch/s390/pci/pci_debug.c:pci_perf_show() {
...
mutex_lock(&zdev->fmb_lock);
if (!zdev->statistics_on || !zdev->fmb) {
mutex_unlock(&zdev->fmb_lock);
seq_puts(m, "FMB statistics disabled\n");
return 0;
}
...
}
Similarly, the later commit "vfio-pci/zdev: Add VFIO FMB device features"
relies on the same (!zdev->statistics_on || !zdev->fmb) check in
vfio_pci_zdev_feature_fmb_read(), and zpci_fmb_request_on() rejects subsequent
enable attempts with -EINVAL when zdev->statistics_on is still true.
Would this cause pci_perf_show() to report zeroed or stale FMB counters instead
of "FMB statistics disabled" when enabling FMB fails?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261028154352.15108-1-oelghoul@linux.ibm.com?part=3
next prev parent reply other threads:[~2026-10-28 15:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 15:43 [PATCH v11 0/5] vfio-pci/zdev: Improved zPCI Function Measurement Support Omar Elghoul
2026-10-28 15:43 ` [PATCH v11 1/5] s390/pci: Hold fmb_lock when enabling or disabling PCI devices Omar Elghoul
2026-10-28 15:54 ` sashiko-bot
2026-10-28 15:43 ` [PATCH v11 2/5] s390/pci: Improve function measurement state management Omar Elghoul
2026-10-28 15:57 ` sashiko-bot
2026-10-28 21:05 ` Niklas Schnelle
2026-10-28 15:43 ` [PATCH v11 3/5] s390/pci: Reuse FMB buffer across enable and disable cycles Omar Elghoul
2026-10-28 15:59 ` sashiko-bot [this message]
2026-10-28 16:15 ` Omar Elghoul
2026-10-28 21:12 ` Niklas Schnelle
2026-10-29 12:27 ` Omar Elghoul
2026-10-28 15:43 ` [PATCH v11 4/5] s390/pci: Fence FMB enable/disable via debugfs for passthrough devices Omar Elghoul
2026-10-28 15:47 ` sashiko-bot
2026-10-28 15:43 ` [PATCH v11 5/5] vfio-pci/zdev: Add VFIO FMB device features Omar Elghoul
2026-10-28 15:59 ` sashiko-bot
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=sashiko-outbox-188110@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=oelghoul@linux.ibm.com \
--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.