From: Jason Gunthorpe <jgg@ziepe.ca>
To: "Aneesh Kumar K.V" <aneesh.kumar@kernel.org>
Cc: Jiri Pirko <jiri@resnulli.us>,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
iommu@lists.linux.dev, linux-media@vger.kernel.org,
sumit.semwal@linaro.org, benjamin.gaignard@collabora.com,
Brian.Starkey@arm.com, jstultz@google.com, tjmercier@google.com,
christian.koenig@amd.com, m.szyprowski@samsung.com,
robin.murphy@arm.com, leon@kernel.org, sean.anderson@linux.dev,
ptesarik@suse.com, catalin.marinas@arm.com,
suzuki.poulose@arm.com, steven.price@arm.com,
thomas.lendacky@amd.com, john.allen@amd.com,
ashish.kalra@amd.com, suravee.suthikulpanit@amd.com,
linux-coco@lists.linux.dev
Subject: Re: [PATCH v5 1/2] dma-mapping: introduce DMA_ATTR_CC_SHARED for shared memory
Date: Thu, 21 May 2026 14:54:20 -0300 [thread overview]
Message-ID: <20260521175420.GA7702@ziepe.ca> (raw)
In-Reply-To: <yq5azf1s6aic.fsf@kernel.org>
On Thu, May 21, 2026 at 09:05:39PM +0530, Aneesh Kumar K.V wrote:
> I am wondering whether this is better
>
> static inline dma_addr_t dma_direct_map_phys(struct device *dev,
> phys_addr_t phys, size_t size, enum dma_data_direction dir,
> unsigned long attrs, bool flush)
> {
> dma_addr_t dma_addr;
>
> /*
> * For a device requiring unencrypted DMA, MMIO memory is treated
> * as shared.
> */
> if (force_dma_unencrypted(dev) && (attrs & DMA_ATTR_MMIO))
> attrs |= DMA_ATTR_CC_SHARED;
It is an option, I would be happier if we went and fixed the few
callers to properly pass the shared. CC did this with the
pgprot_decrypted() stuff, same reasoning:
diff --git a/block/blk-mq-dma.c b/block/blk-mq-dma.c
index bfdb9ed7074116..e77f6404caa3db 100644
--- a/block/blk-mq-dma.c
+++ b/block/blk-mq-dma.c
@@ -90,7 +90,7 @@ static bool blk_dma_map_direct(struct request *req, struct device *dma_dev,
unsigned int attrs = 0;
if (iter->p2pdma.map == PCI_P2PDMA_MAP_THRU_HOST_BRIDGE)
- attrs |= DMA_ATTR_MMIO;
+ attrs |= iter->p2pdma.mem->dma_mapping_flags;
iter->addr = dma_map_phys(dma_dev, vec->paddr, vec->len,
rq_dma_dir(req), attrs);
@@ -115,7 +115,7 @@ static bool blk_rq_dma_map_iova(struct request *req, struct device *dma_dev,
iter->len = dma_iova_size(state);
if (iter->p2pdma.map == PCI_P2PDMA_MAP_THRU_HOST_BRIDGE)
- attrs |= DMA_ATTR_MMIO;
+ attrs |= iter->p2pdma.mem->dma_mapping_flags;
do {
error = dma_iova_link(dma_dev, state, vec->paddr, mapped,
diff --git a/drivers/dma-buf/dma-buf-mapping.c b/drivers/dma-buf/dma-buf-mapping.c
index 794acff2546a34..96022fadc48245 100644
--- a/drivers/dma-buf/dma-buf-mapping.c
+++ b/drivers/dma-buf/dma-buf-mapping.c
@@ -147,7 +147,7 @@ struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach,
ret = dma_iova_link(attach->dev, dma->state,
phys_vec[i].paddr, 0,
phys_vec[i].len, dir,
- DMA_ATTR_MMIO);
+ provider->dma_mapping_flags);
if (ret)
goto err_unmap_dma;
@@ -155,7 +155,7 @@ struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach,
} else {
addr = dma_map_phys(attach->dev, phys_vec[i].paddr,
phys_vec[i].len, dir,
- DMA_ATTR_MMIO);
+ provider->dma_mapping_flags);
ret = dma_mapping_error(attach->dev, addr);
if (ret)
goto err_unmap_dma;
diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index 7c898542af8d5e..e4229b4d35c767 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -282,6 +282,8 @@ int pcim_p2pdma_init(struct pci_dev *pdev)
continue;
p2p->mem[i].owner = &pdev->dev;
+ p2p->mem[i].dma_mapping_flags =
+ DMA_ATTR_MMIO | DMA_ATTR_CC_SHARED;
p2p->mem[i].bus_offset =
pci_bus_address(pdev, i) - pci_resource_start(pdev, i);
}
diff --git a/include/linux/pci-p2pdma.h b/include/linux/pci-p2pdma.h
index 873de20a224759..402dc5e5d62b0a 100644
--- a/include/linux/pci-p2pdma.h
+++ b/include/linux/pci-p2pdma.h
@@ -21,10 +21,12 @@ struct scatterlist;
*
* A p2pdma provider is a range of MMIO address space available to the CPU.
* @owner: Device to which this provider belongs.
+ * @dma_mapping_flags: DMA attributes to use for host bridge mappings.
* @bus_offset: Bus offset for p2p communication.
*/
struct p2pdma_provider {
struct device *owner;
+ unsigned long dma_mapping_flags;
u64 bus_offset;
};
diff --git a/mm/hmm.c b/mm/hmm.c
index 5955f2f0c83db1..c3f445acddf873 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -811,7 +811,7 @@ dma_addr_t hmm_dma_map_pfn(struct device *dev, struct hmm_dma_map *map,
case PCI_P2PDMA_MAP_NONE:
break;
case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:
- attrs |= DMA_ATTR_MMIO;
+ attrs |= p2pdma_state->mem->dma_mapping_flags;
pfns[idx] |= HMM_PFN_P2PDMA;
break;
case PCI_P2PDMA_MAP_BUS_ADDR:
next prev parent reply other threads:[~2026-05-21 17:54 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20260325192400eucas1p2ae38ff4c2b3ab35a7047cfd680d9fda3@eucas1p2.samsung.com>
2026-03-25 19:23 ` [PATCH v5 0/2] dma-buf: heaps: system: add an option to allocate explicitly shared/decrypted memory Jiri Pirko
2026-03-25 19:23 ` [PATCH v5 1/2] dma-mapping: introduce DMA_ATTR_CC_SHARED for shared memory Jiri Pirko
2026-03-31 15:08 ` Jason Gunthorpe
2026-04-20 6:34 ` Aneesh Kumar K.V
2026-04-20 9:29 ` Jiri Pirko
2026-04-21 9:42 ` Aneesh Kumar K.V
2026-04-21 11:53 ` Jiri Pirko
2026-04-21 12:10 ` Jason Gunthorpe
2026-04-22 7:51 ` Petr Tesarik
2026-04-22 9:18 ` Aneesh Kumar K.V
2026-04-24 22:55 ` Jason Gunthorpe
2026-04-26 13:05 ` Jason Gunthorpe
2026-05-21 15:35 ` Aneesh Kumar K.V
2026-05-21 17:54 ` Jason Gunthorpe [this message]
2026-05-22 4:39 ` Aneesh Kumar K.V
2026-05-22 13:22 ` Jason Gunthorpe
2026-03-25 19:23 ` [PATCH v5 2/2] dma-buf: heaps: system: add system_cc_shared heap for explicitly " Jiri Pirko
2026-03-27 19:43 ` T.J. Mercier
2026-03-31 15:08 ` Jason Gunthorpe
2026-04-02 12:23 ` Maxime Ripard
2026-04-02 12:56 ` Jiri Pirko
2026-03-27 9:38 ` [PATCH v5 0/2] dma-buf: heaps: system: add an option to allocate explicitly shared/decrypted memory Marek Szyprowski
2026-03-27 12:10 ` Jason Gunthorpe
2026-03-27 19:43 ` T.J. Mercier
2026-04-02 4:41 ` Sumit Semwal
2026-04-02 5:35 ` Marek Szyprowski
2026-04-02 9:52 ` Brian Starkey
2026-04-02 12:02 ` Jason Gunthorpe
2026-04-02 12:58 ` Jiri Pirko
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=20260521175420.GA7702@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=Brian.Starkey@arm.com \
--cc=aneesh.kumar@kernel.org \
--cc=ashish.kalra@amd.com \
--cc=benjamin.gaignard@collabora.com \
--cc=catalin.marinas@arm.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=iommu@lists.linux.dev \
--cc=jiri@resnulli.us \
--cc=john.allen@amd.com \
--cc=jstultz@google.com \
--cc=leon@kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-media@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=ptesarik@suse.com \
--cc=robin.murphy@arm.com \
--cc=sean.anderson@linux.dev \
--cc=steven.price@arm.com \
--cc=sumit.semwal@linaro.org \
--cc=suravee.suthikulpanit@amd.com \
--cc=suzuki.poulose@arm.com \
--cc=thomas.lendacky@amd.com \
--cc=tjmercier@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.