linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: mark.rutland@arm.com, peterz@infradead.org,
	aryabinin@virtuozzo.com, akpm@linux-foundation.org,
	Will Deacon <will.deacon@arm.com>, Ingo Molnar <mingo@redhat.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	kasan-dev@googlegroups.com,
	Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [PATCH] x86, asm-generic: add KASAN instrumentation to bitops
Date: Thu, 30 Mar 2017 09:03:54 +0200	[thread overview]
Message-ID: <20170330070354.GA5369@gmail.com> (raw)
In-Reply-To: <20170322150915.138175-1-dvyukov@google.com>


* Dmitry Vyukov <dvyukov@google.com> wrote:

> +#include <asm-generic/bitops-instrumented.h>
> +
>  #include <asm-generic/bitops/find.h>
>  
>  #include <asm-generic/bitops/sched.h>
> diff --git a/include/asm-generic/bitops-instrumented.h b/include/asm-generic/bitops-instrumented.h
> new file mode 100644
> index 000000000000..01d02113fc7e
> --- /dev/null
> +++ b/include/asm-generic/bitops-instrumented.h
> @@ -0,0 +1,53 @@
> +/* See atomic-instrumented.h for explanation. */
> +#ifndef _LINUX_BITOPS_INSTRUMENTED_H
> +#define _LINUX_BITOPS_INSTRUMENTED_H
> +
> +#include <linux/kasan-checks.h>
> +
> +#define ADDR(nr, addr) ((void *)(addr) + ((nr) >> 3))
> +
> +#define INSTR_VOID(func)						\
> +static __always_inline void func(long nr, volatile unsigned long *addr)	\
> +{									\
> +	kasan_check_write(ADDR(nr, addr), 1);				\
> +	arch_##func(nr, addr);						\
> +}
> +
> +#define INSTR_BOOL(func)						\
> +static __always_inline bool func(long nr, volatile unsigned long *addr)	\
> +{									\
> +	kasan_check_write(ADDR(nr, addr), 1);				\
> +	return arch_##func(nr, addr);					\
> +}

Is the 'ADDR()' construct going to result in any extra inlined instructions in an 
instrumented kernel? If yes, why not do it inside the KASAN callback to reduce 
inlining overhead?

> +INSTR_VOID(set_bit);
> +INSTR_VOID(__set_bit);
> +INSTR_VOID(clear_bit);
> +INSTR_VOID(__clear_bit);
> +INSTR_VOID(clear_bit_unlock);
> +INSTR_VOID(__clear_bit_unlock);
> +INSTR_VOID(change_bit);
> +INSTR_VOID(__change_bit);
> +
> +INSTR_BOOL(test_and_set_bit);
> +INSTR_BOOL(test_and_set_bit_lock);
> +INSTR_BOOL(__test_and_set_bit);
> +INSTR_BOOL(test_and_clear_bit);
> +INSTR_BOOL(__test_and_clear_bit);
> +INSTR_BOOL(test_and_change_bit);
> +INSTR_BOOL(__test_and_change_bit);
> +#ifdef clear_bit_unlock_is_negative_byte
> +INSTR_BOOL(clear_bit_unlock_is_negative_byte);
> +#endif
> +
> +static bool test_bit(int nr, const volatile unsigned long *addr)
> +{
> +	kasan_check_read(ADDR(nr, addr), 1);
> +	return arch_test_bit(nr, addr);
> +}

Same objections as to the atomic primitives: don't hide function signatures behind 
CPP complexity for marginal line count reduction.

Thanks,

	Ingo

      reply	other threads:[~2017-03-30  7:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-22 15:09 [PATCH] x86, asm-generic: add KASAN instrumentation to bitops Dmitry Vyukov
2017-03-30  7:03 ` Ingo Molnar [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170330070354.GA5369@gmail.com \
    --to=mingo@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=dvyukov@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will.deacon@arm.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).