Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp109172imi; Thu, 21 Jul 2022 17:06:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vV9u8mN9S9qpv+mhIx8UQ0OFP8t0qyLQfrEIHzdSP3Cn52zACreLILyOFIr8ZZgVzE5c18 X-Received: by 2002:a63:1259:0:b0:40d:d290:24ef with SMTP id 25-20020a631259000000b0040dd29024efmr766030pgs.141.1658448415679; Thu, 21 Jul 2022 17:06:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658448415; cv=none; d=google.com; s=arc-20160816; b=Xb8ArXbAcGF1zfzW3N9lYRCpkO1nfRYxXu6TMuG73gVKnpu5iOX0ngrTLBW+I+9suS DHhGxXJcQXYMqdj/T/NaKqC+C5nTtax2A7FQNC8vtSiwaOEyAeFCfg37MBoYQbYoHmA9 YnY63kdN8JGgVQpGtJMoiaWe/OH2PlmduNjZGIPjxdlmjeckJjaUL5Ub2tvB47OQOJg2 zc2wxppLTWPIdb8kJgF3ZRPhDwKHUQa0z93Ehk2gQFD4Zp/avj94EVtE96lItROjyaL7 xcEyvjT0yCVmgp7YcsxqIsrCfTxxmbWCwLe7qPbOODDCr4dTefZ5DjOfio6D4Yoh76eE BxYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TfUx8CmhONPumASQ3Ohn0ZPBwIqk0yRSMBdm0KN2cgU=; b=we8wijWAsxnyVaXi65YP6daV3DW8GQC4DxKzbhBs8dPD4dQX/CLSfG2PaaeEYNzy4E 7+LVyXZwboQfOG0ElnD28DaS5sPgbgQ8K+HkVRfT1+KXgiU07QcUU3Osh9wF1GYaTifA RumgXYAmbYqrbRfCCtv0S1zhScRIgo/CqnAnfqXReBtq0qGhU3GFuBp8S+U5SVFzC5hm 8UNzSDM0Xqw0/DZbPxz5d3DOixr5POBTLa2pUwjKXdzpCM2Uurbbu9ITehZUYVfsTPNF c1tVAiSGX0B5q8KCaVDBytVMPyPFzfEu26rc+NDptkVvm5bT0NFlrR9tfHq/fV3t6uRI hLmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rOHN3ZGG; 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 e25-20020a656799000000b00408b735eff4si3620541pgr.467.2022.07.21.17.06.38; Thu, 21 Jul 2022 17:06:55 -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=rOHN3ZGG; 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 S233436AbiGVAB1 (ORCPT + 99 others); Thu, 21 Jul 2022 20:01:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233314AbiGVABY (ORCPT ); Thu, 21 Jul 2022 20:01:24 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7666F8F530 for ; Thu, 21 Jul 2022 17:01:20 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id by8so3648107ljb.13 for ; Thu, 21 Jul 2022 17:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TfUx8CmhONPumASQ3Ohn0ZPBwIqk0yRSMBdm0KN2cgU=; b=rOHN3ZGGd0VZ8vpBhxUS3HRRKOp92PUaDlqmaWVQgqErtb6Xo8/DY7Q5ALgGDkl1G8 qQ7FlqyStGgGVHuhOQy8qypFsKQl0an3DzVR1DnoI8XA+tnSI9bgkFO0XC0hMI2lE/QL wrMQyRmh4idG2r0aPrIKyi9Ui4tb8TLAnFuCOHGHkKg7V5iR9yCd4zWR1hs2+4bvChdy x40yWVd9k2XjY9Czw6f7QBnQThHo7oCtU7sh2xOK23lJiJx7iwopE2D/670kdQaj0UZG RDlQoapXQoEoN9uzBnp0raGVgaQwy6wESzIK0Be3BQGnm+GFq/VbVNMUye51vkNgxkgT Df8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TfUx8CmhONPumASQ3Ohn0ZPBwIqk0yRSMBdm0KN2cgU=; b=oQIwnHBn5OSsHL+yxHfLbJWKqX3QqG6fP7rEq9IXPucxId3NslvZIX3dd1jbIx+xOs Y7ONUncYXxWskcnKV1KLw96rElJu+Unp7weDPuoGdHjLLokEIa2rpqgRFRLx4XhwQrKw Hr2ALxhIQFN9egy5Xn/nVWY34wlQM4C7hKauFAGFdwP58WpDdpyYpXzq9dTT1Vl2G6T8 5lXoYHRTysR7mckRcoqyMXqmCCy7EBMqYS4JYGqTQMBwgs+ZMC6whaa9blxyT9bODOHT 9ps92+bEIDUXDtA0/pReO9zNgZMAIF2vFT5glMOIp1CUvQPEXtAmAUzudickiPbuH8Xs DbGg== X-Gm-Message-State: AJIora+RcnR9LBatvoWlBmCZkRst3Jk0wkJQJRvYIK8ePi4238Rv1pbP OTysaexknQa+F7yoOcPyOZnW5nhet4coDvn5nDOuHw== X-Received: by 2002:a2e:9d02:0:b0:25d:d6b9:b753 with SMTP id t2-20020a2e9d02000000b0025dd6b9b753mr262234lji.344.1658448078269; Thu, 21 Jul 2022 17:01:18 -0700 (PDT) MIME-Version: 1.0 References: <20220721055728.718573-1-kaleshsingh@google.com> <20220721055728.718573-18-kaleshsingh@google.com> In-Reply-To: From: Kalesh Singh Date: Thu, 21 Jul 2022 17:01:07 -0700 Message-ID: Subject: Re: [PATCH v5 17/17] KVM: arm64: Introduce hyp_dump_backtrace() To: Oliver Upton Cc: Marc Zyngier , Mark Rutland , Mark Brown , "Madhavan T. Venkataraman" , Fuad Tabba , Will Deacon , Quentin Perret , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , andreyknvl@gmail.com, vincenzo.frascino@arm.com, Masami Hiramatsu , Alexei Starovoitov , Andrew Jones , Kefeng Wang , Marco Elver , Keir Fraser , Zenghui Yu , Ard Biesheuvel , "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , kvmarm , LKML , android-mm@google.com, "Cc: Android Kernel" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Thu, Jul 21, 2022 at 1:35 PM Oliver Upton wrote: > > Hi Kalesh, > > Nifty series! Had the chance to take it for a spin :) Few comments > below: Hi Oliver. Thanks for giving it a try :) > > On Wed, Jul 20, 2022 at 10:57:28PM -0700, Kalesh Singh wrote: > > In non-protected nVHE mode, unwinds and dumps the hypervisor backtrace > > from EL1. This is possible beacuase the host can directly access the > > hypervisor stack pages in non-proteced mode. > > > > Signed-off-by: Kalesh Singh > > --- > > > > Changes in v5: > > - Move code out from nvhe.h header to handle_exit.c, per Marc > > - Fix stacktrace symoblization when CONFIG_RAMDOMIZE_BASE is enabled, > > per Fuad > > - Use regular comments instead of doc comments, per Fuad > > > > arch/arm64/kvm/handle_exit.c | 65 +++++++++++++++++++++++++++++++----- > > 1 file changed, 56 insertions(+), 9 deletions(-) > > > > diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c > > index ad568da5c7d7..432b6b26f4ad 100644 > > --- a/arch/arm64/kvm/handle_exit.c > > +++ b/arch/arm64/kvm/handle_exit.c > > [...] > > > @@ -318,6 +319,56 @@ void handle_exit_early(struct kvm_vcpu *vcpu, int exception_index) > > kvm_handle_guest_serror(vcpu, kvm_vcpu_get_esr(vcpu)); > > } > > > > +/* > > + * kvm_nvhe_print_backtrace_entry - Symbolizes and prints the HYP stack address > > + */ > > +static void kvm_nvhe_print_backtrace_entry(unsigned long addr, > > + unsigned long hyp_offset) > > +{ > > + unsigned long va_mask = GENMASK_ULL(vabits_actual - 1, 0); > > + > > + /* Mask tags and convert to kern addr */ > > + addr = (addr & va_mask) + hyp_offset; > > + kvm_err(" [<%016lx>] %pB\n", addr, (void *)(addr + kaslr_offset())); > > +} > > It is a bit odd to see this get churned from the last patch. Is it > possible to introduce the helper earlier on? In fact, the non-protected > patch should come first to layer the series better. Agreed. pKVM is the one with the extra layer. I'll reorder this in the next version. > > Also, it seems to me that there isn't much need for the indirection if > the pKVM unwinder is made to work around the below function signature: Ok, I'll fold it into the below function. > > > > > +/* > > + * hyp_dump_backtrace_entry - Dump an entry of the non-protected nVHE HYP stacktrace > > + * > > + * @arg : the hypervisor offset, used for address translation > > + * @where : the program counter corresponding to the stack frame > > + */ > > +static bool hyp_dump_backtrace_entry(void *arg, unsigned long where) > > +{ > > + kvm_nvhe_print_backtrace_entry(where, (unsigned long)arg); > > + > > + return true; > > +} > > > > > +/* > > + * hyp_dump_backtrace - Dump the non-proteced nVHE HYP backtrace. > > + * > > + * @hyp_offset: hypervisor offset, used for address translation. > > + * > > + * The host can directly access HYP stack pages in non-protected > > + * mode, so the unwinding is done directly from EL1. This removes > > + * the need for shared buffers between host and hypervisor for > > + * the stacktrace. > > + */ > > +static void hyp_dump_backtrace(unsigned long hyp_offset) > > +{ > > + struct kvm_nvhe_stacktrace_info *stacktrace_info; > > + struct unwind_state state; > > + > > + stacktrace_info = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info); > > + > > + kvm_nvhe_unwind_init(&state, stacktrace_info->fp, stacktrace_info->pc); > > + > > + kvm_err("Non-protected nVHE HYP call trace:\n"); > > I don't see the value in discerning non-protected vs. protected in the > preamble, as panic() will dump the kernel commandline which presumably > would have a `kvm-arm.mode=protected` in the case of pKVM. Ok, I'll remove the distinction. > > > > Not entirely your problem, but we should really use a consistent name > for that thing we have living at EL2. Hyp or nVHE (but not both) would > be appropriate. > Right, I think just "nVHE" is probably sufficient. (Open to other suggestions) > > > > + unwind(&state, hyp_dump_backtrace_entry, (void *)hyp_offset); > > + kvm_err("---- End of Non-protected nVHE HYP call trace ----\n"); > > Maybe: > > kvm_err("---[ end ${NAME_FOR_EL2} trace ]---"); > > (more closely matches the pattern of the arm64 stacktrace) Agreed. Thanks, Kalesh > > -- > Thanks, > Oliver