From patchwork Wed Jun 7 19:45:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13271195 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 10BEAC7EE23 for ; Wed, 7 Jun 2023 19:46:36 +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:Message-ID: References:Mime-Version: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=+eXAz7mLuUgjUjRqS1F3UfLDD02RSbAFp+yybVGz6T8=; b=SqPQ+7u/3/nxeEWCz5mBUI5/WT f3qmQ4eS0Ui6PsQOe1u2vYjGTLWto2dHOZ268xcHxXmed6t47OodTrCnDISip6+tlS+1zBpP+E1lO uWEJ72CJrWQUCEh9V+AaHN+AbV4db2ybkY+AWR1ufOZXdk+l00Ug/k/DNv9m72SS7RlVLyEmH1WxC 4Bp6/13rLHrq/Nhi16PzKqYfJcHVREfM/oFH3j2fLxBSnlhB3fiKL7/JnLZc8PAI7sVbD1kt3UJlm hSYHy82rUPO9xphmd9GREEBcMjs7QLRRpRQ9pF3ZF5q3uQRZqV9UYdw+/jvoabAQEtL534EMe10Rs 6fKO5zvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q6z6e-0070VY-0n; Wed, 07 Jun 2023 19:46:08 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q6z6b-0070Sq-0y for linux-arm-kernel@lists.infradead.org; Wed, 07 Jun 2023 19:46:06 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-568fa455b8fso116940657b3.3 for ; Wed, 07 Jun 2023 12:46:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686167160; x=1688759160; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hzxVwxnrNt+YQp7iV0J7o3+qKksOkJQBVAdrxipkKZg=; b=fMZYG2zR8/wyVaV7AOWU2176k/b30yDMKXHbC/LdYCNKxTdoLKCXlQ6JSsEJpKCovx u9u+W+rKoRyLy9Nud2MHk1nP4o/c3i4sFDaqNU5Tz18ncnoHJWBcV7YBp35rYblNSMrB Srt2tjPaFXVZin7mr/aGXsbIXt58qgfwgTEdJPUyg6mM2OwgX47KdIHSaIQqmi0eqIPL 5v2P2BX/GBKy3oqa1yCJwfGXELL6EMogyVQSIkmTzCQjg5UWFxSp21LfjJpQZem0aQR2 wMmq8AKiEtvscrwUGTY8A+yxh1qWK/2oPM6gQEZ/Tb/oHE/8BwS7FZkxI6PRefMOjJOI XiPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686167160; x=1688759160; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hzxVwxnrNt+YQp7iV0J7o3+qKksOkJQBVAdrxipkKZg=; b=Tp/W725vvmsjfEm1Ldf70zbMenFfERjcU87l0e1nRy4KwD8NhBMVjJwq853cMt0bfo QB1BL7GeyaGj6mrnDruVaUFhoN27O8ulUdIb9WUsi+x9bGVPIgClU4B+NFmw227egEzI Z27OsN3LTc88+pi9YYSS5aLiGu7YKatx8HU2QR+90A51O9K+fCufbt5qKmeqbzis2oD7 oYBMlEc/DNcrivJYEndE1A3mxMHbq15jyoAK/CKtJEfwNMYZaaC7w6rVuMHsWN4Tyh+x 5XOd+mAOxaDx7ClSO9Uo+eYPfOkwLUihOTXpNGq+g771r+NOX1/khwaMd1dhG0ndsJhH KlJA== X-Gm-Message-State: AC+VfDxvbqnwfeAmZ8H6yE/PDTNNhim6GK8IfhCFqvfBUbu44wOUcrZL hSSdowlEbIP+ICk4GnMQmdGiTkLotc7l/+aO0Q== X-Google-Smtp-Source: ACHHUZ6V41FX37D247KNGDPz31teBiVq6V+3LyWxqzaVMHNbR4cZ9zys4EkzeS1q16KMxoLnqrscogFEIf4yfE0S0w== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a81:ae17:0:b0:568:9bcc:5e16 with SMTP id m23-20020a81ae17000000b005689bcc5e16mr3400413ywh.2.1686167159720; Wed, 07 Jun 2023 12:45:59 -0700 (PDT) Date: Wed, 7 Jun 2023 19:45:51 +0000 In-Reply-To: <20230607194554.87359-1-jingzhangos@google.com> Mime-Version: 1.0 References: <20230607194554.87359-1-jingzhangos@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230607194554.87359-2-jingzhangos@google.com> Subject: [PATCH v4 1/4] KVM: arm64: Enable writable for ID_AA64DFR0_EL1 From: Jing Zhang To: KVM , KVMARM , ARMLinux , Marc Zyngier , Oliver Upton Cc: Will Deacon , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Fuad Tabba , Reiji Watanabe , Raghavendra Rao Ananta , Suraj Jitindar Singh , Jing Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230607_124605_340751_02D5F8AB X-CRM114-Status: GOOD ( 12.15 ) 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 Since number of context-aware breakpoints must be no more than number of supported breakpoints according to Arm ARM, return an error if userspace tries to set CTX_CMPS field to such value. Signed-off-by: Jing Zhang --- arch/arm64/kvm/sys_regs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 50d4e25f42d3..a6299c796d03 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1539,9 +1539,14 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, u64 val) { - u8 pmuver, host_pmuver; + u8 pmuver, host_pmuver, brps, ctx_cmps; bool valid_pmu; + brps = FIELD_GET(ID_AA64DFR0_EL1_BRPs_MASK, val); + ctx_cmps = FIELD_GET(ID_AA64DFR0_EL1_CTX_CMPs_MASK, val); + if (ctx_cmps > brps) + return -EINVAL; + host_pmuver = kvm_arm_pmu_get_pmuver_limit(); /* @@ -2061,7 +2066,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { .get_user = get_id_reg, .set_user = set_id_aa64dfr0_el1, .reset = read_sanitised_id_aa64dfr0_el1, - .val = ID_AA64DFR0_EL1_PMUVer_MASK, }, + .val = GENMASK(63, 0), }, ID_SANITISED(ID_AA64DFR1_EL1), ID_UNALLOCATED(5,2), ID_UNALLOCATED(5,3), From patchwork Wed Jun 7 19:45:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13271196 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 D9607C7EE2E for ; Wed, 7 Jun 2023 19:46:36 +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:Message-ID: References:Mime-Version: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=fcUwEZWP7c1qlNxFCP3ASC1kIrKMBqgAfYaGbrsrq7o=; b=vRArESQPR4Lba+saHwGggUe4jG j+DJKZCyO08FerticXvONuT/H+s/JqcU26LyX8WGARo0O0/uuno/icFPHJzuzjRaX1wKtbls0WDl9 Bo1WOYvUCn6qwhfU2OqKLHgXIS5G8CjdzhvTFKvMq7mqHEFXVdY+E7TFEXClCWhwBAacDrB8LFR1F zZegfgiCW6GRcxxggY2TDOZIaDPjG10p82KgizVAkyCvu9OZwDuWDCHT8P2dOIm+t7qEkVNJyf0lB xg8BGODC6QV7LwRJik4/s76rTz2uj70FDuXVxc7L/2n2rZ1nvIwbDwaklw7zrf3aHR4tc0q0AQesv Wg8Muzug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q6z6h-0070WY-2q; Wed, 07 Jun 2023 19:46:11 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q6z6c-0070Th-1r for linux-arm-kernel@lists.infradead.org; Wed, 07 Jun 2023 19:46:07 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5695f6ebd85so94892227b3.3 for ; Wed, 07 Jun 2023 12:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686167162; x=1688759162; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GMvXXWaPKrwI8ANUMqyoY6XpdWuvZ2GGO8wtmAqxRv8=; b=44H05++tu/UWuqm3JuxpRf6vMLsECzczci0UyIUM3OThFWRiahAt92FfhRZhSbBwli 8/1qfxGZ/VTr91tecb7st2f1w7Mt72fLDC0mU1zCkJiAIN7Mw7S6hlj8V2HdVsEihDHA PeILBnvUmqvJ0x1+JXeJCdoAS9EAyiy4jPlmRyYm6dBlIsDjr/9Xbu4BCkGDqs2l1fAY 4wVh3IropgCq0jmNSAvgDdMkA6uKJ/X7wqGEoBknvm2MDi9mY5pYcLlv94VLhn6OjOOc ucZmGH8BIvzeugQBdnkUorBxJjwXODIhc/tDcFubiJ/6d25Kctx8gI/Xns5hEqSi7CLO RadQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686167162; x=1688759162; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GMvXXWaPKrwI8ANUMqyoY6XpdWuvZ2GGO8wtmAqxRv8=; b=h4xSy1/dZyRAAlP1RNfZjnxcNOS2hwRpyiZ2QsDkkDVcFMmhXCwU0AUbXiJOFkBWH0 XDT7PiuAPmv33ob50R/p44RRIwNk3gK11K2gY10DUZIaHs7MW5G6TCUu9nsZJHBAB8QL WZneXPZhHoOTC/hYeCVCm9fB0KSmKOEaC1uPxlnHfv5n1WEPD/p0SLLhWBQPsG4Ea0je +NwiJAU+rvRWDyq4QPOR7uwkL0MDj0CrIcJATwvr15ANNx/IgbkGSOSnZB0d0JNpfKRb u4mirfv5v5QSgOM7i1A8mi1zuUncW8OI14PGAEyZuPOWDAv48S27gPwT2JtwvpOPsfMh +cFg== X-Gm-Message-State: AC+VfDyvHW/T9vS9TPZRsqgYLF7oPPKcH6339bVHIiQhH+iycWT6nmvF RNJoO6V+RHMk4IE+8lavgNVN1byJ/iPVHfPR+A== X-Google-Smtp-Source: ACHHUZ4KSb7sB8/bYxjIdGGm9lhaO9umaUIt7cTmZ1//R+CmbCUOZ0UJCj1y/ESSBxrH8CNkeqmF30Cs6PkVID1Mpw== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a05:6902:100c:b0:ba8:4ff5:3217 with SMTP id w12-20020a056902100c00b00ba84ff53217mr2467566ybt.3.1686167162151; Wed, 07 Jun 2023 12:46:02 -0700 (PDT) Date: Wed, 7 Jun 2023 19:45:52 +0000 In-Reply-To: <20230607194554.87359-1-jingzhangos@google.com> Mime-Version: 1.0 References: <20230607194554.87359-1-jingzhangos@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230607194554.87359-3-jingzhangos@google.com> Subject: [PATCH v4 2/4] KVM: arm64: Enable writable for ID_DFR0_EL1 From: Jing Zhang To: KVM , KVMARM , ARMLinux , Marc Zyngier , Oliver Upton Cc: Will Deacon , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Fuad Tabba , Reiji Watanabe , Raghavendra Rao Ananta , Suraj Jitindar Singh , Jing Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230607_124606_614834_9B59F412 X-CRM114-Status: GOOD ( 11.73 ) 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 All valid fields in ID_DFR0_EL1 are writable from usrespace with this change. Signed-off-by: Jing Zhang --- arch/arm64/kvm/sys_regs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index a6299c796d03..3964a85a89fe 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -2017,7 +2017,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { .set_user = set_id_dfr0_el1, .visibility = aa32_id_visibility, .reset = read_sanitised_id_dfr0_el1, - .val = ID_DFR0_EL1_PerfMon_MASK, }, + .val = GENMASK(63, 0), }, ID_HIDDEN(ID_AFR0_EL1), AA32_ID_SANITISED(ID_MMFR0_EL1), AA32_ID_SANITISED(ID_MMFR1_EL1), From patchwork Wed Jun 7 19:45:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13271194 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 864A7C77B7A for ; Wed, 7 Jun 2023 19:46:35 +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:Message-ID: References:Mime-Version: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=JjS4oqFF07LzrNdIJH3iRdV8OomkHfjtZPkpXbgsnr4=; b=gWmumZS5wiJF0XeALFDyLqQYvE zqyp048gKmOR1zF66Z/YCIyhqaufLvj11asK3PLh0d5SbRJ53McZ6SspD2iXBeO2FLYWCzsKvcsen eBVoQxxJwx/By6EXeTCro9invtBxEoUqEziZgtn2yY6eDCOZzQNkRIWh5LnDRhv2tpQCDA4uz7JwI uAZ1G0GxKB4bLRZd/nGy8tvhahd8oQNAOqoZtJuOdSCGJ6O9Iljzj88rXLU82zqn1gE9bMevQ0ne4 v+tI3rihSOqblUs8W+ReILySu5LVTp/K/oYPOi79DBWZ+YE3xvwvfbN4s3V5r2EIgc06IYRT5GeAx Bm/rykEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q6z6i-0070Wp-1R; Wed, 07 Jun 2023 19:46:12 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q6z6c-0070Tu-1t for linux-arm-kernel@lists.infradead.org; Wed, 07 Jun 2023 19:46:07 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1b04c328aa1so30851335ad.2 for ; Wed, 07 Jun 2023 12:46:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686167164; x=1688759164; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=huLg6ss0tcmHNDWws/J4wYZLAswrAiv7bwqrVCr+Www=; b=rvQpvgjutLDBUFD6re8s66cYIwgJnhk30RuWpsooLwa0/DnV1KMpLh1QKXz+AU3+EJ toULyYGPVwLcH+MSf1zAwjIgC+QmNBB84JuvtVGLm32grPQNsyGJC3yXIN+pXqUx0vmf kYkm0cPqzfksnRtP/WQ3XaIV5kyL5FExnTnvHnNEHk9QkXCUYZPtMjAyqZOwoW4K0Hq1 y35uWuI4QoY/hqnEX3uFzWlae+hnEGx6aU+9CDnIEosOHdw7Xdp/4v0Mg9VKQ9GeT0yk 980+Iqqj10VIbOSXVkqMt9C0azx+wOnrkAIodnSMgi7gX9SdshzFmuUiEcp8K2mTBDU0 eicg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686167164; x=1688759164; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=huLg6ss0tcmHNDWws/J4wYZLAswrAiv7bwqrVCr+Www=; b=KqztD4dUosjVbwuicOkWeapHoQC3yRwOU3ax61D3y7/vB2BCMSrb78+VBTnBQFN+YE lkxrKzo310772y5HqGx7NL8u8fUjSvcuUJyCj2EJUa2d5gXiYydKhE65mwl3kAnz9gsc LI1Yjg+99cPNJdRUx6VtK3yXXZKh3TLokyIYuB9hZgDJXEWgpOnQJXuGj7aZJheFEH5/ 6RuK7AkCuhRPUiMBhyy/tIrYH3XKz9onTkKGs9ltC3aQ9ErlYcj5JjFIgir2d4Rs/gEH tcitCPU8Vz5UmlpyRS55VmRGwlN4Z7d0fTpgkxDj+IzchnX6F/5BnkxT6lk0e5BUVr8r lHIA== X-Gm-Message-State: AC+VfDzUnArzCYiohvh0XSvH79uold8o/gKg015r/1JsX8AJpUUd1pkB LpEelQ+2bsMqIi0pkSq6YfoCRPQQmp91n4LFXg== X-Google-Smtp-Source: ACHHUZ4hJXt9tbUdkBWtP+0/4Tl+ZJnlb3E1BRZjLecrD3nbq3Co9zEpbNCwpWdnYYtl6Y/VvwJ4Y5DV8ySaS3odNA== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a17:903:453:b0:1ae:549f:af6e with SMTP id iw19-20020a170903045300b001ae549faf6emr1907179plb.7.1686167163943; Wed, 07 Jun 2023 12:46:03 -0700 (PDT) Date: Wed, 7 Jun 2023 19:45:53 +0000 In-Reply-To: <20230607194554.87359-1-jingzhangos@google.com> Mime-Version: 1.0 References: <20230607194554.87359-1-jingzhangos@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230607194554.87359-4-jingzhangos@google.com> Subject: [PATCH v4 3/4] KVM: arm64: Enable writable for ID_AA64PFR0_EL1 From: Jing Zhang To: KVM , KVMARM , ARMLinux , Marc Zyngier , Oliver Upton Cc: Will Deacon , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Fuad Tabba , Reiji Watanabe , Raghavendra Rao Ananta , Suraj Jitindar Singh , Jing Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230607_124606_622942_A1CFA2FE X-CRM114-Status: GOOD ( 14.50 ) 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 Return an error if userspace tries to set SVE field of the register to a value that conflicts with SVE configuration for the guest. SIMD/FP/SVE fields of the requested value are validated according to Arm ARM. Signed-off-by: Jing Zhang --- arch/arm64/kvm/sys_regs.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 3964a85a89fe..8f3ad9c12b27 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1509,9 +1509,36 @@ static u64 read_sanitised_id_aa64pfr0_el1(struct kvm_vcpu *vcpu, val &= ~ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_AMU); + if (!system_supports_sve()) + val &= ~ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_SVE); + return val; } +static int set_id_aa64pfr0_el1(struct kvm_vcpu *vcpu, + const struct sys_reg_desc *rd, + u64 val) +{ + int fp, simd; + bool has_sve = id_aa64pfr0_sve(val); + + simd = cpuid_feature_extract_signed_field(val, ID_AA64PFR0_EL1_AdvSIMD_SHIFT); + fp = cpuid_feature_extract_signed_field(val, ID_AA64PFR0_EL1_FP_SHIFT); + /* AdvSIMD field must have the same value as FP field */ + if (simd != fp) + return -EINVAL; + + /* fp must be supported when sve is supported */ + if (has_sve && (fp < 0)) + return -EINVAL; + + /* Check if there is a conflict with a request via KVM_ARM_VCPU_INIT */ + if (vcpu_has_sve(vcpu) ^ has_sve) + return -EPERM; + + return set_id_reg(vcpu, rd, val); +} + static u64 read_sanitised_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd) { @@ -2049,9 +2076,9 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_ID_AA64PFR0_EL1), .access = access_id_reg, .get_user = get_id_reg, - .set_user = set_id_reg, + .set_user = set_id_aa64pfr0_el1, .reset = read_sanitised_id_aa64pfr0_el1, - .val = ID_AA64PFR0_EL1_CSV2_MASK | ID_AA64PFR0_EL1_CSV3_MASK, }, + .val = GENMASK(63, 0), }, ID_SANITISED(ID_AA64PFR1_EL1), ID_UNALLOCATED(4,2), ID_UNALLOCATED(4,3), From patchwork Wed Jun 7 19:45:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13271197 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 EDB8AC77B7A for ; Wed, 7 Jun 2023 19:46:43 +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:Message-ID: References:Mime-Version: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=ArzdjUQv70laY/JbryR9wrABaJIt71WBtdlDoUHAjdY=; b=t5NF8K/0fNq4AQGaFb3Kxop2yk cSPKVSl3TbXjmSR9PnR+CoLINTvDD5jU/7RPBORcq3NCFiFFXVLOGd60ap2nvaNWiSFFGNe96SK0n D03QEbxNh8DsCZonZ7KNhpJePgeraQsvTzkFtNjrMA3+FW4106T+Kpfp5rvmwGocJm4I4VhzmJMxO YK6lN36n6xbQ9DvhQvmM4/u/hQV9rVGVtYP9kzpRugiASoTpAO4H+3FoLMzA4IdWLxJdsfjq21oOn u9EDNItfC1aQf6Dvv5LhwkBfoUfBVQmlCtIxOuc0r0vmtAf3rAxLW1OQCcs7O//4T/FuQ1Zn07zWn ioKP1dIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q6z6o-0070Yl-0c; Wed, 07 Jun 2023 19:46:18 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q6z6f-0070US-1i for linux-arm-kernel@lists.infradead.org; Wed, 07 Jun 2023 19:46:10 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-53f84f75bf4so2618815a12.3 for ; Wed, 07 Jun 2023 12:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686167166; x=1688759166; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Kt9Re8VhD2+c+e08bfchTfKK01Rj2MUePQIf0sCv4Xg=; b=qnLVcf4LBOV1GocAfKmE7OOXWzG9JXsx+o5fD5NyUihLa4ZmEEtGXBCpzgiwnDFzpW 3i9IE5h6ihvg8wwHtLHRzRrmvSiqyq53LJ5VdfHiV/e3LDQnWSjiBl2omUAEyOSXHCvb CHDx0jkRuYbIVXezwbq9YBlEropjp33Q5X5v8O3ixEuMOEQeQ8f1dVDxgyOFKJPD+e8v 8eqaxzIAlQKYECNoDAZ2EDzO7PmAJgcbwIXx6TA6P1gNq8IfNTK8hknyk2zzl5/syfVP N64VmdmpBXc9YSc4MaxWzquMO6VleuSWpfh2cPXzcRKY2zF8umgZx0vTVuieF++qHdj4 q5Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686167166; x=1688759166; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Kt9Re8VhD2+c+e08bfchTfKK01Rj2MUePQIf0sCv4Xg=; b=G7ixnExZp/mlo0nKVZbmza+fog+68SKWQZ4W47QAjEKM99hwp+zhNF7jH8yM302fad dpGk0QFzSEASWhpc9aytoax/8DMNFYcIgfV7+IYoYG/Xs1xLOEmcnoj375qyIAnti1j1 dMLFbPfWva35xjtDunEuOsEqxMPH3Co0JIw/HoDoukTaOy6gO8oM/hAKvTkFp5BIz7zJ TYjb8UBX8JiPxI80eb1pQkmoSOhDazESbXiupfBxerLTxUo+fM6NuIk+UMHgU/53K7vY 8OdwJCR+UbKldWih3dT25NX8NPRBP5CthjrFUeczWAU0vTah/MkMSdI4K2ysitNHb1XV zHkA== X-Gm-Message-State: AC+VfDymC7AqdbS3SvWT+ttXPHa/9Nez3qzzavdNbgJEyrTMr0BirrOm qKbQRvsLkIPxFVOWj4HAcOew7JDQJc9GLvf8MA== X-Google-Smtp-Source: ACHHUZ6AdZhHVsK3gBqZ29mngq3wYJzUe8nyFBCy0MXmvWuiKLwI//W+KPq7fWqN45t7RWSqbJlvv7QNt3JQHgOuqw== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a17:902:db02:b0:1b0:4af9:9032 with SMTP id m2-20020a170902db0200b001b04af99032mr2121642plx.0.1686167165934; Wed, 07 Jun 2023 12:46:05 -0700 (PDT) Date: Wed, 7 Jun 2023 19:45:54 +0000 In-Reply-To: <20230607194554.87359-1-jingzhangos@google.com> Mime-Version: 1.0 References: <20230607194554.87359-1-jingzhangos@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230607194554.87359-5-jingzhangos@google.com> Subject: [PATCH v4 4/4] KVM: arm64: Enable writable for ID_AA64MMFR{0, 1, 2}_EL1 From: Jing Zhang To: KVM , KVMARM , ARMLinux , Marc Zyngier , Oliver Upton Cc: Will Deacon , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Fuad Tabba , Reiji Watanabe , Raghavendra Rao Ananta , Suraj Jitindar Singh , Jing Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230607_124609_570686_35FCC04F X-CRM114-Status: GOOD ( 13.11 ) 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 Enable writable from userspace for ID_AA64MMFR{0, 1, 2}_EL1. Added a macro for defining general writable idregs. Signed-off-by: Jing Zhang --- arch/arm64/kvm/sys_regs.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 8f3ad9c12b27..54c762c95983 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1391,9 +1391,6 @@ static u64 kvm_arm_read_id_reg(const struct kvm_vcpu *vcpu, u32 encoding) val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_DFR0_EL1_PerfMon), pmuver_to_perfmon(vcpu_pmuver(vcpu))); break; - case SYS_ID_AA64MMFR2_EL1: - val &= ~ID_AA64MMFR2_EL1_CCIDX_MASK; - break; case SYS_ID_MMFR4_EL1: val &= ~ARM64_FEATURE_MASK(ID_MMFR4_EL1_CCIDX); break; @@ -1663,6 +1660,18 @@ static int set_id_dfr0_el1(struct kvm_vcpu *vcpu, return pmuver_update(vcpu, rd, val, perfmon_to_pmuver(perfmon), valid_pmu); } +static u64 read_sanitised_id_aa64mmfr2_el1(struct kvm_vcpu *vcpu, + const struct sys_reg_desc *rd) +{ + u64 val; + u32 id = reg_to_encoding(rd); + + val = read_sanitised_ftr_reg(id); + val &= ~ID_AA64MMFR2_EL1_CCIDX_MASK; + + return val; +} + /* * cpufeature ID register user accessors * @@ -1898,6 +1907,16 @@ static unsigned int elx2_visibility(const struct kvm_vcpu *vcpu, .val = 0, \ } +#define ID_SANITISED_WRITABLE(name) { \ + SYS_DESC(SYS_##name), \ + .access = access_id_reg, \ + .get_user = get_id_reg, \ + .set_user = set_id_reg, \ + .visibility = id_visibility, \ + .reset = general_read_kvm_sanitised_reg,\ + .val = GENMASK(63, 0), \ +} + /* sys_reg_desc initialiser for known cpufeature ID registers */ #define AA32_ID_SANITISED(name) { \ SYS_DESC(SYS_##name), \ @@ -2113,9 +2132,14 @@ static const struct sys_reg_desc sys_reg_descs[] = { ID_UNALLOCATED(6,7), /* CRm=7 */ - ID_SANITISED(ID_AA64MMFR0_EL1), - ID_SANITISED(ID_AA64MMFR1_EL1), - ID_SANITISED(ID_AA64MMFR2_EL1), + ID_SANITISED_WRITABLE(ID_AA64MMFR0_EL1), + ID_SANITISED_WRITABLE(ID_AA64MMFR1_EL1), + { SYS_DESC(SYS_ID_AA64MMFR2_EL1), + .access = access_id_reg, + .get_user = get_id_reg, + .set_user = set_id_reg, + .reset = read_sanitised_id_aa64mmfr2_el1, + .val = GENMASK(63, 0), }, ID_UNALLOCATED(7,3), ID_UNALLOCATED(7,4), ID_UNALLOCATED(7,5),