From patchwork Thu May 2 14:35:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10926987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF63A1398 for ; Thu, 2 May 2019 14:37:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD7F0284DA for ; Thu, 2 May 2019 14:37:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C162528511; Thu, 2 May 2019 14:37:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5317A284DA for ; Thu, 2 May 2019 14:37:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hMCoE-00041g-P8; Thu, 02 May 2019 14:35:38 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hMCoE-00041b-8g for xen-devel@lists.xenproject.org; Thu, 02 May 2019 14:35:38 +0000 X-Inumbo-ID: 8cbf395c-6ce7-11e9-843c-bc764e045a96 Received: from prv1-mh.provo.novell.com (unknown [137.65.248.33]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 8cbf395c-6ce7-11e9-843c-bc764e045a96; Thu, 02 May 2019 14:35:37 +0000 (UTC) Received: from INET-PRV1-MTA by prv1-mh.provo.novell.com with Novell_GroupWise; Thu, 02 May 2019 08:35:36 -0600 Message-Id: <5CCB0037020000780022B506@prv1-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 18.1.0 Date: Thu, 02 May 2019 08:35:35 -0600 From: "Jan Beulich" To: "xen-devel" Mime-Version: 1.0 Content-Disposition: inline Subject: [Xen-devel] [PATCH v2] x86: suppress XPTI-related TLB flushes when possible 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 , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP When there's no XPTI-enabled PV domain at all, there's no need to issue respective TLB flushes. Hardwire opt_xpti_* to false when !PV, and record the creation of PV domains by bumping opt_xpti_* accordingly. As to the sticky opt_xpti_domu vs increment/decrement of opt_xpti_hwdom, this is done this way to avoid (a) widening the former variable, (b) any risk of a missed flush, which would result in an XSA if a DomU was able to exercise it, and (c) any races updating the variable. Fundamentally the TLB flush done when context switching out the domain's vCPU-s the last time before destroying the domain ought to be sufficient, so in principle DomU handling could be made match hwdom's. Signed-off-by: Jan Beulich --- v2: Add comment to spec_ctrl.h. Explain difference in accounting of DomU and hwdom. --- TBD: The hardwiring to false could be extended to opt_pv_l1tf_* and (for !HVM) opt_l1d_flush as well. --- a/xen/arch/x86/flushtlb.c +++ b/xen/arch/x86/flushtlb.c @@ -218,7 +218,7 @@ unsigned int flush_area_local(const void */ invpcid_flush_one(PCID_PV_PRIV, addr); invpcid_flush_one(PCID_PV_USER, addr); - if ( opt_xpti_hwdom || opt_xpti_domu ) + if ( opt_xpti_hwdom > 1 || opt_xpti_domu > 1 ) { invpcid_flush_one(PCID_PV_PRIV | PCID_PV_XPTI, addr); invpcid_flush_one(PCID_PV_USER | PCID_PV_XPTI, addr); --- a/xen/arch/x86/pv/domain.c +++ b/xen/arch/x86/pv/domain.c @@ -272,6 +272,9 @@ void pv_domain_destroy(struct domain *d) destroy_perdomain_mapping(d, GDT_LDT_VIRT_START, GDT_LDT_MBYTES << (20 - PAGE_SHIFT)); + opt_xpti_hwdom -= IS_ENABLED(CONFIG_LATE_HWDOM) && + !d->domain_id && opt_xpti_hwdom; + XFREE(d->arch.pv.cpuidmasks); FREE_XENHEAP_PAGE(d->arch.pv.gdt_ldt_l1tab); @@ -310,7 +313,16 @@ int pv_domain_initialise(struct domain * /* 64-bit PV guest by default. */ d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0; - d->arch.pv.xpti = is_hardware_domain(d) ? opt_xpti_hwdom : opt_xpti_domu; + if ( is_hardware_domain(d) && opt_xpti_hwdom ) + { + d->arch.pv.xpti = true; + ++opt_xpti_hwdom; + } + if ( !is_hardware_domain(d) && opt_xpti_domu ) + { + d->arch.pv.xpti = true; + opt_xpti_domu = 2; + } if ( !is_pv_32bit_domain(d) && use_invpcid && cpu_has_pcid ) switch ( ACCESS_ONCE(opt_pcid) ) --- a/xen/arch/x86/spec_ctrl.c +++ b/xen/arch/x86/spec_ctrl.c @@ -80,10 +80,12 @@ static int __init parse_spec_ctrl(const opt_eager_fpu = 0; +#ifdef CONFIG_PV if ( opt_xpti_hwdom < 0 ) opt_xpti_hwdom = 0; if ( opt_xpti_domu < 0 ) opt_xpti_domu = 0; +#endif if ( opt_smt < 0 ) opt_smt = 1; @@ -634,6 +636,7 @@ static __init void l1tf_calculations(uin : (3ul << (paddr_bits - 2)))); } +#ifdef CONFIG_PV int8_t __read_mostly opt_xpti_hwdom = -1; int8_t __read_mostly opt_xpti_domu = -1; @@ -700,6 +703,9 @@ static __init int parse_xpti(const char return rc; } custom_param("xpti", parse_xpti); +#else /* !CONFIG_PV */ +# define xpti_init_default(caps) ((void)(caps)) +#endif /* CONFIG_PV */ void __init init_speculation_mitigations(void) { --- a/xen/include/asm-x86/spec_ctrl.h +++ b/xen/include/asm-x86/spec_ctrl.h @@ -43,7 +43,18 @@ extern bool bsp_delay_spec_ctrl; extern uint8_t default_xen_spec_ctrl; extern uint8_t default_spec_ctrl_flags; +#ifdef CONFIG_PV +/* + * Values -1, 0, and 1 have the usual meaning of "not established yet", + * "disabled", and "enabled". Values larger than 1 indicate there's actually + * at least one such domain (or there has been). This way XPTI-specific TLB + * flushes can be avoided when no XPTI-enabled domain is/was active. + */ extern int8_t opt_xpti_hwdom, opt_xpti_domu; +#else +# define opt_xpti_hwdom false +# define opt_xpti_domu false +#endif extern int8_t opt_pv_l1tf_hwdom, opt_pv_l1tf_domu;