2022-08-15 11:04:20

by Chen Zhongjin

[permalink] [raw]
Subject: [PATCH] x86/unwind/orc: Add 'unwind_debug' cmdline option

From: Josh Poimboeuf <[email protected]>

Sometimes the one-line ORC unwinder warnings aren't very helpful. Add a
new 'unwind_debug' cmdline option which will dump the full stack
contents of the current task when an error condition is encountered.

Signed-off-by: Josh Poimboeuf <[email protected]>
Reviewed-by: Miroslav Benes <[email protected]>
---
.../admin-guide/kernel-parameters.txt | 6 +++
arch/x86/kernel/unwind_orc.c | 46 +++++++++++++++++++
2 files changed, 52 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index cc3ea8febc62..85d48f6052fd 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -6317,6 +6317,12 @@
unknown_nmi_panic
[X86] Cause panic on unknown NMI.

+ unwind_debug [X86-64]
+ Enable unwinder debug output. This can be
+ useful for debugging certain unwinder error
+ conditions, including corrupt stacks and
+ bad/missing unwinder metadata.
+
usbcore.authorized_default=
[USB] Default USB device authorization:
(default -1 = authorized except for wireless USB,
diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
index 38185aedf7d1..c539ca39e9f4 100644
--- a/arch/x86/kernel/unwind_orc.c
+++ b/arch/x86/kernel/unwind_orc.c
@@ -13,8 +13,13 @@

#define orc_warn_current(args...) \
({ \
+ static bool dumped_before;
if (state->task == current && !state->error) \
orc_warn(args); \
+ if (unwind_debug && !dumped_before) \
+ unwind_dump(state); \
+ dumped_before = true; \
+ } \
})

extern int __start_orc_unwind_ip[];
@@ -23,8 +28,49 @@ extern struct orc_entry __start_orc_unwind[];
extern struct orc_entry __stop_orc_unwind[];

static bool orc_init __ro_after_init;
+static bool unwind_debug __ro_after_init;
static unsigned int lookup_num_blocks __ro_after_init;

+static int __init unwind_debug_cmdline(char *str)
+{
+ unwind_debug = true;
+
+ return 0;
+}
+early_param("unwind_debug", unwind_debug_cmdline);
+
+static void unwind_dump(struct unwind_state *state)
+{
+ static bool dumped_before;
+ unsigned long word, *sp;
+ struct stack_info stack_info = {0};
+ unsigned long visit_mask = 0;
+
+ if (dumped_before)
+ return;
+
+ dumped_before = true;
+
+ printk_deferred("unwind stack type:%d next_sp:%p mask:0x%lx graph_idx:%d\n",
+ state->stack_info.type, state->stack_info.next_sp,
+ state->stack_mask, state->graph_idx);
+
+ for (sp = __builtin_frame_address(0); sp;
+ sp = PTR_ALIGN(stack_info.next_sp, sizeof(long))) {
+ if (get_stack_info(sp, state->task, &stack_info, &visit_mask))
+ break;
+
+ for (; sp < stack_info.end; sp++) {
+
+ word = READ_ONCE_NOCHECK(*sp);
+
+ printk_deferred("%0*lx: %0*lx (%pB)\n", BITS_PER_LONG/4,
+ (unsigned long)sp, BITS_PER_LONG/4,
+ word, (void *)word);
+ }
+ }
+}
+
static inline unsigned long orc_ip(const int *ip)
{
return (unsigned long)ip + *ip;


2022-08-15 11:49:17

by Chen Zhongjin

[permalink] [raw]
Subject: Re: [PATCH] x86/unwind/orc: Add 'unwind_debug' cmdline option

I accidentally attached this with my patch.

Please ignore this one.


Thanks,

Chen

On 2022/8/15 18:58, Chen Zhongjin wrote:
> From: Josh Poimboeuf <[email protected]>
>
> Sometimes the one-line ORC unwinder warnings aren't very helpful. Add a
> new 'unwind_debug' cmdline option which will dump the full stack
> contents of the current task when an error condition is encountered.
>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> Reviewed-by: Miroslav Benes <[email protected]>
> ---
> .../admin-guide/kernel-parameters.txt | 6 +++
> arch/x86/kernel/unwind_orc.c | 46 +++++++++++++++++++
> 2 files changed, 52 insertions(+)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index cc3ea8febc62..85d48f6052fd 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -6317,6 +6317,12 @@
> unknown_nmi_panic
> [X86] Cause panic on unknown NMI.
>
> + unwind_debug [X86-64]
> + Enable unwinder debug output. This can be
> + useful for debugging certain unwinder error
> + conditions, including corrupt stacks and
> + bad/missing unwinder metadata.
> +
> usbcore.authorized_default=
> [USB] Default USB device authorization:
> (default -1 = authorized except for wireless USB,
> diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
> index 38185aedf7d1..c539ca39e9f4 100644
> --- a/arch/x86/kernel/unwind_orc.c
> +++ b/arch/x86/kernel/unwind_orc.c
> @@ -13,8 +13,13 @@
>
> #define orc_warn_current(args...) \
> ({ \
> + static bool dumped_before;
> if (state->task == current && !state->error) \
> orc_warn(args); \
> + if (unwind_debug && !dumped_before) \
> + unwind_dump(state); \
> + dumped_before = true; \
> + } \
> })
>
> extern int __start_orc_unwind_ip[];
> @@ -23,8 +28,49 @@ extern struct orc_entry __start_orc_unwind[];
> extern struct orc_entry __stop_orc_unwind[];
>
> static bool orc_init __ro_after_init;
> +static bool unwind_debug __ro_after_init;
> static unsigned int lookup_num_blocks __ro_after_init;
>
> +static int __init unwind_debug_cmdline(char *str)
> +{
> + unwind_debug = true;
> +
> + return 0;
> +}
> +early_param("unwind_debug", unwind_debug_cmdline);
> +
> +static void unwind_dump(struct unwind_state *state)
> +{
> + static bool dumped_before;
> + unsigned long word, *sp;
> + struct stack_info stack_info = {0};
> + unsigned long visit_mask = 0;
> +
> + if (dumped_before)
> + return;
> +
> + dumped_before = true;
> +
> + printk_deferred("unwind stack type:%d next_sp:%p mask:0x%lx graph_idx:%d\n",
> + state->stack_info.type, state->stack_info.next_sp,
> + state->stack_mask, state->graph_idx);
> +
> + for (sp = __builtin_frame_address(0); sp;
> + sp = PTR_ALIGN(stack_info.next_sp, sizeof(long))) {
> + if (get_stack_info(sp, state->task, &stack_info, &visit_mask))
> + break;
> +
> + for (; sp < stack_info.end; sp++) {
> +
> + word = READ_ONCE_NOCHECK(*sp);
> +
> + printk_deferred("%0*lx: %0*lx (%pB)\n", BITS_PER_LONG/4,
> + (unsigned long)sp, BITS_PER_LONG/4,
> + word, (void *)word);
> + }
> + }
> +}
> +
> static inline unsigned long orc_ip(const int *ip)
> {
> return (unsigned long)ip + *ip;

2022-08-15 23:24:16

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] x86/unwind/orc: Add 'unwind_debug' cmdline option

Hi Chen,

I love your patch! Perhaps something to improve:

[auto build test WARNING on tip/x86/core]
[also build test WARNING on soc/for-next clk/clk-next linus/master v6.0-rc1 next-20220815]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Chen-Zhongjin/x86-unwind-orc-Add-unwind_debug-cmdline-option/20220815-190328
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git a1a5482a2c6e38a3ebed32e571625c56a8cc41a6
config: x86_64-randconfig-a003-20220815 (https://download.01.org/0day-ci/archive/20220816/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/3295e738f5b51f1f1f223bf52a8ecee2ab93fbca
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Chen-Zhongjin/x86-unwind-orc-Add-unwind_debug-cmdline-option/20220815-190328
git checkout 3295e738f5b51f1f1f223bf52a8ecee2ab93fbca
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash arch/x86/kernel/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

arch/x86/kernel/unwind_orc.c:17:9: error: expected identifier or '(' before 'if'
17 | if (state->task == current && !state->error) \
| ^~
In file included from include/asm-generic/bug.h:7,
from arch/x86/include/asm/bug.h:87,
from include/linux/bug.h:5,
from include/linux/jump_label.h:257,
from include/linux/static_key.h:1,
from arch/x86/include/asm/nospec-branch.h:6,
from arch/x86/include/asm/paravirt_types.h:40,
from arch/x86/include/asm/ptrace.h:97,
from arch/x86/include/asm/math_emu.h:5,
from arch/x86/include/asm/processor.h:13,
from arch/x86/include/asm/timex.h:5,
from include/linux/timex.h:67,
from include/linux/time32.h:13,
from include/linux/time.h:60,
from include/linux/stat.h:19,
from include/linux/module.h:13,
from arch/x86/kernel/unwind_orc.c:3:
include/linux/once_lite.h:34:10: error: expected identifier or '(' before ')' token
34 | })
| ^
include/linux/once_lite.h:11:9: note: in expansion of macro 'DO_ONCE_LITE_IF'
11 | DO_ONCE_LITE_IF(true, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~
include/linux/printk.h:605:9: note: in expansion of macro 'DO_ONCE_LITE'
605 | DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:12:9: note: in expansion of macro 'printk_deferred_once'
12 | printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:18:17: note: in expansion of macro 'orc_warn'
18 | orc_warn(args); \
| ^~~~~~~~
arch/x86/kernel/unwind_orc.c:19:17: error: expected identifier or '(' before 'if'
19 | if (unwind_debug && !dumped_before) \
| ^~
>> arch/x86/kernel/unwind_orc.c:21:17: warning: data definition has no type or storage class
21 | dumped_before = true; \
| ^~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:21:17: error: type defaults to 'int' in declaration of 'dumped_before' [-Werror=implicit-int]
arch/x86/kernel/unwind_orc.c:22:9: error: expected identifier or '(' before '}' token
22 | } \
| ^
arch/x86/kernel/unwind_orc.c:23:1: error: expected identifier or '(' before '}' token
23 | })
| ^
arch/x86/kernel/unwind_orc.c:23:2: error: expected identifier or '(' before ')' token
23 | })
| ^
arch/x86/kernel/unwind_orc.c: In function 'orc_find':
arch/x86/kernel/unwind_orc.c:219:35: error: '__start_orc_unwind_ip' undeclared (first use in this function); did you mean '__start_orc_unwind'?
219 | return __orc_find(__start_orc_unwind_ip + start,
| ^~~~~~~~~~~~~~~~~~~~~
| __start_orc_unwind
arch/x86/kernel/unwind_orc.c:219:35: note: each undeclared identifier is reported only once for each function it appears in
arch/x86/kernel/unwind_orc.c: At top level:
arch/x86/kernel/unwind_orc.c:239:32: error: '__start_orc_unwind_ip' undeclared here (not in a function); did you mean '__start_orc_unwind'?
239 | static int *cur_orc_ip_table = __start_orc_unwind_ip;
| ^~~~~~~~~~~~~~~~~~~~~
| __start_orc_unwind
arch/x86/kernel/unwind_orc.c: In function 'unwind_next_frame':
arch/x86/kernel/unwind_orc.c:534:18: error: expected ')' before 'break'
534 | }
| ^
| )
535 | break;
| ~~~~~
>> arch/x86/kernel/unwind_orc.c:16:21: warning: unused variable 'dumped_before' [-Wunused-variable]
16 | static bool dumped_before;
| ^~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:531:25: note: in expansion of macro 'orc_warn_current'
531 | orc_warn_current("missing R10 value at %pB\n",
| ^~~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:767:1: error: expected declaration or statement at end of input
767 | EXPORT_SYMBOL_GPL(__unwind_start);
| ^~~~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:767:1: error: expected declaration or statement at end of input
arch/x86/kernel/unwind_orc.c:767:1: error: expected declaration or statement at end of input
arch/x86/kernel/unwind_orc.c:533:25: error: label 'err' used but not defined
533 | goto err;
| ^~~~
arch/x86/kernel/unwind_orc.c:506:17: error: label 'the_end' used but not defined
506 | goto the_end;
| ^~~~
>> arch/x86/kernel/unwind_orc.c:468:14: warning: variable 'indirect' set but not used [-Wunused-but-set-variable]
468 | bool indirect = false;
| ^~~~~~~~
>> arch/x86/kernel/unwind_orc.c:466:25: warning: unused variable 'prev_type' [-Wunused-variable]
466 | enum stack_type prev_type = state->stack_info.type;
| ^~~~~~~~~
>> arch/x86/kernel/unwind_orc.c:465:59: warning: unused variable 'prev_sp' [-Wunused-variable]
465 | unsigned long ip_p, sp, tmp, orig_ip = state->ip, prev_sp = state->sp;
| ^~~~~~~
>> arch/x86/kernel/unwind_orc.c:465:38: warning: unused variable 'orig_ip' [-Wunused-variable]
465 | unsigned long ip_p, sp, tmp, orig_ip = state->ip, prev_sp = state->sp;
| ^~~~~~~
>> arch/x86/kernel/unwind_orc.c:465:33: warning: unused variable 'tmp' [-Wunused-variable]
465 | unsigned long ip_p, sp, tmp, orig_ip = state->ip, prev_sp = state->sp;
| ^~~
>> arch/x86/kernel/unwind_orc.c:465:23: warning: unused variable 'ip_p' [-Wunused-variable]
465 | unsigned long ip_p, sp, tmp, orig_ip = state->ip, prev_sp = state->sp;
| ^~~~
arch/x86/kernel/unwind_orc.c:768: error: control reaches end of non-void function [-Werror=return-type]
At top level:
>> arch/x86/kernel/unwind_orc.c:16:21: warning: 'dumped_before' defined but not used [-Wunused-variable]
16 | static bool dumped_before;
| ^~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:531:25: note: in expansion of macro 'orc_warn_current'
531 | orc_warn_current("missing R10 value at %pB\n",
| ^~~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:421:13: warning: 'deref_stack_iret_regs' defined but not used [-Wunused-function]
421 | static bool deref_stack_iret_regs(struct unwind_state *state, unsigned long addr,
| ^~~~~~~~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:405:13: warning: 'deref_stack_regs' defined but not used [-Wunused-function]
405 | static bool deref_stack_regs(struct unwind_state *state, unsigned long addr,
| ^~~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:395:13: warning: 'deref_stack_reg' defined but not used [-Wunused-function]
395 | static bool deref_stack_reg(struct unwind_state *state, unsigned long addr,
| ^~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:42:13: warning: 'unwind_dump' defined but not used [-Wunused-function]
42 | static void unwind_dump(struct unwind_state *state)
| ^~~~~~~~~~~
cc1: some warnings being treated as errors


vim +21 arch/x86/kernel/unwind_orc.c

10
11 #define orc_warn(fmt, ...) \
12 printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
13
14 #define orc_warn_current(args...) \
15 ({ \
> 16 static bool dumped_before;
17 if (state->task == current && !state->error) \
18 orc_warn(args); \
19 if (unwind_debug && !dumped_before) \
20 unwind_dump(state); \
> 21 dumped_before = true; \
22 } \
23 })
24

--
0-DAY CI Kernel Test Service
https://01.org/lkp

2022-08-16 03:34:15

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] x86/unwind/orc: Add 'unwind_debug' cmdline option

Hi Chen,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on soc/for-next clk/clk-next linus/master v6.0-rc1 next-20220815]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Chen-Zhongjin/x86-unwind-orc-Add-unwind_debug-cmdline-option/20220815-190328
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git a1a5482a2c6e38a3ebed32e571625c56a8cc41a6
config: x86_64-randconfig-a003-20220815 (https://download.01.org/0day-ci/archive/20220816/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/3295e738f5b51f1f1f223bf52a8ecee2ab93fbca
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Chen-Zhongjin/x86-unwind-orc-Add-unwind_debug-cmdline-option/20220815-190328
git checkout 3295e738f5b51f1f1f223bf52a8ecee2ab93fbca
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> arch/x86/kernel/unwind_orc.c:17:9: error: expected identifier or '(' before 'if'
17 | if (state->task == current && !state->error) \
| ^~
In file included from include/asm-generic/bug.h:7,
from arch/x86/include/asm/bug.h:87,
from include/linux/bug.h:5,
from include/linux/jump_label.h:257,
from include/linux/static_key.h:1,
from arch/x86/include/asm/nospec-branch.h:6,
from arch/x86/include/asm/paravirt_types.h:40,
from arch/x86/include/asm/ptrace.h:97,
from arch/x86/include/asm/math_emu.h:5,
from arch/x86/include/asm/processor.h:13,
from arch/x86/include/asm/timex.h:5,
from include/linux/timex.h:67,
from include/linux/time32.h:13,
from include/linux/time.h:60,
from include/linux/stat.h:19,
from include/linux/module.h:13,
from arch/x86/kernel/unwind_orc.c:3:
>> include/linux/once_lite.h:34:10: error: expected identifier or '(' before ')' token
34 | })
| ^
include/linux/once_lite.h:11:9: note: in expansion of macro 'DO_ONCE_LITE_IF'
11 | DO_ONCE_LITE_IF(true, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~
include/linux/printk.h:605:9: note: in expansion of macro 'DO_ONCE_LITE'
605 | DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:12:9: note: in expansion of macro 'printk_deferred_once'
12 | printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:18:17: note: in expansion of macro 'orc_warn'
18 | orc_warn(args); \
| ^~~~~~~~
arch/x86/kernel/unwind_orc.c:19:17: error: expected identifier or '(' before 'if'
19 | if (unwind_debug && !dumped_before) \
| ^~
arch/x86/kernel/unwind_orc.c:21:17: warning: data definition has no type or storage class
21 | dumped_before = true; \
| ^~~~~~~~~~~~~
>> arch/x86/kernel/unwind_orc.c:21:17: error: type defaults to 'int' in declaration of 'dumped_before' [-Werror=implicit-int]
>> arch/x86/kernel/unwind_orc.c:22:9: error: expected identifier or '(' before '}' token
22 | } \
| ^
arch/x86/kernel/unwind_orc.c:23:1: error: expected identifier or '(' before '}' token
23 | })
| ^
>> arch/x86/kernel/unwind_orc.c:23:2: error: expected identifier or '(' before ')' token
23 | })
| ^
arch/x86/kernel/unwind_orc.c: In function 'orc_find':
>> arch/x86/kernel/unwind_orc.c:219:35: error: '__start_orc_unwind_ip' undeclared (first use in this function); did you mean '__start_orc_unwind'?
219 | return __orc_find(__start_orc_unwind_ip + start,
| ^~~~~~~~~~~~~~~~~~~~~
| __start_orc_unwind
arch/x86/kernel/unwind_orc.c:219:35: note: each undeclared identifier is reported only once for each function it appears in
arch/x86/kernel/unwind_orc.c: At top level:
>> arch/x86/kernel/unwind_orc.c:239:32: error: '__start_orc_unwind_ip' undeclared here (not in a function); did you mean '__start_orc_unwind'?
239 | static int *cur_orc_ip_table = __start_orc_unwind_ip;
| ^~~~~~~~~~~~~~~~~~~~~
| __start_orc_unwind
arch/x86/kernel/unwind_orc.c: In function 'unwind_next_frame':
>> arch/x86/kernel/unwind_orc.c:534:18: error: expected ')' before 'break'
534 | }
| ^
| )
535 | break;
| ~~~~~
arch/x86/kernel/unwind_orc.c:16:21: warning: unused variable 'dumped_before' [-Wunused-variable]
16 | static bool dumped_before;
| ^~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:531:25: note: in expansion of macro 'orc_warn_current'
531 | orc_warn_current("missing R10 value at %pB\n",
| ^~~~~~~~~~~~~~~~
>> arch/x86/kernel/unwind_orc.c:767:1: error: expected declaration or statement at end of input
767 | EXPORT_SYMBOL_GPL(__unwind_start);
| ^~~~~~~~~~~~~~~~~
>> arch/x86/kernel/unwind_orc.c:767:1: error: expected declaration or statement at end of input
>> arch/x86/kernel/unwind_orc.c:767:1: error: expected declaration or statement at end of input
>> arch/x86/kernel/unwind_orc.c:533:25: error: label 'err' used but not defined
533 | goto err;
| ^~~~
>> arch/x86/kernel/unwind_orc.c:506:17: error: label 'the_end' used but not defined
506 | goto the_end;
| ^~~~
arch/x86/kernel/unwind_orc.c:468:14: warning: variable 'indirect' set but not used [-Wunused-but-set-variable]
468 | bool indirect = false;
| ^~~~~~~~
arch/x86/kernel/unwind_orc.c:466:25: warning: unused variable 'prev_type' [-Wunused-variable]
466 | enum stack_type prev_type = state->stack_info.type;
| ^~~~~~~~~
arch/x86/kernel/unwind_orc.c:465:59: warning: unused variable 'prev_sp' [-Wunused-variable]
465 | unsigned long ip_p, sp, tmp, orig_ip = state->ip, prev_sp = state->sp;
| ^~~~~~~
arch/x86/kernel/unwind_orc.c:465:38: warning: unused variable 'orig_ip' [-Wunused-variable]
465 | unsigned long ip_p, sp, tmp, orig_ip = state->ip, prev_sp = state->sp;
| ^~~~~~~
arch/x86/kernel/unwind_orc.c:465:33: warning: unused variable 'tmp' [-Wunused-variable]
465 | unsigned long ip_p, sp, tmp, orig_ip = state->ip, prev_sp = state->sp;
| ^~~
arch/x86/kernel/unwind_orc.c:465:23: warning: unused variable 'ip_p' [-Wunused-variable]
465 | unsigned long ip_p, sp, tmp, orig_ip = state->ip, prev_sp = state->sp;
| ^~~~
arch/x86/kernel/unwind_orc.c:768: error: control reaches end of non-void function [-Werror=return-type]
At top level:
arch/x86/kernel/unwind_orc.c:16:21: warning: 'dumped_before' defined but not used [-Wunused-variable]
16 | static bool dumped_before;
| ^~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:531:25: note: in expansion of macro 'orc_warn_current'
531 | orc_warn_current("missing R10 value at %pB\n",
| ^~~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:421:13: warning: 'deref_stack_iret_regs' defined but not used [-Wunused-function]
421 | static bool deref_stack_iret_regs(struct unwind_state *state, unsigned long addr,
| ^~~~~~~~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:405:13: warning: 'deref_stack_regs' defined but not used [-Wunused-function]
405 | static bool deref_stack_regs(struct unwind_state *state, unsigned long addr,
| ^~~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:395:13: warning: 'deref_stack_reg' defined but not used [-Wunused-function]
395 | static bool deref_stack_reg(struct unwind_state *state, unsigned long addr,
| ^~~~~~~~~~~~~~~
arch/x86/kernel/unwind_orc.c:42:13: warning: 'unwind_dump' defined but not used [-Wunused-function]
42 | static void unwind_dump(struct unwind_state *state)
| ^~~~~~~~~~~
cc1: some warnings being treated as errors


vim +17 arch/x86/kernel/unwind_orc.c

ee9f8fce996408 Josh Poimboeuf 2017-07-24 10
ee9f8fce996408 Josh Poimboeuf 2017-07-24 11 #define orc_warn(fmt, ...) \
b08418b5483125 Josh Poimboeuf 2020-04-25 12 printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
b08418b5483125 Josh Poimboeuf 2020-04-25 13
b08418b5483125 Josh Poimboeuf 2020-04-25 14 #define orc_warn_current(args...) \
b08418b5483125 Josh Poimboeuf 2020-04-25 15 ({ \
3295e738f5b51f Josh Poimboeuf 2022-08-15 @16 static bool dumped_before;
b59cc97674c947 Josh Poimboeuf 2021-02-05 @17 if (state->task == current && !state->error) \
b08418b5483125 Josh Poimboeuf 2020-04-25 @18 orc_warn(args); \
3295e738f5b51f Josh Poimboeuf 2022-08-15 @19 if (unwind_debug && !dumped_before) \
3295e738f5b51f Josh Poimboeuf 2022-08-15 20 unwind_dump(state); \
3295e738f5b51f Josh Poimboeuf 2022-08-15 @21 dumped_before = true; \
3295e738f5b51f Josh Poimboeuf 2022-08-15 @22 } \
b08418b5483125 Josh Poimboeuf 2020-04-25 @23 })
ee9f8fce996408 Josh Poimboeuf 2017-07-24 24

--
0-DAY CI Kernel Test Service
https://01.org/lkp

2022-08-17 03:07:03

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] x86/unwind/orc: Add 'unwind_debug' cmdline option

Hi Chen,

I love your patch! Perhaps something to improve:

[auto build test WARNING on tip/x86/core]
[also build test WARNING on clk/clk-next linus/master v6.0-rc1 next-20220816]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Chen-Zhongjin/x86-unwind-orc-Add-unwind_debug-cmdline-option/20220815-190328
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git a1a5482a2c6e38a3ebed32e571625c56a8cc41a6
config: x86_64-randconfig-a012-20220815
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6afcc4a459ead8809a0d6d9b4bf7b64bcc13582b)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/3295e738f5b51f1f1f223bf52a8ecee2ab93fbca
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Chen-Zhongjin/x86-unwind-orc-Add-unwind_debug-cmdline-option/20220815-190328
git checkout 3295e738f5b51f1f1f223bf52a8ecee2ab93fbca
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash arch/x86/kernel/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

arch/x86/kernel/unwind_orc.c:17:2: error: expected identifier or '('
if (state->task == current && !state->error) \
^
arch/x86/kernel/unwind_orc.c:19:3: error: expected identifier or '('
if (unwind_debug && !dumped_before) \
^
arch/x86/kernel/unwind_orc.c:21:3: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
dumped_before = true; \
^
int
arch/x86/kernel/unwind_orc.c:22:2: error: extraneous closing brace ('}')
} \
^
arch/x86/kernel/unwind_orc.c:22:11: error: extraneous closing brace ('}')
} \
^
arch/x86/kernel/unwind_orc.c:23:2: error: expected identifier or '('
})
^
arch/x86/kernel/unwind_orc.c:219:21: error: use of undeclared identifier '__start_orc_unwind_ip'
return __orc_find(__start_orc_unwind_ip + start,
^
arch/x86/kernel/unwind_orc.c:225:21: error: use of undeclared identifier '__start_orc_unwind_ip'
return __orc_find(__start_orc_unwind_ip, __start_orc_unwind,
^
arch/x86/kernel/unwind_orc.c:226:30: error: use of undeclared identifier '__start_orc_unwind_ip'
__stop_orc_unwind_ip - __start_orc_unwind_ip, ip);
^
arch/x86/kernel/unwind_orc.c:239:32: error: use of undeclared identifier '__start_orc_unwind_ip'
static int *cur_orc_ip_table = __start_orc_unwind_ip;
^
arch/x86/kernel/unwind_orc.c:314:62: error: use of undeclared identifier '__start_orc_unwind_ip'
size_t orc_ip_size = (void *)__stop_orc_unwind_ip - (void *)__start_orc_unwind_ip;
^
arch/x86/kernel/unwind_orc.c:336:20: error: use of undeclared identifier '__start_orc_unwind_ip'
orc = __orc_find(__start_orc_unwind_ip, __start_orc_unwind,
^
arch/x86/kernel/unwind_orc.c:348:19: error: use of undeclared identifier '__start_orc_unwind_ip'
orc = __orc_find(__start_orc_unwind_ip, __start_orc_unwind, num_entries,
^
>> arch/x86/kernel/unwind_orc.c:531:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("missing R10 value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:535:3: error: expected ')'
break;
^
arch/x86/kernel/unwind_orc.c:531:4: note: to match this '('
orc_warn_current("missing R10 value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:539:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("missing R13 value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:543:3: error: expected ')'
break;
^
arch/x86/kernel/unwind_orc.c:539:4: note: to match this '('
orc_warn_current("missing R13 value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:547:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("missing RDI value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:551:3: error: expected ')'
break;
^
arch/x86/kernel/unwind_orc.c:547:4: note: to match this '('
orc_warn_current("missing RDI value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:555:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("missing DX value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:559:3: error: expected ')'
break;
^
arch/x86/kernel/unwind_orc.c:555:4: note: to match this '('
orc_warn_current("missing DX value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:593:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("can't access registers at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:607:3: error: expected ')'
state->ip = unwind_recover_rethook(state, state->ip,
^
arch/x86/kernel/unwind_orc.c:593:4: note: to match this '('
orc_warn_current("can't access registers at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:617:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("can't access iret registers at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:622:3: error: expected ')'
state->ip = unwind_recover_rethook(state, state->ip,
^
arch/x86/kernel/unwind_orc.c:617:4: note: to match this '('
orc_warn_current("can't access iret registers at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:665:3: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("stack going in the wrong direction? at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
7 warnings and 20 errors generated.


vim +/dumped_before +531 arch/x86/kernel/unwind_orc.c

81b67439d14767 Josh Poimboeuf 2020-04-25 462
ee9f8fce996408 Josh Poimboeuf 2017-07-24 463 bool unwind_next_frame(struct unwind_state *state)
ee9f8fce996408 Josh Poimboeuf 2017-07-24 464 {
81b67439d14767 Josh Poimboeuf 2020-04-25 465 unsigned long ip_p, sp, tmp, orig_ip = state->ip, prev_sp = state->sp;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 466 enum stack_type prev_type = state->stack_info.type;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 467 struct orc_entry *orc;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 468 bool indirect = false;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 469
ee9f8fce996408 Josh Poimboeuf 2017-07-24 470 if (unwind_done(state))
ee9f8fce996408 Josh Poimboeuf 2017-07-24 471 return false;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 472
ee9f8fce996408 Josh Poimboeuf 2017-07-24 473 /* Don't let modules unload while we're reading their ORC data. */
ee9f8fce996408 Josh Poimboeuf 2017-07-24 474 preempt_disable();
ee9f8fce996408 Josh Poimboeuf 2017-07-24 475
d31a580266eeb1 Josh Poimboeuf 2018-05-18 476 /* End-of-stack check for user tasks: */
ee9f8fce996408 Josh Poimboeuf 2017-07-24 477 if (state->regs && user_mode(state->regs))
d31a580266eeb1 Josh Poimboeuf 2018-05-18 478 goto the_end;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 479
ee9f8fce996408 Josh Poimboeuf 2017-07-24 480 /*
ee9f8fce996408 Josh Poimboeuf 2017-07-24 481 * Find the orc_entry associated with the text address.
ee9f8fce996408 Josh Poimboeuf 2017-07-24 482 *
372a8eaa05998c Josh Poimboeuf 2020-07-17 483 * For a call frame (as opposed to a signal frame), state->ip points to
372a8eaa05998c Josh Poimboeuf 2020-07-17 484 * the instruction after the call. That instruction's stack layout
372a8eaa05998c Josh Poimboeuf 2020-07-17 485 * could be different from the call instruction's layout, for example
372a8eaa05998c Josh Poimboeuf 2020-07-17 486 * if the call was to a noreturn function. So get the ORC data for the
372a8eaa05998c Josh Poimboeuf 2020-07-17 487 * call instruction itself.
ee9f8fce996408 Josh Poimboeuf 2017-07-24 488 */
ee9f8fce996408 Josh Poimboeuf 2017-07-24 489 orc = orc_find(state->signal ? state->ip : state->ip - 1);
ae6a45a0868986 Josh Poimboeuf 2019-06-26 490 if (!orc) {
ae6a45a0868986 Josh Poimboeuf 2019-06-26 491 /*
ae6a45a0868986 Josh Poimboeuf 2019-06-26 492 * As a fallback, try to assume this code uses a frame pointer.
ae6a45a0868986 Josh Poimboeuf 2019-06-26 493 * This is useful for generated code, like BPF, which ORC
ae6a45a0868986 Josh Poimboeuf 2019-06-26 494 * doesn't know about. This is just a guess, so the rest of
ae6a45a0868986 Josh Poimboeuf 2019-06-26 495 * the unwind is no longer considered reliable.
ae6a45a0868986 Josh Poimboeuf 2019-06-26 496 */
ae6a45a0868986 Josh Poimboeuf 2019-06-26 497 orc = &orc_fp_entry;
ae6a45a0868986 Josh Poimboeuf 2019-06-26 498 state->error = true;
ae6a45a0868986 Josh Poimboeuf 2019-06-26 499 }
d31a580266eeb1 Josh Poimboeuf 2018-05-18 500
d31a580266eeb1 Josh Poimboeuf 2018-05-18 501 /* End-of-stack check for kernel threads: */
d31a580266eeb1 Josh Poimboeuf 2018-05-18 502 if (orc->sp_reg == ORC_REG_UNDEFINED) {
d31a580266eeb1 Josh Poimboeuf 2018-05-18 503 if (!orc->end)
d31a580266eeb1 Josh Poimboeuf 2018-05-18 504 goto err;
d31a580266eeb1 Josh Poimboeuf 2018-05-18 505
d31a580266eeb1 Josh Poimboeuf 2018-05-18 506 goto the_end;
d31a580266eeb1 Josh Poimboeuf 2018-05-18 507 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 508
ee9f8fce996408 Josh Poimboeuf 2017-07-24 509 /* Find the previous frame's stack: */
ee9f8fce996408 Josh Poimboeuf 2017-07-24 510 switch (orc->sp_reg) {
ee9f8fce996408 Josh Poimboeuf 2017-07-24 511 case ORC_REG_SP:
ee9f8fce996408 Josh Poimboeuf 2017-07-24 512 sp = state->sp + orc->sp_offset;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 513 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 514
ee9f8fce996408 Josh Poimboeuf 2017-07-24 515 case ORC_REG_BP:
ee9f8fce996408 Josh Poimboeuf 2017-07-24 516 sp = state->bp + orc->sp_offset;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 517 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 518
ee9f8fce996408 Josh Poimboeuf 2017-07-24 519 case ORC_REG_SP_INDIRECT:
87ccc826bf1c9e Peter Zijlstra 2021-02-03 520 sp = state->sp;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 521 indirect = true;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 522 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 523
ee9f8fce996408 Josh Poimboeuf 2017-07-24 524 case ORC_REG_BP_INDIRECT:
ee9f8fce996408 Josh Poimboeuf 2017-07-24 525 sp = state->bp + orc->sp_offset;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 526 indirect = true;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 527 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 528
ee9f8fce996408 Josh Poimboeuf 2017-07-24 529 case ORC_REG_R10:
81b67439d14767 Josh Poimboeuf 2020-04-25 530 if (!get_reg(state, offsetof(struct pt_regs, r10), &sp)) {
b08418b5483125 Josh Poimboeuf 2020-04-25 @531 orc_warn_current("missing R10 value at %pB\n",
ee9f8fce996408 Josh Poimboeuf 2017-07-24 532 (void *)state->ip);
d31a580266eeb1 Josh Poimboeuf 2018-05-18 533 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 534 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 535 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 536
ee9f8fce996408 Josh Poimboeuf 2017-07-24 537 case ORC_REG_R13:
81b67439d14767 Josh Poimboeuf 2020-04-25 538 if (!get_reg(state, offsetof(struct pt_regs, r13), &sp)) {
b08418b5483125 Josh Poimboeuf 2020-04-25 539 orc_warn_current("missing R13 value at %pB\n",
ee9f8fce996408 Josh Poimboeuf 2017-07-24 540 (void *)state->ip);
d31a580266eeb1 Josh Poimboeuf 2018-05-18 541 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 542 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 543 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 544
ee9f8fce996408 Josh Poimboeuf 2017-07-24 545 case ORC_REG_DI:
81b67439d14767 Josh Poimboeuf 2020-04-25 546 if (!get_reg(state, offsetof(struct pt_regs, di), &sp)) {
b08418b5483125 Josh Poimboeuf 2020-04-25 547 orc_warn_current("missing RDI value at %pB\n",
ee9f8fce996408 Josh Poimboeuf 2017-07-24 548 (void *)state->ip);
d31a580266eeb1 Josh Poimboeuf 2018-05-18 549 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 550 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 551 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 552
ee9f8fce996408 Josh Poimboeuf 2017-07-24 553 case ORC_REG_DX:
81b67439d14767 Josh Poimboeuf 2020-04-25 554 if (!get_reg(state, offsetof(struct pt_regs, dx), &sp)) {
b08418b5483125 Josh Poimboeuf 2020-04-25 555 orc_warn_current("missing DX value at %pB\n",
ee9f8fce996408 Josh Poimboeuf 2017-07-24 556 (void *)state->ip);
d31a580266eeb1 Josh Poimboeuf 2018-05-18 557 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 558 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 559 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 560
ee9f8fce996408 Josh Poimboeuf 2017-07-24 561 default:
b08418b5483125 Josh Poimboeuf 2020-04-25 562 orc_warn("unknown SP base reg %d at %pB\n",
ee9f8fce996408 Josh Poimboeuf 2017-07-24 563 orc->sp_reg, (void *)state->ip);
d31a580266eeb1 Josh Poimboeuf 2018-05-18 564 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 565 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 566
ee9f8fce996408 Josh Poimboeuf 2017-07-24 567 if (indirect) {
ee9f8fce996408 Josh Poimboeuf 2017-07-24 568 if (!deref_stack_reg(state, sp, &sp))
d31a580266eeb1 Josh Poimboeuf 2018-05-18 569 goto err;
87ccc826bf1c9e Peter Zijlstra 2021-02-03 570
87ccc826bf1c9e Peter Zijlstra 2021-02-03 571 if (orc->sp_reg == ORC_REG_SP_INDIRECT)
87ccc826bf1c9e Peter Zijlstra 2021-02-03 572 sp += orc->sp_offset;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 573 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 574
ee9f8fce996408 Josh Poimboeuf 2017-07-24 575 /* Find IP, SP and possibly regs: */
ee9f8fce996408 Josh Poimboeuf 2017-07-24 576 switch (orc->type) {
ee819aedf34a8f Julien Thierry 2020-09-04 577 case UNWIND_HINT_TYPE_CALL:
ee9f8fce996408 Josh Poimboeuf 2017-07-24 578 ip_p = sp - sizeof(long);
ee9f8fce996408 Josh Poimboeuf 2017-07-24 579
ee9f8fce996408 Josh Poimboeuf 2017-07-24 580 if (!deref_stack_reg(state, ip_p, &state->ip))
d31a580266eeb1 Josh Poimboeuf 2018-05-18 581 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 582
19138af1bd880d Masami Hiramatsu 2021-09-14 583 state->ip = unwind_recover_ret_addr(state, state->ip,
19138af1bd880d Masami Hiramatsu 2021-09-14 584 (unsigned long *)ip_p);
ee9f8fce996408 Josh Poimboeuf 2017-07-24 585 state->sp = sp;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 586 state->regs = NULL;
81b67439d14767 Josh Poimboeuf 2020-04-25 587 state->prev_regs = NULL;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 588 state->signal = false;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 589 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 590
ee819aedf34a8f Julien Thierry 2020-09-04 591 case UNWIND_HINT_TYPE_REGS:
b02fcf9ba12110 Josh Poimboeuf 2017-12-04 592 if (!deref_stack_regs(state, sp, &state->ip, &state->sp)) {
b08418b5483125 Josh Poimboeuf 2020-04-25 593 orc_warn_current("can't access registers at %pB\n",
b08418b5483125 Josh Poimboeuf 2020-04-25 594 (void *)orig_ip);
d31a580266eeb1 Josh Poimboeuf 2018-05-18 595 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 596 }
19138af1bd880d Masami Hiramatsu 2021-09-14 597 /*
19138af1bd880d Masami Hiramatsu 2021-09-14 598 * There is a small chance to interrupt at the entry of
f3a112c0c40dd9 Masami Hiramatsu 2022-03-26 599 * arch_rethook_trampoline() where the ORC info doesn't exist.
f3a112c0c40dd9 Masami Hiramatsu 2022-03-26 600 * That point is right after the RET to arch_rethook_trampoline()
19138af1bd880d Masami Hiramatsu 2021-09-14 601 * which was modified return address.
f3a112c0c40dd9 Masami Hiramatsu 2022-03-26 602 * At that point, the @addr_p of the unwind_recover_rethook()
19138af1bd880d Masami Hiramatsu 2021-09-14 603 * (this has to point the address of the stack entry storing
19138af1bd880d Masami Hiramatsu 2021-09-14 604 * the modified return address) must be "SP - (a stack entry)"
19138af1bd880d Masami Hiramatsu 2021-09-14 605 * because SP is incremented by the RET.
19138af1bd880d Masami Hiramatsu 2021-09-14 606 */
f3a112c0c40dd9 Masami Hiramatsu 2022-03-26 607 state->ip = unwind_recover_rethook(state, state->ip,
19138af1bd880d Masami Hiramatsu 2021-09-14 608 (unsigned long *)(state->sp - sizeof(long)));
ee9f8fce996408 Josh Poimboeuf 2017-07-24 609 state->regs = (struct pt_regs *)sp;
81b67439d14767 Josh Poimboeuf 2020-04-25 610 state->prev_regs = NULL;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 611 state->full_regs = true;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 612 state->signal = true;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 613 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 614
ee819aedf34a8f Julien Thierry 2020-09-04 615 case UNWIND_HINT_TYPE_REGS_PARTIAL:
b02fcf9ba12110 Josh Poimboeuf 2017-12-04 616 if (!deref_stack_iret_regs(state, sp, &state->ip, &state->sp)) {
b08418b5483125 Josh Poimboeuf 2020-04-25 617 orc_warn_current("can't access iret registers at %pB\n",
b08418b5483125 Josh Poimboeuf 2020-04-25 618 (void *)orig_ip);
d31a580266eeb1 Josh Poimboeuf 2018-05-18 619 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 620 }
19138af1bd880d Masami Hiramatsu 2021-09-14 621 /* See UNWIND_HINT_TYPE_REGS case comment. */
f3a112c0c40dd9 Masami Hiramatsu 2022-03-26 622 state->ip = unwind_recover_rethook(state, state->ip,
19138af1bd880d Masami Hiramatsu 2021-09-14 623 (unsigned long *)(state->sp - sizeof(long)));
ee9f8fce996408 Josh Poimboeuf 2017-07-24 624
81b67439d14767 Josh Poimboeuf 2020-04-25 625 if (state->full_regs)
81b67439d14767 Josh Poimboeuf 2020-04-25 626 state->prev_regs = state->regs;
b02fcf9ba12110 Josh Poimboeuf 2017-12-04 627 state->regs = (void *)sp - IRET_FRAME_OFFSET;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 628 state->full_regs = false;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 629 state->signal = true;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 630 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 631
ee9f8fce996408 Josh Poimboeuf 2017-07-24 632 default:
b08418b5483125 Josh Poimboeuf 2020-04-25 633 orc_warn("unknown .orc_unwind entry type %d at %pB\n",
58c3862b521ead Josh Poimboeuf 2017-10-20 634 orc->type, (void *)orig_ip);
a0f81bf2688804 Josh Poimboeuf 2020-04-25 635 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 636 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 637
ee9f8fce996408 Josh Poimboeuf 2017-07-24 638 /* Find BP: */
ee9f8fce996408 Josh Poimboeuf 2017-07-24 639 switch (orc->bp_reg) {
ee9f8fce996408 Josh Poimboeuf 2017-07-24 640 case ORC_REG_UNDEFINED:
81b67439d14767 Josh Poimboeuf 2020-04-25 641 if (get_reg(state, offsetof(struct pt_regs, bp), &tmp))
81b67439d14767 Josh Poimboeuf 2020-04-25 642 state->bp = tmp;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 643 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 644
ee9f8fce996408 Josh Poimboeuf 2017-07-24 645 case ORC_REG_PREV_SP:
ee9f8fce996408 Josh Poimboeuf 2017-07-24 646 if (!deref_stack_reg(state, sp + orc->bp_offset, &state->bp))
d31a580266eeb1 Josh Poimboeuf 2018-05-18 647 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 648 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 649
ee9f8fce996408 Josh Poimboeuf 2017-07-24 650 case ORC_REG_BP:
ee9f8fce996408 Josh Poimboeuf 2017-07-24 651 if (!deref_stack_reg(state, state->bp + orc->bp_offset, &state->bp))
d31a580266eeb1 Josh Poimboeuf 2018-05-18 652 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 653 break;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 654
ee9f8fce996408 Josh Poimboeuf 2017-07-24 655 default:
58c3862b521ead Josh Poimboeuf 2017-10-20 656 orc_warn("unknown BP base reg %d for ip %pB\n",
ee9f8fce996408 Josh Poimboeuf 2017-07-24 657 orc->bp_reg, (void *)orig_ip);
d31a580266eeb1 Josh Poimboeuf 2018-05-18 658 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 659 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 660
ee9f8fce996408 Josh Poimboeuf 2017-07-24 661 /* Prevent a recursive loop due to bad ORC data: */
ee9f8fce996408 Josh Poimboeuf 2017-07-24 662 if (state->stack_info.type == prev_type &&
ee9f8fce996408 Josh Poimboeuf 2017-07-24 663 on_stack(&state->stack_info, (void *)state->sp, sizeof(long)) &&
ee9f8fce996408 Josh Poimboeuf 2017-07-24 664 state->sp <= prev_sp) {
b08418b5483125 Josh Poimboeuf 2020-04-25 665 orc_warn_current("stack going in the wrong direction? at %pB\n",
ee9f8fce996408 Josh Poimboeuf 2017-07-24 666 (void *)orig_ip);
d31a580266eeb1 Josh Poimboeuf 2018-05-18 667 goto err;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 668 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 669
ee9f8fce996408 Josh Poimboeuf 2017-07-24 670 preempt_enable();
ee9f8fce996408 Josh Poimboeuf 2017-07-24 671 return true;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 672
d31a580266eeb1 Josh Poimboeuf 2018-05-18 673 err:
d31a580266eeb1 Josh Poimboeuf 2018-05-18 674 state->error = true;
d31a580266eeb1 Josh Poimboeuf 2018-05-18 675
d31a580266eeb1 Josh Poimboeuf 2018-05-18 676 the_end:
ee9f8fce996408 Josh Poimboeuf 2017-07-24 677 preempt_enable();
ee9f8fce996408 Josh Poimboeuf 2017-07-24 678 state->stack_info.type = STACK_TYPE_UNKNOWN;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 679 return false;
ee9f8fce996408 Josh Poimboeuf 2017-07-24 680 }
ee9f8fce996408 Josh Poimboeuf 2017-07-24 681 EXPORT_SYMBOL_GPL(unwind_next_frame);
ee9f8fce996408 Josh Poimboeuf 2017-07-24 682

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (26.36 kB)
config (154.50 kB)
Download all attachments

2022-08-17 04:05:48

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] x86/unwind/orc: Add 'unwind_debug' cmdline option

Hi Chen,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on clk/clk-next linus/master v6.0-rc1 next-20220816]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Chen-Zhongjin/x86-unwind-orc-Add-unwind_debug-cmdline-option/20220815-190328
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git a1a5482a2c6e38a3ebed32e571625c56a8cc41a6
config: x86_64-randconfig-a012-20220815
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6afcc4a459ead8809a0d6d9b4bf7b64bcc13582b)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/3295e738f5b51f1f1f223bf52a8ecee2ab93fbca
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Chen-Zhongjin/x86-unwind-orc-Add-unwind_debug-cmdline-option/20220815-190328
git checkout 3295e738f5b51f1f1f223bf52a8ecee2ab93fbca
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> arch/x86/kernel/unwind_orc.c:17:2: error: expected identifier or '('
if (state->task == current && !state->error) \
^
arch/x86/kernel/unwind_orc.c:19:3: error: expected identifier or '('
if (unwind_debug && !dumped_before) \
^
>> arch/x86/kernel/unwind_orc.c:21:3: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
dumped_before = true; \
^
int
>> arch/x86/kernel/unwind_orc.c:22:2: error: extraneous closing brace ('}')
} \
^
arch/x86/kernel/unwind_orc.c:22:11: error: extraneous closing brace ('}')
} \
^
arch/x86/kernel/unwind_orc.c:23:2: error: expected identifier or '('
})
^
>> arch/x86/kernel/unwind_orc.c:219:21: error: use of undeclared identifier '__start_orc_unwind_ip'
return __orc_find(__start_orc_unwind_ip + start,
^
arch/x86/kernel/unwind_orc.c:225:21: error: use of undeclared identifier '__start_orc_unwind_ip'
return __orc_find(__start_orc_unwind_ip, __start_orc_unwind,
^
arch/x86/kernel/unwind_orc.c:226:30: error: use of undeclared identifier '__start_orc_unwind_ip'
__stop_orc_unwind_ip - __start_orc_unwind_ip, ip);
^
arch/x86/kernel/unwind_orc.c:239:32: error: use of undeclared identifier '__start_orc_unwind_ip'
static int *cur_orc_ip_table = __start_orc_unwind_ip;
^
arch/x86/kernel/unwind_orc.c:314:62: error: use of undeclared identifier '__start_orc_unwind_ip'
size_t orc_ip_size = (void *)__stop_orc_unwind_ip - (void *)__start_orc_unwind_ip;
^
arch/x86/kernel/unwind_orc.c:336:20: error: use of undeclared identifier '__start_orc_unwind_ip'
orc = __orc_find(__start_orc_unwind_ip, __start_orc_unwind,
^
arch/x86/kernel/unwind_orc.c:348:19: error: use of undeclared identifier '__start_orc_unwind_ip'
orc = __orc_find(__start_orc_unwind_ip, __start_orc_unwind, num_entries,
^
arch/x86/kernel/unwind_orc.c:531:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("missing R10 value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
>> arch/x86/kernel/unwind_orc.c:535:3: error: expected ')'
break;
^
arch/x86/kernel/unwind_orc.c:531:4: note: to match this '('
orc_warn_current("missing R10 value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:539:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("missing R13 value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:543:3: error: expected ')'
break;
^
arch/x86/kernel/unwind_orc.c:539:4: note: to match this '('
orc_warn_current("missing R13 value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:547:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("missing RDI value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:551:3: error: expected ')'
break;
^
arch/x86/kernel/unwind_orc.c:547:4: note: to match this '('
orc_warn_current("missing RDI value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:555:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("missing DX value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:559:3: error: expected ')'
break;
^
arch/x86/kernel/unwind_orc.c:555:4: note: to match this '('
orc_warn_current("missing DX value at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:593:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("can't access registers at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:607:3: error: expected ')'
state->ip = unwind_recover_rethook(state, state->ip,
^
arch/x86/kernel/unwind_orc.c:593:4: note: to match this '('
orc_warn_current("can't access registers at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:617:4: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("can't access iret registers at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
arch/x86/kernel/unwind_orc.c:622:3: error: expected ')'
state->ip = unwind_recover_rethook(state, state->ip,
^
arch/x86/kernel/unwind_orc.c:617:4: note: to match this '('
orc_warn_current("can't access iret registers at %pB\n",
^
arch/x86/kernel/unwind_orc.c:14:39: note: expanded from macro 'orc_warn_current'
#define orc_warn_current(args...) \
^
arch/x86/kernel/unwind_orc.c:665:3: warning: unused variable 'dumped_before' [-Wunused-variable]
orc_warn_current("stack going in the wrong direction? at %pB\n",
^
arch/x86/kernel/unwind_orc.c:16:14: note: expanded from macro 'orc_warn_current'
static bool dumped_before;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
7 warnings and 20 errors generated.


vim +17 arch/x86/kernel/unwind_orc.c

ee9f8fce996408 Josh Poimboeuf 2017-07-24 10
ee9f8fce996408 Josh Poimboeuf 2017-07-24 11 #define orc_warn(fmt, ...) \
b08418b5483125 Josh Poimboeuf 2020-04-25 12 printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
b08418b5483125 Josh Poimboeuf 2020-04-25 13
b08418b5483125 Josh Poimboeuf 2020-04-25 14 #define orc_warn_current(args...) \
b08418b5483125 Josh Poimboeuf 2020-04-25 15 ({ \
3295e738f5b51f Josh Poimboeuf 2022-08-15 16 static bool dumped_before;
b59cc97674c947 Josh Poimboeuf 2021-02-05 @17 if (state->task == current && !state->error) \
b08418b5483125 Josh Poimboeuf 2020-04-25 18 orc_warn(args); \
3295e738f5b51f Josh Poimboeuf 2022-08-15 19 if (unwind_debug && !dumped_before) \
3295e738f5b51f Josh Poimboeuf 2022-08-15 20 unwind_dump(state); \
3295e738f5b51f Josh Poimboeuf 2022-08-15 @21 dumped_before = true; \
3295e738f5b51f Josh Poimboeuf 2022-08-15 @22 } \
b08418b5483125 Josh Poimboeuf 2020-04-25 23 })
ee9f8fce996408 Josh Poimboeuf 2017-07-24 24

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (11.12 kB)
config (154.50 kB)
Download all attachments