[Crash-utility] [PATCH v2] x86_64: VC exception stack support

HAGIO KAZUHITO(萩尾 一仁) k-hagio-ab at nec.com
Wed Nov 25 04:50:27 UTC 2020


Hi Alexey,

Thanks for updating this patch.

-----Original Message-----
> Linux-5.10 has introduced SEV-ES support. New (5th) exception
> stack was added: 'VC_stack'.
> 
> 'struct exception_stacks' cannot be used to obtain size of
> VC stack, as it equals zero there. Try another structure
> 'struct cea_exception_stacks' first as it represents actual
> CPU entry area with valid stack sizes and guard pages.
> 
> Added check for the case when VC stack is not mapped.
> It happens when SEV-ES is not active or not supported.

Seems one more check for "bt -E" is needed.

crash> bt -E
...
CPU 0 VC EXCEPTION STACK:
bt: invalid kernel virtual address: fffffe0000011000  type: "stack contents"
bt: read of stack at fffffe0000011000 failed

> 
> Signed-off-by: Alexey Makhalov <amakhalov at vmware.com>
> ---
>  x86_64.c | 29 ++++++++++++++++++++++++-----
>  1 file changed, 24 insertions(+), 5 deletions(-)
> 
> diff --git a/x86_64.c b/x86_64.c
> index fc05e8a..6160305 100644
> --- a/x86_64.c
> +++ b/x86_64.c
> @@ -1367,6 +1367,7 @@ x86_64_ist_init(void)
>  	ulong init_tss;
>  	struct machine_specific *ms;
>  	struct syment *boot_sp, *tss_sp, *ist_sp;
> +	char *exc_stack_struct_name = NULL;
> 
>          ms = machdep->machspec;
>  	if (!(tss_sp = per_cpu_symbol_search("per_cpu__init_tss"))) {
> @@ -1442,16 +1443,25 @@ x86_64_ist_init(void)
>  		return;
>  	}
> 
> -	if (MEMBER_EXISTS("exception_stacks", "NMI_stack")) {
> +	if (MEMBER_EXISTS("cea_exception_stacks", "NMI_stack")) {
> +		/* The effective cpu entry area mapping with guard pages. */
> +		exc_stack_struct_name = "cea_exception_stacks";
> +	} else if (MEMBER_EXISTS("exception_stacks", "NMI_stack")) {
> +		/* The exception stacks' physical storage. No guard pages and no VC stack. */
> +		exc_stack_struct_name = "exception_stacks";
> +	}
> +	if (exc_stack_struct_name) {
>                  for (i = 0; i < MAX_EXCEPTION_STACKS; i++) {
>  			if (STREQ(ms->stkinfo.exception_stacks[i], "DEBUG"))
> -				ms->stkinfo.esize[i] = MEMBER_SIZE("exception_stacks", "DB_stack");
> +				ms->stkinfo.esize[i] = MEMBER_SIZE(exc_stack_struct_name, "DB_stack");
>  			else if (STREQ(ms->stkinfo.exception_stacks[i], "NMI"))
> -				ms->stkinfo.esize[i] = MEMBER_SIZE("exception_stacks", "NMI_stack");
> +				ms->stkinfo.esize[i] = MEMBER_SIZE(exc_stack_struct_name, "NMI_stack");
>  			else if (STREQ(ms->stkinfo.exception_stacks[i], "DOUBLEFAULT"))
> -				ms->stkinfo.esize[i] = MEMBER_SIZE("exception_stacks", "DF_stack");
> +				ms->stkinfo.esize[i] = MEMBER_SIZE(exc_stack_struct_name, "DF_stack");
>  			else if (STREQ(ms->stkinfo.exception_stacks[i], "MCE"))
> -				ms->stkinfo.esize[i] = MEMBER_SIZE("exception_stacks", "MCE_stack");
> +				ms->stkinfo.esize[i] = MEMBER_SIZE(exc_stack_struct_name, "MCE_stack");
> +			else if (STREQ(ms->stkinfo.exception_stacks[i], "VC"))
> +				ms->stkinfo.esize[i] = MEMBER_SIZE(exc_stack_struct_name, "VC_stack");
>  		}
>  		/*
>  	 	 *  Adjust the top-of-stack addresses down to the base stack address.
> @@ -5092,6 +5102,13 @@ skip_stage:
>  			ms->stkinfo.exception_stacks[estack], bt->stackbase);
>  		if (!(bt->stackbase))
>  			goto skip_stage;
> +		/* VC stack can be unmapped if SEV-ES is inactive. */
> +		if (STREQ(ms->stkinfo.exception_stacks[estack], "VC")) {
> +			physaddr_t phys;
> +			/* Skip this stack if page is not present. */
> +			if (!kvtop(NULL, bt->stackbase, &phys, 0))

Nitpicking, kvtop() accepts NULL for paddr. (or there is also accessible())

Thanks,
Kazu

> +				goto skip_stage;
> +		}
>  		bt->stackbuf = ms->irqstack;
>  		alter_stackbuf(bt);
>  		in_nmi_stack = STREQ(ms->stkinfo.exception_stacks[estack], "NMI");
> @@ -5373,6 +5390,8 @@ x86_64_exception_stacks_init(void)
>  				ms->stkinfo.exception_stacks[ist-1] = "DOUBLEFAULT";
>  			if (strstr(buf, "machine"))
>  				ms->stkinfo.exception_stacks[ist-1] = "MCE";
> +			if (strstr(buf, "vmm"))
> +				ms->stkinfo.exception_stacks[ist-1] = "VC";
>  		}
>  	}
> 
> --
> 2.11.0





More information about the Crash-utility mailing list