Skip to content
Snippets Groups Projects
  1. 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
  2. Sep 10, 2024
  3. Sep 05, 2024
  4. Aug 26, 2024
  5. Aug 23, 2024
  6. Aug 07, 2024
  7. Jul 31, 2024
  8. Jul 16, 2024
  9. Jul 10, 2024
    • Miguel Ojeda's avatar
      docs: rust: quick-start: add section on Linux distributions · b1263411
      Miguel Ojeda authored
      
      Now that we are starting to support several Rust compiler and `bindgen`
      versions, there is a good chance some Linux distributions work out of
      the box.
      
      Thus, provide some instructions on how to set the toolchain up for a
      few major Linux distributions. This simplifies the setup users need to
      build the kernel.
      
      In addition, add an introduction to the document so that it is easier
      to understand its structure and move the LLVM+Rust kernel.org toolchains
      paragraph there (removing "depending on the Linux version"). We may want
      to reorganize the document or split it in the future, but I wanted to
      focus this commit on the new information added about each particular
      distribution.
      
      Finally, remove the `rustup`'s components mention in `changes.rst` since
      users do not need it if they install the toolchain via the distributions
      (and anyway it was too detailed for that main document).
      
      Cc: Jan Alexander Steffens <heftig@archlinux.org>
      Cc: Johannes Löthberg <johannes@kyriasis.com>
      Cc: Fabian Grünbichler <debian@fabian.gruenbichler.email>
      Cc: Josh Stone <jistone@redhat.com>
      Cc: Randy Barlow <randy@electronsweatshop.com>
      Cc: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
      Cc: Matoro Mahri <matoro_gentoo@matoro.tk>
      Cc: Ryan Scheel <ryan.havvy@gmail.com>
      Cc: figsoda <figsoda@pm.me>
      Cc: Jörg Thalheim <joerg@thalheim.io>
      Cc: Theodore Ni <43ngvg@masqt.com>
      Cc: Winter <nixos@winter.cafe>
      Cc: William Brown <wbrown@suse.de>
      Cc: Xiaoguang Wang <xiaoguang.wang@suse.com>
      Cc: Andrea Righi <andrea.righi@canonical.com>
      Cc: Zixing Liu <zixing.liu@canonical.com>
      Cc: Nathan Chancellor <nathan@kernel.org>
      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-14-ojeda@kernel.org
      
      
      Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      b1263411
    • Miguel Ojeda's avatar
      rust: start supporting several compiler versions · 63b27f4a
      Miguel Ojeda authored
      It is time to start supporting several Rust compiler versions and thus
      establish a minimum Rust version.
      
      We may still want to upgrade the minimum sometimes in the beginning since
      there may be important features coming into the language that improve
      how we write code (e.g. field projections), which may or may not make
      sense to support conditionally.
      
      We will start with a window of two stable releases, and widen it over
      time. Thus this patch does not move the current minimum (1.78.0), but
      instead adds support for the recently released 1.79.0.
      
      This should already be enough for kernel developers in distributions that
      provide recent Rust compiler versions routinely, such as Arch Linux,
      Debian Unstable (outside the freeze period), Fedora Linux, Gentoo
      Linux (especially the testing channel), Nix (unstable) and openSUSE
      Tumbleweed. See the documentation patch about it later in this series.
      
      In addition, Rust for Linux is now being built-tested in Rust's pre-merge
      CI [1]. That is, every change that is attempting to land into the Rust
      compiler is tested against the kernel, and it is merged only if it passes
      -- thanks to the Rust project for that!
      
      Thus, with the pre-merge CI in place, both projects hope to avoid
      unintentional changes to Rust that break the kernel. This means that,
      in general, apart from intentional changes on their side (that we will
      need to workaround conditionally on our side), the upcoming Rust compiler
      versions should generally work.
      
      For instance, currently, the beta (1.80.0) and nightly (1.81.0) branches
      work as well.
      
      Of course, the Rust for Linux CI job in the Rust toolchain may still need
      to be temporarily disabled for different reasons, but the intention is
      to help bring Rust for Linux into stable Rust.
      
      Link: https://github.com/rust-lang/rust/pull/125209
      
       [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-7-ojeda@kernel.org
      
      
      Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      63b27f4a
  10. Jul 03, 2024
  11. Jun 26, 2024
  12. May 30, 2024
  13. May 28, 2024
  14. May 11, 2024
    • Barry Song's avatar
      Documentation: coding-style: ask function-like macros to evaluate parameters · 6813216b
      Barry Song authored
      Patch series "codingstyle: avoid unused parameters for a function-like
      macro", v7.
      
      A function-like macro could result in build warnings such as "unused
      variable." This patchset updates the guidance to recommend always using a
      static inline function instead and also provides checkpatch support for
      this new rule.
      
      
      This patch (of 2):
      
      Recent commit 77292bb8 ("crypto: scomp - remove memcpy if
      sg_nents is 1 and pages are lowmem") leads to warnings on xtensa
      and loongarch,
         In file included from crypto/scompress.c:12:
         include/crypto/scatterwalk.h: In function 'scatterwalk_pagedone':
         include/crypto/scatterwalk.h:76:30: warning: variable 'page' set but not used [-Wunused-but-set-variable]
            76 |                 struct page *page;
               |                              ^~~~
         crypto/scompress.c: In function 'scomp_acomp_comp_decomp':
      >> crypto/scompress.c:174:38: warning: unused variable 'dst_page' [-Wunused-variable]
           174 |                         struct page *dst_page = sg_page(req->dst);
               |
      
      The reason is that flush_dcache_page() is implemented as a noop
      macro on these platforms as below,
      
       #define flush_dcache_page(page) do { } while (0)
      
      The driver code, for itself, seems be quite innocent and placing
      maybe_unused seems pointless,
      
       struct page *dst_page = sg_page(req->dst);
      
       for (i = 0; i < nr_pages; i++)
       	flush_dcache_page(dst_page + i);
      
      And it should be independent of architectural implementation
      differences.
      
      Let's provide guidance on coding style for requesting parameter
      evaluation or proposing the migration to a static inline
      function.
      
      Link: https://lkml.kernel.org/r/20240507032757.146386-1-21cnbao@gmail.com
      Link: https://lkml.kernel.org/r/20240507032757.146386-2-21cnbao@gmail.com
      
      
      Signed-off-by: default avatarBarry Song <v-songbaohua@oppo.com>
      Suggested-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
      Reviewed-by: default avatarMark Brown <broonie@kernel.org>
      Acked-by: default avatarJoe Perches <joe@perches.com>
      Cc: Chris Zankel <chris@zankel.net>
      Cc: Huacai Chen <chenhuacai@loongson.cn>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Cc: Stephen Rothwell <sfr@canb.auug.org.au>
      Cc: Andy Whitcroft <apw@canonical.com>
      Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
      Cc: Xining Xu <mac.xxn@outlook.com>
      Cc: Charlemagne Lasse <charlemagnelasse@gmail.com>
      Cc: Jeff Johnson <quic_jjohnson@quicinc.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      6813216b
  15. May 05, 2024
  16. May 02, 2024
  17. Apr 12, 2024
    • Simon Glass's avatar
      arm64: boot: Support Flat Image Tree · 7a23b027
      Simon Glass authored
      
      Add a script which produces a Flat Image Tree (FIT), a single file
      containing the built kernel and associated devicetree files.
      Compression defaults to gzip which gives a good balance of size and
      performance.
      
      The files compress from about 86MB to 24MB using this approach.
      
      The FIT can be used by bootloaders which support it, such as U-Boot
      and Linuxboot. It permits automatic selection of the correct
      devicetree, matching the compatible string of the running board with
      the closest compatible string in the FIT. There is no need for
      filenames or other workarounds.
      
      Add a 'make image.fit' build target for arm64, as well.
      
      The FIT can be examined using 'dumpimage -l'.
      
      This uses the 'dtbs-list' file but processes only .dtb files, ignoring
      the overlay .dtbo files.
      
      This features requires pylibfdt (use 'pip install libfdt'). It also
      requires compression utilities for the algorithm being used. Supported
      compression options are the same as the Image.xxx files. Use
      FIT_COMPRESSION to select an algorithm other than gzip.
      
      While FIT supports a ramdisk / initrd, no attempt is made to support
      this here, since it must be built separately from the Linux build.
      
      Signed-off-by: default avatarSimon Glass <sjg@chromium.org>
      Acked-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Link: https://lore.kernel.org/r/20240329032836.141899-3-sjg@chromium.org
      
      
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      7a23b027
  18. Apr 11, 2024
  19. Apr 10, 2024
  20. Apr 02, 2024
  21. Mar 29, 2024
    • Miguel Ojeda's avatar
      rust: upgrade to Rust 1.77.1 · b481dd85
      Miguel Ojeda authored
      This is the next upgrade to the Rust toolchain, from 1.76.0 to 1.77.1
      (i.e. the latest) [1].
      
      See the upgrade policy [2] and the comments on the first upgrade in
      commit 3ed03f4d ("rust: upgrade to Rust 1.68.2").
      
      # Unstable features
      
      The `offset_of` feature (single-field `offset_of!`) that we were using
      got stabilized in Rust 1.77.0 [3].
      
      Therefore, now the only unstable features allowed to be used outside the
      `kernel` crate is `new_uninit`, though other code to be upstreamed may
      increase the list.
      
      Please see [4] for details.
      
      # Required changes
      
      Rust 1.77.0 merged the `unused_tuple_struct_fields` lint into `dead_code`,
      thus upgrading it from `allow` to `warn` [5]. In turn, this made `rustc`
      complain about the `ThisModule`'s pointer field being never read, but
      the previous patch adds the `as_ptr` method to it, needed by Binder [6],
      so that we do not need to locally `allow` it.
      
      # Other changes
      
      Rust 1.77.0 introduces the `--check-cfg` feature [7], for which there
      is a Call for Testing going on [8]. We were requested to test it and
      we found it useful [9] -- we will likely enable it in the future.
      
      # `alloc` upgrade and reviewing
      
      The vast majority of changes are due to our `alloc` fork being upgraded
      at once.
      
      There are two kinds of changes to be aware of: the ones coming from
      upstream, which we should follow as closely as possible, and the updates
      needed in our added fallible APIs to keep them matching the newer
      infallible APIs coming from upstream.
      
      Instead of taking a look at the diff of this patch, an alternative
      approach is reviewing a diff of the changes between upstream `alloc` and
      the kernel's. This allows to easily inspect the kernel additions only,
      especially to check if the fallible methods we already have still match
      the infallible ones in the new version coming from upstream.
      
      Another approach is reviewing the changes introduced in the additions in
      the kernel fork between the two versions. This is useful to spot
      potentially unintended changes to our additions.
      
      To apply these approaches, one may follow steps similar to the following
      to generate a pair of patches that show the differences between upstream
      Rust and the kernel (for the subset of `alloc` we use) before and after
      applying this patch:
      
          # Get the difference with respect to the old version.
          git -C rust checkout $(linux/scripts/min-tool-version.sh rustc)
          git -C linux ls-tree -r --name-only HEAD -- rust/alloc |
              cut -d/ -f3- |
              grep -Fv README.md |
              xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH
          git -C linux diff --patch-with-stat --summary -R > old.patch
          git -C linux restore rust/alloc
      
          # Apply this patch.
          git -C linux am rust-upgrade.patch
      
          # Get the difference with respect to the new version.
          git -C rust checkout $(linux/scripts/min-tool-version.sh rustc)
          git -C linux ls-tree -r --name-only HEAD -- rust/alloc |
              cut -d/ -f3- |
              grep -Fv README.md |
              xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH
          git -C linux diff --patch-with-stat --summary -R > new.patch
          git -C linux restore rust/alloc
      
      Now one may check the `new.patch` to take a look at the additions (first
      approach) or at the difference between those two patches (second
      approach). For the latter, a side-by-side tool is recommended.
      
      Link: https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1770-2024-03-21 [1]
      Link: https://rust-for-linux.com/rust-version-policy [2]
      Link: https://github.com/rust-lang/rust/pull/118799 [3]
      Link: https://github.com/Rust-for-Linux/linux/issues/2 [4]
      Link: https://github.com/rust-lang/rust/pull/118297 [5]
      Link: https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-2-08ba9197f637@google.com/#Z31rust:kernel:lib.rs [6]
      Link: https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html [7]
      Link: https://github.com/rust-lang/rfcs/pull/3013#issuecomment-1936648479 [8]
      Link: https://github.com/rust-lang/rust/issues/82450#issuecomment-1947462977
      
       [9]
      Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
      Tested-by: default avatarBoqun Feng <boqun.feng@gmail.com>
      Link: https://lore.kernel.org/r/20240217002717.57507-1-ojeda@kernel.org
      
      
      [ Upgraded to 1.77.1. Removed `allow(dead_code)` thanks to the previous
        patch. Reworded accordingly. No changes to `alloc` during the beta. ]
      Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      b481dd85
  22. Mar 18, 2024
Loading