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 551C6CD4855 for ; Tue, 12 May 2026 09:05:45 +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=cHkoIqOn+tRTxVyuZ6YpuR+upIrx+a6VyEiW8TBWung=; b=oCU3lynXqUu41L0+Nrc8ds787m vhpWOe9Remx4sUCzEvXoBGc1GLp21E6l6ml1yD8ctMnJdJzyPojS40FThA9PAajNc4NzgnOPotIz3 FMRDyBR1oVuC7mfBwfUS/fBvS8e8yXD9dbRHTBc3z1g2sn8bS89B6MlUb2yD10VoiueZ3dFFr7sYv OaBz16eKU79ZCqopi/FMSBHzHHPT4GYClRJDP86lk7WHl4lGvZwImeLjFZ/VN/+ppqDlXRkhBKqOv MLbXqF3M7Y/FyZP3o08eLCJEoEUbzMtJrjZgFoBQ41HwtV9HqwfvgXMi6niHLg18lc+MLoU9XhvT7 jwj1VhFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMj3a-0000000GBt5-3nMj; Tue, 12 May 2026 09:05:38 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMj3Z-0000000GBsI-3fe0 for linux-arm-kernel@bombadil.infradead.org; Tue, 12 May 2026 09:05:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=cHkoIqOn+tRTxVyuZ6YpuR+upIrx+a6VyEiW8TBWung=; b=alrT+hjh4uHFqo4/kIL3yc6qXR Ev3GZAJEFsxJzFHc03cz4D22PDKx9PCDtVZBsT95Jp6EX2j22MBsX93koam7KtJxiieCA6IfD9sqz hJHf8qQpF9MuMUkp5KtPtkyR4SW/twnHm5qBA7+KPMLAsg0EDoUcPQ/Kgm1K6G65fUSUkziwsf9Tj h9tvF3Ydx42wmNyGzz8jfgbhmMnYv5CVdhsFRn0F4rGci3rhqEsjqvoIjA43q5JQLCutl4tZ474Dx +HsgpfKtM+CEC1WhQeKt21TAuzA46eHUS/YrWAj5PMeWYgivdcDPMXPSn2V0Cv/qXU83UZEntyhjE msER8mJQ==; Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by desiato.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMj3T-0000000EBi1-1L7c for linux-arm-kernel@lists.infradead.org; Tue, 12 May 2026 09:05:34 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id E525A43EDE; Tue, 12 May 2026 09:05:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 907ECC2BCC7; Tue, 12 May 2026 09:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778576729; bh=9Mg/60FkAPiuc5fK1clRWn/J5QY6mHmOM4Gl+OW5I34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PshDt4XM1mvyyVNCfQLjWwIf61GnnlnERZolrSawcYkDpIfioObQLoAfIjMw/7M9Q YTz8/cGsgsVdmSVFE/GDDmGWLQM5F4mbClisOqcvomviQfO7wGGvr66P5s7Yiwte+5 fybLHXIDwBOPobE+QScCdJAI7IZ0kpk0ywCc2LZ19NFx0yfONadhppdaHsCn2eAjh8 GG2JzF/vxM9xMkbcFyz8zC2oyR5p+10XySzCrgJhMLuYJFT1/jmjORHauK5wfh1zjO /VYUPHV3+vGyJTDhUvmUU0I3RSZ8c0/PMsyqyLxd7jCDFGv0lm7o8rsAl39LxXz082 XDhYX9Ue6FRQA== 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 Subject: [PATCH v4 05/13] dma-mapping: make dma_pgprot() honor DMA_ATTR_CC_SHARED Date: Tue, 12 May 2026 14:34:00 +0530 Message-ID: <20260512090408.794195-6-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260512090408.794195-1-aneesh.kumar@kernel.org> References: <20260512090408.794195-1-aneesh.kumar@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260512_100532_591152_A38F849F X-CRM114-Status: GOOD ( 11.64 ) 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(). 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 97ae4fa10521..ac315dd046c4 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -298,9 +298,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); @@ -603,9 +600,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