From patchwork Sun Feb 25 20:08:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13571026 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 0C316C54E49 for ; Sun, 25 Feb 2024 20:08:47 +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=qxoQ93eM9I+Uwm39oKeoj5M+EBbsilPNKlOXRtRGf1U=; b=cWtG7nOgSymLK4 17C3tz6jy3JrdDz+AxR9ig3Q9l577H0QL28tX5Ah9rKyRo2+z2dT09ulEs41g0yCHa7G+ntPN+xXa ygcvwxMNTnmWdpyrAjwppPXeO+Nf9lLdXsCk+UUI8yl/lcfHG1gIRHmH9m9wmp/pNahkDUp9vG4be UZB0kTBzvZXeHlHvk4Vaozvho+PQFjaPn4WAYcvtZBRuUPhdVPemT82ADLeqJqjfR77g9s+X9viPz QduXwEt90WRQXyk0srlWk96uDCkWoiAsUpTQU8z9QO5aaU/W0vEBmCbHS0Vvb2C1xJ4w7ZS0hdSyJ qtYFP3rkNRpU0hzA3jTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reKnd-0000000Fcqo-2xCk; Sun, 25 Feb 2024 20:08:37 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reKnK-0000000FckB-2bN8 for linux-arm-kernel@lists.infradead.org; Sun, 25 Feb 2024 20:08:20 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a3ed9cae56fso369869766b.1 for ; Sun, 25 Feb 2024 12:08:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708891696; x=1709496496; 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=QC3pcDM1Ey3dTkjBKsVJTDPbi3o492y4kegvDdvubjY=; b=IaJ+bWL5LCykz2burBK9tId9FBY3Qlm/Jqvy9P/9+Sp6KURTSquNGSYbBAYn3gyPuu f9hlP1X1PXST5wNlhSxOba6+Z4Rurbsx3eyCmN26uYeXNBVtAIaPvKWeODRyBQ32wbjw RA+HgLL+LixiX1QfbHNhyyaWwcx5mxqNyD1hrtv+lf3YCEjEWCpeUGLUiVtZDsHyXBsI S2uTIrvzN3dGRDjbQTVTuG0paKCghnBehUDQBZxL/6vFJ+uw69vbpr9KFwu5dUqjKrfF tv9FOtj9Hl7SskhKRYlEtJyBh5hrrPC/iC3gc2cco+oqhmV9AJl00rfP69f0GUlu/iiw 0HSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708891696; x=1709496496; 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=QC3pcDM1Ey3dTkjBKsVJTDPbi3o492y4kegvDdvubjY=; b=UZmZUGz0cWiZjfiQDhejM55v8b8cUoHGK0EojK3HZ8/3jtj07Zgd5ibaAexvMVimhO GpjLBRHjX9BmanRT7yj+zlRg1824If6tjUaMqKHxySCReoBFtVND2rqkmqD43DhFGDYl 7vKiKqK9YVOuQkJFQDtVVgK3QQ9LO66++Ec3yh3Ql8VIctjjLbIl/Y0RjFEBjaSCXVy7 5Q0EQ/d7Yg11U3z48pH0XP/zLn9+DaCNAvUo+TsVkz0Nw6gsEvKzFcVpwVBVWt+ZxWy/ JGT9r9gkkaiwecwos65Wz9noESWc+Y607q5ok9R0Ct5CqCpZT1TC4gDBlD4l96HCQto+ rmcA== X-Gm-Message-State: AOJu0YwbEZnloyqLpWX6utg3FFlA8GEZWbq+lDwXd536rYRSp3K89nu9 9OoQc0n1xBG313Pq3bcwSJtI0ldKC8dzVqyZj6SRb0ZfKbHyiEtdmRSWAt8C/dw= X-Google-Smtp-Source: AGHT+IFhKSmAMGVKE3e79lh/Twxe14kufH36JgG8EFNdH/4PPIzZ7artQFAubFyeEzB2wpB3+rihOg== X-Received: by 2002:a17:907:208f:b0:a3f:421:26a5 with SMTP id pv15-20020a170907208f00b00a3f042126a5mr4791471ejb.12.1708891696123; Sun, 25 Feb 2024 12:08:16 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id hu14-20020a170907a08e00b00a4340138ab5sm504621ejc.5.2024.02.25.12.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 12:08:15 -0800 (PST) From: Linus Walleij Date: Sun, 25 Feb 2024 21:08:13 +0100 Subject: [PATCH 4/7] ARM: proc: Use inlines instead of defines MIME-Version: 1.0 Message-Id: <20240225-arm32-cfi-v1-4-6943306f065b@linaro.org> References: <20240225-arm32-cfi-v1-0-6943306f065b@linaro.org> In-Reply-To: <20240225-arm32-cfi-v1-0-6943306f065b@linaro.org> To: Russell King , Sami Tolvanen , Kees Cook , Nathan Chancellor , Nick Desaulniers , Ard Biesheuvel , Arnd Bergmann Cc: linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Linus Walleij X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240225_120818_810995_24F55D65 X-CRM114-Status: GOOD ( 15.35 ) 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 We currently access the per-cpu vtable with defines such as: define cpu_proc_init PROC_VTABLE(_proc_init) Convert all of these instances to static inlines instead: static inline __nocfi void cpu_proc_init(void) { PROC_VTABLE(_proc_init)(); } This has the upside that we can add the __nocfi tag to the inline function so CFI can skip over this and work, and we can simplify some platform code that was looking into the symbol table to be able to call cpu_reset(), now we can just call it instead. Signed-off-by: Linus Walleij --- arch/arm/common/mcpm_entry.c | 10 ++------ arch/arm/include/asm/proc-fns.h | 57 +++++++++++++++++++++++++++++++++-------- arch/arm/mach-sunxi/mc_smp.c | 7 +---- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/arch/arm/common/mcpm_entry.c b/arch/arm/common/mcpm_entry.c index e013ff1168d3..3e19f246caff 100644 --- a/arch/arm/common/mcpm_entry.c +++ b/arch/arm/common/mcpm_entry.c @@ -234,13 +234,10 @@ int mcpm_cpu_power_up(unsigned int cpu, unsigned int cluster) return ret; } -typedef typeof(cpu_reset) phys_reset_t; - void mcpm_cpu_power_down(void) { unsigned int mpidr, cpu, cluster; bool cpu_going_down, last_man; - phys_reset_t phys_reset; mpidr = read_cpuid_mpidr(); cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0); @@ -298,8 +295,7 @@ void mcpm_cpu_power_down(void) * the kernel as if the power_up method just had deasserted reset * on the CPU. */ - phys_reset = (phys_reset_t)(unsigned long)__pa_symbol(cpu_reset); - phys_reset(__pa_symbol(mcpm_entry_point), false); + cpu_reset(__pa_symbol(mcpm_entry_point), false); /* should never get here */ BUG(); @@ -376,7 +372,6 @@ static int __init nocache_trampoline(unsigned long _arg) unsigned int mpidr = read_cpuid_mpidr(); unsigned int cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0); unsigned int cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1); - phys_reset_t phys_reset; mcpm_set_entry_vector(cpu, cluster, cpu_resume_no_hyp); setup_mm_for_reboot(); @@ -387,8 +382,7 @@ static int __init nocache_trampoline(unsigned long _arg) __mcpm_outbound_leave_critical(cluster, CLUSTER_DOWN); __mcpm_cpu_down(cpu, cluster); - phys_reset = (phys_reset_t)(unsigned long)__pa_symbol(cpu_reset); - phys_reset(__pa_symbol(mcpm_entry_point), false); + cpu_reset(__pa_symbol(mcpm_entry_point), false); BUG(); } diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h index 280396483f5d..9bd6bf5f901a 100644 --- a/arch/arm/include/asm/proc-fns.h +++ b/arch/arm/include/asm/proc-fns.h @@ -131,18 +131,55 @@ static inline void init_proc_vtable(const struct processor *p) } #endif -#define cpu_proc_init PROC_VTABLE(_proc_init) -#define cpu_check_bugs PROC_VTABLE(check_bugs) -#define cpu_proc_fin PROC_VTABLE(_proc_fin) -#define cpu_reset PROC_VTABLE(reset) -#define cpu_do_idle PROC_VTABLE(_do_idle) -#define cpu_dcache_clean_area PROC_TABLE(dcache_clean_area) -#define cpu_set_pte_ext PROC_TABLE(set_pte_ext) -#define cpu_do_switch_mm PROC_VTABLE(switch_mm) +static inline void __nocfi cpu_proc_init(void) +{ + PROC_VTABLE(_proc_init)(); +} +static inline void __nocfi cpu_check_bugs(void) +{ + PROC_VTABLE(check_bugs)(); +} +static inline void __nocfi cpu_proc_fin(void) +{ + PROC_VTABLE(_proc_fin)(); +} +static inline void __nocfi cpu_reset(unsigned long addr, bool hvc) +{ + PROC_VTABLE(reset)(addr, hvc); +} +static inline int __nocfi cpu_do_idle(void) +{ + return PROC_VTABLE(_do_idle)(); +} +static inline void __nocfi cpu_dcache_clean_area(void *addr, int size) +{ + PROC_TABLE(dcache_clean_area)(addr, size); +} +#ifdef CONFIG_ARM_LPAE +static inline void __nocfi cpu_set_pte_ext(pte_t *ptep, pte_t pte) +{ + PROC_TABLE(set_pte_ext)(ptep, pte); +} +#else +static inline void __nocfi cpu_set_pte_ext(pte_t *ptep, pte_t pte, unsigned int ext) +{ + PROC_TABLE(set_pte_ext)(ptep, pte, ext); +} +#endif +static inline void __nocfi cpu_do_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm) +{ + PROC_VTABLE(switch_mm)(pgd_phys, mm); +} /* These two are private to arch/arm/kernel/suspend.c */ -#define cpu_do_suspend PROC_VTABLE(do_suspend) -#define cpu_do_resume PROC_VTABLE(do_resume) +static inline void __nocfi cpu_do_suspend(void *p) +{ + PROC_VTABLE(do_suspend)(p); +} +static inline void __nocfi cpu_do_resume(void *p) +{ + PROC_VTABLE(do_resume)(p); +} #endif extern void cpu_resume(void); diff --git a/arch/arm/mach-sunxi/mc_smp.c b/arch/arm/mach-sunxi/mc_smp.c index 277f6aa8e6c2..791eabb7d433 100644 --- a/arch/arm/mach-sunxi/mc_smp.c +++ b/arch/arm/mach-sunxi/mc_smp.c @@ -646,17 +646,12 @@ static bool __init sunxi_mc_smp_cpu_table_init(void) * * We need the trampoline code to enable CCI-400 on the first cluster */ -typedef typeof(cpu_reset) phys_reset_t; - static int __init nocache_trampoline(unsigned long __unused) { - phys_reset_t phys_reset; - setup_mm_for_reboot(); sunxi_cluster_cache_disable_without_axi(); - phys_reset = (phys_reset_t)(unsigned long)__pa_symbol(cpu_reset); - phys_reset(__pa_symbol(sunxi_mc_smp_resume), false); + cpu_reset(__pa_symbol(sunxi_mc_smp_resume), false); BUG(); }