From patchwork Thu Mar 7 14:22:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13585769 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 0F2C0C54798 for ; Thu, 7 Mar 2024 14:22:20 +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=YcWCiYSXPZCTR02DodhnH7fKzLrIrk13DlFtZ6SnJV4=; b=Ev22CA0edXCpNr ACIaduAycF9/b7vNbSiJ26+gg6AbokOmpq9xaaquFxBcmU+6seGmYhrnD6x7OhMtD9V3o49uYr0I/ SIt9wRLeEjqnlTbZxhpQA8unS4qiH4UmrMeFguUvSyGVZvB2WMkAgKAJBZ6hG5ZEMJ+kFN+PWNvlG PEO6J3Kw2l/wt+IAGbZ+3rd1XvQgNca3bbEYyLWT8TJBkLdQHELN88I4/V7n+92nWb32riAW6uiQZ SChPmT+aIZ6QAN/i4/A4TSeajR0dO0NBqaEeQ2kYiqhjINdWZ3dbXdr63r9187dWhhzZSKy6Ocgat YYwvIeWMZwW/EnjhHpIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdP-000000051AM-3O09; Thu, 07 Mar 2024 14:22:11 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdJ-0000000514s-3plY for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 14:22:07 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-512bde3d197so968535e87.0 for ; Thu, 07 Mar 2024 06:22:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709821323; x=1710426123; 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=vaHsL9uZaLpUW/gtSno6U8/q3nfzw7ffg7lr4P7gXB0=; b=pHytGSbW7uH33b53BOqlBEItuwdX9knadICdjCx1RdPw+8okl4x6rP9lwbrsgppvqh VB4X5RvPvhtTjL1ByAxKBA1NCyUaGUdRr47NEEcq4sZG3ZJdY3fiuftLJxlC7QeuvjpE DIqg7yVM2Sfl9k+mQkhBSB/1sb4MWWBPzQv/+D+O5g6wXKr22+zVo1wTRepOPWER9o+1 CuYN9IYaJadzxewPgvG7T6Oh6CP7mbsvLmDMAlwfTtuMwcrS2ul1bGa1LhCBmYG1duUa F89IQDS7yNNWN0h0bZctXT0el95xLfLoQ7WMOuhssy58jgENNpT4eJTCxUwyF5dDyuK5 RhCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709821323; x=1710426123; 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=vaHsL9uZaLpUW/gtSno6U8/q3nfzw7ffg7lr4P7gXB0=; b=lomRRksQVZ8cvg2K+Qo7shHP6c99kBxNNa91lnymCMHadSFuLxz1k5JjNANvbnCyQq RWFmhbEHpc74GHb8eNcEdJ6bEzbQVaVxSC+jLRj+MLoeEXu5asN4ohCMglfFId/2QnH1 YtW5UOBaQ3SVf3MXbFkICVjOMjn4b1FkR+Oii2+yGnyvDS27Bdtd0Ipc0gSbcFbXTWTD gLPiJz8sxb2FuO3y3+BrUntCAF86wslBCRPXh0YRqo4f8bvvHcLcaTMF/3HawnIhd+Bl kbrpIBuhE4UeHONdP9hYMprOVOoqKhjP1bIfyEvh6Cl69gMVRCGxRVO6gyzuzmCWSWyU YFfg== X-Gm-Message-State: AOJu0YwQkSH/gwaydrmKwq8Z/5JNPLCjhR9Tf3Z3LdpjpUPlnKhJNBwm m0xUsg//J5RbSENkhCEE3oRbjsBCAsd1+wgRAKe2mjj+o7IF8N/9BRl6rSoOjhw= X-Google-Smtp-Source: AGHT+IEjEs26cHK1t9iAXvxyu/L9BJnGLeqBGsWPyI0GJgRqzy6czqPbkg8pKDhoELdHGfHHlDTaeg== X-Received: by 2002:a05:6512:3b1:b0:513:600c:4ae1 with SMTP id v17-20020a05651203b100b00513600c4ae1mr1522176lfp.27.1709821323348; Thu, 07 Mar 2024 06:22:03 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x11-20020a19e00b000000b005133b381a5csm2417137lfg.90.2024.03.07.06.22.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 06:22:02 -0800 (PST) From: Linus Walleij Date: Thu, 07 Mar 2024 15:22:00 +0100 Subject: [PATCH v2 1/9] ARM: Support CLANG CFI MIME-Version: 1.0 Message-Id: <20240307-arm32-cfi-v2-1-cc74ea0306b3@linaro.org> References: <20240307-arm32-cfi-v2-0-cc74ea0306b3@linaro.org> In-Reply-To: <20240307-arm32-cfi-v2-0-cc74ea0306b3@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-20240307_062205_985558_9931D856 X-CRM114-Status: GOOD ( 11.71 ) 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 Support Control Flow Integrity (CFI) when compiling with CLANG. In the as-of-writing LLVM CLANG implementation (v17) the 32-bit ARM platform is supported by the generic CFI implementation, which isn't tailored specifically for ARM32 but works well enough to enable the feature. Signed-off-by: Linus Walleij --- arch/arm/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 0af6709570d1..1216656a40bc 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -34,6 +34,7 @@ config ARM select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7 select ARCH_SUPPORTS_ATOMIC_RMW + select ARCH_SUPPORTS_CFI_CLANG select ARCH_SUPPORTS_HUGETLBFS if ARM_LPAE select ARCH_SUPPORTS_PER_VMA_LOCK select ARCH_USE_BUILTIN_BSWAP From patchwork Thu Mar 7 14:22:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13585771 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 181A1C48BF6 for ; Thu, 7 Mar 2024 14:22:25 +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=0SQjousCDXDkxOlBJ2ocfnM1o3srohN6EuFvnzEeHog=; b=s4nEnVTg2q+8Bv /Hx/X1XlEVLn4XYkV0ajULuuSC50/Z74fcyODfEuuBZNiND/FOy2YARb5Aaq8IgLV+e7mpRu///nA QUNcjgltzsPOiROy1gUsN//gBADj8kJHBHB77mywB7Usdhh9EEpc72vhkjd6FSoxhHj79udpoH3Z+ dZ1H98pNtYwD+7TzgWxz2kav3P4pFyMnRuCCyYG5Rv2r2VtWREfna9iCSUOvkn0HIwuiAKsFw1rGT NZUfHI7fGhM8jdQCIDdPUJ9oF5u+8udV73OE/X2bmxeGyGJLERGXIV9z1VIydnUaZsOPSmld/FpYS YbuBhmcwVoEvHRE+McEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdQ-000000051BB-3Aey; Thu, 07 Mar 2024 14:22:12 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdK-0000000515V-3Awz for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 14:22:08 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5135e8262e4so1028552e87.0 for ; Thu, 07 Mar 2024 06:22:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709821325; x=1710426125; 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=x8Pxmb+SJtaf6Rq8IgIflwtKkppPo4bfFWLJbSoBsFk=; b=HFmtD/GVyp9OdznqZAbsHGPNBUiU/1RuQDWu7PoOo03a2/G1a77gw2v+YiH5+3t/jJ cH9apzWk3MFNz+thJl+PO2NRPufIKZZRrQ4yYbzxm6ydSqpFF6mfnyQy2bIGpjW18Nas pkF/TXag6EYMgonvDaLQZgds8GELIg7isNGaqu/+bQRtUe4e3zTArV9Sl/9TfwQw9L1r P6bT7XMu/Ejjmh0jCh0XlG4WJU6QzGq2UeJwY7ZbFbm9wCzLbAuB2eJaac4SDsUOiXxp t1au6/denQ59ANhmsdg/JMFcP/R7p+jcFe/dh+UjNd1sbjWB9u85mMHXWbk+PjsEDMe9 fk3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709821325; x=1710426125; 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=x8Pxmb+SJtaf6Rq8IgIflwtKkppPo4bfFWLJbSoBsFk=; b=alyQNSNrgWiMAaZCMzEyU43AbWHRqg6K9uJp6st4o7oL+3dA/y7ozoxbfHzjCsLsBx pacIGJT0/nxZfDOxIkwz56QSsisr0w6zWHoRlTWslPbMkzKDc54p+GURkGxYWiSTRg5r R34rddk0GnOlcoDK0DSIekM5qosbhXxTkS/bq3EP9PYRCXXRmEZA392Tyus93M3mhwRn 1eoGc+OsqOjXY2qn3hPde3KR36FHkWnVJqIvu/ZaQxQVs1Kc6IRqTmgQOY9SoyjczME6 MQ+HXe+r56aLhbk+wPpWIBzvLzgNc1nvfmQhjPXF+KFcSbWsZc5VsQLv/GoSL+iicxg0 yQSA== X-Gm-Message-State: AOJu0YxOLsSN9prXhFlgQmNjk7CJOxgj9dEuEx55Fuae7/7QsqvEu6+Z 19zSMWqlpa+3TX0hWxNs/gYiyLANWEERg4dfPlEKpOairvzWfI+qQVEX181DIfQ= X-Google-Smtp-Source: AGHT+IEsEJyP5Gecw/WvzollfZYjFKnEe7nllK/88gszUJ80WnmTVHMiLEEuKZmKX560jolbjhl1ug== X-Received: by 2002:a05:6512:3d26:b0:513:1c47:5381 with SMTP id d38-20020a0565123d2600b005131c475381mr2115492lfv.2.1709821324688; Thu, 07 Mar 2024 06:22:04 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x11-20020a19e00b000000b005133b381a5csm2417137lfg.90.2024.03.07.06.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 06:22:04 -0800 (PST) From: Linus Walleij Date: Thu, 07 Mar 2024 15:22:01 +0100 Subject: [PATCH v2 2/9] ARM: tlbflush: Make TLB flushes into static inlines MIME-Version: 1.0 Message-Id: <20240307-arm32-cfi-v2-2-cc74ea0306b3@linaro.org> References: <20240307-arm32-cfi-v2-0-cc74ea0306b3@linaro.org> In-Reply-To: <20240307-arm32-cfi-v2-0-cc74ea0306b3@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-20240307_062206_861319_DAB58C62 X-CRM114-Status: GOOD ( 13.42 ) 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 Instead of just using defines to define the TLB flush functions, use static inlines. This has the upside that we can tag those as __nocfi so we can execute a CFI-enabled kernel. Move the variables around a bit so the functions can find their global variable cpu_tlb. Signed-off-by: Linus Walleij --- arch/arm/include/asm/tlbflush.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/arm/include/asm/tlbflush.h b/arch/arm/include/asm/tlbflush.h index 38c6e4a2a0b6..7340518ee0e9 100644 --- a/arch/arm/include/asm/tlbflush.h +++ b/arch/arm/include/asm/tlbflush.h @@ -210,13 +210,23 @@ struct cpu_tlb_fns { unsigned long tlb_flags; }; +extern struct cpu_tlb_fns cpu_tlb; + +#define __cpu_tlb_flags cpu_tlb.tlb_flags + /* * Select the calling method */ #ifdef MULTI_TLB -#define __cpu_flush_user_tlb_range cpu_tlb.flush_user_range -#define __cpu_flush_kern_tlb_range cpu_tlb.flush_kern_range +static inline void __nocfi __cpu_flush_user_tlb_range(unsigned long s, unsigned long e, struct vm_area_struct *vma) +{ + cpu_tlb.flush_user_range(s, e, vma); +} +static inline void __nocfi __cpu_flush_kern_tlb_range(unsigned long s, unsigned long e) +{ + cpu_tlb.flush_kern_range(s, e); +} #else @@ -228,10 +238,6 @@ extern void __cpu_flush_kern_tlb_range(unsigned long, unsigned long); #endif -extern struct cpu_tlb_fns cpu_tlb; - -#define __cpu_tlb_flags cpu_tlb.tlb_flags - /* * TLB Management * ============== From patchwork Thu Mar 7 14:22:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13585773 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 57AA7C48BF6 for ; Thu, 7 Mar 2024 14:22:33 +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=l3jz1S/MUSlE2CzazwdkxUsAg5LqjXJL8ESRjmegLhA=; b=tdbrQcmHBwrpdO 0Z6V7dt58PK+hlRiwo8cgVu4v5xbsPwigghvFYegD634in9+JwR+O4DTHYwKdocbbRYPlyd3Tmx4J UgoUR7Fql3ElaUTjNRhEPjnMuhYInr9fMm2Ww8PwMtgMA9MIxtnZZGxQQzAAeHBEAI9uPoBENGNbb YE/HAFuTAk4eoRHl0wz69MykdQJ6V2cnCtuQjPKceQ7GtOng8VsVFLk+xJrvrFmRtqadbcM5XYRnZ zmwjtlvywPjA1deYJOkz9KdaE1vctQtMI8YRcBKWffDJWL2FO1St19HEIJnCzNUxWfVpVjBFh/DHf jzpOOdvVGm42RJC88rRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdZ-000000051Jn-2ZdQ; Thu, 07 Mar 2024 14:22:21 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdN-0000000517A-12Ex for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 14:22:10 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-512b3b04995so704886e87.3 for ; Thu, 07 Mar 2024 06:22:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709821327; x=1710426127; 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=B30jBDh8l6oorNFVXLBM1TGNZMOeiKLndpCjpsCjwrU=; b=oMOJgm9oIr5SkkGXdGgZbMdIHS6UelAs8bTJ6sVliVEwfYwoyQW1kFNf2PxlImbuNv hL3TR9M0H6dwTpGoRC07JXPyoQEWATpfnyMIN2AMa6b2nyrlbLBeTkFFpVKEcsqSeoSw WtCX8TjFLIrqOBxgZugJXLAy+WjI1/nR/H9yO6uNAxx24w3WLMhyUb3WkYWTaFtigQHY gpX1RBD+EDTikZIK6WcHt3OsJvOXM871Mi9jshgtSu7bHMmloD1pT1ofjRS5AtjgS9r2 vveIi49quAYu051HozcZOMEXb1Y6avqpu4GXiO6QN1QdDYVRZF6ESClEc5DDHaG+3MfR spXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709821327; x=1710426127; 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=B30jBDh8l6oorNFVXLBM1TGNZMOeiKLndpCjpsCjwrU=; b=XpGReiQOeZk+QpVghB/MkwkRI6OeTmQtts5+7T5nCCdKZs8ozMKmafKxSBNptxunsc t857y+i2dWV86lJ3rmAzMtbVAQDRiVAfKg3w7fZTMnInJ14QlU3sfqiqZLUYzuYG5C/X qGxhp+oY9vk1MPaGvONGzvkq3C5wuUIiFbiBt8FawlM81SJHtPLhfcyOLAM1WPlu52QM INa0kpox3PQCXz3HC3PHN3Q1sxkdeMLd3rV98RUWZliO+3RanEeb4qauVTL2SYe/Z+/G yvVuH1KYxvMlxWmPqJWnik85eFrpBoSXb13FXQ6S0weuTtdt9CgpJdOsWw48j1AVJ/VV bMNg== X-Gm-Message-State: AOJu0YwNqAR4m+Ckf4mAsI9Bh7E8NqQ9o2GE9t6UGgNjZW0Rl8Vu6eqb ZWKNEkpsM1Y1A5m4ZeydncRfx0PzlOto+oFzkV50GlSAHnQU5W2hCGd8yfuPRdE= X-Google-Smtp-Source: AGHT+IGXjoDQpzRMRKlzo/7VGOXZ+RgzbXKawPARgnq/UpHXLLP5tU5H1naXKLsUutRVz3aQXuGqlA== X-Received: by 2002:a19:430e:0:b0:513:4847:2c0d with SMTP id q14-20020a19430e000000b0051348472c0dmr1459347lfa.29.1709821326883; Thu, 07 Mar 2024 06:22:06 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x11-20020a19e00b000000b005133b381a5csm2417137lfg.90.2024.03.07.06.22.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 06:22:05 -0800 (PST) From: Linus Walleij Date: Thu, 07 Mar 2024 15:22:02 +0100 Subject: [PATCH v2 3/9] ARM: bugs: Check in the vtable instead of defined aliases MIME-Version: 1.0 Message-Id: <20240307-arm32-cfi-v2-3-cc74ea0306b3@linaro.org> References: <20240307-arm32-cfi-v2-0-cc74ea0306b3@linaro.org> In-Reply-To: <20240307-arm32-cfi-v2-0-cc74ea0306b3@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-20240307_062209_566081_EF192582 X-CRM114-Status: GOOD ( 18.74 ) 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 Instead of checking if cpu_check_bugs() exist, check for this callback directly in the CPU vtable: this is better because the function is just a define to the vtable entry and this is why the code works. But we want to be able to specify a proper function for cpu_check_bugs() so look into the vtable instead. In bugs.c assign PROC_VTABLE(switch_mm) instead of assigning cpu_do_switch_mm where again this is just a define into the vtable: this makes it possible to make cpu_do_switch_mm() into a real function. Signed-off-by: Linus Walleij --- arch/arm/kernel/bugs.c | 2 +- arch/arm/mm/proc-v7-bugs.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/bugs.c b/arch/arm/kernel/bugs.c index 087bce6ec8e9..35d39efb51ed 100644 --- a/arch/arm/kernel/bugs.c +++ b/arch/arm/kernel/bugs.c @@ -7,7 +7,7 @@ void check_other_bugs(void) { #ifdef MULTI_CPU - if (cpu_check_bugs) + if (PROC_VTABLE(check_bugs)) cpu_check_bugs(); #endif } diff --git a/arch/arm/mm/proc-v7-bugs.c b/arch/arm/mm/proc-v7-bugs.c index 8bc7a2d6d6c7..ea3ee2bd7b56 100644 --- a/arch/arm/mm/proc-v7-bugs.c +++ b/arch/arm/mm/proc-v7-bugs.c @@ -87,14 +87,14 @@ static unsigned int spectre_v2_install_workaround(unsigned int method) case SPECTRE_V2_METHOD_HVC: per_cpu(harden_branch_predictor_fn, cpu) = call_hvc_arch_workaround_1; - cpu_do_switch_mm = cpu_v7_hvc_switch_mm; + PROC_VTABLE(switch_mm) = cpu_v7_hvc_switch_mm; spectre_v2_method = "hypervisor"; break; case SPECTRE_V2_METHOD_SMC: per_cpu(harden_branch_predictor_fn, cpu) = call_smc_arch_workaround_1; - cpu_do_switch_mm = cpu_v7_smc_switch_mm; + PROC_VTABLE(switch_mm) = cpu_v7_smc_switch_mm; spectre_v2_method = "firmware"; break; } From patchwork Thu Mar 7 14:22:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13585772 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 11749C54798 for ; Thu, 7 Mar 2024 14:22:33 +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=kC8hvxgq7WFMKW QMFzvOo3+0HwEh4XL0r7KCxgY9pHuII6q8x5KkNlzg+JFTyr7E9oFaNbAimXp5lgycAq2LNLMO3gD F65oVnyHeD1EJ2DriDVTSXrvlf+O1V3y1PqoeaZKwhkSDsVO0uLIjvNAi0XHNQsr4PQ8XTvRYLIrB T558VJpUyqiXJSUPWD4qDzUk9A2BiLRcDnzGKuBcxnkIsRuO2nDM2cnQZq6yUhV9+hC7v3N5setnR wVwMN4VuNWVa8zgRr/Yj0YbU969Eo4GEJvjOjVgpMFuBmZ9WRSbVayVK8CMuoPY/ipL68LsqBxsLt pqwvvfGJ8o7ljT6jIreQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdc-000000051Li-2b8g; Thu, 07 Mar 2024 14:22:24 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdO-0000000517t-04tQ for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 14:22:11 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-513181719easo740183e87.3 for ; Thu, 07 Mar 2024 06:22:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709821328; x=1710426128; 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=fJxulZPPBux/Qv/5W8JchpKxzDxafZByyMpqg6bVP6IG7UQBPuPBg5qWW40NW/l6S5 Sr5jRs6/JzZUoDIt+xgRX7V/aKq9tnIX6hClxzGKUvFPO2nXEfjSYepR/y3+G7umamXf 795MJoL8lbG+TA1m0rIsbjH2LDjbZdCXNgoyn9113+lFLlZCbKOH3j/GvCrgWSHr2yDU OaV1Z9UdKdc9C4Vqp9tQiDjRNOpUazLVO+fp/p2CmktMmodlgzLu1irgQoHJBrGzDOsg dJLU39f7v4y/Z3Ne+l048PJ+DyEg89mtyIIBCaW9FcYV0E78VNLXPRa+pZeh8aLZnTEr 90eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709821328; x=1710426128; 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=V6kEycAGh1VLsmZO55rfSC5AcFxnISzXbpb4zTm9KQP1Gn4rcXBf14438cHGvA/Rby mD8hK58mkavro1koKMcIcBqdpS2j/kHNU4TNQharShiSlEkxG78aLmqbCXXvpPd129DM gI0uAhABs8uFzdkg3e1sVtrUceevRA2NM6rOEP7KnThQMx0uZzpdN7SfMwwedDCAldcz vrUa60KQYN2aVYFavqqetMI2IlgNEuVng05Kl4lD5KFR3ZanWPznsP/EXpH1C2hN5M6m jvZEO81xq3WniKcFKO+BrUgM32sC/O0VF3IwmyYCxBuT8tAIBqCPCnLMTvaj3DFj0QMw epRQ== X-Gm-Message-State: AOJu0YyyouC4QSdDeDi1ssO6JC36qW0DFaKsO3NfNTMENvGMNuf8Guxg P6MrM6aFs3HI84+zQiWr0pKOcV4WobCMxktiBJLEU9kCc+dxg/33efu4aNGPzW4= X-Google-Smtp-Source: AGHT+IELgAm1/45/O9CskIcUj9k8CU3DbEr4VnQhmRSWgTo2h/a2mNo6b8VOMOqIzgSwAxzWHUGx1A== X-Received: by 2002:a05:6512:33d3:b0:513:83c5:3724 with SMTP id d19-20020a05651233d300b0051383c53724mr1014083lfg.37.1709821328286; Thu, 07 Mar 2024 06:22:08 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x11-20020a19e00b000000b005133b381a5csm2417137lfg.90.2024.03.07.06.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 06:22:07 -0800 (PST) From: Linus Walleij Date: Thu, 07 Mar 2024 15:22:03 +0100 Subject: [PATCH v2 4/9] ARM: proc: Use inlines instead of defines MIME-Version: 1.0 Message-Id: <20240307-arm32-cfi-v2-4-cc74ea0306b3@linaro.org> References: <20240307-arm32-cfi-v2-0-cc74ea0306b3@linaro.org> In-Reply-To: <20240307-arm32-cfi-v2-0-cc74ea0306b3@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-20240307_062210_095363_180CEA1B X-CRM114-Status: GOOD ( 15.95 ) 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(); } From patchwork Thu Mar 7 14:22:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13585774 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 55B11C48BF6 for ; Thu, 7 Mar 2024 14:22:37 +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=NyjxNT0wCJZdeKr3kg4RyYm6N2Ty38wHzESrLvSEkBY=; b=lHeROp5TMqg7W1 KFtlxjwB8GXr1IHMCgIyId4BWYzGE2sSC2eV5AFbo2ImWfK3YRk0Z+a311PEoqiZkCetY/GWUECy0 mluxkrGVL7j79qNI8lhjEZw1JfNVpHP8pXjE4usKMXApt7fqcbCj86H23kCwWexFa4P2eIqsQ7cuP Y4rAsm5AyS7qMWL+HdjaWBwa9RW1HjCeGY+53ZGuNXmh91gcZIoae0amCHzMPWD9SzdvNlr5NBZR6 kwI4KXouz6umx9Culj6NsK+XRLG/WB4zdQqdaVTOyZjCIzYi7/V/ADduUrTjVIYEdfKDSVA1a0wyP tMI+GnEOStLgv+YPp5/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEde-000000051NF-1pgR; Thu, 07 Mar 2024 14:22:26 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdP-0000000518x-2nB3 for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 14:22:13 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5132010e5d1so1286020e87.0 for ; Thu, 07 Mar 2024 06:22:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709821329; x=1710426129; 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=0hQVFeBxn1IenYJfJewA7K4YjroRXq1981Lcc541jow=; b=NPXwEk9kR8CHxxQXNjq9nCF1ESju/ofGZPNn97IsS31iUVNRO7FHTiLEt8siKG5IBh 0U50OR/EUZ/vPeVBpsIMn6OlQYg2ut4c6mAuAYn+XWIWld/qCp9/FSi6LMNXHSHdt1xi A4p4YueJAoCc2jlgFSpXVff6LLF8pLT3Yit4WjTswcIE4QCN6iZ+jynOdlSUsoCvCWQh N/SPMrDMDq32XttK7aKdTllhgxZL7SlaPrnCrAObQ9afKgy0kcxhGBYWy72Rh3hzpczV MP1x4UBU7YQRv9tE+a0aj21qdV/mfAf+kc0KRbneKwCmMxYwv/Xyu1AD0ipa9T5UXLrr Y19g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709821329; x=1710426129; 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=0hQVFeBxn1IenYJfJewA7K4YjroRXq1981Lcc541jow=; b=PlbJxfzUmttEeGtE/sp9XHeTvtQ27P6Ts5yebCLLciXbHCTsiaL6tYgQEH7uEWWhVd p//RKj9k53bCIwnFRiYiG21ppEiG/wj4DoAs/k8yzYCwCrLSogmuhelFSaImSoeol4js /yjhRetR6cPMKNujf8M3mXf/CqNdAJ4Vgh4UPajn9Ru2ZZ88feEfYWkGg530Cb8XK9Ij WL6yRIErMV1SSeWyUWXsZ8poEgRGdt5uiBpZGLCFH2KmGVHb1JZp+CjUJfG7ZY87Mp0Q wgfpKzYRNJh9zAqQE2dpArFW1qme3HAGNzxgMcVIf7v+zDEU2xqDNXphAmH8MV0nqQvE fHCw== X-Gm-Message-State: AOJu0Ywh/v5qT/hngrn4XPzRCKRZo4dyiooZN+5sD1NPrfU7hirRIII8 mM2R4qG/JnDWR2VS7nq5gMdh5ckaXbHc4mqod6/NCnhSqeBpc25FtUDj89Lh+Ls= X-Google-Smtp-Source: AGHT+IEQGnmVcalNP3Hec44WlB/kQtAuRD4bDECAOf1RXnT2QXtjQ6JZsUFXdFMtMvyH8obZ0o6x1g== X-Received: by 2002:a05:6512:e94:b0:512:da6d:23aa with SMTP id bi20-20020a0565120e9400b00512da6d23aamr1760365lfb.67.1709821329648; Thu, 07 Mar 2024 06:22:09 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x11-20020a19e00b000000b005133b381a5csm2417137lfg.90.2024.03.07.06.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 06:22:09 -0800 (PST) From: Linus Walleij Date: Thu, 07 Mar 2024 15:22:04 +0100 Subject: [PATCH v2 5/9] ARM: delay: Turn delay functions into static inlines MIME-Version: 1.0 Message-Id: <20240307-arm32-cfi-v2-5-cc74ea0306b3@linaro.org> References: <20240307-arm32-cfi-v2-0-cc74ea0306b3@linaro.org> In-Reply-To: <20240307-arm32-cfi-v2-0-cc74ea0306b3@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-20240307_062211_865481_D595DFFF X-CRM114-Status: GOOD ( 13.12 ) 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 The members of the vector table arm_delay_ops are called directly using defines, but this is really confusing for KCFI. Wrap the calls in static inlines and tag them with __nocfi so things start to work. Without this patch, platforms without a delay timer will not boot (sticks in calibrating loop etc). Signed-off-by: Linus Walleij --- arch/arm/include/asm/delay.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h index 1d069e558d8d..7d611b810b6c 100644 --- a/arch/arm/include/asm/delay.h +++ b/arch/arm/include/asm/delay.h @@ -55,7 +55,10 @@ extern struct arm_delay_ops { unsigned long ticks_per_jiffy; } arm_delay_ops; -#define __delay(n) arm_delay_ops.delay(n) +static inline void __nocfi __delay(unsigned long n) +{ + arm_delay_ops.delay(n); +} /* * This function intentionally does not exist; if you see references to @@ -76,8 +79,15 @@ extern void __bad_udelay(void); * first constant multiplications gets optimized away if the delay is * a constant) */ -#define __udelay(n) arm_delay_ops.udelay(n) -#define __const_udelay(n) arm_delay_ops.const_udelay(n) +static inline void __nocfi __udelay(unsigned long n) +{ + arm_delay_ops.udelay(n); +} + +static inline void __nocfi __const_udelay(unsigned long n) +{ + arm_delay_ops.const_udelay(n); +} #define udelay(n) \ (__builtin_constant_p(n) ? \ From patchwork Thu Mar 7 14:22:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13585775 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 9A302C54798 for ; Thu, 7 Mar 2024 14:22:37 +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=oCYZFnQhlAnpMSSMC1v+hap02Hvxmb7DsabuccVsbRQ=; b=yk7CpV43A9RZbm kWwxUvKnn+BA8fRjD6qFKSMnLqLoIpx9x7GdcbWAkheJN2DVPYtjeQ+xmplcjJMbMJWZ7V3w8BbuZ TLVRHsHo3Mofhq6VEc0POHyBn4tG0Cg1jAs+f+iybpLpv6KlQAnpJNvoVlBn6FFUaPqQn3aZ0kD8v LgTfMehn2S3YJhhNXt+ba4Bl6gqc8k3q6UrGKaagxW9yLVdkECu3bj/smlrIKvqqDXwtIMTnWZN4K d8iz7BW3epMsuOyNLquBT7c2DcCc3yCagbs4hbrp2OOgkGroXvlscpk80hZ+GqnfhfK3tpTrl5luv A9wQkaEe18i8iUaNQfgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdg-000000051OW-1YYv; Thu, 07 Mar 2024 14:22:28 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdQ-000000051AP-3f9O for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 14:22:14 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-51320ca689aso972292e87.2 for ; Thu, 07 Mar 2024 06:22:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709821331; x=1710426131; 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=VdBurprtbHQ0vf8zuRQqqoRGQBp+uV6pNFNeBm4lwRE=; b=WxcjedxNtIXFYB0WfdFUeB+VS4nPwlAGjq74srgCABPju5IPtmRHoG/uCjy0GmkF3N 4Hy+9GASKx9Ze7rfNZTXJTW2IW9EfkvylRSV7MgpqwDN58+q9K3dQRVadnm8P+aBpeTJ bHPp+W1zAoHtOPn4OWX7nWesAnA0AYgSu0s2hwhcMHNpz+dpnjjA2FC4uqpDZXJiiETq /usrtcJSOKGKtcqnJCxhGXfP7ElmsePbDQSgfdtiUDhuDOdIGCagwmHyCgy2r7KBVAZk rgRNAmLqENoaj345qfKWWGzNFSX+N3AzqaGyzZv02JyT9WzmJ38sIg8JEZFN9KZWn4xj fX6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709821331; x=1710426131; 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=VdBurprtbHQ0vf8zuRQqqoRGQBp+uV6pNFNeBm4lwRE=; b=q0Y1kDW3mIh/ExqtONbJ9ATNcyd8Br3pTMwxD6GLIaIDJ3yoLcMokCXPmIVg2Tgeqx Ij3RxyMz2ErsAvStGv/syIdjighcaZmA/mTzTSD7y33qaL3xVAXQTyiyx9PpWAQhKa6v BmsaQcZ4TjqGVsXfsP0QBF0vVapP+TKjW4Tu5X0Bxhs9bSlE7oeCHSsLLnFQiy+/KGYh eIDQv9DiVKV69roqxTn5pj1AFQIgSSiclEXHPvZxqvFfzP4IV8j4FthQZ50fc2WEBNBu TH0i+jnMlMlsOh1P1NNGnmtFQK0jylfWTNsZSKN/zxlJtQn+LOtYA7VUAXakd846vWDH 40gQ== X-Gm-Message-State: AOJu0YwvDL+DqzHvn+dsMVH7R+uyG6lf25A9uYtxjJvHlQPbVGZhWcb5 8VoaEVxhkUTeXgVjeyltz83HMO6vUwxhiIgokB78rcOk7UtsF41XsWZQTAfqO8c= X-Google-Smtp-Source: AGHT+IF1nk9H64kQ8tJhZkw9Mweac5JVWSD30bjZZ4qOdm9T9dqmbpu8DjJBXk4PnLtBpqOSRtMGzw== X-Received: by 2002:a05:6512:10c3:b0:513:2643:873d with SMTP id k3-20020a05651210c300b005132643873dmr2066032lfg.36.1709821331003; Thu, 07 Mar 2024 06:22:11 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x11-20020a19e00b000000b005133b381a5csm2417137lfg.90.2024.03.07.06.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 06:22:10 -0800 (PST) From: Linus Walleij Date: Thu, 07 Mar 2024 15:22:05 +0100 Subject: [PATCH v2 6/9] ARM: turn CPU cache flush functions into static inlines MIME-Version: 1.0 Message-Id: <20240307-arm32-cfi-v2-6-cc74ea0306b3@linaro.org> References: <20240307-arm32-cfi-v2-0-cc74ea0306b3@linaro.org> In-Reply-To: <20240307-arm32-cfi-v2-0-cc74ea0306b3@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-20240307_062213_032851_D8BE861B X-CRM114-Status: GOOD ( 17.17 ) 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 The members of the vector table struct cpu_cache_fns cpu_cache are called directly using defines, but this is really confusing for KCFI. Wrap the calls in static inlines and tag them with __nocfi so things start to work. Conversely a similar approach is used for the __glue() helpers which define their way into an assembly ENTRY(symbol) for respective CPU variant. We wrap these into static inlines and prefix them with __nocfi as well. (This happens on !MULTI_CACHE systems.) For this case we also need to invoke the __glue() macro to provide a proper function prototype for the inner function. Signed-off-by: Linus Walleij --- arch/arm/include/asm/cacheflush.h | 45 +++++++++++++++++++++++++++++++-------- arch/arm/mm/dma.h | 28 ++++++++++++++++++------ 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h index 1075534b0a2e..76fb665162a4 100644 --- a/arch/arm/include/asm/cacheflush.h +++ b/arch/arm/include/asm/cacheflush.h @@ -122,14 +122,38 @@ struct cpu_cache_fns { extern struct cpu_cache_fns cpu_cache; -#define __cpuc_flush_icache_all cpu_cache.flush_icache_all -#define __cpuc_flush_kern_all cpu_cache.flush_kern_all -#define __cpuc_flush_kern_louis cpu_cache.flush_kern_louis -#define __cpuc_flush_user_all cpu_cache.flush_user_all -#define __cpuc_flush_user_range cpu_cache.flush_user_range -#define __cpuc_coherent_kern_range cpu_cache.coherent_kern_range -#define __cpuc_coherent_user_range cpu_cache.coherent_user_range -#define __cpuc_flush_dcache_area cpu_cache.flush_kern_dcache_area +static inline void __nocfi __cpuc_flush_icache_all(void) +{ + cpu_cache.flush_icache_all(); +} +static inline void __nocfi __cpuc_flush_kern_all(void) +{ + cpu_cache.flush_icache_all(); +} +static inline void __nocfi __cpuc_flush_kern_louis(void) +{ + cpu_cache.flush_kern_louis(); +} +static inline void __nocfi __cpuc_flush_user_all(void) +{ + cpu_cache.flush_user_all(); +} +static inline void __nocfi __cpuc_flush_user_range(unsigned long start, unsigned long end, unsigned int flags) +{ + cpu_cache.flush_user_range(start, end, flags); +} +static inline void __nocfi __cpuc_coherent_kern_range(unsigned long start, unsigned long end) +{ + cpu_cache.coherent_kern_range(start, end); +} +static inline int __nocfi __cpuc_coherent_user_range(unsigned long start, unsigned long end) +{ + return cpu_cache.coherent_user_range(start, end); +} +static inline void __nocfi __cpuc_flush_dcache_area(void *kaddr, size_t sz) +{ + cpu_cache.flush_kern_dcache_area(kaddr, sz); +} /* * These are private to the dma-mapping API. Do not use directly. @@ -137,7 +161,10 @@ extern struct cpu_cache_fns cpu_cache; * is visible to DMA, or data written by DMA to system memory is * visible to the CPU. */ -#define dmac_flush_range cpu_cache.dma_flush_range +static inline void __nocfi dmac_flush_range(const void *start, const void *end) +{ + cpu_cache.dma_flush_range(start, end); +} #else diff --git a/arch/arm/mm/dma.h b/arch/arm/mm/dma.h index aaef64b7f177..251b8a9fffc1 100644 --- a/arch/arm/mm/dma.h +++ b/arch/arm/mm/dma.h @@ -5,8 +5,6 @@ #include #ifndef MULTI_CACHE -#define dmac_map_area __glue(_CACHE,_dma_map_area) -#define dmac_unmap_area __glue(_CACHE,_dma_unmap_area) /* * These are private to the dma-mapping API. Do not use directly. @@ -14,8 +12,20 @@ * is visible to DMA, or data written by DMA to system memory is * visible to the CPU. */ -extern void dmac_map_area(const void *, size_t, int); -extern void dmac_unmap_area(const void *, size_t, int); + +/* These turn into function declarations for each per-CPU glue function */ +void __glue(_CACHE,_dma_map_area)(const void *, size_t, int); +void __glue(_CACHE,_dma_unmap_area)(const void *, size_t, int); + +static inline void __nocfi dmac_map_area(const void *start, size_t sz, int flags) +{ + __glue(_CACHE,_dma_map_area)(start, sz, flags); +} + +static inline void __nocfi dmac_unmap_area(const void *start, size_t sz, int flags) +{ + __glue(_CACHE,_dma_unmap_area)(start, sz, flags); +} #else @@ -25,8 +35,14 @@ extern void dmac_unmap_area(const void *, size_t, int); * is visible to DMA, or data written by DMA to system memory is * visible to the CPU. */ -#define dmac_map_area cpu_cache.dma_map_area -#define dmac_unmap_area cpu_cache.dma_unmap_area +static inline void __nocfi dmac_map_area(const void *start, size_t sz, int flags) +{ + cpu_cache.dma_map_area(start, sz, flags); +} +static inline void __nocfi dmac_unmap_area(const void *start, size_t sz, int flags) +{ + cpu_cache.dma_unmap_area(start, sz, flags); +} #endif From patchwork Thu Mar 7 14:22:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13585776 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 E37CFC48BF6 for ; Thu, 7 Mar 2024 14:22:54 +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=CmM26Oo1B6dgB2aCt3tedBfAAWdc/hEfGy5RnWMq6xQ=; b=lmDdM3XSdBPPGd OU4TaymntTXlDUK8rN/l4fXzj5ofFGIf21eutMAnoKrAfXCvk9iiLebtswZhZgrvLHZcFTMi8z+KM cifjTY0ILiO1yKhwSSHRVIazyibdp3kRs5eFBKqG7v14Rz2WCHU95PlPt7xUu0jmt0a1smFqFPai1 dFOLmIHQ9hMNGKgUKe1GA6kdPhX5E755GJhLN7MGUEZuRay8QfdWutMV/XgxaWuR1TtGJech7fzA2 aqwVUjGbz5Ti3yYqaHQkM/YSVUeFnbE0N75VDTNHxajNC3CEPfVpnVs/NOexxoVg2hq0VRQk1ZXym x7k0F6bFbGnveDObTxCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdt-000000051XV-1oX9; Thu, 07 Mar 2024 14:22:41 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdR-000000051BP-3g2w for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 14:22:15 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-51325c38d10so1984251e87.1 for ; Thu, 07 Mar 2024 06:22:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709821332; x=1710426132; 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=hqBogdja5tMMOO5wTCklLeqAnS4o63/YOLSFeJQB8FQ=; b=oqHPNWH0PODYLvxCcOHXyQM5b83R86PBtI1g/mhe7XENzM9i94QFTjrAcKfZRoxe3c ezlZY8G9XJj+xmQVuSLT2v79QThfH92R/PdQ3mBNJkYAXrLxuXY6YzcHyzuO66oQObPg KF6xF19OHbEBgYNGhKW5YUjA/NnH03JB/yyTIhpFKNTxqnvXYR4zGtrXzldYh/U6O0hZ o8UnOO9NymVBxzgJjskFc/S7kOTlGV1a8xOwkQYZMIaHblgYN/AeWMMG9CoR6oAhV4da xxzmc6NaKroqm8EkKQWI37J1UsbmYnuuGPKgsAOtI0Nnn43BvWWnorA4Ufuwn5Ua7RF8 iyJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709821332; x=1710426132; 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=hqBogdja5tMMOO5wTCklLeqAnS4o63/YOLSFeJQB8FQ=; b=ATpPZBdafpFqyeh2f7CkPlGu5zro0mpN2+jS6zw7DglbCgoR/sIPuaHk3/fXwwnXNp /Fzx12bOPSbzjywPKsyvLHHAYjL2amUnvUVU1tYhXrK4DON2dqsXHucWgKP0YRVs/hrX m1IOxH+pv+DfdV87qJCJdP3sQ2+fzx+tUx91FwwzjbCWf4RkO9KnjTFF/FxeRVgcB7Na g/I0BZ/M14ZEBZNxgoNKJ2n7Bexpz9+6BjZ9UoRLrXfnUtquMHTxOO86aYD37qUIh5Jf nsRH2SbahXs1nofpAF8/fYeuF8pKG7GlfZ42Ostl+cCnukcvqy9/cTbfpqRBTVpoLzvh uyLA== X-Gm-Message-State: AOJu0Yz+H4SxFZvTb6D/Ijw9atOcakMCsqcWG2EHEqMdiUQFrhNjZf0H oKEEruE0zsLY3aHdbVBrWW2WckTR120KzFrNfU6KVDniSztZsHBYkcwKOlDE/v4= X-Google-Smtp-Source: AGHT+IGHiABAzZ0gzslhFBFFCHaQfxDyREIPjRltUdsCGKwCOVgo5+NjSeovE0CeKpTNYEbNM0cxZA== X-Received: by 2002:a19:ca1d:0:b0:513:3b3e:c361 with SMTP id a29-20020a19ca1d000000b005133b3ec361mr610924lfg.2.1709821332426; Thu, 07 Mar 2024 06:22:12 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x11-20020a19e00b000000b005133b381a5csm2417137lfg.90.2024.03.07.06.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 06:22:11 -0800 (PST) From: Linus Walleij Date: Thu, 07 Mar 2024 15:22:06 +0100 Subject: [PATCH v2 7/9] ARM: page: Turn highpage accesses into static inlines MIME-Version: 1.0 Message-Id: <20240307-arm32-cfi-v2-7-cc74ea0306b3@linaro.org> References: <20240307-arm32-cfi-v2-0-cc74ea0306b3@linaro.org> In-Reply-To: <20240307-arm32-cfi-v2-0-cc74ea0306b3@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-20240307_062214_142128_827E9293 X-CRM114-Status: GOOD ( 13.82 ) 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 Clearing and copying pages in highmem uses either the cpu_user vtable or the __glue() assembler stubs to call into per-CPU versions of these functions. This is all really confusing for KCFI so wrap these into static inlines and prefix each inline function with __nocfi. __cpu_clear_user_highpage() and __cpu_copy_user_highpage() are exported in arch/arm/mm/proc-syms.c which causes a problem with using static inlines, but it turns out that these exports are completely unused, so we can just delete them. Signed-off-by: Linus Walleij --- arch/arm/include/asm/page.h | 36 +++++++++++++++++++++++++++++------- arch/arm/mm/proc-syms.c | 7 +------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h index 119aa85d1feb..8bf297228627 100644 --- a/arch/arm/include/asm/page.h +++ b/arch/arm/include/asm/page.h @@ -138,17 +138,39 @@ void xscale_mc_clear_user_highpage(struct page *page, unsigned long vaddr); #ifdef MULTI_USER extern struct cpu_user_fns cpu_user; -#define __cpu_clear_user_highpage cpu_user.cpu_clear_user_highpage -#define __cpu_copy_user_highpage cpu_user.cpu_copy_user_highpage +static inline void __nocfi __cpu_clear_user_highpage(struct page *page, + unsigned long vaddr) +{ + cpu_user.cpu_clear_user_highpage(page, vaddr); +} + +static inline void __nocfi __cpu_copy_user_highpage(struct page *to, + struct page *from, unsigned long vaddr, + struct vm_area_struct *vma) +{ + cpu_user.cpu_copy_user_highpage(to, from, vaddr, vma); +} #else -#define __cpu_clear_user_highpage __glue(_USER,_clear_user_highpage) -#define __cpu_copy_user_highpage __glue(_USER,_copy_user_highpage) +/* These turn into function declarations for each per-CPU glue function */ +void __glue(_USER,_clear_user_highpage)(struct page *page, unsigned long vaddr); +void __glue(_USER,_copy_user_highpage)(struct page *to, struct page *from, + unsigned long vaddr, struct vm_area_struct *vma); + +static inline void __nocfi __cpu_clear_user_highpage(struct page *page, + unsigned long vaddr) +{ + __glue(_USER,_clear_user_highpage)(page, vaddr); +} + +static inline void __nocfi __cpu_copy_user_highpage(struct page *to, + struct page *from, unsigned long vaddr, + struct vm_area_struct *vma) +{ + __glue(_USER,_copy_user_highpage)(to, from, vaddr, vma); +} -extern void __cpu_clear_user_highpage(struct page *page, unsigned long vaddr); -extern void __cpu_copy_user_highpage(struct page *to, struct page *from, - unsigned long vaddr, struct vm_area_struct *vma); #endif #define clear_user_highpage(page,vaddr) \ diff --git a/arch/arm/mm/proc-syms.c b/arch/arm/mm/proc-syms.c index e21249548e9f..c93fec38d9f4 100644 --- a/arch/arm/mm/proc-syms.c +++ b/arch/arm/mm/proc-syms.c @@ -31,14 +31,9 @@ EXPORT_SYMBOL(__cpuc_flush_dcache_area); EXPORT_SYMBOL(cpu_cache); #endif -#ifdef CONFIG_MMU -#ifndef MULTI_USER -EXPORT_SYMBOL(__cpu_clear_user_highpage); -EXPORT_SYMBOL(__cpu_copy_user_highpage); -#else +#if defined(CONFIG_MMU) && defined(MULTI_USER) EXPORT_SYMBOL(cpu_user); #endif -#endif /* * No module should need to touch the TLB (and currently From patchwork Thu Mar 7 14:22:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13585778 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 A0DC6C54E49 for ; Thu, 7 Mar 2024 14:22:56 +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=+CPW0zr5OAEosT+gkaB8qohpOW9Zu0C7Ug8MgBC9BMc=; b=S+PJ30r+OI1Ykc ptYxyiUpBiNNpiqEKB5y82raX6uh8H8tKUf9pulkDL1v3ovUWwYi9R6DjmypzqpqsYJVCogdrkZCs qBP57cGj+CIpUefKnIFJdhMZHUZ3PrjwgQ1z2cz9LIx85cjfDnfx0YVeI8YChBlGXVARRrVXR0OSd tdkIoCZ+uShhYKsvgQLR+AcUAay7KpoHOCdNPHi3F0Wa76iIKCU/5rkLHdSRvFd0oWf2tgO3NnrqO 31SvucpVxaZDcch9sH/WvZYGd1ogDtWrLy35WSCUzaWta3RWsLzoW09MfM1YEF2GPItrT9aLAZJ3p bKf3C+5u3O2GV0hlj1Dw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdu-000000051Yf-3rhr; Thu, 07 Mar 2024 14:22:42 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdT-000000051Co-3nhc for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 14:22:17 +0000 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-5134d7e16a8so783002e87.3 for ; Thu, 07 Mar 2024 06:22:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709821334; x=1710426134; 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=t7VN7dAxY/atiKl1Kg9VLJc8sP0Tkd5ODVxcz6HIAw0=; b=PVjetRkHXomfzbvjw/a3Yk3jcIMqleMT/OiQ4kHUO8gGgLziCnp6t/jewPerGhjPG9 p7D8oKx+SnvAsGQBPKuCdDJ7xTMma4C4cARMBje3iQyiSWq67hCBweEz6gsS2tWI+rG8 hj1rXwsOWJZw3Ks/clM8nspkNKxGdQHqpAWVV+LSdAZEU/mhupUqSty1RE2sUppByxCO C3amDFM5nBfWpLYE94BXIml0pDCSy20miBYNRfclLbkqQFMfKZ3t107TE8HPgG6j8Gid VjBqp6c7OGYP4YradN+jPLXFo77UWO3WXjPWfqM5kTFt43/T54AEEdnYdlZQm0cw7zf/ NaMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709821334; x=1710426134; 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=t7VN7dAxY/atiKl1Kg9VLJc8sP0Tkd5ODVxcz6HIAw0=; b=pIbjdI4nOmlmh9Npvk7WILo2Yrn0kHwnYeOXfIBb3JFV9mgqsxkGJGWZVzjsmlw5kb ISqBZeYXKXgZ7oKZg5s7SwUneF217lsECQBZQRj4W7q3eMRSRmuh77kHpyp7lPH2JnEf pvPORbDDVy6TmYjGi9/QNgHifVg+QRtFGsW2FsvbNv2ewPR4w3txmKDgIuwEbYxRvWTa uztHQ8V7GmYWc/Q4TSAvxlQsMQ+vwZJTKZ4ysJSQb0DNfJmuHsXgQPSZQxdvLQer2pXy Q9qn9xZqTk/Oe8huxxFQoaZooD/+mBF+H/60/Ab7UNEWjEWhdvr+T+0NkJa8lVTtxNqk xLkw== X-Gm-Message-State: AOJu0YzdUZpv5iyafmgVZ0M418uZ0ILwt5ak8M/y+x+xeZw6nxcOQ2ON c3P+o2sa1GFgDRJSFfPma3oD3HsUBB1r0WqvDyHQvgdBRbTT/rnv/RHJzoFu9FY= X-Google-Smtp-Source: AGHT+IGuVdEctc6eZaqVDqgJkOSPcRt7FloO7oS7Ik9PTreXsBbLelwTC+GMVqluqHoE3YBWXS+GEQ== X-Received: by 2002:a05:6512:1107:b0:513:df6:dcd3 with SMTP id l7-20020a056512110700b005130df6dcd3mr2367653lfg.48.1709821333814; Thu, 07 Mar 2024 06:22:13 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x11-20020a19e00b000000b005133b381a5csm2417137lfg.90.2024.03.07.06.22.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 06:22:13 -0800 (PST) From: Linus Walleij Date: Thu, 07 Mar 2024 15:22:07 +0100 Subject: [PATCH v2 8/9] ARM: ftrace: Define ftrace_stub_graph MIME-Version: 1.0 Message-Id: <20240307-arm32-cfi-v2-8-cc74ea0306b3@linaro.org> References: <20240307-arm32-cfi-v2-0-cc74ea0306b3@linaro.org> In-Reply-To: <20240307-arm32-cfi-v2-0-cc74ea0306b3@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-20240307_062216_038805_75E6FD25 X-CRM114-Status: GOOD ( 11.13 ) 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 Several architectures defines this stub for the graph tracer, and it is needed for CFI, as it needs a separate symbol for it. The trick from include/asm-generic/vmlinux.lds.h to define ftrace_stub_graph to ftrace_stub isn't working when using CFI. Commit 883bbbffa5a4 contains the details. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-ftrace.S | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/kernel/entry-ftrace.S b/arch/arm/kernel/entry-ftrace.S index 3e7bcaca5e07..bc598e3d8dd2 100644 --- a/arch/arm/kernel/entry-ftrace.S +++ b/arch/arm/kernel/entry-ftrace.S @@ -271,6 +271,10 @@ ENTRY(ftrace_stub) ret lr ENDPROC(ftrace_stub) +ENTRY(ftrace_stub_graph) + ret lr +ENDPROC(ftrace_stub_graph) + #ifdef CONFIG_DYNAMIC_FTRACE __INIT From patchwork Thu Mar 7 14:22:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13585777 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 49D76C54798 for ; Thu, 7 Mar 2024 14:22:56 +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=qNHY6EsfeeaeEMeVPKYItKsGFk/v0QBjC6wmUbSiZSw=; b=SJmYNseFkJCA6M JjgwafkKEmXusoVOcBX6rvlwJSv5yw6qxHondWtL1+Rq34ZCb4Eh9AwtS3mDo+Z1dydHURgZlJ3GS j45G+hCHJ0luoamDzhnbW4j6XNp216gBL3LHAS4Kr/jzwYeSPfUaDRoaA90Zr/tNSeUgHSNkN6lcG DdVE719QKS1xhjnQmYwBzhwgXyLtwsyXusX7tncUmsSKFWriaNIXJNDIG3PN5waJf+Si8TrMMfQ7V N+mrVBORvxT9dERnCM0MO4+vNeqHCPmnmwmtiGodHcDoGlmiZmjmDF4VQGmF5kTwIVs2l4HJg5Khw 6hwVbkMzUJ5eELoTL5YA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdv-000000051ZI-3DFa; Thu, 07 Mar 2024 14:22:43 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riEdV-000000051DR-1WbQ for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 14:22:19 +0000 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-5131f3fc695so999207e87.1 for ; Thu, 07 Mar 2024 06:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709821335; x=1710426135; 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=gA8ZxFrx9Z5SRPo+jVn81u04sn9IDPwgcfATkPUWIfU=; b=qS1y79aHEAtkYNiB5etMRLEjEAdRE48y9hGE70CVJMg3P9o9ywHjGJhnT+HpQgtPW2 ifciquuWV6EWWlqtVm46HT3sw48hdcijHm2yDe0i505gDH0U4a6IM3Z+e9QUiQ2v6dQi M/ELm5eJ47HnpkGpYMwlPgfmruTxEPXckaT4LLIVWZ8oateg3wB0k/bXHwbQNjlQqfio uebncAgS/EFsucgQ0RDZdUF7prFVUFAtI2+Mb1MiUZsMJYAmUvs5S2vVHnea/4v3NLOq Ms3+030ImC7f/xU/iAiivdWwj4vSEKejI7X8+rJbB8fF8jf4hIHsNG1X5C0g3vm1yEEl XWjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709821335; x=1710426135; 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=gA8ZxFrx9Z5SRPo+jVn81u04sn9IDPwgcfATkPUWIfU=; b=VxQe9zWPCkR1LEGkIFio6ctNZ/t7KDltcxhcfVJNbFT0lK9Dspn/FUvpVThSEd9CA0 PGVH1tltrlf8M7AxTkxhe1JwkAkIzq0Zjvzko5QY5e7Z1AVf6YmExl5n54Sk6ztHMV2t xrshtvZZMjh1KVnwMr2HlrGs2JHaKWnOZ7kE9uif05YiaB03mZHQ2d2g61TJGugCTHyM PoeL6ZTdzEXmMwZ5xZuKEnWfVq/85+J4RMfm2l/aJ5v16RndLLMfsOpn50hEnDzLJeed PwRfTn1eZWJ4T55pcF5vdm7Jteu2cqmfrVPcE4rrNagCLiXwUzGa2TJAtYw6flgdezoq Othg== X-Gm-Message-State: AOJu0YwYyBDCLcBHSAx7hi7vf5u05fwrBJIL9gmGOAkMcgG+JR204VQE N/ddmqeiB3osBNO9Z2NG/8z6MtkdRxVtd4uC/dAvtBAueFwZ5wHeAq5CqORK42s= X-Google-Smtp-Source: AGHT+IFJ0RWu6nZugPa5qOJDHSREvOJkqmv9RWJNmGCystSvavUS9gLkmUCT0/awji5M89TB64nTNw== X-Received: by 2002:a05:6512:2216:b0:513:4a0c:b83d with SMTP id h22-20020a056512221600b005134a0cb83dmr1652946lfu.46.1709821335171; Thu, 07 Mar 2024 06:22:15 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x11-20020a19e00b000000b005133b381a5csm2417137lfg.90.2024.03.07.06.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 06:22:14 -0800 (PST) From: Linus Walleij Date: Thu, 07 Mar 2024 15:22:08 +0100 Subject: [PATCH v2 9/9] ARM: KCFI: Allow permissive CFI mode MIME-Version: 1.0 Message-Id: <20240307-arm32-cfi-v2-9-cc74ea0306b3@linaro.org> References: <20240307-arm32-cfi-v2-0-cc74ea0306b3@linaro.org> In-Reply-To: <20240307-arm32-cfi-v2-0-cc74ea0306b3@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-20240307_062217_471535_36038C81 X-CRM114-Status: GOOD ( 14.95 ) 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 This registers a breakpoint handler for the new breakpoint type (0x03) inserted by LLVM CLANG for CFI breakpoints. If we are in permissive mode, just print a backtrace and continue. Example with CONFIG_CFI_PERMISSIVE enabled: root@Vexpress:/ echo CFI_FORWARD_PROTO > /sys/kernel/debug/provoke-crash/DIRECT lkdtm: Performing direct entry CFI_FORWARD_PROTO lkdtm: Calling matched prototype ... lkdtm: Calling mismatched prototype ... hw-breakpoint: Permissive CFI breakpoint CPU: 0 PID: 114 Comm: sh Not tainted 6.8.0-rc1+ #111 Hardware name: ARM-Versatile Express unwind_backtrace from show_stack+0x28/0x30 (...) lkdtm: FAIL: survived mismatched prototype function call! lkdtm: Unexpected! This kernel (6.8.0-rc1+ armv7l) was built with CONFIG_CFI_CLANG=y As you can see the LKDTM test fails, but I expect that this would be expected behaviour in the permissive mode. Signed-off-by: Linus Walleij --- arch/arm/include/asm/hw_breakpoint.h | 1 + arch/arm/kernel/hw_breakpoint.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/arch/arm/include/asm/hw_breakpoint.h b/arch/arm/include/asm/hw_breakpoint.h index 62358d3ca0a8..e7f9961c53b2 100644 --- a/arch/arm/include/asm/hw_breakpoint.h +++ b/arch/arm/include/asm/hw_breakpoint.h @@ -84,6 +84,7 @@ static inline void decode_ctrl_reg(u32 reg, #define ARM_DSCR_MOE(x) ((x >> 2) & 0xf) #define ARM_ENTRY_BREAKPOINT 0x1 #define ARM_ENTRY_ASYNC_WATCHPOINT 0x2 +#define ARM_ENTRY_CFI_BREAKPOINT 0x3 #define ARM_ENTRY_SYNC_WATCHPOINT 0xa /* DSCR monitor/halting bits. */ diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c index dc0fb7a81371..256146684813 100644 --- a/arch/arm/kernel/hw_breakpoint.c +++ b/arch/arm/kernel/hw_breakpoint.c @@ -932,6 +932,16 @@ static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr, case ARM_ENTRY_SYNC_WATCHPOINT: watchpoint_handler(addr, fsr, regs); break; + case ARM_ENTRY_CFI_BREAKPOINT: + if (IS_ENABLED(CONFIG_CFI_PERMISSIVE)) { + pr_err("Permissive CFI breakpoint\n"); + dump_stack(); + /* Skip the breaking instruction */ + instruction_pointer(regs) += 4; + } else { + die("Oops - CFI", regs, 0); + } + break; default: ret = 1; /* Unhandled fault. */ }