From patchwork Fri Jul 15 06:10:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 12918780 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9968BC43334 for ; Fri, 15 Jul 2022 06:18:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=MH4eqMpqTIG+RVsRdgDDHFrBpJBJKMMeytGEiav6G78=; b=I06ZGeOexB719/ixR5jops5wR6 Cy9E/bUP1in9b4ay1Z0EoOe16+n+QPu/s+8Lx5v6heC29SDTEvhZW4jGj8EfpyhKYNK7I1Qk1jARj rafK4yaBHSqy4mImFhz7i1Sa02B260sAvRwoazfn1H2V/Yy81WfwCp8mOooOzUrGUUk2xfKjv5sJz vZTuvTIr+LzaOt9G4YamJBn2F/ZS9BDEOP51AwvAn8N3Y+9F7eW60F7k8FbWlprKp9Nx+jjXo4KiO DS/UPBJXuOI6lugkXZi4sKAsciWkQlpW15TfLBOJ5DIpP2wDKlbW15tYODyW6HwEK120i/8isVRtD mFjunL+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCEdT-004YpZ-3y; Fri, 15 Jul 2022 06:17:11 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCEYE-004WXj-21 for linux-arm-kernel@lists.infradead.org; Fri, 15 Jul 2022 06:11:48 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31cb93cadf2so33666157b3.11 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=V9urwvv6uH8qSarQs5MmLUZHysjt7yeBbWJa639ll/HgEN9UIGOmWlXEvJDgEOLHTy 6Y+dSIaXkgXooxqhryjIaE2+KXNVEo4kORa5T1KewtFDZLNn7idudy/MGEvCoP42tXWV ud5/8keNnc+iZm23dQ9rUg81t4O9pwKtqXE+8vyDvkbGCJI8qLhDaobEgUDHR6Uh/Ni3 S5dc2wYa2RFIkOtEWs2Qo5hlQFAXZu65mqArZ9G9mT/PbluB//lnS6G550X0pPDDYQQt Y1MSnlcKLaWQ/aAYKg+a77huNXWBt3UVW3jLSx6vu2N0sv1U/80u4OSt9ytNUR/0yzvY 6JxQ== X-Gm-Message-State: AJIora8HLNmUMaj1t0xaRcyhdeukExl6UfCNi177ml1YbYmWWdz2eAd4 XBF/AOzZ6Odm1uxWXhb3lpE0oWp0s0yR4GFEEA== X-Google-Smtp-Source: AGRyM1vfpvfXbao8rDt6oOq5i85WSVodppQ11DSfR0dlAxIEEuKVDbQoAxSVRuw8vhTAwf/zAn7NyXoNXMOZ7LmHhA== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220714_231146_167197_4DB457C7 X-CRM114-Status: GOOD ( 12.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 */