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 6E323CD5BAF for ; Fri, 22 May 2026 04:30:17 +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=KUK+7oDi4SWVkG4JnsspRP7bf98T3iHls52sNW0+aSI=; b=s9EZK8kP+NSD3idTU/kp7L6xgM SY/LCHhcp4agtdTeW4tPsZMRLx+XWSvungNCDC3RbeGxgS/SBudBjq+bbIVPP2OprHPcvjYjA46ns HZKA7dQVzEnjHhxcOTd6PvOt5/kqD6t94WnjPmuou3dSUjQZGrVsR5Gk0St5+oB1hSZXsUUtG4Tcg QgrzUBDk9HiWh1bQ0fBzP1m9ZYrkahZ+avlHffteAMCxS96kPYgxNSPGJUS6dbURPRoiofrYk6nDZ QNOKLsAskwCPkvuIlj+UC2DXitQicUnT9qzrG4hoD9q7L+zc/xWYh2CuJL6iG3l8ERVIWiyzHX6VC gAjw9ybw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wQHWV-00000009k6r-1mbo; Fri, 22 May 2026 04:30:11 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wQHWU-00000009k66-1qbt for linux-arm-kernel@lists.infradead.org; Fri, 22 May 2026 04:30:10 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id DD69760224; Fri, 22 May 2026 04:30:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D7A01F000E9; Fri, 22 May 2026 04:29:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779424209; bh=KUK+7oDi4SWVkG4JnsspRP7bf98T3iHls52sNW0+aSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=h2bO8JMrXUTKXlYbOzGyq+pBqaAkbLLxW5FczPW1wATQAHHGgRUcMO4XuC8LxwcRL 8f7P8dd4oZECJnWUO/T4V+PILFMz3tfsFDYxyHu1FbwqDJ3IUQ36oXt9SeBWz7RNOC to8lEpTZ2flA8EoohYinnIqyhXAeBLY/KSI6WD6DYR+n//zi2aHqgVisz1o9g3/jeq xl30t9dUEDeKflAuPivOnwVnyiiI/uPww7Lvl/Xt5jhq7vZNrBK5pwmrrQTVIhzuVm VTBEU18mJTaIvOcUr19P/DByFsiMMZDPKaWRU1hf44l8Mc4LTpcrIQFAjAGY0g4ZU0 pupisVugAfirw== 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, Jiri Pirko Subject: [PATCH v5 08/20] dma-mapping: make dma_pgprot() honor DMA_ATTR_CC_SHARED Date: Fri, 22 May 2026 09:58:03 +0530 Message-ID: <20260522042815.370873-9-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260522042815.370873-1-aneesh.kumar@kernel.org> References: <20260522042815.370873-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 is set and pgprot_encrypted() otherwise Convert the dma-direct allocation and mmap paths to pass DMA_ATTR_CC_SHARED instead of open-coding force_dma_unencrypted() handling around dma_pgprot(). Tested-by: Jiri Pirko 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 7cf1618a235d..429791b2599a 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -290,9 +290,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); @@ -614,9 +611,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 23ed8eb9233e..44f715f3aa2d 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -543,13 +543,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) + return pgprot_decrypted(dma_prot); + else + return pgprot_encrypted(dma_prot); } #endif /* CONFIG_MMU */ -- 2.43.0