From patchwork Fri Jul 19 10:29:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11049979 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 9D9A913BD for ; Fri, 19 Jul 2019 10:31:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89F74288B7 for ; Fri, 19 Jul 2019 10:31:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A1EF288BE; Fri, 19 Jul 2019 10:31:33 +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 0434C288B7 for ; Fri, 19 Jul 2019 10:31:32 +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 1hoQ9S-0004Fk-QO; Fri, 19 Jul 2019 10:30:10 +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 1hoQ9R-0004FX-Dg for xen-devel@lists.xenproject.org; Fri, 19 Jul 2019 10:30:09 +0000 X-Inumbo-ID: 2b82be16-aa10-11e9-8caa-938f29f2802e Received: from m4a0039g.houston.softwaregrp.com (unknown [15.124.2.85]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2b82be16-aa10-11e9-8caa-938f29f2802e; Fri, 19 Jul 2019 10:30:06 +0000 (UTC) Received: FROM m4a0039g.houston.softwaregrp.com (15.120.17.147) BY m4a0039g.houston.softwaregrp.com WITH ESMTP; Fri, 19 Jul 2019 10:30:02 +0000 Received: from M4W0334.microfocus.com (2002:f78:1192::f78:1192) 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; Fri, 19 Jul 2019 10:29:13 +0000 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (15.124.8.12) by M4W0334.microfocus.com (15.120.17.146) 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; Fri, 19 Jul 2019 10:29:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D7W7I6UYjJYeq4PA+Sva3B9MJD3OpkLz05j1CpkG9MKAPhCon4mARmi7WnogcrOEE1fdArz+jOEJL4iGF530zONaUKJMu7fFMuwvoDMg73DzNsWeevSAdmpnjm287vqd7Vp8wyiFqYWl3sGXo1VyRQH/51eZomzoKKgSUKP1jV/PHJCgDP/f19XGCGDiKpdZskqLBDDq3mXGCRPnfMeC+dr6eg3W3WkVea7gdA/2jBeyX3h/2wUfrWacR5L4Yxkg9YIfCBHtDqNgvNbz5i3WbwtwO8lzGldk2ucTK3YhYj1tRwgWP6UENcnTUmaJ5MM1JN4HDLziXALuO8O94ckJuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qvVnFIBxtG1VqNAilCVCJY2BYlSAiKIw3lPug2FFKw4=; b=XRGp0tuDmrw/e8pUTrlUkPL7NVG3Z8gV7Xz89M/7mMlHI5prAGoxNSvjnGYur5pR/Q8dJkho1X+pLxOiA+YUB5QitsMAMk3HNld5HLed3PZWv3s+72kSAt+OHHbSRwep1uhi9TrMSh7Rfs9MVePeJ8eKHbzzVvV3pkCG/TNo5jw2ingoARqHjxICH0MhiSoSRahqaj7ApA4fQStXAWMF9Xp51zHX8H/HMz+HyCOI7FRP7NnuKNWAePSXA+oe7J5i5mDJjZfKIuAXPoWzU6RWI9kSPSDweimRDZDXtS1wK1pOsNBOViSe9w+U2rNQ06x8/dBHdFztLK9bA7/f2Z2Pzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=suse.com;dmarc=pass action=none header.from=suse.com;dkim=pass header.d=suse.com;arc=none Received: from DM6PR18MB3401.namprd18.prod.outlook.com (10.255.174.218) by DM6PR18MB2540.namprd18.prod.outlook.com (20.179.105.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2094.12; Fri, 19 Jul 2019 10:29:11 +0000 Received: from DM6PR18MB3401.namprd18.prod.outlook.com ([fe80::1fe:35f6:faf3:78c7]) by DM6PR18MB3401.namprd18.prod.outlook.com ([fe80::1fe:35f6:faf3:78c7%7]) with mapi id 15.20.2073.012; Fri, 19 Jul 2019 10:29:11 +0000 From: Jan Beulich To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v2 1/2] x86/cpu/intel: Clear cache self-snoop capability in CPUs with known errata Thread-Index: AQHVPhzObMH32PKqfka5dBK6AxG1/g== Date: Fri, 19 Jul 2019 10:29:11 +0000 Message-ID: References: <0ccb27d1-6612-d915-a898-8423ac3afdd0@suse.com> In-Reply-To: <0ccb27d1-6612-d915-a898-8423ac3afdd0@suse.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0318.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a4::18) To DM6PR18MB3401.namprd18.prod.outlook.com (2603:10b6:5:1cc::26) 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: 3cd9dc7f-2a39-4b19-3330-08d70c33f0b4 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:DM6PR18MB2540; x-ms-traffictypediagnostic: DM6PR18MB2540: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2803; x-forefront-prvs: 01039C93E4 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(39860400002)(136003)(376002)(346002)(396003)(366004)(199004)(189003)(66066001)(446003)(11346002)(3846002)(6116002)(6436002)(36756003)(26005)(53936002)(5640700003)(2616005)(476003)(102836004)(186003)(6486002)(478600001)(14454004)(2351001)(25786009)(256004)(486006)(6506007)(71200400001)(7736002)(6916009)(71190400001)(2501003)(316002)(4326008)(99286004)(8676002)(305945005)(86362001)(31696002)(54906003)(31686004)(5660300002)(2906002)(66556008)(76176011)(52116002)(6512007)(386003)(80792005)(66946007)(81156014)(68736007)(8936002)(81166006)(66446008)(64756008)(66476007); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR18MB2540; H:DM6PR18MB3401.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: o1il4NumIbrL7IaNZ+CxYBCvIE+ZedMPik1kpU3oXGnBc2nnzIYO5+Av2ptgMWkb5YbZmKVoeEj5Pp6bT55VIG/RWUf8ypoWhf9upsNbg6lFkv6hhFlwOgq5J+AiWmJP5FjKzG/2FKrFutLy68ybpRPwuMOwU+u1/zqKA53X/K44mYwQURsI4vwf8r9pAHyZLBjxj9yj8UIqP7+bI9+o9ZJHHECTW380z01CEr406xZt/YCyJ4Mmwzzo/xotjFaTw21je09HpRp4XIANJYiILQk8zP/L5PH7y+KdrHE5opdLVqgvAWIC5Jj2YXD95Eg1lYhIVXgpPEQwMZb+9gC7yhi4F8S17PtHKWIlajHPMmbirXhsRjZm/Su4Vpqi8TZ4hh8hG+bdf8HnsDcBaAxKLO60TsCceM1VlnRUgAk56Ew= Content-ID: <4CC21AF714A82747BDEB6CD3E73ECC72@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 3cd9dc7f-2a39-4b19-3330-08d70c33f0b4 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jul 2019 10:29:11.8250 (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: DM6PR18MB2540 X-OriginatorOrg: suse.com Subject: [Xen-devel] [PATCH v2 1/2] x86/cpu/intel: Clear cache self-snoop capability in CPUs with known errata 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 From: Ricardo Neri Processors which have self-snooping capability can handle conflicting memory type across CPUs by snooping its own cache. However, there exists CPU models in which having conflicting memory types still leads to unpredictable behavior, machine check errors, or hangs. Clear this feature on affected CPUs to prevent its use. Suggested-by: Alan Cox Signed-off-by: Ricardo Neri [Linux commit 1e03bff3600101bd9158d005e4313132e55bdec8] Strip Yonah - as per ark.intel.com it doesn't look to be 64-bit capable. Call the new function on the boot CPU only. Don't clear the CPU feature flag itself, as it is exposed to guests (who could otherwise observe it disappear after migration). Requested-by: Andrew Cooper Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- v2: Introduce and use XEN_SELFSNOOP. --- NB: The function name isn't fully appropriate anymore, but I'd prefer to keep Linux'es name to allow matching the two changes. --- a/xen/arch/x86/cpu/intel.c +++ b/xen/arch/x86/cpu/intel.c @@ -15,6 +15,36 @@ #include "cpu.h" /* + * Processors which have self-snooping capability can handle conflicting + * memory type across CPUs by snooping its own cache. However, there exists + * CPU models in which having conflicting memory types still leads to + * unpredictable behavior, machine check errors, or hangs. Clear this + * feature to prevent its use on machines with known erratas. + */ +static void __init check_memory_type_self_snoop_errata(void) +{ + if (!boot_cpu_has(X86_FEATURE_SS)) + return; + + switch (boot_cpu_data.x86_model) { + case 0x0f: /* Merom */ + case 0x16: /* Merom L */ + case 0x17: /* Penryn */ + case 0x1d: /* Dunnington */ + case 0x1e: /* Nehalem */ + case 0x1f: /* Auburndale / Havendale */ + case 0x1a: /* Nehalem EP */ + case 0x2e: /* Nehalem EX */ + case 0x25: /* Westmere */ + case 0x2c: /* Westmere EP */ + case 0x2a: /* SandyBridge */ + return; + } + + setup_force_cpu_cap(X86_FEATURE_XEN_SELFSNOOP); +} + +/* * Set caps in expected_levelling_cap, probe a specific masking MSR, and set * caps in levelling_caps if it is found, or clobber the MSR index if missing. * If preset, reads the default value into msr_val. @@ -256,8 +286,11 @@ static void early_init_intel(struct cpui (boot_cpu_data.x86_mask == 3 || boot_cpu_data.x86_mask == 4)) paddr_bits = 36; - if (c == &boot_cpu_data) + if (c == &boot_cpu_data) { + check_memory_type_self_snoop_errata(); + intel_init_levelling(); + } ctxt_switch_levelling(NULL); } --- a/xen/include/asm-x86/cpufeatures.h +++ b/xen/include/asm-x86/cpufeatures.h @@ -30,6 +30,7 @@ XEN_CPUFEATURE(SC_MSR_PV, (FSCAPIN XEN_CPUFEATURE(SC_MSR_HVM, (FSCAPINTS+0)*32+17) /* MSR_SPEC_CTRL used by Xen for HVM */ XEN_CPUFEATURE(SC_RSB_PV, (FSCAPINTS+0)*32+18) /* RSB overwrite needed for PV */ XEN_CPUFEATURE(SC_RSB_HVM, (FSCAPINTS+0)*32+19) /* RSB overwrite needed for HVM */ +XEN_CPUFEATURE(XEN_SELFSNOOP, (FSCAPINTS+0)*32+20) /* SELFSNOOP gets used by Xen itself */ XEN_CPUFEATURE(SC_MSR_IDLE, (FSCAPINTS+0)*32+21) /* (SC_MSR_PV || SC_MSR_HVM) && default_xen_spec_ctrl */ XEN_CPUFEATURE(XEN_LBR, (FSCAPINTS+0)*32+22) /* Xen uses MSR_DEBUGCTL.LBR */ XEN_CPUFEATURE(SC_VERW_PV, (FSCAPINTS+0)*32+23) /* VERW used by Xen for PV */ From patchwork Fri Jul 19 10:29:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11049981 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 91D1B13BD for ; Fri, 19 Jul 2019 10:31:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EC85287D1 for ; Fri, 19 Jul 2019 10:31:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D5DF288BB; Fri, 19 Jul 2019 10:31:54 +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 EF60B287D1 for ; Fri, 19 Jul 2019 10:31:53 +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 1hoQ9T-0004Fq-3e; Fri, 19 Jul 2019 10:30:11 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hoQ9R-0004Fa-Ly for xen-devel@lists.xenproject.org; Fri, 19 Jul 2019 10:30:09 +0000 X-Inumbo-ID: 2dd7cfda-aa10-11e9-8980-bc764e045a96 Received: from m9a0003g.houston.softwaregrp.com (unknown [15.124.64.68]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2dd7cfda-aa10-11e9-8980-bc764e045a96; Fri, 19 Jul 2019 10:30:08 +0000 (UTC) Received: FROM m9a0003g.houston.softwaregrp.com (15.121.0.190) BY m9a0003g.houston.softwaregrp.com WITH ESMTP; Fri, 19 Jul 2019 10:30:03 +0000 Received: from M4W0334.microfocus.com (2002:f78:1192::f78:1192) by M9W0067.microfocus.com (2002:f79:be::f79:be) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Fri, 19 Jul 2019 10:29:37 +0000 Received: from NAM03-DM3-obe.outbound.protection.outlook.com (15.124.8.12) by M4W0334.microfocus.com (15.120.17.146) 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; Fri, 19 Jul 2019 10:29:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N+SbXQCmb0EG2MpDimHimQFRqRCy+uEHAbFLD7mhZVfiivL6rKs2dJGyyJIk7YVSrkr2dDrJBI2QJFPNj7tAmZLcxIJnPVYtTqAhdZfCw+ycAsFlAxahCcXZMxy00Y44fye2+lubtvmx+j1oHewAxS0rNMDdqRqlHLPNL04TGSA6AG65qNwS8I97/eAeQH7ItBx5qrQ7MqdwzhxPFQWjbvKIBFJg9x9jtfq6YBiiJwN0/jtZQ3bVWIhqcYn+y7gKxIBrYY6R0QoFueYCIPdcWQkYUAQU3cADQSGb0sY2GS+w1I1Kh6UYICZG/dnuYF5sEemrOw3H15fJSyulk7gsXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AXO7ZHh8KO9QySatYEKjIhxrXNYQLgOP6fVcipQY5aM=; b=PoHG6DBMjH/Qzg0ZAC96ritAnhUvqnuY3x2nUVRhpDGOb4SnuSI3o7tIWqtA9xUcN27pYqP3hTLQ64FI8T9lyTSwAJxZQC8MVFmq0HwNAf1nhedRVLhrwBbnYujyGO86mVlQMBktXz2V0I3RZxH3Xqd3m/qRhSnUfi//Jd/gfGLRC3G0sqAZsr+mW0T8sVmcbuZgwKIDm1+bgD0wrCDkG5fmVrbZqBFGls4jiAo89B8nTK5oqji5v58crhGGxjUOyIc3/vQoQuWgrx2B+690/PSGqJ0OOynVKzYk6cEvSRmPxwew8OJAD+ImvDBrNvyomjW+fD60ekYZNtMcMVzTRQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=suse.com;dmarc=pass action=none header.from=suse.com;dkim=pass header.d=suse.com;arc=none Received: from DM6PR18MB3401.namprd18.prod.outlook.com (10.255.174.218) by DM6PR18MB2540.namprd18.prod.outlook.com (20.179.105.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2094.12; Fri, 19 Jul 2019 10:29:36 +0000 Received: from DM6PR18MB3401.namprd18.prod.outlook.com ([fe80::1fe:35f6:faf3:78c7]) by DM6PR18MB3401.namprd18.prod.outlook.com ([fe80::1fe:35f6:faf3:78c7%7]) with mapi id 15.20.2073.012; Fri, 19 Jul 2019 10:29:36 +0000 From: Jan Beulich To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v2 2/2] x86/mtrr: Skip cache flushes on CPUs with cache self-snooping Thread-Index: AQHVPhzduXN26MwI5kWBrLOv0yjR7g== Date: Fri, 19 Jul 2019 10:29:36 +0000 Message-ID: <2120a03f-3712-82d2-0b3d-759a996d0c87@suse.com> References: <0ccb27d1-6612-d915-a898-8423ac3afdd0@suse.com> In-Reply-To: <0ccb27d1-6612-d915-a898-8423ac3afdd0@suse.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0334.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a4::34) To DM6PR18MB3401.namprd18.prod.outlook.com (2603:10b6:5:1cc::26) 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: c35da599-08a2-4708-6a24-08d70c33ff7d x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:DM6PR18MB2540; x-ms-traffictypediagnostic: DM6PR18MB2540: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2582; x-forefront-prvs: 01039C93E4 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(39860400002)(136003)(376002)(346002)(396003)(366004)(199004)(189003)(66066001)(446003)(11346002)(3846002)(6116002)(6436002)(36756003)(26005)(53936002)(5640700003)(2616005)(476003)(102836004)(186003)(6486002)(478600001)(14454004)(2351001)(25786009)(256004)(14444005)(486006)(6506007)(71200400001)(7736002)(6916009)(71190400001)(2501003)(316002)(4326008)(99286004)(8676002)(305945005)(86362001)(31696002)(54906003)(31686004)(5660300002)(2906002)(66556008)(76176011)(52116002)(6512007)(386003)(80792005)(66946007)(81156014)(68736007)(8936002)(81166006)(66446008)(64756008)(66476007); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR18MB2540; H:DM6PR18MB3401.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: dWU70aBWfFS/HywhVK35Vz5QhSQHLBF/1rk6p8SDIu1ZOF59qaQoPRVPUr/fkfO1hw4BxIvHrEygi0OiaMODjFVbIBVQ5lN1NiACRjzNJBOusiMtNU+oHPBFOqXbqrmy3VNvhiW1Et7Hsc21Os3RkUJZtFpJE1r9kQ5UCw7gmrOJh9W/mw7AqvWo3wsdEVJlW5z9oRn14WkfdrrBWfS3CjaH7p2WCoy/vnszD78cLEKlLw7Gu0r85Vggv5+fQes1iRQrSFtLx/Lp0Wvs3NAJv+aKLJF/BaJ7KnIoejRrLMifz1j6nqzbvKt4yaN3cu8hqhZIB61XKIZJVxI6Cjxf7P7ePzPJcrXFxCxSnsrPRfVFqhA5m85LGFpIfH3/4VRts4LVUVTbUIOTbezmerhP/CatZNnEgAxncJrEodQUhjo= Content-ID: <52C2239B8BC4724684C1374403D8B075@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: c35da599-08a2-4708-6a24-08d70c33ff7d X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jul 2019 10:29:36.6608 (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: DM6PR18MB2540 X-OriginatorOrg: suse.com Subject: [Xen-devel] [PATCH v2 2/2] x86/mtrr: Skip cache flushes on CPUs with cache self-snooping 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 From: Ricardo Neri Programming MTRR registers in multi-processor systems is a rather lengthy process. Furthermore, all processors must program these registers in lock step and with interrupts disabled; the process also involves flushing caches and TLBs twice. As a result, the process may take a considerable amount of time. On some platforms, this can lead to a large skew of the refined-jiffies clock source. Early when booting, if no other clock is available (e.g., booting with hpet=disabled), the refined-jiffies clock source is used to monitor the TSC clock source. If the skew of refined-jiffies is too large, Linux wrongly assumes that the TSC is unstable: clocksource: timekeeping watchdog on CPU1: Marking clocksource 'tsc-early' as unstable because the skew is too large: clocksource: 'refined-jiffies' wd_now: fffedc10 wd_last: fffedb90 mask: ffffffff clocksource: 'tsc-early' cs_now: 5eccfddebc cs_last: 5e7e3303d4 mask: ffffffffffffffff tsc: Marking TSC unstable due to clocksource watchdog As per measurements, around 98% of the time needed by the procedure to program MTRRs in multi-processor systems is spent flushing caches with wbinvd(). As per the Section 11.11.8 of the Intel 64 and IA 32 Architectures Software Developer's Manual, it is not necessary to flush caches if the CPU supports cache self-snooping. Thus, skipping the cache flushes can reduce by several tens of milliseconds the time needed to complete the programming of the MTRR registers: Platform Before After 104-core (208 Threads) Skylake 1437ms 28ms 2-core ( 4 Threads) Haswell 114ms 2ms Reported-by: Mohammad Etemadi Signed-off-by: Ricardo Neri [Linux commit fd329f276ecaad7a371d6f91b9bbea031d0c3440] Use alternatives patching instead of static_cpu_has() (which we don't have [yet]). Interestingly we've been lacking the 2nd wbinvd(), which I'm taking the liberty here. Requested-by: Andrew Cooper Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- v2: Re-base (use XEN_SELFSNOOP). --- a/xen/arch/x86/cpu/mtrr/generic.c +++ b/xen/arch/x86/cpu/mtrr/generic.c @@ -450,7 +450,14 @@ static bool prepare_set(void) /* Enter the no-fill (CD=1, NW=0) cache mode and flush caches. */ write_cr0(read_cr0() | X86_CR0_CD); - wbinvd(); + + /* + * Cache flushing is the most time-consuming step when programming + * the MTRRs. Fortunately, as per the Intel Software Development + * Manual, we can skip it if the processor supports cache self- + * snooping. + */ + alternative("wbinvd", "", X86_FEATURE_XEN_SELFSNOOP); cr4 = read_cr4(); if (cr4 & X86_CR4_PGE) @@ -466,6 +473,9 @@ static bool prepare_set(void) /* Disable MTRRs, and set the default type to uncached */ mtrr_wrmsr(MSR_MTRRdefType, deftype & ~0xcff); + /* Again, only flush caches if we have to. */ + alternative("wbinvd", "", X86_FEATURE_XEN_SELFSNOOP); + return cr4 & X86_CR4_PGE; }