linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib/stackdepot.c: use a non-instrumented version of memcpy()
@ 2018-05-16 15:34 Alexander Potapenko
  2018-05-16 16:47 ` Andrey Ryabinin
  2018-05-18  1:04 ` kbuild test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander Potapenko @ 2018-05-16 15:34 UTC (permalink / raw)
  To: akpm, dvyukov, aryabinin; +Cc: linux-mm, linux-kernel

stackdepot used to call memcpy(), which compiler tools normally
instrument, therefore every lookup used to unnecessarily call instrumented
code.  This is somewhat ok in the case of KASAN, but under KMSAN a lot of
time was spent in the instrumentation.

(A similar change has been previously committed for memcmp())

Signed-off-by: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
---
 lib/stackdepot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index e513459a5601..d48c744fa750 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -140,7 +140,7 @@ static struct stack_record *depot_alloc_stack(unsigned long *entries, int size,
 	stack->handle.slabindex = depot_index;
 	stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN;
 	stack->handle.valid = 1;
-	memcpy(stack->entries, entries, size * sizeof(unsigned long));
+	__memcpy(stack->entries, entries, size * sizeof(unsigned long));
 	depot_offset += required_size;
 
 	return stack;
-- 
2.17.0.441.gb46fe60e1d-goog

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib/stackdepot.c: use a non-instrumented version of memcpy()
  2018-05-16 15:34 [PATCH] lib/stackdepot.c: use a non-instrumented version of memcpy() Alexander Potapenko
@ 2018-05-16 16:47 ` Andrey Ryabinin
  2018-05-17  8:53   ` Alexander Potapenko
  2018-05-18  1:04 ` kbuild test robot
  1 sibling, 1 reply; 4+ messages in thread
From: Andrey Ryabinin @ 2018-05-16 16:47 UTC (permalink / raw)
  To: Alexander Potapenko, akpm, dvyukov; +Cc: linux-mm, linux-kernel

On 05/16/2018 06:34 PM, Alexander Potapenko wrote:
> stackdepot used to call memcpy(), which compiler tools normally
> instrument, therefore every lookup used to unnecessarily call instrumented
> code.  This is somewhat ok in the case of KASAN, but under KMSAN a lot of
> time was spent in the instrumentation.
> 
> (A similar change has been previously committed for memcmp())
> 
> Signed-off-by: Alexander Potapenko <glider@google.com>
> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> ---
>  lib/stackdepot.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/stackdepot.c b/lib/stackdepot.c
> index e513459a5601..d48c744fa750 100644
> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -140,7 +140,7 @@ static struct stack_record *depot_alloc_stack(unsigned long *entries, int size,
>  	stack->handle.slabindex = depot_index;
>  	stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN;
>  	stack->handle.valid = 1;
> -	memcpy(stack->entries, entries, size * sizeof(unsigned long));
> +	__memcpy(stack->entries, entries, size * sizeof(unsigned long));

This has no effect. Since the whole file is not instrumented memcpy automagically replaced with __memcpy.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib/stackdepot.c: use a non-instrumented version of memcpy()
  2018-05-16 16:47 ` Andrey Ryabinin
@ 2018-05-17  8:53   ` Alexander Potapenko
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Potapenko @ 2018-05-17  8:53 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Andrew Morton, Dmitriy Vyukov, Linux Memory Management List, LKML

On Wed, May 16, 2018 at 6:45 PM Andrey Ryabinin <aryabinin@virtuozzo.com>
wrote:

> On 05/16/2018 06:34 PM, Alexander Potapenko wrote:
> > stackdepot used to call memcpy(), which compiler tools normally
> > instrument, therefore every lookup used to unnecessarily call
instrumented
> > code.  This is somewhat ok in the case of KASAN, but under KMSAN a lot
of
> > time was spent in the instrumentation.
> >
> > (A similar change has been previously committed for memcmp())
> >
> > Signed-off-by: Alexander Potapenko <glider@google.com>
> > Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
> > Cc: Dmitry Vyukov <dvyukov@google.com>
> > ---
> >  lib/stackdepot.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/stackdepot.c b/lib/stackdepot.c
> > index e513459a5601..d48c744fa750 100644
> > --- a/lib/stackdepot.c
> > +++ b/lib/stackdepot.c
> > @@ -140,7 +140,7 @@ static struct stack_record
*depot_alloc_stack(unsigned long *entries, int size,
> >       stack->handle.slabindex = depot_index;
> >       stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN;
> >       stack->handle.valid = 1;
> > -     memcpy(stack->entries, entries, size * sizeof(unsigned long));
> > +     __memcpy(stack->entries, entries, size * sizeof(unsigned long));

> This has no effect. Since the whole file is not instrumented memcpy
automagically replaced with __memcpy.
You're right, we just didn't have the code defining memcpy() to __memcpy()
in KMSAN. I'll fix that instead.


-- 
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib/stackdepot.c: use a non-instrumented version of memcpy()
  2018-05-16 15:34 [PATCH] lib/stackdepot.c: use a non-instrumented version of memcpy() Alexander Potapenko
  2018-05-16 16:47 ` Andrey Ryabinin
@ 2018-05-18  1:04 ` kbuild test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2018-05-18  1:04 UTC (permalink / raw)
  To: Alexander Potapenko
  Cc: kbuild-all, akpm, dvyukov, aryabinin, linux-mm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2862 bytes --]

Hi Alexander,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.17-rc5 next-20180517]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Alexander-Potapenko/lib-stackdepot-c-use-a-non-instrumented-version-of-memcpy/20180518-015328
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=sh 

All errors (new ones prefixed by >>):

   lib/stackdepot.c: In function 'depot_alloc_stack':
>> lib/stackdepot.c:143:2: error: implicit declaration of function '__memcpy'; did you mean 'memcpy'? [-Werror=implicit-function-declaration]
     __memcpy(stack->entries, entries, size * sizeof(unsigned long));
     ^~~~~~~~
     memcpy
   cc1: some warnings being treated as errors

vim +143 lib/stackdepot.c

   106	
   107	/* Allocation of a new stack in raw storage */
   108	static struct stack_record *depot_alloc_stack(unsigned long *entries, int size,
   109			u32 hash, void **prealloc, gfp_t alloc_flags)
   110	{
   111		int required_size = offsetof(struct stack_record, entries) +
   112			sizeof(unsigned long) * size;
   113		struct stack_record *stack;
   114	
   115		required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN);
   116	
   117		if (unlikely(depot_offset + required_size > STACK_ALLOC_SIZE)) {
   118			if (unlikely(depot_index + 1 >= STACK_ALLOC_MAX_SLABS)) {
   119				WARN_ONCE(1, "Stack depot reached limit capacity");
   120				return NULL;
   121			}
   122			depot_index++;
   123			depot_offset = 0;
   124			/*
   125			 * smp_store_release() here pairs with smp_load_acquire() from
   126			 * |next_slab_inited| in depot_save_stack() and
   127			 * init_stack_slab().
   128			 */
   129			if (depot_index + 1 < STACK_ALLOC_MAX_SLABS)
   130				smp_store_release(&next_slab_inited, 0);
   131		}
   132		init_stack_slab(prealloc);
   133		if (stack_slabs[depot_index] == NULL)
   134			return NULL;
   135	
   136		stack = stack_slabs[depot_index] + depot_offset;
   137	
   138		stack->hash = hash;
   139		stack->size = size;
   140		stack->handle.slabindex = depot_index;
   141		stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN;
   142		stack->handle.valid = 1;
 > 143		__memcpy(stack->entries, entries, size * sizeof(unsigned long));
   144		depot_offset += required_size;
   145	
   146		return stack;
   147	}
   148	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 47759 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-18  1:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-16 15:34 [PATCH] lib/stackdepot.c: use a non-instrumented version of memcpy() Alexander Potapenko
2018-05-16 16:47 ` Andrey Ryabinin
2018-05-17  8:53   ` Alexander Potapenko
2018-05-18  1:04 ` kbuild test robot

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).