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 B4E1EC43458 for ; Wed, 1 Jul 2026 05:52:26 +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=WaFole9WpH4WOdu0NoPZcwNtksyiD1swupReo/MXirw=; b=CR6D6S6PbW7v40A8YcxJaQKgCF nvaBGubTwH/ShppAy9dbwdzVBk8QKwxUNizYuevrfjjR1WmY7EeyM16EfgD/v35Uau5VPgtudrS04 2Clmpbj6QkLr6EeXy195/mnUAg6UBi4N3TXdUMDNe9HtjQo8mcBpnEXkyNSaU9n5HejbHgmgwXnoG 4akms7vbjH8hARoEAK/FD5E2aHJm+tRyYewKd/9L0oiK6mXLYQknSZZLhW9fymzRqQoKeyckVoa5k MFYVR5LPDwXCZCm+5V9lKFMbFyvvmP9S0CEf1IX6yLgorqnurgYyzMfDTxDNupARmWJqVqIxpWfMf z8gllLqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wenrw-00000000j3q-1vZB; Wed, 01 Jul 2026 05:52:20 +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 1wenrv-00000000j2u-0Mve for linux-arm-kernel@lists.infradead.org; Wed, 01 Jul 2026 05:52:19 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 84971601D7; Wed, 1 Jul 2026 05:52:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C60B01F00A3A; Wed, 1 Jul 2026 05:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782885138; bh=WaFole9WpH4WOdu0NoPZcwNtksyiD1swupReo/MXirw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CTOPEfvw+FTCjKT/3u4xNFzwHn2wRv7oSUt5koWJF9u9uNkLVk0MOmnuX0sfPKxAR A5jTcoIgUSqlN78yWHoDkpWvbDcimQDU8TpT+DslgtdgKQx8C59xg4vXr1vvuqUN3+ ITwjK3Ea3288affFm4tea8Z478PtpCkPaAOF3umxoqmh2VlYK5pMD5fWUGfWeb9KQi 7wB+vIqlrcEmteCtLDA3If4owvXWb8HNSPY+YsWg2vFQU4DiwxHgNPwp+ezusSFQwi ZkKgOwXfldX9XL6QJOAF3jv7OaGA5XsBKIP72v4dlk3/zl9yyyC7xQlOzbYzmi9eKV 0wIHdeWYMTnTQ== 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 , Michael Kelley Subject: [PATCH v7 14/22] dma-mapping: make dma_pgprot() honor __DMA_ATTR_ALLOC_CC_SHARED Date: Wed, 1 Jul 2026 11:19:18 +0530 Message-ID: <20260701054926.825925-15-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260701054926.825925-1-aneesh.kumar@kernel.org> References: <20260701054926.825925-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(). 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 64cb9f13ef03..9935f7caa459 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -283,9 +283,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); @@ -605,9 +602,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