From patchwork Tue Oct 12 04:35:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12551465 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61712C433EF for ; Tue, 12 Oct 2021 04:53:55 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2FD9C60F21 for ; Tue, 12 Oct 2021 04:53:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2FD9C60F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=eZSPaZe0RWN1PthSONBjAfmJr3FQ9Y0AGggrL8pr6BU=; b=XcbJVt17GztHX7ZbvPVudPiAAF cE5Cw0mkSCEKybC5WmL1G1gk2/lGu1KpbieYekPnGvtuZ0dovp9lER7BPOTQsk4IcJHzanG6rtCUD Rgj8IFZrcpT/hbToQXX/57WelN9TNTI93g+JJdLu1cwcVOQ1OMfrxhLaf9QjHxCOPjO/GHfBzqqRy KN3lLpYx0DvweEwissNEFlQA89kRgkYJVpdWG3ZWYM72Mr9zPMxnwHwvH5GCVZHajD5ezo4LhpVqp ljNmji+X3xMavI7IG73/kUbRGrwKUrxz20PWC8Xm4AlKH5m17i4IUEHPg08TXx07k7nFs6ibGGUc/ jgzpgaVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ma9l6-00BW4i-LK; Tue, 12 Oct 2021 04:51:25 +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 1ma9X2-00BQYV-T5 for linux-arm-kernel@lists.infradead.org; Tue, 12 Oct 2021 04:36:54 +0000 Received: by mail-pj1-x104a.google.com with SMTP id on18-20020a17090b1d1200b001a04d94fd9fso1224354pjb.2 for ; Mon, 11 Oct 2021 21:36:52 -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=X2MC5tS4urnyh50skPCY/9xIv7Rg4adWM6caa08DYXc=; b=inNCt9FpIq76B+VhKdpWkwhHuSBX1gL+4xixhQW+svRbgV2n+ibgsdFUCNmdtoMru2 /it/NY6mdNUiEezsHyd52DTIcssGR44sV17vmvs3biSKEQaMcDmePmVdCsE7EOOmmICQ g3K5iFvnZOU1DXcSFi3420WslBqkRO1yBTilD2CQLSFmjVj/FnILkKaZBBVq8qOJOqwI w07qZGVrqOdO8jQH5FI+AHLzxUDDqdXxSOg6Ln7nkNxoSl1AUhvikgKBoaHiZKe2hZ0S cVlQJHpaMstreT9JmVbLDZ2PiW3p0ajTViN3Kr0rA8/MLsVEqSUGf+/i2fAnNshMHjyF hXmg== 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=X2MC5tS4urnyh50skPCY/9xIv7Rg4adWM6caa08DYXc=; b=Q4F2qhowNMUgGBiVyq9KFvDSNkLCnNDVv11g1FeCduX3XcQKegi6qEsINVuN/+3RHH IWVx2LZpZmbuJslkuSHSt2x+na4k9PQCtisyB4Yrq+p8lp41/NJ0mV5ljixNrlHnP982 pNpckNMERZlLmxvobrRajteo1feb81E2lHqpC6hbUDK8GLazKk+5UWBnff3ywNdQWWHa UDnZ//dWzd7575E+dMxlSA7i/l5/seo/E82beceNlOQZSfsDmhzWUUUFixtWesnLQNOn 4tnPziLzwJDjar/8Vdt3cdwsbP/Z+RVSDiX3QTTgt2b2c/CljvnlbBqNj1eut107ciUa OSSw== X-Gm-Message-State: AOAM532t0iG6Umxo7XTyBRZYhEM5xlNzi/85IsVMPK8DTff4vGgHYTlO wc9kxK6pjLonJaUeAoFV3bTT07VMp3A= X-Google-Smtp-Source: ABdhPJyXRkRDYHX+V64uORGsvksZYYcAzeDYpRvgXni5jgbKqEJlLN+vJO2JfCbxPWmEGCNi7HHH8xh+o+g= X-Received: from reiji-vws.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:15a3]) (user=reijiw job=sendgmr) by 2002:aa7:81c7:0:b0:44c:517f:a759 with SMTP id c7-20020aa781c7000000b0044c517fa759mr29319641pfn.3.1634013411673; Mon, 11 Oct 2021 21:36:51 -0700 (PDT) Date: Mon, 11 Oct 2021 21:35:31 -0700 In-Reply-To: <20211012043535.500493-1-reijiw@google.com> Message-Id: <20211012043535.500493-22-reijiw@google.com> Mime-Version: 1.0 References: <20211012043535.500493-1-reijiw@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [RFC PATCH 21/25] 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-20211011_213653_009876_CCC4F4DE X-CRM114-Status: GOOD ( 11.18 ) 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 | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 595ab1c79bae..23a3bcac4986 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -342,6 +342,38 @@ static struct feature_config_ctrl ftr_ctrl_mte = { .cfg_val = HCR_TID5, }; +/* 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, + .cfg_reg = VCPU_MDCR_EL2, + .cfg_mask = MDCR_EL2_TPM, + .cfg_val = MDCR_EL2_TPM, +}; + +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, + .cfg_reg = VCPU_MDCR_EL2, + .cfg_mask = (MDCR_EL2_TPMS | + (MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT)), + .cfg_val = MDCR_EL2_TPMS, +}; + +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, + .cfg_reg = VCPU_MDCR_EL2, + .cfg_mask = MDCR_EL2_TTRF, + .cfg_val = MDCR_EL2_TTRF, +}; + struct id_reg_info { u32 sys_reg; /* Register ID */ u64 sys_val; /* Sanitized system value */ @@ -727,6 +759,12 @@ static struct id_reg_info id_aa64dfr0_el1_info = { .init = init_id_aa64dfr0_el1_info, .validate = validate_id_aa64dfr0_el1, .get_reset_val = get_reset_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 = {