Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp504307pxf; Thu, 11 Mar 2021 08:23:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzt3Mij4IwqVP0Ryt1jfxMzC9n2XuLpO6YFqlqShxjYQjH2NlC8N++GZZ+ZNqIgFS9m6Nb0 X-Received: by 2002:aa7:c497:: with SMTP id m23mr9349114edq.74.1615479824407; Thu, 11 Mar 2021 08:23:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615479824; cv=none; d=google.com; s=arc-20160816; b=cLekQo3RdmF54ZVtWlQ92sbin7vWB2rVdduKROvhookDlebwJzxohrz2z+U6HB6rZd ZpQ7zgtt0Os2MZi5WMwKNe5Z0rEKbpy3LGbbKT1oYIilo+29kE/u2f/ra2AUQmXzqtBz tZmmCZrwLeCM3XRAqNgq5xbyuFA9db6/7abh/GJR4L3CSt8MAUUYypjfSgf7toymHZ3U mS45DviQQlC/GBEk7Dzw3mrGyr7XfyZ7dTDiVXW2Z2uOQuzsfu1hfFdowwh9Qq9jPYAV e6SaoupYjfa9bJxxjrP3GHzxYaE/mviPGkRKA6khSkepMF9MOSY6LDbkvd9EQt7qGgho Yb6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=yUbbXs3Sd9kEwN9m70cz8yGTwkr243YBD86uJeS8dH8=; b=fvItEjC6GNr+SUQEnN28mK0hq2KWR+hhfnqScNDG84HzQ5WaOs8FLzO2JZiVVPtFmA 28TiTGoK14Xq9dA84egOAymtQhKwl0cKBvW5ImgmVReeReJjFjwpCNeeUPgB0cmEW+8i pW2VJrS7B3NNtEFQYwgeNQHQqh4zyImCRZ6DjyvyU6ho+58iu5x35Ua7koqdtGPJSKMt jaSqOh2UI1sgI1NGttzK0tU5NYmjBP4yBpBvYvT9HF6flnhqjZW4hlLsNV/2QZnwMmZG JooBaa4hTQCnR6VaMsC1zeJhqyhpYHkH4G+hjoMNP8BYYLaoCqK8m7ptPUJ1IhJUcTHi VdqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=msyy8vEG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c21si2195638edt.47.2021.03.11.08.23.21; Thu, 11 Mar 2021 08:23:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=msyy8vEG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S234522AbhCKQVf (ORCPT + 99 others); Thu, 11 Mar 2021 11:21:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:52778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234455AbhCKQVV (ORCPT ); Thu, 11 Mar 2021 11:21:21 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 753FC6146B; Thu, 11 Mar 2021 16:21:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615479681; bh=T+Bt7gZGUjrxDrEQ2211vo0Svgs66BNqHKZT8ttELhs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=msyy8vEG3L5NnRfp90UsA3PFVsDk+faHyWPzudfFi2aM/2Lvau5b/GnFNFcjIXYZ4 /FPfplr6+dJ+Ygyxek9GF75aVSIKUAhjFY2DwV7sWVm97x5FwS8KoEB8jv0f+eOe5r D+CB5H+c+4unbcsz4kmfZUKT6e4dOQsekhttSnJwJ+Gu+i2j6CiZKKViTJq3oSyeGj 9AHJddEqOypI8jb3iT3JG8m/gWS/Dj0XdFiyEnFY3k24jWWUF64Kk2DzTpcsNKGuQO DVxwDWaJDzz/tETwYwz9YuW6E9q1MifTBV3A3QBKQr83A1938NCDySQy65h8ppgjBl 2vXAIC0pBrEsg== Date: Thu, 11 Mar 2021 16:21:13 +0000 From: Will Deacon To: Quentin Perret Cc: catalin.marinas@arm.com, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, robh+dt@kernel.org, ardb@kernel.org Subject: Re: [PATCH v4 16/34] KVM: arm64: Prepare the creation of s1 mappings at EL2 Message-ID: <20210311162112.GD31206@willie-the-truck> References: <20210310175751.3320106-1-qperret@google.com> <20210310175751.3320106-17-qperret@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210310175751.3320106-17-qperret@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 10, 2021 at 05:57:33PM +0000, Quentin Perret wrote: > When memory protection is enabled, the EL2 code needs the ability to > create and manage its own page-table. To do so, introduce a new set of > hypercalls to bootstrap a memory management system at EL2. > > This leads to the following boot flow in nVHE Protected mode: > > 1. the host allocates memory for the hypervisor very early on, using > the memblock API; > > 2. the host creates a set of stage 1 page-table for EL2, installs the > EL2 vectors, and issues the __pkvm_init hypercall; > > 3. during __pkvm_init, the hypervisor re-creates its stage 1 page-table > and stores it in the memory pool provided by the host; > > 4. the hypervisor then extends its stage 1 mappings to include a > vmemmap in the EL2 VA space, hence allowing to use the buddy > allocator introduced in a previous patch; > > 5. the hypervisor jumps back in the idmap page, switches from the > host-provided page-table to the new one, and wraps up its > initialization by enabling the new allocator, before returning to > the host. > > 6. the host can free the now unused page-table created for EL2, and > will now need to issue hypercalls to make changes to the EL2 stage 1 > mappings instead of modifying them directly. > > Note that for the sake of simplifying the review, this patch focuses on > the hypervisor side of things. In other words, this only implements the > new hypercalls, but does not make use of them from the host yet. The > host-side changes will follow in a subsequent patch. > > Credits to Will for __pkvm_init_switch_pgd. > > Co-authored-by: Will Deacon > Signed-off-by: Will Deacon > Signed-off-by: Quentin Perret > --- > arch/arm64/include/asm/kvm_asm.h | 4 + > arch/arm64/include/asm/kvm_host.h | 7 + > arch/arm64/include/asm/kvm_hyp.h | 8 ++ > arch/arm64/include/asm/kvm_pgtable.h | 2 + > arch/arm64/kernel/image-vars.h | 16 +++ > arch/arm64/kvm/hyp/Makefile | 2 +- > arch/arm64/kvm/hyp/include/nvhe/mm.h | 71 ++++++++++ > arch/arm64/kvm/hyp/nvhe/Makefile | 4 +- > arch/arm64/kvm/hyp/nvhe/hyp-init.S | 27 ++++ > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 49 +++++++ > arch/arm64/kvm/hyp/nvhe/mm.c | 173 +++++++++++++++++++++++ > arch/arm64/kvm/hyp/nvhe/setup.c | 197 +++++++++++++++++++++++++++ > arch/arm64/kvm/hyp/pgtable.c | 2 - > arch/arm64/kvm/hyp/reserved_mem.c | 92 +++++++++++++ > arch/arm64/mm/init.c | 3 + > 15 files changed, 652 insertions(+), 5 deletions(-) > create mode 100644 arch/arm64/kvm/hyp/include/nvhe/mm.h > create mode 100644 arch/arm64/kvm/hyp/nvhe/mm.c > create mode 100644 arch/arm64/kvm/hyp/nvhe/setup.c > create mode 100644 arch/arm64/kvm/hyp/reserved_mem.c Acked-by: Will Deacon Will