From nobody Sat Nov 30 04:28:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1618398353; cv=pass; d=zohomail.com; s=zohoarc; b=MssnfJRcHdEKo0zIfBCOfm9CczUYRHWTc9Ep7DTV4fbGHDtsUrL8dwJvc3KzHet/5uF9UfYStFDaPfr7X9UgEcBFyUTrtJq9nD6QLQYYJvLghVq6gOkAwMd5ZlS+zCwCAUsfYTnA5PrlVcXiAZ+YpZgNbnbCgREErXVIKLIgMlU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618398353; 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=XHgQn41rDI5whB93Ym85E1U2wOPzHicCd0BkH1NVL9I=; b=ZCsQhAbNHKADsiwO6w+0auAB8bzmXzYv+rmEnnsXtQgckQkIh5Ma9QG2H0dr86xMPpfGk/4hrI0pWlv2wLwcr07S5G9E1gAqPBKztJH7DosY5zSAug4/ALlrX3RdkJOrsTDW2WQsUM7xvRW2GWpGs5yflSTnxFIRykPwGSxHhys= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject 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 1618398353013525.5721894847962; Wed, 14 Apr 2021 04:05:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.110487.210904 (Exim 4.92) (envelope-from ) id 1lWdKv-0004Vs-Ca; Wed, 14 Apr 2021 11:05:33 +0000 Received: by outflank-mailman (output) from mailman id 110487.210904; Wed, 14 Apr 2021 11:05:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lWdKv-0004Vl-8C; Wed, 14 Apr 2021 11:05:33 +0000 Received: by outflank-mailman (input) for mailman id 110487; Wed, 14 Apr 2021 11:05:32 +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.92) (envelope-from ) id 1lWdKt-0004VO-T5 for xen-devel@lists.xenproject.org; Wed, 14 Apr 2021 11:05:31 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id af2d35c6-e725-47db-8ce4-1c7cd1d3f697; Wed, 14 Apr 2021 11:05:29 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: af2d35c6-e725-47db-8ce4-1c7cd1d3f697 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1618398329; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=VZIYLeSV0aN4XSzvaC8ife+MYqs04guLDyVOrAMIvpY=; b=h8Pp8zsk1LJ2IuuvDPYLpJriFZhyCY9f/Yx1vTihKQTmCp+Q2k+QHCHi tNlJq2CkYj5y8a7Xf7YWICZBTqEu44tzhzJgvUIQD4LlhoDlMTOodVorx uYLp5UrZqPDEQpC3W+JZ6vQ5Du6gToIIAyqQurjpjR90j0o2Mmyraq2BF c=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: zXKDX9ILNqWN/JyKuPLjvVqX7ZHcK7zH4hbSHXa8Bdt5Icw9ZTnqX+aIN7Kqd1HxQHHXJXwxDm ucOEsxPiK1U43HcHamlgoLbsIDfEgWLvQSIDd3lZuXeLta3OrBTM6ESlazM8RkF9lQVZNUrCpT uio/f6hUIihM/Oe1dHvuiRMbYenTJA2zEZvg6tnu0tinlRsy1HaKo5SJYJUMyDrdK2dwKP50E1 Jhx04128J427iOnEOywI5x9WqrbVvXytStoueZ1M5q4kymSOR7/CB2WTZxZeMZU6qF65r+kW0U CTk= X-SBRS: 5.2 X-MesageID: 41559652 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:0XFYFqCdMQN2w8XlHegptMeALOonbusQ8zAX/mhLY1h8btGYm8 eynP4SyB/zj3IrVGs9nM2bUZPufVr1zrQwxYUKJ7+tUE3duGWuJJx/9oeK+VHdMgXE3Kpm2a 9kGpISNPTZEUV6gcHm4AOxDtYnx529/Lq1gPrFpk0NcShBQchbnmNEIyycFVB7QxQDOIEwE4 CS6tECiz2rf3kWacrTPAh4Y8HoodrXmJX6JSMXHhJP0njysRqEyp7fVyKZ0BAXTi9Vzd4Zn1 TtvgTl6syYwpeG4zDG0Wu71eU1pPLAzZ95CNWImowpLFzX+32VTaBAf5HHgzwvuuGo7z8R4a nxijMtJd565X+UXkzdm2qV5yDa3Dwj62DvxDaj6BOJy6yJJ0NJN+N7iY1UaRff4UY71esMqp 5j5G6Fq4FRSSrJgSWV3am4azhRikG2rXA++NRj6EB3bI12Us41kaUv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1Zjam/XryVLAWhbOdY+lWmdle7bb9GUaCAXZEdtA xz7d3Nv+iZcUPDqU3tlAo+BqJF6GC8R8yuRCqKBO5T6tS/fW22vZHC2r/7sB7HDR2ha0oZgo VZdUsfKuR74wNS87Ef42yVUaz4okUsjl1Exypo/2Sdg7Sb3A== X-IronPort-AV: E=Sophos;i="5.82,221,1613451600"; d="scan'208";a="41559652" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ByKilPfKc1aWHxulc+pIAFbdkIBkPhYGSmwkvedYmi7wMEWnQGI/6IYmndjTBq4yQeQIprEIELqugvDk3j+LilNDeF10fqyVR0IvITypo+yjH1NtF+2RZ1PclU9SiqnjtYnmrPYb5pxu/7qZbMSGRfAPdBR+OVF2cRYMdkDGSu5u3mTkOeamAUq5mtIaqqTti1ckllpTwM+h73bRaI/JXEwkLKfktkEwspydj5OvsxV9YwNWgAKI4JPhMcf2Uw4oKOUGC50hGv0CmDAJ9GPB+PsDJw/fjUAp6X78Mh+Yax9Li3+yhs/P1wZN93Qrh27sPnJZsRVVczguel6NFlel5g== 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=XHgQn41rDI5whB93Ym85E1U2wOPzHicCd0BkH1NVL9I=; b=RmmaUeI90iX9HQYUvchCry531vN+ktCo1wQ3aY30gH0TqNGDhVassjtQnJ44Hz5KYTcvFYTc41wUmfrfWlwkkzYUvdup/KDYf1zlkKXhrI7leFtiyBxfKPtJX94yZLBJhKGfa7TE8+AvkDpmS300RT8wf3Q9f049RNnQyg+gT+qi1KRPKQ79LY6ihw//L5c/PakTE2n3JCn9psUQoZ/oVkm3VIN7M/dPK4lMlDJVbuWQT1VejANil1j4FK1Xo8JW+tR4cDFGyQPMjs1vjXpmwwR4qoUs4tObYnQ20OXzvPC894EVMHe8+zgqHsIsdbh2p3biXrxo/52LaIvrOblyAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XHgQn41rDI5whB93Ym85E1U2wOPzHicCd0BkH1NVL9I=; b=JDzbVUR2rvwzEYUZa+hctOeueYYRGNRSxYkik88rNu0kurwJs/NIFGgKtjQO3qSe+py9PPmojFkBlhNzZ24GfLqmltErU8IgYSi8cqy0IKt1SuGOoNmDIiz3J2YTb1bCY3aAHp9qt7uFthSPS9Tt6V+TVfGYTQfcnvizrnRwwNk= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH 1/2] x86/amd: split LFENCE dispatch serializing setup logic into helper Date: Wed, 14 Apr 2021 13:04:32 +0200 Message-ID: <20210414110433.83084-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210414110433.83084-1-roger.pau@citrix.com> References: <20210414110433.83084-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MRXP264CA0006.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:15::18) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b5da8a8f-be1b-4a87-cb75-08d8ff35353a X-MS-TrafficTypeDiagnostic: DM5PR03MB2842: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZcQEnS6t140d6uTg1uSOtlk9ixypH6Gd+o79IvnYOya5s3bggRi6WUqf01nYX0rAPiWo4RduyRUR4pcrFoJGEns5qzlI/Uqa3e/pzEsLcWOJKgiyd0kjDV2kzd1VaLj768MONMNIC1swUyXmslVJDZHZtGViUCEy6Sdu961Kq6KTxZtiFzP5W5Eu+xz/nirPQyW5YRIHSuVn0OJbpQM8pMV6J3/9LwzC7MQ1fUFAqQlspPhZbj35nsXH9ScEWXDGnJPedXEyeRvyODX34mdAKCHMYceYH19m0DaQzSUU2Rhk/ShUwDx3nc2mTVkBdDsbTGaNm6qhOICQNzKYyZYLPOwu6e14ufoIanbbVaXpbrKncrGqLBuqDQb5lJa1/3ADGhKpIg7QZI8/ezWP/BNZVHBAiO/CuIAmVBrzUDu6clWhf4r/T+vaCms7kXdD/eDJLE0TS8MB/TjQJgPqUg6XgO9NXp6W2RNjNBK8Gxsoc5U3vivGmJjZxzzfQZ8DlMfwc93KmN4boHdISuZQ/mG1IzpfTycCRKtlBj1rB0tSKw+ocmXOHzIipToajfFSTAuMDXjZjJdbpfNI1p82KEOZHrYfx15EObPbIsIy7yzfoRI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(346002)(366004)(136003)(396003)(376002)(956004)(83380400001)(2616005)(6916009)(316002)(6486002)(54906003)(8936002)(4326008)(38100700002)(8676002)(478600001)(6496006)(186003)(6666004)(16526019)(26005)(36756003)(5660300002)(1076003)(2906002)(66946007)(66556008)(66476007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?THpRRTludWN5STZKM3dxRStGMTAyQnFkT1ZucExQTTVhRTJTZDdNWWo0Nkpn?= =?utf-8?B?Ty8yVnRxcEdTd0FPSldBS0hTT09UNnpLUG5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b75-08d8ff35353a X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2021 11:05:26.5649 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1WcTvLjFzEQ8cug6eimh+rdhNLAbqHHvTwziYPHXFS7kgRyzfYI96BgZznG0EJ4tpWpLnPCykWfasBidO6Z+gw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2842 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Split the logic to attempt to setup the LFENCE to be dispatch serializing on AMD into a helper, so it can be shared with Hygon. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Andrew Cooper --- xen/arch/x86/cpu/amd.c | 62 ++++++++++++++++++++++------------------ xen/arch/x86/cpu/cpu.h | 1 + xen/arch/x86/cpu/hygon.c | 27 +---------------- 3 files changed, 36 insertions(+), 54 deletions(-) diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c index 8bc51bec10d..9c8dcd91eef 100644 --- a/xen/arch/x86/cpu/amd.c +++ b/xen/arch/x86/cpu/amd.c @@ -642,6 +642,38 @@ void early_init_amd(struct cpuinfo_x86 *c) ctxt_switch_levelling(NULL); } =20 +void amd_init_lfence(struct cpuinfo_x86 *c) +{ + uint64_t value; + + /* + * Attempt to set lfence to be Dispatch Serialising. This MSR almost + * certainly isn't virtualised (and Xen at least will leak the real + * value in but silently discard writes), as well as being per-core + * rather than per-thread, so do a full safe read/write/readback cycle + * in the worst case. + */ + if (rdmsr_safe(MSR_AMD64_DE_CFG, value)) + /* Unable to read. Assume the safer default. */ + __clear_bit(X86_FEATURE_LFENCE_DISPATCH, + c->x86_capability); + else if (value & AMD64_DE_CFG_LFENCE_SERIALISE) + /* Already dispatch serialising. */ + __set_bit(X86_FEATURE_LFENCE_DISPATCH, + c->x86_capability); + else if (wrmsr_safe(MSR_AMD64_DE_CFG, + value | AMD64_DE_CFG_LFENCE_SERIALISE) || + rdmsr_safe(MSR_AMD64_DE_CFG, value) || + !(value & AMD64_DE_CFG_LFENCE_SERIALISE)) + /* Attempt to set failed. Assume the safer default. */ + __clear_bit(X86_FEATURE_LFENCE_DISPATCH, + c->x86_capability); + else + /* Successfully enabled! */ + __set_bit(X86_FEATURE_LFENCE_DISPATCH, + c->x86_capability); +} + static void init_amd(struct cpuinfo_x86 *c) { u32 l, h; @@ -686,37 +718,11 @@ static void init_amd(struct cpuinfo_x86 *c) if (c =3D=3D &boot_cpu_data && !cpu_has(c, X86_FEATURE_RSTR_FP_ERR_PTRS)) setup_force_cpu_cap(X86_BUG_FPU_PTRS); =20 - /* - * Attempt to set lfence to be Dispatch Serialising. This MSR almost - * certainly isn't virtualised (and Xen at least will leak the real - * value in but silently discard writes), as well as being per-core - * rather than per-thread, so do a full safe read/write/readback cycle - * in the worst case. - */ if (c->x86 =3D=3D 0x0f || c->x86 =3D=3D 0x11) /* Always dispatch serialising on this hardare. */ __set_bit(X86_FEATURE_LFENCE_DISPATCH, c->x86_capability); - else /* Implicily "=3D=3D 0x10 || >=3D 0x12" by being 64bit. */ { - if (rdmsr_safe(MSR_AMD64_DE_CFG, value)) - /* Unable to read. Assume the safer default. */ - __clear_bit(X86_FEATURE_LFENCE_DISPATCH, - c->x86_capability); - else if (value & AMD64_DE_CFG_LFENCE_SERIALISE) - /* Already dispatch serialising. */ - __set_bit(X86_FEATURE_LFENCE_DISPATCH, - c->x86_capability); - else if (wrmsr_safe(MSR_AMD64_DE_CFG, - value | AMD64_DE_CFG_LFENCE_SERIALISE) || - rdmsr_safe(MSR_AMD64_DE_CFG, value) || - !(value & AMD64_DE_CFG_LFENCE_SERIALISE)) - /* Attempt to set failed. Assume the safer default. */ - __clear_bit(X86_FEATURE_LFENCE_DISPATCH, - c->x86_capability); - else - /* Successfully enabled! */ - __set_bit(X86_FEATURE_LFENCE_DISPATCH, - c->x86_capability); - } + else /* Implicily "=3D=3D 0x10 || >=3D 0x12" by being 64bit. */ + amd_init_lfence(c); =20 /* * If the user has explicitly chosen to disable Memory Disambiguation diff --git a/xen/arch/x86/cpu/cpu.h b/xen/arch/x86/cpu/cpu.h index 1992596d1b2..1ac3b2867a0 100644 --- a/xen/arch/x86/cpu/cpu.h +++ b/xen/arch/x86/cpu/cpu.h @@ -20,3 +20,4 @@ extern bool detect_extended_topology(struct cpuinfo_x86 *= c); =20 void early_init_amd(struct cpuinfo_x86 *c); void amd_log_freq(const struct cpuinfo_x86 *c); +void amd_init_lfence(struct cpuinfo_x86 *c); diff --git a/xen/arch/x86/cpu/hygon.c b/xen/arch/x86/cpu/hygon.c index 46293f1f367..2272e1113f1 100644 --- a/xen/arch/x86/cpu/hygon.c +++ b/xen/arch/x86/cpu/hygon.c @@ -32,32 +32,7 @@ static void init_hygon(struct cpuinfo_x86 *c) { unsigned long long value; =20 - /* - * Attempt to set lfence to be Dispatch Serialising. This MSR almost - * certainly isn't virtualised (and Xen at least will leak the real - * value in but silently discard writes), as well as being per-core - * rather than per-thread, so do a full safe read/write/readback cycle - * in the worst case. - */ - if (rdmsr_safe(MSR_AMD64_DE_CFG, value)) - /* Unable to read. Assume the safer default. */ - __clear_bit(X86_FEATURE_LFENCE_DISPATCH, - c->x86_capability); - else if (value & AMD64_DE_CFG_LFENCE_SERIALISE) - /* Already dispatch serialising. */ - __set_bit(X86_FEATURE_LFENCE_DISPATCH, - c->x86_capability); - else if (wrmsr_safe(MSR_AMD64_DE_CFG, - value | AMD64_DE_CFG_LFENCE_SERIALISE) || - rdmsr_safe(MSR_AMD64_DE_CFG, value) || - !(value & AMD64_DE_CFG_LFENCE_SERIALISE)) - /* Attempt to set failed. Assume the safer default. */ - __clear_bit(X86_FEATURE_LFENCE_DISPATCH, - c->x86_capability); - else - /* Successfully enabled! */ - __set_bit(X86_FEATURE_LFENCE_DISPATCH, - c->x86_capability); + amd_init_lfence(c); =20 /* * If the user has explicitly chosen to disable Memory Disambiguation --=20 2.30.1