Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2774075iof; Wed, 8 Jun 2022 11:43:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtmqlep37BmoClrVd8cpz/NW31F8G2/ZmiiaxzIO+Z8+xSdX+WqtuxIQmDEbisO7tkqhPJ X-Received: by 2002:a17:907:d90:b0:711:d151:51aa with SMTP id go16-20020a1709070d9000b00711d15151aamr15901423ejc.452.1654713836497; Wed, 08 Jun 2022 11:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654713836; cv=none; d=google.com; s=arc-20160816; b=VrGyVJRYd5hG52w1dV2nXMNFBwiuUSVr7sePtbU/2GieSnJ7PsHjzR4GB4Yru1hmeg ck+nKrr8bj2UbvrNRTj6/ytlN/RvRiSwMiVxr6xe9Dq193zZWMwxEbjO1kQjcFYnktIj 7aa+MwEIyZWnJvtnKvlGqYVuvGvsBU/sNz9MDzEr+qRVZcjz9xZqoSDYO/eaeuXVodYG 8N5ErUS4qTZB/RealqsKQylNYKl+LFosOiG7AU4ioW+AuDrqea8WKpw+so1IQPhWVk3T nKj8V5Ge4paU1i1GF91LaUCztGEb07uYq3k0YhCDxUzO83gHJ2RIc3mD5AndjRsK//Xu b8gA== 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=YI9Mc2y8PFJNJ6+277vO+Lm0SzBPppWh2ZCOqdRyG6U=; b=kBUc67cvn+tWyflDaM5DmB8SogfIOBolJINFifYM1JX2sRSX3mNX9nwUqBXtTAkUhX w4jOkkZlSPpT+c7JMVfH09pAedP/V1qsl+Itl/fgYyahvPgbN8W28CFOFs/KEDlUmKlU YCD09bbB1G+2NZF/fz9u1xvQDts3G7UOEjeYHUIH6IVuZ7B8qa7NP456Q2O+GUOMPONx p05jGjvkSA3Iy8EW2x5/ky9wMT4gQXZnd8r5IWIDahQg90VMvtUZr8E/OOqJM37a3+A9 men6p9yimO85MFbMdfKzheWA221/jsIHxH7IwwWFU+2xpzHFnYk1uz2G8NYhYNLtoNK2 59tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="T6/f1qoA"; 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 gt40-20020a1709072da800b006ff1554acd3si13750850ejc.571.2022.06.08.11.43.10; Wed, 08 Jun 2022 11:43:56 -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="T6/f1qoA"; 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 S233035AbiFHRxL (ORCPT + 99 others); Wed, 8 Jun 2022 13:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232999AbiFHRxH (ORCPT ); Wed, 8 Jun 2022 13:53:07 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12D74DE9E for ; Wed, 8 Jun 2022 10:53:06 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id a10so8756445wmj.5 for ; Wed, 08 Jun 2022 10:53:06 -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=YI9Mc2y8PFJNJ6+277vO+Lm0SzBPppWh2ZCOqdRyG6U=; b=T6/f1qoAHYT15Hdc059V8LrdJ4GLuSvSfJhPDPXC+CHKqgTSOEQjMe4N5wpirC9FtU RM1ZClrDDtGGUlsCUAvtRIHYu9T+qgfZPKRBdo1OkSLN/NVYr5H+xiWvptYKDx6wqeny 98WMYiqOFUzT7s9uim5WWfH7PaQ5W60nWnLtQu1OSsqgNpTO7ud2I//C7+LUHkz58v62 rsQ/j9znMPtuROLFr+FjZXc0UwWxNvrenPI2c7c0cAxxB5dJ7AiY12fFjqgLSjIZ0nPl 3nYmv2UftqPeTJRZ2lCEraPv7280jJJyl1DnnOuSEjLXO4M22RgXjayoWXjoMjFvWeBv rQ8Q== 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=YI9Mc2y8PFJNJ6+277vO+Lm0SzBPppWh2ZCOqdRyG6U=; b=LYS1stGN9SyVBSXgwoJUq0U3s+NblnjNkulFcLm2PL25qHLtHoOGgnaVBo8ETu4xZp 0XirIEoEOsQRNWS6Yx4xWDCYL9pjcnJ/ZtG7SA+byLBDK9mAr7YOihZm9JaEHy79o21t nhXIIF0LKlMlKJal1wwqU8IiZ86MDIfxbwHIDaTs/hkSHqMekxkJk3xeQ7CUnv4vXGJy ae8FaZrMtSHTVdhHNeXhiu6aZha8BaIqw61psq7+TVP7NUyGhSl1u8BqdLyNx/+wOfBV 1Pu5jt/+9uUmm+1kgH7uakCtYDLU7tB3/76eSZ21rfRIZqy/oZQneXx3cg+lACZQwNcS Vxsw== X-Gm-Message-State: AOAM531rR+M5ILgnlPXw5B/jNXAlAZjhSzcoKXaQzBtRF/AycF9ldETJ /R5Gy8ODPNi+Kqgv4md6DHc+SLQ5OZp7UTlPuGP25A== X-Received: by 2002:a1c:7901:0:b0:39c:4252:d7f1 with SMTP id l1-20020a1c7901000000b0039c4252d7f1mr380895wme.178.1654710784341; Wed, 08 Jun 2022 10:53:04 -0700 (PDT) MIME-Version: 1.0 References: <20220607165105.639716-1-kaleshsingh@google.com> <20220607165105.639716-4-kaleshsingh@google.com> <87k09rzk0o.wl-maz@kernel.org> In-Reply-To: <87k09rzk0o.wl-maz@kernel.org> From: Kalesh Singh Date: Wed, 8 Jun 2022 10:52:53 -0700 Message-ID: Subject: Re: [PATCH v3 3/5] KVM: arm64: Add hypervisor overflow stack To: Marc Zyngier Cc: Mark Rutland , Mark Brown , Will Deacon , Quentin Perret , Fuad Tabba , Suren Baghdasaryan , "T.J. Mercier" , "Cc: Android Kernel" , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Masami Hiramatsu , Alexei Starovoitov , "Madhavan T. Venkataraman" , Peter Zijlstra , Andrew Jones , Zenghui Yu , Kefeng Wang , Keir Fraser , Ard Biesheuvel , Oliver Upton , "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , kvmarm , LKML 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, T_SCC_BODY_TEXT_LINE,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 Wed, Jun 8, 2022 at 12:34 AM Marc Zyngier wrote: > > On Tue, 07 Jun 2022 17:50:45 +0100, > Kalesh Singh wrote: > > > > Allocate and switch to 16-byte aligned secondary stack on overflow. This > > provides us stack space to better handle overflows; and is used in > > a subsequent patch to dump the hypervisor stacktrace. > > > > Signed-off-by: Kalesh Singh > > --- > > arch/arm64/kernel/stacktrace.c | 3 +++ > > arch/arm64/kvm/hyp/nvhe/host.S | 9 ++------- > > 2 files changed, 5 insertions(+), 7 deletions(-) > > > > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > > index a84e38d41d38..f346b4c66f1c 100644 > > --- a/arch/arm64/kernel/stacktrace.c > > +++ b/arch/arm64/kernel/stacktrace.c > > @@ -242,4 +242,7 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, > > > > unwind(task, &state, consume_entry, cookie); > > } > > +#else /* __KVM_NVHE_HYPERVISOR__ */ > > +DEFINE_PER_CPU(unsigned long [PAGE_SIZE/sizeof(long)], overflow_stack) > > + __aligned(16); > > Does this need to be a whole page? With 64kB pages, this is > potentially a lot of memory for something that will hardly ever be > used. The rest of the kernel limits this to 4kB, which seems more > reasonable. There is no guard page anyway, so PAGE_SIZE doesn't > provide any extra protection. My oversight on the !4kB page sizes. I think this could be as small as: (STACK_SIZE - 1) / 2 + sizeof(long) '/ 2' : Min frame size (x29, x30) '+ sizeof(long)' : To round up since we only save the one address (PC) for each frame. WDYT? Thanks, Kalesh > > > #endif /* !__KVM_NVHE_HYPERVISOR__ */ > > diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S > > index ea6a397b64a6..4e3032a244e1 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/host.S > > +++ b/arch/arm64/kvm/hyp/nvhe/host.S > > @@ -177,13 +177,8 @@ SYM_FUNC_END(__host_hvc) > > b hyp_panic > > > > .L__hyp_sp_overflow\@: > > - /* > > - * Reset SP to the top of the stack, to allow handling the hyp_panic. > > - * This corrupts the stack but is ok, since we won't be attempting > > - * any unwinding here. > > - */ > > - ldr_this_cpu x0, kvm_init_params + NVHE_INIT_STACK_HYP_VA, x1 > > - mov sp, x0 > > + /* Switch to the overflow stack */ > > + adr_this_cpu sp, overflow_stack + PAGE_SIZE, x0 > > > > b hyp_panic_bad_stack > > ASM_BUG() > > -- > > 2.36.1.255.ge46751e96f-goog > > > > > > Thanks, > > M. > > -- > Without deviation from the norm, progress is not possible.