From nobody Sat Apr 27 18:09:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1577194063; cv=none; d=zohomail.com; s=zohoarc; b=m0eFDqf+kiPQLN/3XLX/Ai8WgliNrmapjMyLQk68iX4KxAHny5kXr8ScXWYWpfzwZvRqeTcmhzFSMUCK5r8G00DVpN4uVh6ttEhwCBkOy3tViB7z1Ut/gAFlRNH4wK4OdeR7OO42gwyGu4kR8GbehcS36qDQk5oSBCfetVx3CCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577194063; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DHcvlc7CxItl8+yZnVl5e+FyQXC+baah4jxnDQfce/c=; b=hMDMgbuk7gFbwCekq4maSNnCCWh96sSsylCyw4daMaFUqItB3PcIuDtWtSho3ebBbA/2UKo+oXOF3qBDFFBe9P3w+bJLay6YEHr87+SWd9YtTULCDzC1h1dvTnLMdeKQ00G8f/oPEIQPX0fYl+hdw+ISVY/f1imlAFFrfaZwQ2A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1577194059893270.2870584019124; Tue, 24 Dec 2019 05:27:39 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijkD3-0007c3-Om; Tue, 24 Dec 2019 13:26:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijkD2-0007bx-Dd for xen-devel@lists.xenproject.org; Tue, 24 Dec 2019 13:26:48 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 01d479fc-2651-11ea-a1e1-bc764e2007e4; Tue, 24 Dec 2019 13:26:35 +0000 (UTC) X-Inumbo-ID: 01d479fc-2651-11ea-a1e1-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1577193995; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ILxDEKri0JABc13Mus7DeHu3fI8SI/vl6MDDKTElL6k=; b=BzIaSZro3BFtsPyVodMlO9xXxbkqMvtCF+RiSEpjTWUeGKCs48PFDAsD zTSwDh+R8LA1I+g4l0qZONhb2OJ8BsMB7JPiflWj3l5wyp8oS8OjLX3Hj oqPe9cqOu5I0Z3H0l4SM2NNqsRcawD90JVpuuJTJQnTLQVex1pmB8cMov k=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 9BhStHHStYFRC7DMPum2rsiCs9YMpQtSOLoolAH+fbviWDlZmDuEsyVthidANrzCwhQY816dsa mFDGEjkXaPPj6xBmrUb5yqB6Lw5Z78e+V73pvEeqbQKhIgYpbUHDpZwR5OcKTnmxU2dZldac4+ XtsFOLoEQHNS7AE4tvqaRXuu/K4Vd812hvNnXjpfkgdsLCn9cMR2EInY+jIj2XrGkPM4oQFrC0 DsGqQnrvkROxGrMe8DDZUUkt9Ad6wMZ0I8hHnVb4+qC0KwDGgdzWm48l90Q3FRuAoC/hAKPB3u R48= X-SBRS: 2.7 X-MesageID: 10478268 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,351,1571716800"; d="scan'208";a="10478268" From: Roger Pau Monne To: Date: Tue, 24 Dec 2019 14:26:15 +0100 Message-ID: <20191224132616.47441-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191224132616.47441-1-roger.pau@citrix.com> References: <20191224132616.47441-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/2] x86/hvm: improve performance of HVMOP_flush_tlbs X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) There's no need to call paging_update_cr3 unless CR3 trapping is enabled, and that's only the case when using shadow paging or when requested for introspection purposes, otherwise there's no need to pause all the vCPUs of the domain in order to perform the flush. Check whether CR3 trapping is currently in use in order to decide whether the vCPUs should be paused, otherwise just perform the flush. Signed-off-by: Roger Pau Monn=C3=A9 --- xen/arch/x86/hvm/hvm.c | 55 ++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 4dfaf35566..7dcc16afc6 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3985,25 +3985,36 @@ bool hvm_flush_vcpu_tlb(bool (*flush_vcpu)(void *ct= xt, struct vcpu *v), static DEFINE_PER_CPU(cpumask_t, flush_cpumask); cpumask_t *mask =3D &this_cpu(flush_cpumask); struct domain *d =3D current->domain; + /* + * CR3 trapping is only enabled when running with shadow paging or when + * requested for introspection purposes, otherwise there's no need to = call + * paging_update_cr3 and hence pause all vCPUs. + */ + bool trap_cr3 =3D !paging_mode_hap(d) || + (d->arch.monitor.write_ctrlreg_enabled & + monitor_ctrlreg_bitmask(VM_EVENT_X86_CR3)); struct vcpu *v; =20 - /* Avoid deadlock if more than one vcpu tries this at the same time. */ - if ( !spin_trylock(&d->hypercall_deadlock_mutex) ) - return false; + if ( trap_cr3 ) + { + /* Avoid deadlock if more than one vcpu tries this at the same tim= e. */ + if ( !spin_trylock(&d->hypercall_deadlock_mutex) ) + return false; =20 - /* Pause all other vcpus. */ - for_each_vcpu ( d, v ) - if ( v !=3D current && flush_vcpu(ctxt, v) ) - vcpu_pause_nosync(v); + /* Pause all other vcpus. */ + for_each_vcpu ( d, v ) + if ( v !=3D current && flush_vcpu(ctxt, v) ) + vcpu_pause_nosync(v); =20 - /* Now that all VCPUs are signalled to deschedule, we wait... */ - for_each_vcpu ( d, v ) - if ( v !=3D current && flush_vcpu(ctxt, v) ) - while ( !vcpu_runnable(v) && v->is_running ) - cpu_relax(); + /* Now that all VCPUs are signalled to deschedule, we wait... */ + for_each_vcpu ( d, v ) + if ( v !=3D current && flush_vcpu(ctxt, v) ) + while ( !vcpu_runnable(v) && v->is_running ) + cpu_relax(); =20 - /* All other vcpus are paused, safe to unlock now. */ - spin_unlock(&d->hypercall_deadlock_mutex); + /* All other vcpus are paused, safe to unlock now. */ + spin_unlock(&d->hypercall_deadlock_mutex); + } =20 cpumask_clear(mask); =20 @@ -4015,8 +4026,15 @@ bool hvm_flush_vcpu_tlb(bool (*flush_vcpu)(void *ctx= t, struct vcpu *v), if ( !flush_vcpu(ctxt, v) ) continue; =20 - paging_update_cr3(v, false); + if ( trap_cr3 ) + paging_update_cr3(v, false); =20 + /* + * It's correct to do this flush without pausing the vCPUs: any vC= PU + * context switch will already flush the tlb and the worse that co= uld + * happen is that Xen ends up performing flushes on pCPUs that are= no + * longer running the target vCPUs. + */ cpu =3D read_atomic(&v->dirty_cpu); if ( is_vcpu_dirty_cpu(cpu) ) __cpumask_set_cpu(cpu, mask); @@ -4026,9 +4044,10 @@ bool hvm_flush_vcpu_tlb(bool (*flush_vcpu)(void *ctx= t, struct vcpu *v), flush_tlb_mask(mask); =20 /* Done. */ - for_each_vcpu ( d, v ) - if ( v !=3D current && flush_vcpu(ctxt, v) ) - vcpu_unpause(v); + if ( trap_cr3 ) + for_each_vcpu ( d, v ) + if ( v !=3D current && flush_vcpu(ctxt, v) ) + vcpu_unpause(v); =20 return true; } --=20 2.24.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat Apr 27 18:09:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1577194056; cv=none; d=zohomail.com; s=zohoarc; b=dj2k0sj0PsXdKWpba/wuJDnBPgT2kBYoqJAPQgMwK75GZHdGa/g5h5ZkD5xJ3SnbuY7o7SsZDoobUwmEyp0fT1akWjl1dAkXShD4WkxH4ifcVlybUrrh0WckRsbrtx116v6urTsohcVleyodZyH2b8Fbjly+C/RSYdy38AfBgZg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577194056; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2lE79GW0mD0Ic6Q2/F3JBDc0E/wSJqiUbzcvR2CNeIY=; b=UOrjS35YQ5ZS+csvCtiwJcXdeAbbLdLPEYK9HIx+nx+bE1Mt22dBQ9VJtkYcD9DhLgqc3SxMByy51NaMYPqTVvPx1HaAVXzvt2oP52TQwtu95aQXKF12vdTJGZMLsxeGIgNDkdn9XZJdgsu5liXiI3eKlqXkJ5vwUxeb8p0ejRA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1577194056850952.1925234150183; Tue, 24 Dec 2019 05:27:36 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijkD5-0007cJ-2X; Tue, 24 Dec 2019 13:26:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijkD4-0007c7-2M for xen-devel@lists.xenproject.org; Tue, 24 Dec 2019 13:26:50 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 09474ce6-2651-11ea-97c0-12813bfff9fa; Tue, 24 Dec 2019 13:26:48 +0000 (UTC) X-Inumbo-ID: 09474ce6-2651-11ea-97c0-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1577194009; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ICSVxRlJuO1oJkbo5+46yIpxwXSyE7neSx5HbBCtE0M=; b=HGFqYMRshsa93Pdo+orv7qDw2XjTGxyMtKf8tDD1W+0ODY+0KbhmROra V+LH5HamguQihk+A2TL5z9Io1GlXT+TQ6Y+zte6rn608WDaFzM9ABeQvi TxYlTqYYnQyViwJ00iYb3uykqAjdo0Ce41OOZZMbSjxu76kqqE7znBdMC U=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 8IC11BcHavp+duOeqZGHkwrIFkfknOI3tEbPk1D9HN58GdGLqaJ1GsVmTmGmHs05whJ/HyUj2z ugoOkCVvwoEmvNj7STisJY/I4TBXSR3H1YBrspL4Gs+aiUgPNat5NEAjNaKrsJJS5YitgFTmbY hENcBVOPutrqHoD1b8cm9APGO1+kPJdt5XRnodpGeXQZigIbuomA1EK6RXdtQRiRj8BvHkEUbg WWuW9/nkmdPTqMwFqHfYICLeA0hPr868TMkt8b+dSYakGdMkBRRyYG0foBwXQocw4DA1DJhlJZ f5Y= X-SBRS: 2.7 X-MesageID: 10124154 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,351,1571716800"; d="scan'208";a="10124154" From: Roger Pau Monne To: Date: Tue, 24 Dec 2019 14:26:16 +0100 Message-ID: <20191224132616.47441-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191224132616.47441-1-roger.pau@citrix.com> References: <20191224132616.47441-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/2] x86/tlb: use Xen L0 assisted TLB flush when available X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Use Xen's L0 HVMOP_flush_tlbs hypercall when available in order to perform flushes. This greatly increases the performance of tlb flushes when running with a high amount of vCPUs as a Xen guest, and is specially important when running in shim mode. The following figures are from a PV guest running `make -j342 xen` in shim mode with 32 vCPUs. Using x2APIC and ALLBUT shorthand: real 4m35.973s user 4m35.110s sys 36m24.117s Using L0 assisted flush: real 1m17.391s user 4m42.413s sys 6m20.773s Signed-off-by: Roger Pau Monn=C3=A9 --- xen/arch/x86/guest/xen/xen.c | 11 +++++++++++ xen/arch/x86/smp.c | 6 ++++++ xen/include/asm-x86/guest/xen.h | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index 6dbc5f953f..e6493caecf 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -281,6 +281,17 @@ int xg_free_unused_page(mfn_t mfn) return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn)); } =20 +int xg_flush_tlbs(void) +{ + int rc; + + do { + rc =3D xen_hypercall_hvm_op(HVMOP_flush_tlbs, NULL); + } while ( rc =3D=3D -ERESTART ); + + return rc; +} + static void ap_resume(void *unused) { map_vcpuinfo(); diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c index 427c33db9d..a892db28c1 100644 --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -235,6 +236,11 @@ void flush_area_mask(const cpumask_t *mask, const void= *va, unsigned int flags) { bool cpus_locked =3D false; =20 + if ( xen_guest && + !(flags & ~(FLUSH_TLB | FLUSH_TLB_GLOBAL | FLUSH_VA_VALID)) && + !xg_flush_tlbs() ) + return; + spin_lock(&flush_lock); cpumask_and(&flush_cpumask, mask, &cpu_online_map); cpumask_clear_cpu(cpu, &flush_cpumask); diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xe= n.h index 2042a9a0c2..f0de9e4d71 100644 --- a/xen/include/asm-x86/guest/xen.h +++ b/xen/include/asm-x86/guest/xen.h @@ -36,6 +36,7 @@ extern uint32_t xen_cpuid_base; const struct hypervisor_ops *xg_probe(void); int xg_alloc_unused_page(mfn_t *mfn); int xg_free_unused_page(mfn_t mfn); +int xg_flush_tlbs(void); =20 DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); @@ -47,6 +48,12 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); =20 static inline const struct hypervisor_ops *xg_probe(void) { return NULL; } =20 +static inline int xg_flush_tlbs(void) +{ + ASSERT_UNREACHABLE(); + return -ENOSYS; +} + #endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */ =20 --=20 2.24.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel