From patchwork Wed Jul 3 12:04:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11029391 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 7317D14F6 for ; Wed, 3 Jul 2019 12:07:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61B0128893 for ; Wed, 3 Jul 2019 12:07:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 555E828884; Wed, 3 Jul 2019 12:07:37 +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,UNPARSEABLE_RELAY 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 CAF8D28884 for ; Wed, 3 Jul 2019 12:07:36 +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 1hie16-0007Ug-9J; Wed, 03 Jul 2019 12:05:40 +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 1hie14-0007Ub-Uf for xen-devel@lists.xenproject.org; Wed, 03 Jul 2019 12:05:38 +0000 X-Inumbo-ID: ddecfa68-9d8a-11e9-91b9-ff0a5194ccb6 Received: from m4a0041g.houston.softwaregrp.com (unknown [15.124.2.87]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ddecfa68-9d8a-11e9-91b9-ff0a5194ccb6; Wed, 03 Jul 2019 12:05:37 +0000 (UTC) Received: FROM m4a0041g.houston.softwaregrp.com (15.120.17.147) BY m4a0041g.houston.softwaregrp.com WITH ESMTP; Wed, 3 Jul 2019 12:05:30 +0000 Received: from M9W0067.microfocus.com (2002:f79:be::f79:be) by M4W0335.microfocus.com (2002:f78:1193::f78:1193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Wed, 3 Jul 2019 12:04:39 +0000 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (15.124.72.11) by M9W0067.microfocus.com (15.121.0.190) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10 via Frontend Transport; Wed, 3 Jul 2019 12:04:39 +0000 Received: from BY5PR18MB3394.namprd18.prod.outlook.com (10.255.139.95) by BY5PR18MB3379.namprd18.prod.outlook.com (10.255.136.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2032.20; Wed, 3 Jul 2019 12:04:37 +0000 Received: from BY5PR18MB3394.namprd18.prod.outlook.com ([fe80::2005:4b02:1d60:d1bc]) by BY5PR18MB3394.namprd18.prod.outlook.com ([fe80::2005:4b02:1d60:d1bc%3]) with mapi id 15.20.2052.010; Wed, 3 Jul 2019 12:04:37 +0000 From: Jan Beulich To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v3] x86: suppress XPTI-related TLB flushes when possible Thread-Index: AQHVMZd8pzxdv6yBEke5NzY7LaNciw== Date: Wed, 3 Jul 2019 12:04:37 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: DB6PR07CA0087.eurprd07.prod.outlook.com (2603:10a6:6:2b::25) To BY5PR18MB3394.namprd18.prod.outlook.com (2603:10b6:a03:194::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@suse.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [87.234.252.170] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e7329d6e-567b-430e-e6ac-08d6ffae9eb3 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600148)(711020)(4605104)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020); SRVR:BY5PR18MB3379; x-ms-traffictypediagnostic: BY5PR18MB3379: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 00872B689F x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(396003)(136003)(366004)(39860400002)(346002)(376002)(189003)(199004)(53936002)(52116002)(6436002)(5640700003)(6512007)(7736002)(2351001)(102836004)(6486002)(68736007)(6506007)(8936002)(14454004)(80792005)(26005)(31686004)(72206003)(305945005)(54906003)(386003)(3846002)(8676002)(316002)(81166006)(186003)(2501003)(81156014)(486006)(66476007)(14444005)(66066001)(36756003)(476003)(2616005)(4326008)(256004)(99286004)(73956011)(2906002)(5660300002)(71190400001)(64756008)(71200400001)(6116002)(66446008)(6916009)(66556008)(66946007)(25786009)(478600001)(31696002)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY5PR18MB3379; H:BY5PR18MB3394.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: suse.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: MKx8p0wHxutXCrZh/14DhwU3aS4fFBvVohmzkDBOrN464cI/wUGvtEjvn504CId3jYWFXiP9t4TydTUaN9d4DOMg3l5m4a5ZY5q8hR1t/0+waAaIZaC4fBdmXYZV7zVDL4ZBK8qOjYUQ+A8y1qeFQVaMwk6dcthfpXQqBlegsq1wdBrBAiZVrpADShwL3wj0iFutM00y32363KxdnxP9sh+Nm5kSmlRjQwM6QPvE6wOwf+qWpZhHIT8nhggLWJWlpf+yNK805Z2oGAEMyWR0CituVHktn68kssTsnpJ+DhdruSV2wAuM6zHQyt1Jtirx3TbofFim2/EyY11fvY9nv6lF8b7GNfrLSgSIJTUs0MYaiesTeXBSGCptorHAXKNHyVlhLJ4oFJMOVmnVe3lsPPeiQycihYZKhJq1wKopKaw= Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: e7329d6e-567b-430e-e6ac-08d6ffae9eb3 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jul 2019 12:04:37.3904 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 856b813c-16e5-49a5-85ec-6f081e13b527 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: JBeulich@suse.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR18MB3379 X-OriginatorOrg: suse.com Subject: [Xen-devel] [PATCH v3] 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 , =?utf-8?q?Roger_Pau_Monn=C3=A9?= 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 --- v3: Re-base. 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 @@ -85,10 +85,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; @@ -187,6 +189,7 @@ static int __init parse_spec_ctrl(const } custom_param("spec-ctrl", parse_spec_ctrl); +#ifdef CONFIG_PV int8_t __read_mostly opt_xpti_hwdom = -1; int8_t __read_mostly opt_xpti_domu = -1; @@ -253,6 +256,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 */ int8_t __read_mostly opt_pv_l1tf_hwdom = -1; int8_t __read_mostly opt_pv_l1tf_domu = -1; --- 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;