From patchwork Mon Feb 14 06:57:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12745068 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 06B3FC433F5 for ; Mon, 14 Feb 2022 07:20:25 +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=cBqvU6bDknSTeRO7Tazk0zmRPxaYJy29Alvz78dyL4A=; b=1gRliuPnia5x5WSShBR2uTLCcN B665NHXJ5WkegFoRqhtBWZ1sTf/AkJCx0tHNSyYP2zZb7wZ6hPIYgoJ2Y8DQwV6F7RyW88aNcCmYn whwb2TNF6MH65tU00qvsUwSHv3iaBbRZfgN6N1asDPVOhpfiDlfGboFV+C+3g//Q9UElz40F7YI3K o4+hF7zOcThMXYSCulaoKOXMz6d3GG8L48F2tB/+eA2bc+SR1P8gipAUUcvgCjcg3qud5QV82Jndg Tm60IkDOHWjKDcDTvVuL6A3OWYtLSE5pPzBU98nHdNk0gUHP087iF8QAe38ooYymbJLYbEWM/EBVK qRLizNhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJVdQ-00DeXa-Qk; Mon, 14 Feb 2022 07:18:58 +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 1nJVMj-00DXeP-T1 for linux-arm-kernel@lists.infradead.org; Mon, 14 Feb 2022 07:01:43 +0000 Received: by mail-pj1-x1049.google.com with SMTP id a15-20020a17090ad80f00b001b8a1e1da50so11515534pjv.6 for ; Sun, 13 Feb 2022 23:01:40 -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=ju7y0INwCkVlTLrGGMqN8WpA4pAC77LT4GJuAIzw0k4=; b=dW97xLS3Zq7BUp9OFgrYXx9OPZjlDniVb0QY3oGt2NWSrc9zm8dQdio2ZyVuL11KfO bGbdHEjXjbOQMA0MrV222jVAlYgL5ubTMCDAG0JdwDvryI4nu/xDi3CWKDX3tt4SQGnF XmQJtHEpXONICXTk3SQTNp8U4j+5LYhIEF4FnKvgzDTFpxhBfznHpdtoqfCpIIAGY9MS t8gjBeJiNsXwFR/MvrHpS+tZYzu5h+v6rPDGCfaLPpTv9PzzdVe5U0+/Jf8HltyKX3qB 4oasagz52cbDQ9j9OgN4wRDWy3hvXkO/EXEzCPiy2RlF13N/gvr4te2XnQ765XXfteXV 6waw== 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=ju7y0INwCkVlTLrGGMqN8WpA4pAC77LT4GJuAIzw0k4=; b=0ulNBRbsJaCGXbnNYJ38Wb6/NcEeQL2zf88vF093QdHpsXBkuPG1QxIDvxSPLyJCKB SS0p56S2l+nAOyHYx7BH6F+AxVKmujRpxVsKXB86v+65dG3b57v8yGp7BBRsRgv+sfNz CLQZMzrhyh2v758J/z2xcJYCv5agIi71O8fjR035pO25gGz9K4vN1QvW6RJJnwkh+hOj QAcqHwFtrf5MjP0HH6jJWgTgdgs/nXVIiAEHNPs12o3a32Ae0AAjNpRnl9SRUA8O4fAC qnqG/6PkLZSILkZx7b4AKh861OF2wSZt/0B0BJ2A/i4FefuOHatkG5BBG57ZSsFrwP5C NJaA== X-Gm-Message-State: AOAM533OT1LM0YWmhUDD+w+zbt05NRirTWzwsZRih8mil07oq2MXoIjT eKQqILON6s8wNgfLQSij4Kz6p9AV0iU= X-Google-Smtp-Source: ABdhPJw38wrkf0DY+q9xEUe+4IZIcMsK0dHMLQQ5rU+27P+/eKD5VvrZIoA2rsFN/Y4lan8hmVuWz0OYkuM= 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:dcca:: with SMTP id t10mr12648551pll.133.1644822100107; Sun, 13 Feb 2022 23:01:40 -0800 (PST) Date: Sun, 13 Feb 2022 22:57:43 -0800 In-Reply-To: <20220214065746.1230608-1-reijiw@google.com> Message-Id: <20220214065746.1230608-25-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 24/27] 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-20220213_230141_992500_57A49C61 X-CRM114-Status: GOOD ( 14.45 ) 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 | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index d91be297559d..205670a7d7c5 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -373,6 +373,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, @@ -432,6 +437,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, +}; + struct id_reg_info { /* Register ID */ u32 sys_reg; @@ -991,6 +1005,10 @@ static struct id_reg_info id_aa64mmfr0_el1_info = { static struct id_reg_info id_aa64mmfr1_el1_info = { .sys_reg = SYS_ID_AA64MMFR1_EL1, .validate = validate_id_aa64mmfr1_el1, + .trap_features = &(const struct feature_config_ctrl *[]) { + &ftr_ctrl_lor, + NULL, + }, }; static struct id_reg_info id_aa64dfr0_el1_info = { @@ -1111,10 +1129,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(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; }