From patchwork Thu Jan 6 04:27:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12705126 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 9DF93C433EF for ; Thu, 6 Jan 2022 04:45:23 +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=ABDDq7eV+VskpXLwM0CcK2WiWO1n+mImlL3LqwRYADU=; b=WZ7N7cSs+CJByb8KsIY57W1a8t +xd2g6bJXKUl7NaLZNzD/FQtLSE4wV7RYIIrVDVBaKPY7AmFcf3zRJ2ye9pzF33Pu98tPYy51AdvC MMExM0b1IaC13ZMPGy2BsEN4qzRksvo9CkHLAWKCpkgFAVpoamlhbRALuhOKuqfMQURUDzAOnEOIj sR7rAPK8yeoI3iIvyYDstGX+1tm7KL+p94r2BTt1okmKhYOMLZtqzdKzYJG2QaX5TCg/i1hKyCJID wAe5bidhfj6lriiTycRTAdeS5rLk8dvrfZchHPwZjRkK3YsL8MEVGpuYk0M4cj3s72e74FpPalrhi 8mTMnzSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5Kcm-00GXmE-IE; Thu, 06 Jan 2022 04:43:42 +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 1n5KOg-00GS5s-6M for linux-arm-kernel@lists.infradead.org; Thu, 06 Jan 2022 04:29:08 +0000 Received: by mail-pj1-x1049.google.com with SMTP id j1-20020a17090a694100b001b1044f134aso1009826pjm.6 for ; Wed, 05 Jan 2022 20:29:05 -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=vAzKz8VnLED7JizGSuKkWSji/qrCKwtnpVmiTZ6Ul2s=; b=nlnwOfQvStw+Mz8pAhxQWNUgrkdZWCwkurIHjLg+9XvBQSKPI0ruIWzx9i3TlRvImH m6z6XWk7Oh0v1de3XruoETBbXK2Jc3oSutRuWqGbdy9A4BeE651nGnvdyAagvVASxvO6 bwJwHrStu95hSl4DhAwVrYf4rivTcyqqYZCcJ70NIos6rkqUoc6F2JVckr2yevgznADu /akLiPtHj2GBhRPH0L3NMvDlX/hZy32zpaNXQDoIxNetZ+8VdkP6inbJiDiSauuxQbR8 VxnyQKrOvCIjh2jISoEhtb7eo5V9ybjPYiJqGYvP5bfcdnMteLYCXlQraB66IgSzQu+2 rZ6Q== 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=vAzKz8VnLED7JizGSuKkWSji/qrCKwtnpVmiTZ6Ul2s=; b=bn+KqZC6v4B1dyoXjyCA1aezFa/0Bc/G538M8x+iKZ5x8/74lwYeBj6dHeJP3nZoZx UHhqpsl+uqy9CUgEMEixftW4ZoBCzi0ZJndsciWZAbFfBUppkbm6Yz17Jn7k68LEwnns GX2oIOZlS7AOkYa9yiWOL8icxVoDuYXJUzVIfBwkOTCP/iTjCINB7nyqqn9OVS1oY4au fkz0WWlIoG45hr05p3SwMKFu/YXEvHA6LjEpZ6N8BJ2ZS+lm3oCbYWt1fTQAk7JvHVMh C9mNFFt9Gu2quRsOE0hSRf2KnLHZ5TBIVPUTgfrnhz24xx/YfMzAokxYojrdtWPkvONO tH3w== X-Gm-Message-State: AOAM531zXHTZ02/oQTPqQzoD5Ft4tAvHboHUg1nKyaIbHF4XDchLcADd +o1eVa2NIJPIdeNnoQ6gxXlC1U+yP9A= X-Google-Smtp-Source: ABdhPJzD5NQdlHGXFcJ/ANmXYaRnVSoPiNlfdJcywqQUu+s82OazALe8sdMAz6vdAAJzU2LN2c+4+RPgFw4= 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:b687:b0:149:90e2:8687 with SMTP id c7-20020a170902b68700b0014990e28687mr39915203pls.131.1641443344718; Wed, 05 Jan 2022 20:29:04 -0800 (PST) Date: Wed, 5 Jan 2022 20:27:04 -0800 In-Reply-To: <20220106042708.2869332-1-reijiw@google.com> Message-Id: <20220106042708.2869332-23-reijiw@google.com> Mime-Version: 1.0 References: <20220106042708.2869332-1-reijiw@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [RFC PATCH v4 22/26] 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 , 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-20220105_202906_295591_1764E490 X-CRM114-Status: GOOD ( 12.02 ) 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 | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 72e745c5a9c2..229671ec3abd 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -349,6 +349,22 @@ 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_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 +391,31 @@ 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_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 { u32 sys_reg; /* Register ID */ u64 sys_val; /* Sanitized system value */ @@ -898,6 +939,12 @@ 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_pmuv3, + &ftr_ctrl_pms, + &ftr_ctrl_tracefilt, + NULL, + }, }; static struct id_reg_info id_dfr0_el1_info = {