From patchwork Sun Feb 25 20:08: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: 13571028 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 A5C10C54E4F for ; Sun, 25 Feb 2024 20:08:50 +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=wVPlNu3ud0rM3h WOP5KbUJFH4GWBX6oQ8Ty9hNO1COEr8Yg5HuRvxPpZdHMk2rHmlcA+9zRiD/Nw8g4VWs9LtpIUs5p wBbcDv/Qt0lQAz9U87HEbxzMtlNiI+uVwhxCRVNsVIZTfa8V5tWKuxVhdO/NF13oJrbZNK43foDdc qRQaiJV+eXUUkMH0aCyno72v/+ny74TF84/WBYeQ9nRcy1udCwHma0c7tmwttyK4Cn0Kbgycasqjb FlwPx5lecCQOwZqLAB5xX+3zBzuycAbXbhUQloy0OCWFkDxAfPFpDYrApiROqPLfbZzgIjd+PQjEa 3YofthMigmU+xyAWkk7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reKnf-0000000Fcs9-2ylz; Sun, 25 Feb 2024 20:08:39 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reKnL-0000000FclX-3MPr for linux-arm-kernel@lists.infradead.org; Sun, 25 Feb 2024 20:08:21 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a3f1bf03722so233307566b.1 for ; Sun, 25 Feb 2024 12:08:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708891698; x=1709496498; 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=wCaAk1hFhoKYzXruPQ1eeh68X3Jw/YYzJJCu/WP1lK3P9qp8Qj99bhawQFzvzPiU6g dV4Wy/gauyKbn016dnIkgmR/3AIWtAImzGFaRs9UOGTQkY3uWE64lnVxQTBNrI+EukBt mzTcQfLcE+Pe96+QNzmXd4eHjqu8/oRB5qsCk8NO8n8j6IFX6nLl14pn4PTqNvhxSByy BGQoLXoImGB0mKTPsT7iUOWMc8VVlt1y1JTKY1llCHGDuqt0cpmkZ8UhQPCRMiAsnNa9 lA/4+m9A/CwE/xHlIJ7di8iymqXKd80iBMZe8tFAGRYLPdLliD1S2CkAzR7e/3UsPmde xMdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708891698; x=1709496498; 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=fqPUgXP+iuMdcKFsHCw74HK6hZNZP2a/s7ROVAa/b0Y+GrPVUyXYgUcKJThtkdxgTc +rYYeJ6zyq9d30HNqHfnHDNY1ayZDbu6mDcCHEM6e/eIb74NRl4GHtei8NorqrRWu9P/ lko/mz0Mo5qmJOwhy0Fh/PkrMSAdx+Cof4Ou+WlVHXEALpgdJ2ds2oF6bFBUDVF6w4SJ 1Z7ivUyCvhn9iBmxL4QfxwmqVU5UVuQCCfY8h7xHZUR0Ly3Vx1BFkXEgePnFHBAFtJR2 T+ZaeIyf+d+x+nLxjutUEpWykEbVEnxwNRwOIvs2/+pX25+HPk8rkYIm1r2H/pFfLuys aI+g== X-Gm-Message-State: AOJu0YzQ1uRNU8xKIsCbhXhqR+Iqt9Wkl9Ez7wipwyvhey7kCNZZ1v2Q bDqlc5zR0bRQmNY7SgIYme2kCN+W5BGjqA2rke/ypRJ7Kl9hpuTCgnsj/eyjczw= X-Google-Smtp-Source: AGHT+IGvoPNI50CVDNAYE+aVj9zM2DSyGYeEYRqrj2AMI1bqHKAqqb7zFpBKsWASbUgdGEAsOR89SA== X-Received: by 2002:a17:907:9905:b0:a3e:998a:cab6 with SMTP id ka5-20020a170907990500b00a3e998acab6mr3511234ejc.74.1708891698443; Sun, 25 Feb 2024 12:08:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 12:08:18 -0800 (PST) From: Linus Walleij Date: Sun, 25 Feb 2024 21:08:15 +0100 Subject: [PATCH 6/7] ARM: turn CPU cache flush functions into static inlines MIME-Version: 1.0 Message-Id: <20240225-arm32-cfi-v1-6-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_120819_995477_20715287 X-CRM114-Status: GOOD ( 16.47 ) 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