From nobody Thu May 9 11:00:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1573529749; cv=none; d=zoho.com; s=zohoarc; b=N/RYEF6giQmHbNNk3lwQZF2zcgh8RGRerPEix76VMRYIjPCatoQbE8RiWgqDknCNutP7waBGp/3P3R6xl89j9uus7KfGZiErdkE6BSbJQ501obLZehP+1Ql1sTKvXLew0qLXLfBguc17dWA1XqSpzBKMAona9htfxvKleYkkzKM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573529749; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=RjB3o0NjWZXINNESvPz4COiSojg7wROs/y6CgxKZ/Pw=; b=RcCHgU6d3x/tBkIN0jJFcFVHMlUNmmmgWGnylYYFdSpAvFZTCGabMH/5Jl8bphiuqYvnnDPuYLX9RFsEs40bYTWmXtytw3GjjFOeqjfBgylF7PAlM4V6bglZseBM1OkSHMUXOBWIHkhmqAm9+/kKssUgCAk+pKn3FF9PORje4FQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157352974939826.163333654700182; Mon, 11 Nov 2019 19:35:49 -0800 (PST) Received: from localhost ([::1]:58892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUMxv-0001px-E4 for importer@patchew.org; Mon, 11 Nov 2019 22:35:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43542) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUMxE-0001KY-R8 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 22:34:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUMxD-0005vl-KT for qemu-devel@nongnu.org; Mon, 11 Nov 2019 22:34:56 -0500 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:34749) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iUMxD-0005vC-Cr for qemu-devel@nongnu.org; Mon, 11 Nov 2019 22:34:55 -0500 Received: by mail-pg1-x543.google.com with SMTP id z188so4967697pgb.1 for ; Mon, 11 Nov 2019 19:34:55 -0800 (PST) Received: from localhost.corp.microsoft.com ([167.220.255.5]) by smtp.googlemail.com with ESMTPSA id f5sm114018pjp.1.2019.11.11.19.34.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Nov 2019 19:34:53 -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; bh=RjB3o0NjWZXINNESvPz4COiSojg7wROs/y6CgxKZ/Pw=; b=Ar5AXk2psvjukJXi6gdH+xtvXmPp9uIXKwTYX28+pv4edMenYVt2Q9cSx6Sir1B8To U/Mp7UNwz4u9P6dJcQtjMhdBxKtaekycaC+pbD1ure7q3xluNVB4AY694Wdw5hhbXVnj LCOw7QFIpSTm4GC9WPrTKXscJfsQ5h8EPGAgNsqrxdBSfO9qYez338FgkBWHcDsFytET 4/fJcb2Qp8DPFg75MLd5Ed36cVo8VjZ3GhwtHY9VWQHzYNHgzp95trzk4oApjEOf1+Sv GdWYuiYl0LWZalpZUzwibW2heGA4Ks6Bn4tUENTyBrSlyKKZ4H+7oZX0er/id3Ug2alL KMqw== 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; bh=RjB3o0NjWZXINNESvPz4COiSojg7wROs/y6CgxKZ/Pw=; b=A1NdleHDwT5Pccw35edVBk6peafY+4ZmvVTAJeBSh8dzi3wg8BeDDFyjyPWh3HRTsd qJEU8ZvcQoSQnPrp2TI1SsxHIWCQywhVek17MWq3JkCVPKbGQnvlUYmSuxLt2Fu+28sS 01T2v9puAx/HpyfDOca/qtbovuevZdsroiMs4kdpejWbNX5hY/8DADrmpPrTdbXiw3l4 SVOZKzoABW8oFgbL/fFjsVGXN8DxVa+4xUvld5ZDrpFwaKC2Rp4Lx7bufUIiTLVkqQXP DDBw0ooLhdv6gZOGQAJV6or/3w3QKMAyjx4Keju6YSqUAZMcu8d27g0t/3ydSgAyr6g6 aH8A== X-Gm-Message-State: APjAAAVWrxvxzoP8oU78XnYIifbdsH3kNv0kGRMGIVRs7wAy7k0voaY6 pbVmXkXoZJRVLLf3O5ekhuA= X-Google-Smtp-Source: APXvYqxm3G75qyaUjRQQIkPwyZGO7sh/u2z8W5LqAbtVsVJkIsjXh8sN7kIATp92EqxAESEhDElMYQ== X-Received: by 2002:a65:46c1:: with SMTP id n1mr11037437pgr.257.1573529693925; Mon, 11 Nov 2019 19:34:53 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com To: pbonzini@redhat.com, rth@twiddle.net, ehabkost@redhat.com, mtosatti@redhat.com, rkagan@virtuozzo.com, vkuznets@redhat.com Subject: [PATCH V4] target/i386/kvm: Add Hyper-V direct tlb flush support Date: Tue, 12 Nov 2019 11:34:27 +0800 Message-Id: <20191112033427.7204-1-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.5 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tianyu Lan , qemu-devel@nongnu.org, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Tianyu Lan Hyper-V direct tlb flush targets KVM on Hyper-V guest. Enable direct TLB flush for its guests meaning that TLB flush hypercalls are handled by Level 0 hypervisor (Hyper-V) bypassing KVM in Level 1. Due to the different ABI for hypercall parameters between Hyper-V and KVM, KVM capabilities should be hidden when enable Hyper-V direct tlb flush otherwise KVM hypercalls may be intercepted by Hyper-V. Add new parameter "hv-direct-tlbflush". Check expose_kvm and Hyper-V tlb flush capability status before enabling the feature. Signed-off-by: Tianyu Lan Reviewed-by: Roman Kagan --- Change since v3: - Fix logic of Hyper-V passthrough mode with direct tlb flush. Change sicne v2: - Update new feature description and name. - Change failure print log. Change since v1: - Add direct tlb flush's Hyper-V property and use hv_cpuid_check_and_set() to check the dependency of tlbflush feature. - Make new feature work with Hyper-V passthrough mode. --- docs/hyperv.txt | 10 ++++++++++ target/i386/cpu.c | 2 ++ target/i386/cpu.h | 1 + target/i386/kvm.c | 24 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index 8fdf25c829..140a5c7e44 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -184,6 +184,16 @@ enabled. =20 Requires: hv-vpindex, hv-synic, hv-time, hv-stimer =20 +3.18. hv-direct-tlbflush +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Enable direct TLB flush for KVM when it is running as a nested +hypervisor on top Hyper-V. When enabled, TLB flush hypercalls from L2 +guests are being passed through to L0 (Hyper-V) for handling. Due to ABI +differences between Hyper-V and KVM hypercalls, L2 guests will not be +able to issue KVM hypercalls (as those could be mishanled by L0 +Hyper-V), this requires KVM hypervisor signature to be hidden. + +Requires: hv-tlbflush, -kvm =20 4. Development features =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 44f1bbdcac..7bc7fee512 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6156,6 +6156,8 @@ static Property x86_cpu_properties[] =3D { HYPERV_FEAT_IPI, 0), DEFINE_PROP_BIT64("hv-stimer-direct", X86CPU, hyperv_features, HYPERV_FEAT_STIMER_DIRECT, 0), + DEFINE_PROP_BIT64("hv-direct-tlbflush", X86CPU, hyperv_features, + HYPERV_FEAT_DIRECT_TLBFLUSH, 0), DEFINE_PROP_BOOL("hv-passthrough", X86CPU, hyperv_passthrough, false), =20 DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index eaa5395aa5..3cb105f7d6 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -907,6 +907,7 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; #define HYPERV_FEAT_EVMCS 12 #define HYPERV_FEAT_IPI 13 #define HYPERV_FEAT_STIMER_DIRECT 14 +#define HYPERV_FEAT_DIRECT_TLBFLUSH 15 =20 #ifndef HYPERV_SPINLOCK_NEVER_RETRY #define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 11b9c854b5..43f5cbc3f6 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -900,6 +900,10 @@ static struct { }, .dependencies =3D BIT(HYPERV_FEAT_STIMER) }, + [HYPERV_FEAT_DIRECT_TLBFLUSH] =3D { + .desc =3D "direct paravirtualized TLB flush (hv-direct-tlbflush)", + .dependencies =3D BIT(HYPERV_FEAT_TLBFLUSH) + }, }; =20 static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max) @@ -1224,6 +1228,7 @@ static int hyperv_handle_properties(CPUState *cs, r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_EVMCS); r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_IPI); r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_STIMER_DIRECT); + r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_DIRECT_TLBFLUSH); =20 /* Additional dependencies not covered by kvm_hyperv_properties[] */ if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) && @@ -1243,6 +1248,25 @@ static int hyperv_handle_properties(CPUState *cs, goto free; } =20 + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_DIRECT_TLBFLUSH)) { + if (kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_DIRECT_TLBFLUSH, 0, 0))= { + if (!cpu->hyperv_passthrough) { + fprintf(stderr, + "Hyper-V %s is not supported by kernel\n", + kvm_hyperv_properties[HYPERV_FEAT_DIRECT_TLBFLUSH].des= c); + return -ENOSYS; + } + + cpu->hyperv_features &=3D ~BIT(HYPERV_FEAT_DIRECT_TLBFLUSH); + } else if (cpu->expose_kvm) { + fprintf(stderr, + "Hyper-V %s requires KVM hypervisor signature " + "to be hidden (-kvm).\n", + kvm_hyperv_properties[HYPERV_FEAT_DIRECT_TLBFLUSH].desc); + return -ENOSYS; + } + } + if (cpu->hyperv_passthrough) { /* We already copied all feature words from KVM as is */ r =3D cpuid->nent; --=20 2.14.5