10 Aug, 2020

3 commits

  • Pull Kbuild updates from Masahiro Yamada:

    - run the checker (e.g. sparse) after the compiler

    - remove unneeded cc-option tests for old compiler flags

    - fix tar-pkg to install dtbs

    - introduce ccflags-remove-y and asflags-remove-y syntax

    - allow to trace functions in sub-directories of lib/

    - introduce hostprogs-always-y and userprogs-always-y syntax

    - various Makefile cleanups

    * tag 'kbuild-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
    kbuild: stop filtering out $(GCC_PLUGINS_CFLAGS) from cc-option base
    kbuild: include scripts/Makefile.* only when relevant CONFIG is enabled
    kbuild: introduce hostprogs-always-y and userprogs-always-y
    kbuild: sort hostprogs before passing it to ifneq
    kbuild: move host .so build rules to scripts/gcc-plugins/Makefile
    kbuild: Replace HTTP links with HTTPS ones
    kbuild: trace functions in subdirectories of lib/
    kbuild: introduce ccflags-remove-y and asflags-remove-y
    kbuild: do not export LDFLAGS_vmlinux
    kbuild: always create directories of targets
    powerpc/boot: add DTB to 'targets'
    kbuild: buildtar: add dtbs support
    kbuild: remove cc-option test of -ffreestanding
    kbuild: remove cc-option test of -fno-stack-protector
    Revert "kbuild: Create directory for target DTB"
    kbuild: run the checker after the compiler

    Linus Torvalds
     
  • ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)

    exists here in sub-directories of lib/ to keep the behavior of
    commit 2464a609ded0 ("ftrace: do not trace library functions").

    Since that commit, not only the objects in lib/ but also the ones in
    the sub-directories are excluded from ftrace (although the commit
    description did not explicitly mention this).

    However, most of library functions in sub-directories are not so hot.
    Re-add them to ftrace.

    Going forward, only the objects right under lib/ will be excluded.

    Cc: Ingo Molnar
    Signed-off-by: Masahiro Yamada
    Acked-by: Steven Rostedt (VMware)

    Masahiro Yamada
     
  • CFLAGS_REMOVE_.o filters out flags when compiling a particular
    object, but there is no convenient way to do that for every object in
    a directory.

    Add ccflags-remove-y and asflags-remove-y to make it easily.

    Use ccflags-remove-y to clean up some Makefiles.

    The add/remove order works as follows:

    [1] KBUILD_CFLAGS specifies compiler flags used globally

    [2] ccflags-y adds compiler flags for all objects in the
    current Makefile

    [3] ccflags-remove-y removes compiler flags for all objects in the
    current Makefile (New feature)

    [4] CFLAGS_ adds compiler flags per file.

    [5] CFLAGS_REMOVE_ removes compiler flags per file.

    Having [3] before [4] allows us to remove flags from most (but not all)
    objects in the current Makefile.

    For example, kernel/trace/Makefile removes $(CC_FLAGS_FTRACE)
    from all objects in the directory, then adds it back to
    trace_selftest_dynamic.o and CFLAGS_trace_kprobe_selftest.o

    The same applies to lib/livepatch/Makefile.

    Please note ccflags-remove-y has no effect to the sub-directories.
    In contrast, the previous notation got rid of compiler flags also from
    all the sub-directories.

    The following are not affected because they have no sub-directories:

    arch/arm/boot/compressed/
    arch/powerpc/xmon/
    arch/sh/
    kernel/trace/

    However, lib/ has several sub-directories.

    To keep the behavior, I added ccflags-remove-y to all Makefiles
    in subdirectories of lib/, except the following:

    lib/vdso/Makefile - Kbuild does not descend into this Makefile
    lib/raid/test/Makefile - This is not used for the kernel build

    I think commit 2464a609ded0 ("ftrace: do not trace library functions")
    excluded too much. In the next commit, I will remove ccflags-remove-y
    from the sub-directories of lib/.

    Suggested-by: Sami Tolvanen
    Signed-off-by: Masahiro Yamada
    Acked-by: Steven Rostedt (VMware)
    Acked-by: Michael Ellerman (powerpc)
    Acked-by: Brendan Higgins (KUnit)
    Tested-by: Anders Roxell

    Masahiro Yamada
     

08 Jun, 2020

4 commits

  • In some cases, when an error occurs during testing and the main test
    routine returns, a memory leak occurs via leaving previously registered
    shadow variables allocated in the kernel as well as shadow_ptr list
    elements. From now on, in case of error, remove all allocated shadow
    variables and shadow_ptr struct elements.

    Signed-off-by: Yannick Cote
    Reviewed-by: Petr Mladek
    Reviewed-by: Kamalesh Babulal
    Acked-by: Miroslav Benes
    Acked-by: Joe Lawrence
    Signed-off-by: Petr Mladek
    Link: https://lore.kernel.org/r/20200603182058.109470-5-ycote@redhat.com

    Yannick Cote
     
  • This change makes the test feel more familiar with narrowing to a
    typical usage by operating on a number of identical structure instances
    and populating the same two new shadow variables symmetrically while
    keeping the same testing and verification criteria for the extra
    variables.

    Signed-off-by: Yannick Cote
    Reviewed-by: Kamalesh Babulal
    Reviewed-by: Petr Mladek
    Acked-by: Miroslav Benes
    Acked-by: Joe Lawrence
    Signed-off-by: Petr Mladek
    Link: https://lore.kernel.org/r/20200603182058.109470-4-ycote@redhat.com

    Yannick Cote
     
  • The initial idea was to make a change to please cppcheck and remove void
    pointer arithmetics found a few times:

    portability: 'obj' is of type 'void *'. When using void pointers
    in calculations, the behaviour is undefined.
    [arithOperationsOnVoidPointer]

    The rest of the changes are to help make the test read as an example
    while continuing to verify the shadow variable code. The logic of the
    test is unchanged but restructured to use descriptive names.

    Signed-off-by: Yannick Cote
    Reviewed-by: Petr Mladek
    Reviewed-by: Kamalesh Babulal
    Acked-by: Miroslav Benes
    Acked-by: Joe Lawrence
    Signed-off-by: Petr Mladek
    Link: https://lore.kernel.org/r/20200603182058.109470-3-ycote@redhat.com

    Yannick Cote
     
  • The test-klp-callbacks script includes a few tests which rely on kernel
    task timings that may not always execute as expected under system load.
    These may generate out of sequence kernel log messages that result in
    test failure.

    Instead of using sleep timing windows to orchestrate these tests, add a
    block_transition module parameter to communicate the test purpose and
    utilize flush_queue() to serialize the test module's task output.

    Signed-off-by: Joe Lawrence
    Reviewed-by: Petr Mladek
    Acked-by: Miroslav Benes
    Signed-off-by: Petr Mladek
    Link: https://lore.kernel.org/r/20200603182058.109470-2-ycote@redhat.com

    Joe Lawrence
     

17 Jan, 2020

2 commits

  • The commit e91c2518a5d22a ("livepatch: Initialize shadow variables
    safely by a custom callback") leads to the following static checker
    warning:

    samples/livepatch/livepatch-shadow-fix1.c:86 livepatch_fix1_dummy_alloc()
    error: 'klp_shadow_alloc()' 'leak' too small (4 vs 8)

    It is because klp_shadow_alloc() is used a wrong way:

    int *leak;
    shadow_leak = klp_shadow_alloc(d, SV_LEAK, sizeof(leak), GFP_KERNEL,
    shadow_leak_ctor, leak);

    The code is supposed to store the "leak" pointer into the shadow variable.
    3rd parameter correctly passes size of the data (size of pointer). But
    the 5th parameter is wrong. It should pass pointer to the data (pointer
    to the pointer) but it passes the pointer directly.

    It works because shadow_leak_ctor() handle "ctor_data" as the data
    instead of pointer to the data. But it is semantically wrong and
    confusing.

    The same problem is also in the module used by selftests. In this case,
    "pvX" variables are introduced. They represent the data stored in
    the shadow variables.

    Reported-by: Dan Carpenter
    Signed-off-by: Petr Mladek
    Reviewed-by: Joe Lawrence
    Acked-by: Miroslav Benes
    Reviewed-by: Kamalesh Babulal
    Signed-off-by: Jiri Kosina

    Petr Mladek
     
  • The shadow variable selftest is quite tricky. Especially it is problematic
    to understand what values are stored, returned, and printed.

    Make it easier to understand by using "int *var, **sv" variables
    consistently everywhere instead of the generic "void *", "ret",
    and "ctor_data".

    Signed-off-by: Petr Mladek
    Reviewed-by: Joe Lawrence
    Acked-by: Miroslav Benes
    Reviewed-by: Kamalesh Babulal
    Signed-off-by: Jiri Kosina

    Petr Mladek
     

01 Nov, 2019

1 commit


06 Feb, 2019

2 commits

  • Add proper error handling when allocating or getting shadow variables
    in the selftest. It prevents an invalid pointer access in some situations.
    It shows the good programming practice in the others.

    The error codes are just the best guess and specific for this particular
    test. In general, klp_shadow_alloc() returns NULL also when the given
    shadow variable has already been allocated. In addition, both
    klp_shadow_alloc() and klp_shadow_get_or_alloc() might fail from
    other reasons when the constructor fails.

    Note, that the error code is not really important even in the real life.
    The use of shadow variables should be transparent for the original
    livepatched code.

    Acked-by: Miroslav Benes
    Acked-by: Joe Lawrence
    Signed-off-by: Petr Mladek

    Petr Mladek
     
  • Fixes the following smatch warning:

    lib/livepatch/test_klp_shadow_vars.c:47 ptr_id() warn: returning -1 instead of -ENOMEM is sloppy

    Signed-off-by: Joe Lawrence
    Acked-by: Miroslav Benes
    Signed-off-by: Petr Mladek

    Joe Lawrence
     

12 Jan, 2019

1 commit

  • Add a few livepatch modules and simple target modules that the included
    regression suite can run tests against:

    - basic livepatching (multiple patches, atomic replace)
    - pre/post (un)patch callbacks
    - shadow variable API

    Signed-off-by: Joe Lawrence
    Signed-off-by: Petr Mladek
    Tested-by: Miroslav Benes
    Tested-by: Alice Ferrazzi
    Acked-by: Joe Lawrence
    Acked-by: Josh Poimboeuf
    Signed-off-by: Jiri Kosina

    Joe Lawrence