[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAAeHK+w4mXJxrerZc0YLXPV0sx6-uadocRHhkrq-4UYRkuXs8g@mail.gmail.com>
Date: Thu, 12 Nov 2020 01:21:21 +0100
From: Andrey Konovalov <andreyknvl@...gle.com>
To: Marco Elver <elver@...gle.com>
Cc: Dmitry Vyukov <dvyukov@...gle.com>,
Alexander Potapenko <glider@...gle.com>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will.deacon@....com>,
Vincenzo Frascino <vincenzo.frascino@....com>,
Evgenii Stepanov <eugenis@...gle.com>,
Andrey Ryabinin <aryabinin@...tuozzo.com>,
Branislav Rankov <Branislav.Rankov@....com>,
Kevin Brodsky <kevin.brodsky@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
kasan-dev <kasan-dev@...glegroups.com>,
Linux ARM <linux-arm-kernel@...ts.infradead.org>,
Linux Memory Management List <linux-mm@...ck.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 08/20] kasan: inline random_tag for HW_TAGS
On Wed, Nov 11, 2020 at 6:02 PM Marco Elver <elver@...gle.com> wrote:
>
> On Tue, Nov 10, 2020 at 11:20PM +0100, Andrey Konovalov wrote:
> > Using random_tag() currently results in a function call. Move its
> > definition to mm/kasan/kasan.h and turn it into a static inline function
> > for hardware tag-based mode to avoid uneeded function calls.
> >
> > Signed-off-by: Andrey Konovalov <andreyknvl@...gle.com>
> > Link: https://linux-review.googlesource.com/id/Iac5b2faf9a912900e16cca6834d621f5d4abf427
> > ---
> > mm/kasan/hw_tags.c | 5 -----
> > mm/kasan/kasan.h | 34 +++++++++++++++++-----------------
> > 2 files changed, 17 insertions(+), 22 deletions(-)
>
> Reviewed-by: Marco Elver <elver@...gle.com>
>
> But see style comments below.
>
> > diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c
> > index 49ea5f5c5643..1476ac07666e 100644
> > --- a/mm/kasan/hw_tags.c
> > +++ b/mm/kasan/hw_tags.c
> > @@ -42,11 +42,6 @@ void kasan_unpoison_memory(const void *address, size_t size)
> > round_up(size, KASAN_GRANULE_SIZE), get_tag(address));
> > }
> >
> > -u8 random_tag(void)
> > -{
> > - return hw_get_random_tag();
> > -}
> > -
> > bool check_invalid_free(void *addr)
> > {
> > u8 ptr_tag = get_tag(addr);
> > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
> > index 8a5501ef2339..7498839a15d3 100644
> > --- a/mm/kasan/kasan.h
> > +++ b/mm/kasan/kasan.h
> > @@ -188,6 +188,12 @@ static inline bool addr_has_metadata(const void *addr)
> >
> > #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
> >
> > +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
> > +void print_tags(u8 addr_tag, const void *addr);
> > +#else
> > +static inline void print_tags(u8 addr_tag, const void *addr) { }
> > +#endif
> > +
> > bool check_invalid_free(void *addr);
> >
> > void *find_first_bad_addr(void *addr, size_t size);
> > @@ -223,23 +229,6 @@ static inline void quarantine_reduce(void) { }
> > static inline void quarantine_remove_cache(struct kmem_cache *cache) { }
> > #endif
> >
> > -#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
> > -
> > -void print_tags(u8 addr_tag, const void *addr);
> > -
> > -u8 random_tag(void);
> > -
> > -#else
> > -
> > -static inline void print_tags(u8 addr_tag, const void *addr) { }
> > -
> > -static inline u8 random_tag(void)
> > -{
> > - return 0;
> > -}
> > -
> > -#endif
> > -
> > #ifndef arch_kasan_set_tag
> > static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
> > {
> > @@ -279,6 +268,17 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
> >
> > #endif /* CONFIG_KASAN_HW_TAGS */
> >
> > +#ifdef CONFIG_KASAN_SW_TAGS
> > +u8 random_tag(void);
> > +#elif defined(CONFIG_KASAN_HW_TAGS)
> > +#define random_tag() hw_get_random_tag()
>
> Shouldn't this also be a function?
>
> +static inline u8 random_tag(void) { return hw_get_random_tag(); }
>
> Or is there a reason why this was made a macro?
No reason, will turn into a function in v10.
>
> > +#else
> > +static inline u8 random_tag(void)
> > +{
> > + return 0;
> > +}
>
> Could just be on 1 line:
>
> +static inline u8 random_tag(void) { return 0; }
Will do in v10.
Thanks!
>
> > +#endif
> > +
> > /*
> > * Exported functions for interfaces called from assembly or from generated
> > * code. Declarations here to avoid warning about missing declarations.
> > --
> > 2.29.2.222.g5d2a92d10f8-goog
> >
Powered by blists - more mailing lists