mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Omar Elghoul <oelghoul@linux.ibm.com>
To: Niklas Schnelle <schnelle@linux.ibm.com>,
	linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org
Cc: hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com,
	borntraeger@linux.ibm.com, svens@linux.ibm.com,
	mjrosato@linux.ibm.com, alifm@linux.ibm.com,
	farman@linux.ibm.com, gbayer@linux.ibm.com, pasic@linux.ibm.com,
	alex@shazbot.org, frankja@linux.ibm.com, imbrenda@linux.ibm.com
Subject: Re: [PATCH v8 2/4] s390/pci: Reuse FMB buffer and preserve state in device re-enablement
Date: Mon, 5 Oct 2026 18:05:20 -0400	[thread overview]
Message-ID: <a6d35b06-694e-45da-ab3d-12279cacdc8c@linux.ibm.com> (raw)
In-Reply-To: <023ed9db17d9c7d785dad387fc18dff6bed862d8.camel@linux.ibm.com>

On 10/5/26 3:53 PM, Niklas Schnelle wrote:
> On Mon, 2026-10-05 at 11:45 -0400, Omar Elghoul wrote:
>> Don't free the FMB buffer when disabling measurement in
>> zpci_fmb_disable_device(). Instead, make the buffer persistent for the
>> lifetime of the device and reuse it across enable/disable cycles. Defer
>> freeing the buffer until teardown in zpci_release_device().
>>
>> To support the persistent buffers, add the fmb_enabled bool to struct
>> zpci_dev to decouple whether FMB is enabled from whether the buffer has
>> been allocated. Audit the only consumer of zdev->fmb as a liveness check
>> and update it to reflect this change.
>>
>> Introduce the function zpci_fmb_reenable_device() to ensure that the FMB
>> is enabled. If it was already enabled, disable it, zero the counters,
>> and re-enable it. This allows the function to be used in both first-time
>> enabling and re-enabling measurement. Call it in zpci_reenable_device()
>> to preserve the FMB enablement if it had been implicitly disabled by
>> firmware in zpci_disable_device().
> 
> I think this causes a sequencing error in zpci_hot_reset_device().
> First the device gets disabled via zpci_disable_device(). This
> implicitly disables the FMB but keeps zdev->fmb_enabled set. Then we
> call zpci_fmb_reenable_device() in zpci_reenable_device(). Since zdev-
>> fmb_enabled is set we don't first enable the FMB and instead go
> directly to disabling it but that is wrong since the FMB is already
> disabled as a side effect of the CLP Set PCI Function (Disable) in
> zpci_disable_device().
> 
> Also, and I think Gerd mentioned this before, there is a disconnect in
> semantics between zpci_fmb_reenable_device() and zpci_reenable_device()
> that is quite confusing. While zpci_reenable_device() re-enables the
> device with existing interrupts and I/O address translations, after it
> was disabled, zpci_fmb_reenable_device() on the other hand does a
> disable and then enable cycle.
> 
> I think the idea here is that zdev->fmb_enabled tries to track whether
> the FMB is supposed to be enabled rather than if it is enabled.  This
> makes some sense since the FMB can get disabled by the device entering
> the error state or a zpci_disable_device() and we want to know if we
> need to re-enable it at the re-enable of the device.
> 
> Importantly, unlike the disablement of a device we always initiate the
> enablement. But then we can't try to disable the FMB without knowing if
> it was already disabled. I think a possible solution for this would be
> to have zpci_fmb_reenable_device() mean that we know that the FMB is
> disabled but should be enabled, which we know when we re-enable the
> device and zdev->fmb_enabled is set. Of course then it doesn't do a
> disable but only an enable despite zdev->fmb_enabled already being set,
> Then zpci_fmb_enable_device() on the other hand sets the flag initially
> and then uses zpci_fmb_reenable_device() or a shared helper. Of course
> we would then have to properly document zdev->fmb_enabled as being a
> the target rather than current state.

I agree with your insight and I'd be happy to follow this approach, but
I think this can cause FMB consumers to read stale snapshots (e.g. if
the device was disabled due to an error state or similar but fmb_enabled
is true). What would you think of leaving fmb_enabled as-is to indicate
whether FMB is actually enabled, and then introducing a second bool,
maybe something like fmb_needed, to track the user's intent and whether
we should call zpci_fmb_reenable_device() from zpci_reenable_device()?

This way, a successful zpci_fmb_enable_device() sets both flags, and
zpci_fmb_disable_device() clears both. zpci_disable_device() should
only clear fmb_enabled and leave fmb_needed as-is, allowing us to track
the implicit disablement by the firmware. This will make fmb_enabled
represent the actual firmware truth, and it becomes a reliable liveness
check for the FMB consumers (debugfs and vfio, for now.)

As for zpci_reenable_device(), it would check fmb_needed and if set,
call zpci_fmb_reenable_device(), since we'd already know by that point
that the FMB was implicitly disabled by firmware.

Thanks

> 
> Thanks,
> Niklas


  reply	other threads:[~2026-10-05 22:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-05 15:45 [PATCH v8 0/4] vfio-pci/zdev: Improved zPCI Function Measurement Support Omar Elghoul
2026-10-05 15:45 ` [PATCH v8 1/4] s390/pci: Hold fmb_lock when enabling or disabling PCI devices Omar Elghoul
2026-10-05 15:45 ` [PATCH v8 2/4] s390/pci: Reuse FMB buffer and preserve state in device re-enablement Omar Elghoul
2026-10-05 19:53   ` Niklas Schnelle
2026-10-05 22:05     ` Omar Elghoul [this message]
2026-10-05 15:45 ` [PATCH v8 3/4] s390/pci: Fence FMB enable/disable via debugfs for passthrough devices Omar Elghoul
2026-10-05 18:42   ` Niklas Schnelle
2026-10-05 15:45 ` [PATCH v8 4/4] vfio-pci/zdev: Add VFIO FMB device features Omar Elghoul

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=a6d35b06-694e-45da-ab3d-12279cacdc8c@linux.ibm.com \
    --to=oelghoul@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=alex@shazbot.org \
    --cc=alifm@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=farman@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=gbayer@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    --cc=schnelle@linux.ibm.com \
    --cc=svens@linux.ibm.com \
    /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

all inboxes | Powered by JetHome®