From patchwork Sat Jul 30 01:56:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 9253029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BA9F76075F for ; Sat, 30 Jul 2016 01:58:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D5BB28445 for ; Sat, 30 Jul 2016 01:58:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DF692845A; Sat, 30 Jul 2016 01:58:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 341C028445 for ; Sat, 30 Jul 2016 01:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752193AbcG3B6J (ORCPT ); Fri, 29 Jul 2016 21:58:09 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:33864 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751936AbcG3B6H (ORCPT ); Fri, 29 Jul 2016 21:58:07 -0400 Received: by mail-pa0-f43.google.com with SMTP id fi15so35857765pac.1 for ; Fri, 29 Jul 2016 18:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=SXpgZaNbtwjNsR87kO3cN/Hc+7NssGytPWS2wi95Rf8=; b=NU1KVxV8zLcLxbtx3HnqFzrzJ55o2wZPnLip0uhLWyA2XFL/MDlTmh/hugHEcwp4iF 9Hix1xiTKYbyrNS3l8cHCMkWqe+b92avO0P0ndCdvKu54ZohlkKYkNMGS1Kv/nYPeVQV 5aEXTCFDgU605nr/ZwSbDNJziK9uhjCnenTv6Ylpr++9F5uhMlKJbIQNOIu8Q5cMSnJA p2FZRSSsUEy1ECMWkdBSCnoSWghmS956OxpeaIjePY7OyzB9a9kYobsSiMN2DfwTs4/P fS41T1HJJNtHkyjEMyRAmInYG5k0z5lVdAAsFqpzUusckPl6/84pSF1LXvmIFV5ne+2x /xjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SXpgZaNbtwjNsR87kO3cN/Hc+7NssGytPWS2wi95Rf8=; b=OOM4RSjeSAkiPyztBdUCNgchsjXAwTavrW6xBrc5bAktSh4L846tUjK3HJxFxeMjbC jCLuV3kSHfikJ/anXdYW3d+xZMayMMwCzYNe4+rmP9i3n/F5wPAqIAz91BGILzdEwsKD z3KxKtLTNiDfPNPDgnTGsd1X+rkvwGGhjaasw6J/a0RHQwFo7Ait4J4MfAPLR75fkpAc cEs/VGHedCkeMiVC4Zn7P2sAPNTsFFfHxfvkVVYKUuRGJTui6NK/KWtBMSEP7WQhG4QW ZtFg2Fq8jQMPygsoZZl+/4qZMg1wcBUfrhZFYbAv/mR5Sh0tP79+KDK7rPWmqIApQHTp pOzg== X-Gm-Message-State: AEkoouuf3Xxugp0anxc0tZQ5M4qcc5Ue1ZG33OM/m8iOLG59UsdgAZUsGlupqrIOWSwDN2KH X-Received: by 10.66.72.195 with SMTP id f3mr72974961pav.141.1469843885105; Fri, 29 Jul 2016 18:58:05 -0700 (PDT) Received: from jmattson.sea.corp.google.com ([100.100.206.154]) by smtp.gmail.com with ESMTPSA id o80sm27838776pfa.67.2016.07.29.18.58.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jul 2016 18:58:04 -0700 (PDT) From: Jim Mattson To: kvm@vger.kernel.org Cc: Jim Mattson Subject: [PATCH] KVM: VMX: Add VMCS to CPU's loaded VMCSs before VMPTRLD Date: Fri, 29 Jul 2016 18:56:53 -0700 Message-Id: <1469843813-30810-1-git-send-email-jmattson@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Kexec needs to know the addresses of all VMCSs that are active on each CPU, so that it can flush them from the VMCS caches. It is safe to record superfluous addresses that are not associated with an active VMCS, but it is not safe to omit an address associated with an active VMCS. After a call to vmcs_load, the VMCS that was loaded is active on the CPU. The VMCS should be added to the CPU's list of active VMCSs before it is loaded. Signed-off-by: Jim Mattson --- arch/x86/kvm/vmx.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 7758680..f3d9995 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2121,22 +2121,14 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); u64 phys_addr = __pa(per_cpu(vmxarea, cpu)); + bool already_loaded = vmx->loaded_vmcs->cpu == cpu; if (!vmm_exclusive) kvm_cpu_vmxon(phys_addr); - else if (vmx->loaded_vmcs->cpu != cpu) + else if (!already_loaded) loaded_vmcs_clear(vmx->loaded_vmcs); - if (per_cpu(current_vmcs, cpu) != vmx->loaded_vmcs->vmcs) { - per_cpu(current_vmcs, cpu) = vmx->loaded_vmcs->vmcs; - vmcs_load(vmx->loaded_vmcs->vmcs); - } - - if (vmx->loaded_vmcs->cpu != cpu) { - struct desc_ptr *gdt = this_cpu_ptr(&host_gdt); - unsigned long sysenter_esp; - - kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); + if (!already_loaded) { local_irq_disable(); crash_disable_local_vmclear(cpu); @@ -2151,6 +2143,18 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) &per_cpu(loaded_vmcss_on_cpu, cpu)); crash_enable_local_vmclear(cpu); local_irq_enable(); + } + + if (per_cpu(current_vmcs, cpu) != vmx->loaded_vmcs->vmcs) { + per_cpu(current_vmcs, cpu) = vmx->loaded_vmcs->vmcs; + vmcs_load(vmx->loaded_vmcs->vmcs); + } + + if (!already_loaded) { + struct desc_ptr *gdt = this_cpu_ptr(&host_gdt); + unsigned long sysenter_esp; + + kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); /* * Linux uses per-cpu TSS and GDT, so set these when switching