From patchwork Tue Apr 19 06:55:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12817538 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 13D88C433EF for ; Tue, 19 Apr 2022 07:20: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=9cLnF93Reg3wjk+/U1gqOYKfKmW7VtJMbabl/01qhBA=; b=HGvjmZa4arpDBCJca0oqmSBd0I fd53XAPAyrry8C+Yjt2Bp1QhL5JXnV/wLt6XAdqFcfocFnPqSOKU/miKyqafNtJ8A0pl1jf1ZScVO TlKtHvuCQ1F4SxKtMuItG5czzKvF3S8bcEVspH9XSh9eCPk9zAs0y8+cytnGGPF+XO9lX6NEkCKWf RqT79yAwGz9YppnI9sDRClDfbJ3S1TxlrAYoHFeZY1iEvCr/2LaXAQp/PRa85Aj2ZKc2XrVFyGkiv jVgHa94Jc+gPUytpuRr3nfIUfjGndGToqIMvzbHl50psdD3rGJUd41S1n7/3tc2E3NXpdXfdvSLvq VlAfdgfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngi8p-001vb1-BW; Tue, 19 Apr 2022 07:19:15 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nghoB-001nk1-St for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2022 06:57:57 +0000 Received: by mail-pl1-x649.google.com with SMTP id k2-20020a170902ba8200b0015613b12004so9241831pls.22 for ; Mon, 18 Apr 2022 23:57:54 -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=FGn+d1/fzCMoysQ55Sv7panNzkYFCREIVH43wm5V/xU=; b=nbP6H9eLPB2KRUszqjTjx8oXBwErZ7lIfZHOLtdkJWYF4Y8A1N/NpiaKp37xuFx1Ud XFYUj8R3HIK/2yg2tTUzGPz29aiDAuuxLbJAZvX5j0DVwEfJ9DmZqNZuYwG854scSWEU KCgssLZ9jYfOjk0MY1SCFqfXsElf5DH70nSmWeFUNB3+TPODZGz0TwDe1XiI63R4XGqW dqIprL+Vy62aXPKqODFGp8794SpD9CXf3AgMD2as9uU2afjv9U086jbrTKkU7e+iSTca ZNe8BSjcDOQEwLGE2Riw8tDL09c0xKw6YVhUNpoL+BtOcOk72Wj/EgA9R6I8puV0x1Po kLNw== 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=FGn+d1/fzCMoysQ55Sv7panNzkYFCREIVH43wm5V/xU=; b=n7nTJ2rF6VMjnSVSepYRCzc/MxaIQfQTY6wdtanCd6HXcVHzRKevMmnG1Cu8qWRUXg JKdUzf/m+jPaaIQjnLw1RkRwZxG9UdA59u4I3r3QCQITHHLx+cECPfiDLNY5sK69H7CP H0P9cZgeHorgQND+ujYSnr64OmAIgfMYxzWiabB1lZ41xYc+krQmIZIR5uP8MriLaXvO G+cfJqBSj8D6XqdPP/oqExcM1bQpprt0MnAkHo7QlJxllQ2DhHvDjRbXMfZXeaZjY3zY fYSOS5M3NIRQExL4n+Q3xTnuPrX5hG+jvyHWNXYeRnCBozBtrju8RI+50EbpW786GZZt qzVA== X-Gm-Message-State: AOAM533RJjLtdta1Our+/hA5QY4kucc8PxwzNeSaACueptzbJc5nSj8C FDN0eeBlHtZKnolzFtHIDa3ws/wvsq8= X-Google-Smtp-Source: ABdhPJxpYOikvgNJvHHbbpFpSUMKs8Qh1bxceFJTHg4QBYMxz42FIi3eaMxP3/8CTDdPHB7uL9Sp54w8dR0= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:90b:3b86:b0:1d2:66cf:569b with SMTP id pc6-20020a17090b3b8600b001d266cf569bmr14889978pjb.206.1650351474413; Mon, 18 Apr 2022 23:57:54 -0700 (PDT) Date: Mon, 18 Apr 2022 23:55:36 -0700 In-Reply-To: <20220419065544.3616948-1-reijiw@google.com> Message-Id: <20220419065544.3616948-31-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 30/38] KVM: arm64: Trap disabled features of ID_AA64MMFR1_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_235755_984229_5BCB4AB8 X-CRM114-Status: GOOD ( 14.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 LORegions, which is indicated in ID_AA64MMFR1_EL1, to program configuration register to trap guest's using the feature when it is not exposed to the guest. Change trap_loregion() to use vcpu_feature_is_available() to simplify checking of the feature's availability. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/sys_regs.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index a09c910198d6..6a8ed59d8d90 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -389,6 +389,11 @@ static void feature_tracefilt_trap_activate(struct kvm_vcpu *vcpu) feature_trap_activate(vcpu, VCPU_MDCR_EL2, MDCR_EL2_TTRF, 0); } +static void feature_lor_trap_activate(struct kvm_vcpu *vcpu) +{ + feature_trap_activate(vcpu, VCPU_HCR_EL2, HCR_TLOR, 0); +} + /* For ID_AA64PFR0_EL1 */ static struct feature_config_ctrl ftr_ctrl_ras = { .ftr_reg = SYS_ID_AA64PFR0_EL1, @@ -448,6 +453,15 @@ static struct feature_config_ctrl ftr_ctrl_tracefilt = { .trap_activate = feature_tracefilt_trap_activate, }; +/* For ID_AA64MMFR1_EL1 */ +static struct feature_config_ctrl ftr_ctrl_lor = { + .ftr_reg = SYS_ID_AA64MMFR1_EL1, + .ftr_shift = ID_AA64MMFR1_LOR_SHIFT, + .ftr_min = 1, + .ftr_signed = FTR_UNSIGNED, + .trap_activate = feature_lor_trap_activate, +}; + #define __FTR_BITS(ftr_sign, ftr_type, bit_pos, safe) { \ .sign = ftr_sign, \ .type = ftr_type, \ @@ -1104,10 +1118,9 @@ static bool trap_loregion(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) { - u64 val = read_id_reg_with_encoding(vcpu, SYS_ID_AA64MMFR1_EL1); u32 sr = reg_to_encoding(r); - if (!(val & (0xfUL << ID_AA64MMFR1_LOR_SHIFT))) { + if (!vcpu_feature_is_available(vcpu, &ftr_ctrl_lor)) { kvm_inject_undefined(vcpu); return false; } @@ -4433,6 +4446,14 @@ static struct id_reg_desc id_aa64mmfr0_el1_desc = { }, }; +static struct id_reg_desc id_aa64mmfr1_el1_desc = { + .reg_desc = ID_SANITISED(ID_AA64MMFR1_EL1), + .trap_features = &(const struct feature_config_ctrl *[]) { + &ftr_ctrl_lor, + NULL, + }, +}; + static struct id_reg_desc id_aa64dfr0_el1_desc = { .reg_desc = ID_SANITISED(ID_AA64DFR0_EL1), /* @@ -4577,7 +4598,7 @@ static struct id_reg_desc *id_reg_desc_table[KVM_ARM_ID_REG_MAX_NUM] = { /* CRm=7 */ ID_DESC(ID_AA64MMFR0_EL1, &id_aa64mmfr0_el1_desc), - ID_DESC_DEFAULT(ID_AA64MMFR1_EL1), + ID_DESC(ID_AA64MMFR1_EL1, &id_aa64mmfr1_el1_desc), ID_DESC_DEFAULT(ID_AA64MMFR2_EL1), ID_DESC_UNALLOC(7, 3), ID_DESC_UNALLOC(7, 4),