From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932708AbdC3HEA (ORCPT ); Thu, 30 Mar 2017 03:04:00 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:36294 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932181AbdC3HD7 (ORCPT ); Thu, 30 Mar 2017 03:03:59 -0400 Date: Thu, 30 Mar 2017 09:03:54 +0200 From: Ingo Molnar To: Dmitry Vyukov Cc: mark.rutland@arm.com, peterz@infradead.org, aryabinin@virtuozzo.com, akpm@linux-foundation.org, Will Deacon , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Peter Zijlstra Subject: Re: [PATCH] x86, asm-generic: add KASAN instrumentation to bitops Message-ID: <20170330070354.GA5369@gmail.com> References: <20170322150915.138175-1-dvyukov@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170322150915.138175-1-dvyukov@google.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Dmitry Vyukov wrote: > +#include > + > #include > > #include > 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 > + > +#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