diff mbox series

[v3,7/9] ARM: page: Turn highpage accesses into static inlines

Message ID 20240311-arm32-cfi-v3-7-224a0f0a45c2@linaro.org (mailing list archive)
State New, archived
Headers show
Series CFI for ARM32 using LLVM | expand

Commit Message

Linus Walleij March 11, 2024, 9:15 a.m. UTC
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 <linus.walleij@linaro.org>
---
 arch/arm/include/asm/page.h | 36 +++++++++++++++++++++++++++++-------
 arch/arm/mm/proc-syms.c     |  7 +------
 2 files changed, 30 insertions(+), 13 deletions(-)

Comments

Ard Biesheuvel March 11, 2024, 12:15 p.m. UTC | #1
On Mon, 11 Mar 2024 at 10:15, Linus Walleij <linus.walleij@linaro.org> wrote:
>
> 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 <linus.walleij@linaro.org>
> ---
>  arch/arm/include/asm/page.h | 36 +++++++++++++++++++++++++++++-------
>  arch/arm/mm/proc-syms.c     |  7 +------
>  2 files changed, 30 insertions(+), 13 deletions(-)
>

Are you sure this patch is needed?

> 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
>
> --
> 2.34.1
>
Linus Walleij March 28, 2024, 8:18 a.m. UTC | #2
On Mon, Mar 11, 2024 at 1:15 PM Ard Biesheuvel <ardb@kernel.org> wrote:
> On Mon, 11 Mar 2024 at 10:15, Linus Walleij <linus.walleij@linaro.org> wrote:
> >
> > 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 <linus.walleij@linaro.org>
> > ---
> >  arch/arm/include/asm/page.h | 36 +++++++++++++++++++++++++++++-------
> >  arch/arm/mm/proc-syms.c     |  7 +------
> >  2 files changed, 30 insertions(+), 13 deletions(-)
> >
>
> Are you sure this patch is needed?

It's not needed, it was a development artifact from fixing the highmem access
before fixing cache and TLB flush. The highmem code did a bunch of that.

Posting v4!

Yours,
Linus Walleij
diff mbox series

Patch

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