Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp567957pxb; Wed, 15 Sep 2021 08:20:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcto19lIrxRchZpjB0lGDeJxJvr1vZ8VlBwB37AdxQa5eWa87TqJuR8agWc1lkzTtIpzOm X-Received: by 2002:a6b:b2d4:: with SMTP id b203mr436960iof.179.1631719231468; Wed, 15 Sep 2021 08:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631719231; cv=none; d=google.com; s=arc-20160816; b=iOPWi7NQKm7hC0RT5ZrjwSPpTPld6EGXw8cUjahHfQoI1l0/mqamhW/OWWgPoYEY0K SYf7m25TrNsd5NfRY3qA9h3tqf+dKFNZVsoLDhfzhcYLC0wOEwHowpv+epouXiu7oz/7 qXrAAhXlOztRzv3KjU5lnf282GitGnltXOgMVwVBoYx/qrFcSE2OOgIpVEA7QpGf0hAl Z+C5S6DaL7T0fvybS3Xig7Xnu054+KUEv+iI9jofKD9ln3rbFwHHN/vANouJvlzTlVwP 7rcclWovhKXLOpDGOOXBb6JIAZaSnFugV/mRcGUzVlgSfFm63Ca4xeA3ciLHQWmrGQGE y17w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lE5kf7OISKlmTZmmgfiMeKh8f7VRtSv6f6uAFhkQPd8=; b=D07NPGXfeiY+KC9HKObuNRKMzc4D9tOL00vVKX389qeb9TYyZHLLRp9557azx/FLtn G4i2aE5oFivJffChFZSJ5RfUkQXTP9ZexzU3nTo2gtrNCSg5wEvcfQ4upXNkzbkh+MC7 Guyj8VQnhaT1KST3vmB5x6M+2RN43waiFO/dtkvKFBxj8bx0fNkNfyg5jHme+LynCMKi c92Vbb2T407Ovi0b6GlnOEDPstBOLiapWy0txFhpS9Y1f7WCrc+Mh64A1cNWCCWA/tky 1PaTlc+mJoolz7AstTCxB8Eby2+YzYILiPtUtbxzT26OlP0TYMPb+qbgOWiI7jBL0amr 8Uow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=DTnmtBm9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s63si122702jaa.30.2021.09.15.08.20.18; Wed, 15 Sep 2021 08:20:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=DTnmtBm9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234177AbhIOPTT (ORCPT + 99 others); Wed, 15 Sep 2021 11:19:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234219AbhIOPTG (ORCPT ); Wed, 15 Sep 2021 11:19:06 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79441C061574; Wed, 15 Sep 2021 08:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=lE5kf7OISKlmTZmmgfiMeKh8f7VRtSv6f6uAFhkQPd8=; b=DTnmtBm9d6aGHwLICCv1Mnk1Tl 0rdkj6iZwR7Ylr4AsvspVewzAMlj7CHujgfTbyerJW03D+ClesOlIPv020grFF39Pbn6CXcyNKgIY UUYmrSv8oK1Tl0HwYwgVWJZzk/umB9Z1ntJiUn0pgNo7Ibih5RtXkhD3OZbBnL2NYC61PVv6mqdpI 9bh8KjBdnJLXsORzvImv2pbm9UeMhhTMP5aXtrk16Jm+QkOZNXa3caoNnfIyOodp/A2vxhWJcz4++ tFrHDYrthotUHlTI5mI5zjChbBp4s+TdGfs0jFaaMdQgFXKSuAtNHgLhU0AjbfDbnSgTBBkC1mDXl N9Psv2UQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQWf6-003QAE-CY; Wed, 15 Sep 2021 15:17:24 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 45A7730003A; Wed, 15 Sep 2021 17:17:22 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1D05220CB3027; Wed, 15 Sep 2021 17:17:22 +0200 (CEST) Date: Wed, 15 Sep 2021 17:17:22 +0200 From: Peter Zijlstra To: =?utf-8?B?546L6LSH?= Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "open list:PERFORMANCE EVENTS SUBSYSTEM" , "open list:PERFORMANCE EVENTS SUBSYSTEM" , "open list:BPF (Safe dynamic programs and tools)" , "open list:BPF (Safe dynamic programs and tools)" , jroedel@suse.de, x86@kernel.org Subject: [PATCH] x86/dumpstack/64: Add guard pages to stack_info Message-ID: References: <20210910153839.GH4323@worktop.programming.kicks-ass.net> <3fb7c51f-696b-da70-1965-1dda9910cb14@linux.alibaba.com> <3f26f7a2-0a09-056a-3a7a-4795b6723b60@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3f26f7a2-0a09-056a-3a7a-4795b6723b60@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 15, 2021 at 09:51:57AM +0800, 王贇 wrote: > > + > > + if (in_exception_stack_guard((void *)address)) > > + pr_emerg("PANIC: exception stack guard: 0x%lx\n", address); > > #endif > > > > pr_emerg("PANIC: double fault, error_code: 0x%lx\n", error_code); > > > > The panic triggered as below after the stack size recovered, I found this info > could be helpful, maybe we should keep it? Could you please test this? --- Subject: x86/dumpstack/64: Add guard pages to stack_info From: Peter Zijlstra Date: Wed Sep 15 17:12:59 CEST 2021 Explicitly add the exception stack guard pages to stack_info and report on them from #DF. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/cpu_entry_area.h | 3 +++ arch/x86/include/asm/stacktrace.h | 3 ++- arch/x86/kernel/dumpstack_64.c | 17 ++++++++++++++++- arch/x86/kernel/traps.c | 17 ++++++++++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) --- a/arch/x86/include/asm/cpu_entry_area.h +++ b/arch/x86/include/asm/cpu_entry_area.h @@ -61,6 +61,9 @@ enum exception_stack_ordering { #define CEA_ESTACK_OFFS(st) \ offsetof(struct cea_exception_stacks, st## _stack) +#define CEA_EGUARD_OFFS(st) \ + offsetof(struct cea_exception_stacks, st## _stack_guard) + #define CEA_ESTACK_PAGES \ (sizeof(struct cea_exception_stacks) / PAGE_SIZE) --- a/arch/x86/include/asm/stacktrace.h +++ b/arch/x86/include/asm/stacktrace.h @@ -14,13 +14,14 @@ #include enum stack_type { - STACK_TYPE_UNKNOWN, + STACK_TYPE_UNKNOWN = 0, STACK_TYPE_TASK, STACK_TYPE_IRQ, STACK_TYPE_SOFTIRQ, STACK_TYPE_ENTRY, STACK_TYPE_EXCEPTION, STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1, + STACK_TYPE_GUARD = 0x80, }; struct stack_info { --- a/arch/x86/kernel/dumpstack_64.c +++ b/arch/x86/kernel/dumpstack_64.c @@ -32,9 +32,15 @@ const char *stack_type_name(enum stack_t { BUILD_BUG_ON(N_EXCEPTION_STACKS != 6); + if (type == STACK_TYPE_TASK) + return "TASK"; + if (type == STACK_TYPE_IRQ) return "IRQ"; + if (type == STACK_TYPE_SOFTIRQ) + return "SOFTIRQ"; + if (type == STACK_TYPE_ENTRY) { /* * On 64-bit, we have a generic entry stack that we @@ -63,6 +69,11 @@ struct estack_pages { }; #define EPAGERANGE(st) \ + [PFN_DOWN(CEA_EGUARD_OFFS(st))] = { \ + .offs = CEA_EGUARD_OFFS(st), \ + .size = PAGE_SIZE, \ + .type = STACK_TYPE_GUARD + \ + STACK_TYPE_EXCEPTION + ESTACK_ ##st, }, \ [PFN_DOWN(CEA_ESTACK_OFFS(st)) ... \ PFN_DOWN(CEA_ESTACK_OFFS(st) + CEA_ESTACK_SIZE(st) - 1)] = { \ .offs = CEA_ESTACK_OFFS(st), \ @@ -111,10 +122,11 @@ static __always_inline bool in_exception k = (stk - begin) >> PAGE_SHIFT; /* Lookup the page descriptor */ ep = &estack_pages[k]; - /* Guard page? */ + /* unknown entry */ if (!ep->size) return false; + begin += (unsigned long)ep->offs; end = begin + (unsigned long)ep->size; regs = (struct pt_regs *)end - 1; @@ -193,6 +205,9 @@ int get_stack_info(unsigned long *stack, if (!get_stack_info_noinstr(stack, task, info)) goto unknown; + if (info->type & STACK_TYPE_GUARD) + goto unknown; + /* * Make sure we don't iterate through any given stack more than once. * If it comes up a second time then there's something wrong going on: --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -461,6 +461,19 @@ DEFINE_IDTENTRY_DF(exc_double_fault) } #endif +#ifdef CONFIG_X86_64 + { + struct stack_info info; + + if (get_stack_info_noinstr((void *)address, current, &info) && + info.type & STACK_TYPE_GUARD) { + const char *name = stack_type_name(info.type & ~STACK_TYPE_GUARD); + pr_emerg("BUG: %s stack guard hit at %p (stack is %p..%p)\n", + name, (void *)address, info.begin, info.end); + } + } +#endif + pr_emerg("PANIC: double fault, error_code: 0x%lx\n", error_code); die("double fault", regs, error_code); panic("Machine halted."); @@ -708,7 +721,9 @@ asmlinkage __visible noinstr struct pt_r sp = regs->sp; stack = (unsigned long *)sp; - if (!get_stack_info_noinstr(stack, current, &info) || info.type == STACK_TYPE_ENTRY || + if (!get_stack_info_noinstr(stack, current, &info) || + info.type & STACK_TYPE_GUARD || + info.type == STACK_TYPE_ENTRY || info.type >= STACK_TYPE_EXCEPTION_LAST) sp = __this_cpu_ist_top_va(VC2);