From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3BB44BC00F; Wed, 1 Jul 2026 18:07:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782929227; cv=none; b=eBiIMo6m5xCpB5ChacZjuuhEBqmv2l7gF8eeNGXN0Ao7Vhn0JpALz11+mnrBT1jKM6ERznPcA6XTI2Iq3ETY0Rb76MWKXUXGjBvxV35k4BBD2guhFOsP8a5nB7eYUlCyXK2lg+8WjzHjxIVfLgyPaGGF65YNX3wm9onpBs88I8c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782929227; c=relaxed/simple; bh=gwar5tNYM6be9xihwD/IsTkYs1Crb719n98SigRiw0o=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oUughGA2tiUDS6p8e8TflRFSeWkr9U10yByZEPveLy0CsFy7YPiuvK8zA/DkqWNMuelTkWIWl5mjri39BSaOz9xIFNgQphyLAlSY6nrw7GEsAqP/XXFD+aPfb66jAnk1DnTK98dt9X8AJhyJEotwnporbrRZjf/jM6DIzdYr+Zw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shazbot.org; spf=pass smtp.mailfrom=shazbot.org; dkim=pass (2048-bit key) header.d=shazbot.org header.i=@shazbot.org header.b=gcvbEmFN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iOcyrwU5; arc=none smtp.client-ip=103.168.172.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shazbot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shazbot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shazbot.org header.i=@shazbot.org header.b="gcvbEmFN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iOcyrwU5" Received: from phl-compute-09.internal (phl-compute-09.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id 27344EC00FB; Wed, 1 Jul 2026 14:07:04 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Wed, 01 Jul 2026 14:07:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shazbot.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1782929224; x=1783015624; bh=pcS+lZQq4yNpKC+RPjg+DV+HTSzs32SQph4KqdacYYM=; b= gcvbEmFNUOYmmRZUCYW4lLbB7Gx8bs4E60P5PsjgsM6G4bhqQ0YXuoFNICto7csV 1KZu49kueMvqznGIi6M6ov/7xmapCpCsy5dBFleuZ0dXJBPaEsU9dBS/kC5l4W1t Dcmu9dgAKOK1x/mDq19yML9GsM7qbz6zvYFcIc9CqYXtSzrZNMh2VwTvHQtizUX6 NP3ElZbO5e17bWlIbfRtK8R6KE8w1yB4xLf0mcL3tH4MdaQBtezH6qF1ZCLBVFqP sN0OJcE1aLBTJxq2epQ4vqfaCxXUbFFFd42JOfggPnYf/snzCK9Je9gyTjPX4Omj SjpElNkQuk3Qr7lN+K7sLA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1782929224; x= 1783015624; b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B3AEn5WIBYtkg2gbojz2jXDEmyLh7mfI4fkjM0Wz1B7U2nl31ZZbloA X-ME-Proxy: Feedback-ID: i03f14258:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 1 Jul 2026 14:07:02 -0400 (EDT) Date: Wed, 1 Jul 2026 12:07:00 -0600 From: Alex Williamson To: Zhiping Zhang Cc: Jason Gunthorpe , Leon Romanovsky , Michael Guralnik , Sumit Semwal , Christian Konig , Bjorn Helgaas , , , , , alex@shazbot.org Subject: Re: [PATCH v10 3/4] vfio/pci: implement get_pci_tph and DMA_BUF_TPH feature Message-ID: <20260701120700.58bcafa1@shazbot.org> In-Reply-To: <20260630224328.3218796-4-zhipingz@meta.com> References: <20260630224328.3218796-1-zhipingz@meta.com> <20260630224328.3218796-4-zhipingz@meta.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, 30 Jun 2026 15:42:25 -0700 Zhiping Zhang wrote: > Implement dma-buf get_pci_tph for vfio-pci exported dma-bufs and add > VFIO_DEVICE_FEATURE_DMA_BUF_TPH so userspace can publish TPH metadata > for a VFIO-owned device. >=20 > 8-bit ST and 16-bit Extended ST are distinct PCIe TPH namespaces; the > uAPI carries both with explicit validity flags, and get_pci_tph() > returns the value matching the importer's requested namespace or > -EOPNOTSUPP. >=20 > Publish and read the TPH descriptor under dmabuf->resv, matching the > locking used for other importer-visible dma-buf state. The SET ioctl > takes dma_resv_lock_interruptible(), while the callback runs under > DMA-buf's asserted resv lock. >=20 > Reject requests the device cannot consume as a completer: > pcie_tph_completer_type() must report at least > PCI_EXP_DEVCAP2_TPH_COMP_TPH_ONLY, and Extended ST requires > PCI_EXP_DEVCAP2_TPH_COMP_EXT_TPH. Make PROBE follow the same hardware > gate so the feature only probes as supported when the device can really > consume it. >=20 > Signed-off-by: Zhiping Zhang > --- > drivers/vfio/pci/vfio_pci_core.c | 3 + > drivers/vfio/pci/vfio_pci_dmabuf.c | 99 +++++++++++++++++++++++++++++- > drivers/vfio/pci/vfio_pci_priv.h | 12 ++++ > include/uapi/linux/vfio.h | 43 +++++++++++++ > 4 files changed, 155 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci= _core.c > index a28f1e99362c..c7d6902bc61b 100644 > --- a/drivers/vfio/pci/vfio_pci_core.c > +++ b/drivers/vfio/pci/vfio_pci_core.c > @@ -1572,6 +1572,9 @@ int vfio_pci_core_ioctl_feature(struct vfio_device = *device, u32 flags, > return vfio_pci_core_feature_token(vdev, flags, arg, argsz); > case VFIO_DEVICE_FEATURE_DMA_BUF: > return vfio_pci_core_feature_dma_buf(vdev, flags, arg, argsz); > + case VFIO_DEVICE_FEATURE_DMA_BUF_TPH: > + return vfio_pci_core_feature_dma_buf_tph(vdev, flags, arg, > + argsz); > default: > return -ENOTTY; > } > diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_p= ci_dmabuf.c > index c16f460c01d6..8de72f9e7502 100644 > --- a/drivers/vfio/pci/vfio_pci_dmabuf.c > +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c > @@ -3,6 +3,7 @@ > */ > #include > #include > +#include > #include > =20 > #include "vfio_pci_priv.h" > @@ -19,7 +20,14 @@ struct vfio_pci_dma_buf { > u32 nr_ranges; > struct kref kref; > struct completion comp; > - u8 revoked : 1; > + > + /* Protected by dmabuf->resv. */ > + u16 tph_st_ext; > + u8 tph_st; > + bool revoked; > + u8 tph_st_valid:1; > + u8 tph_st_ext_valid:1; > + u8 tph_ph:2; Since it seems there will be a v11, note again the comment made here on v9: On Tue, 23 Jun 2026 22:24:54 -0700 Zhiping Zhang wrote: > On Tue, Jun 23, 2026 at 11:17=E2=80=AFAM Alex Williamson wrote: > > > > Nit, it would be more accurate to say: > > > > /* > > * Updates protected by dmabuf->resv, @revoked additionally > > * protected by memory_lock. > > */ > > > > revoked also has an unprotected read, but it's previously existing and > > benign, and likely just needs a READ_ONCE() annotation. > > =20 >=20 > Agreed, I'll update the comment and add READ_ONCE() as well. The READ_ONCE was added, but the comment remains as in v9. The READ_ONCE rationale should be described in the commit log too. Thanks, Alex