Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4051474pxv; Tue, 13 Jul 2021 09:37:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGiLZmu0zwlfiUGUSF44RK7wrY06K3MSjAXFvWumoMh1i1shOtg4+Y09GqD/q1kppHg8Z3 X-Received: by 2002:a17:906:dfdb:: with SMTP id jt27mr1386243ejc.138.1626194226601; Tue, 13 Jul 2021 09:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626194226; cv=none; d=google.com; s=arc-20160816; b=Dci71ppUKIMM5qvqXMCEXtU2t71b2IoutHE26OAKgAwevKI/7PsyNNwIx0y1+lP0il 9UT51zBKgqoCdQMVEBui66d5e5nVlMPZPCQbEmyuez8iwsRiKQZ+0gbqoQ6mLc2A9T1l 8CipOI2yHDyDXz0GYAdppp6ZXFmpfuM2Ije8WX3hQK2zBne5hxoUDiHPu0lIPbqJ/GhM Geg2/6g0BKZ4MMIaVRVg9gJNAjiszJH0Ey58+LBT35cvYeQ6f5uC2ikq+GxGY3tTDVz8 OJ6wDxDnyroISp1kg8ATgBIP2p1LPI2SmgFVi9WYYlIMl0AKdbwm+7xVIY3XrXIRhFgS dapw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=SpdLdjXPNNhl9wZEIGsluiDA75HnwRkDLJ0hyfNw524=; b=iXXYZ7IN7L84uuE4ReR/DfQ8NcN/Rt1IzRIKWKeZXQqh9OV9JQ6BsEl2J/ztHdC1ej 9muBL+wgHeZE6TUaY+NEni9ulQfBxa/1eni6TtLWZImnLBblCjfUAQeZaaPg4C7qigzS /2JH6MxigFo8Q9uJxYuTaHJqzQ8ybf7ZahM6lxn+B1b03agfWmMityKV5yNLJOg76beU W7BWF4mz1TOP81S25IvLeLSxvXNdR0iemfMn8AvIAxKJ2+MgDdAAPSEBl4JpcUe2Iva9 f614ycgKSrg/QjmpAB1S+CzxS67OidfYcT3Ns1uDdHvVjwFCNoTCUMEIsajR15f8wL4e yltw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=t4kjJYie; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oy5si5072048ejb.482.2021.07.13.09.36.44; Tue, 13 Jul 2021 09:37:06 -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=@google.com header.s=20161025 header.b=t4kjJYie; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235320AbhGMQh3 (ORCPT + 99 others); Tue, 13 Jul 2021 12:37:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233872AbhGMQhL (ORCPT ); Tue, 13 Jul 2021 12:37:11 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59CB4C0613B8 for ; Tue, 13 Jul 2021 09:34:16 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id x84-20020a2531570000b029055d47682463so26322381ybx.5 for ; Tue, 13 Jul 2021 09:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=SpdLdjXPNNhl9wZEIGsluiDA75HnwRkDLJ0hyfNw524=; b=t4kjJYieQpw4LJJALxZZ4yV76kGvq8sra8kEjcnQ/7a5lTzX7A6+wiG8ekpz7CQX4a Pe8S7iB37i6ptXkE42k3LXAaLtO59dWKm6lWAgzAzJB9Cwpm+MF5RAVjdSF2xMGyCurH +W1b6lpnT6MyT431QmjSyogeY4Ezs/g+qK3dauIgzmvURYHnLgZarQrl6yx3DSNggXLS QcUq9U0GDoourspKZfcRadoHXEinNe53UcM0w7SIfjoXA38Zmvv0DYsnr3obTK1vwDPQ IIgTUoWgr0/h2/iqv+qcKbqvInG1NJ5XTRFDd1SHKRbh+UPSQu4KgYhJ+hb0JbNQPAE9 Rnng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=SpdLdjXPNNhl9wZEIGsluiDA75HnwRkDLJ0hyfNw524=; b=jG1b/KDsIMe17vLCFJxPR878fo/N16sH0mWYzZhGjcHT72wyvKDF/vI+0/OL7QoWIr w8zOBvORbHN/+DBDUEBAYLdLN115E3i14nL9J0PVyZSO6IR5yTTjRlh861otSyhYsyO2 DQlPv6pwnxBKvTBgsFLoq0XWbuSeIaWexOsk395DP+td4yLRlRofdEIpoSdlSbZUDDQ6 OBnBg6/25HgOi6G45PtvAKCNEPX8xOOUD84wiCYGr/1lsI2C1LEC1YoVLmfLMPBMdWzA H57jtHwkHcVQKWNScHm+9YYygTZmCHHFYV4YzLerUtrwM0euhgcc9Wxua21FHEEbiU7W iSbw== X-Gm-Message-State: AOAM533Fujp+4l/IGEcPKQJwyHfTzz54DzDz3Jk0Ar10BrvtLZd7sVcg 4G1PAV4MtE1eAd+0/0jv5aZHoa9nO+I= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:825e:11a1:364b:8109]) (user=seanjc job=sendgmr) by 2002:a25:ae25:: with SMTP id a37mr7393055ybj.253.1626194055577; Tue, 13 Jul 2021 09:34:15 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 13 Jul 2021 09:33:00 -0700 In-Reply-To: <20210713163324.627647-1-seanjc@google.com> Message-Id: <20210713163324.627647-23-seanjc@google.com> Mime-Version: 1.0 References: <20210713163324.627647-1-seanjc@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v2 22/46] KVM: VMX: Remove direct write to vcpu->arch.cr0 during vCPU RESET/INIT From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Reiji Watanabe Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove a bogus write to vcpu->arch.cr0 that immediately precedes vmx_set_cr0() during vCPU RESET/INIT. For RESET, this is a nop since the "old" CR0 value is meaningless. But for INIT, if the vCPU is coming from paging enabled mode, crushing vcpu->arch.cr0 will cause the various is_paging() checks in vmx_set_cr0() to get false negatives. For the exit_lmode() case, the false negative is benign as vmx_set_efer() is called immediately after vmx_set_cr0(). For EPT without unrestricted guest, the false negative will cause KVM to unnecessarily run with CR3 load/store exiting. But again, this is benign, albeit sub-optimal. Reviewed-by: Reiji Watanabe Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 02aec75ec6f6..ed631564c651 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4383,7 +4383,6 @@ static void init_vmcs(struct vcpu_vmx *vmx) static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) { struct vcpu_vmx *vmx = to_vmx(vcpu); - u64 cr0; if (!init_event) init_vmcs(vmx); @@ -4454,9 +4453,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) kvm_make_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu); - cr0 = X86_CR0_NW | X86_CR0_CD | X86_CR0_ET; - vmx->vcpu.arch.cr0 = cr0; - vmx_set_cr0(vcpu, cr0); /* enter rmode */ + vmx_set_cr0(vcpu, X86_CR0_NW | X86_CR0_CD | X86_CR0_ET); vmx_set_cr4(vcpu, 0); vmx_set_efer(vcpu, 0); -- 2.32.0.93.g670b81a890-goog