From patchwork Sun Dec 6 14:51:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 40424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C7C33B7C12 for ; Mon, 7 Dec 2009 01:52:14 +1100 (EST) Received: from localhost ([127.0.0.1]:48069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHIT4-0005zi-JM for incoming@patchwork.ozlabs.org; Sun, 06 Dec 2009 09:52:10 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NHISY-0005xe-50 for qemu-devel@nongnu.org; Sun, 06 Dec 2009 09:51:38 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NHIST-0005tF-OH for qemu-devel@nongnu.org; Sun, 06 Dec 2009 09:51:37 -0500 Received: from [199.232.76.173] (port=52577 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHIST-0005t8-Gx for qemu-devel@nongnu.org; Sun, 06 Dec 2009 09:51:33 -0500 Received: from fmmailgate01.web.de ([217.72.192.221]:39367) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NHISS-00035j-SU for qemu-devel@nongnu.org; Sun, 06 Dec 2009 09:51:33 -0500 Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172]) by fmmailgate01.web.de (Postfix) with ESMTP id 2F80813FEA239; Sun, 6 Dec 2009 15:51:31 +0100 (CET) Received: from [88.65.36.198] (helo=[192.168.1.10]) by smtp06.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #314) id 1NHISP-0002g8-00; Sun, 06 Dec 2009 15:51:29 +0100 Message-ID: <4B1BC4EC.90704@web.de> Date: Sun, 06 Dec 2009 15:51:24 +0100 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Anthony Liguori X-Enigmail-Version: 0.95.7 X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX18B6iJS7Hu2CubjfpCTcw1AsuwcdkrwY2QCk9d9 ecgVPBBBqr9l2gMjMcrDFo1o5Bz27AP2VixWURHdhlGnTPb/Ol IyZs0NwMQ= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 Cc: Marcelo Tosatti , qemu-devel , Avi Kivity Subject: [Qemu-devel] [PATCH] kvm: x86: Fix initial kvm_has_msr_star X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org KVM_GET_MSR_INDEX_LIST returns -E2BIG when the provided space is too small for all MSRs. But this is precisely the error we trigger with the initial request in order to obtain that size. Do not fail in that case. This caused a subtle corruption of the guest state as MSR_STAR was not properly saved/restored. The corruption became visible with latest kvm optimizing the MSR updates. Signed-off-by: Jan Kiszka --- target-i386/kvm.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 3b61a7f..88b504c 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -244,9 +244,9 @@ static int kvm_has_msr_star(CPUState *env) * save/restore */ msr_list.nmsrs = 0; ret = kvm_ioctl(env->kvm_state, KVM_GET_MSR_INDEX_LIST, &msr_list); - if (ret < 0) + if (ret < 0 && ret != -E2BIG) { return 0; - + } /* Old kernel modules had a bug and could write beyond the provided memory. Allocate at least a safe amount of 1K. */ kvm_msr_list = qemu_mallocz(MAX(1024, sizeof(msr_list) +