From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C7A7C433F5 for ; Tue, 12 Oct 2021 04:38:57 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D8EA060EE5 for ; Tue, 12 Oct 2021 04:38:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D8EA060EE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=RBVB2dkoE521YbQIK4WQ/XDet7PIGLtD6Q5ejbi0VXQ=; b=aS4Df8FfZXprrbXdayZPKN2mwq 2tX0qdnGyknYbEeio+2dbabteCOxNyB3DuYZ3wj7abl9HI+wPMwJcGyylhB532eO5AFft69SrZykM Lwn/XCJPdrTr6dyRygCMUWaQUwfCwcE0QYzGR7Tz0Wx1v/kD/yU+gr4CzYO9prBdfEawi49Y3U4nb RARgbVF12PPJ171ah9aZ96S8nv/GBHU6C09UfIrmt8xwRZAXYLwBJ++d406BkCiTsi6BBAmGSI8zS YCw+Rd5hdnb3wXWVvnmPadc8Vu0IQN6Kr73DHJD5Tt/9zq0VdjaS/hZX7HbgMUWnX4Oop2ePbj19+ YyckAFgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ma9XY-00BQkc-1d; Tue, 12 Oct 2021 04:37:24 +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 1ma9We-00BQNR-13 for linux-arm-kernel@lists.infradead.org; Tue, 12 Oct 2021 04:36:29 +0000 Received: by mail-pf1-x44a.google.com with SMTP id c123-20020a621c81000000b004446be17615so5705797pfc.7 for ; Mon, 11 Oct 2021 21:36:26 -0700 (PDT) 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=N5SZSA+fUqRTbjo35OUmhwDTNPioIOsC+zg6mLlAOeI=; b=Frtj842iBGMNrPh6OG3pi0Ms5HCdrLoaoymnVC+SUwO8+nKGBSOJVdpZwwm/QTQbF8 OTYgVScpMIOT0ud7g2c8hytKJ2CjSjDz8M4XdeW7TJqSm2DEPdgyODcnwhB2ODPv6mBy aCnGplUEJ7fzS1cDJvyDiowSxXzf1dgt50MFJ/Uk5H21JMyKTRiuLsErBtQwO2+JItNz iBxKlc8wMy4/NwvNuNqhflcxOhfd2YbyIgr5mN/ngArSdHJllHqhq/3p1yIaKfs1EZGh Cvc+6I1dKsoE3RBupUrn125tyGYruhnhJUP/+o/18uTjunuMSuy2ARiKdbaEzViiwxtU j8Tw== 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=N5SZSA+fUqRTbjo35OUmhwDTNPioIOsC+zg6mLlAOeI=; b=aX7NYXcSgNV+e1uO7y1yJsroXx49aXC7ksDQHCFMn2y40WZHny66nYmuahy1VEVdXX +SCI9f7uS81kCtu9ackasgBHPc1enQbAp2fIOM7TkxX5aDSSNEa8ArZ0lvBwxHV4NvFz uEO+Z5mHBj+vcq1mLohqc9hXY9x+NLbW/W2XgdWJQrn630HpnOTI5dXPEO8NuhcekQGw NQ1B1cpM2vtb/ubLSCoMZrEgnFkxB4OS4dT8vNI1ceVD9y6mPC3wec3s0xtG0anTAi2Z 9TPaf29hFZIUcyiOaMWosj7y4LV1q6aoJ3H6UjC8Qc+ro95CVPIN2Vr/ygaoqJjRIW2F Gvxg== X-Gm-Message-State: AOAM531EX+Zc8cBO1oX604pTSmerZ2Z4knVJkyARFirt8Eplni5fmxAx ajcGS6mcC4tb41SJqoVWWdc7V3fhr58= X-Google-Smtp-Source: ABdhPJxq/Mk4VVM9slvxTOJugnOnUA71qyKTuAL0h3f8/ueBhLbCcxivpgKtoQVfP4/2KUnvpPsw8Foxo9o= X-Received: from reiji-vws.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:15a3]) (user=reijiw job=sendgmr) by 2002:a62:60c7:0:b0:40a:4bd7:752c with SMTP id u190-20020a6260c7000000b0040a4bd7752cmr29343562pfb.52.1634013386318; Mon, 11 Oct 2021 21:36:26 -0700 (PDT) Date: Mon, 11 Oct 2021 21:35:15 -0700 In-Reply-To: <20211012043535.500493-1-reijiw@google.com> Message-Id: <20211012043535.500493-6-reijiw@google.com> Mime-Version: 1.0 References: <20211012043535.500493-1-reijiw@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [RFC PATCH 05/25] KVM: arm64: Keep consistency of ID registers between vCPUs 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-20211011_213628_121486_8D6875E7 X-CRM114-Status: GOOD ( 14.95 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org All vCPUs that are owned by a VM must have the same values of ID registers. Return an error at the very first KVM_RUN for a vCPU if the vCPU has different values in any ID registers from any other vCPUs that have already started KVM_RUN once. Also, return an error if userspace tries to change a value of ID register for a vCPU that already started KVM_RUN once. Changing ID register is still not allowed at present though. Signed-off-by: Reiji Watanabe --- arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/kvm/arm.c | 3 +++ arch/arm64/kvm/sys_regs.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 0cd351099adf..69af669308b0 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -745,6 +745,8 @@ int kvm_arm_vcpu_arch_has_attr(struct kvm_vcpu *vcpu, long kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm, struct kvm_arm_copy_mte_tags *copy_tags); +int kvm_id_regs_consistency_check(const struct kvm_vcpu *vcpu); + /* Guest/host FPSIMD coordination helpers */ int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu); void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu); diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index fe102cd2e518..45ca72a37872 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -620,6 +620,9 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) ret = kvm_arm_pmu_v3_enable(vcpu); + if (kvm_id_regs_consistency_check(vcpu)) + return -EPERM; + return ret; } diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 8a0b88f9a975..2fe3121d50ca 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1331,6 +1331,10 @@ static int __set_id_reg(struct kvm_vcpu *vcpu, if (val != read_id_reg(vcpu, rd, raz) && !GET_ID_REG_INFO(encoding)) return -EINVAL; + /* Don't allow to change the reg after the first KVM_RUN. */ + if (vcpu->arch.has_run_once) + return -EINVAL; + if (raz) return (val == 0) ? 0 : -EINVAL; @@ -2901,6 +2905,33 @@ int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) return write_demux_regids(uindices); } +int kvm_id_regs_consistency_check(const struct kvm_vcpu *vcpu) +{ + int i; + const struct kvm_vcpu *t_vcpu; + + /* + * Make sure vcpu->arch.has_run_once is visible for others so that + * ID regs' consistency between two vCPUs is checked by either one + * at least. + */ + smp_mb(); + WARN_ON(!vcpu->arch.has_run_once); + + kvm_for_each_vcpu(i, t_vcpu, vcpu->kvm) { + if (!t_vcpu->arch.has_run_once) + /* ID regs still could be updated. */ + continue; + + if (memcmp(&__vcpu_sys_reg(vcpu, ID_REG_BASE), + &__vcpu_sys_reg(t_vcpu, ID_REG_BASE), + sizeof(__vcpu_sys_reg(vcpu, ID_REG_BASE)) * + KVM_ARM_ID_REG_MAX_NUM)) + return -EINVAL; + } + return 0; +} + static void id_reg_info_init_all(void) { int i; -- 2.33.0.882.g93a45727a2-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel