Received: by 10.223.164.202 with SMTP id h10csp273692wrb; Wed, 29 Nov 2017 22:03:47 -0800 (PST) X-Google-Smtp-Source: AGs4zMaSjAGoQbQ8HmSTo1yeZNhVYfg/gIi8ds5GsjfqELi2e9F+S1MI/4/EeICtExX7rQeRl624 X-Received: by 10.99.127.87 with SMTP id p23mr1298359pgn.400.1512021827357; Wed, 29 Nov 2017 22:03:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512021827; cv=none; d=google.com; s=arc-20160816; b=b3alOe92hMHzd5KozrInv0dKt2lKvl7ItA1PvxH0NTXC0AMIQf1/fGjozo0APRvq0c 4bR4hXa25bZWAX8Apobki7mzY8c1zQDAT9DurF6F7ce7VuosxQaTkcPaI3Rev6YgsO+q 2S9J0zzKbPYNPg99n/8y5iXDIgBANj3JVQbznkSZWEB/QUrSeMJ3+QgYDyYwPkE7ehee yLDGn94Ly5hWC1c9pbjfg2gvSfG+ys9nK9OACwbImWE6L7WTwbj28kA6ZECKBspvSueJ WZYuR9C83IrZDXhBwrFVkWHpDAq4gluEEPF0uJ1T0Vne/u5tsyd2S1RpgnHB8IeUzDXz NWFg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=7b+KbFf52Q1FLU9oiiZ3M0lCGYBBEMMeSQy7RKd/qBE=; b=PqUD9E+I9fS4hjdC488zsj9xOxZSxkfmr1HwvMu4hqo62rttyNRER7WyTJCno4F9PS wRC5eBGhSKb4GW/dzMndlbmmKOa9wQQUsFSe26xXbFVJwUrtMboDfVyeu9rcI3ttm+vg d6e//8QHoGR/QelcG7mDeNjvoeAzcttNiyhyXeYd6a6wdenZoWGo9acu4OyqZJ1CH0Zg 1uDMqJ9QjFS6f57zzQ/kDrDTjSJMlKR2OlxPiZT3JegKTalfVLykO+wa5kOVvPum6x93 NZoUnj53gHfKFHOajGW95+Oj1lrBfbao26MBH/EBvXwOOZ+ThWzFQWxp8fykplk5uXiM o6PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JmO9YusY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r19si2482849pgv.315.2017.11.29.22.03.34; Wed, 29 Nov 2017 22:03:47 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=JmO9YusY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753384AbdK3GBy (ORCPT + 99 others); Thu, 30 Nov 2017 01:01:54 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34837 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751694AbdK3GB0 (ORCPT ); Thu, 30 Nov 2017 01:01:26 -0500 Received: by mail-pg0-f68.google.com with SMTP id q20so2599736pgv.2; Wed, 29 Nov 2017 22:01:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7b+KbFf52Q1FLU9oiiZ3M0lCGYBBEMMeSQy7RKd/qBE=; b=JmO9YusYzaI8R7WZkN3YvWadWrKZmZl7AHQJXuXdNW+cPbGsDjHTC0Q33R65V16flv 9LOhk0vxrrUeGxmtpfc0sqSx4QCdufnTEgMePK8ed/guRVxd3vpquxrvh3tVEDPvUv4J XIH1Q4bbG0DObMyqqhWUxrawLFIOivM3E1lXQx35dzExz/m5Spmr+UwFPpJR1mCijhyw Ym1+t2NWjqpGI/gy06wQporoFtStu7ifDoE8jqBi9/usQgSje/k0q/ycQWCiYhs7j23A nqBuSSYofLN3Mj5IA5dHJk1tETqnOn6Fw4lJq/Tu+JsKRRMBA/S1dRSAlwMhJ7dVZoTK +dmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7b+KbFf52Q1FLU9oiiZ3M0lCGYBBEMMeSQy7RKd/qBE=; b=oN+v5FS5FD/rQ60EV8P6BNghyKcew1unr0uWGDd6qj7IP1EwgZcMSMUWnf+70mDeax F1GKP+2SEnSAezlpRVjc0meLje3BESAC93xDYucVKnjCnf+Ehhqgu9KBIZEFqS7HWOP0 QnN8kzbgJLJoy+j22KpiJW0ZCAH8+hV0hzwwbg/ypsBaTJqCRcbhT8bkmynX6/weskBt HUCMWv3S9BGsn/SVqSzg5i4WPiq4dBDeBQghhun2XqGMLAh06gOr5Qloo9TwckVMc5Mo 3x2DCI39vt+P2TfmlVuazgXHPGvhxjxdDt7FMCCO60KZ/QOufKEy5xcWTrzWs3n07X0U Ozow== X-Gm-Message-State: AJaThX6vUW4FFpdicflR+0a8AXf2/TJb9XwU8QR5fgDIlGc2bKBw0Lcv //2AT/EMwro6lyPU81buGu0gQQ== X-Received: by 10.101.101.208 with SMTP id y16mr1362846pgv.159.1512021686066; Wed, 29 Nov 2017 22:01:26 -0800 (PST) Received: from localhost ([203.205.141.123]) by smtp.gmail.com with ESMTPSA id b9sm4977308pgu.20.2017.11.29.22.01.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 22:01:25 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Peter Zijlstra , Wanpeng Li Subject: [PATCH v7 3/4] KVM: X86: introduce invalidate_gpa argument to tlb flush Date: Wed, 29 Nov 2017 22:01:13 -0800 Message-Id: <1512021674-9880-4-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512021674-9880-1-git-send-email-wanpeng.li@hotmail.com> References: <1512021674-9880-1-git-send-email-wanpeng.li@hotmail.com> 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 From: Wanpeng Li Introduce a new bool invalidate_gpa argument to kvm_x86_ops->tlb_flush, it will be used by later patches to just flush guest tlb. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Peter Zijlstra Signed-off-by: Wanpeng Li --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm.c | 14 +++++++------- arch/x86/kvm/vmx.c | 21 +++++++++++---------- arch/x86/kvm/x86.c | 6 +++--- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index b97726e..63d34bc 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -952,7 +952,7 @@ struct kvm_x86_ops { unsigned long (*get_rflags)(struct kvm_vcpu *vcpu); void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags); - void (*tlb_flush)(struct kvm_vcpu *vcpu); + void (*tlb_flush)(struct kvm_vcpu *vcpu, bool invalidate_gpa); void (*run)(struct kvm_vcpu *vcpu); int (*handle_exit)(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 1f3e7f2..14cca8c 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -285,7 +285,7 @@ static int vgif = true; module_param(vgif, int, 0444); static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0); -static void svm_flush_tlb(struct kvm_vcpu *vcpu); +static void svm_flush_tlb(struct kvm_vcpu *vcpu, bool invalidate_gpa); static void svm_complete_interrupts(struct vcpu_svm *svm); static int nested_svm_exit_handled(struct vcpu_svm *svm); @@ -2035,7 +2035,7 @@ static int svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) return 1; if (npt_enabled && ((old_cr4 ^ cr4) & X86_CR4_PGE)) - svm_flush_tlb(vcpu); + svm_flush_tlb(vcpu, true); vcpu->arch.cr4 = cr4; if (!npt_enabled) @@ -2385,7 +2385,7 @@ static void nested_svm_set_tdp_cr3(struct kvm_vcpu *vcpu, svm->vmcb->control.nested_cr3 = __sme_set(root); mark_dirty(svm->vmcb, VMCB_NPT); - svm_flush_tlb(vcpu); + svm_flush_tlb(vcpu, true); } static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, @@ -2989,7 +2989,7 @@ static void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, svm->nested.intercept_exceptions = nested_vmcb->control.intercept_exceptions; svm->nested.intercept = nested_vmcb->control.intercept; - svm_flush_tlb(&svm->vcpu); + svm_flush_tlb(&svm->vcpu, true); svm->vmcb->control.int_ctl = nested_vmcb->control.int_ctl | V_INTR_MASKING_MASK; if (nested_vmcb->control.int_ctl & V_INTR_MASKING_MASK) svm->vcpu.arch.hflags |= HF_VINTR_MASK; @@ -4785,7 +4785,7 @@ static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr) return 0; } -static void svm_flush_tlb(struct kvm_vcpu *vcpu) +static void svm_flush_tlb(struct kvm_vcpu *vcpu, bool invalidate_gpa) { struct vcpu_svm *svm = to_svm(vcpu); @@ -5076,7 +5076,7 @@ static void svm_set_cr3(struct kvm_vcpu *vcpu, unsigned long root) svm->vmcb->save.cr3 = __sme_set(root); mark_dirty(svm->vmcb, VMCB_CR); - svm_flush_tlb(vcpu); + svm_flush_tlb(vcpu, true); } static void set_tdp_cr3(struct kvm_vcpu *vcpu, unsigned long root) @@ -5090,7 +5090,7 @@ static void set_tdp_cr3(struct kvm_vcpu *vcpu, unsigned long root) svm->vmcb->save.cr3 = kvm_read_cr3(vcpu); mark_dirty(svm->vmcb, VMCB_CR); - svm_flush_tlb(vcpu); + svm_flush_tlb(vcpu, true); } static int is_disabled(void) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index b10d203..8c7e816 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -4136,9 +4136,10 @@ static void exit_lmode(struct kvm_vcpu *vcpu) #endif -static inline void __vmx_flush_tlb(struct kvm_vcpu *vcpu, int vpid) +static inline void __vmx_flush_tlb(struct kvm_vcpu *vcpu, int vpid, + bool invalidate_gpa) { - if (enable_ept) { + if (enable_ept && (invalidate_gpa || !enable_vpid)) { if (!VALID_PAGE(vcpu->arch.mmu.root_hpa)) return; ept_sync_context(construct_eptp(vcpu, vcpu->arch.mmu.root_hpa)); @@ -4147,15 +4148,15 @@ static inline void __vmx_flush_tlb(struct kvm_vcpu *vcpu, int vpid) } } -static void vmx_flush_tlb(struct kvm_vcpu *vcpu) +static void vmx_flush_tlb(struct kvm_vcpu *vcpu, bool invalidate_gpa) { - __vmx_flush_tlb(vcpu, to_vmx(vcpu)->vpid); + __vmx_flush_tlb(vcpu, to_vmx(vcpu)->vpid, invalidate_gpa); } static void vmx_flush_tlb_ept_only(struct kvm_vcpu *vcpu) { if (enable_ept) - vmx_flush_tlb(vcpu); + vmx_flush_tlb(vcpu, true); } static void vmx_decache_cr0_guest_bits(struct kvm_vcpu *vcpu) @@ -4353,7 +4354,7 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) ept_load_pdptrs(vcpu); } - vmx_flush_tlb(vcpu); + vmx_flush_tlb(vcpu, true); vmcs_writel(GUEST_CR3, guest_cr3); } @@ -8026,7 +8027,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu) return kvm_skip_emulated_instruction(vcpu); } - __vmx_flush_tlb(vcpu, vmx->nested.vpid02); + __vmx_flush_tlb(vcpu, vmx->nested.vpid02, true); nested_vmx_succeed(vcpu); return kvm_skip_emulated_instruction(vcpu); @@ -10710,11 +10711,11 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->nested.vpid02); if (vmcs12->virtual_processor_id != vmx->nested.last_vpid) { vmx->nested.last_vpid = vmcs12->virtual_processor_id; - __vmx_flush_tlb(vcpu, to_vmx(vcpu)->nested.vpid02); + __vmx_flush_tlb(vcpu, to_vmx(vcpu)->nested.vpid02, true); } } else { vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid); - vmx_flush_tlb(vcpu); + vmx_flush_tlb(vcpu, true); } } @@ -11424,7 +11425,7 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu, * L1's vpid. TODO: move to a more elaborate solution, giving * each L2 its own vpid and exposing the vpid feature to L1. */ - vmx_flush_tlb(vcpu); + vmx_flush_tlb(vcpu, true); } /* Restore posted intr vector. */ if (nested_cpu_has_posted_intr(vmcs12)) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index bc501aa..c279530 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6775,10 +6775,10 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu) kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap); } -static void kvm_vcpu_flush_tlb(struct kvm_vcpu *vcpu) +static void kvm_vcpu_flush_tlb(struct kvm_vcpu *vcpu, bool invalidate_gpa) { ++vcpu->stat.tlb_flush; - kvm_x86_ops->tlb_flush(vcpu); + kvm_x86_ops->tlb_flush(vcpu, invalidate_gpa); } void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu) @@ -6835,7 +6835,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) if (kvm_check_request(KVM_REQ_MMU_SYNC, vcpu)) kvm_mmu_sync_roots(vcpu); if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu)) - kvm_vcpu_flush_tlb(vcpu); + kvm_vcpu_flush_tlb(vcpu, true); if (kvm_check_request(KVM_REQ_REPORT_TPR_ACCESS, vcpu)) { vcpu->run->exit_reason = KVM_EXIT_TPR_ACCESS; r = 0; -- 2.7.4 From 1585450068301717427@xxx Thu Nov 30 00:50:10 +0000 2017 X-GM-THRID: 1585450068301717427 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread