Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp514812pxm; Wed, 2 Mar 2022 03:16:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPx89dJbEoJPX3+pDwdt7Qj9+iMEEWBpHmo+x7g7FMdKxuwYkxdb4DrrsUrQZx9XMAZkhv X-Received: by 2002:a17:906:9b93:b0:6da:6388:dc57 with SMTP id dd19-20020a1709069b9300b006da6388dc57mr1539700ejc.338.1646219760557; Wed, 02 Mar 2022 03:16:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646219760; cv=none; d=google.com; s=arc-20160816; b=ofW/zeFqrL4l/OyUCcODAPY1JYP0KjCU7vCqBPjdPZ7pqLD4kfamAZA+A6csCOw/ks jtYe/TkXyHSIMwTmjVTW7v1WJTC2EwlRhFPLUQfNKUWmZQK5FP/UNTgc66XGGT1IJbk0 c87GST9CmTi2QKP7peE2He7d1//QNG5bxoMowJJGBIOBFnAvCczoRt9YNq6evqw2jKpU w4QnxrB1gGRWyYzxvU6PJyIbOkFErKY30CtT7vfrdVpIVQQF8bkKZwwght6s1G4bK8f9 Y1+8KNuc8ZF0kFjq/u3jTSaSvUliMq6zsblvwp1TRAWihZa/gICIB9o4VVPCdF3QHNju Codw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=BioFtGPRnpetEcsI5bx7bLNBn8+0o8nIZcLGyODvhW0=; b=il1E/UwPPdc+tUNOhGXNKfpPaSZHY+gqmQnCgrEWU/jqh1g06XM3X/iVDj8JCqZQG4 gRK40oBCaYmwLffm7gb3LHwqM5KRG19prIxfdLyp57V7dsvisynTEUOfF+jB61tN1uSH M6xKP4uvds7uw29t68HOeI1IkLP/K17s0gqbaShomXPptqYhplgfTmaJ2yhCUmQwxZTR PX7fRs8TFcyjzW91p4jzav/ZdFLfW7WVY2W79ynGzehSH1+k7MFFv4dZQamMQ7Oqlbh9 hrvZ41X4zon5pl/3wndcXWBH/IdUXU+OpF2RKbx/HUncTf7kJLsQX9A0/iKiuTz/Znhz IP5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dUnB2XUT; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i5-20020a05640242c500b004159d32e23fsi2634519edc.309.2022.03.02.03.15.38; Wed, 02 Mar 2022 03:16:00 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=dUnB2XUT; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239989AbiCBH66 (ORCPT + 99 others); Wed, 2 Mar 2022 02:58:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236101AbiCBH65 (ORCPT ); Wed, 2 Mar 2022 02:58:57 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 685577EA31 for ; Tue, 1 Mar 2022 23:58:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 17A00B81F1E for ; Wed, 2 Mar 2022 07:58:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8CA6C004E1; Wed, 2 Mar 2022 07:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646207891; bh=fHrv4m4CZ1D4uxW2jCaTRj1I7ej4PPHZOGKkWlysm4g=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dUnB2XUTnE5vK5JzLbAgEW50QvwE2+UBfxSaTeoskrlX9XDeXehPnrq/P5UhtMEEM OoCqfowmWiTr5JGkwnZVzxEaRU9L+sGHxYpQMgJ0Qo5zapzgyFjulVDuGyh5GO/4Eq ANmbKiA/vjEudisECe7n+T9xOkvg8i7U6oAHkxWipuvQdAL/BOOMRV7cXTvDhnAG/9 O+Grnr6iOYd0+SWrN0ZIRjoz+ITdwY73Yy6L4SnKASL2kpaQuGJ+lRHlfBRFea7MRA Dvzg8izETb1AKQ34OQjdA6QuTEGc0GY8yhJHOU7BrZ7KtU436+0jYXgGFXWt/+vDc3 3RVNzJL6IfQsQ== Received: from ip-185-104-136-29.ptr.icomera.net ([185.104.136.29] helo=billy-the-mountain.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nPJs9-00BbrE-2m; Wed, 02 Mar 2022 07:58:09 +0000 Date: Wed, 02 Mar 2022 07:58:05 +0000 Message-ID: <87sfs06b1u.wl-maz@kernel.org> From: Marc Zyngier To: Kalesh Singh Cc: will@kernel.org, qperret@google.com, tabba@google.com, surenb@google.com, kernel-team@android.com, James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Mark Rutland , Mark Brown , Masami Hiramatsu , Peter Collingbourne , "Madhavan T. Venkataraman" , Andrew Walbran , Andrew Scull , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 4/8] KVM: arm64: Add guard pages for pKVM (protected nVHE) hypervisor stack In-Reply-To: <20220225033548.1912117-5-kaleshsingh@google.com> References: <20220225033548.1912117-1-kaleshsingh@google.com> <20220225033548.1912117-5-kaleshsingh@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.104.136.29 X-SA-Exim-Rcpt-To: kaleshsingh@google.com, will@kernel.org, qperret@google.com, tabba@google.com, surenb@google.com, kernel-team@android.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com, broonie@kernel.org, mhiramat@kernel.org, pcc@google.com, madvenka@linux.microsoft.com, qwandor@google.com, ascull@google.com, ardb@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Fri, 25 Feb 2022 03:34:49 +0000, Kalesh Singh wrote: > > Maps the stack pages in the flexible private VA range and allocates > guard pages below the stack as unbacked VA space. The stack is aligned > to twice its size to aid overflow detection (implemented in a subsequent > patch in the series). > > Signed-off-by: Kalesh Singh > --- > > Changes in v4: > - Replace IS_ERR_OR_NULL check with IS_ERR check now that > pkvm_alloc_private_va_range() returns an error for null > pointer, per Fuad > > Changes in v3: > - Handle null ptr in IS_ERR_OR_NULL checks, per Mark > > arch/arm64/kvm/hyp/nvhe/setup.c | 25 +++++++++++++++++++++---- > 1 file changed, 21 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c > index 27af337f9fea..1b69a25c1861 100644 > --- a/arch/arm64/kvm/hyp/nvhe/setup.c > +++ b/arch/arm64/kvm/hyp/nvhe/setup.c > @@ -105,11 +105,28 @@ static int recreate_hyp_mappings(phys_addr_t phys, unsigned long size, > if (ret) > return ret; > > - end = (void *)per_cpu_ptr(&kvm_init_params, i)->stack_hyp_va; > + /* > + * Private mappings are allocated upwards from __io_map_base > + * so allocate the guard page first then the stack. > + */ > + start = (void *)pkvm_alloc_private_va_range(PAGE_SIZE, PAGE_SIZE); > + if (IS_ERR(start)) > + return PTR_ERR(start); > + > + /* > + * The stack is aligned to twice its size to facilitate overflow > + * detection. > + */ > + end = (void *)per_cpu_ptr(&kvm_init_params, i)->stack_pa; > start = end - PAGE_SIZE; > - ret = pkvm_create_mappings(start, end, PAGE_HYP); > - if (ret) > - return ret; > + start = (void *)__pkvm_create_private_mapping((phys_addr_t)start, > + PAGE_SIZE, PAGE_SIZE * 2, PAGE_HYP); Similar comments as the previous patch. I'd rather you treat each stack as a two-page VA, populated by a single page. It would be a lot clearer, and less fragile. > + if (IS_ERR(start)) > + return PTR_ERR(start); > + end = start + PAGE_SIZE; > + > + /* Update stack_hyp_va to end of the stack's private VA range */ > + per_cpu_ptr(&kvm_init_params, i)->stack_hyp_va = (unsigned long) end; > } > > /* Thanks, M. -- Without deviation from the norm, progress is not possible.