mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gerd Bayer <gbayer@linux.ibm.com>
To: Omar Elghoul <oelghoul@linux.ibm.com>,
	linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, schnelle@linux.ibm.com,
	Halil Pasic <pasic@linux.ibm.com>
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, alex@shazbot.org, frankja@linux.ibm.com,
	imbrenda@linux.ibm.com, Gerd Bayer <gbayer@linux.ibm.com>
Subject: Re: [PATCH v9 2/4] s390/pci: Reuse FMB buffer and preserve state in device re-enablement
Date: Wed, 14 Oct 2026 09:27:21 +0200	[thread overview]
Message-ID: <ebed4ad46283c7b34679a040b72ba3ba873dd606.camel@linux.ibm.com> (raw)
In-Reply-To: <4d6b3e6c-c1af-4a1f-9a8b-4266f386a299@linux.ibm.com>

On Mon, 2026-10-12 at 13:41 -0400, Omar Elghoul wrote:
> On 10/12/26 5:22 AM, Gerd Bayer wrote:
> > On Wed, 2026-10-07 at 09:59 -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().
> > 
> > I lost track if this was discussed before: Would it make sense to break
> > this out into a separate patch, so that memory allocation/life-time
> > questions are decoupled from function-measurement preservation?
> 
> I think we did discuss that before and I expressed a preference for
> leaving them in together, but since this patch seems to be growing I
> guess splitting it would make review easier.

Hi Omar,

reviewing is one argument, the others are: Debugging, bi-section,
fixing, back-porting, ...

   [ snip ]

> > 
> 
> > > +/* Re-enable PCI function measurement: clear the software IOMMU counters
> > > + * and (re-)enable the FMB. This function is used to restore the desired
> > > + * FMB enablement state when measurement may be implicitly disabled by
> > > + * firmware (i.e., via CLP in zpci_disable_device())
> > > + */
> > > +int zpci_fmb_reenable_device(struct zpci_dev *zdev)
> > > +{
> > > +	u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_SET_MEASURE);
> > > +	struct zpci_iommu_ctrs *ctrs;
> > > +	struct zpci_fib fib = {0};
> > > +	unsigned long flags;
> > > +	u8 cc, status;
> > > +
> > > +	lockdep_assert_held(&zdev->fmb_lock);
> > > +
> > > +	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 the zdev lives */
> > > +		memset(zdev->fmb, 0, sizeof(*zdev->fmb));
> > >   	}
> > > -	return cc ? -EIO : 0;
> > > +
> > > +	/* reset software counters */
> > > +	spin_lock_irqsave(&zdev->dom_lock, flags);
> > > +	ctrs = zpci_get_iommu_ctrs(zdev);
> > > +	if (ctrs) {
> > > +		atomic64_set(&ctrs->mapped_pages, 0);
> > > +		atomic64_set(&ctrs->unmapped_pages, 0);
> > > +		atomic64_set(&ctrs->global_rpcits, 0);
> > > +		atomic64_set(&ctrs->sync_map_rpcits, 0);
> > > +		atomic64_set(&ctrs->sync_rpcits, 0);
> > > +	}
> > > +	spin_unlock_irqrestore(&zdev->dom_lock, flags);
> > 
> > I know this is pre-existing, but how about breaking out the buffer and
> > counter preparation/clearing into a helper function?
> 
> I believe it has been done in a previous version of this series at which
> point we had two callers for it. Since we don't have another caller now
> I didn't think of splitting it up.

To me, the "detour" into clearing the zpci_iommu_ctrs together with its
additional locking requirements was the point where I felt: This
function is doing too many things :)

   [ snip ]
> > 

> > Oh, and while playing around with this patch (with and without my
> > additional modifications), I realized that statistics/function
> > measurement gets re-enabled when I run `zpcictl --reset-fw <bdf>` to a
> > function - despite it being switched off before the reset.
> 
> Great catch -- the FMB re-enablement in zpci_reenable_device() was just
> one of the two places that needed it, I missed to add it in
> pcibios_enable_device() instead of the existing unconditional enable. I
> will fix this in the next version.

It just occured to me, that if you plan to use the same conditional
enable based on fmb_requested/statistics_on in pcibios_enable_device()
you may want to change the initialization of that bool to "true" in
zpci_create_device() to keep the default behavior of the statistics
being on.

That said, I always felt a little uncomfortable with this default
setting, since it creates load on the overall system, even if nobody
cares about the data. Apparently, that default-enable was chosen at the
initial introduction of statistics with commit d0b0885316ab ("s390/pci:
performance statistics and debug infrastructure"). But that's a
separate discussion I need to have with Niklas and Halil

> re: splitting up the functions into a pair of request functions and a
> pair that actually do the MPCIFC: it will make resolving this issue more
> straightforward, because preserving the state in pcibios_enable_device()
> will require us to disable FMB without clearing its flag in
> pcibios_disable_device() as well, which is cleanly possible with the
> changes you suggested.
> 
> Thanks!
> 
> 
[ snip ]

Thank you!
Gerd

  reply	other threads:[~2026-10-14  7:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 13:59 [PATCH v9 0/4] vfio-pci/zdev: Improved zPCI Function Measurement Support Omar Elghoul
2026-10-07 13:59 ` [PATCH v9 1/4] s390/pci: Hold fmb_lock when enabling or disabling PCI devices Omar Elghoul
2026-10-07 13:59 ` [PATCH v9 2/4] s390/pci: Reuse FMB buffer and preserve state in device re-enablement Omar Elghoul
2026-10-12  9:22   ` Gerd Bayer
2026-10-12 17:41     ` Omar Elghoul
2026-10-14  7:27       ` Gerd Bayer [this message]
2026-10-07 13:59 ` [PATCH v9 3/4] s390/pci: Fence FMB enable/disable via debugfs for passthrough devices Omar Elghoul
2026-10-07 13:59 ` [PATCH v9 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=ebed4ad46283c7b34679a040b72ba3ba873dd606.camel@linux.ibm.com \
    --to=gbayer@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=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=oelghoul@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®