From patchwork Mon Feb 14 06:57:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12745008 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 CF60BC433F5 for ; Mon, 14 Feb 2022 07:02:05 +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=lvoO8766rWm5F4bgkPhrJLdGEduU1EEnsxrTS8CeyBA=; b=pDv5Xqiqc5h6E2FuhwJKboaQxe PKOGVEuJ6ZNMnmlJZKjK5DbHy9A3YiuHclE7IlMPap8ORIP+Wbgf1oJ0Lqr6LYYoIW2b5EWPmSnf8 e5j5RTFxdZYfAZfJ7rSA0SgapbWhIeeLmH6gvmjGFcmcxd8f578k7Cyp+z9xdlY0R22EmATLncbZ0 EFmVOlY5ve5NkmUupyh5qk+/lfuUoaL3u+y0Ux5jv3q8ErDba8SoijQrRzRxxJ56rJsb0qoZYXylp lWFkFweW3JHG0UCg6T4w2NRrSUUVqagi63zI2vkeDdGe/a2WWegBS58mOllxYYd2tcetpW/tGGPo7 Mid08oOw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJVLT-00DWxb-5T; Mon, 14 Feb 2022 07:00:23 +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 1nJVKd-00DWX8-UM for linux-arm-kernel@lists.infradead.org; Mon, 14 Feb 2022 06:59:33 +0000 Received: by mail-pf1-x44a.google.com with SMTP id i16-20020aa78d90000000b004be3e88d746so11101946pfr.13 for ; Sun, 13 Feb 2022 22:59:30 -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=M/a/Vc/shmJJLkjZEVBmniQlBoL+OJyInbuc84cKOVo=; b=oHiVtTsoFuP7yxvyHQnSpouOUcn7G4EYC+Ud3GVI/+GZOlUg97m7sK+ac0e7acp21k br/kA9rY0/54R62sM2+J6XotY6GpkxYuJsq96VMGi2rokSONE9v65Nk0WLHRhgqQ+kkz j6XS69iblworG4svJ04iUpjYT8hYS4RSKesB+K2856MWjkpvigJyP0bOMW1mo2gcJBrl 5Qj4dZUhifjRold70IjyqXd944ao9fLKeVarR4PxB6/a47gB3xqndq4YcD3bYKqjmNBf ktzk+MGTgVt6OZbt1a0wY1KSoLsOl64r7hw+BPjxAIQ1OfkQjvNbPcsoT3XoxHuKUeDq 31Ag== 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=M/a/Vc/shmJJLkjZEVBmniQlBoL+OJyInbuc84cKOVo=; b=F7gq+UaIBYIpXCcZbkudoIv41ei+7gNXXPZV57JbPltT/7RuTSGXcnTM5JLZez6HZc KOyV5yx02XuV1dL57H+Y1cRq+avxlAUzs6cjkODzn5Xsg/lLiHFoIvaAnJG8iCqc/IDx d2zGIanbJmWa2Q5NNaSOX9+A+OJB9jJXk5qMcBng7lzE8h5KYzOl0ZU8NEePCnJGZIFi FVfNhHig1msjENRR5vgsjj9onAOij2xwoZgYcBqHwhsE0IItcqbDdPMhm+1FMzjIQJj9 7IIzBERzea/IyPC33E87iQfnyMUJE0FeDXhBOfof1jBV5OyFilu4vSgy0gfmh4ctHwLT 6qSA== X-Gm-Message-State: AOAM533RN3eIEQXjR2fBqjYHq55lCIdG+NGGB1fuxsZ44Tki2CcSA66z z4VNEWSHAfur6s9ZZngltuvlFD71BZE= X-Google-Smtp-Source: ABdhPJwsfhL7pM3Pz0k0600RZWcFVmJjjZYx2f1pfIZDVbRupYBHsW6Obk+gUclfejqilFnthPKptjfIvSo= 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:4c8e:: with SMTP id my14mr1640298pjb.0.1644821969667; Sun, 13 Feb 2022 22:59:29 -0800 (PST) Date: Sun, 13 Feb 2022 22:57:25 -0800 In-Reply-To: <20220214065746.1230608-1-reijiw@google.com> Message-Id: <20220214065746.1230608-7-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 06/27] KVM: arm64: Make ID_AA64ISAR0_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-20220213_225932_026421_84FA5D28 X-CRM114-Status: GOOD ( 12.70 ) 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_info for ID_AA64ISAR0_EL1 to make it writable by userspace. Updating sm3, sm4, sha1, sha2 and sha3 fields are allowed only if values of those fields follow Arm ARM. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/sys_regs.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index b41e9662736d..eb2ae03cbf54 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -387,6 +387,29 @@ static int validate_id_aa64pfr1_el1(struct kvm_vcpu *vcpu, return 0; } +static int validate_id_aa64isar0_el1(struct kvm_vcpu *vcpu, + const struct id_reg_info *id_reg, u64 val) +{ + unsigned int sm3, sm4, sha1, sha2, sha3; + + /* Run consistency checkings according to Arm ARM */ + sm3 = cpuid_feature_extract_unsigned_field(val, ID_AA64ISAR0_SM3_SHIFT); + sm4 = cpuid_feature_extract_unsigned_field(val, ID_AA64ISAR0_SM4_SHIFT); + if (sm3 != sm4) + return -EINVAL; + + sha1 = cpuid_feature_extract_unsigned_field(val, ID_AA64ISAR0_SHA1_SHIFT); + sha2 = cpuid_feature_extract_unsigned_field(val, ID_AA64ISAR0_SHA2_SHIFT); + if ((sha1 == 0) ^ (sha2 == 0)) + return -EINVAL; + + sha3 = cpuid_feature_extract_unsigned_field(val, ID_AA64ISAR0_SHA3_SHIFT); + if (((sha2 == 2) ^ (sha3 == 1)) || (!sha1 && sha3)) + return -EINVAL; + + return 0; +} + static void init_id_aa64pfr0_el1_info(struct id_reg_info *id_reg) { u64 limit = id_reg->vcpu_limit_val; @@ -454,6 +477,11 @@ static struct id_reg_info id_aa64pfr1_el1_info = { .vcpu_mask = vcpu_mask_id_aa64pfr1_el1, }; +static struct id_reg_info id_aa64isar0_el1_info = { + .sys_reg = SYS_ID_AA64ISAR0_EL1, + .validate = validate_id_aa64isar0_el1, +}; + /* * An ID register that needs special handling to control the value for the * guest must have its own id_reg_info in id_reg_info_table. @@ -465,6 +493,7 @@ static struct id_reg_info id_aa64pfr1_el1_info = { static struct id_reg_info *id_reg_info_table[KVM_ARM_ID_REG_MAX_NUM] = { [IDREG_IDX(SYS_ID_AA64PFR0_EL1)] = &id_aa64pfr0_el1_info, [IDREG_IDX(SYS_ID_AA64PFR1_EL1)] = &id_aa64pfr1_el1_info, + [IDREG_IDX(SYS_ID_AA64ISAR0_EL1)] = &id_aa64isar0_el1_info, }; static int validate_id_reg(struct kvm_vcpu *vcpu, u32 id, u64 val)