From nobody Sat Nov 30 00:46:35 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=1618498112; cv=pass; d=zohomail.com; s=zohoarc; b=Ia8IdRygo+SxBtUI2csMwP1G1oYOTqWzquZmAHYaurdNN2oYbfcUzHHaRgNlPd4QXpE6LzyY/vn8RU0vxRdGtcHZUEtcgw0u8kdARXXeOXqVw1pQYz7H/YD15D1M6Xfsb++JtNWM+OajrVVMvDDajbTldu3qyxYgieg4Ttl0Gec= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618498112; 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=UwyYue/XhqLfsb2rqRAARfa6x/vmze08A9OfANytI5g=; b=GBn4pIwpNt1X+kzYNbTTbei9+i5mCU13U0U+cZwhgdj2emh6aE7pO17bSRHbQdhn0uEZa1JUnRtTomtVlHEpnkJMAaUgF/Fb+zmAbGVfMBuRHGj11URWNnXkBfsAEvAwriyqqLbATE91k3MY5ZNTafDwCFA58FEeq9wrY3YUG5Q= 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 1618498112382566.4334864548248; Thu, 15 Apr 2021 07:48:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.111328.212939 (Exim 4.92) (envelope-from ) id 1lX3I1-00033G-Ka; Thu, 15 Apr 2021 14:48:17 +0000 Received: by outflank-mailman (output) from mailman id 111328.212939; Thu, 15 Apr 2021 14:48:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lX3I1-000339-HD; Thu, 15 Apr 2021 14:48:17 +0000 Received: by outflank-mailman (input) for mailman id 111328; Thu, 15 Apr 2021 14:48:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lX3I0-00032q-On for xen-devel@lists.xenproject.org; Thu, 15 Apr 2021 14:48:16 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 636f3f57-afef-4453-82f4-e8ec4e66ea69; Thu, 15 Apr 2021 14:48:15 +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: 636f3f57-afef-4453-82f4-e8ec4e66ea69 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1618498095; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=cd3CoYPuX3aw4POTIwakPsHJdWcXzR23STMzF2A8Gxg=; b=dxZCOVXaztatAZycjsW7KWiGOhFLnrceOx2KJaVtIRtHGi8fiAq8nwlp mLxL2/jFqLQAT7lcQQrOboIrT7NkDiI1dDlUJdmUxp8CZQZt2Xz/Sl8Mh Rn/Uxr/cTnjBSlJFWjipcFM2WtszYeF0bXvhky4Z9QDGgnPxob4QQsB3R 8=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: MSxrH3aSPgtVH+NdE4xYn9oXog9R0vvuNeeioSsvCurZ58i3UO1iu4ue43Ag/7/fOuIUqH0WaZ 6Oh5lK98YuqloLN8CDhO4fgxDOROOzdvbUHTrAw7oRbf6HoYkFyJE+xu13tOBITEI8itT0loBd /HL5ChFlWeD0s6n12931fccHJ10MmHxLYIRGyzuI/rhOs7qYswW45oKoYo78/b9MX0Fwsg32O3 jYtg0Ixp+mBA52sd0YozhJKeal30rucfXMUJIoWDtUOGmyOM3Y79Mpf/ntkocydlIZHpdP6zqw o/8= X-SBRS: 5.2 X-MesageID: 42063248 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:7GzHpq3tLbHCxB2Q/wjQxgqjBTd3eYIsi2QD101hICF9Wvez0+ izgfUW0gL1gj4NWHcm3euNIrWEXGm0z/FIyKErF/OHUBP9sGWlaLtj44zr3iH6F0TFmtJ1/Z xLN5JzANiYNzVHpO7n/Qi1FMshytGb8KauwdzT1WtpUBsCUcBdxi1SYzzrdnFebg9AGJY/Cd 6g/cJBvTWtYjA6ac68C3kDUYH41qH2vbjhZgMLAANi1RmWgVqTmcPHOjW7/jNbaTNAxr8+7X PI+jaW2oyPu+y2oyWssVP7wI9RnLLau7l+LeyKzvMYMzD9zjuvDb4RIIGqmBAQjKWR5E0xkN /Kyi1QT/hbz3/KZGm6rV/M9mDboU8TwkTvw1OZnnfvyPaRLFlRa7sj9PBkWyDU5EY6sNZ33L gj5RPii7NtAQ7dhyO43tDUVnhR5zuJiEA/mu0ehWE3a/p4VJZtq+UkjSZoOaZFNif75Ic7Kf JpHcHR6d1HGGnqE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Ye27Z3w/X1AELb55mwiKCQcmoBhiLFvMN29umOU6Uiq/v2fWNtl7MOHKGQnVdo5 ZEe0wWZtlCjTdnrLRf6FnMdoXH5mQ/k1Vf5jl7kEXKwYbO2haDIX17 X-IronPort-AV: E=Sophos;i="5.82,225,1613451600"; d="scan'208";a="42063248" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eu3d2bpmFRGe6lIT2/uzTKh+x+7uSTvY9+by+wK49IVfnGA/FpG0RFmiw6tf7ODc5UnVmxyFPKsKw4fPckivj3LCOu564Odwtamit3NcJgy8iHAgw0QitA6pjyuPYA8Qw0RPLWFIbLqv5NiiyXMwca4ezXIN18KchTa6KV/1/7Xj9TpcJWjmZ538wHFdgh5cxbeM2UABRIa6erOSsujRHbNyY/1f9dS6OXeB+gEu9l9mA4+999KdxezLhnI0BHlG2F0Pg9u5ycHhTAYcZ6cvJK593OqQrjbkjeuZHUDx4EidyrrE5b0In2jVn44WRzl7xmLOTlkEPC1h0EDc2BOQBw== 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=UwyYue/XhqLfsb2rqRAARfa6x/vmze08A9OfANytI5g=; b=em+XRa27kQZBPzF/kO2KzlZTx1K76oBJGlXrNoPKJ6A0G/A+qnd5ThmhV0aDV8+D7Qz/Vf7YmH0AOO0pbv2EA7X4Z0PIP9JqoOduyV/FwS6yNPPi+UYtUiL8HPPcX/6YNti6P4VQHQ6+4vgxsxDhRwLXkyOmPyxk/1+lXhVMbbY3gNDkCR+tOWZjlN1xt6Ho/iAFmyl9/J2pekEBXA9ONetA3kphWorkupbMtqptDl8h1iZpo6ZJeniBkCRFVXs6zMXxd0M/TPy+m4/B7jiMHOrCDbkogO/vpp+lakisyJbqtUFHgnVpmOkeEDFys7DfpvuelVKkvxzFQCdBWg6umA== 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=UwyYue/XhqLfsb2rqRAARfa6x/vmze08A9OfANytI5g=; b=JwGj4kzlXyu9mS9h8m4BqHSxtisGu16lf2P4AQa+4Vf8hZ44XF2NsQ8hqxiQBsUzpgEMm3gysU2QRAbHWgjBCSBlGll+5Rra3XDZXemw0oTyPfEfu1c+4oKrENmK0SmlyGINd7msTyxKl4V6jKKzJjq9B4IGnF/L65bDfx4K3P0= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v2 1/2] x86/amd: split LFENCE dispatch serializing setup logic into helper Date: Thu, 15 Apr 2021 16:47:30 +0200 Message-ID: <20210415144731.3356-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210415144731.3356-1-roger.pau@citrix.com> References: <20210415144731.3356-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0034.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500::22) 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: c9f4d596-5332-45fe-6375-08d9001d7c91 X-MS-TrafficTypeDiagnostic: DM5PR03MB2843: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rHN73m3+DJp2fBe1TB3iF6vCRhrih70InOCOrLA6exbXz8hRwh1FltfpoZwyBkh4NTcOnulf4hsAAEwZUS42TG7i18iZPzO8ir+VhoGfHPdqGPGwBf6mBbbr89mS99xaX1t3OAzh3I3R+FfSGJOt6Kjt+gssXfbx7mEvPlbyb94iwwPvsxv0ZT5UezuxSNMlOH7FFHN8n5QU3ixlNtlv/usij77vfc2KpnFjvI8tnwGBjHMx2AuDwab4Thm7cK6fAV9xp6GcfBhsez8C+pLLOs8gg44Xby6GXX50UqsZZItyU5g6+STfpFGdcrKzQKAy707C3FHkTazp1F2PQsqH9H9ZIoMbxufYxqXSx4Rr7iV5ePMEMl9MvBX+Git+j8Ui3x8m8y4Dq0XjtijiT16DrngOSfG0ysuqirV22qEqtTCuar8RhtS7ZvVcUFeqj0O80aLbVYzTI8avAC28LZHdLVS6RwBukA/nyeU1ctOh6kK+lMiXaB95wJ5JZFtPhCiJmwcO8MLUkqZPeIfdtn9gN/5tf9JMO74AYrYQUR2FYcsDUga9qFBUq1t9TVGkHEJZvoR7ZaSunRYuvkp0QdvZWYO3DMTvXl+O3vjHrPV6Iuw= 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)(346002)(396003)(366004)(376002)(39860400002)(136003)(956004)(478600001)(38100700002)(8676002)(6666004)(5660300002)(1076003)(8936002)(66946007)(2616005)(66476007)(66556008)(26005)(2906002)(6496006)(6916009)(6486002)(83380400001)(36756003)(4326008)(86362001)(316002)(54906003)(16526019)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?Y3kvYTEzdU9paHZheVlUaXFQZ0hUVzdVUDdGWHlML3VRY2h4akx3ZWp5U2wy?= =?utf-8?B?dGJEOFN6L0J2UmgvN05rZDl5S2Rlc1JvcTY5Yzlkb0crd0l2MXJEYjRwRDFh?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ource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 14:48:09.4640 (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: IoA1qmNjF0fG0R8JKbabjlhkNO2NGEV9Mq53HYwTeXkGmYWE0xCcYP+phEHhjr14CcqMMjyl0HKxExckm8d66A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2843 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Split the logic to attempt to setup 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 --- Changes since v1: - Fix typo in commit message. --- 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 00:46:36 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=1618498118; cv=pass; d=zohomail.com; s=zohoarc; b=U8BkxWImqmtSY9xcwYa+KW6CFG/Bve4ZlcGzcRWD78M4SQjcXc5zb0TdOYe49PP5+neLZOrHc2GrMhiE1OSxWCxnaXPqo2jeKslj1GLBbBcDNU3ViFQ2sJi0Z4wGZQiT4H6R9WGyBvWZwTNLEu1mqVob8AL3/LNOyXCqMxp+HvY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618498118; 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=JOwBr5KtW140gDg1QrHVd6cRRXtjGL3eSjcb7YdoXo4=; b=PuJP5IuuLi8np4feu9JL6pomYrvVylOVgCnv8VaaGAJvN5vBxirdBctYUdz+zmeu2dArgPvhXcQKVxVYp7hbcbBPnbC7wl5c4VN4DH+BRO7t2CX5L9p41+srG66KUPanTjYrF2BCYSBletYxhN025S1w4EUt9BQy8u8OdNUkVRI= 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 1618498118313212.00785396935464; Thu, 15 Apr 2021 07:48:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.111329.212951 (Exim 4.92) (envelope-from ) id 1lX3I7-00037X-6V; Thu, 15 Apr 2021 14:48:23 +0000 Received: by outflank-mailman (output) from mailman id 111329.212951; Thu, 15 Apr 2021 14:48:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lX3I7-00037O-25; Thu, 15 Apr 2021 14:48:23 +0000 Received: by outflank-mailman (input) for mailman id 111329; Thu, 15 Apr 2021 14:48:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lX3I5-00032q-MK for xen-devel@lists.xenproject.org; Thu, 15 Apr 2021 14:48:21 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ba634281-d9ce-4cc2-95b1-2ebe5457b840; Thu, 15 Apr 2021 14:48:16 +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: ba634281-d9ce-4cc2-95b1-2ebe5457b840 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1618498096; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Kunq9PfgxSdHoMHI/h5eyL0p/6ZQDQ9CXx7r1toiMfM=; b=RpTca5FHx9WpZjxlLdlAE5XQJyhdj/5Xz2g94icGZ0DcXK8dD/0Sx8v6 j2ya/9rNGI04zI2bZ1ngOjn2FdR2FWPpw6CgbKon0u/0TjT6VqfXkQZuH i4DG8vPDsGrZ4XBxseTcOc7cnurCYcojCU4Bxt4DaQ6rbVDTBY97T5Vna 8=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: FEbPpeL8df1hy1rsFcLMO3YI3udxTCCFg6dhO9v9eOznpAVdz5FcHV4sl7P15zEZq8dR8UHZmA OvVgbiklyasegMrCVPZ0+x7GDO/3i8ggPe31C0tmhr6si9Z0ZKyR7z5d/tost+Drcc96iOTJt9 be1hmZznwyNwE1ZwWa0N1tEu8vEhId4Uwpfk2GJYQyLL5nTvQmhgiHIrLMw2EKEDCj/5AdpJfy O5XTRqlP6jBL7uUuAUs+kgz5z3Q4stViB3ivKZOVQBmJsdCN5Z2K9FALYFxmGr70oXElkUqkhO leA= X-SBRS: 5.2 X-MesageID: 42063254 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:tc1wfqgoMcpzAgN7FZ4RXlguL3BQXzxw3DAbvn1ZSRFFG/Gwv/ uF2NwGyB75jysQUnk8mdaGfJKNW2/Y6IQd2+csFJ+Ydk3DtHGzJI9vqbHjzTrpBjHk+odmup tIW5NVTOf9BV0St6rHySGlDtctx8SG+qi0heHYi0xgVx1udrsI1WdEIyywe3cGIzVuL5w/CZ aa+457vDKmY3sadYCWAXMCUujFqbTw5e/bSDQBAAMq7xTLsCOw5NfBYmKl9zo9cxcK+7ct9m DZjxf0j5/Dj9iXwgLRvlWjlqh+t8DmzrJ4damxo+w0DhmptQqyfoRmXNS5zUEIicWi8kwjnt WJgzpIBbUK11rrcmu4oQTg1mD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ZdETcUtijy4UveXKCEMqtwDsa9VOBm0Fvjv+P9mT5aDPpqdqKkqdpBHoMV 33yVwXw971Gw+C36UdEaQ+PCB/b1U98m1r+Kene5fLAAunM8FF81zSCA72TJZtDIyEE64XtB B0/pWhmPKWbTPx3ETohgRAS5g+hVqPcIeVGwKDGelB7ty8NxCtu8KRkbKOpQaybyC6ZUQejZ BCbmoKYK14+38fsLE= X-IronPort-AV: E=Sophos;i="5.82,225,1613451600"; d="scan'208";a="42063254" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OL6HwFSEdUhn36uyypCEs90+eC/dHYiZx9cltDvjwN/dBSiUZAHYlyERN+G/jYAOYRTrh2LKi1ij3wwYSbHneArn48qpNCYLIJRgHwMclujQxAJjnM39np38qWbGTyzCtG7TQPkHHrg6chx8GS7glOjCFSRKyndbVnID1QoF2KUukRPZhC71Py1yOBdAfdNcFPdxN6JBRr7jldVhiuuAsoMgjA7ZYAMiSpbmdY2fW5kwQ0QAbos+palp2YwOam2EdH7gk98v230846gef7nFgvVnXURM3v58HJmU8mMzSgpCg4s/Q7tZQzqrvFGhJG8DErPRYu+MDUpRGg52q0tnJg== 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=JOwBr5KtW140gDg1QrHVd6cRRXtjGL3eSjcb7YdoXo4=; b=eg92DNrqdeaqo/mVLYLavp2KI7ptwOw8/4MYC2Su+8kQnSEk/Q571aaKDz8y9ZDlH7tJJiaNE5ZjYvaHMP7a/wifhVnAl/47MHOQzHyLWkZxjjnzGP/Tb4UjIX6uAM9HlvxqbzcldUqzRNg2nQ33eOaGaGUdsEDsUd6y8uE1uwX9JEw8eT8cpHymGV3LJ633jowmBjdkO2492tZm3c4nt0BaN927r3j/4XDsKIwVUo8Iw4VrS1/IMCbGq61MiqY3wQmArNNzdceP0UfYEJ/FCjPwi0bp3nD4fVWs3QFdqV4JY+99BBBM8+MJHgNyJSQUdE+kco3dP7t+PwsS72rr+w== 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=JOwBr5KtW140gDg1QrHVd6cRRXtjGL3eSjcb7YdoXo4=; b=m1CZ4Wuvv8pZfsX7eraohBhTXUZWpiBmZSCExXc2DeS2KoX7MJN2vvt716pWtUMgQrt2n2upxOQNzmt9X6GE+SHStJUV/iU7rWIJDu838oBlbGf42CslOryr4ZtYzKPJW1W6rf3C4mbqNFAVzGslVXGsebXrz97iCumzS5zM9Oo= From: Roger Pau Monne To: CC: Roger Pau Monne , Ian Jackson , Wei Liu , Anthony PERARD , Jan Beulich , Andrew Cooper Subject: [PATCH v2 2/2] x86/cpuid: support LFENCE always serializing CPUID bit Date: Thu, 15 Apr 2021 16:47:31 +0200 Message-ID: <20210415144731.3356-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210415144731.3356-1-roger.pau@citrix.com> References: <20210415144731.3356-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0122.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::14) 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: 5316dbc0-40a7-4017-02e3-08d9001d7f8d X-MS-TrafficTypeDiagnostic: DM6PR03MB5273: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VlxIf4Ami62kJKjfLvVpn/OvsqpY17gIJcFykPHUsUm4QuPD7r3kaZGKnrEgquO8pgWY7f7/Qxqtz8UTMuefHKiBjKoFa2MzXiL98rubL3WTiSlNQUaU7vP2PeMJmnm72NNww0X1C/zJlHyO+pyM6U7QQekTncUqFmeZ13xFUAQzD5ivTZ030bkjoiNLn8hWkbMa5yvZjD38J1DCrp5173KrU5jsMk7n/USgEQcGugRLVHPDjMOpCjswRElnTjDruiCvbjenDwKHKHxklcGh4eKF95SCCS7xy279KVF5Fti3iX98ZgfjapI24JJw2YxAGUNC6FO1s9hGgZBkfIGSFbg+8QqdJvpIdvR5d3ro5w5lSFd2d1Y2fweabMj/FqTCG/QZk9DC82kO+3pLU6wyj+yEU/dllzWilnPne1YDK6iw3GPn+Y+TJQ/MxYsiGHOyjtD9IC5Dlle4+B96y4QFgRzIrRxn4Cuti+n2sCrIKIRXA6Uatxz1kJ1Ohapi4RLKgJQ2TIs+Ce+kH+30EjpNEJlgt1+5hnyKT0R/EzMH4JCmMAHds6/48Pnwa4RGvnVil6tbxENusc0wD2XEbfvg+2H5GEHVax0UtHo/+ZKs2I0= 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)(396003)(39860400002)(136003)(366004)(376002)(346002)(66556008)(66476007)(4326008)(36756003)(6666004)(66946007)(478600001)(54906003)(38100700002)(5660300002)(1076003)(316002)(83380400001)(2616005)(6486002)(186003)(8676002)(6916009)(86362001)(16526019)(26005)(8936002)(107886003)(2906002)(956004)(6496006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?amdxckhEV3pOUG0wU3UycG4rWWNKRWx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09vV0JvTFNxa01qODB2dz09?= X-MS-Exchange-CrossTenant-Network-Message-Id: 5316dbc0-40a7-4017-02e3-08d9001d7f8d X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 14:48:14.4894 (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: 6iZpcfzhz5IGQSRCN/MXPHX0xucbqDzNUwyOs+uXxiKKb3+mBoM1ifIL92UiDJ2z/qD/74mlt7WZsrx5n9+Cvw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB5273 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) AMD Milan (Zen3) 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. The forcefully always on setting is due to the addition of SEV-SNP so that a VMM cannot break the confidentiality of a guest. 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 if the underlying hardware supports leaf 80000021, as a way to signal that LFENCE is always serializing. Hardware that doesn't have the leaf might also get the bit set because Xen has performed the necessary arrangements, but that's not yet exposed to guests. 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. Suggested-by: Andrew Cooper Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v1: - Rename to lfence+. - Add feature to libxl_cpuid.c. - Reword commit message. --- Note this doesn't yet expose the bit on hardware that doesn't support leaf 80000021. It's still TBD whether we want to hardcode this support manually, or instead rely on a more general approach like the one suggested by the shrink max CPUID leaf patch from Jan. --- tools/libs/light/libxl_cpuid.c | 2 ++ 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 ++++++++++++++++++++- 7 files changed, 58 insertions(+), 2 deletions(-) diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index aee28b0430d..d3ab66b9a71 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -284,6 +284,8 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *c= puid, const char* str) {"svm_decode", 0x8000000a, NA, CPUID_REG_EDX, 7, 1}, {"svm_pausefilt",0x8000000a, NA, CPUID_REG_EDX, 10, 1}, =20 + {"lfence+", 0x80000021, NA, CPUID_REG_EAX, 2, 1}, + {"maxhvleaf", 0x40000000, NA, CPUID_REG_EAX, 0, 8}, =20 {NULL, 0, NA, CPUID_REG_INV, 0, 0} diff --git a/tools/misc/xen-cpuid.c b/tools/misc/xen-cpuid.c index 628e8f5aa25..9a47237f4a8 100644 --- a/tools/misc/xen-cpuid.c +++ b/tools/misc/xen-cpuid.c @@ -179,6 +179,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+", +}; + static const struct { const char *name; const char *abbr; @@ -196,6 +201,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 42bc8d4279d..732990f2cc0 100644 --- a/xen/include/public/arch-x86/cpufeatureset.h +++ b/xen/include/public/arch-x86/cpufeatureset.h @@ -278,6 +278,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