Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp406236img; Tue, 26 Feb 2019 02:08:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IYKR4YA4jwP9MUXhXHfxwIvB+s307isHQcnNafjlAdQ5Yuw1e688wHQypdcJC0TYeBj4y+y X-Received: by 2002:a63:1021:: with SMTP id f33mr19275793pgl.392.1551175693368; Tue, 26 Feb 2019 02:08:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551175693; cv=none; d=google.com; s=arc-20160816; b=T/Y7Eb/tiB6Z6IqApqup0Z07otoi0bwml6ZtXIds25PCTMnPap9NpqBongglma5AJD DP2aZr1v5TwqNYNpqzDGLnh1ZsYC1GynC2NvdPjc9a9cNlHcu4ilFvOmyw9/zl2BASIL 9eMkbdGpa6ChS56B8yyQVRVbTe+9ev7eRIhj49djEAL3RfmK26G8NJCH60YO1Pu+9621 xzA/l8mwlzsLF1RgHIhyQ+SY7BG/dAoNXb4+XsJ+IpTZKXHaCBnxYLyvJf74U+hwmCDc s6WPNSW6Qs+lUt5BXDQd6je6w7WfB0DtgjDtfd6QA0bYYrUnPJd8ghH2SQoywavwiviE QY4A== 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:references:cc:to:from:subject; bh=/XWZhiEw2EhANXTM0RQdonAZu51HmccCZucwvOrvTbg=; b=egVhqXa4FSZFCcb/GKnxOKCHhq/eQvoi2NQi+H5o2b8/rMH3pms0QXXiRosTi8BC3b 51RJeQIsrcLcPbrzdkLFMUZFoEgDguCMNy9srHAcne2VWHAWD4Hmwr6pGlbZI8c6EX0i 6x3ugVn2d3k0VQBKNs8+BWG9ceTFyzlLdzS9eIy7WW+OeTDFbOSmH4Vy4hO5hK7fEcYF Z1LYj//K4TPUMQfb0TeK2VAnw//5NrMrNTG48vntqfWicvEnitNhrH3VWnxiN7l5fl5E jPQTFdHkBL6o/piTWvztwc5o9EB5V/dNeJPos8LKOkaM9qtoNDumfxef8hWeP496hOg4 ffjg== 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 d16si11369007pgv.70.2019.02.26.02.07.58; Tue, 26 Feb 2019 02:08:13 -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 S1728077AbfBZKGP (ORCPT + 99 others); Tue, 26 Feb 2019 05:06:15 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:44040 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727662AbfBZKGO (ORCPT ); Tue, 26 Feb 2019 05:06:14 -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 500CB80D; Tue, 26 Feb 2019 02:06:14 -0800 (PST) Received: from [10.1.196.105] (eglon.cambridge.arm.com [10.1.196.105]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0CEDE3F71D; Tue, 26 Feb 2019 02:06:11 -0800 (PST) Subject: Re: [PATCH v6 1/6] arm64/kvm: preserve host HCR_EL2 value From: James Morse 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, Mark Rutland , Julien Thierry References: <1550568271-5319-1-git-send-email-amit.kachhap@arm.com> <1550568271-5319-2-git-send-email-amit.kachhap@arm.com> Message-ID: <65651349-e505-bc58-85b0-e6d2b2a2a533@arm.com> Date: Tue, 26 Feb 2019 10:06:10 +0000 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Amit, On 25/02/2019 17:39, James Morse wrote: > On 19/02/2019 09:24, 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. >> diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c >> index 9e350fd3..8e18f7f 100644 >> --- a/virt/kvm/arm/arm.c >> +++ b/virt/kvm/arm/arm.c >> @@ -1328,6 +1328,7 @@ static void cpu_hyp_reinit(void) >> cpu_init_hyp_mode(NULL); >> >> kvm_arm_init_debug(); >> + __cpu_copy_hyp_conf(); > > Your commit message says: > | The saving of the register is done once during cpu hypervisor initialization state > > But cpu_hyp_reinit() is called each time secondary CPUs come online. Its also called as > part of the cpu-idle mechanism via hyp_init_cpu_pm_notifier(). cpu-idle can ask the > firmware to power-off the CPU until an interrupt becomes pending for it. KVM's EL2 state > disappears when this happens, these calls take care of setting it back up again. On Juno, > this can happen tens of times a second, and this adds an extra call to EL2. The bit I missed was the MDCR_EL2 copy is behind kvm_arm_init_debug(), so we already have an unnecessary EL2 call here, so its nothing new. Assuming the deactivate_traps_vhe_put() vcpu isn't needed, and with Mark's comments addressed: Reviewed-by: James Morse If we can avoid repeated calls to EL2 once we've got HCR_EL2+MDCR_EL2, even better! Thanks, James