Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp627585img; Fri, 22 Mar 2019 05:27:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjduzKM3oJ/TVAQzfbDydFRrZxsKoiqRYzG+ryqs89oZl7Jda03AfEtXfk17GiG7p0JUsD X-Received: by 2002:a63:61d7:: with SMTP id v206mr8533460pgb.349.1553257648643; Fri, 22 Mar 2019 05:27:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257648; cv=none; d=google.com; s=arc-20160816; b=cFPh2CD+w5y/RUo4SYuB572pr32jsyCvj7XAF68IsodUVq3+Qodce6QPyeAPShtS6K PJj5kHqTOYJ/FDEp6HUeucmouVkDSKTjkoVnhK2Zp84clwhNpr66rv8/S2DvJtO2v4TM nMjwnpz2efd+0J2YF2Zq3XU1NfRkI+XmKciDMMv9i3t3SW5Xb1dwI1h2bGLOGifJ5nMs Gr6pW5vgSWqZ1qi84ZLLyJMCkxPgkcwGD0tjqZ0pZskr/4IfhIdqEGDLyktS48Xjh5dL TV+LmfsY4okSPyuh2N9BepxFiAkAnO7/97JwyiGfNLW2aIqrmg/u47cq0LU3WscGMNm5 4Dkg== 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=J8vdfAmnPky4tCSkTG2mqNC6FUDm9hTB7/sBcU6/SeY=; b=ReHj/nPMc0u/zmKay6bvvqDCNTN4I5GI8noC3Xufdlqcz0++MNwycLoDsuMlNwjuCl v6J9iYQiM4cGNrxAzkV088Ejg1GEFF6RnXVG4ta7AV2wyqhuwE0+yKlMGFwx+Tt/TCWv HMCBuMVoMGpj8WfwTPv3gBwRZ835op2FFfT/AdiCNJZL4hAFu1RweR1f9pULaxvDnhz/ xvYogi6L+ztnmHjAXNL0WBDCRBqRlJq5oRzTGEARt0AVXO5uVP0Q98+SnDno9i5dksKw HYHnKN9zMDxux7USndwHhWH62iBY1TrSGZYhFsWJgYWHXz+IK5L6iYZ3VwwFHAa/m+y/ ZDWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tq5O+YLj; 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 o1si6838231plk.7.2019.03.22.05.27.13; Fri, 22 Mar 2019 05:27:28 -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=Tq5O+YLj; 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 S2390816AbfCVMXp (ORCPT + 99 others); Fri, 22 Mar 2019 08:23:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:35206 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390655AbfCVMXj (ORCPT ); Fri, 22 Mar 2019 08:23:39 -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 95479218A1; Fri, 22 Mar 2019 12:23:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257419; bh=+1PYINcUFQ56bOHgp+tVwe2tJ9XzuE/XqUX17EGUyL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tq5O+YLj3ro8258MaOwQIPEZqcg2wRR5LzTI0p1+FV/bxHUAKOjUadQNA8IHkLb8Z N59PDEyvv2+GogK3Zj90q5tPnphO1GlcuGKp2kc7YUbmFF6KSWCQsDoXEvnqM9KuWg ZxO11FKMCmu2Pu40P5bUIa4dnDqlG5a2qY4JkcBk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jim Mattson , Konrad Rzeszutek Wilk , Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.0 225/238] KVM: VMX: Compare only a single byte for VMCS "launched" in vCPU-run Date: Fri, 22 Mar 2019 12:17:24 +0100 Message-Id: <20190322111311.621105920@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit 61c08aa9606d4e48a8a50639c956448a720174c3 upstream. The vCPU-run asm blob does a manual comparison of a VMCS' launched status to execute the correct VM-Enter instruction, i.e. VMLAUNCH vs. VMRESUME. The launched flag is a bool, which is a typedef of _Bool. C99 does not define an exact size for _Bool, stating only that is must be large enough to hold '0' and '1'. Most, if not all, compilers use a single byte for _Bool, including gcc[1]. Originally, 'launched' was of type 'int' and so the asm blob used 'cmpl' to check the launch status. When 'launched' was moved to be stored on a per-VMCS basis, struct vcpu_vmx's "temporary" __launched flag was added in order to avoid having to pass the current VMCS into the asm blob. The new '__launched' was defined as a 'bool' and not an 'int', but the 'cmp' instruction was not updated. This has not caused any known problems, likely due to compilers aligning variables to 4-byte or 8-byte boundaries and KVM zeroing out struct vcpu_vmx during allocation. I.e. vCPU-run accesses "junk" data, it just happens to always be zero and so doesn't affect the result. [1] https://gcc.gnu.org/ml/gcc-patches/2000-10/msg01127.html Fixes: d462b8192368 ("KVM: VMX: Keep list of loaded VMCSs, instead of vcpus") Cc: Reviewed-by: Jim Mattson Reviewed-by: Konrad Rzeszutek Wilk Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6399,7 +6399,7 @@ static void __vmx_vcpu_run(struct kvm_vc "mov %%" _ASM_AX", %%cr2 \n\t" "3: \n\t" /* Check if vmlaunch or vmresume is needed */ - "cmpl $0, %c[launched](%%" _ASM_CX ") \n\t" + "cmpb $0, %c[launched](%%" _ASM_CX ") \n\t" /* Load guest registers. Don't clobber flags. */ "mov %c[rax](%%" _ASM_CX "), %%" _ASM_AX " \n\t" "mov %c[rbx](%%" _ASM_CX "), %%" _ASM_BX " \n\t"