From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CDCFC433FE for ; Wed, 2 Mar 2022 07:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239992AbiCBH67 (ORCPT ); Wed, 2 Mar 2022 02:58:59 -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 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.