Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp154902imw; Thu, 14 Jul 2022 23:37:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uIIO7VRR4O9WJwMIg/vIX9YPr/AA5xg2ucWt8t+GTMBr4g6lvDwoucS+IBks8vokNwqKxm X-Received: by 2002:a17:902:b60d:b0:16b:e832:7295 with SMTP id b13-20020a170902b60d00b0016be8327295mr12112342pls.144.1657867078157; Thu, 14 Jul 2022 23:37:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657867078; cv=none; d=google.com; s=arc-20160816; b=TufnWmrllTbB5fDHkB74+3H2oEnvcXeLEH3bbgXGHJx50Km1LlyEYi8UgLEZIYyqQA ZqSlPKfDU5XLB8qmVGdrcjhIj8RvOdu1bJKcw8OZs7bMocRS2nKl7fzTQXSN69Gm7v3a SkEs+0gOtNekx04d09PbFwxGR7zJaSh7bZzAHuxXJpjq1mDFaLgj/A6+ac85D/wXZj4W kGXlR9wYL1H1LpEM+8mBUwaVe8XQn/lClhZ2Kf5d8nk9ASAlWLA74fEOTZDzVUJrvXvY D78OEUUW6QQ/w0Xn7+pneYHRTjvjGayurMSD01DseNLp16aKJ5tk86nHkjww5AouA0rm sZsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=I1SuK+mlx4+9ePe7Z4q/Ds8UD0oS6ojhAZGxfH2qnag=; b=Pb2D1RUhh7I8V06Vnu09bP6LrQbP99bEdRv9vZxL2Jg4fBot8frpzWixquAD/OqMdM 1DxLl0GRnJchjQY8/QxUP5yPrRaVzCoH7IWCvvuAem8H51OV1PDM2lVNJADYW4OEOxMS aljkW3Y6BIQUJHx96WI28R4Tq9K2KPFtire4ywe1503u6/jyjjiKGpewIvxZnnXfVyR0 oRtce5aY2KHsBpAgCTSiUPW9KnaMX4GzR9sQIXeklDWnNapuGEnN7xHYjA8j3s37d5Zl R3ETkKzaNEmJI9t+v8QOrdMeKTZRY7bMFuGDWDSJBhUtN0NicOapnvtGejbvxHHYY8YM HGUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JdLDNIjx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a170902708700b0016bd72f9107si209718plk.615.2022.07.14.23.37.41; Thu, 14 Jul 2022 23:37:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JdLDNIjx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230392AbiGOGM6 (ORCPT + 99 others); Fri, 15 Jul 2022 02:12:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbiGOGMH (ORCPT ); Fri, 15 Jul 2022 02:12:07 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 335B47B797 for ; Thu, 14 Jul 2022 23:11:45 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-31c9f68d48cso33858607b3.0 for ; Thu, 14 Jul 2022 23:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=I1SuK+mlx4+9ePe7Z4q/Ds8UD0oS6ojhAZGxfH2qnag=; b=JdLDNIjxjl26urcQRjobE7lTFwccfK46WtRp+G7+hkl3xjEvwMw68U/MYBXubciMxG BUImcs+xTk3eLMzI43bui6vTXiNnZu8GyF+VhTxsBvMu84qLdmtpNmydEJC1khQOQ50Z iSxrEYA8fXN/craiygC6fAoFdYfU1OKsRY4QkJxHDjnzj3AKTL1loj3883Xiz45eqNE8 NzpjLCCYzvSug/99Xx/FJEKg7xSZx78LuAbSVSyhjyyMngJSswROraDCbOLtuRtJsQPS 5wF5vbQpcK4Ay7pfQPwg7dQgjrZm2O+7wGs5DLCMznbnRwd0oZO0Z5vhLoDnd0cxM7iy pjvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=I1SuK+mlx4+9ePe7Z4q/Ds8UD0oS6ojhAZGxfH2qnag=; b=g1l8b1R13boUtiuSBMV9EUgmdK8+0UIwRC3zWlchyCDHO2CJUHHNt/JmJ5Ifa+lUd/ 7wWYQVshzHTMybZPhjUVYfyBLq/pMfrAT+xw4npy+QMyseQbGxsPjY6Z9tpM5GHDU54r Zv21aSDDWue67/TSx/qPQhwbojufHucZ2Wy2V/8BnzHxFdcNZBaT8Pq4hkGMuwLtUKps 2bQe9hPoubf70NdXDhVRzCpYPTqYlyoZu9NE6FRUSbKsZgOXeLN37EXuP+7/gEARXVkQ KU4vqFt+rmOr0Jn3klVBuip5FDd/cnBZUzipzJ/LUjqYdXp4vtWHtPvYWkaOhfYZZ8L5 vnAw== X-Gm-Message-State: AJIora80b1J0Rq7e3edZ37gzdeOar9glQ31pzec4TCJGov6nM4fsmOQp b1wExDlANcrrFC/vbMxta7IrZ2Qdf9631cK/LA== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:f010:455b:62ce:19e]) (user=kaleshsingh job=sendgmr) by 2002:a25:1c04:0:b0:660:1ffc:fb9 with SMTP id c4-20020a251c04000000b006601ffc0fb9mr12710440ybc.431.1657865504408; Thu, 14 Jul 2022 23:11:44 -0700 (PDT) Date: Thu, 14 Jul 2022 23:10:25 -0700 In-Reply-To: <20220715061027.1612149-1-kaleshsingh@google.com> Message-Id: <20220715061027.1612149-17-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220715061027.1612149-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH v4 16/18] KVM: arm64: Introduce pkvm_dump_backtrace() From: Kalesh Singh To: maz@kernel.org, mark.rutland@arm.com, broonie@kernel.org, madvenka@linux.microsoft.com Cc: will@kernel.org, qperret@google.com, tabba@google.com, kaleshsingh@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, andreyknvl@gmail.com, russell.king@oracle.com, vincenzo.frascino@arm.com, mhiramat@kernel.org, ast@kernel.org, drjones@redhat.com, wangkefeng.wang@huawei.com, elver@google.com, keirf@google.com, yuzenghui@huawei.com, ardb@kernel.org, oupton@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, android-mm@google.com, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dumps the pKVM hypervisor backtrace from EL1 by reading the unwinded addresses from the shared stacktrace buffer. Signed-off-by: Kalesh Singh --- arch/arm64/include/asm/stacktrace/nvhe.h | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/arch/arm64/include/asm/stacktrace/nvhe.h b/arch/arm64/include/asm/stacktrace/nvhe.h index c3f94b10f8f0..ec1a4ee21c21 100644 --- a/arch/arm64/include/asm/stacktrace/nvhe.h +++ b/arch/arm64/include/asm/stacktrace/nvhe.h @@ -190,5 +190,54 @@ static int notrace unwind_next(struct unwind_state *state) } NOKPROBE_SYMBOL(unwind_next); +#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE +DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)], pkvm_stacktrace); + +/** + * pkvm_dump_backtrace - Dump the protected nVHE HYP backtrace. + * + * @hyp_offset: hypervisor offset, used for address translation. + * + * Dumping of the pKVM HYP backtrace is done by reading the + * stack addresses from the shared stacktrace buffer, since the + * host cannot direclty access hyperviosr memory in protected + * mode. + */ +static inline void pkvm_dump_backtrace(unsigned long hyp_offset) +{ + unsigned long *stacktrace_pos; + unsigned long va_mask, pc; + + stacktrace_pos = (unsigned long *)this_cpu_ptr_nvhe_sym(pkvm_stacktrace); + va_mask = GENMASK_ULL(vabits_actual - 1, 0); + + kvm_err("Protected nVHE HYP call trace:\n"); + + /* The stack trace is terminated by a null entry */ + for (; *stacktrace_pos; stacktrace_pos++) { + /* Mask tags and convert to kern addr */ + pc = (*stacktrace_pos & va_mask) + hyp_offset; + kvm_err(" [<%016lx>] %pB\n", pc, (void *)pc); + } + + kvm_err("---- End of Protected nVHE HYP call trace ----\n"); +} +#else /* !CONFIG_PROTECTED_NVHE_STACKTRACE */ +static inline void pkvm_dump_backtrace(unsigned long hyp_offset) +{ + kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE\n"); +} +#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */ + +/** + * kvm_nvhe_dump_backtrace - Dump KVM nVHE hypervisor backtrace. + * + * @hyp_offset: hypervisor offset, used for address translation. + */ +static inline void kvm_nvhe_dump_backtrace(unsigned long hyp_offset) +{ + if (is_protected_kvm_enabled()) + pkvm_dump_backtrace(hyp_offset); +} #endif /* __KVM_NVHE_HYPERVISOR__ */ #endif /* __ASM_STACKTRACE_NVHE_H */ -- 2.37.0.170.g444d1eabd0-goog