From patchwork Mon Feb 14 06:57:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12745064 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 51951C433F5 for ; Mon, 14 Feb 2022 07:17:32 +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=tm31Y/UUdH+jQ4UswLwRvNietuZs48GtxyGlK7efY2k=; b=K6OU/xkXu5DjdAU4YqAJGCxAOM AkjWwTVJUdDIug7J1UJdtxl5W3IVe7Xo8/OCF9rx/DlhWrOJgxJBtbz+wNqcygAnhcgSKMrWX8Wk3 Gnl64kNLA2GEChIHUXmArlsLK6+pTbOwdOkKi7wgTYOgQwjLNDHxZG9vbWxaikyVctM2xVqrUdBgi x99CAqNUe0vfG27xi/vOPPBmp5SgBSbRuah/41DSu5aDQ8AtVeN8KhUWh3y4repatCW7iEGPuMOD3 DgOpijNGxN7vyramPn3raufleL59N6V7o2S2dmbmxEBTLcuQb0EOG6NBs30kJ+jGXTUw4J2bXI5Ki upmJe62A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJVad-00DdUE-Bv; Mon, 14 Feb 2022 07:16:04 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJVMc-00DXZm-Mo for linux-arm-kernel@lists.infradead.org; Mon, 14 Feb 2022 07:01:36 +0000 Received: by mail-pj1-x1049.google.com with SMTP id jf17-20020a17090b175100b001b90cf26a4eso11535859pjb.3 for ; Sun, 13 Feb 2022 23:01:33 -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=mSRpxjHIlhptG36+PMQyXPeJOkFuTYwuZZGycm/GLdk=; b=rGVTfGKggvN6iR3mSSwoY2Pa7BNpyND9IY5sOWPcyJ/zZjbgwSGeQ0OZrFLTDuG+mJ kE5zYcxxih3QRjNxJsvfG7W4VI8AqCKQlLY9mpc3hiIpsRTLicdumsBcWspVug9vYJ0f VKdVrDoTQVOvJHv1LmX7z5YMegjua8kumBweR+NwZUMc39Q3fF9KWG/i57ZQUwVi/jC7 f5g1tDavr1EPJRBQTe9UbqyoLjf1S+0dkRy886epazldjYK2xwXWgIC3v7x22IhWiE34 hTKpwk9jvsiVnHBT+FR99JOSKm3Iz5cW3fdWEN4dpy1aj3e41aSpUPuc8Jaf5zRPhaCE +QUQ== 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=mSRpxjHIlhptG36+PMQyXPeJOkFuTYwuZZGycm/GLdk=; b=aYPqXaByqBCO1o4F5i/S+qSIOKAG+GKK4onn+QnVCg+PsQ8HMCkRzDcfYcKb6o1Qgq HLK79cmnU/QOgt6o+wfaHgjmkQC0ixVutSpRt8DIiFZYeZoO9ezI7vnsdXMkmSWwMmJj AIJoCJbL3UkdRBzVMVo/dMlnJSEmDazUFrrev7hsiCzrMgcuHGsncHu9YP6027Qyzqc2 p4VQNGhcFUyOOmY+9oSK+swvyyJIWSe8Cp+dgNnbY9QiqgIDe6XlC+3D4iii8K7H1TuW YuzdFOq8SYSdPmJM96+cQlQAOeUqn3AplKD/zAHtk5c5BnLxI+8yxptq4Dn+JC7yudQ1 40jw== X-Gm-Message-State: AOAM530QaOstt3BDCHK1aNkV8fs726ElDdgTE1VRCSTZn0kcDVcJeOs8 dE15h5NOJ4YIZ/lS4MJXWf21XsYoQVo= X-Google-Smtp-Source: ABdhPJx5Hnva0pItL3HUoljdoKfaWez4J61dUM7Uj7HSG9xqpxbCfqSDFLir+dEeNS3ayFvvMXIi9kkilZQ= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:903:404a:: with SMTP id n10mr13009659pla.132.1644822093198; Sun, 13 Feb 2022 23:01:33 -0800 (PST) Date: Sun, 13 Feb 2022 22:57:42 -0800 In-Reply-To: <20220214065746.1230608-1-reijiw@google.com> Message-Id: <20220214065746.1230608-24-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 23/27] 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-20220213_230134_818044_370E0E6D X-CRM114-Status: GOOD ( 11.52 ) 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 a3d22f7f642b..d91be297559d 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -349,6 +349,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, @@ -375,6 +399,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, +}; + struct id_reg_info { /* Register ID */ u32 sys_reg; @@ -941,6 +998,13 @@ static struct id_reg_info id_aa64dfr0_el1_info = { .init = init_id_aa64dfr0_el1_info, .validate = validate_id_aa64dfr0_el1, .vcpu_mask = vcpu_mask_id_aa64dfr0_el1, + .trap_features = &(const struct feature_config_ctrl *[]) { + &ftr_ctrl_trace, + &ftr_ctrl_pmuv3, + &ftr_ctrl_pms, + &ftr_ctrl_tracefilt, + NULL, + }, }; static struct id_reg_info id_dfr0_el1_info = {