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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4AE44C4451B for ; Fri, 17 Jul 2026 18:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IkFBlHM9TbaSw6EdZs7ctVNZjEKNsaSG21JkeuDmlSA=; b=aHLuKbOqx3rULIUkWWd8WrTrp7 Mhm/jqNN7z6qyVEa1NSGNO8DtsQjms69PeXkJI3LOnw+sAf2qZMuHM3OhJ3dtLJyYhrvIg7Y4L7El CQFY/ubQ5ZvYxcAOdxgGlpxO7eqSwwYpryuYtD7s8oURRWlfAKjuL+NEs0gjmSh4jwSut97SMlyyE 7h2oo4fU5synaiUs/xXhqWejZT+GRTbX1u1t6zKSvhbsJswQnKiDgSmRVyBn4DUUUqVEYlgNmLxMe RJNHaHGuTtfvcRt0vaKDjpk8vaCSJOLIXPAs74OJ8SDZe+vic/zMaUp6Pm068MJZwznvm7UMTLH88 LubjAQiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wkmyR-00000002xmR-1Bsp; Fri, 17 Jul 2026 18:07:47 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wkmyP-00000002xl3-2gBz for linux-arm-kernel@lists.infradead.org; Fri, 17 Jul 2026 18:07:45 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 163C8600DA; Fri, 17 Jul 2026 18:07:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 863641F000E9; Fri, 17 Jul 2026 18:07:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784311664; bh=IkFBlHM9TbaSw6EdZs7ctVNZjEKNsaSG21JkeuDmlSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jpXbh1c5NN9ni0L+tVVrdZw70rzNXRJeifg5Rs/lMab41T8Ylgnz8PO1aCzPc4UHg zHAQUYGizCjDNOd5OxUjZjeAC2NAP1v7Wv0ZyBAxekfXyYIj4PYrz6UkHpGaudfU27 QpYd7iiOSfMwgDy+5KmPMPzceGNno1Yh8HhdcxaYv7fTs+WmnqQs267gcGh3z0okPF yahaiX2oPFpc0Ny5bn0+THR1w9Euxp/wm+CfdIDuEaLQZCw+QecQhh29k/AUSOq3R8 S6tjDMuVdv9DmKCpR3AWQqqc0MHV/1S84d8XGGn8rbRmNu9QEpdMaxKkPwyP4snICT A3qnwGSNszIyQ== From: "Aneesh Kumar K.V (Arm)" To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev Cc: "Aneesh Kumar K.V (Arm)" , Robin Murphy , Marek Szyprowski , Will Deacon , Marc Zyngier , Steven Price , Suzuki K Poulose , Catalin Marinas , Jiri Pirko , Jason Gunthorpe , Mostafa Saleh , Petr Tesarik , Alexey Kardashevskiy , Dan Williams , Xu Yilun , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , x86@kernel.org, Jason Gunthorpe , Jiri Pirko , Michael Kelley Subject: [PATCH v8 14/23] dma-mapping: make dma_pgprot() honor __DMA_ATTR_ALLOC_CC_SHARED Date: Fri, 17 Jul 2026 23:34:32 +0530 Message-ID: <20260717180442.110954-15-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260717180442.110954-1-aneesh.kumar@kernel.org> References: <20260717180442.110954-1-aneesh.kumar@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Fold encrypted/decrypted pgprot selection into dma_pgprot() so callers do not need to adjust the page protection separately. Update dma_pgprot() to apply pgprot_decrypted() when DMA_ATTR_CC_SHARED or __DMA_ATTR_ALLOC_CC_SHARED is set and pgprot_encrypted() otherwise Convert the dma-direct mmap paths to pass DMA_ATTR_CC_SHARED instead of open-coding force_dma_unencrypted() handling around dma_pgprot(). Reviewed-by: Jason Gunthorpe Tested-by: Jiri Pirko Tested-by: Michael Kelley Tested-by: Mostafa Saleh Signed-off-by: Aneesh Kumar K.V (Arm) --- kernel/dma/direct.c | 8 +++----- kernel/dma/mapping.c | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 9f013ff8e0f6..f54c7929b97f 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -286,9 +286,6 @@ void *dma_direct_alloc(struct device *dev, size_t size, if (remap) { pgprot_t prot = dma_pgprot(dev, PAGE_KERNEL, attrs); - if (force_dma_unencrypted(dev)) - prot = pgprot_decrypted(prot); - /* remove any dirty cache lines on the kernel alias */ arch_dma_prep_coherent(page, size); @@ -607,9 +604,10 @@ int dma_direct_mmap(struct device *dev, struct vm_area_struct *vma, unsigned long pfn = PHYS_PFN(dma_to_phys(dev, dma_addr)); int ret = -ENXIO; - vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs); if (force_dma_unencrypted(dev)) - vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot); + attrs |= DMA_ATTR_CC_SHARED; + + vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs); if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret)) return ret; diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index d2f70b6ccd0f..a628820fd10e 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -537,13 +537,21 @@ EXPORT_SYMBOL(dma_get_sgtable_attrs); */ pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs) { + pgprot_t dma_prot; + if (dev_is_dma_coherent(dev)) - return prot; + dma_prot = prot; #ifdef CONFIG_ARCH_HAS_DMA_WRITE_COMBINE - if (attrs & DMA_ATTR_WRITE_COMBINE) - return pgprot_writecombine(prot); + else if (attrs & DMA_ATTR_WRITE_COMBINE) + dma_prot = pgprot_writecombine(prot); #endif - return pgprot_dmacoherent(prot); + else + dma_prot = pgprot_dmacoherent(prot); + + if (attrs & (DMA_ATTR_CC_SHARED | __DMA_ATTR_ALLOC_CC_SHARED)) + return pgprot_decrypted(dma_prot); + else + return pgprot_encrypted(dma_prot); } #endif /* CONFIG_MMU */ -- 2.43.0