From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795136844; b=ZmnB24AkPtVDcLVrhcvUN4uqzSSHd1yodGq/myq4h7y7ZRCTC8fTou4u2UysQLsk8xuD Dl7cRvM+wJW9AP4jkL4Dc6/ZXuJRPoccKprDhM4F8zqvEmXCCS1sju8UxUvgBzCUNtN8k 5NMlMxi1Ao+Fg5M/5Qq+NcFML+w9UyS4qmU9hOWaxdNJUqr80kSz5LFAs+jHTkXdLr+Yd ka1UvBDFQLfF3p3yOYlUUGIWLg9DOmSp07YQrt/k6/u1slg21ibP1iX9r5mdOv8dwbK1w T+4betK/VqWfUfa+qvGiBItt2EhKxtos+FfazHCzG9LwKHaIMHwoueJovPV6DRcVqoA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795136844; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=dRkr2BvKaK0JNp+xEr+CP1uqN9jcKW992wqEJ/xsaHY=; b=2E4ZZ03pO3E2yeQ9IvNglmfoBYPM0v+9aPFK4M215pVEoVzc3PlBmmxAEw4wcjtmyUGr liPttZx+j4T7DNqU0Wyfxh/IKszo8c4AmSuhYR0YAdYayITfk8BWdVpt35r6GwhTAl7jN DausRR0JZ4tCNT24TEiJaW+BuaTOlNBIfhgEHAcijTHgCu+fWXB5T4sawXCRmRSnA1RGD Us6yhv336vo1ZJUR188ty/lKMfMF+OWaVJQ0cxBwNQLVe3si75ip5pANm+4Ibo9YAfJIZ tQN9mAuG75bq0HgwvOPkaVr2+UJKRJG92fl0isQEeLRQmJd5M9y/mqer7KejqXyua3g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--lrizzo.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ES4ennDZ; arc=none smtp.remote-ip=209.85.208.70 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E8F860A5BC7 for ; Fri, 20 Nov 2026 01:07:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3E8F860A5BC7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--lrizzo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ES4ennDZ Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-6b879462421so1812602a12.1 for ; Thu, 19 Nov 2026 17:07:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795136843; x=1795741643; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=dRkr2BvKaK0JNp+xEr+CP1uqN9jcKW992wqEJ/xsaHY=; b=ES4ennDZTflXaeQYEQfAfoxa0BxH02PkL8QJTPLMmiyR8dGrQsgV/SPDpmfK9jWggM 8PsX/g1+mZvKeuRNgQkM8SEyf2GEO9at10u0q9ywBXwoo9l49k6G4O/x40PqgY030zP/ igs4cHyJTjN/xg8fABXqLn9FfqPtAL28NK9ZFbdjjzUI7ufY/4gx3bAOAuFk3MLlq7VR qpTGXQmaxwPLPGIKBdDahDSf6RCltzeLW6C+1MDEgwNoiZxMqqYB14/uaR1OzpKhQwlL S9hgbuZSqmEyW1dCCCazJwkmHAGJfc27Sv+lSoZqyUK6hrlaDOSC4YVeqtW5w+FUWT9B kYlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795136843; x=1795741643; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dRkr2BvKaK0JNp+xEr+CP1uqN9jcKW992wqEJ/xsaHY=; b=cQHqC884fbCmxX/AjWDRu5MP/nzgOEejKDkOffTrxFtX7r5ePaSeSZNtpEKVuiyTe6 mZLsSLW1Qu+9MQF24EbkPbgcY6wc0O3ASOkk9ECVde9iSNXf50R+gcAnC9o90Uv+mS9S bbtB8Ra3YhevqLFX7mi1Lp2plLGUjTwl3nUHzRtTPLCKkrUi6B/1nT8qG0y2YoEAS/+O 3DdifFGX893/oNdKu/w7lXLNpJHo7INJm7UZA3KJa2RDhDLdxLba4yVDdUTfNaYiRRXQ 4TLQFlJZVxsn0/HsAgPMoVxexeVqdUFSJ+9nt5LVZ8NoNbKVu+bDV8f0XIAxev546CuS vO+g== X-Forwarded-Encrypted: i=1; AL+hErEwwDj/NcOHzCd5TzcLaPXJkXue8GNPut3+622RlFOgzOhzEUKEeeDhh+9Uz1A1tYF92mGaOibJmgw=@vger.kernel.org X-Gm-Message-State: APuU4Z+yAWibST6BzoyXU9gdru3Y4QLqb6H0yLbv8Z3L62/mJBCRX0W0 FYlxavGuZmF4qqZ5tp0hB+/Ikkae7ods4PG6f7N5lEm5hAsYuAdd/S43tMX8jXT3iLjeDL47KPp 5SCrqwg== X-Received: from ejcfw45.prod.google.com ([2002:a17:907:502d:b0:c50:519f:c790]) (user=lrizzo job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:370b:b0:c51:34ae:dd7 with SMTP id a640c23a62f3a-c5134ae12d8mr166377466b.17.1795136842505; Thu, 19 Nov 2026 17:07:22 -0800 (PST) Date: Fri, 20 Nov 2026 01:06:50 +0000 In-Reply-To: <20261120010655.467825-1-lrizzo@google.com> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261109182533.3594984-1-lrizzo@google.com> <20261120010655.467825-1-lrizzo@google.com> X-Mailer: git-send-email 2.56.1.809.ga0b61035b5-goog Message-ID: <20261120010655.467825-21-lrizzo@google.com> Subject: [RFC PATCH v3 20/25] arm64/mm, mm: Support decrypted PISA pages in Realms From: Luigi Rizzo To: Andrew Morton , David Hildenbrand , Johannes Weiner , Vlastimil Babka , Joerg Roedel , Will Deacon , Robin Murphy , Marek Szyprowski , Jens Axboe , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Luigi Rizzo Cc: Lorenzo Stoakes , "Liam R . Howlett" , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Zi Yan , Harry Yoo , Christoph Lameter , David Rientjes , Roman Gushchin , Hao Li , Matthew Wilcox , Jan Kara , Jann Horn , Catalin Marinas , Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Jonathan Corbet , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , Willem de Bruijn , Kuniyuki Iwashima , Joshua Washington , Harshitha Ramamurthy , Alexander Lobakin , Christoph Hellwig , Jason Gunthorpe , Dragos Tatulea , Naman Gulati , Pranjal Shrivastava , Mostafa Saleh , Randy Dunlap , linux-mm@kvack.org, iommu@lists.linux.dev, netdev@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, driver-core@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Luigi Rizzo Content-Type: text/plain; charset="UTF-8" An arm64 Realm (ARM CCA guest) only reports CC_ATTR_MEM_ENCRYPT, so PISA did not treat it as a CoCo guest and refused to initialize there. Treat a Realm as a CoCo guest: PISA pages are decrypted (shared with the host) when they are allocated, as on SEV-SNP and TDX. A decrypted page is mapped with PROT_NS_SHARED, the top IPA bit, set in the address field of its PTEs. PISA maps such pages into user space with ordinary PTEs (page cache, migrated user pages, zerocopy receive), and for those pte_pfn() must be the PFN of the page, or vm_normal_page() and GUP see a PFN that has no struct page. Make __pte_to_phys() strip the bit when what is left is a decrypted PISA page. The check is behind pisa_decrypt_key, so outside CoCo guests it costs one static branch, and every other shared mapping (ioremap() of emulated MMIO, swiotlb, DMA mmap) keeps the address it has today. pisa_decrypt_key and the lookup are exported because pte_pfn() is used by modules. Signed-off-by: Luigi Rizzo --- arch/arm64/include/asm/pgtable.h | 28 ++++++++++++++++++++++++++-- mm/pisa-meta.c | 9 +++++++++ mm/pisa-node.c | 9 +++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index a474c9fb485ad..86c60b8f43ae0 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -108,7 +108,7 @@ static inline void arch_leave_lazy_mmu_mode(void) TLBF_NOBROADCAST | TLBF_NONOTIFY | TLBF_NOWALKCACHE) #ifdef CONFIG_ARM64_PA_BITS_52 -static inline phys_addr_t __pte_to_phys(pte_t pte) +static inline phys_addr_t __pte_to_phys_raw(pte_t pte) { pte_val(pte) &= ~PTE_MAYBE_SHARED; return (pte_val(pte) & PTE_ADDR_LOW) | @@ -119,7 +119,7 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys) return (phys | (phys >> PTE_ADDR_HIGH_SHIFT)) & PHYS_TO_PTE_ADDR_MASK; } #else -static inline phys_addr_t __pte_to_phys(pte_t pte) +static inline phys_addr_t __pte_to_phys_raw(pte_t pte) { return pte_val(pte) & PTE_ADDR_LOW; } @@ -130,6 +130,30 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys) } #endif +#if defined(CONFIG_PISA) && !defined(__DISABLE_EXPORTS) +DECLARE_STATIC_KEY_FALSE(pisa_decrypt_key); +bool __pisa_phys_decrypted(phys_addr_t phys); +#endif + +static inline phys_addr_t __pte_to_phys(pte_t pte) +{ +#if defined(CONFIG_PISA) && !defined(__DISABLE_EXPORTS) + /* + * In a Realm, PISA maps its decrypted pages into user space with ordinary + * PTEs. Those have PROT_NS_SHARED, the top IPA bit, set in their address + * field, but pte_pfn() must be the PFN of the page: strip the bit when + * what is left is a decrypted PISA page. Other shared mappings keep it. + */ + if (static_branch_unlikely(&pisa_decrypt_key) && (pte_val(pte) & PROT_NS_SHARED)) { + phys_addr_t phys = __pte_to_phys_raw(__pte(pte_val(pte) & ~PROT_NS_SHARED)); + + if (__pisa_phys_decrypted(phys)) + return phys; + } +#endif + return __pte_to_phys_raw(pte); +} + #define pte_pfn(pte) (__pte_to_phys(pte) >> PAGE_SHIFT) #define pfn_pte(pfn,prot) \ __pte(__phys_to_pte_val((phys_addr_t)(pfn) << PAGE_SHIFT) | pgprot_val(prot)) diff --git a/mm/pisa-meta.c b/mm/pisa-meta.c index 99c5bc42eed10..b608ef71152af 100644 --- a/mm/pisa-meta.c +++ b/mm/pisa-meta.c @@ -189,6 +189,15 @@ bool __is_pisa_direct(phys_addr_t phys, size_t size) (phys & (PISA_SIZE - 1)) + size <= PISA_SIZE; } +#ifdef CONFIG_ARM64 +/* For __pte_to_phys(): true if @phys is in a decrypted PISA page. */ +bool __pisa_phys_decrypted(phys_addr_t phys) +{ + return pisa_pfn_flags(PHYS_PFN(phys)) & PISA_DECRYPTED; +} +EXPORT_SYMBOL(__pisa_phys_decrypted); +#endif + /* * Update @meta's position on @pa's lists under @pa->lock. When all blocks * become available (avail == bpp), either queues @meta to @pisa_free_list (and diff --git a/mm/pisa-node.c b/mm/pisa-node.c index 12fbb617c342b..aa4f8759ae5e8 100644 --- a/mm/pisa-node.c +++ b/mm/pisa-node.c @@ -36,11 +36,16 @@ unsigned int pisa_reservoir_max __read_mostly = 16; /* Enabled in CoCo guests by pisa_node_init(): new PISA pages are decrypted for DMA. */ DEFINE_STATIC_KEY_FALSE(pisa_decrypt_key); +EXPORT_SYMBOL(pisa_decrypt_key); -/* A confidential guest: PISA pages are decrypted for DMA. A bare-metal SME host is not one. */ +/* + * A confidential guest: PISA pages are decrypted for DMA. A bare-metal SME host + * is not one. An arm64 Realm only reports CC_ATTR_MEM_ENCRYPT. + */ static bool pisa_coco_guest(void) { - return cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT); + return cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) || + (IS_ENABLED(CONFIG_ARM64) && cc_platform_has(CC_ATTR_MEM_ENCRYPT)); } /* Memory encryption that PISA cannot handle: neither an SME host nor a guest it decrypts for. */ -- 2.56.1.809.ga0b61035b5-goog