Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5532331ybl; Tue, 27 Aug 2019 06:12:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxtLu3l+1aJijMxCxQ79K5P5oHKqyjOyvolVRvpCUifzbm0zvqgugGtTeiaha0rmqzHMwmG X-Received: by 2002:a65:43c2:: with SMTP id n2mr21395581pgp.110.1566911521628; Tue, 27 Aug 2019 06:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566911521; cv=none; d=google.com; s=arc-20160816; b=PY5m5tM44N89HhnO3hnXIv8ykMIgQw3US4PJ+VIRr12ptpnT/GLlas0aqhoFi8ROXJ 12CUq9vdiGbS/2r6GcVPzILcs9hbqXXBEqSeAC2pq860gzhEDSEYKob3iRTjv/7DJGph DP4zpILU91EeGJYKHTtvXh4xdBghTqhLHmquZUSm0wfZtiuT6hdzFgqpN5Txzoq636QU aBZ+WhOjEdVJqAbLtdNkcviss08cDKm5Oj9awgWYLKmXPvaEzX5R7kqzyUBD3jmaa7qw GtU+OIRDNjRTUEm6EE1/AQQ7EGI6Prd2xSeniarAu81G/yTgmeEfec38FpMa9wI9bgZY 5IDg== 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 :in-reply-to:references:mime-version:dkim-signature; bh=0p0/hlezeGt/XbIcoNDfHR/8GDIxHTpZEoMAoi00kVo=; b=WnWCcg2b3XC3MiDw0SSiUBm170Wh2PKGYPr/emtPGxERpa/ZMGPWO7UQEPdRgTELPI 9jlic3d46EFaTxYPzxaP/exN7t+6zKYXYoepMtgLe/2vf6hUFsurWBySFIAtz1iXDkPu IIIpeCcNqDfk0WBD77Y6P9AtCG4h9YH6APPoEcr7lP77AtQ3a6capyPVqhtHRjs5spfK jAjyNvP91HqW6EnglarJHrskuGczHNZsc2aIxSRxhfv5b8RbJpjQBDV4HXEtl08fzvyr wpBIiXb4l3yL6/Yevu2xmMsEIXTgZBeO622kLz+KnMZ9PtnBX94fSrTc/eI0rLi40+Ak Fe/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lwwkBmUD; 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=QUARANTINE 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 j4si2664879pjt.9.2019.08.27.06.11.46; Tue, 27 Aug 2019 06:12:01 -0700 (PDT) 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=lwwkBmUD; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730001AbfH0NHn (ORCPT + 99 others); Tue, 27 Aug 2019 09:07:43 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:47058 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729770AbfH0NHm (ORCPT ); Tue, 27 Aug 2019 09:07:42 -0400 Received: by mail-pf1-f193.google.com with SMTP id q139so14072552pfc.13; Tue, 27 Aug 2019 06:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0p0/hlezeGt/XbIcoNDfHR/8GDIxHTpZEoMAoi00kVo=; b=lwwkBmUDxvrSWCOKfQtDd9u6cFOILblaRkNEidKKOyHtBc3Y4yvbvqiAfXUh9n5TxK tBQqsvPhhXlqFv27/EfIqNoSw+t2qirVwqVRtLAvq0fTNWgjVVVvpyrXZdxiFJ9WpKsN 0eA/xKIyBetTXLQg2hSC39JBJi0wrpM9HJzX+VU62MNye6pZ3X0t0ExlRrwAQRbZZG01 v7RWCShBtjCUsTu62FtRb/YPo3PP+tpoiJ+AwqTFC06wZfVgr7UXghWE6YBz6A4j1krm 7Rdq7VXhwciuSiWFHQzdrNjspRnGxpIR21uJHy30f2gDBWemnvnx6etM25pY7UzXQZ31 hoPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0p0/hlezeGt/XbIcoNDfHR/8GDIxHTpZEoMAoi00kVo=; b=LWkXurlSpoNv23QWUS1DWgnFYto4noncFRsADRe5hTzemz12+eIAzgjzS51uw0ppfJ V9e4DXv3K9npEOfPlAb5MI7p2Dy9nsk/N91ujPyhs1RbJCtLh8327arjXQB8UF3+1rHK 16SmKSG0qZPoeKxUgbeGEbNYIDriJ38Ad7BrRH1GINMvwK+2tK5K2MQV+Hr+X7Mpmwwr jk1JG9iUc19mvXsM9dviASRdDaseDNQUciMgttE553QK3aB1z9bHRWvIxfHEot0DFR8m kFSpSuPHcgjYhTsImGve3yK2yxxIDTfI4+saUzHtY9vUsNfBqHXiHmGU4kSd1WNd0N1Z /cqw== X-Gm-Message-State: APjAAAU6xf/BAT4DJjH4ifHxkinnp0T7xpskV5woE8lGU5xcwcLFCcPB ObJ02Foy5A+WI3NFL8OBSWFZSG80f7ozv0sJgw8= X-Received: by 2002:a62:8343:: with SMTP id h64mr24990152pfe.170.1566911262160; Tue, 27 Aug 2019 06:07:42 -0700 (PDT) MIME-Version: 1.0 References: <20190819131737.26942-1-Tianyu.Lan@microsoft.com> <87ftlnm7o8.fsf@vitty.brq.redhat.com> <87v9uilr5x.fsf@vitty.brq.redhat.com> In-Reply-To: <87v9uilr5x.fsf@vitty.brq.redhat.com> From: Tianyu Lan Date: Tue, 27 Aug 2019 21:07:32 +0800 Message-ID: Subject: Re: [PATCH V3 0/3] KVM/Hyper-V: Add Hyper-V direct tlb flush support To: Vitaly Kuznetsov Cc: Tianyu Lan , kvm , linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, "linux-kernel@vger kernel org" , Paolo Bonzini , Radim Krcmar , corbet@lwn.net, KY Srinivasan , Haiyang Zhang , Stephen Hemminger , Sasha Levin , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "the arch/x86 maintainers" , michael.h.kelley@microsoft.com 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 On Tue, Aug 27, 2019 at 8:38 PM Vitaly Kuznetsov wrote: > > Tianyu Lan writes: > > > On Tue, Aug 27, 2019 at 2:41 PM Vitaly Kuznetsov wrote: > >> > >> lantianyu1986@gmail.com writes: > >> > >> > From: Tianyu Lan > >> > > >> > This patchset is to add Hyper-V direct tlb support in KVM. Hyper-V > >> > in L0 can delegate L1 hypervisor to handle tlb flush request from > >> > L2 guest when direct tlb flush is enabled in L1. > >> > > >> > Patch 2 introduces new cap KVM_CAP_HYPERV_DIRECT_TLBFLUSH to enable > >> > feature from user space. User space should enable this feature only > >> > when Hyper-V hypervisor capability is exposed to guest and KVM profile > >> > is hided. There is a parameter conflict between KVM and Hyper-V hypercall. > >> > We hope L2 guest doesn't use KVM hypercall when the feature is > >> > enabled. Detail please see comment of new API > >> > "KVM_CAP_HYPERV_DIRECT_TLBFLUSH" > >> > >> I was thinking about this for awhile and I think I have a better > >> proposal. Instead of adding this new capability let's enable direct TLB > >> flush when KVM guest enables Hyper-V Hypercall page (writes to > >> HV_X64_MSR_HYPERCALL) - this guarantees that the guest doesn't need KVM > >> hypercalls as we can't handle both KVM-style and Hyper-V-style > >> hypercalls simultaneously and kvm_emulate_hypercall() does: > >> > >> if (kvm_hv_hypercall_enabled(vcpu->kvm)) > >> return kvm_hv_hypercall(vcpu); > >> > >> What do you think? > >> > >> (and instead of adding the capability we can add kvm.ko module parameter > >> to enable direct tlb flush unconditionally, like > >> 'hv_direct_tlbflush=-1/0/1' with '-1' being the default (autoselect > >> based on Hyper-V hypercall enablement, '0' - permanently disabled, '1' - > >> permanenetly enabled)). > >> > > > > Hi Vitaly:: > > Actually, I had such idea before. But user space should check > > whether hv tlb flush > > is exposed to VM before enabling direct tlb flush. If no, user space > > should not direct > > tlb flush for guest since Hyper-V will do more check for each > > hypercall from nested > > VM with enabling the feauter.. > > If TLB Flush enlightenment is not exposed to the VM at all there's no > difference if we enable direct TLB flush in eVMCS or not: the guest > won't be using 'TLB Flush' hypercall and will do TLB flushing with > IPIs. And, in case the guest enables Hyper-V hypercall page, it is > definitelly not going to use KVM hypercalls so we can't break these. > Yes, this won't tigger KVM/Hyper-V hypercall conflict. My point is that if tlb flush enlightenment is not enabled, enabling direct tlb flush will not accelate anything and Hyper-V still will check each hypercalls from nested VM in order to intercpt tlb flush hypercall But guest won't use tlb flush hypercall in this case. The check of each hypercall in Hyper-V is redundant. We may avoid the overhead via checking status of tlb flush enlightenment and just enable direct tlb flush when it's enabled. --- Best regards Tianyu Lan