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 X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DF94C433E0 for ; Thu, 4 Mar 2021 19:27:43 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 21E2D64F5F for ; Thu, 4 Mar 2021 19:27:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21E2D64F5F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=X7AFYr81GnwjV1TLT+ffbZxg6b35GpJrXOXM1q9UeIM=; b=Gi4D/j8PVFAOFIt2KcCmxEeKi MnP/2NP6Q3Fkf0oG7wuRWHmLl/IVMIFyuK6FyPSKFqOQHDszXH0CA0+r6zZNN6QWO+VUfP6xxfOBF 1o0KM0TCImtq+qvOZ666NOgdHKIRGE1PFv/qjY/BsNkmdKSTayEA1uXK2EIyImKkSUHHLrvyOV/jX LQQ8quR4PlnQAKrjYvqoTQMb1BhXUAAWbjTLZL9cAxZl5MF03t2qlgGmCWvcsO/1+ILTApHLRcgGS 5x1vdKZDd75Z+CxXk1dOFARcN+vVbeqh9js1mM8ZhK8g9WKwa1sI1VxD7lR8QcROd/SsQ3tHlrPtx /xWcXqA1Q==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHtbg-009knY-Px; Thu, 04 Mar 2021 19:25:56 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHtbZ-009klM-D3 for linux-arm-kernel@lists.infradead.org; Thu, 04 Mar 2021 19:25:51 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9CD2A64F60; Thu, 4 Mar 2021 19:25:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614885947; bh=d5oyr0RbUTr11eGau8HQOa9mCj+ZMHZCRHmDN/GuD5o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eoTTgYBi5Y3qIoUH4K2ybb28vRP9ms605NREGXE9ltqXx1sIS6WNUyKEXteNnyJPy eEfyhYFaf9li2Otd8xLVO7qcKq6MJIjSalFKpTMcq17zvI9cwWJKu5Vb5EFb/XYVCZ 2IhNMlyJJZIN8U3rm1c2NqktkoeCD+i0qn2po3eWk5i7wnVk5izKSyIF1LPV5o/s2B 4+q7xqXHuRHVQ0OjT47DYPDjKn2VxmZ9f8NWSo0KIZFDjJ5IHlICuwqRUoBEqS0RvA 8m5RZ0wJ8gGiEWFgJJycEvk9brxtFyGUFBb1kaXyBbB0CCMxFv+GreCHZ0D/QEfFtn shJ9nsNOAfWxg== Date: Thu, 4 Mar 2021 19:25:41 +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 Subject: Re: [PATCH v3 16/32] KVM: arm64: Elevate hypervisor mappings creation at EL2 Message-ID: <20210304192540.GE21795@willie-the-truck> References: <20210302150002.3685113-1-qperret@google.com> <20210302150002.3685113-17-qperret@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210302150002.3685113-17-qperret@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) 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, Mar 02, 2021 at 02:59:46PM +0000, Quentin Perret wrote: > Previous commits have introduced infrastructure to enable the EL2 code > to manage its own stage 1 mappings. However, this was preliminary work, > and none of it is currently in use. > > Put all of this together by elevating the mapping creation at EL2 when > memory protection is enabled. In this case, the host kernel running > at EL1 still creates _temporary_ EL2 mappings, only used while > initializing the hypervisor, but frees them right after. > > As such, all calls to create_hyp_mappings() after kvm init has finished > turn into hypercalls, as the host now has no 'legal' way to modify the > hypevisor page tables directly. > > Signed-off-by: Quentin Perret > --- > arch/arm64/include/asm/kvm_mmu.h | 2 +- > arch/arm64/kvm/arm.c | 87 +++++++++++++++++++++++++++++--- > arch/arm64/kvm/mmu.c | 43 ++++++++++++++-- > 3 files changed, 120 insertions(+), 12 deletions(-) [...] > @@ -1489,13 +1497,14 @@ static void cpu_hyp_reinit(void) > kvm_init_host_cpu_context(&this_cpu_ptr_hyp_sym(kvm_host_data)->host_ctxt); > > cpu_hyp_reset(); > - cpu_set_hyp_vector(); > > if (is_kernel_in_hyp_mode()) > kvm_timer_init_vhe(); > else > cpu_init_hyp_mode(); > > + cpu_set_hyp_vector(); > + > kvm_arm_init_debug(); > > if (vgic_present) > @@ -1691,18 +1700,59 @@ static void teardown_hyp_mode(void) > } > } > > +static int do_pkvm_init(u32 hyp_va_bits) > +{ > + void *per_cpu_base = kvm_ksym_ref(kvm_arm_hyp_percpu_base); > + int ret; > + > + preempt_disable(); > + hyp_install_host_vector(); It's a shame we need this both here _and_ on the reinit path, but it looks like it's necessary. > + ret = kvm_call_hyp_nvhe(__pkvm_init, hyp_mem_base, hyp_mem_size, > + num_possible_cpus(), kern_hyp_va(per_cpu_base), > + hyp_va_bits); > + preempt_enable(); > + > + return ret; > +} [...] > /** > * Inits Hyp-mode on all online CPUs > */ > static int init_hyp_mode(void) > { > + u32 hyp_va_bits; > int cpu; > - int err = 0; > + int err = -ENOMEM; > + > + /* > + * The protected Hyp-mode cannot be initialized if the memory pool > + * allocation has failed. > + */ > + if (is_protected_kvm_enabled() && !hyp_mem_base) > + return err; This skips the error message you get on the out_err path. > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 4d41d7838d53..9d331bf262d2 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -221,15 +221,39 @@ void free_hyp_pgds(void) > if (hyp_pgtable) { > kvm_pgtable_hyp_destroy(hyp_pgtable); > kfree(hyp_pgtable); > + hyp_pgtable = NULL; > } > mutex_unlock(&kvm_hyp_pgd_mutex); > } > > +static bool kvm_host_owns_hyp_mappings(void) > +{ > + if (static_branch_likely(&kvm_protected_mode_initialized)) > + return false; > + > + /* > + * This can happen at boot time when __create_hyp_mappings() is called > + * after the hyp protection has been enabled, but the static key has > + * not been flipped yet. > + */ > + if (!hyp_pgtable && is_protected_kvm_enabled()) > + return false; > + > + WARN_ON(!hyp_pgtable); > + > + return true; return !(WARN_ON(!hyp_pgtable) && is_protected_kvm_enabled()); ? Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel