Received: by 10.213.65.68 with SMTP id h4csp2979370imn; Mon, 9 Apr 2018 12:10:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx48hx6lzTcEgoYOZVrNGTmEI6rdgGjV7jhz4XBJnx2QEXv20OpajOIYc9O+4W2ug7NPWmNnr X-Received: by 2002:a17:902:7b8e:: with SMTP id w14-v6mr25775450pll.52.1523301006923; Mon, 09 Apr 2018 12:10:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523301006; cv=none; d=google.com; s=arc-20160816; b=Fkn5XbSONz/Qn6VbiHBA8CTiYpTJ9ccGG+y0M/DSbis30zyLkqqQAmKoex1DQdmLCp 9O0Z/F7l+7eYi0cnd3J+RS30xw75NjoI8tVy0h5qLuL/V+doRlCihVOXEIPwf2C1ctjx wVNAHq1hCa6GRNGJPN9aCBnpUJV/OOQvmMHWs+wnjD3Az8B7wo795lgQ8Kj4+ryzI9Mt 6blvfJn70/8HFq7wpgry6iMHDZpHdUrtcrlvBdupXWLQ2xbfRfkkgfa+NnaAUlX1xxDw 5I6uzodMkHxYc2+dOCexPf0RZL4Xiq5V+ESIdhKVOzu2HWXoDdGsj+WoKs0fvBuiKVEg /UGQ== 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:dkim-signature:arc-authentication-results; bh=C0OVMopkXV+y5UvXpRDcGPCjZ0qAfsu/anTlsNQW8cE=; b=ZTi/L3hu10D1U1ryuZsuEJVZG3oLEp1Kb46lPEMxgAuQFKHHCuLatt6Fb6zblzKQ3u wumAIwhhQbrdvjbrmQzw4DxQnFYnFAELxsxT/RUeddfXzkphtok5O4a/O77OvVmuHnGu rXCe1abUcH0ngID89EOBjDKpyYZhNs4lVaaaj3H9Dd6kuYN5GeGwoTw58akfG9Orjb77 6ezOLo/Lsi05oHvArlNKgRr1IM/RTpQN1irm/om0iUxy8gVD4M3aWQWNlV4rrq1rkai7 lFtDpTj5dmlNyxynWIdRUC7tpYe7kxOrh60E98hdRfxEwn0D2/vHY1Wl+Q7qkQvtBQjs +KNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@christofferdall-dk.20150623.gappssmtp.com header.s=20150623 header.b=1udonJSb; 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 89-v6si835542pla.572.2018.04.09.12.09.29; Mon, 09 Apr 2018 12:10:06 -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; dkim=fail header.i=@christofferdall-dk.20150623.gappssmtp.com header.s=20150623 header.b=1udonJSb; 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 S1752986AbeDITD3 (ORCPT + 99 others); Mon, 9 Apr 2018 15:03:29 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:53674 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751546AbeDITD1 (ORCPT ); Mon, 9 Apr 2018 15:03:27 -0400 Received: by mail-wm0-f68.google.com with SMTP id 66so14979150wmd.3 for ; Mon, 09 Apr 2018 12:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=C0OVMopkXV+y5UvXpRDcGPCjZ0qAfsu/anTlsNQW8cE=; b=1udonJSbSYXbocjNNyzyRCn61b+zBiq8zxANDta6VtOzPzQNx1999DblNXHqQXGVZs Y6YUpe4tuv90vmpgqntoVWtrnZZ+EL64yK/lpZ7J/7BFkvlQp3EjCG/yjcuHkTctHD+Y ROv/dBIYaib14CrbGdSPd//paI6OZj5fxhqhSduqacvIj2HNdpCNiszIzSIwp7eDMeE8 DNPJE+xmLlYEz32W0kfM2u2fiBoaaLd57BxMYEe9mzaORI3lXwZj0VP3ikM5mLvajb3f VDcGBNsTgIEKtRig5ENLn/Ps1up3Fa+TWbVA3M0CoR078Z7yNlfLmBs0aMCo44cd6Plv 4ADQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=C0OVMopkXV+y5UvXpRDcGPCjZ0qAfsu/anTlsNQW8cE=; b=MlCnjvO8H4EstmWwJJ+Vrw0FW0ZMuFgeW3VvOx7O5gSoAJ5rMsVAqBup+WWfEzACF/ LzO7vwq3PXTH/6E/doX70j1uOTFVzdbLSR4zUu/9skmU4voHUAYaWVdzS7vhCYuOLPFo 4WrDbwLIjidvpUwc1AJmlEIAuhyD84JuwnGXMKECZN8GEifxIZ5IdzPWynBqAJO/ZAs6 vvnXvJwRyWcW/dguyJgen/hIu2meUz8FHmU+I6Sn57ZUclnM03Tpf4IMBbpFWuFeGQvY suZMblb1r0yg+t80mW2iN/OS8hbQFTDu8NEAYV6I6gRP4rVGSut7u5XG1JSukwc0TqDe WWyQ== X-Gm-Message-State: ALQs6tB9n24cdWyOmjwOfXJrJ+Pl2ZJIzm+I04OvU7945ExpAitIhnwx K4CIoc7PSeLWFXX23vgwdJ35hw== X-Received: by 10.80.222.205 with SMTP id d13mr22894229edl.76.1523300606296; Mon, 09 Apr 2018 12:03:26 -0700 (PDT) Received: from localhost (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id k24sm645855ede.62.2018.04.09.12.03.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Apr 2018 12:03:25 -0700 (PDT) Date: Mon, 9 Apr 2018 21:03:24 +0200 From: Christoffer Dall To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, arnd@arndb.de, catalin.marinas@arm.com, kvmarm@lists.cs.columbia.edu, linux-arch@vger.kernel.org, marc.zyngier@arm.com, suzuki.poulose@arm.com, will.deacon@arm.com, yao.qi@arm.com, kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, awallis@codeaurora.org Subject: Re: [PATCHv2 09/12] arm64/kvm: preserve host HCR_EL2 value Message-ID: <20180409190324.GG10904@cbox> References: <20171127163806.31435-1-mark.rutland@arm.com> <20171127163806.31435-10-mark.rutland@arm.com> <20180206123915.GA21802@cbox> <20180409145709.dneotb6xaznw44c4@lakrids.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180409145709.dneotb6xaznw44c4@lakrids.cambridge.arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 09, 2018 at 03:57:09PM +0100, Mark Rutland wrote: > On Tue, Feb 06, 2018 at 01:39:15PM +0100, Christoffer Dall wrote: > > On Mon, Nov 27, 2017 at 04:38:03PM +0000, Mark Rutland wrote: > > > diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c > > > index 525c01f48867..2205f0be3ced 100644 > > > --- a/arch/arm64/kvm/hyp/switch.c > > > +++ b/arch/arm64/kvm/hyp/switch.c > > > @@ -71,6 +71,8 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) > > > { > > > u64 val; > > > > > > + vcpu->arch.host_hcr_el2 = read_sysreg(hcr_el2); > > > + > > > > Looking back at this, it seems excessive to switch this at every > > round-trip. I think it should be possible to have this as a single > > global (or per-CPU) variable that gets restored directly when returning > > from the VM. > > I suspect this needs to be per-cpu, to account for heterogeneous > systems. > > I guess if we move hcr_el2 into kvm_cpu_context, that gives us a > per-vcpu copy for guests, and a per-cpu copy for the host (in the global > kvm_host_cpu_state). > > I'll have a look at how gnarly that turns out. I'm not sure how we can > initialise that sanely for the !VHE case to match whatever el2_setup > did. There's no harm in jumping down to EL2 to read a register during the initialization phase. All it requires is an annotation of the callee function, and a kvm_call_hyp(), and it's actually quite fast unless you start saving/restoring a bunch of additional system registers. See how we call __kvm_set_tpidr_el2() for example. Thanks, -Christoffer