From 9f44a48b365924ee6f576c95bf0649160b6be58a Mon Sep 17 00:00:00 2001 From: Jian Yu Date: Mon, 24 Jun 2024 20:00:20 -0700 Subject: [PATCH] LU-17793 libcfs: fix objtool warning in lbug_with_loc() After lbug_with_loc() was removed from the objtool global_noreturns array in Linux commit v6.4-rc2-10-g34245659debd, building Lustre hit the following warning: libcfs/libcfs/fail.o: warning: objtool: __cfs_fail_check_set() falls through to next function __cfs_fail_timeout_set() This patch fixes the above warning by adding an unreachable panic() at the end of lbug_with_loc() to terminate all of the call paths in that function. As a consequence of this change, we need to make the patch fix more errors, such as: lnet/lnet/api-ni.c: In function 'lnet_res_type2str': libcfs/include/libcfs/libcfs_private.h:119:9: error: this statement may fall through [-Werror=implicit-fallthrough=] 119 | lbug_with_loc(&msgdata); \ | ^~~~~~~~~~~~~~~~~~~~~~~ lnet/lnet/api-ni.c:1143:17: note: in expansion of macro 'LBUG' 1143 | LBUG(); | ^~~~ lnet/lnet/api-ni.c:1144:9: note: here 1144 | case LNET_COOKIE_TYPE_MD: | ^~~~ and lustre/obdclass/lprocfs_status.c: In function 'lprocfs_stats_lock': lustre/obdclass/lprocfs_status.c:470:1: error: control reaches end of non-void function [-Werror=return-type] 470 | } | ^ Change-Id: I5574559619b4b6746f4e7da51f3213ede246a73b Signed-off-by: Jian Yu Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55505 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Aurelien Degremont Reviewed-by: Bruno Faccini Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- config/lustre-build-linux.m4 | 19 +++++++++++++++++++ libcfs/include/libcfs/libcfs_private.h | 11 ++++++++--- libcfs/libcfs/debug.c | 16 +++++++++++++--- lustre/llite/pcc.c | 1 + lustre/obdclass/lprocfs_status.c | 1 + lustre/osp/osp_object.c | 1 + lustre/ptlrpc/pack_generic.c | 2 ++ 7 files changed, 45 insertions(+), 6 deletions(-) diff --git a/config/lustre-build-linux.m4 b/config/lustre-build-linux.m4 index b6d437e..3b45956 100644 --- a/config/lustre-build-linux.m4 +++ b/config/lustre-build-linux.m4 @@ -490,6 +490,23 @@ Kernel module loading support is highly recommended. ]) ]) +# +# LC_LBUG_WITH_LOC_IN_OBJTOOL +# +# Linux v6.4-rc2-10-g34245659debd +# objtool: Remove superfluous global_noreturns entries +# +AC_DEFUN([LC_LBUG_WITH_LOC_IN_OBJTOOL], [ + AC_MSG_CHECKING([if lbug_with_loc is in objtool global_noreturns array]) + AS_IF([grep -q lbug_with_loc $LINUX_OBJ/tools/objtool/objtool],[ + AC_DEFINE(HAVE_LBUG_WITH_LOC_IN_OBJTOOL, 1, + [lbug_with_loc is in objtool global_noreturns array]) + AC_MSG_RESULT(yes) + ],[ + AC_MSG_RESULT(no) + ]) +]) # LC_LBUG_WITH_LOC_IN_OBJTOOL + AC_DEFUN([LB_PROG_LINUX_SRC], [ LB2_SRC_CHECK_CONFIG([MODULES]) LB2_SRC_CHECK_CONFIG([MODVERSIONS]) @@ -512,6 +529,8 @@ LB_LINUX_PATH LB_LINUX_SYMVERFILE # 2.6.28 LC_MODULE_LOADING +# 6.5 +LC_LBUG_WITH_LOC_IN_OBJTOOL ]) # diff --git a/libcfs/include/libcfs/libcfs_private.h b/libcfs/include/libcfs/libcfs_private.h index 2c50e96..89690ef 100644 --- a/libcfs/include/libcfs/libcfs_private.h +++ b/libcfs/include/libcfs/libcfs_private.h @@ -111,12 +111,17 @@ do { \ # define LINVRNT(exp) ((void)sizeof!!(exp)) #endif -void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *msg); +void +#ifdef HAVE_LBUG_WITH_LOC_IN_OBJTOOL +__noreturn +#endif +lbug_with_loc(struct libcfs_debug_msg_data *msg); #define LBUG() \ do { \ - LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_EMERG, NULL); \ - lbug_with_loc(&msgdata); \ + LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_EMERG, NULL); \ + lbug_with_loc(&msgdata); \ + break; \ } while(0) /* diff --git a/libcfs/libcfs/debug.c b/libcfs/libcfs/debug.c index 66ca9d7..868cbf1 100644 --- a/libcfs/libcfs/debug.c +++ b/libcfs/libcfs/debug.c @@ -43,6 +43,7 @@ #include #include #include +#include #ifdef HAVE_PANIC_NOTIFIER_H #include #endif @@ -417,7 +418,11 @@ void libcfs_debug_dumplog(void) } EXPORT_SYMBOL(libcfs_debug_dumplog); -void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *msgdata) +void +#ifdef HAVE_LBUG_WITH_LOC_IN_OBJTOOL +__noreturn +#endif +lbug_with_loc(struct libcfs_debug_msg_data *msgdata) { libcfs_catastrophe = 1; libcfs_debug_msg(msgdata, "LBUG\n"); @@ -428,13 +433,18 @@ void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *msgdata) } dump_stack(); - if (libcfs_panic_on_lbug) + if (libcfs_panic_on_lbug) { + msleep(cfs_time_seconds(6)); panic("LBUG"); - else + } else libcfs_debug_dumplog(); set_current_state(TASK_UNINTERRUPTIBLE); while (1) schedule(); +#ifndef HAVE_LBUG_WITH_LOC_IN_OBJTOOL + /* not reached */ + panic("LBUG after schedule."); +#endif } EXPORT_SYMBOL(lbug_with_loc); diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index a1a1df0..d60c645 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -451,6 +451,7 @@ pcc_get_opcode_delim(enum pcc_field_op opc) return PCC_EXPRESSION_DELIM_GT; default: LBUG(); + return NULL; } } diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 1a5564b..009feb2 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -466,6 +466,7 @@ int lprocfs_stats_lock(struct lprocfs_stats *stats, return stats->ls_biggest_alloc_num; default: LBUG(); + return -EINVAL; } } diff --git a/lustre/osp/osp_object.c b/lustre/osp/osp_object.c index ccf5875..74da125 100644 --- a/lustre/osp/osp_object.c +++ b/lustre/osp/osp_object.c @@ -2433,6 +2433,7 @@ static int osp_object_print(const struct lu_env *env, void *cookie, static int osp_object_invariant(const struct lu_object *o) { LBUG(); + return -EINVAL; } const struct lu_object_operations osp_lu_obj_ops = { diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index d386ab4..40eda56 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -483,6 +483,7 @@ int lustre_shrink_msg(struct lustre_msg *msg, int segment, return lustre_shrink_msg_v2(msg, segment, newlen, move_data); default: LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return -EINVAL; } } EXPORT_SYMBOL(lustre_shrink_msg); @@ -534,6 +535,7 @@ int lustre_grow_msg(struct lustre_msg *msg, int segment, unsigned int newlen) return lustre_grow_msg_v2(msg, segment, newlen); default: LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return -EINVAL; } } EXPORT_SYMBOL(lustre_grow_msg); -- 1.8.3.1