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=-12.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,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 B721BC43381 for ; Fri, 5 Feb 2021 18:07:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7460F64E4D for ; Fri, 5 Feb 2021 18:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233684AbhBEQZD (ORCPT ); Fri, 5 Feb 2021 11:25:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:37902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233646AbhBEQTq (ORCPT ); Fri, 5 Feb 2021 11:19:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id CD84E64E36; Fri, 5 Feb 2021 18:01:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612548079; bh=Bjw+NwhSJiekA9yibIou0xtFz7GFWwM2qh2Z7IfduJs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=b4HZizp8pcHVlwOrLYNlzVCFECExmAgpMYBpIaotN429mrIqldMuX+mLpVm+aS0MU /V8FUuY+jMnKmzgliriV7vFHvHSDdRrB8O7sl8iIcS3DDvZ9Jn6/+4+AE5HsLPiDFa aZf9s7FitOkxgvJsmohm0hF9W22GJ/tPEdghM93av/wBi2rIe7vdocYCiN8k9I/F5W h0awdwpj52CjngapeMwPC6oNTlGcBYp5NsB6DfbRNsKt4xNz0+K3z4rIhwCQWz7UpE 1oIzVZLqhPRqap54FS7ZwNWgovFJ+/tTDAZcctOzyDyKEtr2R3rnAwbldU4Vbjg3bp p4UY6ypiDH6SA== Date: Fri, 5 Feb 2021 18:01:13 +0000 From: Will Deacon To: Quentin Perret Cc: Catalin Marinas , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Fuad Tabba , Mark Rutland , David Brazdil Subject: Re: [RFC PATCH v2 17/26] KVM: arm64: Elevate Hyp mappings creation at EL2 Message-ID: <20210205180113.GH22665@willie-the-truck> References: <20210108121524.656872-1-qperret@google.com> <20210108121524.656872-18-qperret@google.com> <20210203153138.GB18974@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On Thu, Feb 04, 2021 at 11:08:33AM +0000, Quentin Perret wrote: > On Wednesday 03 Feb 2021 at 15:31:39 (+0000), Will Deacon wrote: > > On Fri, Jan 08, 2021 at 12:15:15PM +0000, Quentin Perret wrote: > > > @@ -1481,7 +1486,10 @@ static void cpu_set_hyp_vector(void) > > > struct bp_hardening_data *data = this_cpu_ptr(&bp_hardening_data); > > > void *vector = hyp_spectre_vector_selector[data->slot]; > > > > > > - *this_cpu_ptr_hyp_sym(kvm_hyp_vector) = (unsigned long)vector; > > > + if (!is_protected_kvm_enabled()) > > > + *this_cpu_ptr_hyp_sym(kvm_hyp_vector) = (unsigned long)vector; > > > + else > > > + kvm_call_hyp_nvhe(__pkvm_cpu_set_vector, data->slot); > > > > *Very* minor nit, but it might be cleaner to have static inline functions > > with the same prototypes as the hypercalls, just to make the code even > > easier to read. e.g > > > > if (!is_protected_kvm_enabled()) > > _cpu_set_vector(data->slot); > > else > > kvm_call_hyp_nvhe(__pkvm_cpu_set_vector, data->slot); > > > > you could then conceivably wrap that in a macro and avoid having the > > "is_protected_kvm_enabled()" checks explicit every time. > > Happy to do this here, but are you suggesting to generalize this pattern > to other places as well? I think it's probably a good pattern to follow, but no need to generalise it prematurely. > > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > > > index 3cf9397dabdb..9d4c9251208e 100644 > > > --- a/arch/arm64/kvm/mmu.c > > > +++ b/arch/arm64/kvm/mmu.c > > > @@ -225,15 +225,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; > > > + > > > + BUG_ON(!hyp_pgtable); > > > > Can we fail more gracefully, e.g. by continuing without KVM? > > Got any suggestion as to how that can be done? We could also just remove > that line -- that really should not happen. Or downgrade to WARN_ON. Will