From patchwork Mon Apr 27 11:08:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1277553 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499j08648lz9sP7 for ; Mon, 27 Apr 2020 21:16:40 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=F40alGe9; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 499j085GvRzDqXB for ; Mon, 27 Apr 2020 21:16:40 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1044; helo=mail-pj1-x1044.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=F40alGe9; dkim-atps=neutral Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 499hw062VVzDqdR for ; Mon, 27 Apr 2020 21:13:04 +1000 (AEST) Received: by mail-pj1-x1044.google.com with SMTP id a31so5429442pje.1 for ; Mon, 27 Apr 2020 04:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QlgWPiHbKIj+MSdQA3QcOG1FRZxqFhP1QkuZIvdsOM0=; b=F40alGe9D5kh7QsA+LcWao4O+otyQBCvWColrczFNNqJTmIkWuHqItNDysRynV8ULV SbKZX+JYLABF11QTqogDC/sYrGE+7RTN+GP8f1quKLXaXOyTRy7s7sv2mE3ZgnMjtral WmfdCnYxPkgTHT8WTvQx3i//AK1rklZbKANT/+1flx+vaaFbwoooc0w6P9uFcIGnYBrk xF27yDSr18V8l3GI4jJKEjwEc83973JSGJa2h5Ld4tGHV0I/tSq3qm78tJhl+9gpnn1U +Bjyv8+62AGc+IdpQgjSPeSf6OULf5RFJlXTMuW9RrB9bvj89aAO7vQCr7u48692CF7e hDbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QlgWPiHbKIj+MSdQA3QcOG1FRZxqFhP1QkuZIvdsOM0=; b=cZyxpcA4v+K4j/L/2WtpZBmANTWOiOTYsd+HSErPLkiUxEwXROrUZ16mKpoJtHgSUg ZUDD/pekHb6k6ywUkcXrDOVLqaqHBs//903e/tEG7a1gy9Dspixv0bJOqPoqdc/cwf2O g+TDBw0iASyRZp8LUuT15CIDfu5MEk1H3AMsb72KnfXW/KnYnpFlEat+4mw+nA1FkKeP uWw5Lbfbuv1UL5BbTOUQcDVSD3dhO03CMMFNGwaEhh5JjHLvmiWpRxGf6drJ7wa/kqpM ds8dTa/NIEoMOLABpdIs0//Xffi2UX9S0XvNFcAdey0894ev8m4hqAf9f+PgX2Hmjskd qKxw== X-Gm-Message-State: AGi0Pua3VayU2gjPze91OyI3vBXBNHhSQ3WOsZwHF99Q+lvoDlM4KIN+ Sw8hfa8Wf86oBHVvM0fCR4RFV49P X-Google-Smtp-Source: APiQypKgKtoHwqrSs6mtMoUoH8fNHSMlhiVCocWKNsZc2m/kNeS5qwFkT6hzof8gHD4sTtneIGda3A== X-Received: by 2002:a17:90a:7482:: with SMTP id p2mr22622318pjk.151.1587985982624; Mon, 27 Apr 2020 04:13:02 -0700 (PDT) Received: from bobo.ibm.com ([203.220.177.17]) by smtp.gmail.com with ESMTPSA id b1sm10567431pfi.140.2020.04.27.04.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2020 04:13:02 -0700 (PDT) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Mon, 27 Apr 2020 21:08:07 +1000 Message-Id: <20200427110813.1276533-11-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200427110813.1276533-1-npiggin@gmail.com> References: <20200427110813.1276533-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH 10/16] core: interrupt markers for stack traces X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Use magic marker in the exception stack frame that is used by the unwinder to decode the interrupt type and NIA. The below example trace comes from a modified skiboot that uses virtual memory, but any interrupt type will appear similarly. CPU 0000 Backtrace: S: 0000000031c13580 R: 0000000030028210 .vm_dsi+0x360 S: 0000000031c13630 R: 000000003003b0dc .exception_entry+0x4fc S: 0000000031c13830 R: 0000000030001f4c exception_entry_foo+0x4 --- Interrupt 0x300 at 000000003002431c --- S: 0000000031c13b40 R: 000000003002430c .make_free.isra.0+0x110 S: 0000000031c13bd0 R: 0000000030025198 .mem_alloc+0x4a0 S: 0000000031c13c80 R: 0000000030028bac .__memalign+0x48 S: 0000000031c13d10 R: 0000000030028da4 .__zalloc+0x18 S: 0000000031c13d90 R: 000000003002fb34 .opal_init_msg+0x34 S: 0000000031c13e20 R: 00000000300234b4 .main_cpu_entry+0x61c S: 0000000031c13f00 R: 00000000300031b8 boot_entry+0x1b0 --- OPAL boot --- Signed-off-by: Nicholas Piggin --- asm/asm-offsets.c | 1 + asm/head.S | 5 +++++ core/exceptions.c | 2 ++ core/stack.c | 11 +++++++++++ include/mem-map.h | 2 +- include/stack.h | 6 ++++++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/asm/asm-offsets.c b/asm/asm-offsets.c index 2328d4d0f..7be0a1157 100644 --- a/asm/asm-offsets.c +++ b/asm/asm-offsets.c @@ -38,6 +38,7 @@ int main(void) OFFSET(CPUTHREAD_STACK_BOT_TOK, cpu_thread, stack_bot_tok); #endif OFFSET(STACK_TYPE, stack_frame, type); + OFFSET(STACK_MAGIC, stack_frame, magic); OFFSET(STACK_LOCALS, stack_frame, locals); OFFSET(STACK_GPR0, stack_frame, gpr[0]); OFFSET(STACK_GPR1, stack_frame, gpr[1]); diff --git a/asm/head.S b/asm/head.S index 450fb71f1..88b2bc12a 100644 --- a/asm/head.S +++ b/asm/head.S @@ -176,6 +176,7 @@ _exception: mfspr %r3,SPR_SRR0 mfspr %r4,SPR_SRR1 std %r3,STACK_SRR0(%r1) + std %r3,16(%r1) std %r4,STACK_SRR1(%r1) mfspr %r3,SPR_DSISR mfspr %r4,SPR_DAR @@ -231,6 +232,8 @@ _exception: stw %r4,STACK_XER(%r1) std %r5,STACK_CTR(%r1) std %r6,STACK_LR(%r1) + LOAD_IMM64(%r3,STACK_INT_MAGIC) + std %r3,STACK_MAGIC(%r1) LOAD_IMM64(%r4, SKIBOOT_BASE) LOAD_IMM32(%r5,__toc_start - __head) LOAD_IMM32(%r6, exception_entry_foo - __head) @@ -928,6 +931,8 @@ opal_entry: /* Store token in CPU thread */ std %r0,CPUTHREAD_CUR_TOKEN(%r16) + LOAD_IMM64(%r12,STACK_INT_MAGIC) + std %r12,STACK_MAGIC(%r1) /* Mark the stack frame */ li %r12,STACK_ENTRY_OPAL_API std %r12,STACK_TYPE(%r1) diff --git a/core/exceptions.c b/core/exceptions.c index dacc02a28..fd069aa60 100644 --- a/core/exceptions.c +++ b/core/exceptions.c @@ -65,6 +65,8 @@ void exception_entry(struct stack_frame *stack) nip = stack->srr0; msr = stack->srr1; } + stack->msr = msr; + stack->pc = nip; if (!(msr & MSR_RI)) fatal = true; diff --git a/core/stack.c b/core/stack.c index 688ef7044..2df960b3e 100644 --- a/core/stack.c +++ b/core/stack.c @@ -35,6 +35,12 @@ static void __nomcount __backtrace_create(struct bt_entry *entries, if (!fp || (unsigned long)fp > top_adj) break; eframe = (struct stack_frame *)fp; + if (eframe->magic == STACK_INT_MAGIC) { + entries->exception_type = eframe->type; + entries->exception_pc = eframe->pc; + } else { + entries->exception_type = 0; + } entries->sp = (unsigned long)fp; entries->pc = fp[2]; entries++; @@ -99,6 +105,11 @@ void backtrace_print(struct bt_entry *entries, struct bt_metadata *metadata, if (symbols) l += snprintf_symbol(buf + l, max - l, entries->pc); l += snprintf(buf + l, max - l, "\n"); + if (entries->exception_type) { + l += snprintf(buf + l, max - l, + " --- Interrupt 0x%lx at %016lx ---\n", + entries->exception_type, entries->exception_pc); + } entries++; } if (metadata->token <= OPAL_LAST) diff --git a/include/mem-map.h b/include/mem-map.h index b65401257..15ec09ea0 100644 --- a/include/mem-map.h +++ b/include/mem-map.h @@ -19,7 +19,7 @@ /* End of the exception region we copy from 0x0. 0x0-0x100 will have * IPL data and is not actually for exception vectors. */ -#define EXCEPTION_VECTORS_END 0x2000 +#define EXCEPTION_VECTORS_END 0x3000 #define NACA_OFF 0x4000 diff --git a/include/stack.h b/include/stack.h index bd4fa2f64..3e987ea81 100644 --- a/include/stack.h +++ b/include/stack.h @@ -45,6 +45,7 @@ #define STACK_WARNING_GAP 2048 #define STACK_CHECK_GUARD_BASE 0xdeadf00dbaad300 +#define STACK_INT_MAGIC 0xb1ab1af00ba1234ULL #ifndef __ASSEMBLY__ @@ -72,6 +73,9 @@ struct stack_frame { * one doubleword. */ uint64_t locals[1]; + /* Interrupt entry magic value */ + uint64_t magic; + /* Entry type */ uint64_t type; @@ -104,6 +108,8 @@ struct stack_frame { struct bt_entry { unsigned long sp; unsigned long pc; + unsigned long exception_type; + unsigned long exception_pc; }; /* Backtrace metadata */