Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp485461imn; Tue, 26 Jul 2022 00:47:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tjo9d6DBC3u3EVnQjYovKfli8GFcsi0gIvMCyah39QbU8ZOcG1GJ8ZvFCQA4ZfOVVtg+OP X-Received: by 2002:a05:6402:1e8a:b0:43c:570d:760f with SMTP id f10-20020a0564021e8a00b0043c570d760fmr1652653edf.109.1658821627273; Tue, 26 Jul 2022 00:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658821627; cv=none; d=google.com; s=arc-20160816; b=fYqN1aS7AaJPmWJDV80RxgFCPN6Xj+N/MRFOaPDAWPoBvjI6b+2liUhIiiOKq2gwFZ WZhghakc3pKiyfFWNVkjn3AjtGR8OBiks9UUwFcZxHFA7qA8OJ9dGICilo105QxuUiCN 6ydkRbVQzwEeQjPL16z9vwLG6NXLTWfS8927fk9+cC1q6cjWromGaLElp4Sv8LLVGzR9 FyuOuTfJCUPLXwzcQhHDhb0mkYDup6Id3vw4fNdKPTjbJv1U+2m6gdA2wePFDJW5Zvq6 ignjHAd4+COgZq1RGVnx+3AHvtvLseigwfO/NmFeQWk93S3Spcc0b1oZCGI3/ezrftD0 68OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :references:mime-version:message-id:in-reply-to:date:dkim-signature; bh=Yr2SeyZfI0iUSRRhOZVPZMhkgZCPOBYcwpq2LIzTDZU=; b=bGWkS3Qa44v4qV+QQXpatH6BTFYvZnXDJ2bjmhn1kcyrdjknlPaAs+6OlbK8F3KWpx 0mfS0hDmZL0ems3ycDwLLB+TM6DzaPd0O6UB90pi7IK6GrRtyFuoxYML1TWoEH3zTcbn VTN6P7IVIOj838engRep0zMenylvMLZ3Wi7wWz78WDBE7FKbZpPK1ap9LD7KnnExJKOJ 2iLt5hl5RHIKsbrDx1NSVC3x4h008ZQFspy4X44XRHHfl6RiNUR3mDBQ4fAwobK7Ziw5 LlBWKMfvMbTs/PzjFuRjA829BFCYqJ8rub8GPaxbB6BkRNZPy9CG3kwhVVwvIiiolN2b eFxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ld594Kma; 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 i19-20020a056402055300b0043ac66b0d92si12679391edx.379.2022.07.26.00.46.42; Tue, 26 Jul 2022 00:47:07 -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=ld594Kma; 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 S238297AbiGZHkK (ORCPT + 99 others); Tue, 26 Jul 2022 03:40:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238504AbiGZHio (ORCPT ); Tue, 26 Jul 2022 03:38:44 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0118125DB for ; Tue, 26 Jul 2022 00:38:27 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id r64-20020a254443000000b006707b7c2baeso10452626yba.16 for ; Tue, 26 Jul 2022 00:38:27 -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:content-transfer-encoding; bh=Yr2SeyZfI0iUSRRhOZVPZMhkgZCPOBYcwpq2LIzTDZU=; b=ld594KmaC+x5hDg3TfDCFLBo3mJAZfZadHtvCv4LxhROGpYJjZU5u3nKSiZtJGEeDg IIuDeTXXeGCm/m63A/vVxNjaLgs/Y/a/sPcp5QPfaHOHooP7/BenwvBsnpWGgpYKdke2 NSEaG4+gALZAkhG6CrQW2qi5i3MnwMxygSzrgKO+y48x97DWG5b6cKMHnWq5gI3k7I8o aF84buGLeVeeiDm2loKcvHAEv/qJorx273cBmBrFBtvuFayq67ts1t/eZYcPdJiP1OrJ 37UDImjN43qQLenhSw1pgI8Q7IZ/5+VyJ8X+qvF10PD0zs4JSX97+y7BUrreFoc3hEaK +Rtw== 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:content-transfer-encoding; bh=Yr2SeyZfI0iUSRRhOZVPZMhkgZCPOBYcwpq2LIzTDZU=; b=r2zaWBmwvx9BzeVK+P2O6AMgOKvQfBsH0DWiporefLiUW5em70dyyWmsLbjUkK3n9s p2GlLbqVrTSIB1Lql1joc/VrByGjkNk4ClSOvT4dzN4kRSwfwcfn/0lcw6Gr4eb4FQPI bD6T+ObRQrVij+1NCIzMp0cHdZp40Oor6lnRVqCWat6Ukfa7CR14PDYAwPc29drwI9tJ SZUjWnk8g39T/f4v1gj/IdMctXt9pH82nUB7bGqxO8WWJheZWSJXEm6BkWnvIOw6gicY UanmShiSvbleuAEn4SqmphVfxOIKTQnlszmOR/PUnkUUbjpN7I0FK73fiLiApAC7JT/N ta9Q== X-Gm-Message-State: AJIora/v2xZIxetdAJNVRdpNcH1D4YpHGROCFL+eITK1AEwdwJp7mpbK N6aZXCw7B5iqXx2kRDHSHnlMk+ozC+YkEzZrdg== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:4f77:3b64:736a:394e]) (user=kaleshsingh job=sendgmr) by 2002:a81:911:0:b0:31f:4906:80a2 with SMTP id 17-20020a810911000000b0031f490680a2mr1032907ywj.351.1658821107235; Tue, 26 Jul 2022 00:38:27 -0700 (PDT) Date: Tue, 26 Jul 2022 00:37:46 -0700 In-Reply-To: <20220726073750.3219117-1-kaleshsingh@google.com> Message-Id: <20220726073750.3219117-14-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220726073750.3219117-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.37.1.359.gd136c6c3e2-goog Subject: [PATCH v6 13/17] KVM: arm64: Allocate shared pKVM hyp stacktrace buffers From: Kalesh Singh To: maz@kernel.org, mark.rutland@arm.com, broonie@kernel.org, madvenka@linux.microsoft.com, tabba@google.com, oliver.upton@linux.dev Cc: will@kernel.org, qperret@google.com, kaleshsingh@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, andreyknvl@gmail.com, vincenzo.frascino@arm.com, mhiramat@kernel.org, ast@kernel.org, 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" Content-Transfer-Encoding: quoted-printable 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,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 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 for the buffer required, assuming the min frame 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. The stacktrace buffers are used later in the series to dump the nVHE hypervisor stacktrace when using protected-mode. Signed-off-by: Kalesh Singh Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba --- Changes in v6: - Fix typo in commit text, per Fuad - Add Fuad=E2=80=99s Reviewed-by and Tested-by tags Changes in v5: - Fix typo in commit text, per Marc arch/arm64/include/asm/memory.h | 8 ++++++++ arch/arm64/kvm/hyp/nvhe/stacktrace.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memor= y.h index 0af70d9abede..cab80a9a4086 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -113,6 +113,14 @@ =20 #define OVERFLOW_STACK_SIZE SZ_4K =20 +/* + * With the minimum frame size of [x29, x30], exactly half the combined + * sizes of the hyp and overflow stacks is the maximum size needed to + * save the unwinded stacktrace; plus an additional entry to delimit the + * end. + */ +#define NVHE_STACKTRACE_SIZE ((OVERFLOW_STACK_SIZE + PAGE_SIZE) / 2 + size= of(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 b8a280aa026a..e2edda92a108 100644 --- a/arch/arm64/kvm/hyp/nvhe/stacktrace.c +++ b/arch/arm64/kvm/hyp/nvhe/stacktrace.c @@ -34,6 +34,10 @@ static void hyp_prepare_backtrace(unsigned long fp, unsi= gned long pc) stacktrace_info->pc =3D pc; } =20 +#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE +DEFINE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)], pkvm_sta= cktrace); +#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */ + /* * kvm_nvhe_prepare_backtrace - prepare to dump the nVHE backtrace * --=20 2.37.1.359.gd136c6c3e2-goog