From patchwork Thu Jan 6 04:26:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12705084 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 A62A7C433F5 for ; Thu, 6 Jan 2022 04:31:21 +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=W896bOH5r0mGAc0PjsJymAIDviCGKLglbOrIRM+FEws=; b=RQQSM9IbzIWuXIj2XjTDa7NsAb v1oqjFh/pqZXVsw5Rg4BeQVmKGUbzk60m1k2dEhSOZT5UkY0xeq9e70yXrBkEpibEuJZN57NktJSm 9UDeczB67Q2hCTB4lgVNXjc1xD93alouul7Mw7poi2k8Ys3j9DHzvq5Mc9GJPswu+bTpqpLYg0Krz dPbBSolMq0PkVX3bYk4OqN/Mo4NRV2b9pJEfqoAC1XuW7MkWrg8R55vwyowEZ7T2rn2pSQI8G8ppg GF+KGG5098UtU6BOFxzGSfpG30Ak/lfVIIDvEznj4swukxLlUr6p4O0YTK5GZ1QRWyrBZuzwRqApN fG6zOM/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5KPS-00GSTU-4V; Thu, 06 Jan 2022 04:29:54 +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 1n5KOH-00GRpy-As for linux-arm-kernel@lists.infradead.org; Thu, 06 Jan 2022 04:28:42 +0000 Received: by mail-pj1-x104a.google.com with SMTP id h33-20020a17090a29a400b001b20b7d48dfso1043871pjd.0 for ; Wed, 05 Jan 2022 20:28: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=iggCERYPvKZzkmiH5L0dJnOh5/4oawtODr5G6JGC3EA=; b=mVLqwj6g6bvq57fUaSXBKokDOk+Vl5QV/c2R0889pzyzfCBoA/raBr27Y7kswkDDvt wCDfvRtxY/zyAeZZpDDG6FaHhPoAsHlTPkalAKLnRzJSHDPdJBhM+95Oc37OOpPNILcg XJQblN1T7v+0cS6yn+I85idg1qCUXVRBP/sKXhl0gKeZysvAhhVQqLZ/AA4DHQwrbePb s8vCdjD+phywxu/FGU3qwT6KZ4N/E7IAJW/Q9jWJr5q0fFXjEVz4nMKM/ULNrtzDFP59 Gs7JiJpDxpAcEoQqEGZBABmMH3cUOOzEu/PL9UWJC/RjpX69PO75BPiBBuXuTIbRRwRD DHKQ== 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=iggCERYPvKZzkmiH5L0dJnOh5/4oawtODr5G6JGC3EA=; b=gNVMXbGcoGsDITW0lWSgAPZuCRWuqpr9md2r1sJh5Va+03fPd+YEFHfxNZ3EQ9AEZ8 ZqdJcsXOO/om5SC/fosSyTHBH6KnY9/S+J9PksqdDs9uH1eFWA5AZ7h+7BqY17uFluXr YDQL1BdQ+QWP5U39aDb+1VQ/vUOiQQ/7QqjDgf7tANornwqecHQCRoTBHYevPLyBzAzR 5qJU0zxBJq0yB+Y9egyiHOYqFIISwti/0VA1a1Cc/OBxPe7GDUWey3NfEV+Z01rU/dDz 8AFgnHQnY5Np1zKPZoqJYodz+T9q9ereILNuv4GZfHcEgcaUJKp2n55nNkLLpn1/lPES vOdQ== X-Gm-Message-State: AOAM532aurrYcK7xVp60g/62K4SYTpAKsUcbbhhTIbszL9kqh3jAKD6o I2VCdU4yJ7fqXUl0/j96DqthFyhQTs0= X-Google-Smtp-Source: ABdhPJxDhvY2RCuxPGDkqE5OOdzgA9LIz2uvcajr4q2pHOtqqx/TF2sfgcMcvVhIt9btg/jJEMB+aQVz7pA= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:90a:2a4e:: with SMTP id d14mr528686pjg.0.1641443319139; Wed, 05 Jan 2022 20:28:39 -0800 (PST) Date: Wed, 5 Jan 2022 20:26:48 -0800 In-Reply-To: <20220106042708.2869332-1-reijiw@google.com> Message-Id: <20220106042708.2869332-7-reijiw@google.com> Mime-Version: 1.0 References: <20220106042708.2869332-1-reijiw@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [RFC PATCH v4 06/26] 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 , 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-20220105_202841_421517_9915778B X-CRM114-Status: GOOD ( 13.71 ) 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 ae9ca341a2e4..3f1313875be5 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -374,6 +374,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; @@ -441,6 +464,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. @@ -452,6 +480,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)