Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4608302yba; Wed, 10 Apr 2019 00:43:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4r2YQNOMFIwXqvS3iU2MtGS/tJs1ZmJZ9bpRWfE/bJrCGb13QkEM2h8wBukYh+MH8Hsin X-Received: by 2002:a62:41dc:: with SMTP id g89mr41957882pfd.109.1554882227666; Wed, 10 Apr 2019 00:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554882227; cv=none; d=google.com; s=arc-20160816; b=SEXONH7HoLHzszlHe5MocyW+QF/J6ZanoECBEaLfSOqUzSUOcOiSpWeREUodkbD3F1 1KodD4w6cD/MzIgibI7BHGF67FKrc8NoKLkQklTM79NtIjGdZNKUvnRkuqpWRF74Wwvs O8u7up2vLTiXK0rpYnf6TrFHGaByqjCfsq2N2kdEsJsL0csfHzTzAuSh5C3/1eOpQ80P HHs+4t3HjqtXjRUKvIxZD9Fz5BGVGmtmaZ/B+q/I4WKYM/Oo/zw3kM+ZPkGkW8ooQ+Op K+2bEXxWhoG7SENVMJMZii98qsz0Bi3NoE3b+gMOcdQqEXZ0rO5KrTnOdlT6fQxenFqU 9l7w== 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=ErohtXhOs75ydI7qACaRLDM6+K3tG2AVpmu1irVFlwY=; b=BS4SzjsozaajavnmsdM6v2LbjtnHz2vyhiHosH7/89hD6aMbpRm/2hg1HzL0X2pcfe 6vnXgci4wMCqR4IvYT73BqCnoIghW/IVcYd/5HEgi+cgFkNbA2ZaosjkpqBfEvc+D5rR s+4EaBGKXN2UU6SJagMpX3qh0S9MHJXCM4chgwft9NHvIDLmXe5hwFu9ErGg3nzf4h6x APYXhbij9rn2viUeiGBpOun2zJCtGh5z+bfuZny96qWzijdp/ciWci58diRDS/+xI9di 6eHppTaVNleTx/QptCw7o0VcnpD4OgevWrGHz8bMbIdZK1CzSXSiAwNGOQYO5nU8N/ra JL8g== 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 i26si31936661pfd.140.2019.04.10.00.43.32; Wed, 10 Apr 2019 00:43:47 -0700 (PDT) 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 S1727841AbfDJGp3 (ORCPT + 99 others); Wed, 10 Apr 2019 02:45:29 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:48300 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727331AbfDJGp3 (ORCPT ); Wed, 10 Apr 2019 02:45:29 -0400 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 7DB79A78; Tue, 9 Apr 2019 23:45:28 -0700 (PDT) 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 BB6CF3F718; Tue, 9 Apr 2019 23:45:24 -0700 (PDT) Subject: Re: [PATCH v8 4/9] KVM: arm/arm64: preserve host HCR_EL2 value To: Marc Zyngier , Kristina Martsenko , James Morse , linux-arm-kernel@lists.infradead.org Cc: Christoffer Dall , Catalin Marinas , Will Deacon , Andrew Jones , Dave Martin , Ramana Radhakrishnan , kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, Mark Rutland , Julien Thierry References: <1554172037-4516-1-git-send-email-amit.kachhap@arm.com> <1554172037-4516-5-git-send-email-amit.kachhap@arm.com> <6131d2cb-1062-6331-c2c3-7026081c458a@arm.com> <9a373ede-cdf8-c992-6f4b-352e46e0030a@arm.com> <1c4e4f50-8324-ed78-1bfd-aee05b6d4fc5@arm.com> From: Amit Daniel Kachhap Message-ID: <4d52c05d-500a-9cd0-4621-6979988ba600@arm.com> Date: Wed, 10 Apr 2019 12:15:22 +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: <1c4e4f50-8324-ed78-1bfd-aee05b6d4fc5@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 Mark, On 4/9/19 2:08 PM, Marc Zyngier wrote: > On 08/04/2019 19:39, Kristina Martsenko wrote: >> On 08/04/2019 14:05, Amit Daniel Kachhap wrote: >>> Hi James, >>> >>> On 4/6/19 4:07 PM, James Morse wrote: >>>> Hi Amit, >>>> >>>> On 02/04/2019 03:27, 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 non-VHE 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. >>>> >>>> These HCR_EL2 flags have had me confused for quite a while. >>>> I thought this was preserving the value that head.S or cpufeature.c had set, and with >>>> ptrauth we couldn't know what this register should be anymore, the host flags has to vary. >>>> >>>> Kristina's explanation of it[0], clarified things, and with a bit more digging it appears >>>> we always set API/APK, even if the hardware doesn't support the feature (as its harmless). >>>> So we don't need to vary the host flags... >>> >>> API/APK is always set for NVHE host mode. >>>> >>>> My question is, what breaks if this patch isn't merged? (the MDCR change is cleanup we can >>>> do because of this HCR change), is this HCR change just cleanup too? If so, can we merge >>>> ptrauth without either, so we only make the change when its needed? (it will cause some >>>> changes in your patch 7, but I can't see where you depend on the host flags). >>> >>> Yes you are right that this patch does not directly effect pointer authentication functionality but contains several optimizations and cleanups such as, >>> >>> * Removes assigning static flags HCR_HOST_VHE_FLAGS/HCR_HOST_NVHE_FLAGS from switch.c so switching functions now are more generic in nature. >>> * Currently the variation in hcr_el2 flags is across modes (VHE/NVHE). Any future conditional change within those modes in host HCR_EL2 may not effect code changes in switch.c >>> * Save of hcr_el2 done at hyp init time so not expensive switching wise. >>> >>> I am fine on posting it separately also. >> >> FWIW I think it makes sense to post the HCR and MDCR patches separately >> from this series. That should make it clear that pointer auth does not >> depend on these changes, and should make it easier to evaluate the >> changes on their own. >> >> Others' opinions are welcome as well. > > Agreed. I'm quite eager to move forward with this series, and the least > unrelated changes it makes, the better. Cleanups and optimizations can > always be merged at a later time. yes sure. I will re-spin the patch series shortly. Thanks, Amit D. > > Thanks, > > M. >