From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 AF870394496 for ; Mon, 13 Apr 2026 08:31:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776069112; cv=none; b=TX5VuHSFn+3mMcLwu4sT4rlRi0EZfQxJdMu9FBVt5v1D6mC4nGDoyPoR8JDN+AYoNr75RzYk+UsEZ7XLHYfdVe2OSOyN2BbdKUP9vZTeGvB4biwM2ahmtyXF8c2Hso39iSv5LVG1K/ynJBOLvQDlO8royQEJzTj6vMzSXM8GKNA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776069112; c=relaxed/simple; bh=ygX3QGpmpzQ4vDb35DrfpC80ywfwMhPNQFU2B1S833A=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=lSKhXdI7Rvk6gbzZacbEWX23GRvjl9jHZqU6RrhtwCgND5JRnQoK75TT4qDU/RrMFubIJ8nX67IHSB02aY3uEICoPSZptprYPJsfrssRZkmyDx6hjygh7CvAKv2AgZ6M7+WGQPhEdjUt8qnjOMoVpJtNex4/b7eT6Nw7OtDVMJY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=eZAyKEiL; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="eZAyKEiL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1776069111; x=1807605111; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=ygX3QGpmpzQ4vDb35DrfpC80ywfwMhPNQFU2B1S833A=; b=eZAyKEiLNDAcCguLfo7h0TEfW001AB6mONoY+EKiN8Qu2mA9/GRvdJDc XOHmCyQwWNLpnjFgmT/s/JJdckUuQatpd0iX21BOR86bO5Zc603+PfIZz SUilkH9itz1tPCXEO6FDiDpzbpDL5orVT2K6sHXNC1lKt8stJpPr9/rL8 dWF2BtlOvzYEbJJ3/Soj9+YW7fdWJdSt7uJVZabNitHYA5ZVkdEKJ24lp ZWaVdAkh3Di4NWr8VbJFTKIdcBiyuK7GMf+/5i8YufXNpLPgghwQ5zxuq N2XI2A/qRlaLciBhJ2BJyZ80NpvrCkiOB/L7xxjbiSOcou5lthtcsJnmc Q==; X-CSE-ConnectionGUID: slV3QEbTRXWCzW3PRqSifA== X-CSE-MsgGUID: S6jFqbrjQ1GYVWe5u6j8jw== X-IronPort-AV: E=McAfee;i="6800,10657,11757"; a="76907458" X-IronPort-AV: E=Sophos;i="6.23,176,1770624000"; d="scan'208";a="76907458" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2026 01:31:51 -0700 X-CSE-ConnectionGUID: kRnB8EohQb611Ginyevg6g== X-CSE-MsgGUID: AiU4VxdXSISX/Yzv4b1gFg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,176,1770624000"; d="scan'208";a="233756454" Received: from allen-sbox.sh.intel.com (HELO [10.239.159.30]) ([10.239.159.30]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2026 01:31:47 -0700 Message-ID: Date: Mon, 13 Apr 2026 16:29:59 +0800 Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 12/26] vfio/pci: Change the DMA-buf exporter to use mapping_type To: Jason Gunthorpe Cc: Christian Koenig , Dongwon Kim , dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, iommu@lists.linux.dev, Kevin Tian , Leon Romanovsky , linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, Matthew Brost , Simona Vetter , Sumit Semwal , Thomas Hellstrom , Vivek Kasireddy References: <12-v1-b5cab63049c0+191af-dmabuf_map_type_jgg@nvidia.com> Content-Language: en-US From: Baolu Lu In-Reply-To: <12-v1-b5cab63049c0+191af-dmabuf_map_type_jgg@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/18/26 08:11, Jason Gunthorpe wrote: > Simple conversion to add a match_mapping() callback that offers an > exporter SGT mapping type. Later patches will add a physical address > exporter so go straight to adding the match_mapping() function. > > The check for attachment->peer2peer is replaced with setting > exporter_requires_p2p=true. VFIO always uses MMIO memory. > > Signed-off-by: Jason Gunthorpe > --- > drivers/vfio/pci/vfio_pci_dmabuf.c | 31 +++++++++++++++++++++++++----- > 1 file changed, 26 insertions(+), 5 deletions(-) > > diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c > index d4d0f7d08c53e2..c7addef5794abf 100644 > --- a/drivers/vfio/pci/vfio_pci_dmabuf.c > +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c > @@ -25,9 +25,6 @@ static int vfio_pci_dma_buf_attach(struct dma_buf *dmabuf, > { > struct vfio_pci_dma_buf *priv = dmabuf->priv; > > - if (!attachment->peer2peer) > - return -EOPNOTSUPP; > - > if (priv->revoked) > return -ENODEV; > > @@ -75,11 +72,35 @@ static void vfio_pci_dma_buf_release(struct dma_buf *dmabuf) > kfree(priv); > } > > -static const struct dma_buf_ops vfio_pci_dmabuf_ops = { > - .attach = vfio_pci_dma_buf_attach, > +static const struct dma_buf_mapping_sgt_exp_ops vfio_pci_dma_buf_sgt_ops = { > .map_dma_buf = vfio_pci_dma_buf_map, > .unmap_dma_buf = vfio_pci_dma_buf_unmap, > +}; > + > +static int vfio_pci_dma_buf_match_mapping(struct dma_buf_match_args *args) > +{ > + struct vfio_pci_dma_buf *priv = args->dmabuf->priv; > + struct dma_buf_mapping_match sgt_match[1]; > + > + dma_resv_assert_held(priv->dmabuf->resv); My understanding of this lock assertion is that priv and the underlying priv->vdev are accessed within this function. Therefore, the lock is necessary to protect them. Do I understand it right? However, callers - for example, dma_buf_mapping_attach() - do not acquire dma_resv_lock() before calling this function. So kernel traces will always be triggered. > + > + /* > + * Once we pass vfio_pci_dma_buf_cleanup() the dmabuf will never be > + * usable again. > + */ > + if (!priv->vdev) > + return -ENODEV; > + > + sgt_match[0] = DMA_BUF_EMAPPING_SGT_P2P(&vfio_pci_dma_buf_sgt_ops, > + priv->vdev->pdev); > + > + return dma_buf_match_mapping(args, sgt_match, ARRAY_SIZE(sgt_match)); > +} > + > +static const struct dma_buf_ops vfio_pci_dmabuf_ops = { > + .attach = vfio_pci_dma_buf_attach, > .release = vfio_pci_dma_buf_release, > + .match_mapping = vfio_pci_dma_buf_match_mapping, > }; > > /* Thanks, baolu