From patchwork Fri Mar 11 04:47:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12777424 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 88726C433EF for ; Fri, 11 Mar 2022 04:54: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=8KTn/mSy1I2a/cWIP/oux5/k6ydxQIqTJtKpFstdpkA=; b=iFX+C94QVRT6IkBUVPuS2YAZ1N FOSeRcrv5Sgv4Bwh7QxocjZULaoAsXIL3AOtmIDdDz4bSm/mDAlPcYTty6aPK+g76tJiHDOLuaZdZ Jizy5Mb0kY9TYcHJbxUm6jway4OdUrvahPa00zm+spGtLPiZw3ofvQFcRkrkqmGIDRrXiD5q7dYvi w60t3ArfnJgafMmYEnSA18hiIEi5Fe0Iirorha5ruNeN2kzVBHO4L4GJLDsUVd4eADsYdt+dt5Rh0 rnlGFPVTj4nO/auZCXGHbM4kKkZSjCJtEqJTnv5vY3Q7PIrQVAc0zYLu/YcHRWsICQLpA5hIfSJYq wAR9NsGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSXGI-00F1Ms-4N; Fri, 11 Mar 2022 04:52:22 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSXCr-00EzgA-Fb for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 04:48:53 +0000 Received: by mail-pf1-x44a.google.com with SMTP id y27-20020aa7943b000000b004f6decccdb5so4550407pfo.1 for ; Thu, 10 Mar 2022 20:48:48 -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=uoX+Y+G6xoHPXp4kqnfSVmpfMNJMZgMHDhyE0auL83Q=; b=YNltLUs0JQ2gFkvqzjAXUoHgAi9ZfaLM/L+GHykWnnLtUkQPfLjXODJYzEL9TwOD6t KT525jlPQqr6DC8/EAKJleLT4RIABEucKJ5u44URo1HHUaVsuoJY+jybtXEexOHuofJ6 wCj0ICOlApK+2jJbRNw4N3p1WM8pFyr4Ubpf6Pt8qMqU0jlcXMYsJZjx35tteE0y5NUY qnS6lOa6QbzS4qN2M5utqKhbabagUFrSOdlffYrSdoPd8AZqgRpu5tPA0ERglZjeaJ5R 1E63LdOlRt9IhJ41HAwVfOJRFHL9oVsIcfQZg6j8+/BIPZmoEh1N4r0YC/zkS2bMai5t aVag== 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=uoX+Y+G6xoHPXp4kqnfSVmpfMNJMZgMHDhyE0auL83Q=; b=DR5yXjayr4PIdmq3LLwlqtEsGYzeSM+E2P1Cda1FFsK0QDW//RLsP41BiyPPl9TNUI tVAkLLPKIIOloDFHA6ea6AC5NSF/MFJifayyFT3IqPr8D2rbeQAY0U8YNGT5v3PHZKlk Hod10s1tUmUYgC4OlOg8jvlUa3Lk3vR0bQXKiEITpOVHHUL36g6vXoYUSJ/9R2y99LZH ErGDfHvV4m0ilBIijah5QCB+QEorfBe12x9BkXazRolHu3UcdFklunjjTkmI0k1sFfYw PNDobEIHLzUzh2R2FeHeyFG7cVvIwgSfPh5RsHZ8JqwXxyJZRqAzJpS8QlJ4WcWO3NZw i9pQ== X-Gm-Message-State: AOAM5313WZOuZOJ68B5meBzX84N3bcDI0UFBjBYKYsfMgD9fu2kwDyls d6PAPnEeyrTyI/I94qqS/TnifrLBoHM= X-Google-Smtp-Source: ABdhPJzlEs8FIbA8U2Dis881SY2f6s+kkp+46U11VGjc7k6FSU9t7G0DvVjrYGujHVyxJSa56LXMGJhejwU= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a05:6a00:1a47:b0:4e1:5bc7:840d with SMTP id h7-20020a056a001a4700b004e15bc7840dmr8455437pfv.10.1646974127983; Thu, 10 Mar 2022 20:48:47 -0800 (PST) Date: Thu, 10 Mar 2022 20:47:56 -0800 In-Reply-To: <20220311044811.1980336-1-reijiw@google.com> Message-Id: <20220311044811.1980336-11-reijiw@google.com> Mime-Version: 1.0 References: <20220311044811.1980336-1-reijiw@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v6 10/25] KVM: arm64: Make MVFR1_EL1 writable 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-20220310_204849_595626_BD6A1431 X-CRM114-Status: GOOD ( 16.59 ) 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 This patch adds id_reg_desc for MVFR1_EL1 to make it writable by userspace. There are only a few valid combinations of values that can be set for FPHP and SIMDHP fields according to Arm ARM. Return an error when userspace tries to set those fields to values that don't match any of the valid combinations. 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 46d95626f4d5..45d22b9e0d40 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -632,6 +632,36 @@ static int validate_id_dfr0_el1(struct kvm_vcpu *vcpu, return 0; } +static int validate_mvfr1_el1(struct kvm_vcpu *vcpu, + const struct id_reg_desc *id_reg, u64 val) +{ + unsigned int fphp, simdhp; + struct fphp_simdhp { + unsigned int fphp; + unsigned int simdhp; + }; + /* Permitted fphp/simdhp value combinations according to Arm ARM */ + struct fphp_simdhp valid_fphp_simdhp[3] = {{0, 0}, {2, 1}, {3, 2}}; + int i; + bool is_valid_fphp_simdhp = false; + + fphp = cpuid_feature_extract_unsigned_field(val, MVFR1_FPHP_SHIFT); + simdhp = cpuid_feature_extract_unsigned_field(val, MVFR1_SIMDHP_SHIFT); + + for (i = 0; i < ARRAY_SIZE(valid_fphp_simdhp); i++) { + if (valid_fphp_simdhp[i].fphp == fphp && + valid_fphp_simdhp[i].simdhp == simdhp) { + is_valid_fphp_simdhp = true; + break; + } + } + + if (!is_valid_fphp_simdhp) + return -EINVAL; + + return 0; +} + static void init_id_aa64pfr0_el1_desc(struct id_reg_desc *id_reg) { u64 limit = id_reg->vcpu_limit_val; @@ -3474,6 +3504,11 @@ static struct id_reg_desc id_dfr0_el1_desc = { .vcpu_mask = vcpu_mask_id_dfr0_el1, }; +static struct id_reg_desc mvfr1_el1_desc = { + .reg_desc = ID_SANITISED(MVFR1_EL1), + .validate = validate_mvfr1_el1, +}; + #define ID_DESC(id_reg_name, id_reg_desc) \ [IDREG_IDX(SYS_##id_reg_name)] = (id_reg_desc) @@ -3482,6 +3517,9 @@ static struct id_reg_desc *id_reg_desc_table[KVM_ARM_ID_REG_MAX_NUM] = { /* CRm=1 */ ID_DESC(ID_DFR0_EL1, &id_dfr0_el1_desc), + /* CRm=3 */ + ID_DESC(MVFR1_EL1, &mvfr1_el1_desc), + /* CRm=4 */ ID_DESC(ID_AA64PFR0_EL1, &id_aa64pfr0_el1_desc), ID_DESC(ID_AA64PFR1_EL1, &id_aa64pfr1_el1_desc),