From 347eeababf50f2eb98be1fbb948d335834aeec33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 8 Jul 2024 14:17:08 +0200 Subject: [PATCH] logging: Fix runtime filtering when frontend and userspace is used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When userspace is used and frontend was used for logging then runtime filtering was failing because in user context filtering data was accessed and filtering data is in the kernel space. Fixing that and adding runtime filtering to the pre frontend function which is already executed in the kernel space and filter data can be accessed. Signed-off-by: Krzysztof Chruściński --- include/zephyr/logging/log_core.h | 4 ++-- subsys/logging/log_msg.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/zephyr/logging/log_core.h b/include/zephyr/logging/log_core.h index 41936eb6696..42ef6e99062 100644 --- a/include/zephyr/logging/log_core.h +++ b/include/zephyr/logging/log_core.h @@ -251,7 +251,7 @@ static inline char z_log_minimal_level_to_char(int level) } \ \ bool is_user_context = k_is_user_context(); \ - if (!IS_ENABLED(CONFIG_LOG_FRONTEND) && IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) && \ + if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) && \ !is_user_context && _level > Z_LOG_RUNTIME_FILTER((_dsource)->filters)) { \ break; \ } \ @@ -335,7 +335,7 @@ static inline char z_log_minimal_level_to_char(int level) (const char *)(_data), (_len));\ break; \ } \ - if (!IS_ENABLED(CONFIG_LOG_FRONTEND) && IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) && \ + if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) && \ !is_user_context && (_level) > Z_LOG_RUNTIME_FILTER(filters)) { \ break; \ } \ diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index b2b6aee9e21..c45eb2201da 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -57,8 +57,10 @@ static bool frontend_runtime_filtering(const void *source, uint32_t level) return true; } - /* If only frontend is used and log got here it means that it was accepted. */ - if (IS_ENABLED(CONFIG_LOG_FRONTEND_ONLY)) { + /* If only frontend is used and log got here it means that it was accepted + * unless userspace is enabled then runtime filtering is done here. + */ + if (!IS_ENABLED(CONFIG_USERSPACE) && IS_ENABLED(CONFIG_LOG_FRONTEND_ONLY)) { return true; }