Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp799686ybe; Fri, 13 Sep 2019 06:34:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZM6pm0NcwrXBI1kT85zU9pJZ1mLKLFOTueXDGAyqy+5ViGaKT7W25X9Ktj0mHMq4MPulD X-Received: by 2002:aa7:d605:: with SMTP id c5mr11362196edr.232.1568381679245; Fri, 13 Sep 2019 06:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568381679; cv=none; d=google.com; s=arc-20160816; b=EMV1silo5LtesxV2jkfDaTqM8m/Isq07JlNJBEGtLziaaBGKuJd6JBsqXsmbuZos7y +QRXCq1GlkagURW9iHT3zu7noGrnUFLTzBxlh6+RATiZ1LenaONytiX4SK0FQHCJ4WN0 k/NQ/ZMx9ucUpDwzXHZQtqT01+bKA3N9G+LzbzAHnt68oSlnVKuf568/1+rRc4EAasdj H5J59ifAakQHy0+qk3YvQG+A8rqWyLTvhxQihAl8zEMcsrhwlxGIRrwIujOQtdlRY4CL VhD7yCSKKJhcmaCFfC5+hqJ3JK+aDGhDDU+sVV8dx1QKBV4Yc2F1Y9pAwZn9yeTiG9qt Vwmw== 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=ybYvkKknRzalqf1k3/UzoooS2Jl/dpKrLqHOLZm7sjA=; b=shTfR1JYWgnpLqDPYFWGPD2xGznrd1pooBplqqbA3bvU6xp0Ica4R5q7XqlxVEWGOQ fQYd0Dc0n7JQ4xarWtQ/SA7QxuHIvib0yeHWyyD2RGUBqlovApUm2h177idt/kCtromI owiFA1wPMASwrxR4+COcSkqYT3X+tdkIB+9waZn/L48NQXaIKIz7RzaweeMIZJfW5Wph yXwjfV1tGyzitOHFCC9bi4eX7xCJdlEtgVVm9K894hxsu9UqJ+euGEpzTryJAxxID9XX p+K4Spla6d6hTLDaGw/OTLr+qOUXw/FDBAN7mJzTEalzuBhOKOEtcT8IfvXQZLWS07wC qDGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=axUsc4X+; 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 c23si10827490edt.376.2019.09.13.06.34.15; Fri, 13 Sep 2019 06:34:39 -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=axUsc4X+; 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 S2391520AbfIMNbT (ORCPT + 99 others); Fri, 13 Sep 2019 09:31:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:41248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388270AbfIMNPJ (ORCPT ); Fri, 13 Sep 2019 09:15:09 -0400 Received: from localhost (unknown [104.132.45.99]) (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 AEB0B206BB; Fri, 13 Sep 2019 13:15:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380507; bh=VKeBhnU2OZGxUtOFmDwiH/+gnCKfaZhuTAMfn4Ruuwc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=axUsc4X+i9SYojsR9AKEpARj5OLIoaerTTcUQSWXh6y1HKA4yjqTJL7m7PiLVZl4j vw0AInNk/c+lbZ/ZqECGpzc7DykZK8p2iTmQGzWnJebNsPIAUzixNWQALTQscqP1i4 /dEB5eE0tywRuCjzcujfTDn20QPby1dlccungX+U= 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 , Sasha Levin Subject: [PATCH 4.19 087/190] KVM: VMX: Compare only a single byte for VMCS "launched" in vCPU-run Date: Fri, 13 Sep 2019 14:05:42 +0100 Message-Id: <20190913130606.517354432@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130559.669563815@linuxfoundation.org> References: <20190913130559.669563815@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 [ Upstream commit 61c08aa9606d4e48a8a50639c956448a720174c3 ] 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: Sasha Levin --- arch/x86/kvm/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 2e310ea62d609..562f5dc4645b6 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -10808,7 +10808,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) "mov %%" _ASM_AX", %%cr2 \n\t" "3: \n\t" /* Check if vmlaunch of vmresume is needed */ - "cmpl $0, %c[launched](%0) \n\t" + "cmpb $0, %c[launched](%0) \n\t" /* Load guest registers. Don't clobber flags. */ "mov %c[rax](%0), %%" _ASM_AX " \n\t" "mov %c[rbx](%0), %%" _ASM_BX " \n\t" -- 2.20.1