Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3805792ybi; Mon, 29 Jul 2019 13:00:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4/w9jun0TWXlZOm0ca14RqwIGiK0xgybgEtUUrJ8SPp2jZvZXMwAyeoFFbOeggEtTqoTj X-Received: by 2002:a63:4f18:: with SMTP id d24mr29375480pgb.126.1564430427356; Mon, 29 Jul 2019 13:00:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430427; cv=none; d=google.com; s=arc-20160816; b=LerY5N4lLGhuUOTa5nCYAPNwd+sTXCSR4HDL8TpmOOtikrxWHq4ezMcsrAezuCJcut 4LLSTYBVdGTuq5cHsbG1LQfWPxczz44geQzjB/76bX7ApF2vZ1EjP8z6c3CiRLWKX8ej DPo84Hxb2B5zSusR1SCF/KLUGPEdBZAf20FBm3zJKmRT0Hf8Llv64XfQ3GysJy/X6PNl DCDisJJqPBfX/uUbx/ei45DKXTEse2qknPx3Z6zdfBGaszKA6d6kuteWj6bXFiIhJlku Lyd8k8dtrF/tg14EdNqc8dP2HDXVZlJJX4NshQTmsDlrmjqd0lBkXqpAHmKLkEtgXvtc 28lw== 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=RtoMGwRZLfWr5eLELTD4bSjUKiqfBL84oyPWLrMOWmA=; b=SE2WezoxqW+jzhlJcF4GNQXnP1nSthPTqAX73jQP1Xvde0UB8YtaV2k7R6HCK9xLd1 HyC7Heh20A8EToIpmUzk4WBQ6gBf1ruQ3PnVY8agCRyJmMykrQ4RwRoYMcCpwqGEppg9 dGwicNqrk17gZtWgFtzcXob9O2ZFst++8IiBBId8WFvP6sk9rfv6cMZuqN9cgO2+B2ET xIvhVfAGvkAaWk5IwHXdNxyedZ3zSyvZkUIOT4yCQEj4689+jLQT9qnJ+ELOXFOxx4nY cLNZDoVQbW1YcXVWhr8GruQ4Y37l6F+C4wi1LqP1TIODbHTcdF0YlCXnuQXnC8APwfX+ l1dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k7r0wJDM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si28091534plb.38.2019.07.29.13.00.12; Mon, 29 Jul 2019 13:00:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k7r0wJDM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390999AbfG2TyM (ORCPT + 99 others); Mon, 29 Jul 2019 15:54:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:46390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390935AbfG2Txw (ORCPT ); Mon, 29 Jul 2019 15:53:52 -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 A6112217D7; Mon, 29 Jul 2019 19:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430031; bh=7oNkVGkCARzG3ouaad00+6R83JA69aiApiOofGoMXcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k7r0wJDMUyOUeM+YAxSH2u8P883Csv/BuK6MbXytvsYzC+kotmfR20vip8g268I+l sLR7r7qsrWb4097ZqO+NChPbPaibHtis7IxnFFu2XjouQV3i+W7GZdlulCQdttUC7J ypQ+uZnfveknkaUw9wX/IeHPavxSX+lvLXvXObRA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Lambertz , anthony , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li Subject: [PATCH 5.2 174/215] KVM: X86: Fix fpu state crash in kvm guest Date: Mon, 29 Jul 2019 21:22:50 +0200 Message-Id: <20190729190810.125640760@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@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: Wanpeng Li commit e751732486eb3f159089a64d1901992b1357e7cc upstream. The idea before commit 240c35a37 (which has just been reverted) was that we have the following FPU states: userspace (QEMU) guest --------------------------------------------------------------------------- processor vcpu->arch.guest_fpu >>> KVM_RUN: kvm_load_guest_fpu vcpu->arch.user_fpu processor >>> preempt out vcpu->arch.user_fpu current->thread.fpu >>> preempt in vcpu->arch.user_fpu processor >>> back to userspace >>> kvm_put_guest_fpu processor vcpu->arch.guest_fpu --------------------------------------------------------------------------- With the new lazy model we want to get the state back to the processor when schedule in from current->thread.fpu. Reported-by: Thomas Lambertz Reported-by: anthony Tested-by: anthony Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Thomas Lambertz Cc: anthony Cc: stable@vger.kernel.org Fixes: 5f409e20b (x86/fpu: Defer FPU state load until return to userspace) Signed-off-by: Wanpeng Li [Add a comment in front of the warning. - Paolo] Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3264,6 +3264,10 @@ void kvm_arch_vcpu_load(struct kvm_vcpu kvm_x86_ops->vcpu_load(vcpu, cpu); + fpregs_assert_state_consistent(); + if (test_thread_flag(TIF_NEED_FPU_LOAD)) + switch_fpu_return(); + /* Apply any externally detected TSC adjustments (due to suspend) */ if (unlikely(vcpu->arch.tsc_offset_adjustment)) { adjust_tsc_offset_host(vcpu, vcpu->arch.tsc_offset_adjustment); @@ -7955,9 +7959,8 @@ static int vcpu_enter_guest(struct kvm_v wait_lapic_expire(vcpu); guest_enter_irqoff(); - fpregs_assert_state_consistent(); - if (test_thread_flag(TIF_NEED_FPU_LOAD)) - switch_fpu_return(); + /* The preempt notifier should have taken care of the FPU already. */ + WARN_ON_ONCE(test_thread_flag(TIF_NEED_FPU_LOAD)); if (unlikely(vcpu->arch.switch_db_regs)) { set_debugreg(0, 7);