From patchwork Tue Jan 23 21:16:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13528142 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 5A42DC47258 for ; Tue, 23 Jan 2024 21:16:57 +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=z1azzH9nLTudzAFHeEdfivGL9a4LPg3lUWA0U94a8t8=; b=nv39sZssAN3GRn kIH32povoSh5nNInB94s+F1MvbNsjgPh4IWa0NpLCdyBKyaQQ+YhsDvIAJrhxy0gaDw2aTM2TvSVz n6g3tptIGtlYMatl+lm3jSHp6Lyd6+UA3kgoJRdUAs6vUYZbQlqU147DKD65SEYruvY7ih0LOtZbq dcfc+ssmjvWWWLBBZ+Vrlzf2w54bKfqZS+3k1bg6G7X1DiKTcPDb89liqs5L6Pe5X9vy03J9DNE5Z taKovIpgpIsidiKXbj4Glc/l394HQDABRLPDtBU/FkhBh8IWvsUcdCgRICA9dVSR6AeASbfgbcddz 5R06GVAQMtvPIrCbWqyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSO8H-000UwH-32; Tue, 23 Jan 2024 21:16:33 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSO85-000UsT-1O for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 21:16:22 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-50eac018059so6654528e87.0 for ; Tue, 23 Jan 2024 13:16:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706044577; x=1706649377; 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=Tfvmlb2pBeVG0ZpgnBJ6vzKJTvgDXiBmio0NoiXFRrY=; b=mV6mdOvXMutI7EOaxJeCWzwlP+nEIy5LSV7fIGeQInTihj/JGN8ZcYTHF9DjMeWTiX x/ODOm4Un9ooaLNxoKQxJwNX5OUGS3D6JorJWeonEgrOtLgzg/zswALox6hhk2S3Ww0r I7HiO3JnJq0Yg7SbGEJcGESUlMaLnc1IdW11r+Kt20vHbV4ZqD/3h5px7s0nUk9YmJbR Lz4246mkOmK6idutwbLBVFsKoSpWt+GunvmIc506uUkjFGn3EpSuoNTJVrH76de7L2iT 6qaTdkdYDAbtxNiokdwQ8pi5Mu+TDLGY4ZZJTaaj8EvhKfDEIn/us+Z1C+NfPJyyhOuQ 6gFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706044577; x=1706649377; 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=Tfvmlb2pBeVG0ZpgnBJ6vzKJTvgDXiBmio0NoiXFRrY=; b=SIhCBEwLbFHHkTD4pRw+y6uaYnPRIA4D51e6hDmdIFURE1uZUfxoyumIRMTa5wu6bQ QCq+i+x0jkbBA9OXQaonE0LUvDajj1/gqyBsev5VOUCnnt5xcujLTtAtX56lf7OOP0hN NzVSbLkj7i+wkXWXupWo2s3AfEtFCLaE74Bv+6KOzq7VhGkPT5LBOHx/WcXBEaDIaMbT CFOjn3OU9bADZ6wbwa8Zs7JPXp/adu8WOhL5D/ISaiYMp8pG71KFMZAezlcoIw3PTM5d 6LpqTOVxG9ORLosyh78Qexr+/m1i1/XFCt1DYG31LtzkzuxgDU2PnKjnC68O2eyTABAv /ziQ== X-Gm-Message-State: AOJu0YzUrJgUSni4u1J48vwMI6k4Ryldd6pAOddlKT/RXndcg6tCZqJ7 uFZ0nTPS42i0wH+OTbL8Vbc5tdsoqnOcpd1JRl9za0UZU3tqiT97u1TWKa7eMQQ= X-Google-Smtp-Source: AGHT+IHkxXBmx1CjiTx9zzTfFegYsN0fFRX1UJi1psE+7kIxbHKYpH19QhOgkvtW7CVPfuFHo0oNFw== X-Received: by 2002:a05:6512:6d2:b0:50b:e713:574d with SMTP id u18-20020a05651206d200b0050be713574dmr3924429lff.75.1706044577498; Tue, 23 Jan 2024 13:16:17 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id o3-20020a056512230300b0050ee557f1dcsm2385427lfu.115.2024.01.23.13.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 13:16:16 -0800 (PST) From: Linus Walleij Date: Tue, 23 Jan 2024 22:16:15 +0100 Subject: [PATCH 2/4] ARM: Move asm statements accessing TTBCR into C functions MIME-Version: 1.0 Message-Id: <20240123-arm32-lpae-pan-v1-2-7ea98a20514c@linaro.org> References: <20240123-arm32-lpae-pan-v1-0-7ea98a20514c@linaro.org> In-Reply-To: <20240123-arm32-lpae-pan-v1-0-7ea98a20514c@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-20240123_131621_489421_EA9F600F X-CRM114-Status: GOOD ( 13.56 ) 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 --- 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..a13e5cf3d1ff 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 volatile("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); }