Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3600116imw; Mon, 18 Jul 2022 10:59:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t7d4ZODUgSEsLOqaWZhDPoDsTURGwiU/qhOsW5qeSIK0aEsSsedvXjWqatEVNRo1PG7AO5 X-Received: by 2002:a17:907:a072:b0:72b:57dc:e84c with SMTP id ia18-20020a170907a07200b0072b57dce84cmr25834621ejc.579.1658167184339; Mon, 18 Jul 2022 10:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658167184; cv=none; d=google.com; s=arc-20160816; b=W8UsqPRCsng+eEIi4Iw7bWSsyqW4U/DaRVhXver7AxTmG7dCznwChaG6vGo76j/lvG RSNbQBx8hUyXdcv9BNhW4Z6Zqrq4stjzUtVKs6WpEX+IntHFReJ/Cc4JLPogCcuZEOv2 0LkXu0OpygVsA2Nt8QICV0LI/SVmIJoHIW5W+weASBbrdUuUba//+hBD5g8KGZ8zOaiL AY8BgFetsl5iCl30Ugg4vN+PXRTJPXC/CxOpnuugwbnfVJkxRUlGfaVuM6bphwCW3+Wx kRanxt87cEsHXAfhnA2+UHqkMmLFPQMlYYBML/+I2hLUZPYOyTqaXN14B1XpK1D76dbL OLNg== 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=NarkEMjRQJGNapnFE354uoBB/FLZcCCiwC99PqFL5qY=; b=zXHH4uCVmIp4Y2YTjfSZ4FQPu064Ivi3e2+FP0hMy5MsK0HvpjvypfhzekAqJh90t2 R5EBp3gMcUPjj2G8BrScuP97/dBhs4VVG6lTAmBWeOarzavCd/IRrjm221F96q0Yil/P 4f7Er6EWOjcaIAp4WROXHRuzIkkiOVcn5hfrfa7WaDcgC5TJLmQJJKkANUs4E9bgyA11 IMjyGmOHgQJNjTyDrUUMOSOInnss9PSgPf+J7Huq3qJtyDxDEmh2rxWINB+3oHf2Hqt4 4hHwWZ2UHmOy9hq89muBb5+oklXYOge2306Nch/WP4JPhKJkmux1dNgXdBY+GkyUL6Ve oMnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=S68ky+N9; 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 l18-20020a056402255200b0043999754363si19956602edb.516.2022.07.18.10.59.18; Mon, 18 Jul 2022 10:59:44 -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=S68ky+N9; 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 S235505AbiGRR1Z (ORCPT + 99 others); Mon, 18 Jul 2022 13:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235413AbiGRR1W (ORCPT ); Mon, 18 Jul 2022 13:27:22 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53C452B1AC for ; Mon, 18 Jul 2022 10:27:20 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id z12so18093801wrq.7 for ; Mon, 18 Jul 2022 10:27: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=NarkEMjRQJGNapnFE354uoBB/FLZcCCiwC99PqFL5qY=; b=S68ky+N9MIZZqrGTw9WcCJuhoDR9m6g+zzdzjK+mpiGOlOMkgUPViUE0yazvxbTVav Yrq5OCexwM9wOYoRIMSmHKvc1e1P1m2lzlsgZsk2EINVKLs8FbE86MSoh6jbX/64wkKa TmI3gVVD5vqZl8NwUinYueWQFaCGVMMcBymaWzUannVPb7zYVB2aes/zUjEB7Gqvz8oP ckNfx0wCYQeIKHff5noIKIPvpUTw9XiQOQs7/yQitKejqOP2jE8lybHPfHJRsnt3DgcJ F4v8L+of8kaCZh2iyCodYJ8P9j81QmB/E5GcG0DzpcCt6yBrW7SIvBDgrvYpLW7gCO2l PB1w== 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=NarkEMjRQJGNapnFE354uoBB/FLZcCCiwC99PqFL5qY=; b=g8AClmlI5N1CoYv49EPmSxT6tYQqoBZ80O1DcV+FNmywN3ZOoILn+Zcrlb0tHBwywh SrqS4LY5BIi8lk47Ys9dFBuf9hfaI0mOrNrTMrcwEBhqP1lX60aonVy6jOxtxdgV+RhL 9yqI0mk0fMzF3STclexQaLfr6KV8p7avfhFuxCAh+qCVRI00Wg26mpESPGBihvUfCCZa FQRnZ9PPZuW6TpMSapmYggtIKJRGi/z/GCPImWxuCURztaHndw9jjNLJDEqVOUYXzkm/ n1wc4Y0lfKBq1eJbfyKYGUPqlavBfjmGLQJNfvGeLU3nni3jmPoXK3fdK6JYwoDXDmHf 6VzQ== X-Gm-Message-State: AJIora+5lQcPRGot+cllDiLYkzkKNr5r6cV62/HpFlaHHZUtBPTLuqCG S3Q3W9XAPfck/Y5MvNqeRD7v0ie1hJjpVPypSIVbBg== X-Received: by 2002:a05:6000:1e04:b0:21d:7ec3:fe5a with SMTP id bj4-20020a0560001e0400b0021d7ec3fe5amr23991658wrb.116.1658165238673; Mon, 18 Jul 2022 10:27:18 -0700 (PDT) MIME-Version: 1.0 References: <20220715061027.1612149-1-kaleshsingh@google.com> <20220715061027.1612149-10-kaleshsingh@google.com> <87bktm51xf.wl-maz@kernel.org> In-Reply-To: <87bktm51xf.wl-maz@kernel.org> From: Kalesh Singh Date: Mon, 18 Jul 2022 10:27:07 -0700 Message-ID: Subject: Re: [PATCH v4 09/18] KVM: arm64: Allocate shared pKVM hyp stacktrace buffers To: Marc Zyngier Cc: Mark Rutland , Mark Brown , "Madhavan T. Venkataraman" , Will Deacon , Quentin Perret , Fuad Tabba , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , andreyknvl@gmail.com, russell.king@oracle.com, vincenzo.frascino@arm.com, Masami Hiramatsu , Alexei Starovoitov , Kefeng Wang , Marco Elver , Keir Fraser , Zenghui Yu , Ard Biesheuvel , Oliver Upton , "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , kvmarm , LKML , "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 Mon, Jul 18, 2022 at 12:13 AM Marc Zyngier wrote: > > On Fri, 15 Jul 2022 07:10:18 +0100, > Kalesh Singh wrote: > > > > In protected nVHE mode the host cannot directly access > > hypervisor memory, so we will dump the hypervisor stacktrace > > to a shared buffer with the host. > > > > The minimum size do the buffer required, assuming the min frame > > s/do/for/ ? Ack > > > size of [x29, x30] (2 * sizeof(long)), is half the combined size of > > the hypervisor and overflow stacks plus an additional entry to > > delimit the end of the stacktrace. > > Let me see if I understand this: the maximum stack size is the > combination of the HYP and overflow stacks, and the smallest possible > stack frame is 128bit (only FP+LR). The buffer thus needs to provide > one 64bit entry per stack frame that fits in the combined stack, plus > one entry as an end marker. > > So the resulting size is half of the combined stack size, plus a > single 64bit word. Is this correct? That understanding is correct. So for the 64 KB pages is slightly more than half a page (overflow stack is 4KB). > > > > > The stacktrace buffers are used later in the seried to dump the > > nVHE hypervisor stacktrace when using protected-mode. > > > > Signed-off-by: Kalesh Singh > > --- > > arch/arm64/include/asm/memory.h | 7 +++++++ > > arch/arm64/kvm/hyp/nvhe/stacktrace.c | 4 ++++ > > 2 files changed, 11 insertions(+) > > > > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > > index 0af70d9abede..28a4893d4b84 100644 > > --- a/arch/arm64/include/asm/memory.h > > +++ b/arch/arm64/include/asm/memory.h > > @@ -113,6 +113,13 @@ > > > > #define OVERFLOW_STACK_SIZE SZ_4K > > > > +/* > > + * With the minimum frame size of [x29, x30], exactly half the combined > > + * sizes of the hyp and overflow stacks is needed to save the unwinded > > + * stacktrace; plus an additional entry to delimit the end. > > + */ > > +#define NVHE_STACKTRACE_SIZE ((OVERFLOW_STACK_SIZE + PAGE_SIZE) / 2 + sizeof(long)) > > + > > /* > > * Alignment of kernel segments (e.g. .text, .data). > > * > > diff --git a/arch/arm64/kvm/hyp/nvhe/stacktrace.c b/arch/arm64/kvm/hyp/nvhe/stacktrace.c > > index a3d5b34e1249..69e65b457f1c 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/stacktrace.c > > +++ b/arch/arm64/kvm/hyp/nvhe/stacktrace.c > > @@ -9,3 +9,7 @@ > > > > DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack) > > __aligned(16); > > + > > +#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE > > +DEFINE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)], pkvm_stacktrace); > > +#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */ > > OK, so the allocation exists even if KVM is not running in protected > mode. I guess this is OK for now, but definitely reinforces my request > that this is only there when compiled for debug mode. > Yes, but in the case you aren't running protected mode you can avoid it by setting PROTECTED_NVHE_STACKTRACE=n. Thanks, Kalesh > Thanks, > > M. > > -- > Without deviation from the norm, progress is not possible.