From nobody Sat Nov 30 02:48:57 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 From nobody Sat Nov 30 02:48:57 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=1618398376; cv=pass; d=zohomail.com; s=zohoarc; b=awOAbyS6VYeMV9U6SI7tGgXlR6CNeMmR8lYqza6RwX2+e5Mcg3Qvj6ECYMSUoYska1VmqhwiFzkGwEV7MdD2jSR5sjMbDfgUZSC89H0rGOI45JPzPIk7d+pZZsIaqiDgVD9DAk8Ky5smcyZ8kYcOmC4M9PfMwQT3QvXJ+YZkmlE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618398376; 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=B1EnhQpxzdq1GIcElCsvj1rntwwV7ItPVmtb3wEEy3o=; b=OvapS825NcyaS/xBwkUWMZ/IJBnXimg/4nflq2rdSNM8GscmEaViKvF9gWokLINWO2Hq+KVhD7Tz5HatjA4RIuLOIUsuDzvMod51/F9S6pICQIY2UyO9n1s/4osB1TXXdOU5HlotVv/K2kUqumEvrscGK3S+QcvSuZcki3Dp8HQ= 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 1618398376613615.0395764345619; Wed, 14 Apr 2021 04:06:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.110491.210916 (Exim 4.92) (envelope-from ) id 1lWdLN-0004eq-MT; Wed, 14 Apr 2021 11:06:01 +0000 Received: by outflank-mailman (output) from mailman id 110491.210916; Wed, 14 Apr 2021 11:06:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lWdLN-0004ei-J7; Wed, 14 Apr 2021 11:06:01 +0000 Received: by outflank-mailman (input) for mailman id 110491; Wed, 14 Apr 2021 11:06:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lWdLM-0004dt-KK for xen-devel@lists.xenproject.org; Wed, 14 Apr 2021 11:06:00 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 32345ef8-5b80-48cd-ba1c-4ade80f65af8; Wed, 14 Apr 2021 11:05:56 +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: 32345ef8-5b80-48cd-ba1c-4ade80f65af8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1618398356; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=d63wDPoILdpretEejbAnyNXF8PmnALolZwq0ccOsIIo=; b=cGI2lpJt2tpRgQA9KgRfPgN9nX8cVMI3u9LhlvpgTYr/4Ts0dXmYtX8G NBS99Iyl3WrAgqFUMEj3Li18+Z43LhfKJGWqF5a4TQUl6oMqeVvbu+PVA vi/JNFVj9ewvh5qtjUtLAUXe11OvPua7sSlnxB5R1dCgrHbSH/A0d/5to g=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: Eo9xcQdVdOVk4BsSVBQrm0A1LPBAIze0XBLD92ktVSTjZtn0wgjSvqSIXIlQV1a6P7VVqPmGi0 9bBEFnqHeAaOWOCiQDSvjtOsiFV9Vv5Hmzn+b0wOxoomA1lq0BfL268bIpGr80N7h2EM6q4502 zevp1tbwSZPshgE1RdgOXDueDvpRlmjQ0IO/KXrJy5l4bZ1a+EzxLABiXUQTWtN4xDuDd/GUys c7oW90EKqHBkYEdfEG3kehgOPvrRkJ76wINOxUGMNWI5W5zHbn86bj+anBIvAJE8yZk+7PIJ5h itw= X-SBRS: 5.2 X-MesageID: 41690053 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:2GJp/KykilBv2K/4DD3iKrPxB+8kLtp033Aq2lEZdDV8eMaVjt 3rufwd2wP9hjp5YgBapfmrPq6cTXTAsbt85ocMNbmvNTOWwleABodk8Ifk3nncCzTzn9Qtjp tIXopfLJnLDVZ8hdvn+wXQKbwd6fSO7azAv5a4815DVgdvApsB0y5YDUKhHlRyVE16A/MCZe Khz+5mgxblRngNdMS8ARA+LrL+jvnGjojvbxJDJzNP0njpsRqS5LT3EweV034lOlslrNtMnw n4ujf06am5v/awxgW07R6r071thNDjxtFfbfb86PQ9FzT2hg6kIKRnVrGS1QpFxN2H1VcwnN HA5yonJsR4gkmhG12dnB2F4XiC7B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/B+g3eV1FtQ6cA/qZp77T7bY/CEyIowX9fU OS9CBQ5P/JVSqO37xyMdNGHU1GLEwnrHhy9uKLcIPdTBiwf+ZY5VygLzu2a7lGUrWIHr0Wsx d369yFhPWMaiL9wQzc1AELe55m4iKiW4e/EQiMEelH/5imIlyKmLKt+9P2gzHtSze3An5oz7 FtZAgVdIBEhTYjhoFsjXT3Razzv04/k1xRpTtgjUXg34C64GHdWUFKWDep8ql+TH1WKDyPi8 +A7O2TkHL66zJB0YPYFEhRcspVcuJgOrTfPmNrM4wIoLWs/6AzmSxNbxclEn4khFnGrpJb9K b83O+XRvbrBnjpM08Q4DJJBoZ7mSowtGFLGvLOnq6Vc0EQEfcSD/867odLmDdnrEPs50YQBi 8dwzAAx8XKNVzoP3N1CKjok8/3mXEj1da/12E= X-IronPort-AV: E=Sophos;i="5.82,221,1613451600"; d="scan'208";a="41690053" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dAAO2zG2lGWnUp6iideDlmOqR/ZjP6ZVsCxCvkdwRf8ExiAOEoM2Q157sMJaocSrUIVWpbLes4/6TR1+IDwxpZskuna+OeZG+ogPX5H28c9nEkwJHTe9wT2mrKWIx0fIdKJ7Xwtvy0skqAMUMseDOMOBTexndYT9RFWmA7np2xdE9P1F48HbpqLJkODibQD1GBbDG6Xh745ftdWfC501YKRLTXYMkF8fC5XNE6BBCEnzpdMtcDtd0RDLiaTOi6aiGbPNs4D2w97amQLSHcnjDTVVKQ2klPeIXmX7udCyItQtVuNHAO9GZzCufxtlAAUrAnRmqToJ2IOS1LKi8/mfIg== 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=B1EnhQpxzdq1GIcElCsvj1rntwwV7ItPVmtb3wEEy3o=; b=NQn9zoaxCNJdwXq5daafpH1bW8jCDPpCEAHC4cPLyptJZUNaBODuvT2hggfDsv9BRnWegbCoC6brj/GFTFxsJx0/osrMrutTEhDT7XPl9ptmxAXlqQjxGasZhMW9I3kQCRDuN8hwdzhmYC/bUOhmnvFlL6aILJ4wupnMLhPaJxAjXBxcGyca/69+lQUwXzn88PH1lko19YvkifIllHDHF58oTD9H79g2dFwmOekTo1HfRoqKmv3OH15z4U0Zz7+uMfGdO+eGnn1zYtGdUAEcG3kjSMehBJDSjlE7hWBMTJVMWkDBOkEtHXOEXlqV0772zwdCuVkUs2+aiWvd5JWG8A== 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=B1EnhQpxzdq1GIcElCsvj1rntwwV7ItPVmtb3wEEy3o=; b=R3PSfHZ/NI0SrVYpf/UW5v6lJYkBXOgkPcbRulniHmrVayMLV6KUKmRomXsGurDQNO6nmtlLcxqQf7eggq5bvf5javU9bnb6PpnWMJwk5zKM+G1ZXD5GswYJE8P1JYUw9EugvWfvxvE8HFM+02YMtAQ8wFa8e7uqR5sV9sfBUcQ= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu , Ian Jackson Subject: [PATCH 2/2] x86/cpuid: support LFENCE always serializing CPUID bit Date: Wed, 14 Apr 2021 13:04:33 +0200 Message-ID: <20210414110433.83084-3-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: MR2P264CA0090.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::30) 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: f4aa7328-fb6c-4bc9-f492-08d8ff353805 X-MS-TrafficTypeDiagnostic: DM5PR03MB2842: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oSMXqTgXK/2y5I1QYAiJfS8Xh0QQZ6omwSzhfhWdb3LXB+sNj0iOuTj8hMIEdPXoBVQb7lVccXMjHTWitypnXczD8bAKVphq7hCfAcqrfWX1LnOXRnGlOCften69mU6D5a6dO/QJc5R26EYAT8HG2LRs9mdzt2yIti3uFXpTsHhxslhAAnLYBO4sMtK1DxP3Wc391nU02p7g5pFs9/eFRrUIOAghocJcKItoZY0D1la8/3p623DtK6VB8p2qkUlUUK7EZ07bey1aBo5oauVDnpJivo7DIqT2KQ0JEfwsXukAYQIgOLtjK8H99wrh2n4cyvHGAd8iL+MouIMjUUfNdKGcSS/Fu3thJD8fFvdQrHRxCg2ZwAs7aM+EVNsG8tp2OoDWED/yK6Mot8ncSfDmODX7AvTM/e18z6aF46uT6vQxhlynCHxv+jRSfiOd45lqvH1TrZbFF0CblpEdTE57lWQf9dE1m2aClI3hxmKDKcwqzcJVykbR5Ak50XZ52jkdLG6SujRTk3gmfYi6NPY/amct2mUa5w9uwSajn4A/qa5e4ZE1OP9vaKHsJbGrevqHLwMswCcp4lXGSvbPlMy5iajm3BNryBd1eatqVvn0VYs= 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)(16526019)(26005)(36756003)(5660300002)(1076003)(2906002)(66946007)(66556008)(66476007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?S2RZcXBFQUp1UjM3b2lMN2tGVXZzaXZyekhNVFZoVWc3aHZkempXcnYzUEN4?= =?utf-8?B?c2kzUjVFS2lYbytzVTIxUlhoa3J0ZDVIY3V4bWMwRkNiZFliZEFpWUh0djBr?= =?utf-8?B?RnNDbFI5RURHc0lFMUdSVzVBdXlnblNZM1BGdGhEWDZSNHN2eVA5VktmMmQ1?= =?utf-8?B?QTNwYkFtVFEvZWZ6V2V1WHVocStPUHlBNzFrVVpVdEVkMEtwcFJmYUNjUHNY?= =?utf-8?B?cUxVVGVrNFlJWEdDUGMxYnV6aUJCcVdUanV3eHBXa0VBZ21CNzh1OEQzZDIr?= =?utf-8?B?VFZBQnJveFF2OGo4bG5hQXdON2QvYWFnZzdLcnM4V2prVGMyVlBydlM3d2V5?= =?utf-8?B?RkFuc2lrODhodEVoeUdrcnJmMnhCdFVMSGxGMjYzMCtwUWs1NFB2cFQzQ3lV?= =?utf-8?B?OVc0L0dnWmdsdmg3TGZ0ZjU5c3ZoK0VHbVdNcW81QU5yTmxtYnRCSFY5TmJw?= =?utf-8?B?ZDlrMW5WK1ZVV1RSWXk2eTJsVkUxRVQxbXFJOFJPU1dqSC9DaUFiK2dGVlkr?= =?utf-8?B?bVRya0JjbHlTYWhhYjhRRVZPaWx2R1hrTURWcVFSRkd4RTkrWmZGQ1Q4Vi9z?= =?utf-8?B?NkRHOG82Wm4zMDhLcCs5YjFCRTRRWG9US29nWkkyS0JyUTlUeVdFOTFXVDNh?= =?utf-8?B?Q1JydDdQZWtaVE1lYk1xbzNNOHV1YTNkMlVrVGo2T0xLYkw5WkZjR0IwemJ0?= =?utf-8?B?M2dBMlUzWDFBTC9NMkpFYnJ5a29CY0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UjdLRHVIWGNNbjdGYzltaHVqSW1SYnc3QStkcHkx?= =?utf-8?B?S1dzMGhCbWVYbm1NTlY5SWkvYWJkR1F1aXRYaURTWGRiUDluMlBDQUE2bTVt?= =?utf-8?B?d3UxYkN2RUZwemhYd2JYNjVYWHpyb1ovemxKMTQzQStlV0EyOE44V21JY3lw?= =?utf-8?B?dm9sWGxnQ3MrSFZVQ0hrQT09?= X-MS-Exchange-CrossTenant-Network-Message-Id: f4aa7328-fb6c-4bc9-f492-08d8ff353805 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:31.2244 (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: BrzGwf3Zy8E9CPAeQhrU0fDWwzZeh/ekpKJzd4OXOPqDtZu4kr6cEbqxsXMb1GGnj6Kruqntdn5ik0Lel2uWHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2842 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Milan AMD CPUs have an LFENCE Always Serializing CPUID bit in leaf 80000021.eax. Previous AMD versions used to have a user settable bit in DE_CFG MSR to select whether LFENCE was dispatch serializing, which Xen always attempts to set. In order to support this new CPUID bit move the LFENCE_DISPATCH synthetic CPUID bit to map the hardware bit (leaving a hole in the synthetic range) and either rely on the bit already being set by the native CPUID output, or attempt to fake it in Xen by modifying the DE_CFG MSR. This requires adding one more entry to the featureset to support leaf 80000021.eax. The bit is exposed to guests by default, as a way to signal that LFENCE is always serializing, either because it's mandated by hardware, or because Xen has performed the necessary arrangements. Note that Xen doesn't allow guests to change the DE_CFG value, so once set by Xen LFENCE will always be serializing. Note that the access to DE_CFG by guests is left as-is: reads will unconditionally return LFENCE_SERIALISE bit set, while writes are silently dropped. The MSR is not present on AMD Milan hardware, but I'm not sure there's any value in adding logic in Xen to also hide it from guests when running on such hardware. Suggested-by: Andrew Cooper Signed-off-by: Roger Pau Monn=C3=A9 --- tools/misc/xen-cpuid.c | 6 ++++ xen/arch/x86/cpu/amd.c | 7 ++++ xen/arch/x86/cpu/common.c | 3 ++ xen/include/asm-x86/cpufeatures.h | 2 +- xen/include/public/arch-x86/cpufeatureset.h | 3 ++ xen/include/xen/lib/x86/cpuid.h | 37 ++++++++++++++++++++- 6 files changed, 56 insertions(+), 2 deletions(-) diff --git a/tools/misc/xen-cpuid.c b/tools/misc/xen-cpuid.c index 2d04162d8d8..38406baadad 100644 --- a/tools/misc/xen-cpuid.c +++ b/tools/misc/xen-cpuid.c @@ -178,6 +178,11 @@ static const char *const str_7a1[32] =3D [ 4] =3D "avx-vnni", [ 5] =3D "avx512-bf16", }; =20 +static const char *const str_e21a[32] =3D +{ + [ 2] =3D "lfence-always-serializing", +}; + static const struct { const char *name; const char *abbr; @@ -195,6 +200,7 @@ static const struct { { "0x80000008.ebx", "e8b", str_e8b }, { "0x00000007:0.edx", "7d0", str_7d0 }, { "0x00000007:1.eax", "7a1", str_7a1 }, + { "0x80000021.eax", "e21a", str_e21a }, }; =20 #define COL_ALIGN "18" diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c index 9c8dcd91eef..35f22c24762 100644 --- a/xen/arch/x86/cpu/amd.c +++ b/xen/arch/x86/cpu/amd.c @@ -646,6 +646,13 @@ void amd_init_lfence(struct cpuinfo_x86 *c) { uint64_t value; =20 + /* + * Some hardware has LFENCE dispatch serializing always enabled, + * nothing to do on that case. + */ + if (test_bit(X86_FEATURE_LFENCE_DISPATCH, c->x86_capability)) + return; + /* * Attempt to set lfence to be Dispatch Serialising. This MSR almost * certainly isn't virtualised (and Xen at least will leak the real diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index e5c3caf41d5..0eb364f8a65 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -412,6 +412,9 @@ static void generic_identify(struct cpuinfo_x86 *c) if (c->extended_cpuid_level >=3D 0x80000008) c->x86_capability[cpufeat_word(X86_FEATURE_CLZERO)] =3D cpuid_ebx(0x80000008); + if (c->extended_cpuid_level >=3D 0x80000021) + c->x86_capability[cpufeat_word(X86_FEATURE_LFENCE_DISPATCH)] + =3D cpuid_eax(0x80000021); =20 /* Intel-defined flags: level 0x00000007 */ if ( c->cpuid_level >=3D 0x00000007 ) { diff --git a/xen/include/asm-x86/cpufeatures.h b/xen/include/asm-x86/cpufea= tures.h index d7e42d9bb6a..6c8f432aee4 100644 --- a/xen/include/asm-x86/cpufeatures.h +++ b/xen/include/asm-x86/cpufeatures.h @@ -24,7 +24,7 @@ XEN_CPUFEATURE(APERFMPERF, X86_SYNTH( 8)) /* APERF= MPERF */ XEN_CPUFEATURE(MFENCE_RDTSC, X86_SYNTH( 9)) /* MFENCE synchronizes RD= TSC */ XEN_CPUFEATURE(XEN_SMEP, X86_SYNTH(10)) /* SMEP gets used by Xen = itself */ XEN_CPUFEATURE(XEN_SMAP, X86_SYNTH(11)) /* SMAP gets used by Xen = itself */ -XEN_CPUFEATURE(LFENCE_DISPATCH, X86_SYNTH(12)) /* lfence set as Dispatch= Serialising */ +/* Bit 12 - unused. */ XEN_CPUFEATURE(IND_THUNK_LFENCE, X86_SYNTH(13)) /* Use IND_THUNK_LFENCE */ XEN_CPUFEATURE(IND_THUNK_JMP, X86_SYNTH(14)) /* Use IND_THUNK_JMP */ XEN_CPUFEATURE(SC_BRANCH_HARDEN, X86_SYNTH(15)) /* Conditional Branch Har= dening */ diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/publ= ic/arch-x86/cpufeatureset.h index a5014798209..c67cd07b26b 100644 --- a/xen/include/public/arch-x86/cpufeatureset.h +++ b/xen/include/public/arch-x86/cpufeatureset.h @@ -277,6 +277,9 @@ XEN_CPUFEATURE(SSBD, 9*32+31) /*A MSR_SPEC_CT= RL.SSBD available */ XEN_CPUFEATURE(AVX_VNNI, 10*32+ 4) /*A AVX-VNNI Instructions */ XEN_CPUFEATURE(AVX512_BF16, 10*32+ 5) /*A AVX512 BFloat16 Instructions */ =20 +/* AMD-defined CPU features, CPUID level 0x80000021.eax, word 11 */ +XEN_CPUFEATURE(LFENCE_DISPATCH, 11*32+ 2) /*A LFENCE always serializin= g */ + #endif /* XEN_CPUFEATURE */ =20 /* Clean up from a default include. Close the enum (for C). */ diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpui= d.h index f4ef8a9f2f0..a4d254ea96e 100644 --- a/xen/include/xen/lib/x86/cpuid.h +++ b/xen/include/xen/lib/x86/cpuid.h @@ -15,6 +15,7 @@ #define FEATURESET_e8b 8 /* 0x80000008.ebx */ #define FEATURESET_7d0 9 /* 0x00000007:0.edx */ #define FEATURESET_7a1 10 /* 0x00000007:1.eax */ +#define FEATURESET_e21a 11 /* 0x80000021.eax */ =20 struct cpuid_leaf { @@ -84,7 +85,7 @@ const char *x86_cpuid_vendor_to_str(unsigned int vendor); #define CPUID_GUEST_NR_TOPO (1u + 1) #define CPUID_GUEST_NR_XSTATE (62u + 1) #define CPUID_GUEST_NR_EXTD_INTEL (0x8u + 1) -#define CPUID_GUEST_NR_EXTD_AMD (0x1cu + 1) +#define CPUID_GUEST_NR_EXTD_AMD (0x21u + 1) #define CPUID_GUEST_NR_EXTD MAX(CPUID_GUEST_NR_EXTD_INTEL, \ CPUID_GUEST_NR_EXTD_AMD) =20 @@ -264,6 +265,38 @@ struct cpuid_policy }; uint32_t nc:8, :4, apic_id_size:4, :16; uint32_t /* d */:32; + + uint64_t :64, :64; /* Leaf 0x80000009. */ + uint64_t :64, :64; /* Leaf 0x8000000a - SVM rev and features. = */ + uint64_t :64, :64; /* Leaf 0x8000000b. */ + uint64_t :64, :64; /* Leaf 0x8000000c. */ + uint64_t :64, :64; /* Leaf 0x8000000d. */ + uint64_t :64, :64; /* Leaf 0x8000000e. */ + uint64_t :64, :64; /* Leaf 0x8000000f. */ + uint64_t :64, :64; /* Leaf 0x80000010. */ + uint64_t :64, :64; /* Leaf 0x80000011. */ + uint64_t :64, :64; /* Leaf 0x80000012. */ + uint64_t :64, :64; /* Leaf 0x80000013. */ + uint64_t :64, :64; /* Leaf 0x80000014. */ + uint64_t :64, :64; /* Leaf 0x80000015. */ + uint64_t :64, :64; /* Leaf 0x80000016. */ + uint64_t :64, :64; /* Leaf 0x80000017. */ + uint64_t :64, :64; /* Leaf 0x80000018. */ + uint64_t :64, :64; /* Leaf 0x80000019 - TLB 1GB Identifiers. */ + uint64_t :64, :64; /* Leaf 0x8000001a - Performance related in= fo. */ + uint64_t :64, :64; /* Leaf 0x8000001b - IBS feature informatio= n. */ + uint64_t :64, :64; /* Leaf 0x8000001c. */ + uint64_t :64, :64; /* Leaf 0x8000001d - Cache properties. */ + uint64_t :64, :64; /* Leaf 0x8000001e - Extd APIC/Core/Node ID= s. */ + uint64_t :64, :64; /* Leaf 0x8000001f - AMD Secure Encryption.= */ + uint64_t :64, :64; /* Leaf 0x80000020 - Platform QoS. */ + + /* Leaf 0x80000021 - Extended Feature 2 */ + union { + uint32_t e21a; + struct { DECL_BITFIELD(e21a); }; + }; + uint32_t /* b */:32, /* c */:32, /* d */:32; }; } extd; =20 @@ -293,6 +326,7 @@ static inline void cpuid_policy_to_featureset( fs[FEATURESET_e8b] =3D p->extd.e8b; fs[FEATURESET_7d0] =3D p->feat._7d0; fs[FEATURESET_7a1] =3D p->feat._7a1; + fs[FEATURESET_e21a] =3D p->extd.e21a; } =20 /* Fill in a CPUID policy from a featureset bitmap. */ @@ -310,6 +344,7 @@ static inline void cpuid_featureset_to_policy( p->extd.e8b =3D fs[FEATURESET_e8b]; p->feat._7d0 =3D fs[FEATURESET_7d0]; p->feat._7a1 =3D fs[FEATURESET_7a1]; + p->extd.e21a =3D fs[FEATURESET_e21a]; } =20 static inline uint64_t cpuid_policy_xcr0_max(const struct cpuid_policy *p) --=20 2.30.1