From nobody Sat May 4 08:45:29 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=1558607317; cv=none; d=zoho.com; s=zohoarc; b=E1A9CFLNIAWZ7GhchuuuLxEOw/Zg9pasvbci8+iaELcMaj9bwcCBPGeGwD3iaP+DBZzeOWdmdsPOzFZQauIWjGd8oUCTI9XqyDxWd9Q2/8pJz3NOecrlXa61CE6EN5LZNCHnsrnrWHZPUQHM0mBH32ueK75XR7USNF4Rtt2N4mE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558607317; 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:ARC-Authentication-Results; bh=cDeADpMhcIBWXr7c0doSSs9KcQo1UuqahXSKVmXjnJY=; b=Rn/2p39Xs1UWJ0NWj5dZcc8KJjRBx0rqczFPTwV0m3OD8OmH99Uq6O1IBHRTEuoEg2XpTdADaxwOEe2BTNA5sNTBTOxpH2nwiiAf29PZJ8JFNIn4SW2Ys5dI5FULE3/8yZF+vjZZeGn7grI1Ad7HmGQAv2R5pCck/s/xRt+NwcQ= 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 1558607317542721.3483404876365; Thu, 23 May 2019 03:28:37 -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 1hTkwK-0004f7-9n; Thu, 23 May 2019 10:27:12 +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.89) (envelope-from ) id 1hTkwJ-0004f2-JR for xen-devel@lists.xenproject.org; Thu, 23 May 2019 10:27:11 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 50477ffe-7d45-11e9-a1f2-8b667931a91e; Thu, 23 May 2019 10:27:07 +0000 (UTC) X-Inumbo-ID: 50477ffe-7d45-11e9-a1f2-8b667931a91e 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@MIAPEX02MSOL01.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@MIAPEX02MSOL01.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@MIAPEX02MSOL01.citrite.net"; x-conformance=sidf_compatible IronPort-SDR: ad6CYnaea4sN/IeB2X9BVdKUwqyqVOxTQhrRnszX2raT2eRGOp9MTztys6KT6dIbphs6OiXXEJ Ypb+MBl9+TGaiqPmTt2/7Wq5pktM4FPRoxnU95GZmXyP1EmPa1Qoe1ClRJ+s8Urmr+Z5t4TVlA gVzrbW4yWS3xKWLtc8cxYjc3u0ytwxndgEuk2wE52XWwiQw12SbR1s7OfYifC39vHwVspvwjxx H+4Z5VwdNw4RCM3X/kQfG2X/G+BbMbzRsf/4X/6jnFPapoA4UJtkRo0TScGfxGf4ODkLkHF0Rr +xY= X-SBRS: 2.7 X-MesageID: 821092 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,502,1549947600"; d="scan'208";a="821092" From: Andrew Cooper To: Xen-devel Date: Thu, 23 May 2019 11:27:03 +0100 Message-ID: <1558607223-19630-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1558540230-26612-1-git-send-email-andrew.cooper3@citrix.com> References: <1558540230-26612-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid 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" This avoids opencoding the slightly-awkward logic. More uses of these wrappers will be introduced shortly. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 I've decided to introduce this patch ahead of "[PATCH] libx86: Elide more empty CPUID leaves when serialising a policy" (which simplifies the xstate hunk a little) as I've found yet more cases where I need to use cpuid_policy_xstates(), and opencoding them all seemed very silly. --- xen/arch/x86/xstate.c | 8 ++------ xen/include/xen/lib/x86/cpuid.h | 12 ++++++++++++ xen/lib/x86/cpuid.c | 3 +-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 3da609a..04da569 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -660,9 +660,7 @@ static bool valid_xcr0(u64 xcr0) int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_a= ccum, const struct xsave_hdr *hdr) { - const struct cpuid_policy *cp =3D d->arch.cpuid; - uint64_t xcr0_max =3D - ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low; + uint64_t xcr0_max =3D cpuid_policy_xcr0(d->arch.cpuid); unsigned int i; =20 if ( (hdr->xstate_bv & ~xcr0_accum) || @@ -686,9 +684,7 @@ int validate_xstate(const struct domain *d, uint64_t xc= r0, uint64_t xcr0_accum, int handle_xsetbv(u32 index, u64 new_bv) { struct vcpu *curr =3D current; - const struct cpuid_policy *cp =3D curr->domain->arch.cpuid; - uint64_t xcr0_max =3D - ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low; + uint64_t xcr0_max =3D cpuid_policy_xcr0(curr->domain->arch.cpuid); u64 mask; =20 if ( index !=3D XCR_XFEATURE_ENABLED_MASK ) diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpui= d.h index 252d2c9..ea4db5b 100644 --- a/xen/include/xen/lib/x86/cpuid.h +++ b/xen/include/xen/lib/x86/cpuid.h @@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy( p->feat._7a1 =3D fs[FEATURESET_7a1]; } =20 +static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p) +{ + return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low; +} + +static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p) +{ + uint64_t val =3D p->xstate.xcr0_high | p->xstate.xss_high; + + return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low; +} + const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature); =20 /** diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c index 23619c7..74c5b18 100644 --- a/xen/lib/x86/cpuid.c +++ b/xen/lib/x86/cpuid.c @@ -144,8 +144,7 @@ void x86_cpuid_policy_fill_native(struct cpuid_policy *= p) cpuid_count_leaf(0xd, 0, &p->xstate.raw[0]); cpuid_count_leaf(0xd, 1, &p->xstate.raw[1]); =20 - xstates =3D ((uint64_t)(p->xstate.xcr0_high | p->xstate.xss_high)= << 32); - xstates |=3D (p->xstate.xcr0_low | p->xstate.xss_low); + xstates =3D cpuid_policy_xstates(p); =20 for ( i =3D 2; i < min_t(unsigned int, 63, ARRAY_SIZE(p->xstate.raw)); ++i ) --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel