Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp333557img; Wed, 27 Feb 2019 23:38:26 -0800 (PST) X-Google-Smtp-Source: AHgI3IYlarjNUtqHLocwFAePaFJzKOGO9douMe0l9pnDjlUENP+cUvPa51MGT0iPYO01A1teOpei X-Received: by 2002:a63:4509:: with SMTP id s9mr7067724pga.420.1551339506721; Wed, 27 Feb 2019 23:38:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551339506; cv=none; d=google.com; s=arc-20160816; b=mGYCfabplwpC8Sk76hTjV/s6QIgM2HVoJ0aK7kGQKSv8HUEjQoWl5bksrnMx1XA5XO 1GQsmgdpDPhEf0hdUpES2wtugXpKGo213yHZ9sxgWCs6nHZ5rRa5Rxdcmfv0cx8PA0w2 MmMy4LSGEOrmEYZW1IEoQzOwZJD2vhjAa5+o+4TAaXYb6j6lI2eomsEkXmGnvhZcdIMj oer1tq5YBehllbtyhQFn9BZmgv0wvbrX+xQRzEeafTCftb2GDEJo4H3D0VEASIrBZ0y3 s1sgmyQXWCGasA3HXtEm2yjQZaHBO7wSfEJuSV7SbxfktWiDuLBxsJwfKEQFZtiXdIKK InVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=AoiEhG9EeOf1bE0V7jfcQZGmD5ytqKBl1g1TDmVEMbE=; b=col9pg9kQ3MBVQCCI8nm7+3CKnLJCBTnV0IXnoj/kW8VK1msFhxPD3VawWA+vjhUqS 0UxdmjdcKvMP2D9dplZ6plsadUZA/RR5x/sLe7muBb5SmL3rK+Nwu1bBKCcJOGf3vE1c sEfg7tEX+uaPdDdMJ+H/oORq3JnVdV7DURiwmdUndlXCk5rh+x8N3VyKw+1pap/XzIrm 5+70IXJsfTayOcPPrfaraDe8MPCurkaLkIXAYFxBhFNmK5GQXUIbl8TghWzICeGA6mBH 59ibNha7+aBp+TfDzrxahyOTM5sNP2FWRj+iA+yGBd5PaWS3b4xQZqNQ1HgzuxtbAZju 2/tQ== 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 18si16316549pgb.383.2019.02.27.23.38.11; Wed, 27 Feb 2019 23:38:26 -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 S1731057AbfB1Gnw (ORCPT + 99 others); Thu, 28 Feb 2019 01:43:52 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:43412 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727819AbfB1Gnv (ORCPT ); Thu, 28 Feb 2019 01:43:51 -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 7CCE080D; Wed, 27 Feb 2019 22:43:51 -0800 (PST) Received: from [10.162.0.144] (a075553-lin.blr.arm.com [10.162.0.144]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A52D33F575; Wed, 27 Feb 2019 22:43:47 -0800 (PST) Subject: Re: [PATCH v6 1/6] arm64/kvm: preserve host HCR_EL2 value To: Mark Rutland 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 References: <1550568271-5319-1-git-send-email-amit.kachhap@arm.com> <1550568271-5319-2-git-send-email-amit.kachhap@arm.com> <20190221115034.GA33673@lakrids.cambridge.arm.com> From: Amit Daniel Kachhap Message-ID: Date: Thu, 28 Feb 2019 12:13:44 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190221115034.GA33673@lakrids.cambridge.arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2/21/19 5:20 PM, Mark Rutland wrote: > 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. ok, Agreed with the name. > > [...] > >> +/** >> + * __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? Yes it works fine for VHE. I missed this. Thanks, Amit > > Thanks, > Mark. >