Whamcloud - gitweb
LU-17793 libcfs: fix objtool warning in lbug_with_loc() 05/55505/4
authorJian Yu <yujian@whamcloud.com>
Tue, 25 Jun 2024 03:00:20 +0000 (20:00 -0700)
committerOleg Drokin <green@whamcloud.com>
Mon, 8 Jul 2024 20:12:09 +0000 (20:12 +0000)
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 <yujian@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55505
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Aurelien Degremont <adegremont@nvidia.com>
Reviewed-by: Bruno Faccini <bfaccini@nvidia.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
config/lustre-build-linux.m4
libcfs/include/libcfs/libcfs_private.h
libcfs/libcfs/debug.c
lustre/llite/pcc.c
lustre/obdclass/lprocfs_status.c
lustre/osp/osp_object.c
lustre/ptlrpc/pack_generic.c

index b6d437e..3b45956 100644 (file)
@@ -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
 ])
 
 #
index 2c50e96..89690ef 100644 (file)
@@ -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)
 
 /*
index 66ca9d7..868cbf1 100644 (file)
@@ -43,6 +43,7 @@
 #include <linux/stacktrace.h>
 #include <linux/utsname.h>
 #include <linux/kallsyms.h>
+#include <linux/delay.h>
 #ifdef HAVE_PANIC_NOTIFIER_H
 #include <linux/panic_notifier.h>
 #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);
 
index a1a1df0..d60c645 100644 (file)
@@ -451,6 +451,7 @@ pcc_get_opcode_delim(enum pcc_field_op opc)
                return PCC_EXPRESSION_DELIM_GT;
        default:
                LBUG();
+               return NULL;
        }
 }
 
index 1a5564b..009feb2 100644 (file)
@@ -466,6 +466,7 @@ int lprocfs_stats_lock(struct lprocfs_stats *stats,
                return stats->ls_biggest_alloc_num;
        default:
                LBUG();
+               return -EINVAL;
        }
 }
 
index ccf5875..74da125 100644 (file)
@@ -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 = {
index d386ab4..40eda56 100644 (file)
@@ -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);