Received: by 10.223.164.202 with SMTP id h10csp163782wrb; Thu, 9 Nov 2017 04:31:52 -0800 (PST) X-Google-Smtp-Source: ABhQp+RdCON0lAFRHUt1W8RMaV2zbj9zMrRv15HPvBa+3DPQCWwv3MuJx/p7gO0Q4YKctDugFRfw X-Received: by 10.101.87.193 with SMTP id q1mr341906pgr.370.1510230712038; Thu, 09 Nov 2017 04:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510230712; cv=none; d=google.com; s=arc-20160816; b=j2YPtlSu3H/JVSJDxAT3roWhj0HfCiE03Sl3yAFywpqdPlZezwwj2Hfy936O7pQJ4C SDQYfn/keHRm9nsSpIIkitzg+aOf7zVpAwPUtsF/QJZAicAu4i1IwtEf/vwir+6Sg6PG zKdNu8WaVCsAo60BALQ0cdrv8k5fVKAxjJEoRbKBKciRdIAvG4jY15Z02GYPJ/WEzLJ1 +8ZAHnZgEkE/z5aiq2Xk4Q/Ku3DC69VC1q5KQktroxrj9fc+WJ9qabatocMomMoMCgnx s0mnWITov52hNxC74R0xSQuUqRcd4wBKBmIdF/XYAIHDxY6t7gPHQOpidDJNXdzU2aBJ VjEQ== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=kfai1zVm8rFewLQWqNuIfX2XXdFC2WiwHXoVW0KvnoA=; b=GATR6wqQzeejj8COt2bmebIvX1yrkUqcSugFfAvOrA28t00FpnJB/ym08twgn5XPH1 llNi2P3Yd1WrNAyu5wAt4okF6bDQj4LqDEWZrAuCQS92C5bk+fm7CI6T3LFg15mSstr3 Gqk9M81N8nJq+LkHWMbZso+Yq6mTdMjQBY9jdn1K7Z61IdFWFZFG9eeSZjWlevpvAcWS dk4f65NeYdMuCKQMBuHp9WyUkimvPZhAwyOfqBu2ZBtLJ8FXKfDHPVHRjOJGSsK7YVUM h+qeDLlfExK2cXQTKSMvUKSmU1zuNPvFUpjG72GA4hkJ9aAXyn7Md52Nl7cPwT3IztEq 1CHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=daGKe0db; 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 o75si6579906pfk.60.2017.11.09.04.31.39; Thu, 09 Nov 2017 04:31:52 -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=daGKe0db; 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 S1754369AbdKIMbD (ORCPT + 80 others); Thu, 9 Nov 2017 07:31:03 -0500 Received: from mail-ot0-f194.google.com ([74.125.82.194]:57304 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754211AbdKIMbB (ORCPT ); Thu, 9 Nov 2017 07:31:01 -0500 Received: by mail-ot0-f194.google.com with SMTP id j29so1696530oth.13; Thu, 09 Nov 2017 04:31:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=kfai1zVm8rFewLQWqNuIfX2XXdFC2WiwHXoVW0KvnoA=; b=daGKe0dbjIBb3Kah7NqzM5i6T3Cjqz+EM8srDEVfo3hns92fkA3wQkK4C1UPHnUSuE Xj2NGNJDbCta5//SDxWaB4xH1qEeMFw+PKoc6+3spSa7QZ6Bmnf6aWGnTcc8kHPYk5R3 0nMFARYf6EeoGx9olKIeeSvTYaOJSC7qjLqdGyo7ec7vayjyMR8djtAQpOg2zK8MV9xE /xBVSggUazwqWkyewDHifqfGSg/TEEQzvM7ilkDL/2Q/3X09eN2Nijq8ZBYCnfsVdiJp ZnVFyh7jwooMbZHIo1eoqlDBqa1DPumyJKr+abLEqjKECYlg7wpysrVDel/03rIEXZa+ 0Xcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=kfai1zVm8rFewLQWqNuIfX2XXdFC2WiwHXoVW0KvnoA=; b=ax5Y9/wcfac0HtKjlW38ds8+Mqy3FlvnwgQeJL7BzPvcV3eY5dFy9hGdtkHfAgWB2v fAvAIuX8sLHwRv+XDaQ0x+ZxPWCFv1WUBCV0i41EsIFrI0obCSJ63PLSA9YVSXi6ugmS sCpj5iSQ00HQjUgIqOe9tYTMiMvlD+Cu45CO5mLOd2AfEjUCmz/kQnmHfb+TG/gcKnWe ElVT1Kz45nk176xGWydhau5CUd4O3VCqjBbcpLHqOSjDMJhHYaDots0k/nYKzJ0Qq1+H nl8sR86KismwYUb7bq1YOi2ku+KYPPtF+C8B5awZkkuUMbEJ3/E9EGbyHqRQbyyd2oaR rT9g== X-Gm-Message-State: AJaThX6dcz/W4vij550nI38AsL6sUUXwcm41goEqwuzbhWfcFZtUcqOh O8JmEjUkgyzqryDJdaJWVyePZYV0hZ1pEIMPmug= X-Received: by 10.157.39.194 with SMTP id c60mr200828otb.435.1510230661353; Thu, 09 Nov 2017 04:31:01 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.53.27 with HTTP; Thu, 9 Nov 2017 04:31:00 -0800 (PST) In-Reply-To: References: <1510192934-5369-1-git-send-email-wanpeng.li@hotmail.com> <1510192934-5369-4-git-send-email-wanpeng.li@hotmail.com> From: Wanpeng Li Date: Thu, 9 Nov 2017 20:31:00 +0800 Message-ID: Subject: Re: [PATCH RESEND 3/3] KVM: Add flush_on_enter before guest enter To: Paolo Bonzini Cc: "linux-kernel@vger.kernel.org" , kvm , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-09 18:54 GMT+08:00 Paolo Bonzini : > On 09/11/2017 03:02, Wanpeng Li wrote: >> From: Wanpeng Li >> >> PV-Flush guest would indicate to flush on enter, flush the TLB before >> entering and exiting the guest. >> >> Cc: Paolo Bonzini >> Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 >> Signed-off-by: Wanpeng Li >> --- >> arch/x86/kvm/x86.c | 12 ++++++++++-- >> 1 file changed, 10 insertions(+), 2 deletions(-) >> >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> index 1ea28a2..f295360 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -2116,7 +2116,13 @@ static void record_steal_time(struct kvm_vcpu *vc= pu) >> &vcpu->arch.st.steal, sizeof(struct kvm_steal_time)))) >> return; >> >> - vcpu->arch.st.steal.preempted =3D KVM_VCPU_NOT_PREEMPTED; >> + if (xchg(&vcpu->arch.st.steal.preempted, KVM_VCPU_NOT_PREEMPTED) = =3D=3D >> + (KVM_VCPU_SHOULD_FLUSH | KVM_VCPU_PREEMPTED)) >> + /* >> + * Do TLB_FLUSH before entering the guest, its passed >> + * the stage of request checking >> + */ >> + kvm_x86_ops->tlb_flush(vcpu); >> >> if (vcpu->arch.st.steal.version & 1) >> vcpu->arch.st.steal.version +=3D 1; /* first time write, = random junk */ >> @@ -2887,7 +2893,9 @@ static void kvm_steal_time_set_preempted(struct kv= m_vcpu *vcpu) >> if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED)) >> return; >> >> - vcpu->arch.st.steal.preempted =3D KVM_VCPU_PREEMPTED; >> + if (xchg(&vcpu->arch.st.steal.preempted, KVM_VCPU_PREEMPTED) =3D= =3D >> + KVM_VCPU_SHOULD_FLUSH) >> + kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); > > This is not necessary. Instead, you can just OR the KVM_VCPU_PREEMPTED > bit; record_steal_time will pick up the request and do the TLB flush late= r. > > Also, I think this is a case where you should prefer INVVPID to INVEP. > That's because "execution of the INVEPT instruction invalidates > guest-physical mappings and combined mappings" while "execution of the > INVVPID instruction invalidates linear mappings and combined mappings". > In this case, invalidating guest-physical mapping is unnecessary. > > So you could add a new bool argument to kvm_x86_ops->tlb_flush. In > vmx.c, __vmx_flush_tlb can do invept if "enable_ept && (invalidate_gpa > || !enable_vpid)". Agreed. Regards, Wanpeng Li From 1583585579661550381@xxx Thu Nov 09 10:54:55 +0000 2017 X-GM-THRID: 1583551507097428689 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread