Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1966884ybh; Tue, 14 Jul 2020 11:53:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxC2cPHVATALaFWwbw0wF3C6Amw1tblmaDjVpuPtM6gTzgb9naI2CUfKSBlJZvzWDE0AbLI X-Received: by 2002:a50:9f22:: with SMTP id b31mr6197967edf.24.1594752823206; Tue, 14 Jul 2020 11:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594752823; cv=none; d=google.com; s=arc-20160816; b=pf9pJ3y/b8YPt17TtHQWPAsn9SE6wWsosKOXHvQ3rvZL2146q214g8NTYRp1QzzG5C 2i41PFmbfAFLlKpMDokCcdnAkzE0ttFfuZxu+ftSIxrzs/FdO9jUJvQbPQY5ByZsiXgY n+CVzqOlOr4zMt9Yr4bVo/U9uxTbiMh6tUYx5kCsJFYXwQ0F4F/3l9D3O9XwoSzL834+ ro5zMug3n1kv207HEo6vxu48CB/Hm1K1D7d0A3SFTT+ny9zV6FSRnBWbssvs5tQllivI gi13G//zwIbUZX2WvcjWypf49RXnw4uzrp95rdzkPj1eCSD4fE/Q5peDI66ssRVaCH9O lU3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LWYUrS1JNbfLzpfmq8h1o8S7PHMYJ+Q+Cz5Nw9dr4+Q=; b=zQFPqaV2r8yHWvfY5ZTq4x33vBliew/uOO5oJsXHwRx+WMeL7vBx8Ys663NCpgCgNU BzkyrvhJpNi4xVR/JYa1RmlQZv4VQ7u0ZlcnbeKaZvcMi46hJeHJhkIHvcEg8onKw79q EkMB16zURrh2VhzOxXU9JXZSd3KVOiuQSwytX54t1ep1dbeLHo8NCj5oUeqT4+F99tYL H3lsiey/KtM5i7RUD+KGWVzh7F6d91tsLiM+7dWMLTt4TapZSNxSpgaZng/CYozrZ4qU Su81/WbqpIcCaRvHBzJKiA7qe1D++GYCQMYe5vOSkNtUdhWwMi/PCdDCh6D/RyQicSoy VDtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hB6+cK8T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk28si10975786edb.425.2020.07.14.11.53.20; Tue, 14 Jul 2020 11:53:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hB6+cK8T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730474AbgGNSwF (ORCPT + 99 others); Tue, 14 Jul 2020 14:52:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:48602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730448AbgGNSwB (ORCPT ); Tue, 14 Jul 2020 14:52:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 81E9922B45; Tue, 14 Jul 2020 18:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594752721; bh=2tzLPYymZ+SPgvAJBgfgZt5Grrz9/AAZo6OAnnOuI/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hB6+cK8THDBc35RyiSID8iX/RTTXvGyhnQ6MS7Gf4ihE9WSyFRoyvSQ5BK5694Jrw q9fN8q6CdW3pMv87Qen+ZH2Je4eCDOzf9NAAozzwXX8ukgaqzpOQ3HV1EqOKofSXpF dF5SBSPjtxjd7w/lYTDqrFsMkI7UscVlkMjMqMQY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.4 085/109] KVM: x86: Mark CR4.TSD as being possibly owned by the guest Date: Tue, 14 Jul 2020 20:44:28 +0200 Message-Id: <20200714184109.619867462@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714184105.507384017@linuxfoundation.org> References: <20200714184105.507384017@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit 7c83d096aed055a7763a03384f92115363448b71 upstream. Mark CR4.TSD as being possibly owned by the guest as that is indeed the case on VMX. Without TSD being tagged as possibly owned by the guest, a targeted read of CR4 to get TSD could observe a stale value. This bug is benign in the current code base as the sole consumer of TSD is the emulator (for RDTSC) and the emulator always "reads" the entirety of CR4 when grabbing bits. Add a build-time assertion in to ensure VMX doesn't hand over more CR4 bits without also updating x86. Fixes: 52ce3c21aec3 ("x86,kvm,vmx: Don't trap writes to CR4.TSD") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Message-Id: <20200703040422.31536-2-sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/kvm_cache_regs.h | 2 +- arch/x86/kvm/vmx/vmx.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/kvm_cache_regs.h +++ b/arch/x86/kvm/kvm_cache_regs.h @@ -7,7 +7,7 @@ #define KVM_POSSIBLE_CR0_GUEST_BITS X86_CR0_TS #define KVM_POSSIBLE_CR4_GUEST_BITS \ (X86_CR4_PVI | X86_CR4_DE | X86_CR4_PCE | X86_CR4_OSFXSR \ - | X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_PGE) + | X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_PGE | X86_CR4_TSD) #define BUILD_KVM_GPR_ACCESSORS(lname, uname) \ static __always_inline unsigned long kvm_##lname##_read(struct kvm_vcpu *vcpu)\ --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3913,6 +3913,8 @@ void vmx_set_constant_host_state(struct void set_cr4_guest_host_mask(struct vcpu_vmx *vmx) { + BUILD_BUG_ON(KVM_CR4_GUEST_OWNED_BITS & ~KVM_POSSIBLE_CR4_GUEST_BITS); + vmx->vcpu.arch.cr4_guest_owned_bits = KVM_CR4_GUEST_OWNED_BITS; if (enable_ept) vmx->vcpu.arch.cr4_guest_owned_bits |= X86_CR4_PGE;