From patchwork Mon Jul 10 19:24:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13307536 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 8432DC0015E for ; Mon, 10 Jul 2023 19:25:22 +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=0h2GjHkV4C2uNEcoGmKqLe0lwFfv9ZLf0BNDcYFsjKU=; b=RkxfsJvX+FNCEU5xOGZyXfGldI Dy0vC3UDQDucV4szEQazccc6s6c2q8AONaowCjtChpsB8WZNNBOeiD754mZsBJdFq/OqZAZ8LXvIx oB6DEpZf9Wnd0veXJdw9tqYyUQpxOUVfdpxqaud0k2fASb29frCzPMHkK92CewRfWI8IxO7c0a7xT lUASwlZivYNHQPbzifyPM1VpBpvuOgJzM0egjB9kyH5I5aKvky4EjaDTupeOmoQv+yfiFs1jwcnMN OaAPrA/TExZCISOnUcvOTpyIi0d/fqnQHSWsVp5oGwwTTb2gfBqNU9MEwf3WLEaZtlOybo0QgObRu hMr7t9GQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qIwV5-00CYMl-18; Mon, 10 Jul 2023 19:24:47 +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 1qIwUz-00CYIR-2E for linux-arm-kernel@lists.infradead.org; Mon, 10 Jul 2023 19:24:42 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-573d70da2dcso56536547b3.1 for ; Mon, 10 Jul 2023 12:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689017079; x=1691609079; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RJ6ya0NEnIa5aVQX1AiBY2Ns/ppVJUg4kBKaquDN4C0=; b=OdWaI8UetC5xlsDbivt/wI1RqtD2Ol3BBLHnxQ9/Cf9Go9SKNCN7pvoug5MOr8pFRE Jr0HJYE6+lJIFXqJiZFwE62NlyzEhmli/QtYehhll8htzke3R17cDFmL4EWRtVDdtxpj v/3b49yRvxDs3842p5I92zZ1Nxbg+u3MD2SrWdYVKspzUMp2ZxinKiQymdYZdCuRoei2 Fav1CzDCizrzfvxke6uiRWaXz9+d3t/p+qH5BHFH/8Hkr4CYv5kH/Gm2210yjr/D/U2A OJ34jvPSX4bqdF8X1d/o/dTD9bTQ9+/d/P8r54rZ+w2wkDB97xWCkJgaW1vJvrm1zxUo Dz9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689017079; x=1691609079; 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=RJ6ya0NEnIa5aVQX1AiBY2Ns/ppVJUg4kBKaquDN4C0=; b=PWzvVrMhAfdIOaHxiCkK9RBwx6wrJGlUyccIqL5zftHXXjgWwf93ET2Za+Jwv4iosl jNaPhqLQ1VSurSsc+OPqgvC/2tWydIp//PD92c4+mIL16CfCF6meKhzfy8RQCNTJrG7N olXXImuOi6+ZQd81wN6DpEyVCHypjgsTspDvhjfxz5yw9f9OgwIr+FA08vHp9iH8QevZ Wl17J29FaZUbLVt/1uL4PpnSvGX4hVXkU1Fnch4WIY9UWIUDnxuA1lwi8p5RQRYD64rv fiw54JP1kykr7PI0J+eihdH4ntoFvZHogZAPaVSIMkJiwDkK9HOG4V/HeyvC34RELDDP tbsQ== X-Gm-Message-State: ABy/qLZjmI/hr7FryR7UtOoIkUgJwv52sp030qyHPxmERK38spoHVD4n 6vpQc2npb4l6E6w3PIvYk6w9W2zefyGJuR2EYA== X-Google-Smtp-Source: APBJJlGrizomlrXrfIIBON5g1LdEHWOUxmR3lblulK7dG7BSaVkBpJJIgLVla3mrwr0NssOyEnvwpwXcUtXHepnUaA== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a25:508:0:b0:c66:b847:544d with SMTP id 8-20020a250508000000b00c66b847544dmr113736ybf.1.1689017079311; Mon, 10 Jul 2023 12:24:39 -0700 (PDT) Date: Mon, 10 Jul 2023 19:24:26 +0000 In-Reply-To: <20230710192430.1992246-1-jingzhangos@google.com> Mime-Version: 1.0 References: <20230710192430.1992246-1-jingzhangos@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230710192430.1992246-4-jingzhangos@google.com> Subject: [PATCH v5 3/6] KVM: arm64: Reject attempts to set invalid debug arch version 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 , Cornelia Huck , Jing Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230710_122441_753223_D41D2279 X-CRM114-Status: GOOD ( 12.78 ) 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 From: Oliver Upton The debug architecture is mandatory in ARMv8, so KVM should not allow userspace to configure a vCPU with less than that. Of course, this isn't handled elegantly by the generic ID register plumbing, as the respective ID register fields have a nonzero starting value. Add an explicit check for debug versions less than v8 of the architecture. Signed-off-by: Oliver Upton Signed-off-by: Jing Zhang --- arch/arm64/kvm/sys_regs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 0160ef9cfe18..c44504038ae9 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1496,6 +1496,7 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, u64 val) { + u8 debugver = SYS_FIELD_GET(ID_AA64DFR0_EL1, DebugVer, val); u8 pmuver = SYS_FIELD_GET(ID_AA64DFR0_EL1, PMUVer, val); /* @@ -1515,6 +1516,13 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, if (pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF) val &= ~ID_AA64DFR0_EL1_PMUVer_MASK; + /* + * ID_AA64DFR0_EL1.DebugVer is one of those awkward fields with a + * nonzero minimum safe value. + */ + if (debugver < ID_AA64DFR0_EL1_DebugVer_IMP) + return -EINVAL; + return set_id_reg(vcpu, rd, val); } @@ -1536,6 +1544,7 @@ static int set_id_dfr0_el1(struct kvm_vcpu *vcpu, u64 val) { u8 perfmon = SYS_FIELD_GET(ID_DFR0_EL1, PerfMon, val); + u8 copdbg = SYS_FIELD_GET(ID_DFR0_EL1, CopDbg, val); if (perfmon == ID_DFR0_EL1_PerfMon_IMPDEF) { val &= ~ID_DFR0_EL1_PerfMon_MASK; @@ -1551,6 +1560,9 @@ static int set_id_dfr0_el1(struct kvm_vcpu *vcpu, if (perfmon != 0 && perfmon < ID_DFR0_EL1_PerfMon_PMUv3) return -EINVAL; + if (copdbg < ID_DFR0_EL1_CopDbg_Armv8) + return -EINVAL; + return set_id_reg(vcpu, rd, val); }