From nobody Sat May 4 15:23:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1558540344; cv=none; d=zoho.com; s=zohoarc; b=RkA4yUYc/8PXrIpWb4fRIJN/tifx79k7XDCdg2HVa34ieOUwKVpp5JXR6GN+8DoYsIAt00HWEIkS6L5owIoKJZH8Lp+4IzxLbB7U3rmg+W2PnCT7RVuo0BEq3TaVXpw05yKGmT2a0jCASUYWU0FvCzPtv4xpzuYcdzqmmsAYWYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558540344; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=8FaquFbdNK6UonSylA0bjD/dM3hOswqVxnko01AHONA=; b=gRerpHR1Gc4mYLPecYu3lmn4ZdJpKZGAg4gF1WW41nAe6gVK1nk92A1sK8KzcXaZPu3a+3IfNzYhNmxTp5WrzD03QHLOQIDsZKL9PxqrFEY4POZ/XFS3x765Gcpe5i8iqHi932aUtvEpfGYr1fF3SUU2/0HRhGkK7q4+U2uO2Yo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1558540344621330.7164006781412; Wed, 22 May 2019 08:52:24 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hTTVl-0003Ft-5F; Wed, 22 May 2019 15:50:37 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hTTVj-0003Fo-PS for xen-devel@lists.xenproject.org; Wed, 22 May 2019 15:50:35 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 559127d6-7ca9-11e9-8980-bc764e045a96; Wed, 22 May 2019 15:50:34 +0000 (UTC) X-Inumbo-ID: 559127d6-7ca9-11e9-8980-bc764e045a96 Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@MIAPEX02MSOL02.citrite.net Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=23.29.105.83; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 23.29.105.83 as permitted sender) identity=mailfrom; client-ip=23.29.105.83; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:23.29.105.83 ip4:162.221.156.83 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@MIAPEX02MSOL02.citrite.net) identity=helo; client-ip=23.29.105.83; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@MIAPEX02MSOL02.citrite.net"; x-conformance=sidf_compatible IronPort-SDR: nWxL6doB0ETaufoBd8d0wuLB0tlrA8ehqJ+cEErDMEOR78mnVLNp//h/CXvA+F7trysnOQWLG6 hbWUMcujevosENXS70zhPg+Gyx43FZ9DlgRhQieuug0iYDZmpBc1Tm22+X19tOLF1xytjgd3bX F2xaSGlFEQot+T2vVAfyeO2fr4tCk3DfoHG5vtwN2yQIdEImG0bwBM2oVq1wkC/3YncU+/eoV8 2e6BGpBr3ziPYUg03ZJ6VRyU5XhcaRQWV4q77DzCfP22EuzF4Mmdk85APd4h38/Bv5JPukxwQt DXs= X-SBRS: 2.7 X-MesageID: 777540 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 23.29.105.83 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.60,499,1549947600"; d="scan'208";a="777540" From: Andrew Cooper To: Xen-devel Date: Wed, 22 May 2019 16:50:30 +0100 Message-ID: <1558540230-26612-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" x86_cpuid_copy_to_buffer() currently serialises the full content of the various subleaf unions. While leaves 4, 0xb and 0xd don't have a concrete max_subleaf field, they do have well defined upper bounds. Diffing the results of `xen-cpuid -p` shows the resutling saving: @@ -1,5 +1,5 @@ Xen reports there are maximum 114 leaves and 1 MSRs -Raw policy: 93 leaves, 1 MSRs +Raw policy: 38 leaves, 1 MSRs CPUID: leaf subleaf -> eax ebx ecx edx 00000000:ffffffff -> 00000016:756e6547:6c65746e:49656e69 @@ -32,7 +32,7 @@ Raw policy: 93 leaves, 1 MSRs MSRs: index -> value 000000ce -> 0000000080000000 -Host policy: 93 leaves, 1 MSRs +Host policy: 33 leaves, 1 MSRs CPUID: leaf subleaf -> eax ebx ecx edx 00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69 which is mostly due to no longer writing out 64 leaves for xstate when (on this CoffeeLake system) 8 will do. Extend the unit tests to cover empty and partially filled subleaf unions. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- tools/tests/cpu-policy/test-cpu-policy.c | 71 ++++++++++++++++++++++++++++= ++++ xen/lib/x86/cpuid.c | 24 ++++++++++- 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-pol= icy/test-cpu-policy.c index beced5e..fd96c0b 100644 --- a/tools/tests/cpu-policy/test-cpu-policy.c +++ b/tools/tests/cpu-policy/test-cpu-policy.c @@ -65,6 +65,77 @@ static void test_cpuid_serialise_success(void) .name =3D "empty policy", .nr_leaves =3D 4, }, + + /* Leaf 4 serialisation stops at the first subleaf with type 0. */ + { + .name =3D "empty leaf 4", + .p =3D { + .basic.max_leaf =3D 4, + }, + .nr_leaves =3D 4 + 4, + }, + { + .name =3D "partial leaf 4", + .p =3D { + .basic.max_leaf =3D 4, + .cache.subleaf[0].type =3D 1, + }, + .nr_leaves =3D 4 + 4 + 1, + }, + + /* Leaf 7 serialisation stops at max_subleaf. */ + { + .name =3D "empty leaf 7", + .p =3D { + .basic.max_leaf =3D 7, + }, + .nr_leaves =3D 4 + 7, + }, + { + .name =3D "partial leaf 7", + .p =3D { + .basic.max_leaf =3D 7, + .feat.max_subleaf =3D 1, + }, + .nr_leaves =3D 4 + 7 + 1, + }, + + /* Leaf 0xb serialisation stops at the first subleaf with type 0. = */ + { + .name =3D "empty leaf 0xb", + .p =3D { + .basic.max_leaf =3D 0xb, + }, + .nr_leaves =3D 4 + 0xb, + }, + { + .name =3D "partial leaf 0xb", + .p =3D { + .basic.max_leaf =3D 0xb, + .topo.subleaf[0].type =3D 1, + }, + .nr_leaves =3D 4 + 0xb + 1, + }, + + /* + * Leaf 0xd serialisation automatically has two leaves, and stops = the + * highest bit set in {xcr0,xss}_{high,low}. + */ + { + .name =3D "empty leaf 0xd", + .p =3D { + .basic.max_leaf =3D 0xd, + }, + .nr_leaves =3D 4 + 0xd + 1, + }, + { + .name =3D "partial 0xd", + .p =3D { + .basic.max_leaf =3D 0xd, + .xstate.xcr0_low =3D 7, + }, + .nr_leaves =3D 4 + 0xd + 1 + 1, + }, }; =20 printf("Testing CPUID serialise success:\n"); diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c index 23619c7..dcab1e7 100644 --- a/xen/lib/x86/cpuid.c +++ b/xen/lib/x86/cpuid.c @@ -242,7 +242,12 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_policy= *p, { case 0x4: for ( subleaf =3D 0; subleaf < ARRAY_SIZE(p->cache.raw); ++sub= leaf ) + { COPY_LEAF(leaf, subleaf, &p->cache.raw[subleaf]); + + if ( p->cache.subleaf[subleaf].type =3D=3D 0 ) + break; + } break; =20 case 0x7: @@ -254,13 +259,30 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_polic= y *p, =20 case 0xb: for ( subleaf =3D 0; subleaf < ARRAY_SIZE(p->topo.raw); ++subl= eaf ) + { COPY_LEAF(leaf, subleaf, &p->topo.raw[subleaf]); + + if ( p->topo.subleaf[subleaf].type =3D=3D 0 ) + break; + } break; =20 case 0xd: - for ( subleaf =3D 0; subleaf < ARRAY_SIZE(p->xstate.raw); ++su= bleaf ) + { + uint64_t xstates; + + COPY_LEAF(leaf, 0, &p->xstate.raw[0]); + COPY_LEAF(leaf, 1, &p->xstate.raw[1]); + + xstates =3D ((uint64_t)(p->xstate.xcr0_high | p->xstate.xss_h= igh) << 32); + xstates |=3D (p->xstate.xcr0_low | p->xstate.xss_l= ow); + + for ( xstates >>=3D 2, subleaf =3D 2; + xstates && subleaf < ARRAY_SIZE(p->xstate.raw); + xstates >>=3D 1, ++subleaf ) COPY_LEAF(leaf, subleaf, &p->xstate.raw[subleaf]); break; + } =20 default: COPY_LEAF(leaf, XEN_CPUID_NO_SUBLEAF, &p->basic.raw[leaf]); --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel