Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp371606pxm; Tue, 22 Feb 2022 12:37:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyqx/Qr/WE9EbeFfOK3npDZm9U744CqHHZTmJyqqmzbsDVZSFU3VcVGR+OEQTdDv4mdG91O X-Received: by 2002:a17:906:b157:b0:6d0:9f3b:a6aa with SMTP id bt23-20020a170906b15700b006d09f3ba6aamr16609911ejb.365.1645562243466; Tue, 22 Feb 2022 12:37:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645562243; cv=none; d=google.com; s=arc-20160816; b=ciBmlv+JOx/tPKarL8DMp5DLnlCULpgVpIWPTuydFdEjI3uql0tlCshXPzD0QAMgaM niLUpu0/Fs//2NAoSh9C5iL5pZ4BIBmm2IwjMXMALh8WudwnHlxgM7NVRtIdtPc3zm4L MH8Exjn/3JeRY9KEVIcQEmLZHvtCTdc/7bhkmQjwLd89MGA3sz1fjU+mFiT+SNRGiYmR pziuDkzuhuiIqDvXWbvvlI2R2NpaBdyt15xgg3SoB1hV6ljYM2jpq60lDXn8AyD0acf9 pjNI8TXYKjhydeQyU6bO8UhmvbXU/0ltTsUgs5DZA02SzDpEEc9agJJUsXgnnEJKalw3 SJ+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=uCBiIIxMb06jv597+sbcek4mEdnsGlSHEXce/9fMDcc=; b=yKsltfaW6FduHHzdrwksg+lHnpo72z58cX6Ccm05Xh52U9ooxiU4uL6pitj6k6Qmjy 3Nl9qbgL0m6PqabiFLiP3DKyHHwgTINp4srlbJpa0t1EW/IWj1oGIRBXII0Wqzv6T2be qbQXTJlzS31XnXl5br3hDXP5LwpIgwnqOwRzsVtFiPb98RGPu0nfmCMjCRHKPv1YXosW zxCLAJv0J/8wg9uW2n5PzPLCnrh6/T6bfZLTOhtfuBL4CI6hRIi8MPlsprFnVqq523be go+7agjVh15tGKl2WctRIUCoSwrfR3SKjwkMcAWjPnxZITSZr/L88NA6iYMirFsmy64a GEcg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lo1si6627164ejb.702.2022.02.22.12.37.00; Tue, 22 Feb 2022 12:37:23 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235141AbiBVSzc (ORCPT + 99 others); Tue, 22 Feb 2022 13:55:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235136AbiBVSzb (ORCPT ); Tue, 22 Feb 2022 13:55:31 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9483F13AA33 for ; Tue, 22 Feb 2022 10:55:05 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 60D2D1042; Tue, 22 Feb 2022 10:55:05 -0800 (PST) Received: from lakrids (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 15A843F66F; Tue, 22 Feb 2022 10:55:02 -0800 (PST) Date: Tue, 22 Feb 2022 18:55:00 +0000 From: Mark Rutland To: Kalesh Singh Cc: will@kernel.org, maz@kernel.org, qperret@google.com, tabba@google.com, surenb@google.com, kernel-team@android.com, Catalin Marinas , James Morse , Alexandru Elisei , Suzuki K Poulose , Ard Biesheuvel , Pasha Tatashin , Joey Gouly , Peter Collingbourne , Andrew Scull , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu Subject: Re: [PATCH v2 4/9] KVM: arm64: Add guard pages for pKVM (protected nVHE) hypervisor stack Message-ID: References: <20220222165212.2005066-1-kaleshsingh@google.com> <20220222165212.2005066-5-kaleshsingh@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220222165212.2005066-5-kaleshsingh@google.com> X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,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 Tue, Feb 22, 2022 at 08:51:05AM -0800, 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 > --- > 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..69df21320b09 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_OR_NULL(start)) > + return PTR_ERR(start); As on a prior patch, this usage of PTR_ERR() pattern is wrong when the ptr is NULL. > + /* > + * 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); > + if (IS_ERR_OR_NULL(start)) > + return PTR_ERR(start); Likewise. Thanks, Mark. > + 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; > } > > /* > -- > 2.35.1.473.g83b2b277ed-goog >