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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D5BBC433EF for ; Mon, 14 Feb 2022 07:01:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241108AbiBNHBQ (ORCPT ); Mon, 14 Feb 2022 02:01:16 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241082AbiBNHBL (ORCPT ); Mon, 14 Feb 2022 02:01:11 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 833BF580D9 for ; Sun, 13 Feb 2022 23:01:04 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id s19-20020a170902b19300b00149a463ad43so5800718plr.1 for ; Sun, 13 Feb 2022 23:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=WUj/Kzsj/O69VN04jOe/HZ0VXGC+h38PtBvDY3Gh//Y=; b=eW4zexmXN7mIa9bVu6vjBGHMgLB/7rpjgnrLO2K6f13JLDDsfUaBLvSc25IiD1Eg67 qlWF+3fKTXbdHykZz6n+oqRY+ZaBxhJOhLmcYzY8+OGuUKTx6mYivvnHJsWLcfpOhxaO LPoJRuijI+7QGo3jzDGcKMw5LK6LvH0o3vq5Lfbo5FvC112L5bQEX33UOPPvb0/LQD2m Gy0xVhzeFU4hd2lDfcGak0sn5As5kwbms8ZRTKDXBX/OMJAqF9/2pEK7hE5Ik4gY9lZ4 cf6SHxybPS5+BJ5njXZ8Ijp0uzJIre2hPoGqCon/10t4LlTHdTTgKo+tPeECnB2ZwzCT zr0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=WUj/Kzsj/O69VN04jOe/HZ0VXGC+h38PtBvDY3Gh//Y=; b=rBL81s4MFuPIoJPUk/smqAQxFrCW37I8R4EJFsCNDc0EZ925i5PFtTvK0QqbGpLBeq exJfmtlCM8PTEEWZL9S4o0e74iDaBaFscCZsHCqZY2aMBtUSeLl5J3Pa7MriwmxiOdcc hTvCPeZlp/kzBoPCy0VZJEMb+Ke6pgDxsog7hpaaA5lA9wXj0GOekBOBFIzC8ovGJ2ux PFER4xJqTbBUTSaxCoaQppQ+RnCp5mCqm/V/RllCvpcj3qdcybI8O8OA/2RJoNRyoP93 SmBW5hCzTl6SHM5HvWCK01iRrgWk5LPo177bChQ9n9EKo8yrGzDv/OHsIoKuufifblIh 6CLQ== X-Gm-Message-State: AOAM530mMcVtMxdE2IGv8Em7uDO0Nvo71eIq9gLCZLTTxSUDHaCbw4rl sWwmFhFrDEsa8JnhS2YpjzeC4ZRE1Kg= X-Google-Smtp-Source: ABdhPJwlxYKRRMUib49hqRqrKo6wQy1TeHvOv+L2pJ6nWfGNBhjTit40UW0kH8YlBovuBGldn0XBTYvEoA0= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:902:cec5:: with SMTP id d5mr12907817plg.143.1644822064037; Sun, 13 Feb 2022 23:01:04 -0800 (PST) Date: Sun, 13 Feb 2022 22:57:37 -0800 In-Reply-To: <20220214065746.1230608-1-reijiw@google.com> Message-Id: <20220214065746.1230608-19-reijiw@google.com> Mime-Version: 1.0 References: <20220214065746.1230608-1-reijiw@google.com> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH v5 18/27] KVM: arm64: Use vcpu->arch cptr_el2 to track value of cptr_el2 for VHE From: Reiji Watanabe To: Marc Zyngier , kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Will Deacon , Andrew Jones , Fuad Tabba , Peng Liang , Peter Shier , Ricardo Koller , Oliver Upton , Jing Zhang , Raghavendra Rao Anata , Reiji Watanabe Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Track the baseline guest value for cptr_el2 in struct kvm_vcpu_arch for VHE. Use this value when setting cptr_el2 for the guest. Currently this value is unchanged, but the following patches will set trapping bits based on features supported for the guest. No functional change intended. Signed-off-by: Reiji Watanabe --- arch/arm64/include/asm/kvm_arm.h | 16 ++++++++++++++++ arch/arm64/kvm/arm.c | 5 ++++- arch/arm64/kvm/hyp/vhe/switch.c | 14 ++------------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 01d47c5886dc..8ab6ea038721 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -288,6 +288,22 @@ GENMASK(19, 14) | \ BIT(11)) +/* + * With VHE (HCR.E2H == 1), accesses to CPACR_EL1 are routed to + * CPTR_EL2. In general, CPACR_EL1 has the same layout as CPTR_EL2, + * except for some missing controls, such as TAM. + * In this case, CPTR_EL2.TAM has the same position with or without + * VHE (HCR.E2H == 1) which allows us to use here the CPTR_EL2.TAM + * shift value for trapping the AMU accesses. + */ +#define CPTR_EL2_VHE_GUEST_DEFAULT (CPACR_EL1_TTA | CPTR_EL2_TAM) + +/* + * Bits that are copied from vcpu->arch.cptr_el2 to set cptr_el2 for + * guest with VHE. + */ +#define CPTR_EL2_VHE_GUEST_TRACKED_MASK (CPACR_EL1_TTA | CPTR_EL2_TAM) + /* Hyp Debug Configuration Register bits */ #define MDCR_EL2_E2TB_MASK (UL(0x3)) #define MDCR_EL2_E2TB_SHIFT (UL(24)) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 68ffced5b09e..7bb744bb23ce 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1182,7 +1182,10 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, } vcpu_reset_hcr(vcpu); - vcpu->arch.cptr_el2 = CPTR_EL2_DEFAULT; + if (has_vhe()) + vcpu->arch.cptr_el2 = CPTR_EL2_VHE_GUEST_DEFAULT; + else + vcpu->arch.cptr_el2 = CPTR_EL2_DEFAULT; /* * Handle the "start in power-off" case. diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c index 11d053fdd604..ed01c4ee9953 100644 --- a/arch/arm64/kvm/hyp/vhe/switch.c +++ b/arch/arm64/kvm/hyp/vhe/switch.c @@ -37,20 +37,10 @@ static void __activate_traps(struct kvm_vcpu *vcpu) ___activate_traps(vcpu); val = read_sysreg(cpacr_el1); - val |= CPACR_EL1_TTA; + val &= ~CPTR_EL2_VHE_GUEST_TRACKED_MASK; + val |= (vcpu->arch.cptr_el2 & CPTR_EL2_VHE_GUEST_TRACKED_MASK); val &= ~CPACR_EL1_ZEN; - /* - * With VHE (HCR.E2H == 1), accesses to CPACR_EL1 are routed to - * CPTR_EL2. In general, CPACR_EL1 has the same layout as CPTR_EL2, - * except for some missing controls, such as TAM. - * In this case, CPTR_EL2.TAM has the same position with or without - * VHE (HCR.E2H == 1) which allows us to use here the CPTR_EL2.TAM - * shift value for trapping the AMU accesses. - */ - - val |= CPTR_EL2_TAM; - if (update_fp_enabled(vcpu)) { if (vcpu_has_sve(vcpu)) val |= CPACR_EL1_ZEN; -- 2.35.1.265.g69c8d7142f-goog