From patchwork Tue Apr 19 06:55:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12817537 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 D3856C433F5 for ; Tue, 19 Apr 2022 07:19:27 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=L5v6c9flEUeiVthTGbs0+rnJWQFv7VfisEbIThXGcaI=; b=L8M7pJpHTyRhaMNAvedhBMcQrh QMapaycrkuXNHWDMQFL7xYyEda9LNnw9Tdiv8Gp3IvNNwkIlAfn9jCOnbt19RKdfgwKKiEUtxjXU+ YKAc61DWAQbk1V+eEQtyKITM/PC77LqhO6VzwnIF2XqOW/2pJ7F4QJrMi5N0euBOmljLOCYVQYZwW rZVon6MEGvyf7akpgmaMRWSA8KJZkdkhMvQL7IlJorXkEPa/qKab3Jwws+ZT2zaZ/S1H8lM7s1P0K uPMFsZqnkS5sYlVSoFTrCIAHjN4urckC7o38h1sXfIoTy1rmIYxncqlqz3Tg7kNQwb5m30w99IeoE 71b0CRMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngi7t-001vEE-5N; Tue, 19 Apr 2022 07:18:17 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nghoA-001njC-76 for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2022 06:57:56 +0000 Received: by mail-pj1-x104a.google.com with SMTP id v9-20020a17090a7c0900b001cb45f88cdcso10161949pjf.0 for ; Mon, 18 Apr 2022 23:57:53 -0700 (PDT) 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=6xPTbO2+lphyYIiZZ7nszYhBXnFaCQQSE3MHungiG3k=; b=It96CsYEpNqOcLwAVOb9ZqqedaZuQTEj/TXyGKgn91DGN1sbhJ2YzVPkGyHNPtG0Nv aNAZtDspBnw31IkOSfsaQRnyOa1+vukEVhRRJuyFETlx+Xga9HV7nASuyNJsYJd6eFZO Z24gMEtrO+U5npwqvSLXDznZlYHSyFsmBAFIFZoEMTLt46ZN4DzUxj55xgjRqSxJ6hm5 euhJuYDyTiUwy8G6uL3tc5CKsuhmecf0ulBOQZbgyj0Zgb0i2TxRTfji88zGyTtAvcIk KyaEUd4bs969tANr4AJvZOIcTWBIOCB3bZmNr5U2nuMhhVOvPHgX0HvX8PSt923l0aer fGuw== 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=6xPTbO2+lphyYIiZZ7nszYhBXnFaCQQSE3MHungiG3k=; b=ndEaUqJjJkeG2FBHJ2q3hxSh3smnvq4qbLZ221OoNispQYIgSbYZ1etOSphslFUMIv W2OgcFX+XRDKJ1fdPMb+JhrVOv+jJErhmqngs41UQf2Yp8yOtwLXDuNRl892UaiHZH8q 3TNvz7wqdtpkPjFW8/PLE3p05Yp3AJ5hUV01szGH0GLpgRnOu6ajy8Gv53+V1icJeFTq 7ovdx/e0r4uPSzEF7cHxAx/ebIJucfRJ+YFxC03ouuy56FfEF1ezMjPR1kg7671jnZu4 1rCMgkFgmrETbiCkiItXlnAfrI8V1LZxiNpgqyv+Bf4sajW/rywVJFyzcTbsmoslcRIF h+gA== X-Gm-Message-State: AOAM533RNnqZ+KGGnAx0mfM2T4i7nsSq+cyNxwkYlFlN7tBsMJgKh2Bm NcLgexv4KATrnvsGP/kSiVRce63cPCI= X-Google-Smtp-Source: ABdhPJy3D0n5a+z17jnE0L3OXrhl0HuwRJ6F1nYYDplfhvW3GN0Q2u9zJiIaYhrSBbwPfSrzLKaQHN+kyIk= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a05:6a00:1490:b0:4fb:1544:bc60 with SMTP id v16-20020a056a00149000b004fb1544bc60mr16144093pfu.73.1650351472945; Mon, 18 Apr 2022 23:57:52 -0700 (PDT) Date: Mon, 18 Apr 2022 23:55:35 -0700 In-Reply-To: <20220419065544.3616948-1-reijiw@google.com> Message-Id: <20220419065544.3616948-30-reijiw@google.com> Mime-Version: 1.0 References: <20220419065544.3616948-1-reijiw@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v7 29/38] KVM: arm64: Trap disabled features of ID_AA64DFR0_EL1 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220418_235754_329114_250AF7B0 X-CRM114-Status: GOOD ( 11.94 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add feature_config_ctrl for PMUv3, PMS and TraceFilt, which are indicated in ID_AA64DFR0_EL1, to program configuration registers to trap guest's using those features when they are not exposed to the guest. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/sys_regs.c | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 10f366957ce9..a09c910198d6 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -365,6 +365,30 @@ static void feature_mte_trap_activate(struct kvm_vcpu *vcpu) feature_trap_activate(vcpu, VCPU_HCR_EL2, HCR_TID5, HCR_DCT | HCR_ATA); } +static void feature_trace_trap_activate(struct kvm_vcpu *vcpu) +{ + if (has_vhe()) + feature_trap_activate(vcpu, VCPU_CPTR_EL2, CPACR_EL1_TTA, 0); + else + feature_trap_activate(vcpu, VCPU_CPTR_EL2, CPTR_EL2_TTA, 0); +} + +static void feature_pmuv3_trap_activate(struct kvm_vcpu *vcpu) +{ + feature_trap_activate(vcpu, VCPU_MDCR_EL2, MDCR_EL2_TPM, 0); +} + +static void feature_pms_trap_activate(struct kvm_vcpu *vcpu) +{ + feature_trap_activate(vcpu, VCPU_MDCR_EL2, MDCR_EL2_TPMS, + MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT); +} + +static void feature_tracefilt_trap_activate(struct kvm_vcpu *vcpu) +{ + feature_trap_activate(vcpu, VCPU_MDCR_EL2, MDCR_EL2_TTRF, 0); +} + /* For ID_AA64PFR0_EL1 */ static struct feature_config_ctrl ftr_ctrl_ras = { .ftr_reg = SYS_ID_AA64PFR0_EL1, @@ -391,6 +415,39 @@ static struct feature_config_ctrl ftr_ctrl_mte = { .trap_activate = feature_mte_trap_activate, }; +/* For ID_AA64DFR0_EL1 */ +static struct feature_config_ctrl ftr_ctrl_trace = { + .ftr_reg = SYS_ID_AA64DFR0_EL1, + .ftr_shift = ID_AA64DFR0_TRACEVER_SHIFT, + .ftr_min = 1, + .ftr_signed = FTR_UNSIGNED, + .trap_activate = feature_trace_trap_activate, +}; + +static struct feature_config_ctrl ftr_ctrl_pmuv3 = { + .ftr_reg = SYS_ID_AA64DFR0_EL1, + .ftr_shift = ID_AA64DFR0_PMUVER_SHIFT, + .ftr_min = ID_AA64DFR0_PMUVER_8_0, + .ftr_signed = FTR_UNSIGNED, + .trap_activate = feature_pmuv3_trap_activate, +}; + +static struct feature_config_ctrl ftr_ctrl_pms = { + .ftr_reg = SYS_ID_AA64DFR0_EL1, + .ftr_shift = ID_AA64DFR0_PMSVER_SHIFT, + .ftr_min = ID_AA64DFR0_PMSVER_8_2, + .ftr_signed = FTR_UNSIGNED, + .trap_activate = feature_pms_trap_activate, +}; + +static struct feature_config_ctrl ftr_ctrl_tracefilt = { + .ftr_reg = SYS_ID_AA64DFR0_EL1, + .ftr_shift = ID_AA64DFR0_TRACE_FILT_SHIFT, + .ftr_min = 1, + .ftr_signed = FTR_UNSIGNED, + .trap_activate = feature_tracefilt_trap_activate, +}; + #define __FTR_BITS(ftr_sign, ftr_type, bit_pos, safe) { \ .sign = ftr_sign, \ .type = ftr_type, \ @@ -4389,6 +4446,13 @@ static struct id_reg_desc id_aa64dfr0_el1_desc = { .ftr_bits = { S_FTR_BITS(FTR_LOWER_SAFE, ID_AA64DFR0_DOUBLELOCK_SHIFT, 0xf), }, + .trap_features = &(const struct feature_config_ctrl *[]) { + &ftr_ctrl_trace, + &ftr_ctrl_pmuv3, + &ftr_ctrl_pms, + &ftr_ctrl_tracefilt, + NULL, + }, }; static struct id_reg_desc id_dfr0_el1_desc = {