Received: by 2002:a4a:800f:0:0:0:0:0 with SMTP id x15csp346952oof; Thu, 21 Feb 2019 03:54:33 -0800 (PST) X-Google-Smtp-Source: AHgI3IYKOz4bco3byOaSML2whG+WnVAqMgSi4x0+zCN/NX5WZQsB200SrN5EFQg7o36zuWmXGrio X-Received: by 2002:a63:d157:: with SMTP id c23mr34015825pgj.170.1550750073467; Thu, 21 Feb 2019 03:54:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550750073; cv=none; d=google.com; s=arc-20160816; b=zW1u71gsdEVT9hu4pOa/lo/fWoJjineuGOwjmBVsgCpYMT9DlcoX9BWqVzpSgfldB3 /dxyVFsCTykNiGWBbJXTizTjS4BuQqHcWBH0BH2eHXTuV8X0rnRAgPnBGVZoJHQ+dZ+P JE3JEZ0iUxKClLJXyDJmLuWg+fWK90HmeJCWk4xxcnZkwxZD76xC+Y2rf14PAdKsDBns skroA1u8AWUpDUyDRbCOctyCfRVAYnCIGagw2SAOzqC6GbfcQqeN8UoiShxQPXU6guE+ pezvO1h8zdJQT77RXU8Wga8voa1ZetogKc10pARDcTzMn+E9VDyAi+hp6HluIcmdos6J S40w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=rbT/wicN8vZHvQHgyPAvCIbUf6X5eojad7Nn2PU15ik=; b=lbmq7sD/MAzSIRxi1zQci9fESjad2p/NVlUnDsJusJvDMqFUSvKapUqgGOZttqkp7u oJ/H5CMS8SL9wbrd5gUjJHSH30/Nunx0569NOocEHD9H0wpule/NzKHARcTatgMHkBch JWJQWdlTiNqB5XBmIdnhjvqkdh+cpY0K64zq3ZWWnHzJlN5ZnDUT0QwrnxlSNQ+7ZuqX /KjCnuZBXcclFZ13LXZBO1OkrL23iDTsJy2erGPVv9PydjWgSuyjMu2woBLewcePgm24 O+zVO8E2bei2ozUFU9d0AwwCeWFI874aIvdjFj5U+9bHTQuPa85utTrEdgUXA7hJDRoy osKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y16si13542178pll.83.2019.02.21.03.54.18; Thu, 21 Feb 2019 03:54:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728044AbfBULxM (ORCPT + 99 others); Thu, 21 Feb 2019 06:53:12 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:42772 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727792AbfBULun (ORCPT ); Thu, 21 Feb 2019 06:50:43 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0667580D; Thu, 21 Feb 2019 03:50:43 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6C0E73F5C1; Thu, 21 Feb 2019 03:50:40 -0800 (PST) Date: Thu, 21 Feb 2019 11:50:34 +0000 From: Mark Rutland To: Amit Daniel Kachhap Cc: linux-arm-kernel@lists.infradead.org, Christoffer Dall , Marc Zyngier , Catalin Marinas , Will Deacon , Andrew Jones , Dave Martin , Ramana Radhakrishnan , kvmarm@lists.cs.columbia.edu, Kristina Martsenko , linux-kernel@vger.kernel.org, James Morse , Julien Thierry Subject: Re: [PATCH v6 1/6] arm64/kvm: preserve host HCR_EL2 value Message-ID: <20190221115034.GA33673@lakrids.cambridge.arm.com> References: <1550568271-5319-1-git-send-email-amit.kachhap@arm.com> <1550568271-5319-2-git-send-email-amit.kachhap@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1550568271-5319-2-git-send-email-amit.kachhap@arm.com> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, Feb 19, 2019 at 02:54:26PM +0530, Amit Daniel Kachhap wrote: > From: Mark Rutland > > When restoring HCR_EL2 for the host, KVM uses HCR_HOST_VHE_FLAGS, which > is a constant value. This works today, as the host HCR_EL2 value is > always the same, but this will get in the way of supporting extensions > that require HCR_EL2 bits to be set conditionally for the host. > > To allow such features to work without KVM having to explicitly handle > every possible host feature combination, this patch has KVM save/restore > for the host HCR when switching to/from a guest HCR. The saving of the > register is done once during cpu hypervisor initialization state and is > just restored after switch from guest. > > For fetching HCR_EL2 during kvm initialisation, a hyp call is made using > kvm_call_hyp and is helpful in NHVE case. > > For the hyp TLB maintenance code, __tlb_switch_to_host_vhe() is updated > to toggle the TGE bit with a RMW sequence, as we already do in > __tlb_switch_to_guest_vhe(). > > The value of hcr_el2 is now stored in struct kvm_cpu_context as both host > and guest can now use this field in a common way. > > Signed-off-by: Mark Rutland > [Added __cpu_copy_hyp_conf, hcr_el2 field in struct kvm_cpu_context] > Signed-off-by: Amit Daniel Kachhap > Cc: Marc Zyngier > Cc: Christoffer Dall > Cc: kvmarm@lists.cs.columbia.edu [...] > +/** > + * __cpu_copy_hyp_conf - copy the boot hyp configuration registers > + * > + * It is called once per-cpu during CPU hyp initialisation. > + */ > +static inline void __cpu_copy_hyp_conf(void) I think this would be better named as something like: cpu_init_host_ctxt() ... as that makes it a bit clearer as to what is being initialized. [...] > +/** > + * __kvm_populate_host_regs - Stores host register values > + * > + * This function acts as a function handler parameter for kvm_call_hyp and > + * may be called from EL1 exception level to fetch the register value. > + */ > +void __hyp_text __kvm_populate_host_regs(void) > +{ > + struct kvm_cpu_context *host_ctxt; > + > + if (has_vhe()) > + host_ctxt = this_cpu_ptr(&kvm_host_cpu_state); > + else > + host_ctxt = __hyp_this_cpu_ptr(kvm_host_cpu_state); Do we need the has_vhe() check here? Can't we always do: host_ctxt = __hyp_this_cpu_ptr(kvm_host_cpu_state); ... regardless of VHE? Or is that broken for VHE somehow? Thanks, Mark.