diff --git a/rust/Makefile b/rust/Makefile index 99204e33f1dd32f0f1a04fbc8af9286f32553b74..7ea5905f544ce09d64477287ddbdf33ff951131e 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -16,8 +16,8 @@ no-clean-files += libmacros.so always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs obj-$(CONFIG_RUST) += alloc.o bindings.o kernel.o -always-$(CONFIG_RUST) += exports_alloc_generated.h exports_bindings_generated.h \ - exports_kernel_generated.h +always-$(CONFIG_RUST) += exports_alloc_generated.h exports_helpers_generated.h \ + exports_bindings_generated.h exports_kernel_generated.h always-$(CONFIG_RUST) += uapi/uapi_generated.rs obj-$(CONFIG_RUST) += uapi.o @@ -313,6 +313,18 @@ $(obj)/exports_core_generated.h: $(obj)/core.o FORCE $(obj)/exports_alloc_generated.h: $(obj)/alloc.o FORCE $(call if_changed,exports) +# Even though Rust kernel modules should never use the bindings directly, +# symbols from the `bindings` crate and the C helpers need to be exported +# because Rust generics and inlined functions may not get their code generated +# in the crate where they are defined. Other helpers, called from non-inline +# functions, may not be exported, in principle. However, in general, the Rust +# compiler does not guarantee codegen will be performed for a non-inline +# function either. Therefore, we export all symbols from helpers and bindings. +# In the future, this may be revisited to reduce the number of exports after +# the compiler is informed about the places codegen is required. +$(obj)/exports_helpers_generated.h: $(obj)/helpers/helpers.o FORCE + $(call if_changed,exports) + $(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE $(call if_changed,exports) diff --git a/rust/exports.c b/rust/exports.c index 3803c21d1403efb8de8ddc4ed63f1298269e3f0c..e5695f3b45b7aa3bd2902c7ae07a9c6176aaa37c 100644 --- a/rust/exports.c +++ b/rust/exports.c @@ -17,6 +17,7 @@ #include "exports_core_generated.h" #include "exports_alloc_generated.h" +#include "exports_helpers_generated.h" #include "exports_bindings_generated.h" #include "exports_kernel_generated.h" diff --git a/rust/helpers/blk.c b/rust/helpers/blk.c index d99c965eb59bf65d9d770778e5a1d294f390d509..cc9f4e6a2d2346eb2814104cce706755ba135e06 100644 --- a/rust/helpers/blk.c +++ b/rust/helpers/blk.c @@ -7,10 +7,8 @@ void *rust_helper_blk_mq_rq_to_pdu(struct request *rq) { return blk_mq_rq_to_pdu(rq); } -EXPORT_SYMBOL_GPL(rust_helper_blk_mq_rq_to_pdu); struct request *rust_helper_blk_mq_rq_from_pdu(void *pdu) { return blk_mq_rq_from_pdu(pdu); } -EXPORT_SYMBOL_GPL(rust_helper_blk_mq_rq_from_pdu); diff --git a/rust/helpers/bug.c b/rust/helpers/bug.c index e2afbad23dcda815d6c9389131461745d30d2dd2..e2d13babc7371051d5ce805d2716e115af8759a7 100644 --- a/rust/helpers/bug.c +++ b/rust/helpers/bug.c @@ -6,4 +6,3 @@ __noreturn void rust_helper_BUG(void) { BUG(); } -EXPORT_SYMBOL_GPL(rust_helper_BUG); diff --git a/rust/helpers/build_bug.c b/rust/helpers/build_bug.c index f3106f248485a561fa00aaa1ae40e86ebe526d6a..e994f7b5928c0151e375ad7303fd02b12f522fbd 100644 --- a/rust/helpers/build_bug.c +++ b/rust/helpers/build_bug.c @@ -7,4 +7,3 @@ const char *rust_helper_errname(int err) { return errname(err); } -EXPORT_SYMBOL_GPL(rust_helper_errname); diff --git a/rust/helpers/err.c b/rust/helpers/err.c index fba4e0be64f593595d7927ca652d23eb46b7dffc..be3d45ef78a25799bf812ca570579f76f201543b 100644 --- a/rust/helpers/err.c +++ b/rust/helpers/err.c @@ -7,16 +7,13 @@ __force void *rust_helper_ERR_PTR(long err) { return ERR_PTR(err); } -EXPORT_SYMBOL_GPL(rust_helper_ERR_PTR); bool rust_helper_IS_ERR(__force const void *ptr) { return IS_ERR(ptr); } -EXPORT_SYMBOL_GPL(rust_helper_IS_ERR); long rust_helper_PTR_ERR(__force const void *ptr) { return PTR_ERR(ptr); } -EXPORT_SYMBOL_GPL(rust_helper_PTR_ERR); diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c index 2b54f22e877411da767688d909666408cc373614..173533616c917ce85dae1a0e8ea78052c7a377e3 100644 --- a/rust/helpers/helpers.c +++ b/rust/helpers/helpers.c @@ -4,19 +4,6 @@ * cannot be called either. This file explicitly creates functions ("helpers") * that wrap those so that they can be called from Rust. * - * Even though Rust kernel modules should never use the bindings directly, some - * of these helpers need to be exported because Rust generics and inlined - * functions may not get their code generated in the crate where they are - * defined. Other helpers, called from non-inline functions, may not be - * exported, in principle. However, in general, the Rust compiler does not - * guarantee codegen will be performed for a non-inline function either. - * Therefore, this file exports all the helpers. In the future, this may be - * revisited to reduce the number of exports after the compiler is informed - * about the places codegen is required. - * - * All symbols are exported as GPL-only to guarantee no GPL-only feature is - * accidentally exposed. - * * Sorted alphabetically. */ diff --git a/rust/helpers/kunit.c b/rust/helpers/kunit.c index 905e4ff4424a5b5d154d69bd3fd40cd2417e81ee..9d725067eb3bc10388fac94c83844910c866ac9e 100644 --- a/rust/helpers/kunit.c +++ b/rust/helpers/kunit.c @@ -7,4 +7,3 @@ struct kunit *rust_helper_kunit_get_current_test(void) { return kunit_get_current_test(); } -EXPORT_SYMBOL_GPL(rust_helper_kunit_get_current_test); diff --git a/rust/helpers/mutex.c b/rust/helpers/mutex.c index 29fd141c387d799e98e58b901d8806f078bff9da..200db7e6279f0f11f59da15ed2cbb0332a9d830e 100644 --- a/rust/helpers/mutex.c +++ b/rust/helpers/mutex.c @@ -7,4 +7,3 @@ void rust_helper_mutex_lock(struct mutex *lock) { mutex_lock(lock); } -EXPORT_SYMBOL_GPL(rust_helper_mutex_lock); diff --git a/rust/helpers/page.c b/rust/helpers/page.c index 7fd333411a88fcd7dfb6c6b69c2c73f7899aa77e..b3f2b8fbf87fc9aa89cb1636736c52be16411301 100644 --- a/rust/helpers/page.c +++ b/rust/helpers/page.c @@ -7,16 +7,13 @@ struct page *rust_helper_alloc_pages(gfp_t gfp_mask, unsigned int order) { return alloc_pages(gfp_mask, order); } -EXPORT_SYMBOL_GPL(rust_helper_alloc_pages); void *rust_helper_kmap_local_page(struct page *page) { return kmap_local_page(page); } -EXPORT_SYMBOL_GPL(rust_helper_kmap_local_page); void rust_helper_kunmap_local(const void *addr) { kunmap_local(addr); } -EXPORT_SYMBOL_GPL(rust_helper_kunmap_local); diff --git a/rust/helpers/refcount.c b/rust/helpers/refcount.c index 13ab64805f7792f5645a5bd74e11c651485e1be3..f47afc148ec36cb07a136228b6555c9aaa220406 100644 --- a/rust/helpers/refcount.c +++ b/rust/helpers/refcount.c @@ -7,16 +7,13 @@ refcount_t rust_helper_REFCOUNT_INIT(int n) { return (refcount_t)REFCOUNT_INIT(n); } -EXPORT_SYMBOL_GPL(rust_helper_REFCOUNT_INIT); void rust_helper_refcount_inc(refcount_t *r) { refcount_inc(r); } -EXPORT_SYMBOL_GPL(rust_helper_refcount_inc); bool rust_helper_refcount_dec_and_test(refcount_t *r) { return refcount_dec_and_test(r); } -EXPORT_SYMBOL_GPL(rust_helper_refcount_dec_and_test); diff --git a/rust/helpers/signal.c b/rust/helpers/signal.c index d44e8096b8a96bfb7ba720691bb7f15489d1de97..63c407f80c26b34401fba224a4976f36a3194d13 100644 --- a/rust/helpers/signal.c +++ b/rust/helpers/signal.c @@ -7,4 +7,3 @@ int rust_helper_signal_pending(struct task_struct *t) { return signal_pending(t); } -EXPORT_SYMBOL_GPL(rust_helper_signal_pending); diff --git a/rust/helpers/slab.c b/rust/helpers/slab.c index 3e0a1a173d8a7d454fecdb5c903f6b55fe7835e6..f043e087f9d666673bcde50aa25610733d5347aa 100644 --- a/rust/helpers/slab.c +++ b/rust/helpers/slab.c @@ -7,4 +7,3 @@ rust_helper_krealloc(const void *objp, size_t new_size, gfp_t flags) { return krealloc(objp, new_size, flags); } -EXPORT_SYMBOL_GPL(rust_helper_krealloc); diff --git a/rust/helpers/spinlock.c b/rust/helpers/spinlock.c index 04fd8ddb4986d4324abc845e3067a04df974ae7d..acc1376b833c786e7f7dde4b4179b750b80e02bd 100644 --- a/rust/helpers/spinlock.c +++ b/rust/helpers/spinlock.c @@ -12,16 +12,13 @@ void rust_helper___spin_lock_init(spinlock_t *lock, const char *name, spin_lock_init(lock); #endif } -EXPORT_SYMBOL_GPL(rust_helper___spin_lock_init); void rust_helper_spin_lock(spinlock_t *lock) { spin_lock(lock); } -EXPORT_SYMBOL_GPL(rust_helper_spin_lock); void rust_helper_spin_unlock(spinlock_t *lock) { spin_unlock(lock); } -EXPORT_SYMBOL_GPL(rust_helper_spin_unlock); diff --git a/rust/helpers/task.c b/rust/helpers/task.c index b176c347f0d41cb42ef91aa119d66cd99d59458a..7ac789232d11cd1e200bf686b6d4e43335c7958a 100644 --- a/rust/helpers/task.c +++ b/rust/helpers/task.c @@ -7,16 +7,13 @@ struct task_struct *rust_helper_get_current(void) { return current; } -EXPORT_SYMBOL_GPL(rust_helper_get_current); void rust_helper_get_task_struct(struct task_struct *t) { get_task_struct(t); } -EXPORT_SYMBOL_GPL(rust_helper_get_task_struct); void rust_helper_put_task_struct(struct task_struct *t) { put_task_struct(t); } -EXPORT_SYMBOL_GPL(rust_helper_put_task_struct); diff --git a/rust/helpers/uaccess.c b/rust/helpers/uaccess.c index 3d004ac1c1805735c318244550fa958ebd2b3e3f..f49076f813cd641a55b3a083ac3f7fbcdf53abb6 100644 --- a/rust/helpers/uaccess.c +++ b/rust/helpers/uaccess.c @@ -7,11 +7,9 @@ unsigned long rust_helper_copy_from_user(void *to, const void __user *from, { return copy_from_user(to, from, n); } -EXPORT_SYMBOL_GPL(rust_helper_copy_from_user); unsigned long rust_helper_copy_to_user(void __user *to, const void *from, unsigned long n) { return copy_to_user(to, from, n); } -EXPORT_SYMBOL_GPL(rust_helper_copy_to_user); diff --git a/rust/helpers/wait.c b/rust/helpers/wait.c index bf361f40c7cbc6a526244119734bc9199e7e946c..c7336bbf275071d66a3879e0eacd247a57f22ead 100644 --- a/rust/helpers/wait.c +++ b/rust/helpers/wait.c @@ -7,4 +7,3 @@ void rust_helper_init_wait(struct wait_queue_entry *wq_entry) { init_wait(wq_entry); } -EXPORT_SYMBOL_GPL(rust_helper_init_wait); diff --git a/rust/helpers/workqueue.c b/rust/helpers/workqueue.c index 12e2ee66aa4f60dceb904fa07843f255d1c3e1c7..f59427acc32373692aaa80b40d2d4fabf66f8df8 100644 --- a/rust/helpers/workqueue.c +++ b/rust/helpers/workqueue.c @@ -13,4 +13,3 @@ void rust_helper_init_work_with_key(struct work_struct *work, work_func_t func, INIT_LIST_HEAD(&work->entry); work->func = func; } -EXPORT_SYMBOL_GPL(rust_helper_init_work_with_key);