Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Feb 01, 2023
    • Steven Rostedt (Google)'s avatar
      ftrace/scripts: Update the instructions for ftrace-bisect.sh · c42a6e68
      Steven Rostedt (Google) authored
      commit 7ae4ba71 upstream.
      
      The instructions for the ftrace-bisect.sh script, which is used to find
      what function is being traced that is causing a kernel crash, and possibly
      a triple fault reboot, uses the old method. In 5.1, a new feature was
      added that let the user write in the index into available_filter_functions
      that maps to the function a user wants to set in set_ftrace_filter (or
      set_ftrace_notrace). This takes O(1) to set, as suppose to writing a
      function name, which takes O(n) (where n is the number of functions in
      available_filter_functions).
      
      The ftrace-bisect.sh requires setting half of the functions in
      available_filter_functions, which is O(n^2) using the name method to enable
      and can take several minutes to complete. The number method is O(n) which
      takes less than a second to complete. Using the number method for any
      kernel 5.1 and after is the proper way to do the bisect.
      
      Update the usage to reflec...
      c42a6e68
  2. Dec 08, 2022
  3. Nov 25, 2022
    • Kees Cook's avatar
      stddef: Introduce struct_group() helper macro · 9fd7bdaf
      Kees Cook authored
      [ Upstream commit 50d7bd38
      
       ]
      
      Kernel code has a regular need to describe groups of members within a
      structure usually when they need to be copied or initialized separately
      from the rest of the surrounding structure. The generally accepted design
      pattern in C is to use a named sub-struct:
      
      	struct foo {
      		int one;
      		struct {
      			int two;
      			int three, four;
      		} thing;
      		int five;
      	};
      
      This would allow for traditional references and sizing:
      
      	memcpy(&dst.thing, &src.thing, sizeof(dst.thing));
      
      However, doing this would mean that referencing struct members enclosed
      by such named structs would always require including the sub-struct name
      in identifiers:
      
      	do_something(dst.thing.three);
      
      This has tended to be quite inflexible, especially when such groupings
      need to be added to established code which causes huge naming churn.
      Three workarounds exist in the kernel for this problem, and each have
      other negative properties.
      
      To avoid the naming churn, there is a design pattern of adding macro
      aliases for the named struct:
      
      	#define f_three thing.three
      
      This ends up polluting the global namespace, and makes it difficult to
      search for identifiers.
      
      Another common work-around in kernel code avoids the pollution by avoiding
      the named struct entirely, instead identifying the group's boundaries using
      either a pair of empty anonymous structs of a pair of zero-element arrays:
      
      	struct foo {
      		int one;
      		struct { } start;
      		int two;
      		int three, four;
      		struct { } finish;
      		int five;
      	};
      
      	struct foo {
      		int one;
      		int start[0];
      		int two;
      		int three, four;
      		int finish[0];
      		int five;
      	};
      
      This allows code to avoid needing to use a sub-struct named for member
      references within the surrounding structure, but loses the benefits of
      being able to actually use such a struct, making it rather fragile. Using
      these requires open-coded calculation of sizes and offsets. The efforts
      made to avoid common mistakes include lots of comments, or adding various
      BUILD_BUG_ON()s. Such code is left with no way for the compiler to reason
      about the boundaries (e.g. the "start" object looks like it's 0 bytes
      in length), making bounds checking depend on open-coded calculations:
      
      	if (length > offsetof(struct foo, finish) -
      		     offsetof(struct foo, start))
      		return -EINVAL;
      	memcpy(&dst.start, &src.start, offsetof(struct foo, finish) -
      				       offsetof(struct foo, start));
      
      However, the vast majority of places in the kernel that operate on
      groups of members do so without any identification of the grouping,
      relying either on comments or implicit knowledge of the struct contents,
      which is even harder for the compiler to reason about, and results in
      even more fragile manual sizing, usually depending on member locations
      outside of the region (e.g. to copy "two" and "three", use the start of
      "four" to find the size):
      
      	BUILD_BUG_ON((offsetof(struct foo, four) <
      		      offsetof(struct foo, two)) ||
      		     (offsetof(struct foo, four) <
      		      offsetof(struct foo, three));
      	if (length > offsetof(struct foo, four) -
      		     offsetof(struct foo, two))
      		return -EINVAL;
      	memcpy(&dst.two, &src.two, length);
      
      In order to have a regular programmatic way to describe a struct
      region that can be used for references and sizing, can be examined for
      bounds checking, avoids forcing the use of intermediate identifiers,
      and avoids polluting the global namespace, introduce the struct_group()
      macro. This macro wraps the member declarations to create an anonymous
      union of an anonymous struct (no intermediate name) and a named struct
      (for references and sizing):
      
      	struct foo {
      		int one;
      		struct_group(thing,
      			int two;
      			int three, four;
      		);
      		int five;
      	};
      
      	if (length > sizeof(src.thing))
      		return -EINVAL;
      	memcpy(&dst.thing, &src.thing, length);
      	do_something(dst.three);
      
      There are some rare cases where the resulting struct_group() needs
      attributes added, so struct_group_attr() is also introduced to allow
      for specifying struct attributes (e.g. __align(x) or __packed).
      Additionally, there are places where such declarations would like to
      have the struct be tagged, so struct_group_tagged() is added.
      
      Given there is a need for a handful of UAPI uses too, the underlying
      __struct_group() macro has been defined in UAPI so it can be used there
      too.
      
      To avoid confusing scripts/kernel-doc, hide the macro from its struct
      parsing.
      
      Co-developed-by: default avatarKeith Packard <keithp@keithp.com>
      Signed-off-by: default avatarKeith Packard <keithp@keithp.com>
      Acked-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Link: https://lore.kernel.org/lkml/20210728023217.GC35706@embeddedor
      
      
      Enhanced-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Link: https://lore.kernel.org/lkml/41183a98-bdb9-4ad6-7eab-5a7292a6df84@rasmusvillemoes.dk
      
      
      Enhanced-by: default avatarDan Williams <dan.j.williams@intel.com>
      Link: https://lore.kernel.org/lkml/1d9a2e6df2a9a35b2cdd50a9a68cac5991e7e5f0.camel@intel.com
      
      
      Enhanced-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://lore.kernel.org/lkml/YQKa76A6XuFqgM03@phenom.ffwll.local
      
      
      Acked-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Stable-dep-of: 58e0be1e
      
       ("net: use struct_group to copy ip/ipv6 header addresses")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9fd7bdaf
  4. Nov 16, 2022
  5. Oct 28, 2022
  6. Oct 26, 2022
    • Janis Schoetterl-Glausch's avatar
      kbuild: rpm-pkg: fix breakage when V=1 is used · cdd42eb4
      Janis Schoetterl-Glausch authored
      [ Upstream commit 2e07005f ]
      
      Doing make V=1 binrpm-pkg results in:
      
       Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.EgV6qJ
       + umask 022
       + cd .
       + /bin/rm -rf /home/scgl/rpmbuild/BUILDROOT/kernel-6.0.0_rc5+-1.s390x
       + /bin/mkdir -p /home/scgl/rpmbuild/BUILDROOT
       + /bin/mkdir /home/scgl/rpmbuild/BUILDROOT/kernel-6.0.0_rc5+-1.s390x
       + mkdir -p /home/scgl/rpmbuild/BUILDROOT/kernel-6.0.0_rc5+-1.s390x/boot
       + make -f ./Makefile image_name
       + cp test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \ echo >&2; \ echo >&2 " ERROR: Kernel configuration is invalid."; \ echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\ echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \ echo >&2 ; \ /bin/false) arch/s390/boot/bzImage /home/scgl/rpmbuild/BUILDROOT/kernel-6.0.0_rc5+-1.s390x/boot/vmlinuz-6.0.0-rc5+
       cp: invalid option -- 'e'
       Try 'cp --help' for more informatio...
      cdd42eb4
    • Masahiro Yamada's avatar
      kbuild: remove the target in signal traps when interrupted · 6d1aef17
      Masahiro Yamada authored
      [ Upstream commit a7f3257d ]
      
      When receiving some signal, GNU Make automatically deletes the target if
      it has already been changed by the interrupted recipe.
      
      If the target is possibly incomplete due to interruption, it must be
      deleted so that it will be remade from scratch on the next run of make.
      Otherwise, the target would remain corrupted permanently because its
      timestamp had already been updated.
      
      Thanks to this behavior of Make, you can stop the build any time by
      pressing Ctrl-C, and just run 'make' to resume it.
      
      Kbuild also relies on this feature, but it is equivalently important
      for any build systems that make decisions based on timestamps (if you
      want to support Ctrl-C reliably).
      
      However, this does not always work as claimed; Make immediately dies
      with Ctrl-C if its stderr goes into a pipe.
      
        [Test Makefile]
      
          foo:
                  echo hello > $@
                  sleep 3
                  echo world >> $@
      
        [Test Result]
      
          $ make                         # hit Ctrl-C
          echo hello > foo
          sleep 3
          ^Cmake: *** Deleting file 'foo'
          make: *** [Makefile:3: foo] Interrupt
      
          $ make 2>&1 | cat              # hit Ctrl-C
          echo hello > foo
          sleep 3
          ^C$                            # 'foo' is often left-over
      
      The reason is because SIGINT is sent to the entire process group.
      In this example, SIGINT kills 'cat', and 'make' writes the message to
      the closed pipe, then dies with SIGPIPE before cleaning the target.
      
      A typical bad scenario (as reported by [1], [2]) is to save build log
      by using the 'tee' command:
      
          $ make 2>&1 | tee log
      
      This can be problematic for any build systems based on Make, so I hope
      it will be fixed in GNU Make. The maintainer of GNU Make stated this is
      a long-standing issue and difficult to fix [3]. It has not been fixed
      yet as of writing.
      
      So, we cannot rely on Make cleaning the target. We can do it by
      ourselves, in signal traps.
      
      As far as I understand, Make takes care of SIGHUP, SIGINT, SIGQUIT, and
      SITERM for the target removal. I added the traps for them, and also for
      SIGPIPE just in case cmd_* rule prints something to stdout or stderr
      (but I did not observe an actual case where SIGPIPE was triggered).
      
      [Note 1]
      
      The trap handler might be worth explaining.
      
          rm -f $@; trap - $(sig); kill -s $(sig) $$
      
      This lets the shell kill itself by the signal it caught, so the parent
      process can tell the child has exited on the signal. Generally, this is
      a proper manner for handling signals, in case the calling program (like
      Bash) may monitor WIFSIGNALED() and WTERMSIG() for WCE although this may
      not be a big deal here because GNU Make handles SIGHUP, SIGINT, SIGQUIT
      in WUE and SIGTERM in IUE.
      
        IUE - Immediate Unconditional Exit
        WUE - Wait and Unconditional Exit
        WCE - Wait and Cooperative Exit
      
      For details, see "Proper handling of SIGINT/SIGQUIT" [4].
      
      [Note 2]
      
      Reverting 392885ee ("kbuild: let fixdep directly write to .*.cmd
      files") would directly address [1], but it only saves if_changed_dep.
      As reported in [2], all commands that use redirection can potentially
      leave an empty (i.e. broken) target.
      
      [Note 3]
      
      Another (even safer) approach might be to always write to a temporary
      file, and rename it to $@ at the end of the recipe.
      
         <command>  > $(tmp-target)
         mv $(tmp-target) $@
      
      It would require a lot of Makefile changes, and result in ugly code,
      so I did not take it.
      
      [Note 4]
      
      A little more thoughts about a pattern rule with multiple targets (or
      a grouped target).
      
          %.x %.y: %.z
                  <recipe>
      
      When interrupted, GNU Make deletes both %.x and %.y, while this solution
      only deletes $@. Probably, this is not a big deal. The next run of make
      will execute the rule again to create $@ along with the other files.
      
      [1]: https://lore.kernel.org/all/YLeot94yAaM4xbMY@gmail.com/
      [2]: https://lore.kernel.org/all/20220510221333.2770571-1-robh@kernel.org/
      [3]: https://lists.gnu.org/archive/html/help-make/2021-06/msg00001.html
      [4]: https://www.cons.org/cracauer/sigint.html
      
      Fixes: 392885ee
      
       ("kbuild: let fixdep directly write to .*.cmd files")
      Reported-by: default avatarIngo Molnar <mingo@kernel.org>
      Reported-by: default avatarRob Herring <robh@kernel.org>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: default avatarIngo Molnar <mingo@kernel.org>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6d1aef17
    • Greg Kroah-Hartman's avatar
      selinux: use "grep -E" instead of "egrep" · 28d9b397
      Greg Kroah-Hartman authored
      commit c969bb8d
      
       upstream.
      
      The latest version of grep claims that egrep is now obsolete so the build
      now contains warnings that look like:
      	egrep: warning: egrep is obsolescent; using grep -E
      fix this by using "grep -E" instead.
      
      Cc: Paul Moore <paul@paul-moore.com>
      Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
      Cc: Eric Paris <eparis@parisplace.org>
      Cc: selinux@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      [PM: tweak to remove vdso reference, cleanup subj line]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      28d9b397
  7. Oct 15, 2022
  8. Sep 23, 2022
  9. Sep 05, 2022
  10. Aug 29, 2022
  11. Aug 25, 2022
    • Helge Deller's avatar
      modules: Ensure natural alignment for .altinstructions and __bug_table sections · 333bdb72
      Helge Deller authored
      [ Upstream commit 87c482bd
      
       ]
      
      In the kernel image vmlinux.lds.S linker scripts the .altinstructions
      and __bug_table sections are 4- or 8-byte aligned because they hold 32-
      and/or 64-bit values.
      
      Most architectures use altinstructions and BUG() or WARN() in modules as
      well, but in the module linker script (module.lds.S) those sections are
      currently missing. As consequence the linker will store their content
      byte-aligned by default, which then can lead to unnecessary unaligned
      memory accesses by the CPU when those tables are processed at runtime.
      
      Usually unaligned memory accesses are unnoticed, because either the
      hardware (as on x86 CPUs) or in-kernel exception handlers (e.g. on
      parisc or sparc) emulate and fix them up at runtime. Nevertheless, such
      unaligned accesses introduce a performance penalty and can even crash
      the kernel if there is a bug in the unalignment exception handlers
      (which happened once to me on the parisc architecture and which is why I
      noticed that issue at all).
      
      This patch fixes a non-critical issue and might be backported at any time.
      It's trivial and shouldn't introduce any regression because it simply
      tells the linker to use a different (8-byte alignment) for those
      sections by default.
      
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Link: https://lore.kernel.org/all/Yr8%2Fgr8e8I7tVX4d@p100/
      
      
      Signed-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      333bdb72
    • Andrew Donnellan's avatar
      gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file · 0bd35968
      Andrew Donnellan authored
      commit 012e8d20 upstream.
      
      Commit 36d4b36b ("lib/nodemask: inline next_node_in() and
      node_random()") refactored some code by moving node_random() from
      lib/nodemask.c to include/linux/nodemask.h, thus requiring nodemask.h to
      include random.h, which conditionally defines add_latent_entropy()
      depending on whether the macro LATENT_ENTROPY_PLUGIN is defined.
      
      This broke the build on powerpc, where nodemask.h is indirectly included
      in arch/powerpc/kernel/prom_init.c, part of the early boot machinery that
      is excluded from the latent entropy plugin using
      DISABLE_LATENT_ENTROPY_PLUGIN. It turns out that while we add a gcc flag
      to disable the actual plugin, we don't undefine LATENT_ENTROPY_PLUGIN.
      
      This leads to the following:
      
          CC      arch/powerpc/kernel/prom_init.o
        In file included from ./include/linux/nodemask.h:97,
                         from ./include/linux/mmzone.h:17,
                         from ./in...
      0bd35968
    • Ondrej Mosnacek's avatar
      kbuild: dummy-tools: avoid tmpdir leak in dummy gcc · 7ef0645e
      Ondrej Mosnacek authored
      commit aac28965 upstream.
      
      When passed -print-file-name=plugin, the dummy gcc script creates a
      temporary directory that is never cleaned up. To avoid cluttering
      $TMPDIR, instead use a static directory included in the source tree.
      
      Fixes: 76426e23
      
       ("kbuild: add dummy toolchains to enable all cc-option etc. in Kconfig")
      Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7ef0645e
  12. Aug 21, 2022
  13. Jul 25, 2022
  14. Jun 29, 2022
  15. Jun 22, 2022
  16. Jun 14, 2022
  17. Jun 09, 2022
  18. Apr 20, 2022
    • Jason A. Donenfeld's avatar
      gcc-plugins: latent_entropy: use /dev/urandom · cc21ae93
      Jason A. Donenfeld authored
      commit c40160f2 upstream.
      
      While the latent entropy plugin mostly doesn't derive entropy from
      get_random_const() for measuring the call graph, when __latent_entropy is
      applied to a constant, then it's initialized statically to output from
      get_random_const(). In that case, this data is derived from a 64-bit
      seed, which means a buffer of 512 bits doesn't really have that amount
      of compile-time entropy.
      
      This patch fixes that shortcoming by just buffering chunks of
      /dev/urandom output and doling it out as requested.
      
      At the same time, it's important that we don't break the use of
      -frandom-seed, for people who want the runtime benefits of the latent
      entropy plugin, while still having compile-time determinism. In that
      case, we detect whether gcc's set_random_seed() has been called by
      making a call to get_random_seed(noinit=true) in the plugin init
      function, which is called after set_random_seed() is called but before
      anything that ca...
      cc21ae93
  19. Apr 13, 2022
  20. Apr 08, 2022
  21. Feb 23, 2022
  22. Feb 16, 2022
  23. Jan 29, 2022
  24. Jan 27, 2022