From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7035EC001DB for ; Thu, 10 Aug 2023 12:39:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References: Cc:To:Subject:MIME-Version:Date:Message-ID:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PwlE3rwaPKl2CeBVBRj1WMPLsmqE7rw3UqggaFKpT+0=; b=i+d3CDxxAslD3r 4UYamHz3FVpcqjDf74ja7IggEC9kzRM0lYSj+yKCk1Qt1/WgT2Z6xeDIWLsCGGYReuzcMdxKIiKrx tOvh2KNuHecwLjfyHVB09eEyQ41LoQ9LZLdsoTAqtxSrA/zMpufi8lEFcbX5s66txTf/WssU52wc3 GFD8Qu9O7w3X42J1SM/wTUgdxhjOYMKBHy/7kHBs253dChQqTvNRYJWnMfqgPud3H+xMYwm4qrElD wVF/hiPZEBGLnMDMxJdqjYnLdqcKjwrIcV5K/xF7FHovFVjt46S0fsiXJA4f1esSv/I3Diok3KVpo bMUTj6B49CQE5qZICJvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU4w0-007dJq-0F; Thu, 10 Aug 2023 12:38:36 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU4vx-007dIx-0s for linux-arm-kernel@lists.infradead.org; Thu, 10 Aug 2023 12:38:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691671112; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e0Wo4ft2/DV+pES3oEs9VkOI6CJR3CbB7D53EzyrdWY=; b=BV1ALE3AtVXZRZjebwOkQKd/3fEvgBcNDLN0TfdLsyOSLeh4I+EhmFoKuR67ZsBmreke15 dkoiNtWDadlfQZniT0CBlAtvmzAE3x7oVslcquh/j5ChVS+g56GmSkS+kYahUavJg7QT/x yMhvBtwQfzQONanIf/kZ2S/4PSA3BKk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-F_kO8FTVMJOhSLxNInsRuQ-1; Thu, 10 Aug 2023 08:38:31 -0400 X-MC-Unique: F_kO8FTVMJOhSLxNInsRuQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3176ace3f58so535607f8f.0 for ; Thu, 10 Aug 2023 05:38:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691671110; x=1692275910; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:reply-to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=e0Wo4ft2/DV+pES3oEs9VkOI6CJR3CbB7D53EzyrdWY=; b=UEHbmwSpy+dJl/nvutdzsd7LORMe8pXYEa7CqmDSwFP7cXGrA9JsMRGnav8CCav9Rv vfChUyWhWGMVfpA9Govk3wMebWnlbxcEduIc3J3GfvhRcM34GBJUraLd5C8o0tEak9sM Ke5TzUkdt3bWB97GHfMIZaiChkS6xWvoPJkNt68l26Yn2axcryPS96IkqkKC/Uo5p9TN J65qARlCJgO22cXnVzDz1xOEKtY5k7ZIPw+0EfAxAWN2diJNc/wWHf62sU8P2lWcz21E dDcpx6hfaOqwGI+aAEwY+dGR3o1axEYb+dhCH/yMV9NoCrNX+zZ7cKyCeXuWzjgzeaqt rlPw== X-Gm-Message-State: AOJu0YyljlwnPRX6XZGYg4uqsTy85D0AFVlZco+yyDx9jWJUVwQudzKI ldljHMtXfZDQfTc/voE9MPXfS28qKDijij8/DzDkfzs2kWsO8o4DYf1Cs9UtfCfoxNUPYihhKKM whAFgeLsREkzhvupu27qbU5OQWfVQi/NhgOk= X-Received: by 2002:a5d:61d0:0:b0:313:f463:9d40 with SMTP id q16-20020a5d61d0000000b00313f4639d40mr2256908wrv.65.1691671109949; Thu, 10 Aug 2023 05:38:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbXiWhGp1spWUmxlRDOb6WbdU0xknSGtpi8pHz6NkVFa/AtQ/PIb5TpAiXANZhMbQnGi8aQw== X-Received: by 2002:a5d:61d0:0:b0:313:f463:9d40 with SMTP id q16-20020a5d61d0000000b00313f4639d40mr2256889wrv.65.1691671109649; Thu, 10 Aug 2023 05:38:29 -0700 (PDT) Received: from ?IPV6:2a01:e0a:59e:9d80:527b:9dff:feef:3874? ([2a01:e0a:59e:9d80:527b:9dff:feef:3874]) by smtp.gmail.com with ESMTPSA id f18-20020a5d6652000000b003143ba62cf4sm2051508wrw.86.2023.08.10.05.38.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Aug 2023 05:38:28 -0700 (PDT) Message-ID: <15fc525c-7357-7457-c3c2-a8211619e787@redhat.com> Date: Thu, 10 Aug 2023 14:38:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v3 26/27] KVM: arm64: Move HCRX_EL2 switch to load/put on VHE systems To: Marc Zyngier , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Mark Brown , Mark Rutland , Will Deacon , Alexandru Elisei , Andre Przywara , Chase Conklin , Ganapatrao Kulkarni , Darren Hart , Miguel Luis , James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu References: <20230808114711.2013842-1-maz@kernel.org> <20230808114711.2013842-27-maz@kernel.org> From: Eric Auger In-Reply-To: <20230808114711.2013842-27-maz@kernel.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_053833_413111_2350E031 X-CRM114-Status: GOOD ( 21.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: eric.auger@redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Marc, On 8/8/23 13:47, Marc Zyngier wrote: > Although the nVHE behaviour requires HCRX_EL2 to be switched > on each switch between host and guest, there is nothing in > this register that would affect a VHE host. > > It is thus possible to save/restore this register on load/put > on VHE systems, avoiding unnecessary sysreg access on the hot > path. Additionally, it avoids unnecessary traps when running > with NV. > > To achieve this, simply move the read/writes to the *_common() > helpers, which are called on load/put on VHE, and more eagerly > on nVHE. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/hyp/include/hyp/switch.h | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > index a4750070563f..060c5a0409e5 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > @@ -197,6 +197,9 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu) > vcpu->arch.mdcr_el2_host = read_sysreg(mdcr_el2); > write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2); > > + if (cpus_have_final_cap(ARM64_HAS_HCX)) > + write_sysreg_s(HCRX_GUEST_FLAGS, SYS_HCRX_EL2); > + > __activate_traps_hfgxtr(vcpu); > } > > @@ -213,6 +216,9 @@ static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu) > vcpu_clear_flag(vcpu, PMUSERENR_ON_CPU); > } > > + if (cpus_have_final_cap(ARM64_HAS_HCX)) > + write_sysreg_s(HCRX_HOST_FLAGS, SYS_HCRX_EL2); > + > __deactivate_traps_hfgxtr(vcpu); > } > > @@ -227,9 +233,6 @@ static inline void ___activate_traps(struct kvm_vcpu *vcpu) > > if (cpus_have_final_cap(ARM64_HAS_RAS_EXTN) && (hcr & HCR_VSE)) > write_sysreg_s(vcpu->arch.vsesr_el2, SYS_VSESR_EL2); > - > - if (cpus_have_final_cap(ARM64_HAS_HCX)) > - write_sysreg_s(HCRX_GUEST_FLAGS, SYS_HCRX_EL2); > } > > static inline void ___deactivate_traps(struct kvm_vcpu *vcpu) > @@ -244,9 +247,6 @@ static inline void ___deactivate_traps(struct kvm_vcpu *vcpu) > vcpu->arch.hcr_el2 &= ~HCR_VSE; > vcpu->arch.hcr_el2 |= read_sysreg(hcr_el2) & HCR_VSE; > } > - > - if (cpus_have_final_cap(ARM64_HAS_HCX)) > - write_sysreg_s(HCRX_HOST_FLAGS, SYS_HCRX_EL2); > } > > static inline bool __populate_fault_info(struct kvm_vcpu *vcpu) Reviewed-by: Eric Auger Thanks Eric _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel