Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp657651pxj; Tue, 18 May 2021 11:10:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHCUir23aJfJVW1PJvelJ8JlOofSdnJSsrOpRNp5I4Xb6/CXZ+N3QPz9cHS4XB6hI3QS1K X-Received: by 2002:a05:6e02:194b:: with SMTP id x11mr5793959ilu.213.1621361436955; Tue, 18 May 2021 11:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621361436; cv=none; d=google.com; s=arc-20160816; b=yS4TyM2V7LrogQK692mwgdgYU9LQLbCcXBjxnzS12LXJSWUzL7U/aSshZVr1q/yImr glN36t+bX7CgYXCsTtk8GfPhFB/QU1jsZli5sLFBUGW4AAiIh05EkhjPUmCDblFARS4p 7huQUDnFMUe1R+BWLmaIYT1R7hIQOvHhprKZRe7D6S4tUc1lxVzomuEoVDYNLuQOAhF6 CajHcgK1zz5wU1mczFu4oqEH4hALe38bNq1S/TbW17CTvtoDivGE83pDlhxdCRaDjU2x 7NjjdWw5ZdjkglhWRvt8jc8iafdyTfGhSSIEkh6LqjpyuorIhMCFp/+CNs5LH5gFfjr6 7zow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GraVfe1kcGTyy5m86EeHbQGGyhbOs0/XovSDY3rZwDg=; b=jPficTZ7RGXXHy1nKg5gCnvoyqe7ndc0V0LkETksb2XFbqnusoNXI16eJU0oM+Kx5N 1l3P5laGxxZhGt08c4pz709xArvO5nc6l9e2kukzy64B+Zag76MPT0eQTBzqAgM1XfHv pqQ9Fk78QpsUyAR3QOK4XJQp80LbbrkDpWjjBiKowwM5JeV/of0E+Pq/skgxPibWUN6D 1wFrnVb8YLn4UHfmVZ6R11cNyLHv75FXl/Nkh4oM+KRqeR6Bu1oRU3cRErnsQ52GM9ab /mC80yHOa1Tt+XC5/1me5GaTUeWS1/C4kMfO+vklzEKPRIGqTncrXrDPXikHm+q/kdV7 TwUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lMuq6JVS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k6si21285997ilo.39.2021.05.18.11.10.23; Tue, 18 May 2021 11:10:36 -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=@linuxfoundation.org header.s=korg header.b=lMuq6JVS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243438AbhEQQLM (ORCPT + 99 others); Mon, 17 May 2021 12:11:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:33864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244769AbhEQPrp (ORCPT ); Mon, 17 May 2021 11:47:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4E7F461D3D; Mon, 17 May 2021 14:44:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262683; bh=ZX2D0TRxrlnnplpK86QgzllrXGhrjlj9rhwj+yGCWSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lMuq6JVSkkQ0k7xBJSM22De9Gp8duEiRxf0sCy3Cdead/ly+fgxLlk0ossmDA0AOP vX363/mibu4dNg9riYiV/y1RppSj/PJBxu76FlTGmApNh/rwKjy39uDi6mMDnQ1aJJ 6UsLlQ1M7rPU6Apqbs7+mE33HyW0xE11NqH1aDUw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoyao Li , Sean Christopherson , Jim Mattson , Paolo Bonzini Subject: [PATCH 5.10 260/289] KVM: VMX: Disable preemption when probing user return MSRs Date: Mon, 17 May 2021 16:03:05 +0200 Message-Id: <20210517140313.898967357@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit 5104d7ffcf24749939bea7fdb5378d186473f890 upstream. Disable preemption when probing a user return MSR via RDSMR/WRMSR. If the MSR holds a different value per logical CPU, the WRMSR could corrupt the host's value if KVM is preempted between the RDMSR and WRMSR, and then rescheduled on a different CPU. Opportunistically land the helper in common x86, SVM will use the helper in a future commit. Fixes: 4be534102624 ("KVM: VMX: Initialize vmx->guest_msrs[] right after allocation") Cc: stable@vger.kernel.org Cc: Xiaoyao Li Signed-off-by: Sean Christopherson Message-Id: <20210504171734.1434054-6-seanjc@google.com> Reviewed-by: Jim Mattson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/vmx.c | 5 +---- arch/x86/kvm/x86.c | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1668,6 +1668,7 @@ int kvm_pv_send_ipi(struct kvm *kvm, uns unsigned long icr, int op_64_bit); void kvm_define_user_return_msr(unsigned index, u32 msr); +int kvm_probe_user_return_msr(u32 msr); int kvm_set_user_return_msr(unsigned index, u64 val, u64 mask); u64 kvm_scale_tsc(struct kvm_vcpu *vcpu, u64 tsc); --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6864,12 +6864,9 @@ static int vmx_create_vcpu(struct kvm_vc for (i = 0; i < ARRAY_SIZE(vmx_uret_msrs_list); ++i) { u32 index = vmx_uret_msrs_list[i]; - u32 data_low, data_high; int j = vmx->nr_uret_msrs; - if (rdmsr_safe(index, &data_low, &data_high) < 0) - continue; - if (wrmsr_safe(index, data_low, data_high) < 0) + if (kvm_probe_user_return_msr(index)) continue; vmx->guest_uret_msrs[j].slot = i; --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -322,6 +322,22 @@ static void kvm_on_user_return(struct us } } +int kvm_probe_user_return_msr(u32 msr) +{ + u64 val; + int ret; + + preempt_disable(); + ret = rdmsrl_safe(msr, &val); + if (ret) + goto out; + ret = wrmsrl_safe(msr, val); +out: + preempt_enable(); + return ret; +} +EXPORT_SYMBOL_GPL(kvm_probe_user_return_msr); + void kvm_define_user_return_msr(unsigned slot, u32 msr) { BUG_ON(slot >= KVM_MAX_NR_USER_RETURN_MSRS);