Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Aug 09, 2024
    • Miguel Ojeda's avatar
      rust: add intrinsics to fix `-Os` builds · 02dfd63a
      Miguel Ojeda authored
      Alice reported [1] that an arm64 build failed with:
      
          ld.lld: error: undefined symbol: __extendsfdf2
          >>> referenced by core.a6f5fc5794e7b7b3-cgu.0
          >>>               rust/core.o:(<f32>::midpoint) in archive vmlinux.a
          >>> referenced by core.a6f5fc5794e7b7b3-cgu.0
          >>>               rust/core.o:(<f32>::midpoint) in archive vmlinux.a
      
          ld.lld: error: undefined symbol: __truncdfsf2
          >>> referenced by core.a6f5fc5794e7b7b3-cgu.0
          >>>               rust/core.o:(<f32>::midpoint) in archive vmlinux.a
      
      Rust 1.80.0 or later together with `CONFIG_CC_OPTIMIZE_FOR_SIZE=y`
      is what triggers it.
      
      In addition, x86_64 builds also fail the same way.
      
      Similarly, compiling with Rust 1.82.0 (currently in nightly) makes
      another one appear, possibly due to the LLVM 19 upgrade there:
      
          ld.lld: error: undefined symbol: __eqdf2
          >>> referenced by core.20495ea57a9f069d-cgu.0
          >>>               rust/core.o:(<f64>::next_up) in archive vmlinux.a
          >>> referen...
      02dfd63a
    • Zehui Xu's avatar
      kbuild: rust: skip -fmin-function-alignment in bindgen flags · 869b5016
      Zehui Xu authored
      GCC 14 recently added -fmin-function-alignment option and the
      root Makefile uses it to replace -falign-functions when available.
      However, this flag can cause issues when passed to the Rust
      Makefile and affect the bindgen process. Bindgen relies on
      libclang to parse C code, and currently does not support the
      -fmin-function-alignment flag, leading to compilation failures
      when GCC 14 is used.
      
      This patch addresses the issue by adding -fmin-function-alignment
      to the bindgen_skip_c_flags in rust/Makefile. This prevents the
      flag from causing compilation issues.
      
      [ Matthew and Gary confirm function alignment should not change
        the ABI in a way that bindgen would care about, thus we did
        not need the extra logic for bindgen from v2. - Miguel ]
      
      Link: https://lore.kernel.org/linux-kbuild/20240222133500.16991-1-petr.pavlu@suse.com/
      
      
      Signed-off-by: default avatarZehui Xu <zehuixu@whu.edu.cn>
      Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
      Reviewed-by: default avatarNeal Gompa <neal@gompa.dev>
      Reviewed-by: default avatarGary Guo <gary@garyguo.net>
      Link: https://lore.kernel.org/r/20240731134346.10630-1-zehuixu@whu.edu.cn
      
      
      [ Reworded title. - Miguel ]
      Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      869b5016
  2. Aug 06, 2024
  3. Jul 31, 2024
  4. Jul 29, 2024
  5. Jul 10, 2024
  6. Jul 08, 2024
  7. Jul 03, 2024
    • Vlastimil Babka's avatar
      slab, rust: extend kmalloc() alignment guarantees to remove Rust padding · ad59baa3
      Vlastimil Babka authored
      Slab allocators have been guaranteeing natural alignment for
      power-of-two sizes since commit 59bb4798
      
       ("mm, sl[aou]b: guarantee
      natural alignment for kmalloc(power-of-two)"), while any other sizes are
      guaranteed to be aligned only to ARCH_KMALLOC_MINALIGN bytes (although
      in practice are aligned more than that in non-debug scenarios).
      
      Rust's allocator API specifies size and alignment per allocation, which
      have to satisfy the following rules, per Alice Ryhl [1]:
      
        1. The alignment is a power of two.
        2. The size is non-zero.
        3. When you round up the size to the next multiple of the alignment,
           then it must not overflow the signed type isize / ssize_t.
      
      In order to map this to kmalloc()'s guarantees, some requested
      allocation sizes have to be padded to the next power-of-two size [2].
      For example, an allocation of size 96 and alignment of 32 will be padded
      to an allocation of size 128, because the existing kmalloc-96 bucket
      doesn't guarantee alignent above ARCH_KMALLOC_MINALIGN. Without slab
      debugging active, the layout of the kmalloc-96 slabs however naturally
      align the objects to 32 bytes, so extending the size to 128 bytes is
      wasteful.
      
      To improve the situation we can extend the kmalloc() alignment
      guarantees in a way that
      
      1) doesn't change the current slab layout (and thus does not increase
         internal fragmentation) when slab debugging is not active
      2) reduces waste in the Rust allocator use case
      3) is a superset of the current guarantee for power-of-two sizes.
      
      The extended guarantee is that alignment is at least the largest
      power-of-two divisor of the requested size. For power-of-two sizes the
      largest divisor is the size itself, but let's keep this case documented
      separately for clarity.
      
      For current kmalloc size buckets, it means kmalloc-96 will guarantee
      alignment of 32 bytes and kmalloc-196 will guarantee 64 bytes.
      
      This covers the rules 1 and 2 above of Rust's API as long as the size is
      a multiple of the alignment. The Rust layer should now only need to
      round up the size to the next multiple if it isn't, while enforcing the
      rule 3.
      
      Implementation-wise, this changes the alignment calculation in
      create_boot_cache(). While at it also do the calulation only for caches
      with the SLAB_KMALLOC flag, because the function is also used to create
      the initial kmem_cache and kmem_cache_node caches, where no alignment
      guarantee is necessary.
      
      In the Rust allocator's krealloc_aligned(), remove the code that padded
      sizes to the next power of two (suggested by Alice Ryhl) as it's no
      longer necessary with the new guarantees.
      
      Reported-by: default avatarAlice Ryhl <aliceryhl@google.com>
      Reported-by: default avatarBoqun Feng <boqun.feng@gmail.com>
      Link: https://lore.kernel.org/all/CAH5fLggjrbdUuT-H-5vbQfMazjRDpp2%2Bk3%3DYhPyS17ezEqxwcw@mail.gmail.com/ [1]
      Link: https://lore.kernel.org/all/CAH5fLghsZRemYUwVvhk77o6y1foqnCeDzW4WZv6ScEWna2+_jw@mail.gmail.com/
      
       [2]
      Reviewed-by: default avatarBoqun Feng <boqun.feng@gmail.com>
      Acked-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
      Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
      Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
      ad59baa3
    • David Gow's avatar
      arch: um: rust: Add i386 support for Rust · ab0f4ced
      David Gow authored
      At present, Rust in the kernel only supports 64-bit x86, so UML has
      followed suit. However, it's significantly easier to support 32-bit i386
      on UML than on bare metal, as UML does not use the -mregparm option
      (which alters the ABI), which is not yet supported by rustc[1].
      
      Add support for CONFIG_RUST on um/i386, by adding a new target config to
      generate_rust_target, and replacing various checks on CONFIG_X86_64 to
      also support CONFIG_X86_32.
      
      We still use generate_rust_target, rather than a built-in rustc target,
      in order to match x86_64, provide a future place for -mregparm, and more
      easily disable floating point instructions.
      
      With these changes, the KUnit tests pass with:
      kunit.py run --make_options LLVM=1 --kconfig_add CONFIG_RUST=y
      --kconfig_add CONFIG_64BIT=n --kconfig_add CONFIG_FORTIFY_SOURCE=n
      
      An earlier version of these changes was proposed on the Rust-for-Linux
      github[2].
      
      [1]: https://github.com/rust-lang/rust/issues/116972
      [2]: https://github.com/Rust-for-Linux/linux/pull/966
      
      
      
      Signed-off-by: default avatarDavid Gow <davidgow@google.com>
      Link: https://patch.msgid.link/20240604224052.3138504-1-davidgow@google.com
      
      
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      ab0f4ced
  8. Jun 28, 2024
  9. Jun 20, 2024
  10. Jun 18, 2024
  11. Jun 14, 2024
  12. Jun 11, 2024
  13. May 14, 2024
  14. May 09, 2024
    • Masahiro Yamada's avatar
      kbuild: use $(src) instead of $(srctree)/$(src) for source directory · b1992c37
      Masahiro Yamada authored
      Kbuild conventionally uses $(obj)/ for generated files, and $(src)/ for
      checked-in source files. It is merely a convention without any functional
      difference. In fact, $(obj) and $(src) are exactly the same, as defined
      in scripts/Makefile.build:
      
          src := $(obj)
      
      When the kernel is built in a separate output directory, $(src) does
      not accurately reflect the source directory location. While Kbuild
      resolves this discrepancy by specifying VPATH=$(srctree) to search for
      source files, it does not cover all cases. For example, when adding a
      header search path for local headers, -I$(srctree)/$(src) is typically
      passed to the compiler.
      
      This introduces inconsistency between upstream and downstream Makefiles
      because $(src) is used instead of $(srctree)/$(src) for the latter.
      
      To address this inconsistency, this commit changes the semantics of
      $(src) so that it always points to the directory in the source tree.
      
      Going forward, the variables used ...
      b1992c37
  15. May 07, 2024
  16. May 05, 2024