Skip to content
Snippets Groups Projects
  1. Oct 06, 2024
  2. Sep 29, 2024
  3. Sep 23, 2024
    • Masahiro Yamada's avatar
      kbuild: remove unnecessary export of RUST_LIB_SRC · fc1c79be
      Masahiro Yamada authored
      
      If RUST_LIB_SRC is defined in the top-level Makefile (via an environment
      variable or command line), it is already exported.
      
      The only situation where it is defined but not exported is when the
      top-level Makefile is wrapped by another Makefile (e.g., GNUmakefile).
      I cannot think of any other use cases.
      
      I know some people use this tip to define custom variables. However,
      even in that case, you can export it directly in the wrapper Makefile.
      
      Example GNUmakefile:
      
          export RUST_LIB_SRC = /path/to/your/sysroot/lib/rustlib/src/rust/library
          include Makefile
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
      fc1c79be
  4. Sep 20, 2024
    • Kris Van Hees's avatar
      kbuild: generate offset range data for builtin modules · 5f5e7344
      Kris Van Hees authored
      
      Create file module.builtin.ranges that can be used to find where
      built-in modules are located by their addresses. This will be useful for
      tracing tools to find what functions are for various built-in modules.
      
      The offset range data for builtin modules is generated using:
       - modules.builtin: associates object files with module names
       - vmlinux.map: provides load order of sections and offset of first member
          per section
       - vmlinux.o.map: provides offset of object file content per section
       - .*.cmd: build cmd file with KBUILD_MODFILE
      
      The generated data will look like:
      
      .text 00000000-00000000 = _text
      .text 0000baf0-0000cb10 amd_uncore
      .text 0009bd10-0009c8e0 iosf_mbi
      ...
      .text 00b9f080-00ba011a intel_skl_int3472_discrete
      .text 00ba0120-00ba03c0 intel_skl_int3472_discrete intel_skl_int3472_tps68470
      .text 00ba03c0-00ba08d6 intel_skl_int3472_tps68470
      ...
      .data 00000000-00000000 = _sdata
      .data 0000f020-0000f680 amd_uncore
      
      For each ELF section, it lists the offset of the first symbol.  This can
      be used to determine the base address of the section at runtime.
      
      Next, it lists (in strict ascending order) offset ranges in that section
      that cover the symbols of one or more builtin modules.  Multiple ranges
      can apply to a single module, and ranges can be shared between modules.
      
      The CONFIG_BUILTIN_MODULE_RANGES option controls whether offset range data
      is generated for kernel modules that are built into the kernel image.
      
      How it works:
      
       1. The modules.builtin file is parsed to obtain a list of built-in
          module names and their associated object names (the .ko file that
          the module would be in if it were a loadable module, hereafter
          referred to as <kmodfile>).  This object name can be used to
          identify objects in the kernel compile because any C or assembler
          code that ends up into a built-in module will have the option
          -DKBUILD_MODFILE=<kmodfile> present in its build command, and those
          can be found in the .<obj>.cmd file in the kernel build tree.
      
          If an object is part of multiple modules, they will all be listed
          in the KBUILD_MODFILE option argument.
      
          This allows us to conclusively determine whether an object in the
          kernel build belong to any modules, and which.
      
       2. The vmlinux.map is parsed next to determine the base address of each
          top level section so that all addresses into the section can be
          turned into offsets.  This makes it possible to handle sections
          getting loaded at different addresses at system boot.
      
          We also determine an 'anchor' symbol at the beginning of each
          section to make it possible to calculate the true base address of
          a section at runtime (i.e. symbol address - symbol offset).
      
          We collect start addresses of sections that are included in the top
          level section.  This is used when vmlinux is linked using vmlinux.o,
          because in that case, we need to look at the vmlinux.o linker map to
          know what object a symbol is found in.
      
          And finally, we process each symbol that is listed in vmlinux.map
          (or vmlinux.o.map) based on the following structure:
      
          vmlinux linked from vmlinux.a:
      
            vmlinux.map:
              <top level section>
                <included section>  -- might be same as top level section)
                  <object>          -- built-in association known
                    <symbol>        -- belongs to module(s) object belongs to
                    ...
      
          vmlinux linked from vmlinux.o:
      
            vmlinux.map:
              <top level section>
                <included section>  -- might be same as top level section)
                  vmlinux.o         -- need to use vmlinux.o.map
                    <symbol>        -- ignored
                    ...
      
            vmlinux.o.map:
              <section>
                  <object>          -- built-in association known
                    <symbol>        -- belongs to module(s) object belongs to
                    ...
      
       3. As sections, objects, and symbols are processed, offset ranges are
          constructed in a straight-forward way:
      
            - If the symbol belongs to one or more built-in modules:
                - If we were working on the same module(s), extend the range
                  to include this object
                - If we were working on another module(s), close that range,
                  and start the new one
            - If the symbol does not belong to any built-in modules:
                - If we were working on a module(s) range, close that range
      
      Signed-off-by: default avatarKris Van Hees <kris.van.hees@oracle.com>
      Reviewed-by: default avatarNick Alcock <nick.alcock@oracle.com>
      Reviewed-by: default avatarAlan Maguire <alan.maguire@oracle.com>
      Reviewed-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Tested-by: default avatarSam James <sam@gentoo.org>
      Reviewed-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Tested-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      5f5e7344
  5. Sep 16, 2024
  6. Sep 15, 2024
  7. Sep 12, 2024
    • Alice Ryhl's avatar
      cfi: add CONFIG_CFI_ICALL_NORMALIZE_INTEGERS · ce4a2620
      Alice Ryhl authored
      
      Introduce a Kconfig option for enabling the experimental option to
      normalize integer types. This ensures that integer types of the same
      size and signedness are considered compatible by the Control Flow
      Integrity sanitizer.
      
      The security impact of this flag is minimal. When Sami Tolvanen looked
      into it, he found that integer normalization reduced the number of
      unique type hashes in the kernel by ~1%, which is acceptable.
      
      This option exists for compatibility with Rust, as C and Rust do not
      have the same set of integer types. There are cases where C has two
      different integer types of the same size and signedness, but Rust only
      has one integer type of that size and signedness. When Rust calls into
      C functions using such types in their signature, this results in CFI
      failures. One example is 'unsigned long long' and 'unsigned long' which
      are both 64-bit on LP64 targets, so on those targets this flag will give
      both types the same CFI tag.
      
      This flag changes the ABI heavily. It is not applied automatically when
      CONFIG_RUST is turned on to make sure that the CONFIG_RUST option does
      not change the ABI of C code. For example, some build may need to make
      other changes atomically with toggling this flag. Having it be a
      separate option makes it possible to first turn on normalized integer
      tags, and then later turn on CONFIG_RUST.
      
      Similarly, when turning on CONFIG_RUST in a build, you may need a few
      attempts where the RUST=y commit gets reverted a few times. It is
      inconvenient if reverting RUST=y also requires reverting the changes you
      made to support normalized integer tags.
      
      To avoid having this flag impact builds that don't care about this, the
      next patch in this series will make CONFIG_RUST turn on this option
      using `select` rather than `depends on`.
      
      Signed-off-by: default avatarAlice Ryhl <aliceryhl@google.com>
      Reviewed-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Tested-by: default avatarGatlin Newhouse <gatlin.newhouse@gmail.com>
      Acked-by: default avatarKees Cook <kees@kernel.org>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240801-kcfi-v2-1-c93caed3d121@google.com
      
      
      Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      ce4a2620
    • Alice Ryhl's avatar
      rust: support for shadow call stack sanitizer · d077242d
      Alice Ryhl authored
      
      Add all of the flags that are needed to support the shadow call stack
      (SCS) sanitizer with Rust, and updates Kconfig to allow only
      configurations that work.
      
      The -Zfixed-x18 flag is required to use SCS on arm64, and requires rustc
      version 1.80.0 or greater. This restriction is reflected in Kconfig.
      
      When CONFIG_DYNAMIC_SCS is enabled, the build will be configured to
      include unwind tables in the build artifacts. Dynamic SCS uses the
      unwind tables at boot to find all places that need to be patched. The
      -Cforce-unwind-tables=y flag ensures that unwind tables are available
      for Rust code.
      
      In non-dynamic mode, the -Zsanitizer=shadow-call-stack flag is what
      enables the SCS sanitizer. Using this flag requires rustc version 1.82.0
      or greater on the targets used by Rust in the kernel. This restriction
      is reflected in Kconfig.
      
      It is possible to avoid the requirement of rustc 1.80.0 by using
      -Ctarget-feature=+reserve-x18 instead of -Zfixed-x18. However, this flag
      emits a warning during the build, so this patch does not add support for
      using it and instead requires 1.80.0 or greater.
      
      The dependency is placed on `select HAVE_RUST` to avoid a situation
      where enabling Rust silently turns off the sanitizer. Instead, turning
      on the sanitizer results in Rust being disabled. We generally do not
      want changes to CONFIG_RUST to result in any mitigations being changed
      or turned off.
      
      At the time of writing, rustc 1.82.0 only exists via the nightly release
      channel. There is a chance that the -Zsanitizer=shadow-call-stack flag
      will end up needing 1.83.0 instead, but I think it is small.
      
      Reviewed-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Reviewed-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Reviewed-by: default avatarKees Cook <kees@kernel.org>
      Acked-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarAlice Ryhl <aliceryhl@google.com>
      Link: https://lore.kernel.org/r/20240829-shadow-call-stack-v7-1-2f62a4432abf@google.com
      
      
      [ Fixed indentation using spaces. - Miguel ]
      Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      d077242d
  8. Sep 08, 2024
  9. Sep 05, 2024
  10. Sep 01, 2024
  11. Aug 27, 2024
    • Miguel Ojeda's avatar
      rust: allow `stable_features` lint · 8e95e53c
      Miguel Ojeda authored
      
      Support for several Rust compiler versions started in commit 63b27f4a
      ("rust: start supporting several compiler versions"). Since we currently
      need to use a number of unstable features in the kernel, it is a matter
      of time until one gets stabilized and the `stable_features` lint warns.
      
      For instance, the `new_uninit` feature may become stable soon, which
      would give us multiple warnings like the following:
      
          warning: the feature `new_uninit` has been stable since 1.82.0-dev
          and no longer requires an attribute to enable
            --> rust/kernel/lib.rs:17:12
             |
          17 | #![feature(new_uninit)]
             |            ^^^^^^^^^^
             |
             = note: `#[warn(stable_features)]` on by default
      
      Thus allow the `stable_features` lint to avoid such warnings. This is
      the simplest approach -- we do not have that many cases (and the goal
      is to stop using unstable features anyway) and cleanups can be easily
      done when we decide to update the minimum version.
      
      An alternative would be to conditionally enable them based on the
      compiler version (with the upcoming `RUSTC_VERSION` or maybe with the
      unstable `cfg(version(...))`, but that one apparently will not work for
      the nightly case). However, doing so is more complex and may not work
      well for different nightlies of the same version, unless we do not care
      about older nightlies.
      
      Another alternative is using explicit tests of the feature calling
      `rustc`, but that is also more complex and slower.
      
      Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
      Link: https://lore.kernel.org/r/20240827100403.376389-1-ojeda@kernel.org
      
      
      Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      8e95e53c
  12. Aug 25, 2024
  13. Aug 18, 2024
  14. Aug 11, 2024
  15. Aug 09, 2024
  16. Aug 06, 2024
  17. Aug 04, 2024
  18. Jul 28, 2024
  19. Jul 21, 2024
  20. Jul 20, 2024
  21. Jul 16, 2024
  22. Jul 14, 2024
  23. Jul 10, 2024
    • Arnd Bergmann's avatar
      kbuild: add syscall table generation to scripts/Makefile.asm-headers · fbb5c060
      Arnd Bergmann authored
      
      There are 11 copies of arch/*/kernel/syscalls/Makefile that all implement
      the same basic logic in a somewhat awkward way.
      
      I tried out various ways of unifying the existing copies and ended up
      with something that hooks into the logic for generating the redirections
      to asm-generic headers. This gives a nicer syntax of being able to list
      the generated files in $(syscall-y) inside of arch/*/include/asm/Kbuild
      instead of both $(generated-y) in that place and also in another
      Makefile.
      
      The configuration for which syscall.tbl file to use and which ABIs to
      enable is now done in arch/*/kernel/Makefile.syscalls. I have done
      patches for all architectures and made sure that the new generic
      rules implement a superset of all the architecture specific corner
      cases.
      
      ince the header file is not specific to asm-generic/*.h redirects
      now, I ended up renaming the file to scripts/Makefile.asm-headers.
      
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      fbb5c060
    • Miguel Ojeda's avatar
      rust: simplify Clippy warning flags set · bb421b51
      Miguel Ojeda authored
      
      All Clippy lint groups that we enable, except `correctness`, have a
      default `warn` level, thus they may be removed now that we relaxed all
      lints to `warn`.
      
      Moreover, Clippy provides an `all` lint group that covers the groups
      we enable by default. Thus just use `all` instead -- the only change is
      that, if Clippy introduces a new lint group or splits an existing one,
      we will cover that one automatically.
      
      In addition, `let_unit_value` is in `style` since Rust 1.62.0, thus it
      does not need to be enabled manually.
      
      Reviewed-by: default avatarFinn Behrens <me@kloenk.dev>
      Tested-by: default avatarBenno Lossin <benno.lossin@proton.me>
      Tested-by: default avatarAndreas Hindborg <a.hindborg@samsung.com>
      Link: https://lore.kernel.org/r/20240709160615.998336-6-ojeda@kernel.org
      
      
      Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      bb421b51
    • Miguel Ojeda's avatar
      rust: relax most deny-level lints to warnings · f8f88aa2
      Miguel Ojeda authored
      Since we are starting to support several Rust toolchains, lints (including
      Clippy ones) now may behave differently and lint groups may include
      new lints.
      
      Therefore, to maximize the chances a given version works, relax some
      deny-level lints to warnings. It may also make our lives a bit easier
      while developing new code or refactoring.
      
      To be clear, the requirements for in-tree code are still the same, since
      Rust code still needs to be warning-free (patches should be clean under
      `WERROR=y`) and the set of lints is not changed.
      
      `unsafe_op_in_unsafe_fn` is left unmodified, i.e. as an error, since it is
      becoming the default in the language (warn-by-default in Rust 2024 [1] and
      ideally an error later on) and thus it should also be very well tested. In
      addition, it is simple enough that it should not have false positives
      (unlike e.g. `rust_2018_idioms`'s `explicit_outlives_requirements`).
      
      `non_ascii_idents` is left unmodified as well, i.e. as an error, since
      it is unlikely one gains any productivity during development if it
      were a warning (in fact, it may be worse, since it is likely one made
      a typo). In addition, it should not have false positives.
      
      Finally, put the two `-D` ones at the top and take the chance to do one
      per line.
      
      Link: https://github.com/rust-lang/rust/pull/112038
      
       [1]
      Reviewed-by: default avatarFinn Behrens <me@kloenk.dev>
      Tested-by: default avatarBenno Lossin <benno.lossin@proton.me>
      Tested-by: default avatarAndreas Hindborg <a.hindborg@samsung.com>
      Link: https://lore.kernel.org/r/20240709160615.998336-5-ojeda@kernel.org
      
      
      Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      f8f88aa2
  24. Jul 08, 2024
  25. Jul 07, 2024
  26. Jun 30, 2024
  27. Jun 25, 2024
    • Tejun Heo's avatar
      sched_ext: Drop tools_clean target from the top-level Makefile · eb4a3b62
      Tejun Heo authored
      
      2a52ca7c ("sched_ext: Add scx_simple and scx_example_qmap example
      schedulers") added the tools_clean target which is triggered by mrproper.
      The tools_clean target triggers the sched_ext_clean target in tools/. This
      unfortunately makes mrproper fail when no BTF enabled kernel image is found:
      
        Makefile:83: *** Cannot find a vmlinux for VMLINUX_BTF at any of "  ../../vmlinux /sys/kernel/btf/vmlinux/boot/vmlinux-4.15.0-136-generic".  Stop.
        Makefile:192: recipe for target 'sched_ext_clean' failed
        make[2]: *** [sched_ext_clean] Error 2
        Makefile:1361: recipe for target 'sched_ext' failed
        make[1]: *** [sched_ext] Error 2
        Makefile:240: recipe for target '__sub-make' failed
        make: *** [__sub-make] Error 2
      
      Clean targets shouldn't fail like this but also it's really odd for mrproper
      to single out and trigger the sched_ext_clean target when no other clean
      targets under tools/ are triggered.
      
      Fix builds by dropping the tools_clean target from the top-level Makefile.
      The offending Makefile line is shared across BPF targets under tools/. Let's
      revisit them later.
      
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Reported-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Link: http://lkml.kernel.org/r/ac065f1f-8754-4626-95db-2c9fcf02567b@nvidia.com
      Fixes: 2a52ca7c ("sched_ext: Add scx_simple and scx_example_qmap example schedulers")
      Cc: David Vernet <void@manifault.com>
      eb4a3b62
  28. Jun 23, 2024
  29. Jun 18, 2024
    • Tejun Heo's avatar
      sched_ext: Add scx_simple and scx_example_qmap example schedulers · 2a52ca7c
      Tejun Heo authored
      
      Add two simple example BPF schedulers - simple and qmap.
      
      * simple: In terms of scheduling, it behaves identical to not having any
        operation implemented at all. The two operations it implements are only to
        improve visibility and exit handling. On certain homogeneous
        configurations, this actually can perform pretty well.
      
      * qmap: A fixed five level priority scheduler to demonstrate queueing PIDs
        on BPF maps for scheduling. While not very practical, this is useful as a
        simple example and will be used to demonstrate different features.
      
      v7: - Compat helpers stripped out in prepartion of upstreaming as the
            upstreamed patchset will be the baselinfe. Utility macros that can be
            used to implement compat features are kept.
      
          - Explicitly disable map autoattach on struct_ops to avoid trying to
            attach twice while maintaining compatbility with older libbpf.
      
      v6: - Common header files reorganized and cleaned up. Compat helpers are
            added to demonstrate how schedulers can maintain backward
            compatibility with older kernels while making use of newly added
            features.
      
          - simple_select_cpu() added to keep track of the number of local
            dispatches. This is needed because the default ops.select_cpu()
            implementation is updated to dispatch directly and won't call
            ops.enqueue().
      
          - Updated to reflect the sched_ext API changes. Switching all tasks is
            the default behavior now and scx_qmap supports partial switching when
            `-p` is specified.
      
          - tools/sched_ext/Kconfig dropped. This will be included in the doc
            instead.
      
      v5: - Improve Makefile. Build artifects are now collected into a separate
            dir which change be changed. Install and help targets are added and
            clean actually cleans everything.
      
          - MEMBER_VPTR() improved to improve access to structs. ARRAY_ELEM_PTR()
            and RESIZEABLE_ARRAY() are added to support resizable arrays in .bss.
      
          - Add scx_common.h which provides common utilities to user code such as
            SCX_BUG[_ON]() and RESIZE_ARRAY().
      
          - Use SCX_BUG[_ON]() to simplify error handling.
      
      v4: - Dropped _example prefix from scheduler names.
      
      v3: - Rename scx_example_dummy to scx_example_simple and restructure a bit
            to ease later additions. Comment updates.
      
          - Added declarations for BPF inline iterators. In the future, hopefully,
            these will be consolidated into a generic BPF header so that they
            don't need to be replicated here.
      
      v2: - Updated with the generic BPF cpumask helpers.
      
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Reviewed-by: default avatarDavid Vernet <dvernet@meta.com>
      Acked-by: default avatarJosh Don <joshdon@google.com>
      Acked-by: default avatarHao Luo <haoluo@google.com>
      Acked-by: default avatarBarret Rhoden <brho@google.com>
      2a52ca7c
  30. Jun 16, 2024
  31. Jun 09, 2024
  32. Jun 02, 2024
Loading