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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35843C433EF for ; Tue, 22 Feb 2022 18:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uobYoZlYuO/Iz1+fTdqZHYGtLTL7wsCQ8GSkOJjzkok=; b=AEKFZMLuPao1Sy LH70Lz5bYrFiEAwyuv1qw4JTj51WdjtFr59alSizubsjRAs1js+ad8qXW9Vyzpqx2emjl5rAjqNmL IdfbbIreqLk109nw984k3iD5+ruk/JQDVl8vqXYKmsi2GmdGB1CIgNTKBTdnSvscM9zpjyjkaGYs9 aC/+yOuWlugbTPb3x1NtBi3904emdcthVFMSLSbKQHx28WBXaBJQ6dl3J9b+FfZkW/8yEW9p6N2fS rIV3cyp9Q2mmsRya43/KCDjxe4m49j3ps8kpV9msXoGn0Um4J1Z8ecZUigVVZ1CJBOv90z4FP6mDe wez1rGSNhSCvjujmA2aQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMaJZ-00BGhz-Bh; Tue, 22 Feb 2022 18:55:09 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMaJW-00BGgy-0u for linux-arm-kernel@lists.infradead.org; Tue, 22 Feb 2022 18:55:07 +0000 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-Disposition: inline In-Reply-To: <20220222165212.2005066-5-kaleshsingh@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220222_105506_132411_F719DA79 X-CRM114-Status: GOOD ( 19.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel