Message ID | a1f0413493eb7db125c3f8086f5d8635b627fd2c.1638825394.git.andreyknvl@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | kasan, vmalloc, arm64: add vmalloc tagging support for SW/HW_TAGS | expand |
On Mon, Dec 6, 2021 at 10:46 PM <andrey.konovalov@linux.dev> wrote: > > From: Andrey Konovalov <andreyknvl@google.com> > > HW_TAGS KASAN relies on ARM Memory Tagging Extension (MTE). With MTE, > a memory region must be mapped as MT_NORMAL_TAGGED to allow setting > memory tags via MTE-specific instructions. > > This change adds proper protection bits to vmalloc() allocations. > These allocations are always backed by page_alloc pages, so the tags > will actually be getting set on the corresponding physical memory. > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> > Co-developed-by: Vincenzo Frascino <vincenzo.frascino@arm.com> > --- > arch/arm64/include/asm/vmalloc.h | 10 ++++++++++ > include/linux/vmalloc.h | 7 +++++++ > mm/vmalloc.c | 2 ++ > 3 files changed, 19 insertions(+) > > diff --git a/arch/arm64/include/asm/vmalloc.h b/arch/arm64/include/asm/vmalloc.h > index b9185503feae..3d35adf365bf 100644 > --- a/arch/arm64/include/asm/vmalloc.h > +++ b/arch/arm64/include/asm/vmalloc.h > @@ -25,4 +25,14 @@ static inline bool arch_vmap_pmd_supported(pgprot_t prot) > > #endif > > +#define arch_vmalloc_pgprot_modify arch_vmalloc_pgprot_modify > +static inline pgprot_t arch_vmalloc_pgprot_modify(pgprot_t prot) > +{ > + if (IS_ENABLED(CONFIG_KASAN_HW_TAGS) && > + (pgprot_val(prot) == pgprot_val(PAGE_KERNEL))) > + prot = pgprot_tagged(prot); > + > + return prot; > +} > + > #endif /* _ASM_ARM64_VMALLOC_H */ > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h > index b22369f540eb..965c4bf475f1 100644 > --- a/include/linux/vmalloc.h > +++ b/include/linux/vmalloc.h > @@ -108,6 +108,13 @@ static inline int arch_vmap_pte_supported_shift(unsigned long size) > } > #endif > > +#ifndef arch_vmalloc_pgprot_modify > +static inline pgprot_t arch_vmalloc_pgprot_modify(pgprot_t prot) > +{ > + return prot; > +} > +#endif > + > /* > * Highlevel APIs for driver use > */ > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 7be18b292679..f37d0ed99bf9 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -3033,6 +3033,8 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, > return NULL; > } > > + prot = arch_vmalloc_pgprot_modify(prot); > + > if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP)) { > unsigned long size_per_node; > > -- > 2.25.1 > Hi Vincenzo, This patch is based on an early version of the HW_TAGS series you had. Could you PTAL and give your sign-off? Thanks!
Hi Andrey, On 12/6/21 9:44 PM, andrey.konovalov@linux.dev wrote: > From: Andrey Konovalov <andreyknvl@google.com> > > HW_TAGS KASAN relies on ARM Memory Tagging Extension (MTE). With MTE, > a memory region must be mapped as MT_NORMAL_TAGGED to allow setting > memory tags via MTE-specific instructions. > > This change adds proper protection bits to vmalloc() allocations. Please avoid "this patch/this change" in patch description and use imperative mode as if you are giving a command to the code base ([1] paragraph 2). > These allocations are always backed by page_alloc pages, so the tags > will actually be getting set on the corresponding physical memory. > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> > Co-developed-by: Vincenzo Frascino <vincenzo.frascino@arm.com> With the change to the commit message: Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com> > --- > arch/arm64/include/asm/vmalloc.h | 10 ++++++++++ > include/linux/vmalloc.h | 7 +++++++ > mm/vmalloc.c | 2 ++ > 3 files changed, 19 insertions(+) > > diff --git a/arch/arm64/include/asm/vmalloc.h b/arch/arm64/include/asm/vmalloc.h > index b9185503feae..3d35adf365bf 100644 > --- a/arch/arm64/include/asm/vmalloc.h > +++ b/arch/arm64/include/asm/vmalloc.h > @@ -25,4 +25,14 @@ static inline bool arch_vmap_pmd_supported(pgprot_t prot) > > #endif > > +#define arch_vmalloc_pgprot_modify arch_vmalloc_pgprot_modify > +static inline pgprot_t arch_vmalloc_pgprot_modify(pgprot_t prot) > +{ > + if (IS_ENABLED(CONFIG_KASAN_HW_TAGS) && > + (pgprot_val(prot) == pgprot_val(PAGE_KERNEL))) > + prot = pgprot_tagged(prot); > + > + return prot; > +} > + > #endif /* _ASM_ARM64_VMALLOC_H */ > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h > index b22369f540eb..965c4bf475f1 100644 > --- a/include/linux/vmalloc.h > +++ b/include/linux/vmalloc.h > @@ -108,6 +108,13 @@ static inline int arch_vmap_pte_supported_shift(unsigned long size) > } > #endif > > +#ifndef arch_vmalloc_pgprot_modify > +static inline pgprot_t arch_vmalloc_pgprot_modify(pgprot_t prot) > +{ > + return prot; > +} > +#endif > + > /* > * Highlevel APIs for driver use > */ > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 7be18b292679..f37d0ed99bf9 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -3033,6 +3033,8 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, > return NULL; > } > > + prot = arch_vmalloc_pgprot_modify(prot); > + > if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP)) { > unsigned long size_per_node; > >
On Mon, Dec 13, 2021 at 4:17 PM Vincenzo Frascino <vincenzo.frascino@arm.com> wrote: > > Hi Andrey, > > On 12/6/21 9:44 PM, andrey.konovalov@linux.dev wrote: > > From: Andrey Konovalov <andreyknvl@google.com> > > > > HW_TAGS KASAN relies on ARM Memory Tagging Extension (MTE). With MTE, > > a memory region must be mapped as MT_NORMAL_TAGGED to allow setting > > memory tags via MTE-specific instructions. > > > > This change adds proper protection bits to vmalloc() allocations. > > Please avoid "this patch/this change" in patch description and use imperative > mode as if you are giving a command to the code base ([1] paragraph 2). Hi Vincenzo, Done in v3. > > These allocations are always backed by page_alloc pages, so the tags > > will actually be getting set on the corresponding physical memory. > > > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> > > Co-developed-by: Vincenzo Frascino <vincenzo.frascino@arm.com> > > With the change to the commit message: > > Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com> Thanks!
diff --git a/arch/arm64/include/asm/vmalloc.h b/arch/arm64/include/asm/vmalloc.h index b9185503feae..3d35adf365bf 100644 --- a/arch/arm64/include/asm/vmalloc.h +++ b/arch/arm64/include/asm/vmalloc.h @@ -25,4 +25,14 @@ static inline bool arch_vmap_pmd_supported(pgprot_t prot) #endif +#define arch_vmalloc_pgprot_modify arch_vmalloc_pgprot_modify +static inline pgprot_t arch_vmalloc_pgprot_modify(pgprot_t prot) +{ + if (IS_ENABLED(CONFIG_KASAN_HW_TAGS) && + (pgprot_val(prot) == pgprot_val(PAGE_KERNEL))) + prot = pgprot_tagged(prot); + + return prot; +} + #endif /* _ASM_ARM64_VMALLOC_H */ diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index b22369f540eb..965c4bf475f1 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -108,6 +108,13 @@ static inline int arch_vmap_pte_supported_shift(unsigned long size) } #endif +#ifndef arch_vmalloc_pgprot_modify +static inline pgprot_t arch_vmalloc_pgprot_modify(pgprot_t prot) +{ + return prot; +} +#endif + /* * Highlevel APIs for driver use */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 7be18b292679..f37d0ed99bf9 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3033,6 +3033,8 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, return NULL; } + prot = arch_vmalloc_pgprot_modify(prot); + if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP)) { unsigned long size_per_node;