Re: [PATCH v7] rust: support for shadow call stack sanitizer

From: Gary Guo
Date: Sun Sep 15 2024 - 07:36:45 EST


On Sun, 15 Sep 2024 09:32:44 +0200
Dirk Behme <dirk.behme@xxxxxxxxx> wrote:

> Yes, it is unrelated to this change. It is PREEMPT_RT usage related. I
> think we could add something like
>
> #ifdef CONFIG_PREEMPT_RT
> void rust_helper___mutex_init(struct mutex *mutex, const char *name,
> struct lock_class_key *key)
> {
> return __mutex_init(mutex, name, key);
> }
> #endif

There's no need to use `ifdef` here (we don't want to try replicate all
ifdefs). Simply add a helper is sufficient. We have logic in
rust/bindings/lib.rs to prefer externed function to helpers if an
externed function exist.

Best,
Gary

>
> to helpers to fix
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/rust/kernel/sync/lock/mutex.rs?&id=6d20d629c6d8575be98eeebe49a16fb2d7b32350
>
> ?
>
> Explanation: Looking at
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/mutex.h?#n52
>
> we have (simplified)
>
> #ifndef CONFIG_PREEMPT_RT
> extern void __mutex_init(struct mutex *lock, const char *name,
> struct lock_class_key *key);
> #else
> #define __mutex_init(mutex, name, key) \
> do { \
> rt_mutex_base_init(&(mutex)->rtmutex); \
> __mutex_rt_init((mutex), name, key); \
> } while (0)
> #endif
>
> So in the CONFIG_PREEMPT_RT case bindgen doesn't resolve the macro
> what could be fixed by adding a helper.
>
> Dirk