Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1097979yba; Sat, 6 Apr 2019 03:39:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGIWTDncXb1ERCFaXNByfOl4T1SBv4sFT9EgEPH6xdORmiwHexaAl5uIjcT4V5Jd5A9izK X-Received: by 2002:a62:19c3:: with SMTP id 186mr18351723pfz.172.1554547196491; Sat, 06 Apr 2019 03:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554547196; cv=none; d=google.com; s=arc-20160816; b=WG7YkHx+XFvDLR0zTehje4qeYxqpa2l/7Nxo6D7F5K4AFyVRBOCqlL18wFtrbW4PmX DDGdIgD636Pul8VTUMBuQ/ggY9oP4jTXJBV2vxvPiT3MUy5sFCW/4yjy67bGvOAk8wLR FLrJqAX//uKT02SgrBPVtLOchpmOD2ECT1Bl0v3MhI0zRU/YGoH6kPu7+Fw/6V7IrXPw +kVulDiZiPx3D8QGGIStqr1sE23T0N1leuZ9VCdvNdteCpl5T3H0BUKyrkwHpPkPN/gm mu7kfTgYIJnH4LboUoCCk86XcmrzkRXTDGdEZN2M8g4Kw8H7OshJ4uA+HkWVye8jZWqv QvmA== 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=7ePQb5krxGKj8oi6fk72hG+0m07QmHeOF/ZWCA3Sxxk=; b=beytfmiLHomcFzqTY9GarDsifsoxkJi4R1e6Q/e41Ei6pL6oU+n0A4Gj7lS88ZzyG6 J+9yf8Vz8TXkpp5iIUMSX2c1kDvIlp4SPAy72yCSG+yOyk6xI72VzQPFRsan9MZdgi1n nBbbU8M3H3DwvMTf65xPfPCGkjLA3rw1WLRMCbzOmflgt6NFMB+4jceVhOXaKIxQWPTc mK6t76Ncvgn1jPR8xoQMdbUhIaa18yfu/o1Tw8/+m1l8MLFHqDUadN0DTCgUOpLBtSmB Aqoo5qjQJVI4wURnre3KmOKU62+rx9HJjWsfj0i9e+ejHmn1uTXVsLrbIrFgCzMuRatf b5rA== 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 a98si21678398pla.267.2019.04.06.03.39.30; Sat, 06 Apr 2019 03:39:56 -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 S1726499AbfDFKhU (ORCPT + 99 others); Sat, 6 Apr 2019 06:37:20 -0400 Received: from foss.arm.com ([217.140.101.70]:59592 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726458AbfDFKhT (ORCPT ); Sat, 6 Apr 2019 06:37:19 -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 7D88015BF; Sat, 6 Apr 2019 03:37:19 -0700 (PDT) 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 36B6B3F557; Sat, 6 Apr 2019 03:37:17 -0700 (PDT) Subject: Re: [PATCH v8 4/9] KVM: arm/arm64: preserve host HCR_EL2 value To: Amit Daniel Kachhap , linux-arm-kernel@lists.infradead.org Cc: 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: <1554172037-4516-1-git-send-email-amit.kachhap@arm.com> <1554172037-4516-5-git-send-email-amit.kachhap@arm.com> From: James Morse Message-ID: Date: Sat, 6 Apr 2019 11:37:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <1554172037-4516-5-git-send-email-amit.kachhap@arm.com> 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 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... 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). I recall Christoffer wanting to keep the restored DAIF register value on guest-exit static to avoid extra loads/stores when we know what the value would be. I think the same logic applies here. You mentioned in the cover letter the series has some history to it! Thanks, James [0] http://lore.kernel.org/r/7ec2f950-7587-5ecd-6caa-c2fd091ad22c@arm.com