From patchwork Fri Aug 30 13:01:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 13785197 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 6D95DCA0FF9 for ; Fri, 30 Aug 2024 14:16:19 +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=vTm1tIDJdnS/elMBQCo/TK03refy/NHYIrFVASatWEQ=; b=i5Xa8ZjjSxft6R3f4nocstLNlR yHoU7dLKVAuVNYwHboziLRLVmG22DJbAwBUgnJ6uWPMACrNzMGwxt+ALcQXx6nRs3CFxYRuoVJxVD VteSmQ7Ir08C5ZQpxCDOHynafyVj8PopVVuUQgqFUOZpqal35Qfz/h5SkxLsfQyvZ0CgUd3P20Mqd cVRDcKlhrVN23VO+cXCnypavI4xHDbCYU4NgkZUg7bOadW60GrulQxM2hhLTm5Cxh12ayvcQVOnih MlxEWV9NexBhgykUaw6+w00Ru3bBV45+QJBX65vX6k6/eo9d2k2YJweukmULsR3o3JoPfQ604SgE9 8BDx6Qlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk2Q6-00000006ZUv-0IER; Fri, 30 Aug 2024 14:16:10 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk1GT-00000006Jfh-3Yny for linux-arm-kernel@lists.infradead.org; Fri, 30 Aug 2024 13:02:11 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 23263CE093A; Fri, 30 Aug 2024 13:02:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32D6CC4CEC9; Fri, 30 Aug 2024 13:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725022927; bh=TZrzB5fPLpvYHwo1cKo9hi7uRpJWiBXXGYqxoUGAtU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iXLp7mliFQhpVDtj60q+mlhp88lZf4ayhJESTovY4dDZSNHaxXwBIpAxk2cDYVIHL N8r3LmWx/eCVYBwMLUYjxwma35obU1xsCFZCGkbrNJCzL49hZUPmzwTUwG7oEL50H+ /hYF9teXpLf9IiaCz0tQaKsWqJU/PEx8OxKQXw0zpsEqSiEcFoWcipbOcwnmC9tcLl h0ZcG3PV263unoc1WgNKrpujqQZMI04+wLJ7t9FLWTv2xPYMPy7FbMSvrFhfuR29p5 Q949ycBjFndGw8P2I9Sct4Q/hFf3OigeQ3e9/+TlIk6HM5LX5Q7R0RdolHtE0DdG3W eegFd0Uu9eBKQ== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: Will Deacon , Sudeep Holla , Catalin Marinas , Lorenzo Pieralisi , Suzuki Poulose , Steven Price , Oliver Upton , Marc Zyngier , linux-coco@lists.linux.dev Subject: [PATCH v2 5/7] arm64: mm: Add confidential computing hook to ioremap_prot() Date: Fri, 30 Aug 2024 14:01:48 +0100 Message-Id: <20240830130150.8568-6-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240830130150.8568-1-will@kernel.org> References: <20240830130150.8568-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240830_060210_079494_AF156AE2 X-CRM114-Status: GOOD ( 14.28 ) 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 Confidential Computing environments such as pKVM and Arm's CCA distinguish between shared (i.e. emulated) and private (i.e. assigned) MMIO regions. Introduce a hook into our implementation of ioremap_prot() so that MMIO regions can be shared if necessary. Signed-off-by: Will Deacon --- arch/arm64/include/asm/io.h | 4 ++++ arch/arm64/mm/ioremap.c | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h index 41fd90895dfc..1ada23a6ec19 100644 --- a/arch/arm64/include/asm/io.h +++ b/arch/arm64/include/asm/io.h @@ -271,6 +271,10 @@ __iowrite64_copy(void __iomem *to, const void *from, size_t count) * I/O memory mapping functions. */ +typedef int (*ioremap_prot_hook_t)(phys_addr_t phys_addr, size_t size, + pgprot_t *prot); +int arm64_ioremap_prot_hook_register(const ioremap_prot_hook_t hook); + #define ioremap_prot ioremap_prot #define _PAGE_IOREMAP PROT_DEVICE_nGnRE diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c index 269f2f63ab7d..6cc0b7e7eb03 100644 --- a/arch/arm64/mm/ioremap.c +++ b/arch/arm64/mm/ioremap.c @@ -3,10 +3,22 @@ #include #include +static ioremap_prot_hook_t ioremap_prot_hook; + +int arm64_ioremap_prot_hook_register(ioremap_prot_hook_t hook) +{ + if (WARN_ON(ioremap_prot_hook)) + return -EBUSY; + + ioremap_prot_hook = hook; + return 0; +} + void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long prot) { unsigned long last_addr = phys_addr + size - 1; + pgprot_t pgprot = __pgprot(prot); /* Don't allow outside PHYS_MASK */ if (last_addr & ~PHYS_MASK) @@ -16,7 +28,16 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr)))) return NULL; - return generic_ioremap_prot(phys_addr, size, __pgprot(prot)); + /* + * If a hook is registered (e.g. for confidential computing + * purposes), call that now and barf if it fails. + */ + if (unlikely(ioremap_prot_hook) && + WARN_ON(ioremap_prot_hook(phys_addr, size, &pgprot))) { + return NULL; + } + + return generic_ioremap_prot(phys_addr, size, pgprot); } EXPORT_SYMBOL(ioremap_prot);