From patchwork Tue Mar 12 12:52:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13589951 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 DE44DC54E60 for ; Tue, 12 Mar 2024 12:53:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AOllUwn+9owvnRFVfg2T8WrZNS5Y4CQvjl8h76rmr3Q=; b=wM9wR7S5KiTXDc bF7rmF/qyoBBFnJFGu2e93fdyFeTI8FxXbdIqQ2FN89EMY3JFPQE9FkWmqgoJARBAMkZ4UwAVbOea sFi0OdzCq/pNhax2L94r2EeVjTzzjgMLG8UGl28tnRG9jUZkuclQ4ow2DX1PXg7n91Ktfxm+OlLUw aNNA8VYyXnSQ7vbPbqUFb1wN9A81xfol9CT/fCEb6PrYV1f07ztaKKIhh3Dee8ome3JbVEfh6IukI LqkNvD6V+884RQdD7ISfnF6Kvu3bosPblNE2m3muhvGEiYvzjngeNpncrYW6DVuLPhfEtEhAnxkE3 QHQIOYqnxb1BVVGgFWaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk1cd-00000005pIE-1hGF; Tue, 12 Mar 2024 12:52:47 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk1cV-00000005pBm-3alu for linux-arm-kernel@lists.infradead.org; Tue, 12 Mar 2024 12:52:42 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a45ecef71deso477204666b.2 for ; Tue, 12 Mar 2024 05:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710247950; x=1710852750; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vAAqIM+pcuAu2i/ucZrUcg2ANAQwDi96LSZYNnljZz8=; b=qhqjuAXme/xyIa7RkSPu0NGJjW0LMk2nASmmq4aSvGjKSbKVCTEv9xFafWx3oDY4UJ GTAc+jF+hxAkvzCIQuyq3YKUWDN+eaooAlm+qMhQBt8umxZj6Olp6Xa9QWYPt26eZ6a0 1Ll2i/sPlYJEkvkOJ1tMUAl9ZYLziWlJmvZqSGwrz67wDC7LK35RduA1lNfk/G02OKqC NK2rl+Djgq2w/9wOsub4Kmny9Sin+bIMvcS+0QyQCenb/5YlDtVX0g6154WGMFwAP2Z4 LpItIZpqI8/EgzNRhhP7S9pHYvq9j8i678NLaCdRiT21+f5GGRP1Co1eWjKIa45UqFtd baDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710247950; x=1710852750; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vAAqIM+pcuAu2i/ucZrUcg2ANAQwDi96LSZYNnljZz8=; b=azY4fFrLE8Aayhzmr+ZE1/KOhD5SDh4jsNPbRTF9FapNJsGpJXB15DoPlcB0oC/6eN rSUt5MKDO31cYl8POmvG1yWL28JmAxDvWuJ8espR44outio1j57RShnxmPzm4GmIyNIb lLraE4i6H91LIPtLwljy4cCO+rh3mTtlasS4TJwjcKtsSqCtOSCJ6tsRO8KXuv4/eWUt NUHgDY5ATohnc2gi9NFuB3/3DecdNFsdGGgSh6/yzGjoCEkjwV5dWVTII5RBVHv3d9lD kkIC5NLAEnpDqi0y1j/cdfsDY80vVfBNUGExLdUSRTWyxLlTvTCTJ3DgDTVAJoWm3Q3S yWIg== X-Gm-Message-State: AOJu0YyqqiYG8EmwWfBPhPNV8gFYKC8hzTiPomM3icfcqPeH91qhYb9n CaidlHjkVzvV87/XKZA23FslQqeyZuwVmRZxCToDCYZRY/rQJWUKziZmJQjv6Mc= X-Google-Smtp-Source: AGHT+IF4s/Xd7MbRgwlMbK9OoZah8by/MPthUn5mD5ZwMDu4o/A+l9v9UoWCc13nVYTBA8xkl1u6WA== X-Received: by 2002:a17:907:c08b:b0:a45:84e2:bde5 with SMTP id st11-20020a170907c08b00b00a4584e2bde5mr1267607ejc.3.1710247950588; Tue, 12 Mar 2024 05:52:30 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id gc5-20020a170906c8c500b00a45a09e7e23sm3845088ejb.136.2024.03.12.05.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 05:52:30 -0700 (PDT) From: Linus Walleij Date: Tue, 12 Mar 2024 13:52:18 +0100 Subject: [PATCH v3 2/4] ARM: Move asm statements accessing TTBCR into C functions MIME-Version: 1.0 Message-Id: <20240312-arm32-lpae-pan-v3-2-532647afcd38@linaro.org> References: <20240312-arm32-lpae-pan-v3-0-532647afcd38@linaro.org> In-Reply-To: <20240312-arm32-lpae-pan-v3-0-532647afcd38@linaro.org> To: Russell King , Ard Biesheuvel , Arnd Bergmann , Stefan Wahren , Kees Cook , Geert Uytterhoeven Cc: linux-arm-kernel@lists.infradead.org, Linus Walleij , Catalin Marinas X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240312_055239_942373_D1BEFFEF X-CRM114-Status: GOOD ( 14.00 ) 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 From: Catalin Marinas This patch implements cpu_get_ttbcr() and cpu_set_ttbcr() and replaces the corresponding asm statements. Signed-off-by: Catalin Marinas Reviewed-by: Kees Cook Signed-off-by: Linus Walleij --- ChangeLog v1->v3: - Drop unnecesary volatile from the asm(mcr) call. --- arch/arm/include/asm/proc-fns.h | 12 ++++++++++++ arch/arm/mm/mmu.c | 7 +++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h index 280396483f5d..9b3105a2a5e0 100644 --- a/arch/arm/include/asm/proc-fns.h +++ b/arch/arm/include/asm/proc-fns.h @@ -178,6 +178,18 @@ extern void cpu_resume(void); }) #endif +static inline unsigned int cpu_get_ttbcr(void) +{ + unsigned int ttbcr; + asm("mrc p15, 0, %0, c2, c0, 2" : "=r" (ttbcr)); + return ttbcr; +} + +static inline void cpu_set_ttbcr(unsigned int ttbcr) +{ + asm("mcr p15, 0, %0, c2, c0, 2" : : "r" (ttbcr)); +} + #else /*!CONFIG_MMU */ #define cpu_switch_mm(pgd,mm) { } diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index 674ed71573a8..9a780da6a4e1 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -1687,9 +1687,8 @@ static void __init early_paging_init(const struct machine_desc *mdesc) */ cr = get_cr(); set_cr(cr & ~(CR_I | CR_C)); - asm("mrc p15, 0, %0, c2, c0, 2" : "=r" (ttbcr)); - asm volatile("mcr p15, 0, %0, c2, c0, 2" - : : "r" (ttbcr & ~(3 << 8 | 3 << 10))); + ttbcr = cpu_get_ttbcr(); + cpu_set_ttbcr(ttbcr & ~(3 << 8 | 3 << 10)); flush_cache_all(); /* @@ -1701,7 +1700,7 @@ static void __init early_paging_init(const struct machine_desc *mdesc) lpae_pgtables_remap(offset, pa_pgd); /* Re-enable the caches and cacheable TLB walks */ - asm volatile("mcr p15, 0, %0, c2, c0, 2" : : "r" (ttbcr)); + cpu_set_ttbcr(ttbcr); set_cr(cr); }