@@ -1885,7 +1885,6 @@ config RUST
bool "Rust support"
depends on HAVE_RUST
depends on RUST_IS_AVAILABLE
- depends on !MODVERSIONS
depends on !GCC_PLUGINS
depends on !RANDSTRUCT
depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
@@ -1896,13 +1895,27 @@ config RUST
This allows other Rust-related options, like drivers written in Rust,
to be selected.
- It is also required to be able to load external kernel modules
- written in Rust.
-
See Documentation/rust/ for more information.
If unsure, say N.
+config RUST_MODULES
+ bool "Rust Module Support"
+ depends on RUST
+ depends on MODULES
+ rust_modules
+ help
+ Enables support for Rust Modules in the kernel.
+
+ This is required to load external kernel modules written in Rust.
+
+ The two primary reasons to consider disabling this are:
+ * Allow MODVERSIONS support
+ * Allow additional code to be optimized out by the compiler if you
+ know that you'll only be using built-in Rust code.
+
+ If unsure, say Y.
+
config RUSTC_VERSION_TEXT
string
depends on RUST
@@ -158,6 +158,7 @@ config MODULE_UNLOAD_TAINT_TRACKING
shown. If unsure, say N.
config MODVERSIONS
+ depends on !RUST_MODULES
bool "Module versioning support"
help
Usually, you have to use modules compiled with your kernel.
@@ -13,7 +13,11 @@
#include <linux/module.h>
+#ifdef CONFIG_RUST_MODULES
#define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym)
+#else
+#define EXPORT_SYMBOL_RUST_GPL(sym)
+#endif
#include "exports_core_generated.h"
#include "exports_alloc_generated.h"
Currently, we don't support MODVERSIONS for Rust symbols. For users that want to use Rust in the kernel but for whom MODVERSIONS is required, this allows the use of built-in Rust code even with MODVERSIONS enabled. It may additionally allow code-size reduction by avoiding exporting symbols that won't be used without Rust modules. Signed-off-by: Matthew Maurer <mmaurer@google.com> --- init/Kconfig | 21 +++++++++++++++++---- kernel/module/Kconfig | 1 + rust/exports.c | 4 ++++ 3 files changed, 22 insertions(+), 4 deletions(-)