Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1795607pxy; Fri, 23 Apr 2021 17:55:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWcz4XC/ax2WmS5C5Mak69tpkGBGsFDZUFG4Y6L+WfNnYOjhrtmxcZbzR6AFntqUlo1bAe X-Received: by 2002:a17:906:1984:: with SMTP id g4mr6795375ejd.525.1619225732337; Fri, 23 Apr 2021 17:55:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619225732; cv=none; d=google.com; s=arc-20160816; b=apHAnkvCkUNKeGozm8sP5Hnc68yvIDnkzMqqf3QTYVx3XiNmXIDcYkgKTxHkD6xur0 mGepuHjiUSX8vsOqnXjRTSlotpqMHMz/qqg/AeOsP1waO0DwqDpOaT1Oy76erGhk/jm+ C39cYphAp3ux5sp+ORLa7QGPUeSGggiLgG+QSNlu9seMPMxh4my3oLOqWnaBANxkL+IF 4E1AQPlXK1pgl/vaJZbrD75EI1WyqZuxWx+XA4jjvczVHf3OCrKUdxmOMM/3jGUqFq1h CF/FfVL8C+He4wAt4nRPw48YR3ShLTi8IbDu/CL9HD1b+DDlKMJ8HIw84sqtBzmCDKF2 X4Gw== 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=qXb6vjQTd1xwjeGuxgHWs2f2nyIxbCEgG3y42oAowog=; b=HaIK6v9+dVIFWX5cT6kSsi3ST+7HGRDECmv2v8eKKSvfHYCol3lW5q73asJuhGdSRE WE9zcaw30C2T76tWtEJqiSqdrz3sfYt2OhhabingaHjal01trJZE1fKbmB5DOXcDx4Wa 3OS18wLrtVxQN4qMtdLY4KcCrCvEcwA1EhY5zZYlOkBzYE+xqHpvss4jZUAMJ/wk4NJN 5Iln35NrEK/85dVdmeEvc97iN06gOGiORb0u+HYrE0CHPSDjwQ7SR33PibyZ3V694mPk a53tg6eRv6vtPFGssBwqdlcUHXZE7zMWwSS5c41UjdN9akeamaIrCJnEAd4uLfpVNFbN wU7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hJ5QM1I+; 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 t20si7042097edr.560.2021.04.23.17.55.08; Fri, 23 Apr 2021 17:55:32 -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=hJ5QM1I+; 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 S244277AbhDXAwj (ORCPT + 99 others); Fri, 23 Apr 2021 20:52:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244320AbhDXAu4 (ORCPT ); Fri, 23 Apr 2021 20:50:56 -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 5DE17C06136D for ; Fri, 23 Apr 2021 17:47:51 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id e13-20020a25d30d0000b02904ec4109da25so26207760ybf.7 for ; Fri, 23 Apr 2021 17:47:51 -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=qXb6vjQTd1xwjeGuxgHWs2f2nyIxbCEgG3y42oAowog=; b=hJ5QM1I+GcatYOsJAhrQYWxqOelYqAAqZTUaiWa8J4truULZy53P1vLI1c8k5c+GhF zSayk6J4HVR89e04/E5spls47PevdzuGhhz1JhwcqWim4Aa8Lw6t3b77+PEU6hFBxkdN EHqYsU+6eKPUgT323rnDunkjJva93ZP5iP7HjjvdITSOTQd7S5wEG98DmsnHHM00zVCg r2T11xOgWHAOxcBWNgL16pWiGyWLlQTcXd4hFcZFzcVr8gbTgvUL/iFjpfAuBfIqkkoA 9tJUeCetGo5mtLMg3LYvI1KrYOx3oQfA+oQppLM7MnQo60EV5vdV5l99FQJIEJsKhvxJ vmPA== 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=qXb6vjQTd1xwjeGuxgHWs2f2nyIxbCEgG3y42oAowog=; b=diRcAhyEIjAvp5DM5yNtmfHBTiQk+eRFPJmsffwLxphrbxsvz/YATHZqIFBoC98o11 9PnSIn02FlnjsDJQxGJFq9aIs1FbkuoI3IPA9VSVMpD1j4/vp0yUlgFJcaxvmUI94BcJ cxybgVv6YxODXPYe/f6KK9DSQRMN6IuvLNl5xdx32RxcxWa/Bp2vawePtx1TozSf0Jj4 m5Cpu9makt+/0UYFR44+LJmp9m1UsrI/qdwp6Wl6idTle33C0yvVf3Vlw1vnlCkk+MbK tnkXVV9ayOmhSVdeqnSQmsCnE59pzzbKBkblGd7Q5WPUWONiYd9CM0o5d1XkOHlUoY/D 7QUg== X-Gm-Message-State: AOAM533KM2R9j1PLizH13/SBQpXRYoGH0HRhbbzvKeLSyanTcRzaXd+8 DTQqdKE6V8eWo+U0QYyaG1mxOxFdE4s= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:ad52:3246:e190:f070]) (user=seanjc job=sendgmr) by 2002:a25:3447:: with SMTP id b68mr6804966yba.180.1619225270603; Fri, 23 Apr 2021 17:47:50 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 23 Apr 2021 17:46:25 -0700 In-Reply-To: <20210424004645.3950558-1-seanjc@google.com> Message-Id: <20210424004645.3950558-24-seanjc@google.com> Mime-Version: 1.0 References: <20210424004645.3950558-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH 23/43] KVM: VMX: Fold ept_update_paging_mode_cr0() back into vmx_set_cr0() 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the CR0/CR3/CR4 shenanigans for EPT without unrestricted guest back into vmx_set_cr0(). This will allow a future patch to eliminate the rather gross stuffing of vcpu->arch.cr0 in the paging transition cases by snapshotting the old CR0. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 5795de909609..c9322cd55390 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3102,27 +3102,6 @@ void ept_save_pdptrs(struct kvm_vcpu *vcpu) kvm_register_mark_dirty(vcpu, VCPU_EXREG_PDPTR); } -static void ept_update_paging_mode_cr0(unsigned long cr0, struct kvm_vcpu *vcpu) -{ - struct vcpu_vmx *vmx = to_vmx(vcpu); - - if (!kvm_register_is_available(vcpu, VCPU_EXREG_CR3)) - vmx_cache_reg(vcpu, VCPU_EXREG_CR3); - if (!(cr0 & X86_CR0_PG)) { - /* From paging/starting to nonpaging */ - exec_controls_setbit(vmx, CPU_BASED_CR3_LOAD_EXITING | - CPU_BASED_CR3_STORE_EXITING); - vcpu->arch.cr0 = cr0; - vmx_set_cr4(vcpu, kvm_read_cr4(vcpu)); - } else if (!is_paging(vcpu)) { - /* From nonpaging to paging */ - exec_controls_clearbit(vmx, CPU_BASED_CR3_LOAD_EXITING | - CPU_BASED_CR3_STORE_EXITING); - vcpu->arch.cr0 = cr0; - vmx_set_cr4(vcpu, kvm_read_cr4(vcpu)); - } -} - void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) { struct vcpu_vmx *vmx = to_vmx(vcpu); @@ -3152,8 +3131,23 @@ void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) } #endif - if (enable_ept && !is_unrestricted_guest(vcpu)) - ept_update_paging_mode_cr0(cr0, vcpu); + if (enable_ept && !is_unrestricted_guest(vcpu)) { + if (!kvm_register_is_available(vcpu, VCPU_EXREG_CR3)) + vmx_cache_reg(vcpu, VCPU_EXREG_CR3); + if (!(cr0 & X86_CR0_PG)) { + /* From paging/starting to nonpaging */ + exec_controls_setbit(vmx, CPU_BASED_CR3_LOAD_EXITING | + CPU_BASED_CR3_STORE_EXITING); + vcpu->arch.cr0 = cr0; + vmx_set_cr4(vcpu, kvm_read_cr4(vcpu)); + } else if (!is_paging(vcpu)) { + /* From nonpaging to paging */ + exec_controls_clearbit(vmx, CPU_BASED_CR3_LOAD_EXITING | + CPU_BASED_CR3_STORE_EXITING); + vcpu->arch.cr0 = cr0; + vmx_set_cr4(vcpu, kvm_read_cr4(vcpu)); + } + } vmcs_writel(CR0_READ_SHADOW, cr0); vmcs_writel(GUEST_CR0, hw_cr0); -- 2.31.1.498.g6c1eba8ee3d-goog