From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5E6EECAAA1 for ; Tue, 6 Sep 2022 09:51:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239220AbiIFJvh (ORCPT ); Tue, 6 Sep 2022 05:51:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239192AbiIFJvc (ORCPT ); Tue, 6 Sep 2022 05:51:32 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17856DFAD; Tue, 6 Sep 2022 02:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=8/NrZAK5q7MnGYfTuWbWU8dghg9PZc1WBiUJ2nOuaC4=; b=IAyCiQiRvm+ndIADZzUDg2ER2+ 8Kz7YGsP3iYQq/EykkXdB+9anNfClC1OCd4udP7exSyBmsfShITgu4AW/cekmSy00tpbcV6w4Z3ZZ CTMbiYiO7uLS00CKzrENWw+PQGegQwk90oJdjBXZmHwsjYekKt9L6qB7xjRqB8yDzIrx9UJL2ta09 9Cz4KilqnGfnvm3x2ffIqJ9TDiR0OTwKzgUuzbHyespz4Z5GO5DTrsxW6DHKFoR9/VyJfyCj3vTwx ++lwBFxBrxfqK99GFdt/TfVWWYD9+Lw5yNmEk+PUrQtcDxl8AOZh3hu+Djvhp+LkaWj2Ifs4NGa/j bvHemi+w==; Received: from hch by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oVVEq-00C5Pm-08; Tue, 06 Sep 2022 09:51:24 +0000 Date: Tue, 6 Sep 2022 02:51:23 -0700 From: Christoph Hellwig To: Jason Gunthorpe Cc: Alex Williamson , Christian =?iso-8859-1?Q?K=F6nig?= , Cornelia Huck , dri-devel@lists.freedesktop.org, kvm@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, Sumit Semwal , Daniel Vetter , Leon Romanovsky , linux-rdma@vger.kernel.org, Maor Gottlieb , Oded Gabbay Subject: Re: [PATCH v2 4/4] vfio/pci: Allow MMIO regions to be exported through dma-buf Message-ID: References: <0-v2-472615b3877e+28f7-vfio_dma_buf_jgg@nvidia.com> <4-v2-472615b3877e+28f7-vfio_dma_buf_jgg@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4-v2-472615b3877e+28f7-vfio_dma_buf_jgg@nvidia.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org > +{ > + struct vfio_pci_dma_buf *priv = dmabuf->priv; > + int rc; > + > + rc = pci_p2pdma_distance_many(priv->vdev->pdev, &attachment->dev, 1, > + true); This should just use pci_p2pdma_distance. > + /* > + * Since the memory being mapped is a device memory it could never be in > + * CPU caches. > + */ DMA_ATTR_SKIP_CPU_SYNC doesn't even apply to dma_map_resource, not sure where this wisdom comes from. > + dma_addr = dma_map_resource( > + attachment->dev, > + pci_resource_start(priv->vdev->pdev, priv->index) + > + priv->offset, > + priv->dmabuf->size, dir, DMA_ATTR_SKIP_CPU_SYNC); This is not how P2P addresses are mapped. You need to use dma_map_sgtable and have the proper pgmap for it. The above is just a badly implemented version of the dma-direct PCI_P2PDMA_MAP_BUS_ADDR case, ignoring mappings through the host bridge or dma-map-ops interactions.