Received: by 10.223.164.202 with SMTP id h10csp1740165wrb; Thu, 16 Nov 2017 03:36:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMbj65paEL9Rl5aIhjiP2lhDnkMqMLWnaHlYWEmeX3eKlTW+lGGjQLAPriqhqjl6NkwNf5r6 X-Received: by 10.84.218.204 with SMTP id g12mr1397637plm.213.1510832178042; Thu, 16 Nov 2017 03:36:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510832178; cv=none; d=google.com; s=arc-20160816; b=qg54u4Vhs3PHNlQLmbm5vIWvRYncfoobQFQnLaeesI1pCwIIPpJ2LutQXSPonIPdxF jAyfUiOv4ySqwrsJeumvK+k63sGS5mWR2MLBHusVC+GoIP8u8Bb7sXbxBlJtRAU79OZz m0Moqj54df5rXJn/OzPmJkxtKP70Z4Qaxr8JFEL43xuSC/P2Y8MePmGVW+w88KkH1BeS UVinDYKIRSPkWefhFdTiZUQ70ftBxUvR0vm5dAcNgDgDDOKv2/tJO4PixTwzAgxEdmzQ hhRRn1ISCLRxMupvC5XjqvqbyMi2D1wCjrpnnbqNDcIj/vK2DrGtFd3zPja9YoifC136 GBdQ== 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=FqnbYHDa7RlUVjxyA95aflFmb+gXksshFljhvlCBzog=; b=c0GB+fztnQBnfZQk8jgMbep3/ztTiC1cVs6Y++L9S3EuAFcKnOF/4GBRvRp7yGLEFQ sGXvb8s0e2iyhPBMqEIFHsLgvUlQMS074hxvw5Hzy73Iqp1hOJgQ0sewhKu3TMIgKtvh aS2sLbH9hJKIcAXyk9D8pjxxEaxpgsDK7GiH4l/nHhNISuRPRLEKOK8auQz3GpNKAgrA X8khTaNhC0m7PNPMqNUosUrkClJeZkIqkddp3MoA1+6WuR1ZocrkcQKO0w23xNwk3zGD ReXdNtOksCUXp/yG1mu7bE9YIA+IikOWz1eMJ62Wz957Wsj3sddsBg8ybaX1P9rIeUFw 2Jig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qFnoF3aP; 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 k185si740109pge.131.2017.11.16.03.35.56; Thu, 16 Nov 2017 03:36:18 -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=qFnoF3aP; 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 S933660AbdKPKRm (ORCPT + 91 others); Thu, 16 Nov 2017 05:17:42 -0500 Received: from mail-ot0-f196.google.com ([74.125.82.196]:56976 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754883AbdKPKRe (ORCPT ); Thu, 16 Nov 2017 05:17:34 -0500 Received: by mail-ot0-f196.google.com with SMTP id j29so18657659oth.13; Thu, 16 Nov 2017 02:17:34 -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=FqnbYHDa7RlUVjxyA95aflFmb+gXksshFljhvlCBzog=; b=qFnoF3aPSiaSACrLX41myYKOgcmw4RMUE6jbmCF1drTysVQStp45Id4bLJDBFgKwxZ CaGP6IhASdfQ2KeAL7IPOt9eIbUjeot8Yxi+MAtOUUOHktwtDC5GC2076R5v/LUzABC+ xby/MsCGI4z2rGR2ggZYbP/iIHs/EjABRYKUaGq9Ki1c52K6MNegVlkzNmA+UlU414b2 1BTV0fnpSA2x1QD5jkIi2KOWjLYEM+bkzbY/utGqy1tmslEk6ZD4BP4rx5UdVPOgVIDD U3GZmePOsWWFx8+Km3XqI8RG/j3mfRJjfMyzyDvF9VeG284DSXKL59L5Sl7vRPdFlLnh 1bEA== 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=FqnbYHDa7RlUVjxyA95aflFmb+gXksshFljhvlCBzog=; b=N0EpIU4/4XBjsV08HXX4fWpFgCYgrmIiZ9eIygXYw8dRMriPj9laVvei3N0dxHK/DO qT0WBL3Z34xofZY2wOrQAt9WIyeVeMtdCNnUkiGy8B9O6+fifJCciXm00Xs9WEWHtQZh d/Yk3vGtgTzwcXmvbi0huTpJkeQyaJVuHHJAWJ386g3R/plBb7oGSQ7Wtbchoi5ifVph ttnNf1bbiVarYWFextxcxQOq2OovAjBC1lkIA9eHNMAFoukGTvecuqRVtEJOsk5ElhKF 5TfpC90brATCwsC6dMO0S+ernDiI14cMoEgGQSMGlO1QWZUwAis+h82ylt3PTV5QR8Jl QGjg== X-Gm-Message-State: AJaThX6fOLNqcaVxouECwTK7m7ozs8beQMt7ykeI5d+Zca+SJ7g7+bg0 AjRCVEBr3CxcF+PVDa6o9uO2nQLT048LQebwpgw= X-Received: by 10.157.52.38 with SMTP id v35mr773165otb.90.1510827453695; Thu, 16 Nov 2017 02:17:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.53.27 with HTTP; Thu, 16 Nov 2017 02:17:33 -0800 (PST) In-Reply-To: <20171115211145.GY21113@char.us.oracle.com> References: <1510567280-19376-1-git-send-email-wanpeng.li@hotmail.com> <1510567280-19376-3-git-send-email-wanpeng.li@hotmail.com> <20171115211145.GY21113@char.us.oracle.com> From: Wanpeng Li Date: Thu, 16 Nov 2017 18:17:33 +0800 Message-ID: Subject: Re: [PATCH v5 2/4] KVM: X86: Add paravirt remote TLB flush To: Konrad Rzeszutek Wilk Cc: "linux-kernel@vger.kernel.org" , kvm , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Peter Zijlstra , 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-16 5:11 GMT+08:00 Konrad Rzeszutek Wilk : > On Mon, Nov 13, 2017 at 02:01:18AM -0800, Wanpeng Li wrote: >> From: Wanpeng Li >> >> Remote flushing api's does a busy wait which is fine in bare-metal >> scenario. But with-in the guest, the vcpus might have been pre-empted >> or blocked. In this scenario, the initator vcpu would end up >> busy-waiting for a long amount of time. >> >> This patch set implements para-virt flush tlbs making sure that it does >> not wait for vcpus that are sleeping. And all the sleeping vcpus flush >> the tlb on guest enter. >> >> The best result is achieved when we're overcommiting the host by running >> multiple vCPUs on each pCPU. In this case PV tlb flush avoids touching >> vCPUs which are not scheduled and avoid the wait on the main CPU. >> >> Test on a Haswell i7 desktop 4 cores (2HT), so 8 pCPUs, running ebizzy >> in one linux guest. >> >> ebizzy -M >> vanilla optimized boost >> 8 vCPUs 10152 10083 -0.68% >> 16 vCPUs 1224 4866 297.5% >> 24 vCPUs 1109 3871 249% >> 32 vCPUs 1025 3375 229.3% >> >> Cc: Paolo Bonzini >> Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 >> Cc: Peter Zijlstra >> Signed-off-by: Wanpeng Li >> --- >> Documentation/virtual/kvm/cpuid.txt | 4 ++++ >> arch/x86/include/uapi/asm/kvm_para.h | 2 ++ >> arch/x86/kernel/kvm.c | 42 +++++++++++++++++++++++++++++= ++++++- >> 3 files changed, 47 insertions(+), 1 deletion(-) >> >> diff --git a/Documentation/virtual/kvm/cpuid.txt b/Documentation/virtual= /kvm/cpuid.txt >> index 117066a..9693fcc 100644 >> --- a/Documentation/virtual/kvm/cpuid.txt >> +++ b/Documentation/virtual/kvm/cpuid.txt >> @@ -60,6 +60,10 @@ KVM_FEATURE_PV_DEDICATED || 8 || guest = checks this feature bit >> || || mizations such as usage = of >> || || qspinlocks. >> -----------------------------------------------------------------------= ------- >> +KVM_FEATURE_PV_TLB_FLUSH || 9 || guest checks this featur= e bit >> + || || before enabling paravirt= ualized >> + || || tlb flush. >> +-----------------------------------------------------------------------= ------- >> KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no gue= st-side >> || || per-cpu warps are expect= ed in >> || || kvmclock. >> diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uap= i/asm/kvm_para.h >> index 6d66556..e267d83 100644 >> --- a/arch/x86/include/uapi/asm/kvm_para.h >> +++ b/arch/x86/include/uapi/asm/kvm_para.h >> @@ -26,6 +26,7 @@ >> #define KVM_FEATURE_PV_EOI 6 >> #define KVM_FEATURE_PV_UNHALT 7 >> #define KVM_FEATURE_PV_DEDICATED 8 >> +#define KVM_FEATURE_PV_TLB_FLUSH 9 >> >> /* The last 8 bits are used to indicate how to interpret the flags fiel= d >> * in pvclock structure. If no bits are set, all flags are ignored. >> @@ -54,6 +55,7 @@ struct kvm_steal_time { >> >> #define KVM_VCPU_NOT_PREEMPTED (0 << 0) >> #define KVM_VCPU_PREEMPTED (1 << 0) >> +#define KVM_VCPU_SHOULD_FLUSH (1 << 1) >> >> #define KVM_CLOCK_PAIRING_WALLCLOCK 0 >> struct kvm_clock_pairing { >> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c >> index 66ed3bc..78794c1 100644 >> --- a/arch/x86/kernel/kvm.c >> +++ b/arch/x86/kernel/kvm.c >> @@ -465,9 +465,40 @@ static void __init kvm_apf_trap_init(void) >> update_intr_gate(X86_TRAP_PF, async_page_fault); >> } >> >> +static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask); >> + >> +static void kvm_flush_tlb_others(const struct cpumask *cpumask, >> + const struct flush_tlb_info *info) > > Something is off there.. >> +{ >> + u8 state; >> + int cpu; >> + struct kvm_steal_time *src; >> + struct cpumask *flushmask =3D this_cpu_cpumask_var_ptr(__pv_tlb_ma= sk); >> + >> + if (unlikely(!flushmask)) >> + return; >> + >> + cpumask_copy(flushmask, cpumask); >> + /* >> + * We have to call flush only on online vCPUs. And >> + * queue flush_on_enter for pre-empted vCPUs >> + */ >> + for_each_cpu(cpu, flushmask) { >> + src =3D &per_cpu(steal_time, cpu); >> + state =3D READ_ONCE(src->preempted); >> + if ((state & KVM_VCPU_PREEMPTED)) { >> + if (try_cmpxchg(&src->preempted, &state, >> + state | KVM_VCPU_SHOULD_FLUSH)) >> + __cpumask_clear_cpu(cpu, flushmask); >> + } >> + } >> + >> + native_flush_tlb_others(flushmask, info); >> +} >> + >> void __init kvm_guest_init(void) >> { >> - int i; >> + int i, cpu; >> >> if (!kvm_para_available()) >> return; >> @@ -484,6 +515,15 @@ void __init kvm_guest_init(void) >> pv_time_ops.steal_clock =3D kvm_steal_clock; >> } >> >> + if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && >> + !kvm_para_has_feature(KVM_FEATURE_PV_DEDICATED)) { >> + for_each_possible_cpu(cpu) { >> + zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask= , cpu), >> + GFP_KERNEL, cpu_to_node(cpu)); >> + } >> + pv_mmu_ops.flush_tlb_others =3D kvm_flush_tlb_others; > > If we migrate to another host that does not expose this, should the > flush_tlb_others be reset back to the generic one? Or we don't care that > much ? > > It seems to me that we would end up copying the cpumask, then loop around= over > all the CPUs and then call native_flush_tlb_others again. Not sure if the= re > is much of performance problem there, but what is the historical way > this is handled? We just enable this feature when !PV_DEDICATED which means vCPUs overcommit, then the loop is better than waiting the other vCPUs that are sleeping. Regards, Wanpeng Li From 1584218726699184268@xxx Thu Nov 16 10:38:31 +0000 2017 X-GM-THRID: 1583909069046568739 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread