From nobody Sat Nov 30 03:53: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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1620056411; cv=none; d=zohomail.com; s=zohoarc; b=QR3AlAP41AGFDhDHltijbfjKhmerAEXayRNUsyg6PwH7Qbqip/5H79dNNrGKPAa0Xqz5FyeF3t2MkufAC/zcI5AFowQNxh33z98xWfm2tyv7GK42XNed0eGUHEd1C11EclvZW7J55A74W6PXpnpph7WZj7O9/yy/2DCuTlIdSOg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620056411; 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=bdRuwXJKESIamgIyQcsUA3Q1omuWQ3UmWCbcyQxJuP0=; b=P2ADP92HmZvhm7UbkD5rVSKq9poTx1aRKInas3+9Z+fUdoLgTrp9lJZLUBjUdXEmdFrLueRmbYwMIJL3+lBcIU9kh+1FTwuqEL8KJq9u8I+70yzFlGBJpcN6VqskT9c4+iX/rbTuuK/XMe7PgjeJUcueCU6BBT8fsNr6ovWymjY= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620056411174155.78078577525332; Mon, 3 May 2021 08:40:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.121701.229550 (Exim 4.92) (envelope-from ) id 1ldaft-0001Do-Jf; Mon, 03 May 2021 15:39:57 +0000 Received: by outflank-mailman (output) from mailman id 121701.229550; Mon, 03 May 2021 15:39:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ldaft-0001Df-GH; Mon, 03 May 2021 15:39:57 +0000 Received: by outflank-mailman (input) for mailman id 121701; Mon, 03 May 2021 15:39:55 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ldafr-00019M-Qf for xen-devel@lists.xenproject.org; Mon, 03 May 2021 15:39:55 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c3bbfcf4-ecb2-4c99-a13a-5e390c53d09e; Mon, 03 May 2021 15:39:50 +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: c3bbfcf4-ecb2-4c99-a13a-5e390c53d09e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620056390; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UBDI32eRY/hcnx9jebSRvWF1wyrbcX7Hg6wiMTv7Ipw=; b=S8dCWq2rP7/xXKspjjOofl+wDIrtDuFJQLS8Hk6HU38vHvzkiyA+sLwJ sN07PFNNkPZ1RmeOR6/LEKzucLuw+eS8fvOan78RU9IKbMDd56Bx1auA3 8YmqwN7RlAfJb/69VjrNucZH9Pku+4cJZ3Wpl0j6tajNwbxyFxbqr7SCO c=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: H5HLuDGyqEByLnCPYbYjLdx7mfF/ERASTva30yvuQ1iok75tvfyaLNmFDOJjcdrg22kapJlzVo /DYx6XvBIdcuSXrsWC2CXKgZhZxazfprOKt5dQJz0I1bNkUPTPNQvfw2zrPiN7b+3OEUuUAmYo 0MkXfJgzwAeV8myO2Kx6f7EqhHyjn6qTUc9mdRVk8FsUxNRXBKZkMNicsQxj1HdFoAfUvv5+VF YdqFWwptXKqRhyk06x/iJkSd9+S4a7zYPcFkLhITqW6X+uOX6QhwuT+79ahopfezdA9puN9XoA oDg= X-SBRS: 5.1 X-MesageID: 43332332 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:KLSibKFGXtC7fUmdpLqEF8eALOonbusQ8zAX/mp2TgFYddHdqt C2kJ0guSPcpRQwfDUbmd6GMLSdWn+0z/VIyKQYILvKZmbbkUSyKoUK1+Xf6hntATf3+OIY9Y oISchDIfnxCVQ/ssrg+gm/FL8boeWvy6yjiefAw3oFd2gDAcxdxj1kAQWWGFAefngkObMFEv Onl696jgvlVXMLbtmqQlkpNtKzw+HjpdbdT1orJzNP0njtsQ+V X-IronPort-AV: E=Sophos;i="5.82,270,1613451600"; d="scan'208";a="43332332" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH 4/5] x86/cpuid: Simplify recalculate_xstate() Date: Mon, 3 May 2021 16:39:37 +0100 Message-ID: <20210503153938.14109-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210503153938.14109-1-andrew.cooper3@citrix.com> References: <20210503153938.14109-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) Make use of the new xstate_uncompressed_size() helper rather than maintaini= ng the running calculation while accumulating feature components. The rest of the CPUID data can come direct from the raw cpuid policy. All per-component data forms an ABI through the behaviour of the X{SAVE,RSTOR}* instructions, and are constant. Use for_each_set_bit() rather than opencoding a slightly awkward version of it. Mask the attributes in ecx down based on the visible features. This isn't actually necessary for any components or attributes defined at the ti= me of writing (up to AMX), but is added out of an abundance of caution. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu Using min() in for_each_set_bit() leads to awful code generation, as it prohibits the optimiations for spotting that the bitmap is <=3D BITS_PER_LO= NG. As p->xstate is long enough already, use a BUILD_BUG_ON() instead. --- xen/arch/x86/cpuid.c | 52 +++++++++++++++++-------------------------------= ---- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 752bf244ea..c7f8388e5d 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -154,8 +154,7 @@ static void sanitise_featureset(uint32_t *fs) static void recalculate_xstate(struct cpuid_policy *p) { uint64_t xstates =3D XSTATE_FP_SSE; - uint32_t xstate_size =3D XSTATE_AREA_MIN_SIZE; - unsigned int i, Da1 =3D p->xstate.Da1; + unsigned int i, ecx_bits =3D 0, Da1 =3D p->xstate.Da1; =20 /* * The Da1 leaf is the only piece of information preserved in the comm= on @@ -167,61 +166,44 @@ static void recalculate_xstate(struct cpuid_policy *p) return; =20 if ( p->basic.avx ) - { xstates |=3D X86_XCR0_YMM; - xstate_size =3D max(xstate_size, - xstate_offsets[X86_XCR0_YMM_POS] + - xstate_sizes[X86_XCR0_YMM_POS]); - } =20 if ( p->feat.mpx ) - { xstates |=3D X86_XCR0_BNDREGS | X86_XCR0_BNDCSR; - xstate_size =3D max(xstate_size, - xstate_offsets[X86_XCR0_BNDCSR_POS] + - xstate_sizes[X86_XCR0_BNDCSR_POS]); - } =20 if ( p->feat.avx512f ) - { xstates |=3D X86_XCR0_OPMASK | X86_XCR0_ZMM | X86_XCR0_HI_ZMM; - xstate_size =3D max(xstate_size, - xstate_offsets[X86_XCR0_HI_ZMM_POS] + - xstate_sizes[X86_XCR0_HI_ZMM_POS]); - } =20 if ( p->feat.pku ) - { xstates |=3D X86_XCR0_PKRU; - xstate_size =3D max(xstate_size, - xstate_offsets[X86_XCR0_PKRU_POS] + - xstate_sizes[X86_XCR0_PKRU_POS]); - } =20 - p->xstate.max_size =3D xstate_size; + /* Subleaf 0 */ + p->xstate.max_size =3D + xstate_uncompressed_size(xstates & ~XSTATE_XSAVES_ONLY); p->xstate.xcr0_low =3D xstates & ~XSTATE_XSAVES_ONLY; p->xstate.xcr0_high =3D (xstates & ~XSTATE_XSAVES_ONLY) >> 32; =20 + /* Subleaf 1 */ p->xstate.Da1 =3D Da1; if ( p->xstate.xsaves ) { + ecx_bits |=3D 3; /* Align64, XSS */ p->xstate.xss_low =3D xstates & XSTATE_XSAVES_ONLY; p->xstate.xss_high =3D (xstates & XSTATE_XSAVES_ONLY) >> 32; } - else - xstates &=3D ~XSTATE_XSAVES_ONLY; =20 - for ( i =3D 2; i < min(63ul, ARRAY_SIZE(p->xstate.comp)); ++i ) + /* Subleafs 2+ */ + xstates &=3D ~XSTATE_FP_SSE; + BUILD_BUG_ON(ARRAY_SIZE(p->xstate.comp) < 63); + for_each_set_bit ( i, &xstates, 63 ) { - uint64_t curr_xstate =3D 1ul << i; - - if ( !(xstates & curr_xstate) ) - continue; - - p->xstate.comp[i].size =3D xstate_sizes[i]; - p->xstate.comp[i].offset =3D xstate_offsets[i]; - p->xstate.comp[i].xss =3D curr_xstate & XSTATE_XSAVES_ONLY; - p->xstate.comp[i].align =3D curr_xstate & xstate_align; + /* + * Pass through size (eax) and offset (ebx) directly. Visbility of + * attributes in ecx limited by visible features in Da1. + */ + p->xstate.raw[i].a =3D raw_cpuid_policy.xstate.raw[i].a; + p->xstate.raw[i].b =3D raw_cpuid_policy.xstate.raw[i].b; + p->xstate.raw[i].c =3D raw_cpuid_policy.xstate.raw[i].c & ecx_bits; } } =20 --=20 2.11.0