From patchwork Wed Jun 28 00:13:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 13295103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97593EB64D9 for ; Wed, 28 Jun 2023 00:14:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbjF1AOa (ORCPT ); Tue, 27 Jun 2023 20:14:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230031AbjF1AO3 (ORCPT ); Tue, 27 Jun 2023 20:14:29 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A02D2E8 for ; Tue, 27 Jun 2023 17:14:28 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1b82616c4ecso7476085ad.2 for ; Tue, 27 Jun 2023 17:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687911268; x=1690503268; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4ZjcXPxOnEy7+SOVIdg9yFzDIlL6q00qvIVRkRmdKtM=; b=DKB7JOxPefuZO7KixVJFWWixhZBrTUmoOWjWM6HbkNPtDJ7RbVMWVl6G+QYa8/0Nez VHQVCnrnSTflid3YqbihoTRbjdG7G0cJHmZOgIfoEorGz8Op/66NSyMDNTTtlUDzw4JU aMKiH+2Vw0Tgx2tMg9ITPTCQP69+dvxX1tatkgiK5oR8pL+yrznMTNWbHvORRCs5Sp++ XEh0e9zrdznltdWvWNkc3wOlpsb0AuPPu0LN+zg7fj/OzOWE+EIsND1JVrKHMQZ4ZY2p TAZCmwRU4oT6/4tm6fmZGWH4Cni0vHZG5naAUjbEM4lu6mgCdpx3HiPS7zENgM9B0V5k GdHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687911268; x=1690503268; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4ZjcXPxOnEy7+SOVIdg9yFzDIlL6q00qvIVRkRmdKtM=; b=g8HGq6hGIeLIQ4Xm9pjkDHWtfzZvu+LzBuaGTnCk6tZEwwfTPZf3dYmGN8akqAXnxH S2O+z58JMA0+AAqas3B2y8/N0mbg+Aoo/HIIdoFws947nj1HM1EFcn4tN0b0iPe2maHD rBsFMYWHW8axZotve9dNRnnhLEZhzatt2pdR+msxXEbx4Uf3X5G/YIVvyCkE3XckQbR+ sx3+1lvX5zOJ05U1/y0sC69MNTW87IoF9HiIKDKS0m04J3Z2++n4iShkDeCQn83OkL3L pFpC5coWc7Ac9Usf7iHEJzBzsc3W1y3Enp+akyhf7Suwt8LqX20KmcVGjLllFeRTBXX3 8LUw== X-Gm-Message-State: AC+VfDz0Hn8rZkUrED3oTCVCJ7pG23Ot8T5ZWRn3A8CPcqEHpzrA8i7q zqVRLtrlM7jtQTXV7Ct0JHU= X-Google-Smtp-Source: ACHHUZ4ajl/K9Afuy4wmkbZFJTlHaXfzvMo7K6CnfYtIi4x1dX/K2YDRLAr1sl1b7VUp9WmPnjfpFA== X-Received: by 2002:a17:902:ea06:b0:1b8:50d:9dd9 with SMTP id s6-20020a170902ea0600b001b8050d9dd9mr7276070plg.51.1687911267850; Tue, 27 Jun 2023 17:14:27 -0700 (PDT) Received: from sc9-mailhost2.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id jd4-20020a170903260400b001b1920cffdasm343796plb.204.2023.06.27.17.14.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:14:27 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Andrew Jones Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, Nikos Nikoleris , Paolo Bonzini , Thomas Huth , Nadav Amit Subject: [PATCH] .debug ignore - to squash with efi:keep efi Date: Wed, 28 Jun 2023 00:13:48 +0000 Message-Id: <20230628001356.2706-1-namit@vmware.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Nadav Amit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 29f352c..2168e01 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ tags *.flat *.efi *.elf +*.debug *.patch .pc patches From patchwork Wed Jun 28 00:13:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 13295106 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2C62EB64DC for ; Wed, 28 Jun 2023 00:14:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230331AbjF1AOm (ORCPT ); Tue, 27 Jun 2023 20:14:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbjF1AOe (ORCPT ); Tue, 27 Jun 2023 20:14:34 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6203626B1 for ; Tue, 27 Jun 2023 17:14:32 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1b8063aa2e1so18043445ad.1 for ; Tue, 27 Jun 2023 17:14:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687911272; x=1690503272; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6VV0a8wWSD+atLlwpNamgRCyPytqoIWQ0GwWykCu/xw=; b=NEeG+Fd2oONFSZHMZgXZhQp48FPLe6z5vzWUJT+7cLVPJw9QNYox443LEIecTTX6TY ZeSSkSBXZTr2GSr0HNmb1SMiXQ88aHJ0NzFurU2/qJV02TXrwPM7fQwNtV4pOqlT+GAJ YPsOYn9t38ODKHcu0AL3ETYaFz44K24gxqh5OYI4/CpebE3uMZxRg57MVBOU2wefkeDU kXbmfbOUkAqDHNEgKLoMbw0X6VwAlPrW87J58l1bnMbxb2T7WILnemY848zXungiaZmm RAgkA50YAlhNVIPGtgDLGIfvXl5BtwhzhLVR+2Wd05jsfiflATyFkLOBt6TvEpNS72YF YmMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687911272; x=1690503272; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6VV0a8wWSD+atLlwpNamgRCyPytqoIWQ0GwWykCu/xw=; b=gIfeMFs2Q051XhjiwuBKeV1NJfBHdbbvq6N+AqDNPBhtlu0uw5RwVbobD1B47oBqvw 034zDiNlvRp/kjIIvCjQJ5Bs3e4B9NHWQotrOKVMKiVaVgVyb3HnWqfKT5eSMNd+AKw6 UmRRSDcr+Hxt6xcVew2qMxJJlkp1WJBXR5eyK47LLyyFhiygm1EvfxydmYJAG2UVFhs0 tJ3arEezeFxcrOmtVAAZCG0AcbwGP+VTCCkhe04RpL+bB/2JfIzfl4fBuYg5fPQZIf3A ql/n+3MervqAcnOQQsYlxAU7u5XcbrlQ1rLIKF8g1SXLtQqExchsXtSIBPKGzl5K2yxi UR8w== X-Gm-Message-State: AC+VfDzxbdCvRoueojPOi7EqOL26cj4Kib+YvH3/Nrxvu+OMjlu90ZPL zK/I2SVdwrVrEAf/Dkc1yTs= X-Google-Smtp-Source: ACHHUZ4uh9514t9KV5Y1JchPqaxRN1mR8gdhBr5xLxQvVkgRsCUbt497+YuIruLuWl9Z4WyPUxJEgA== X-Received: by 2002:a17:903:32d0:b0:1b1:b2fa:1903 with SMTP id i16-20020a17090332d000b001b1b2fa1903mr7562183plr.41.1687911271722; Tue, 27 Jun 2023 17:14:31 -0700 (PDT) Received: from sc9-mailhost2.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id jd4-20020a170903260400b001b1920cffdasm343796plb.204.2023.06.27.17.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:14:31 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Andrew Jones Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, Nikos Nikoleris , Paolo Bonzini , Thomas Huth , Nadav Amit Subject: [kvm-unit-tests PATCH v3 2/6] lib/stack: print base addresses on relocation setups Date: Wed, 28 Jun 2023 00:13:51 +0000 Message-Id: <20230628001356.2706-4-namit@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230628001356.2706-1-namit@vmware.com> References: <20230628001356.2706-1-namit@vmware.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Nadav Amit Making sense from dumped stacks when running EFI tests is very hard due to the relocation. Fix it by adjusting the address back to the original address. Introduce CONFIG_RELOC, which would be set on arm64 and on EFI configs. Suggested-by: Andrew Jones Signed-off-by: Nadav Amit --- v2->v3: * Mark PowerPC as relocatable as well [Andrew] * Fixing incorrect Makefile [Andrew] v1->v2: * Introduce CONFIG_RELOC to support ARM64 [Andrew] --- Makefile | 2 +- arm/Makefile.arm64 | 1 + lib/stack.c | 31 +++++++++++++++++++++++++++++-- powerpc/Makefile.common | 1 + 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 307bc29..ae79059 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ OBJDIRS += $(LIBFDT_objdir) # EFI App ifeq ($(CONFIG_EFI),y) -EFI_CFLAGS := -DCONFIG_EFI +EFI_CFLAGS := -DCONFIG_EFI -DCONFIG_RELOC # The following CFLAGS and LDFLAGS come from: # - GNU-EFI/Makefile.defaults # - GNU-EFI/apps/Makefile diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64 index eada7f9..85b3348 100644 --- a/arm/Makefile.arm64 +++ b/arm/Makefile.arm64 @@ -12,6 +12,7 @@ CFLAGS += -mstrict-align mno_outline_atomics := $(call cc-option, -mno-outline-atomics, "") CFLAGS += $(mno_outline_atomics) +CFLAGS += -DCONFIG_RELOC define arch_elf_check = $(if $(shell ! $(READELF) -rW $(1) >&/dev/null && echo "nok"), diff --git a/lib/stack.c b/lib/stack.c index bdb23fd..dd6bfa8 100644 --- a/lib/stack.c +++ b/lib/stack.c @@ -6,13 +6,38 @@ */ #include +#include #include #define MAX_DEPTH 20 +#ifdef CONFIG_RELOC +extern char _text, _etext; + +static bool base_address(const void *rebased_addr, unsigned long *addr) +{ + unsigned long ra = (unsigned long)rebased_addr; + unsigned long start = (unsigned long)&_text; + unsigned long end = (unsigned long)&_etext; + + if (ra < start || ra >= end) + return false; + + *addr = ra - start; + return true; +} +#else +static bool base_address(const void *rebased_addr, unsigned long *addr) +{ + *addr = (unsigned long)rebased_addr; + return true; +} +#endif + static void print_stack(const void **return_addrs, int depth, bool top_is_return_address) { + unsigned long addr; int i = 0; printf("\tSTACK:"); @@ -20,12 +45,14 @@ static void print_stack(const void **return_addrs, int depth, /* @addr indicates a non-return address, as expected by the stack * pretty printer script. */ if (depth > 0 && !top_is_return_address) { - printf(" @%lx", (unsigned long) return_addrs[0]); + if (base_address(return_addrs[0], &addr)) + printf(" @%lx", addr); i++; } for (; i < depth; i++) { - printf(" %lx", (unsigned long) return_addrs[i]); + if (base_address(return_addrs[i], &addr)) + printf(" %lx", addr); } printf("\n"); } diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 8ce0034..c2e976e 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -24,6 +24,7 @@ CFLAGS += -ffreestanding CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec) CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib CFLAGS += -Wa,-mregnames +CFLAGS += -DCONFIG_RELOC # We want to keep intermediate files .PRECIOUS: %.o From patchwork Wed Jun 28 00:13:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 13295108 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37295C0015E for ; Wed, 28 Jun 2023 00:14:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbjF1AOp (ORCPT ); Tue, 27 Jun 2023 20:14:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230218AbjF1AOf (ORCPT ); Tue, 27 Jun 2023 20:14:35 -0400 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C54BE6C for ; Tue, 27 Jun 2023 17:14:34 -0700 (PDT) Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-39ca48cd4c6so3788640b6e.0 for ; Tue, 27 Jun 2023 17:14:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687911273; x=1690503273; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UmFmTC8bnHNv1WPEh/RUIDJe8hKI7ahTcZbLkHpBtH0=; b=g3zgrX61eFuJp69fuI0Ao+RDcinE9QFo5sdIt1ZdjknZaZtihV6AcQCzZzSzGDJtEN EcLd8Eyc6tp/4QD9ezhuuZE+n9tc1P5d7VKpTpSDguNvT8A6iFLah162s7rWgAWP/82a +es/72/tj6bygzYVGwr2e6+FfhkwBbt3OWkiKlB4NNpOz5iQxmB91malsMMrMw+qVpYv r0+6u8FUxH/QuYjKwTpsiqrSQ3sCYkOLsds9p9LIU2oPKTvZVVXSGf7fXgBw8oOBH1O7 /SB7/n67x1+nzn9WX/8EKyFphftrlpdoJFpJRCmJDGY2TNH7sCXEe11jA3iuJSVIvWrM vv8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687911273; x=1690503273; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UmFmTC8bnHNv1WPEh/RUIDJe8hKI7ahTcZbLkHpBtH0=; b=NoxinPgxoItW8oVBfUqF5wg8+qSfWh/CgUhMmdI6WMCYvziz/q7xns7efr7EjDSo/y 7n0uj/hSThvIrvP4WOV7YwqoRMzXX2F2QMkHAhHFuDoDiZNvAm5gt+pwfwA3Q/dgwzws xwH6AGBxNHpPZ+vhupvSuqzsHczImjl9EyowCT5QZsCmnnmUZRMm5kUVVDEDM2nuryRr WHPll8E+4Cd90QrijhGPqEWmsVravHboS4WyQZ/q0XUrUfzdZsPrzHiCJ+JJEfCd5xtu jlh+OREsoV9ikwQftMV97jK58F/ibDx9mW0QR1oNnX3fqTansuKOoqnSco8oQFYHqLp1 sFNA== X-Gm-Message-State: AC+VfDx1eBhUfmf3kdP84V+A+sWIWGnaAaR3eG1G/QJZ4sjOUGr8xEPL vMqZLbpfticjNpWw9Uox+M6YnlFSMjY= X-Google-Smtp-Source: ACHHUZ7z956FrGM3Nc0mQJn20xFdonGjPggrED2mxicUWJ6uoWGGtr3daHFYVfaE6vzCQi9/Oz4JvQ== X-Received: by 2002:a05:6808:5c3:b0:3a1:e18a:2402 with SMTP id d3-20020a05680805c300b003a1e18a2402mr6284134oij.4.1687911273087; Tue, 27 Jun 2023 17:14:33 -0700 (PDT) Received: from sc9-mailhost2.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id jd4-20020a170903260400b001b1920cffdasm343796plb.204.2023.06.27.17.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:14:32 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Andrew Jones Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, Nikos Nikoleris , Paolo Bonzini , Thomas Huth , Nadav Amit Subject: [kvm-unit-tests PATCH v3 3/6] arm64: enable frame pointer and support stack unwinding Date: Wed, 28 Jun 2023 00:13:52 +0000 Message-Id: <20230628001356.2706-5-namit@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230628001356.2706-1-namit@vmware.com> References: <20230628001356.2706-1-namit@vmware.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Nadav Amit Enable frame pointers for arm64 and perform stack unwinding based on arm64 convention. Signed-off-by: Nadav Amit --- v1->v2: * Adding SPDX [checkpatch] * Moving some unused declarations to next patch [Andrew] * Adding recursion prevention --- arm/Makefile.arm | 3 --- arm/Makefile.arm64 | 1 + arm/Makefile.common | 3 +++ lib/arm64/asm/stack.h | 3 +++ lib/arm64/stack.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 lib/arm64/stack.c diff --git a/arm/Makefile.arm b/arm/Makefile.arm index 2ce00f5..7fd39f3 100644 --- a/arm/Makefile.arm +++ b/arm/Makefile.arm @@ -11,9 +11,6 @@ ifeq ($(CONFIG_EFI),y) $(error Cannot build arm32 tests as EFI apps) endif -# stack.o relies on frame pointers. -KEEP_FRAME_POINTER := y - CFLAGS += $(machine) CFLAGS += -mcpu=$(PROCESSOR) CFLAGS += -mno-unaligned-access diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64 index 85b3348..960880f 100644 --- a/arm/Makefile.arm64 +++ b/arm/Makefile.arm64 @@ -22,6 +22,7 @@ define arch_elf_check = endef cstart.o = $(TEST_DIR)/cstart64.o +cflatobjs += lib/arm64/stack.o cflatobjs += lib/arm64/processor.o cflatobjs += lib/arm64/spinlock.o cflatobjs += lib/arm64/gic-v3-its.o lib/arm64/gic-v3-its-cmd.o diff --git a/arm/Makefile.common b/arm/Makefile.common index 9b45a8f..bc86e44 100644 --- a/arm/Makefile.common +++ b/arm/Makefile.common @@ -22,6 +22,9 @@ $(TEST_DIR)/sieve.elf: AUXFLAGS = 0x1 ################################################################## AUXFLAGS ?= 0x0 +# stack.o relies on frame pointers. +KEEP_FRAME_POINTER := y + CFLAGS += -std=gnu99 CFLAGS += -ffreestanding CFLAGS += -O2 diff --git a/lib/arm64/asm/stack.h b/lib/arm64/asm/stack.h index d000624..be486cf 100644 --- a/lib/arm64/asm/stack.h +++ b/lib/arm64/asm/stack.h @@ -5,4 +5,7 @@ #error Do not directly include . Just use . #endif +#define HAVE_ARCH_BACKTRACE_FRAME +#define HAVE_ARCH_BACKTRACE + #endif diff --git a/lib/arm64/stack.c b/lib/arm64/stack.c new file mode 100644 index 0000000..a2024e8 --- /dev/null +++ b/lib/arm64/stack.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Backtrace support. + */ +#include +#include +#include + +int backtrace_frame(const void *frame, const void **return_addrs, int max_depth) +{ + const void *fp = frame; + static bool walking; + void *lr; + int depth; + + if (walking) { + printf("RECURSIVE STACK WALK!!!\n"); + return 0; + } + walking = true; + + /* + * ARM64 stack grows down. fp points to the previous fp on the stack, + * and lr is just above it + */ + for (depth = 0; fp && depth < max_depth; ++depth) { + + asm volatile ("ldp %0, %1, [%2]" + : "=r" (fp), "=r" (lr) + : "r" (fp) + : ); + + return_addrs[depth] = lr; + } + + walking = false; + return depth; +} + +int backtrace(const void **return_addrs, int max_depth) +{ + return backtrace_frame(__builtin_frame_address(0), + return_addrs, max_depth); +} From patchwork Wed Jun 28 00:13:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 13295107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7FEAEB64D9 for ; Wed, 28 Jun 2023 00:14:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230229AbjF1AOn (ORCPT ); Tue, 27 Jun 2023 20:14:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230183AbjF1AOi (ORCPT ); Tue, 27 Jun 2023 20:14:38 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BB3526BF for ; Tue, 27 Jun 2023 17:14:35 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-553b2979fceso1875827a12.3 for ; Tue, 27 Jun 2023 17:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687911274; x=1690503274; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZBy1+s5+1bIZxGdZDUFvFfxmlLpG2meXbQVky29avoY=; b=ME2yZ5v9engYXuakH/xkWSNpuDotyvZhJ2RAvGD6Phbl8exTwTHA1fNfMd2R8WrIc0 2jARdXArqde2FcNVEU3YD5UBir3iALIMnIAlmse0VEHd9IxKSXfyT4b3JmVxHS0aqh4c PupRRnBINz5mxRbk5JAojUfo4+cDugVhjlZS54+n2nT55wfeocGAGEx9KRVT+/pz3pvN qwWg5t9b+TIkBr4xLnuPFiGDa6IHnErgw8R5jk+UuiAhR4tS+65npigD/11uCfAf5n2C GONXgT1E2uEwo+nU3UNEszV0HHGiaivV1RBTZoAIxY7A3XEnZg1CVv7iBQ+aq4Hm/Wt3 3CWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687911274; x=1690503274; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZBy1+s5+1bIZxGdZDUFvFfxmlLpG2meXbQVky29avoY=; b=VSJF6HRHGQHGdMFUATnlMuCg9Eb1+la46tbnybvc9j9VMrloZ9oElZxi0elZxztxzt PMArUsyL2//jPSPTtKBpwZefelMHxBGUY44FcTfS0SIseUnp6I2k8ww8L8IDp3E6ZjbA mzzClNK6jtRi7l1WK1pWKxsGOvLV4AyHA070vOermmkaJBsiwD5pcWI+UAm3OCqS8229 B1asxk5RvdFd9CdePJtVLoFY+tZrfVXaEDVECAXx7875MzIjVp/hOvl3AzSGhMfVExir 9ZTBx/TkSp1AI0wVHC5GwWiKJhFea6AA7Pm5avjkaH5513N7lavYsQMhYjC7d/huRnnW 1FwQ== X-Gm-Message-State: AC+VfDyeDN0fun+mJRzAZEM7Lob3RAx7i6JRU9ziCAYDvhQI4WZsOI+P qBHLksc6IDMt1nb2sLN4GYJGaBk4QKA= X-Google-Smtp-Source: ACHHUZ7pIvBspewQylA7vvhANwJKaB7OJyudL7l3ZA2ns4WE7tQcz7fiyIKPhAghpJLNHtXnR0dZYA== X-Received: by 2002:a17:90a:2b0e:b0:263:a37:fcc3 with SMTP id x14-20020a17090a2b0e00b002630a37fcc3mr4071354pjc.5.1687911274375; Tue, 27 Jun 2023 17:14:34 -0700 (PDT) Received: from sc9-mailhost2.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id jd4-20020a170903260400b001b1920cffdasm343796plb.204.2023.06.27.17.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:14:33 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Andrew Jones Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, Nikos Nikoleris , Paolo Bonzini , Thomas Huth , Nadav Amit Subject: [kvm-unit-tests PATCH v3 4/6] arm64: stack: update trace stack on exception Date: Wed, 28 Jun 2023 00:13:53 +0000 Message-Id: <20230628001356.2706-6-namit@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230628001356.2706-1-namit@vmware.com> References: <20230628001356.2706-1-namit@vmware.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Nadav Amit Using gdb for backtracing or dumping the stack following an exception is not very helpful as the exact location of the exception is not saved. Add an additional frame to save the location of the exception. One delicate point is dealing with the pretty_print_stacks script. When the stack is dumped, the script would not print the right address for the exception address: for every return address it deducts "1" before looking for the instruction location in the code (using addr2line). As a somewhat hacky solution add "1" for the exception address when dumping the stack. Signed-off-by: Nadav Amit --- v1->v2: * .globl before label [Andrew] * Some comments [Andrew] --- arm/cstart64.S | 13 +++++++++++++ lib/arm64/asm-offsets.c | 6 +++++- lib/arm64/stack.c | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/arm/cstart64.S b/arm/cstart64.S index cbd6b51..865a96d 100644 --- a/arm/cstart64.S +++ b/arm/cstart64.S @@ -314,6 +314,13 @@ exceptions_init: mrs x2, spsr_el1 stp x1, x2, [sp, #S_PC] + /* + * Save a frame pointer using the link to allow unwinding of + * exceptions. + */ + stp x29, x1, [sp, #S_FP] + add x29, sp, #S_FP + mov x0, \vec mov x1, sp mrs x2, esr_el1 @@ -349,6 +356,9 @@ exceptions_init: eret .endm +.globl vector_stub_start +vector_stub_start: + vector_stub el1t_sync, 0 vector_stub el1t_irq, 1 vector_stub el1t_fiq, 2 @@ -369,6 +379,9 @@ vector_stub el0_irq_32, 13 vector_stub el0_fiq_32, 14 vector_stub el0_error_32, 15 +.globl vector_stub_end +vector_stub_end: + .section .text.ex .macro ventry, label diff --git a/lib/arm64/asm-offsets.c b/lib/arm64/asm-offsets.c index 53a1277..80de023 100644 --- a/lib/arm64/asm-offsets.c +++ b/lib/arm64/asm-offsets.c @@ -25,6 +25,10 @@ int main(void) OFFSET(S_PSTATE, pt_regs, pstate); OFFSET(S_ORIG_X0, pt_regs, orig_x0); OFFSET(S_SYSCALLNO, pt_regs, syscallno); - DEFINE(S_FRAME_SIZE, sizeof(struct pt_regs)); + + /* FP and LR (16 bytes) go on the frame above pt_regs */ + DEFINE(S_FP, sizeof(struct pt_regs)); + DEFINE(S_FRAME_SIZE, (sizeof(struct pt_regs) + 16)); + return 0; } diff --git a/lib/arm64/stack.c b/lib/arm64/stack.c index a2024e8..82611f4 100644 --- a/lib/arm64/stack.c +++ b/lib/arm64/stack.c @@ -6,12 +6,16 @@ #include #include +extern char vector_stub_start, vector_stub_end; + int backtrace_frame(const void *frame, const void **return_addrs, int max_depth) { const void *fp = frame; static bool walking; void *lr; int depth; + bool is_exception = false; + unsigned long addr; if (walking) { printf("RECURSIVE STACK WALK!!!\n"); @@ -31,6 +35,20 @@ int backtrace_frame(const void *frame, const void **return_addrs, int max_depth) : ); return_addrs[depth] = lr; + + /* + * If this is an exception, add 1 to the pointer so when the + * pretty_print_stacks script is run it would get the right + * address (it deducts 1 to find the call address, but we want + * the actual address). + */ + if (is_exception) + return_addrs[depth] += 1; + + /* Check if we are in the exception handlers for the next entry */ + addr = (unsigned long)lr; + is_exception = (addr >= (unsigned long)&vector_stub_start && + addr < (unsigned long)&vector_stub_end); } walking = false; From patchwork Wed Jun 28 00:13:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 13295110 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BFB5EB64DC for ; Wed, 28 Jun 2023 00:14:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230295AbjF1AOs (ORCPT ); Tue, 27 Jun 2023 20:14:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230214AbjF1AOj (ORCPT ); Tue, 27 Jun 2023 20:14:39 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72EB0272E for ; Tue, 27 Jun 2023 17:14:36 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1b8054180acso23990215ad.1 for ; Tue, 27 Jun 2023 17:14:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687911276; x=1690503276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1zfLc8s8ukm6B8uTEBNuw3gp/VvXLK+Q2HtLxCf87RA=; b=YiltKE2ojsIX1IvRFbadB/0W28pDqxr5SG/QQIxwovOvmZ9ydT8id2x0lPVM3uyNhL +ZNnoR099reijdo5nZNejbjtA05aUK6BoRdrWc34UIh9gnx3uYugc5CfZP6vXjS9gCSo EalYHyIYYHbKSPH/e68MDdibpEtocA/g0bi2v7l+wSsr9krzQJOyqjLZAUruqdRuTW28 utyqzx++PLQxnUUPXe1ADwHd3SIDVD+iQTLA+65K2IjyGguv19PtDEXPA8LlvDCWf5go +UnSlaPneGiafRR8I7UAC/X8Xb1En9rp615e8UMcYaDSjdlHFCj9bVlX/N8v6RrQ/0MP VYgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687911276; x=1690503276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1zfLc8s8ukm6B8uTEBNuw3gp/VvXLK+Q2HtLxCf87RA=; b=BBIUImLJpqWP7L1IaVQfS/SbmVtOEAOrLdpVmRJAQAZ7uHzcXceI502TP0pe3u8LZO v5rJpGK1fJNfFcDbmscadZIzZY4nJ18PunWNfDlKkObc4pRiFVBBfbs1ZdQ1fpXbiwXu 4ZZ6qOUkZahoFG3/WYF5nM65RGrd0gDqDeNvKbgaKMkQKQorry2JJ/g0hriMMxk+g76P k3+PcNkSFiubVXdxhwKPKbnrXWLadbM+lPxSolxCSpsj6fHjV/MdzwdIfQqrGIcJscZD 1RjdpyfF5MQxzzFKdyb2KQYfhXY6hdJa5pLtB7Yg20AfWaQwav6jxRswMyvwyM2Drgd1 vrvQ== X-Gm-Message-State: AC+VfDwJ+wCFZ8U55VRsNTdnl7HnMbcw8CXjE/PnywiCo1iGu2hDimpM OuGdIqyCPF4xdQ3pq3RDTU0= X-Google-Smtp-Source: ACHHUZ5SRvbDizcqRaoRTMdNa0syYFknidVMQDwP1iEsY47BtD7BGVVdrneA3ak5Wa0+9ZhMSPeWTA== X-Received: by 2002:a17:903:41c7:b0:1b7:ef04:da55 with SMTP id u7-20020a17090341c700b001b7ef04da55mr11767181ple.11.1687911275849; Tue, 27 Jun 2023 17:14:35 -0700 (PDT) Received: from sc9-mailhost2.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id jd4-20020a170903260400b001b1920cffdasm343796plb.204.2023.06.27.17.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:14:35 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Andrew Jones Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, Nikos Nikoleris , Paolo Bonzini , Thomas Huth , Nadav Amit Subject: [kvm-unit-tests PATCH v3 5/6] efi: print address of image Date: Wed, 28 Jun 2023 00:13:54 +0000 Message-Id: <20230628001356.2706-7-namit@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230628001356.2706-1-namit@vmware.com> References: <20230628001356.2706-1-namit@vmware.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Nadav Amit Using gdb to debug tests that are run from efi is very hard without knowing the base address in which the image was loaded. Print the address so it can be used while debugging. Signed-off-by: Nadav Amit --- lib/efi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/efi.c b/lib/efi.c index 2e127a4..2091771 100644 --- a/lib/efi.c +++ b/lib/efi.c @@ -19,6 +19,8 @@ extern int __argc, __envc; extern char *__argv[100]; extern char *__environ[200]; +extern char _text; + extern int main(int argc, char **argv, char **envp); efi_system_table_t *efi_system_table = NULL; @@ -363,6 +365,8 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) goto efi_main_error; } + printf("Address of image is: 0x%lx\n", (unsigned long)&_text); + /* Run the test case */ ret = main(__argc, __argv, __environ); From patchwork Wed Jun 28 00:13:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 13295109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 458C3EB64D9 for ; Wed, 28 Jun 2023 00:14:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230211AbjF1AOq (ORCPT ); Tue, 27 Jun 2023 20:14:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbjF1AOl (ORCPT ); Tue, 27 Jun 2023 20:14:41 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D199A2963 for ; Tue, 27 Jun 2023 17:14:37 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-66767d628e2so2902137b3a.2 for ; Tue, 27 Jun 2023 17:14:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687911277; x=1690503277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bl2xS0hpaMhLNXGaRDLAye8tC/jIz9OZNyY0aYdzy3U=; b=XnE7sHOaoiCiEDBeNgd0++hU1hInSAuTGEsviDuRnsgTiROjl7wXCi0UPgpCNhLZxs jlquyq3qXBoDECqebVv+5HJ+HRK62YGd6gcNgoEdoEpu1+76yZBjl+rtS6joGSZopdG4 kH5hQyzJy9TCtxAUmrwsU+S+2DOpAjOt2nl6TlAbVErCh/OART8zPMqgW5D/a2CnH2Jl iGlrOYqV4Khw+5DFAjRRNMhMQb0Ibh2sBI2n/g1DQmZ1V/oRvmwEhv6mT5z037dshhRs Um7O/P/kLQqtmMDsDZRv2Tmz3WnVkvyTcoAYHO2WU7W2YAe+krcXaM4gr+xzi2fy/wdj lZjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687911277; x=1690503277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bl2xS0hpaMhLNXGaRDLAye8tC/jIz9OZNyY0aYdzy3U=; b=KdVOhTE88q3+U5ZhaDN6g1Kp/24ZtZiHccYp4jvxR6FBw4oh4fRpFNFwXO0Mhl1ao6 87J4WjHQhw7XclCC3k3Aet/7XGKJWjBLehgSNPx4FGKQWUK/3xcoimw3yQ9XNLlIMoaf HvKad5r3BUOxEpB/sFNaKVCLVzKVPvirhGrtMVO8n1z9oi+j04TrsXhaVsGK3+lDZMVe iu8g9J9IDEvbGSFJQ5jBEiZrQ2Vpabl26tr/MOc1sa05MDelXfpQvOlvg13SXWfUCYFL fCpI/zdqV25k33Uu32wj7XHmVfMWJnOH+zH6ZckXh7CxFF+ojzeDA18eAulGZwtyAj8S fGNA== X-Gm-Message-State: AC+VfDz9wK1LRSgNJavH6Qj0psNZnAQg/cfOtsul9CWYGMV1WtOs7xmQ tQujqvUskj3oY8aCqM+7IqM= X-Google-Smtp-Source: ACHHUZ5A7eHI61T59Oo5W/n0/S2XLNxWb6ZKzhIq4esUMRLC0gP+UewjIjEq/P7PoSZ4CFQE3HJIow== X-Received: by 2002:a05:6a20:7d81:b0:12a:cc8:75dc with SMTP id v1-20020a056a207d8100b0012a0cc875dcmr4706951pzj.31.1687911277047; Tue, 27 Jun 2023 17:14:37 -0700 (PDT) Received: from sc9-mailhost2.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id jd4-20020a170903260400b001b1920cffdasm343796plb.204.2023.06.27.17.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:14:36 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Andrew Jones Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, Nikos Nikoleris , Paolo Bonzini , Thomas Huth , Nadav Amit Subject: [kvm-unit-tests PATCH v3 6/6] arm64: dump stack on bad exception Date: Wed, 28 Jun 2023 00:13:55 +0000 Message-Id: <20230628001356.2706-8-namit@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230628001356.2706-1-namit@vmware.com> References: <20230628001356.2706-1-namit@vmware.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Nadav Amit Upon a bad exception, the stack is rather useful for debugging, splat it out. Signed-off-by: Nadav Amit --- lib/arm64/processor.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/arm64/processor.c b/lib/arm64/processor.c index 831207c..5bcad67 100644 --- a/lib/arm64/processor.c +++ b/lib/arm64/processor.c @@ -130,6 +130,7 @@ static void bad_exception(enum vector v, struct pt_regs *regs, printf("Vector: %d (%s)\n", v, vector_names[v]); printf("ESR_EL1: %8s%08x, ec=%#x (%s)\n", "", esr, ec, ec_names[ec]); printf("FAR_EL1: %016lx (%svalid)\n", far, far_valid ? "" : "not "); + dump_stack(); printf("Exception frame registers:\n"); show_regs(regs); abort();