From patchwork Tue Jul 30 15:11:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 13747535 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 205C7C3DA70 for ; Tue, 30 Jul 2024 15:14: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=RBvFX1ei3+h2Brcbd1U2L5kkfJ/oiQ72U8ae2etDYaE=; b=N8U3H+Jvn8VGpJeS+rI7MIBVjL iDNoVOvvd2th0pa5U8q1tuTf5Kl9Q+AAJKSljv1diSzFv5MVQb1Jt3Of7qNP0Cf7IcA+09t1OfMob NZaNufQRc+Fx+yxu799iq8uMN0pWWDoHNkgUmSAAS4AbvN/v7KyAHlEp3oFPxkLzyqRGsW5rhClF/ 0/lG66fWJMA+y6bo+DcyH2frgIVs8KNYGr4aGpefCGvtSMfI6yqsTu+xN7uMGrhozaeclI6vs4noz xhrW3vvhIeniRtglOoV/tE/1CmfeEHOeg3V9HgUkT0w5D6J3lUY/hBxfbZccWEUZOHgsX9+jYC84e oYATFuFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYoYK-0000000FcfC-2e7Q; Tue, 30 Jul 2024 15:14:16 +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 1sYoVh-0000000Fbsr-31r2 for linux-arm-kernel@lists.infradead.org; Tue, 30 Jul 2024 15:11:36 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id DE508CE10DA; Tue, 30 Jul 2024 15:11:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C852C4AF0A; Tue, 30 Jul 2024 15:11:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722352291; bh=wWyS+9FFbvxA5j90iQv++WgQYG0skQr8WSfhg9MLzqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=apd+U1IqmYcWk0Q+9WorkBrtYp18Zz+eNlb1D/ePurMKsXFz6EbGx8wA1/28ta6NY WMjdo0gQbDmEL+gjgxNzEVNTvkpj+hjyeZQbU4i6obSrXGPBfor3wIGwmdFIzTBtqX tH03MRWTRBi16HPr20TOqMH7kC2vWkT1gHlVVzbgQFLvFtBd3Lgo8BfiTXAlTbC0Fh CCBn1ERcp/2od575W2IVddduMPb5e9DKY95Gts2gj3K1GsTuO3TgTXAi2jWUHHwWLS VIJekE7yrT3XxzRDCQh5apbUen65OKgtc8fQRMFM4Iv+KQnstdBNspIVLnkT5tObkP JbiO5iGQ29DpA== 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 5/6] arm64: mm: Add confidential computing hook to ioremap_prot() Date: Tue, 30 Jul 2024 16:11:11 +0100 Message-Id: <20240730151113.1497-6-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240730151113.1497-1-will@kernel.org> References: <20240730151113.1497-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240730_081134_085968_92AD90CB X-CRM114-Status: GOOD ( 14.20 ) 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);