Received: by 10.223.164.202 with SMTP id h10csp174959wrb; Mon, 13 Nov 2017 22:47:08 -0800 (PST) X-Google-Smtp-Source: AGs4zMZaIFo9d3njB6X/49BPD6eMe0YWH3YhjeLeRDz3jsvy5pKK3XO8ymMmbUrZLg/reMgHRV16 X-Received: by 10.98.133.65 with SMTP id u62mr4914246pfd.22.1510642028111; Mon, 13 Nov 2017 22:47:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510642028; cv=none; d=google.com; s=arc-20160816; b=l3Nl5QAsqlDJNVgdcHsFwR0nnWOsZgc9MOHsmEMrjIYyn5ZUeo8gaPnLCtl7gQfU9z lHmxnb3cco/lVCjDZcqc/xJl+5osXZW5Wg79haBWKcgYH2T4HXatC2YH159cFqV6sT5p XY14Ei/SROWj538Ak944anxmqqA8dQvPJe6hD7n/lvhcxPYUqYjTbfziKerPa12S26dH bv1OXX54zeR2HBvbosGggFG6Dh/j+RdvVlykVfeX4wQj1gizfJ2L92Y9lPMOrNt5g/9H O8hhiiYNFC5AIVdrxLqjGjCuTwEOYfb17sq3fIxMdi9W5r6CZoRbEKpFtl/A60EQeBAe PK6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ZLMQQ9JxQgQ2or49w1KevxH10DLj8V/BoqLmkLBtYwM=; b=g3pXxKqJjeWt0rkfrQMkmTnCPItjpqHB8fYDNQYae+jo3fnIPkYouNcbeqfgoQmRXS 3kRsy+KEKmIam3+rrCgbPIZiE2uimnvk2A++xW38pAoMl73X6pA0SoWvmQW061+1WSkn jIu1d5L02KVKth+R7hmzjTI1ta/euHe2qbMDVxQ5hbDqPE41OwQ0DHrdKFIChA11zntb esxghJ5QYmQ3DyF8cs3zf9qfGUsbzUmH9Rb+hKssSjRehrjgpW3Y9cHnlHp9i2a2CCuC WKmgz3bOVKbo/0byZZWrS0ZFnIFdk/d4X+gblemce/xJWrm4Wp91C1sfdHn1Zvf8Gxka X/lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ME9vbOcR; 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 n10si15422035pgc.350.2017.11.13.22.46.55; Mon, 13 Nov 2017 22:47:08 -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=ME9vbOcR; 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 S1752067AbdKNG3G (ORCPT + 89 others); Tue, 14 Nov 2017 01:29:06 -0500 Received: from mail-ot0-f194.google.com ([74.125.82.194]:44418 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750824AbdKNG26 (ORCPT ); Tue, 14 Nov 2017 01:28:58 -0500 Received: by mail-ot0-f194.google.com with SMTP id o23so4927339otd.1; Mon, 13 Nov 2017 22:28:58 -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; bh=ZLMQQ9JxQgQ2or49w1KevxH10DLj8V/BoqLmkLBtYwM=; b=ME9vbOcRMeC7H819/hJenXjXELZV7nBTgPX0kvdQcUF1TAQ9+UJcNi9ac5BwecpO+S 5ynLBagu3E2gBWE5M4wxjH3/a3jI+eHoqRlDAVZjiXf2wYTVLwVhjWuqc1M1z634agvw cxdoL05YzcxOgRaRJZZHCAjuP2KEtumNYMlO/Lp4V2Znij1w4JNa5D/70lke4QC3HxqV yIyi14JHT72FodW6bN455uYIGocCSyyNFFiy1zIjg089p+UVV+WlYGBtjyYqG8gzezEp 5gK6yyjurxp7nvHBnEvrIw5r8oqxmwKfq8kbi/0Wr+5NcE42KZTCHpr6DfdYkTCtHwhf lD0A== 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; bh=ZLMQQ9JxQgQ2or49w1KevxH10DLj8V/BoqLmkLBtYwM=; b=YBi4zi7Kzk3LVzvskWX1G4jPUDTGjRXkOwEItQwj1r3NuK6sBWR2Yn1Ti1WDy7/Qv/ rFatencIAJlnztItBQDeWilKg4+CNwU2frAcW+cwa7hd4KzdQkSqWPb32Csh0aehxokG uoh9OXxsD6hBqvsGirPUoYVZg7oemifM85jCpp8qQQEj0LQlThCqgpqY4j+iUAWbqaEZ JCtDf4gwkLCxGfXHka7PUTY02ETtYNh1G5rzRHXvyyuMyDFxIQh49XUFxjgcg1fFREFx REKHDb6j9cG7UHputEmuw8q47+bsJzCu0zPXnUwOphs/yYvhsCKU0ZoRRVlUJG/sZN+a VYCg== X-Gm-Message-State: AJaThX7huHcG98phOAUo7YBklP1wum2mm4ws5S28/uTOUeqCBXlu7GZt eV/U+Y8Bt4sq8P78pDYheFc78zRzov+D2iLySs8= X-Received: by 10.157.42.233 with SMTP id e96mr6094909otb.375.1510640937723; Mon, 13 Nov 2017 22:28:57 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.53.27 with HTTP; Mon, 13 Nov 2017 22:28:56 -0800 (PST) In-Reply-To: <20171113104634.62cmjalnj73scfnl@hirez.programming.kicks-ass.net> References: <1510533206-9821-1-git-send-email-wanpeng.li@hotmail.com> <1510533206-9821-3-git-send-email-wanpeng.li@hotmail.com> <20171113080403.ici7nt5r4b5fpxa6@hirez.programming.kicks-ass.net> <20171113104634.62cmjalnj73scfnl@hirez.programming.kicks-ass.net> From: Wanpeng Li Date: Tue, 14 Nov 2017 14:28:56 +0800 Message-ID: Subject: Re: [PATCH v4 2/4] KVM: X86: Add paravirt remote TLB flush To: Peter Zijlstra Cc: "linux-kernel@vger.kernel.org" , kvm , Paolo Bonzini , "Radim Kr??m????" , Wanpeng Li Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-13 18:46 GMT+08:00 Peter Zijlstra : > On Mon, Nov 13, 2017 at 04:26:57PM +0800, Wanpeng Li wrote: >> 2017-11-13 16:04 GMT+08:00 Peter Zijlstra : > >> > So if at this point a vCPU gets preempted we'll still spin-wait for it, >> > which is sub-optimal. >> > >> > I think we can come up with something to get around that 'problem' if >> > indeed it is a problem. But we can easily do that as follow up patches. >> > Just let me know if you think its worth spending more time on. >> >> You can post your idea, it is always smart. :) Then we can evaluate >> the complexity and gains. > > I'm not sure I have a fully baked idea just yet, but the general idea > would be something like: > > - switch (back) to a dedicated TLB invalidate IPI > > - introduce KVM_VCPU_IPI_PENDING > > - change flush_tlb_others() into something like: > > for_each_cpu(cpu, flushmask) { > src = &per_cpu(steal_time, cpu); > state = READ_ONCE(src->preempted); > do { > if (state & KVM_VCPU_PREEMPTED) { > if (try_cmpxchg(&src->preempted, &state, > state | KVM_VCPU_SHOULD_FLUSH)) { > __cpumask_clear_cpu(cpu, flushmask); > break; > } > } > } while (!try_cmpxchg(&src->preempted, &state, > state | KVM_VCPU_IPI_PENDING)); > } > > apic->send_IPI_mask(flushmask, CALL_TLB_VECTOR); > > for_each_cpu(cpu, flushmask) { > src = &per_cpu(steal_time, cpu); > smp_cond_load_acquire(&src->preempted, !(VAL & KVM_VCPU_IPI_PENDING); > } > > > - have the TLB invalidate handler do something like: > > state = READ_ONCE(src->preempted); > if (!(state & KVM_VCPU_IPI_PENDING)) > return; > > local_flush_tlb(); > > do { > } while (!try_cmpxchg(&src->preempted, &state, > state & ~KVM_VCPU_IPI_PENDING)); There are a lot of cases handled by flush_tlb_func_remote() -> flush_tlb_function_common(), so I'm afraid to have hole. Regards, Wanpeng Li > > - then at VMEXIT time do something like: > > state = READ_ONCE(src->preempted); > do { > if (!(state & KVM_VCPU_IPI_PENDING)) > break; > } while (!try_cmpxchg(&src->preempted, state, > (state & ~KVM_VCPU_IPI_PENDING) | > KVM_VCPU_SHOULD_FLUSH)); > > and clear any possible pending TLB_VECTOR in the guest state to avoid > raising that IPI spuriously on enter again. > > > This way the preemption will clear the IPI_PENDING and the > flush_others() wait loop will terminate. From 1584020853795060032@xxx Tue Nov 14 06:13:24 +0000 2017 X-GM-THRID: 1583909069046568739 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread