Jason Gunthorpe jgg@ziepe.ca writes:
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 = p2p->mem[i].bus_offset = pci_bus_address(pdev, i) - pci_resource_start(pdev, i); }DMA_ATTR_MMIO | DMA_ATTR_CC_SHARED;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;
pfns[idx] |= HMM_PFN_P2PDMA; break; case PCI_P2PDMA_MAP_BUS_ADDR:attrs |= p2pdma_state->mem->dma_mapping_flags;
Can I convert this as an independent patch with your SOB?
-aneesh