From nobody Wed Dec 4 08:28:44 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730224538; cv=none; d=zohomail.com; s=zohoarc; b=Gn5r/Kk+tgzwCEUti7YBY471ZSOnFgwTI20Y8UAMBQy6Pq84RaFxT9brxzf6zi9UPBGTiRjbr4PNJcezlqzreQf2USpTlqoCGvRiC7cBQdKF/vOlCpGYU8K0bV0sfz2DyArJRFY/05Z5CscjEtF2K7xkabY2EQGQxarjha58/lg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730224538; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6BbM7rIsfqQ52N4fxzS/e+HPw8oF6QxWBr66WOwuncM=; b=XgBIUZkMHP1Fkp4rKiJg7mcYar2Ol02kDleVCCJb+VqI1adVysLAupjU8hrDop8AyD/82Zrp0tk5H69dyLs7muVMHl+R0Vqrysx9uQT9OlXJQy+jy0DzfZnynbqESHeHxCO9K2MzbZS0sd5DQyVIe5MRSs2vu2TVzgUYdCb54ds= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730224538628467.3072090942161; Tue, 29 Oct 2024 10:55:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.827778.1242487 (Exim 4.92) (envelope-from ) id 1t5qR3-00032G-EI; Tue, 29 Oct 2024 17:55:17 +0000 Received: by outflank-mailman (output) from mailman id 827778.1242487; Tue, 29 Oct 2024 17:55: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 1t5qR3-000329-BS; Tue, 29 Oct 2024 17:55:17 +0000 Received: by outflank-mailman (input) for mailman id 827778; Tue, 29 Oct 2024 17:55:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5qR2-000321-He for xen-devel@lists.xenproject.org; Tue, 29 Oct 2024 17:55:16 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f010a9cc-961e-11ef-a0c3-8be0dac302b0; Tue, 29 Oct 2024 18:55:09 +0100 (CET) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5c9150f9ed4so7394016a12.0 for ; Tue, 29 Oct 2024 10:55:09 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f298dc4sm492024866b.124.2024.10.29.10.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 10:55:07 -0700 (PDT) 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: f010a9cc-961e-11ef-a0c3-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmQiLCJoZWxvIjoibWFpbC1lZDEteDUyZC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImYwMTBhOWNjLTk2MWUtMTFlZi1hMGMzLThiZTBkYWMzMDJiMCIsInRzIjoxNzMwMjI0NTA5LjQyMDM3OSwic2VuZGVyIjoiYW5kcmV3LmNvb3BlckBjbG91ZC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730224508; x=1730829308; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6BbM7rIsfqQ52N4fxzS/e+HPw8oF6QxWBr66WOwuncM=; b=Ohm34SP50Q6cWUVmFthjPRLyeG52WcNwWzZeUe7/IX3f6JW+r/3OT4N/w7e10U3KUq gF7i4Z1vzJmr+zR5v2A6p/EwtrvZrM22KxOeJvJ8WCSr4x4gHDJPpiMWTjUzdSOyfpBW GG1nDIDQOQYriRT9tDJSZ52tojTg/pcC4B0u8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730224508; x=1730829308; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6BbM7rIsfqQ52N4fxzS/e+HPw8oF6QxWBr66WOwuncM=; b=Jom6Y6f8SdPFRwAAy8n5FyDl/XVxqu1pBAvvIhZJ11Tj4IK+pIOXhvC66Sik4xpBHL PuxaMI5QuwuYYDcCrM/i8ThKbY0p/LAYuNbzauBLK+78W8/8dTHU1sxYOg8pRCsy2Hkk JfoCazoo/RnAANYF6hj0v0OyjH/2lTolAp2U4KmBPmUBzPRNEUA7uPw/GA3/GQFaXK0T lTjF3Hck9FjevvHl+n4CPmIOn3V6aHwqoeqiwj7O37OzNUoJI+zcTjl8xSCdGFRgsnS5 fVtIn6tGSIipUGoYKr2DD+gnb1lX0k4WsBYehbmnAcvblnBQvRgFkPTQ7i29yBLQlAcL pFrw== X-Gm-Message-State: AOJu0YzfdKvijHr8nQesLgRaxo7Qw0CaxZoE57uyQPWI9GRvj29vmbhY 6VpDZL4pE/LpYNefZ/QHzvxU/E1cL+lq1kdxEBdyrhMDc/D313pwgTZwKaJycyNeCvR6EDHAWXv 4 X-Google-Smtp-Source: AGHT+IEg7lSIABLWHp/uw50QoWD0z1BwMuRDbMkHCOcEo1M3MJqVQG4Svh0AYshqwL5vbQZcQYRFcA== X-Received: by 2002:a17:907:6eac:b0:a9a:7f91:8c76 with SMTP id a640c23a62f3a-a9de5a3e0ebmr1386332666b.0.1730224507968; Tue, 29 Oct 2024 10:55:07 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Alejandro Vallejo Subject: [PATCH] x86/cpu-policy: Extend the guest max policy max leaf/subleaves Date: Tue, 29 Oct 2024 17:55:05 +0000 Message-Id: <20241029175505.2698661-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1730224539486116600 We already have one migration case opencoded (feat.max_subleaf). A more recent discovery is that we advertise x2APIC to guests without ensuring that we provide max_leaf >=3D 0xb. In general, any leaf known to Xen can be safely configured by the toolstack= if it doesn't violate other constraints. Therefore, introduce guest_common_{max,default}_leaves() to generalise the special case we currently have for feat.max_subleaf, in preparation to be a= ble to provide x2APIC topology in leaf 0xb even on older hardware. Signed-off-by: Andrew Cooper Reviewed-by: Alejandro Vallejo Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Alejandro Vallejo On a KabyLake I have to hand, here's the delta in what xen-cpuid -p reports: git diff --no-index xen-cpuid-p-{before,after}.log diff --git a/xen-cpuid-p-before.log b/xen-cpuid-p-after.log index 5a76d05..24e22be 100644 --- a/xen-cpuid-p-before.log +++ b/xen-cpuid-p-after.log @@ -61,7 +61,7 @@ Host policy: 33 leaves, 2 MSRs index -> value 000000ce -> 0000000080000000 0000010a -> 000000000e000c04 -PV Max policy: 33 leaves, 2 MSRs +PV Max policy: 58 leaves, 2 MSRs CPUID: leaf subleaf -> eax ebx ecx edx 00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69 @@ -75,7 +75,7 @@ PV Max policy: 33 leaves, 2 MSRs 0000000d:00000000 -> 00000007:00000000:00000340:00000000 0000000d:00000001 -> 00000007:00000000:00000000:00000000 0000000d:00000002 -> 00000100:00000240:00000000:00000000 - 80000000:ffffffff -> 80000008:00000000:00000000:00000000 + 80000000:ffffffff -> 80000021:00000000:00000000:00000000 80000001:ffffffff -> 00000000:00000000:00000123:28100800 80000002:ffffffff -> 65746e49:2952286c:6f655820:2952286e 80000003:ffffffff -> 55504320:2d334520:30333231:20367620 @@ -87,7 +87,7 @@ PV Max policy: 33 leaves, 2 MSRs index -> value 000000ce -> 0000000080000000 0000010a -> 000000001c020004 -HVM Max policy: 35 leaves, 2 MSRs +HVM Max policy: 60 leaves, 2 MSRs CPUID: leaf subleaf -> eax ebx ecx edx 00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69 @@ -103,7 +103,7 @@ HVM Max policy: 35 leaves, 2 MSRs 0000000d:00000002 -> 00000100:00000240:00000000:00000000 0000000d:00000003 -> 00000040:000003c0:00000000:00000000 0000000d:00000004 -> 00000040:00000400:00000000:00000000 - 80000000:ffffffff -> 80000008:00000000:00000000:00000000 + 80000000:ffffffff -> 80000021:00000000:00000000:00000000 80000001:ffffffff -> 00000000:00000000:00000123:2c100800 80000002:ffffffff -> 65746e49:2952286c:6f655820:2952286e 80000003:ffffffff -> 55504320:2d334520:30333231:20367620 --- xen/arch/x86/cpu-policy.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/cpu-policy.c b/xen/arch/x86/cpu-policy.c index b6d9fad56773..78bc9872b09a 100644 --- a/xen/arch/x86/cpu-policy.c +++ b/xen/arch/x86/cpu-policy.c @@ -391,6 +391,27 @@ static void __init calculate_host_policy(void) p->platform_info.cpuid_faulting =3D cpu_has_cpuid_faulting; } =20 +/* + * Guest max policies can have any max leaf/subleaf within bounds. + * + * - Some incoming VMs have a larger-than-necessary feat max_subleaf. + * - Some VMs we'd like to synthesise leaves not present on the host. + */ +static void __init guest_common_max_leaves(struct cpu_policy *p) +{ + p->basic.max_leaf =3D ARRAY_SIZE(p->basic.raw) - 1; + p->feat.max_subleaf =3D ARRAY_SIZE(p->feat.raw) - 1; + p->extd.max_leaf =3D 0x80000000U + ARRAY_SIZE(p->extd.raw) - 1; +} + +/* Guest default policies inherit the host max leaf/subleaf settings. */ +static void __init guest_common_default_leaves(struct cpu_policy *p) +{ + p->basic.max_leaf =3D host_cpu_policy.basic.max_leaf; + p->feat.max_subleaf =3D host_cpu_policy.feat.max_subleaf; + p->extd.max_leaf =3D host_cpu_policy.extd.max_leaf; +} + static void __init guest_common_max_feature_adjustments(uint32_t *fs) { if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL ) @@ -579,11 +600,7 @@ static void __init calculate_pv_max_policy(void) =20 *p =3D host_cpu_policy; =20 - /* - * Some VMs may have a larger-than-necessary feat max_subleaf. Allow = them - * to migrate in. - */ - p->feat.max_subleaf =3D ARRAY_SIZE(p->feat.raw) - 1; + guest_common_max_leaves(p); =20 x86_cpu_policy_to_featureset(p, fs); =20 @@ -626,8 +643,7 @@ static void __init calculate_pv_def_policy(void) =20 *p =3D pv_max_cpu_policy; =20 - /* Default to the same max_subleaf as the host. */ - p->feat.max_subleaf =3D host_cpu_policy.feat.max_subleaf; + guest_common_default_leaves(p); =20 x86_cpu_policy_to_featureset(p, fs); =20 @@ -666,11 +682,7 @@ static void __init calculate_hvm_max_policy(void) =20 *p =3D host_cpu_policy; =20 - /* - * Some VMs may have a larger-than-necessary feat max_subleaf. Allow = them - * to migrate in. - */ - p->feat.max_subleaf =3D ARRAY_SIZE(p->feat.raw) - 1; + guest_common_max_leaves(p); =20 x86_cpu_policy_to_featureset(p, fs); =20 @@ -790,8 +802,7 @@ static void __init calculate_hvm_def_policy(void) =20 *p =3D hvm_max_cpu_policy; =20 - /* Default to the same max_subleaf as the host. */ - p->feat.max_subleaf =3D host_cpu_policy.feat.max_subleaf; + guest_common_default_leaves(p); =20 x86_cpu_policy_to_featureset(p, fs); =20 base-commit: 56bd76925ec35085528d778e46123b9d10a66018 --=20 2.39.5