logging: Fix runtime filtering when frontend and userspace is used

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 <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruściński 2024-07-08 14:17:08 +02:00 committed by Alberto Escolar
parent 8ed29a625a
commit 347eeababf
2 changed files with 6 additions and 4 deletions

View File

@ -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; \
} \

View File

@ -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;
}