From nobody Fri Apr 26 04:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1568232406; cv=none; d=zoho.com; s=zohoarc; b=hvQ73r+as8xw53vVoiT6/5UOdorGzOIZZ3mLBPIib1B5BFDGLwjYSQZ54ZFB/VUNTfjluzNCVd9wgpCxn3QUMLE4h6VJAUGytViVP0U2wHDvOQRg+94BvxRJ50rTBB1pIv5wQ7BGCNbHtyrYXOiQWSbNpsduyOsSnZ+v3ub7fIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568232406; 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=y3vq+fjT3f7aJ0Qb79twFi8Ht0TxV7WRCoaiEvcuuQ8=; b=Y2XD2vjxlMI3oX3CFpUSqj9sF9cGgh4RRrjHuY8Nb7PVSu2N7lDv6VS55v18TXZgfXYnV542q6L0HTTPnZ3gMJuEXuP8As+TW0sCKHNMgBD72pPXGQgnNZa8N+iQQHfxg7NpA0jcJgmh+/ptwuQCFMoltGpOZsACUWYGluaMmek= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1568232406270837.9447329006142; Wed, 11 Sep 2019 13:06:46 -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 1i88ra-0002zR-L4; Wed, 11 Sep 2019 20:05:14 +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 1i88rZ-0002zH-79 for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 20:05:13 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 75c8370a-d4cf-11e9-83dd-12813bfff9fa; Wed, 11 Sep 2019 20:05:11 +0000 (UTC) X-Inumbo-ID: 75c8370a-d4cf-11e9-83dd-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568232312; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EFnsOsGQ4CPWA4IpIutS5XNwHkOuU3XzDAJN+8JtXFE=; b=YbKccwAAGmDdc8ERovwskz35zz4e2pkORTXYvm8O1jCHHnMeZhSt/apD Rgw8Hi2HTiGtmzhNKp3yy7u0uj4v5mOsENIHTlIxkNrxmVGUntxJ/wNja iMWfkMqQ7ylTW4XbMl8YZNoihEKGvEFMJ63rPdWlvxeEzVCzuLYlPRc2F w=; Authentication-Results: esa1.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@mail.citrix.com 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 (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: YdciJxz1xjqXtNIFvRyhJYBA30Mpis1j+EWu6jaHRfWCr2CVwDOHUQhafHIvkXU9w3ZJ0vrQqW rbFisIEQmUjzH6x3Rr3eThDKgCfyz2E0UKyKiu0B6UqT1WBEhnkKdeX5umxGj/UqVbgDvLlQj4 72qZoyk8PJpiKEbYVoTgv64WrrK4z4eOb29TSQSKDN5JPu9JeO77heVhI4nlEVDJ6crNMmq2Kl CY14KFXUqToEqwCi3cwnNoIGAo+JGe6sAOa4rRNrremsFvpjqJ4/tQPXfkAO74hLaifhmCHc9K gOE= X-SBRS: 2.7 X-MesageID: 5506243 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,494,1559534400"; d="scan'208";a="5506243" From: Andrew Cooper To: Xen-devel Date: Wed, 11 Sep 2019 21:04:57 +0100 Message-ID: <20190911200504.5693-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/8] libx86: Introduce x86_cpu_policies_are_compatible() 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" X-ZohoMail-DKIM: fail (Header signature does not verify) This helper will eventually be the core "can a guest confiured like this run on the CPU?" logic. For now, it is just enough of a stub to allow us to replace the hypercall interface while retaining the previous behaviour. It will be expanded as various other bits of CPUID handling get cleaned up. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- tools/tests/cpu-policy/Makefile | 2 +- tools/tests/cpu-policy/test-cpu-policy.c | 111 +++++++++++++++++++++++++++= +++- xen/include/xen/lib/x86/cpu-policy.h | 19 ++++++ xen/lib/x86/Makefile | 1 + xen/lib/x86/policy.c | 53 +++++++++++++++ 5 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 xen/lib/x86/policy.c diff --git a/tools/tests/cpu-policy/Makefile b/tools/tests/cpu-policy/Makef= ile index fb548c9b9a..70ff154da6 100644 --- a/tools/tests/cpu-policy/Makefile +++ b/tools/tests/cpu-policy/Makefile @@ -39,7 +39,7 @@ CFLAGS +=3D $(APPEND_CFLAGS) =20 vpath %.c ../../../xen/lib/x86 =20 -test-cpu-policy: test-cpu-policy.o msr.o cpuid.o +test-cpu-policy: test-cpu-policy.o msr.o cpuid.o policy.o $(CC) $(CFLAGS) $^ -o $@ =20 -include $(DEPS_INCLUDE) diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-pol= icy/test-cpu-policy.c index fe00cd4276..10cfa7cd97 100644 --- a/tools/tests/cpu-policy/test-cpu-policy.c +++ b/tools/tests/cpu-policy/test-cpu-policy.c @@ -9,8 +9,7 @@ =20 #include #include -#include -#include +#include #include =20 static unsigned int nr_failures; @@ -503,6 +502,111 @@ static void test_cpuid_out_of_range_clearing(void) } } =20 +static void test_is_compatible_success(void) +{ + static struct test { + const char *name; + struct cpuid_policy host_cpuid; + struct cpuid_policy guest_cpuid; + struct msr_policy host_msr; + struct msr_policy guest_msr; + } tests[] =3D { + { + .name =3D "Host CPUID faulting, Guest not", + .host_msr =3D { + .plaform_info.cpuid_faulting =3D true, + }, + }, + { + .name =3D "Host CPUID faulting, Guest wanted", + .host_msr =3D { + .plaform_info.cpuid_faulting =3D true, + }, + .guest_msr =3D { + .plaform_info.cpuid_faulting =3D true, + }, + }, + }; + struct cpu_policy_errors no_errors =3D INIT_CPU_POLICY_ERRORS; + + printf("Testing policy compatibility success:\n"); + + for ( size_t i =3D 0; i < ARRAY_SIZE(tests); ++i ) + { + struct test *t =3D &tests[i]; + struct cpu_policy sys =3D { + &t->host_cpuid, + &t->host_msr, + }, new =3D { + &t->guest_cpuid, + &t->guest_msr, + }; + struct cpu_policy_errors e =3D INIT_CPU_POLICY_ERRORS; + int res =3D x86_cpu_policies_are_compatible(&sys, &new, &e); + + /* Check the expected error output. */ + if ( res !=3D 0 || memcmp(&no_errors, &e, sizeof(no_errors)) ) + fail(" Test '%s' expected no errors\n" + " got res %d { leaf %08x, subleaf %08x, msr %08x }\n", + t->name, res, e.leaf, e.subleaf, e.msr); + } +} + +static void test_is_compatible_failure(void) +{ + static struct test { + const char *name; + struct cpuid_policy host_cpuid; + struct cpuid_policy guest_cpuid; + struct msr_policy host_msr; + struct msr_policy guest_msr; + struct cpu_policy_errors e; + } tests[] =3D { + { + .name =3D "Host basic.max_leaf out of range", + .guest_cpuid.basic.max_leaf =3D 1, + .e =3D { 0, -1, -1 }, + }, + { + .name =3D "Host extd.max_leaf out of range", + .guest_cpuid.extd.max_leaf =3D 1, + .e =3D { 0x80000008, -1, -1 }, + }, + { + .name =3D "Host no CPUID faulting, Guest wanted", + .guest_msr =3D { + .plaform_info.cpuid_faulting =3D true, + }, + .e =3D { -1, -1, 0xce }, + }, + }; + + printf("Testing policy compatibility failure:\n"); + + for ( size_t i =3D 0; i < ARRAY_SIZE(tests); ++i ) + { + struct test *t =3D &tests[i]; + struct cpu_policy sys =3D { + &t->host_cpuid, + &t->host_msr, + }, new =3D { + &t->guest_cpuid, + &t->guest_msr, + }; + struct cpu_policy_errors e =3D INIT_CPU_POLICY_ERRORS; + int res =3D x86_cpu_policies_are_compatible(&sys, &new, &e); + + /* Check the expected error output. */ + if ( res =3D=3D 0 || memcmp(&t->e, &e, sizeof(t->e)) ) + fail(" Test '%s' res %d\n" + " expected { leaf %08x, subleaf %08x, msr %08x }\n" + " got { leaf %08x, subleaf %08x, msr %08x }\n", + t->name, res, + t->e.leaf, t->e.subleaf, t->e.msr, + e.leaf, e.subleaf, e.msr); + } +} + int main(int argc, char **argv) { printf("CPU Policy unit tests\n"); @@ -516,6 +620,9 @@ int main(int argc, char **argv) test_msr_serialise_success(); test_msr_deserialise_failure(); =20 + test_is_compatible_success(); + test_is_compatible_failure(); + if ( nr_failures ) printf("Done: %u failures\n", nr_failures); else diff --git a/xen/include/xen/lib/x86/cpu-policy.h b/xen/include/xen/lib/x86= /cpu-policy.h index 6f07c4b493..65ec71835b 100644 --- a/xen/include/xen/lib/x86/cpu-policy.h +++ b/xen/include/xen/lib/x86/cpu-policy.h @@ -11,6 +11,25 @@ struct cpu_policy struct msr_policy *msr; }; =20 +struct cpu_policy_errors +{ + uint32_t leaf, subleaf; + uint32_t msr; +}; + +#define INIT_CPU_POLICY_ERRORS { ~0u, ~0u, ~0u } + +/* + * Calculate whether two policies are compatible. + * + * i.e. Can a VM configured with @guest run on a CPU supporting @host. + * + * For typical usage, @host should be a system policy. + */ +int x86_cpu_policies_are_compatible(const struct cpu_policy *host, + const struct cpu_policy *guest, + struct cpu_policy_errors *e); + #endif /* !XEN_LIB_X86_POLICIES_H */ =20 /* diff --git a/xen/lib/x86/Makefile b/xen/lib/x86/Makefile index 2f9691e964..780ea05db1 100644 --- a/xen/lib/x86/Makefile +++ b/xen/lib/x86/Makefile @@ -1,2 +1,3 @@ obj-y +=3D cpuid.o obj-y +=3D msr.o +obj-y +=3D policy.o diff --git a/xen/lib/x86/policy.c b/xen/lib/x86/policy.c new file mode 100644 index 0000000000..3155e07a7c --- /dev/null +++ b/xen/lib/x86/policy.c @@ -0,0 +1,53 @@ +#include "private.h" + +#include + +int x86_cpu_policies_are_compatible(const struct cpu_policy *host, + const struct cpu_policy *guest, + struct cpu_policy_errors *e) +{ + uint32_t leaf =3D -1, subleaf =3D -1, msr =3D -1; + int ret =3D -EINVAL; + +#define NA XEN_CPUID_NO_SUBLEAF +#define FAIL_CPUID(l, s) do { leaf =3D (l); subleaf =3D (s); goto out; } w= hile ( 0 ) +#define FAIL_MSR(m) do { msr =3D (m); goto out; } while ( 0 ) + + if ( guest->cpuid->basic.max_leaf > host->cpuid->basic.max_leaf ) + FAIL_CPUID(0, NA); + + if ( guest->cpuid->extd.max_leaf > host->cpuid->extd.max_leaf ) + FAIL_CPUID(0x80000008, NA); + + /* TODO: Audit more CPUID data. */ + + if ( ~host->msr->plaform_info.raw & guest->msr->plaform_info.raw ) + FAIL_MSR(MSR_INTEL_PLATFORM_INFO); + +#undef FAIL_MSR +#undef FAIL_CPUID +#undef NA + + /* Success. */ + ret =3D 0; + + out: + if ( ret && e ) + { + e->leaf =3D leaf; + e->subleaf =3D subleaf; + e->msr =3D msr; + } + + return ret; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 26 04:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1568232406; cv=none; d=zoho.com; s=zohoarc; b=b/hp00xtUnTJyl9DhUTsB8Y1SoOUDoNojFilSaXRAbmRp35v94jpQIj2+4LHPmykFusID16DT4rBOgapz/ICaDUM6OLjSLY6cXHy5MG9Ez8eJ0ZAjeRmJid6ZGlExvhcz06bmZrpaNFY01QWZJEWsterKLwulepd8NXhq3x/5U8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568232406; 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=xaRKqAmL/XL9eBBwdreqTh/C9bAJ0oRVA4KjN2CIsQM=; b=UBbgFnEmxpAYfVOjQ06xpz/UYvbu+OFZDUfflABNh6etTCvCu+dV12rbzwKLTqm1z8WS3GLzZ3+MCeu/RyJ0lgxzbpYB1bcaTFM/MzsO/jB7MrCePUCp8zyO7eS12odke98pd7SmhEIfyhx6Kc2DBGvGhHFXlW0OtGCiYnUdhlg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1568232406009658.0351786734525; Wed, 11 Sep 2019 13:06:46 -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 1i88rb-0002zh-5K; Wed, 11 Sep 2019 20:05:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i88rZ-0002zM-PW for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 20:05:13 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 761b2d20-d4cf-11e9-b299-bc764e2007e4; Wed, 11 Sep 2019 20:05:12 +0000 (UTC) X-Inumbo-ID: 761b2d20-d4cf-11e9-b299-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568232312; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9Qy6fWZ039WeGD+8IdzKXaFvFd/qR+imJDVwqFqt+T4=; b=eAczOgzICp1fq14jdQOsEIcqisEelXM47xXQGk6VXnGEbuOylkElbem0 gh1HFT/1pvPqoigOh9aKor79k/bQm2LtCaRXRROFfJj2ASJNNbde8jMM7 9C9iKr9tXgJFL1+WmMmfQ2GJvUhSWMiq8sB6Az87dG67YqyI/DPsaNYQG o=; Authentication-Results: esa6.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@mail.citrix.com 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 (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: tTtRTWjvKDz+ZurNtGiF2SpOjkw4oN+wk4kaP0jemPOKQ8J3MdZ9Xm/8ZiyB7jKU84Tv0+uoBV 7iiPd0Q/6YVDJXLf7Yr5o7Konsueu2V/DmyHrvMPonfRc3+hsl81BR7KLoB/S9QXGCscHJ+F4o V2CXiKm9HkPWepyT1kRjdAON9zmazkuFnvk2G/97W8I/RzDQDwgrsw5OyNJwCbKi5rSU+160/U UPBvIU30oGDyQ7KWlWcOUQa6xl8Osv2UW4PfF305DsN7N7mwRUlac6qx04hnYJVrgVT+X7K5ka 4u4= X-SBRS: 2.7 X-MesageID: 5695040 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,494,1559534400"; d="scan'208";a="5695040" From: Andrew Cooper To: Xen-devel Date: Wed, 11 Sep 2019 21:04:58 +0100 Message-ID: <20190911200504.5693-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/8] x86/cpuid: Split update_domain_cpuid_info() in half 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" X-ZohoMail-DKIM: fail (Header signature does not verify) update_domain_cpuid_info() currently serves two purposes. First to merge n= ew CPUID data from the toolstack, and second, to perform any necessary updating of derived domain/vcpu settings. The first part of this is going to be superseded by a new and substantially more efficient hypercall. Carve the second part out into a new domain_cpu_policy_changed() helper, and call this from the remains of update_domain_cpuid_info(). This does drop the call_policy_changed, but with the new hypercall hypercall in place, the common case will be a single call per domain. Dropping the optimisation here allows for a cleaner set of following changes. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/domctl.c | 245 ++++++++++++++++++++--------------------------= ---- 1 file changed, 99 insertions(+), 146 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index a744696c6b..d15ae066c3 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -46,101 +46,14 @@ static int gdbsx_guest_mem_io(domid_t domid, struct xe= n_domctl_gdbsx_memio *iop) return iop->remain ? -EFAULT : 0; } =20 -static int update_domain_cpuid_info(struct domain *d, - const struct xen_domctl_cpuid *ctl) +static void domain_cpu_policy_changed(struct domain *d) { - struct cpuid_policy *p =3D d->arch.cpuid; - const struct cpuid_leaf leaf =3D { ctl->eax, ctl->ebx, ctl->ecx, ctl->= edx }; - int old_vendor =3D p->x86_vendor; - unsigned int old_7d0 =3D p->feat.raw[0].d, old_e8b =3D p->extd.raw[8].= b; - bool call_policy_changed =3D false; /* Avoid for_each_vcpu() unnecessa= rily */ - - /* - * Skip update for leaves we don't care about, to avoid the overhead of - * recalculate_cpuid_policy(). - */ - switch ( ctl->input[0] ) - { - case 0x00000000 ... ARRAY_SIZE(p->basic.raw) - 1: - if ( ctl->input[0] =3D=3D 4 && - ctl->input[1] >=3D ARRAY_SIZE(p->cache.raw) ) - return 0; - - if ( ctl->input[0] =3D=3D 7 && - ctl->input[1] >=3D ARRAY_SIZE(p->feat.raw) ) - return 0; - - if ( ctl->input[0] =3D=3D 0xb && - ctl->input[1] >=3D ARRAY_SIZE(p->topo.raw) ) - return 0; - - BUILD_BUG_ON(ARRAY_SIZE(p->xstate.raw) < 2); - if ( ctl->input[0] =3D=3D XSTATE_CPUID && - ctl->input[1] !=3D 1 ) /* Everything else automatically calcu= lated. */ - return 0; - break; - - case 0x40000000: case 0x40000100: - /* Only care about the max_leaf limit. */ - - case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1: - break; - - default: - return 0; - } - - /* Insert ctl data into cpuid_policy. */ - switch ( ctl->input[0] ) - { - case 0x00000000 ... ARRAY_SIZE(p->basic.raw) - 1: - switch ( ctl->input[0] ) - { - case 4: - p->cache.raw[ctl->input[1]] =3D leaf; - break; - - case 7: - p->feat.raw[ctl->input[1]] =3D leaf; - break; - - case 0xb: - p->topo.raw[ctl->input[1]] =3D leaf; - break; - - case XSTATE_CPUID: - p->xstate.raw[ctl->input[1]] =3D leaf; - break; - - default: - p->basic.raw[ctl->input[0]] =3D leaf; - break; - } - break; - - case 0x40000000: - p->hv_limit =3D ctl->eax; - break; + const struct cpuid_policy *p =3D d->arch.cpuid; + struct vcpu *v; =20 - case 0x40000100: - p->hv2_limit =3D ctl->eax; - break; - - case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1: - p->extd.raw[ctl->input[0] - 0x80000000] =3D leaf; - break; - } - - recalculate_cpuid_policy(d); - - switch ( ctl->input[0] ) + if ( is_pv_domain(d) ) { - case 0: - call_policy_changed =3D (p->x86_vendor !=3D old_vendor); - break; - - case 1: - if ( is_pv_domain(d) && ((levelling_caps & LCAP_1cd) =3D=3D LCAP_1= cd) ) + if ( ((levelling_caps & LCAP_1cd) =3D=3D LCAP_1cd) ) { uint64_t mask =3D cpuidmask_defaults._1cd; uint32_t ecx =3D p->basic._1c; @@ -197,25 +110,18 @@ static int update_domain_cpuid_info(struct domain *d, =20 d->arch.pv.cpuidmasks->_1cd =3D mask; } - break; =20 - case 6: - if ( is_pv_domain(d) && ((levelling_caps & LCAP_6c) =3D=3D LCAP_6c= ) ) + if ( ((levelling_caps & LCAP_6c) =3D=3D LCAP_6c) ) { uint64_t mask =3D cpuidmask_defaults._6c; =20 if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD ) - mask &=3D (~0ULL << 32) | ctl->ecx; + mask &=3D (~0ULL << 32) | p->basic.raw[6].c; =20 d->arch.pv.cpuidmasks->_6c =3D mask; } - break; - - case 7: - if ( ctl->input[1] !=3D 0 ) - break; =20 - if ( is_pv_domain(d) && ((levelling_caps & LCAP_7ab0) =3D=3D LCAP_= 7ab0) ) + if ( ((levelling_caps & LCAP_7ab0) =3D=3D LCAP_7ab0) ) { uint64_t mask =3D cpuidmask_defaults._7ab0; =20 @@ -232,35 +138,7 @@ static int update_domain_cpuid_info(struct domain *d, d->arch.pv.cpuidmasks->_7ab0 =3D mask; } =20 - /* - * If the IBRS/IBPB policy has changed, we need to recalculate the= MSR - * interception bitmaps. - */ - call_policy_changed =3D (is_hvm_domain(d) && - ((old_7d0 ^ p->feat.raw[0].d) & - (cpufeat_mask(X86_FEATURE_IBRSB) | - cpufeat_mask(X86_FEATURE_L1D_FLUSH)))); - break; - - case 0xa: - if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL ) - break; - - /* If PMU version is zero then the guest doesn't have VPMU */ - if ( p->basic.pmu_version =3D=3D 0 ) - { - struct vcpu *v; - - for_each_vcpu ( d, v ) - vpmu_destroy(v); - } - break; - - case 0xd: - if ( ctl->input[1] !=3D 1 ) - break; - - if ( is_pv_domain(d) && ((levelling_caps & LCAP_Da1) =3D=3D LCAP_D= a1) ) + if ( ((levelling_caps & LCAP_Da1) =3D=3D LCAP_Da1) ) { uint64_t mask =3D cpuidmask_defaults.Da1; uint32_t eax =3D p->xstate.Da1; @@ -270,10 +148,8 @@ static int update_domain_cpuid_info(struct domain *d, =20 d->arch.pv.cpuidmasks->Da1 =3D mask; } - break; =20 - case 0x80000001: - if ( is_pv_domain(d) && ((levelling_caps & LCAP_e1cd) =3D=3D LCAP_= e1cd) ) + if ( ((levelling_caps & LCAP_e1cd) =3D=3D LCAP_e1cd) ) { uint64_t mask =3D cpuidmask_defaults.e1cd; uint32_t ecx =3D p->extd.e1c; @@ -317,27 +193,104 @@ static int update_domain_cpuid_info(struct domain *d, =20 d->arch.pv.cpuidmasks->e1cd =3D mask; } + } + + for_each_vcpu( d, v ) + { + cpuid_policy_updated(v); + + /* If PMU version is zero then the guest doesn't have VPMU */ + if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL && + p->basic.pmu_version =3D=3D 0 ) + vpmu_destroy(v); + } +} + +static int update_domain_cpuid_info(struct domain *d, + const struct xen_domctl_cpuid *ctl) +{ + struct cpuid_policy *p =3D d->arch.cpuid; + const struct cpuid_leaf leaf =3D { ctl->eax, ctl->ebx, ctl->ecx, ctl->= edx }; + + /* + * Skip update for leaves we don't care about, to avoid the overhead of + * recalculate_cpuid_policy(). + */ + switch ( ctl->input[0] ) + { + case 0x00000000 ... ARRAY_SIZE(p->basic.raw) - 1: + if ( ctl->input[0] =3D=3D 4 && + ctl->input[1] >=3D ARRAY_SIZE(p->cache.raw) ) + return 0; + + if ( ctl->input[0] =3D=3D 7 && + ctl->input[1] >=3D ARRAY_SIZE(p->feat.raw) ) + return 0; + + if ( ctl->input[0] =3D=3D 0xb && + ctl->input[1] >=3D ARRAY_SIZE(p->topo.raw) ) + return 0; + + BUILD_BUG_ON(ARRAY_SIZE(p->xstate.raw) < 2); + if ( ctl->input[0] =3D=3D XSTATE_CPUID && + ctl->input[1] !=3D 1 ) /* Everything else automatically calcu= lated. */ + return 0; break; =20 - case 0x80000008: - /* - * If the IBPB policy has changed, we need to recalculate the MSR - * interception bitmaps. - */ - call_policy_changed =3D (is_hvm_domain(d) && - ((old_e8b ^ p->extd.raw[8].b) & - cpufeat_mask(X86_FEATURE_IBPB))); + case 0x40000000: case 0x40000100: + /* Only care about the max_leaf limit. */ + + case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1: break; + + default: + return 0; } =20 - if ( call_policy_changed ) + /* Insert ctl data into cpuid_policy. */ + switch ( ctl->input[0] ) { - struct vcpu *v; + case 0x00000000 ... ARRAY_SIZE(p->basic.raw) - 1: + switch ( ctl->input[0] ) + { + case 4: + p->cache.raw[ctl->input[1]] =3D leaf; + break; + + case 7: + p->feat.raw[ctl->input[1]] =3D leaf; + break; + + case 0xb: + p->topo.raw[ctl->input[1]] =3D leaf; + break; =20 - for_each_vcpu( d, v ) - cpuid_policy_updated(v); + case XSTATE_CPUID: + p->xstate.raw[ctl->input[1]] =3D leaf; + break; + + default: + p->basic.raw[ctl->input[0]] =3D leaf; + break; + } + break; + + case 0x40000000: + p->hv_limit =3D ctl->eax; + break; + + case 0x40000100: + p->hv2_limit =3D ctl->eax; + break; + + case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1: + p->extd.raw[ctl->input[0] - 0x80000000] =3D leaf; + break; } =20 + recalculate_cpuid_policy(d); + domain_cpu_policy_changed(d); + return 0; } =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 26 04:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1568232408; cv=none; d=zoho.com; s=zohoarc; b=CBrHf4ISWRsSa4ahTpqQOLuxm7lWXjyLWrfxpzWWCsSQtjll69WnDlfo3v0cj8kTRY9nBXL3qsoOOXNfB2Y4YgrE/L2rChgNRGspHV6tdkYPSDS8XGV4fm00BiOuJdpAFQhq1P7NsGIZBZyuNYOF0JR9Zl50Pf/XUAXjdcQbilU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568232408; 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=BcVh3duR+1/VG+1GOuNt9tldzFucLcb3PYaKLgJgDKE=; b=NqTgzvP4B6P2Dkydz9R4IbaCqDsjJ+0x5FLEA11q0KDeWm/IO5jmoS2cFgHVnGGLE/gL9kTdmOOva4KzsytwlLMi/wUD4eQnRF62bkGNuHyenZlos89mOKnbWmWeF7sae1rITY1xQY3kfMYQuHbCWEMzjYyJaItmCDfnVeebo68= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1568232408827862.1813667822844; Wed, 11 Sep 2019 13:06:48 -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 1i88rk-00030w-Ct; Wed, 11 Sep 2019 20:05:24 +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 1i88rj-00030Q-4o for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 20:05:23 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 77962363-d4cf-11e9-83dd-12813bfff9fa; Wed, 11 Sep 2019 20:05:14 +0000 (UTC) X-Inumbo-ID: 77962363-d4cf-11e9-83dd-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568232314; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BIbnzCREkG77hGwoxZ3RMjH/adLjjec/0WbuotSainY=; b=Y/qAtP5RizTiEL+UN51Iu/6u8CO7vCdLHLmv9aMbKbOrRnEhQOztzP/8 6P3ROA2fhQMvTlyB/ugiIRDwoijFXQocIHgmnYagkOtnF+KYok1e1QGJ/ NhdWYL8o8Yrg8MQQYZplsMGvBEIMPll/s4aHJ3QT0drRygk74uEV1FKtV 4=; 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@mail.citrix.com 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=162.221.158.21; 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 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; 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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: iC/85lOS97iYbHxeP+m/voeXswq+JeYqBhLHZ/p93Cik7QXsMus2dDB8dA9+Yiyd4153Ec55UB 9ppGVUz3JoKeb6+ox7U6TOrlfKkAWjWAVmcXkIabxGL5lrTSCV56+Y1iSaFN45k60gWgU/4A2r vqtyNGrbzeL+OxXgXTMtTrkyVatnTfu+vxvbINgD1ytNMJEZNu8biYVsNUjYaAG1XSDqrydOKR gSK9pYZgEGQ2JK3aqAyUOCMJOoDznNrVdvbqcwe/AMLgy9bsXPW1Bsp6ddbEvWK3b57SH1+xoI 7jI= X-SBRS: 2.7 X-MesageID: 5451848 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,494,1559534400"; d="scan'208";a="5451848" From: Andrew Cooper To: Xen-devel Date: Wed, 11 Sep 2019 21:04:59 +0100 Message-ID: <20190911200504.5693-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 3/8] x86/domctl: Implement XEN_DOMCTL_set_cpumsr_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: Sergey Dyasli , Wei Liu , Andrew Cooper , Ian Jackson , Jan Beulich , Daniel De Graaf , =?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" X-ZohoMail-DKIM: fail (Header signature does not verify) This hypercall allows the toolstack to present one combined CPUID and MSR policy for a domain, which can be audited in one go by Xen, which is necess= ary for correctness of the auditing. Reuse the existing set_cpuid XSM access vector, as this is logically the sa= me operation. As x86_cpu_policies_are_compatible() is still only a stub, retain the call = to recalculate_cpuid_policy() to discard unsafe toolstack settings. Signed-off-by: Andrew Cooper Signed-off-by: Sergey Dyasli Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Ian Jackson CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Daniel De Graaf --- tools/libxc/include/xenctrl.h | 5 +++ tools/libxc/xc_cpuid_x86.c | 49 +++++++++++++++++++++++ xen/arch/x86/domctl.c | 80 +++++++++++++++++++++++++++++++++= ++++ xen/include/public/domctl.h | 15 +++++-- xen/xsm/flask/hooks.c | 1 + xen/xsm/flask/policy/access_vectors | 1 + 6 files changed, 147 insertions(+), 4 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 7559e1bc69..e47778535d 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2530,6 +2530,11 @@ int xc_get_system_cpu_policy(xc_interface *xch, uint= 32_t index, int xc_get_domain_cpu_policy(xc_interface *xch, uint32_t domid, uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves, uint32_t *nr_msrs, xen_msr_entry_t *msrs); +int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid, + uint32_t nr_leaves, xen_cpuid_leaf_t *leaves, + uint32_t nr_msrs, xen_msr_entry_t *msrs, + uint32_t *err_leaf_p, uint32_t *err_subleaf_p, + uint32_t *err_msr_idx_p); =20 uint32_t xc_get_cpu_featureset_size(void); =20 diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index b829336082..33b9e9fc85 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -229,6 +229,55 @@ int xc_get_domain_cpu_policy(xc_interface *xch, uint32= _t domid, return ret; } =20 +int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid, + uint32_t nr_leaves, xen_cpuid_leaf_t *leaves, + uint32_t nr_msrs, xen_msr_entry_t *msrs, + uint32_t *err_leaf_p, uint32_t *err_subleaf_p, + uint32_t *err_msr_idx_p) +{ + DECLARE_DOMCTL; + DECLARE_HYPERCALL_BOUNCE(leaves, + nr_leaves * sizeof(*leaves), + XC_HYPERCALL_BUFFER_BOUNCE_IN); + DECLARE_HYPERCALL_BOUNCE(msrs, + nr_msrs * sizeof(*msrs), + XC_HYPERCALL_BUFFER_BOUNCE_IN); + int ret; + + if ( xc_hypercall_bounce_pre(xch, leaves) ) + return -1; + + if ( xc_hypercall_bounce_pre(xch, msrs) ) + return -1; + + domctl.cmd =3D XEN_DOMCTL_set_cpu_policy; + domctl.domain =3D domid; + domctl.u.cpu_policy.nr_leaves =3D nr_leaves; + set_xen_guest_handle(domctl.u.cpu_policy.cpuid_policy, leaves); + domctl.u.cpu_policy.nr_msrs =3D nr_msrs; + set_xen_guest_handle(domctl.u.cpu_policy.msr_policy, msrs); + domctl.u.cpu_policy.err_leaf =3D ~0; + domctl.u.cpu_policy.err_subleaf =3D ~0; + domctl.u.cpu_policy.err_msr_idx =3D ~0; + + ret =3D do_domctl(xch, &domctl); + + xc_hypercall_bounce_post(xch, leaves); + xc_hypercall_bounce_post(xch, msrs); + + if ( ret ) + { + if ( err_leaf_p ) + *err_leaf_p =3D domctl.u.cpu_policy.err_leaf; + if ( err_subleaf_p ) + *err_subleaf_p =3D domctl.u.cpu_policy.err_subleaf; + if ( err_msr_idx_p ) + *err_msr_idx_p =3D domctl.u.cpu_policy.err_msr_idx; + } + + return ret; +} + struct cpuid_domain_info { unsigned int vendor; /* X86_VENDOR_* */ diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index d15ae066c3..99bc2fb10d 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -294,6 +294,65 @@ static int update_domain_cpuid_info(struct domain *d, return 0; } =20 +static int update_domain_cpu_policy(struct domain *d, + xen_domctl_cpu_policy_t *xdpc) +{ + struct cpu_policy new =3D {}; + const struct cpu_policy *sys =3D is_pv_domain(d) + ? &system_policies[XEN_SYSCTL_cpu_policy_pv_max] + : &system_policies[XEN_SYSCTL_cpu_policy_hvm_max]; + struct cpu_policy_errors err =3D INIT_CPU_POLICY_ERRORS; + int ret =3D -ENOMEM; + + /* Start by copying the domain's existing policies. */ + if ( !(new.cpuid =3D xmemdup(d->arch.cpuid)) || + !(new.msr =3D xmemdup(d->arch.msr)) ) + goto out; + + /* Merge the toolstack provided data. */ + if ( (ret =3D x86_cpuid_copy_from_buffer( + new.cpuid, xdpc->cpuid_policy, xdpc->nr_leaves, + &err.leaf, &err.subleaf)) || + (ret =3D x86_msr_copy_from_buffer( + new.msr, xdpc->msr_policy, xdpc->nr_msrs, &err.msr)) ) + goto out; + + /* Trim any newly-stale out-of-range leaves. */ + x86_cpuid_policy_clear_out_of_range_leaves(new.cpuid); + + /* Audit the combined dataset. */ + ret =3D x86_cpu_policies_are_compatible(sys, &new, &err); + if ( ret ) + goto out; + + /* + * Audit was successful. Replace existing policies, leaving the old + * policies to be freed. + */ + SWAP(new.cpuid, d->arch.cpuid); + SWAP(new.msr, d->arch.msr); + + /* TODO: Drop when x86_cpu_policies_are_compatible() is completed. */ + recalculate_cpuid_policy(d); + + /* Recalculate relevant dom/vcpu state now the policy has changed. */ + domain_cpu_policy_changed(d); + + out: + /* Free whichever cpuid/msr structs are not installed in struct domain= . */ + xfree(new.cpuid); + xfree(new.msr); + + if ( ret ) + { + xdpc->err_leaf =3D err.leaf; + xdpc->err_subleaf =3D err.subleaf; + xdpc->err_msr_idx =3D err.msr; + } + + return ret; +} + static int vcpu_set_vmce(struct vcpu *v, const struct xen_domctl_ext_vcpucontext *evc) { @@ -1476,6 +1535,27 @@ long arch_do_domctl( copyback =3D true; break; =20 + case XEN_DOMCTL_set_cpu_policy: + if ( d =3D=3D currd ) /* No domain_pause() */ + { + ret =3D -EINVAL; + break; + } + + domain_pause(d); + + if ( d->creation_finished ) + ret =3D -EEXIST; /* No changing once the domain is running. */ + else + { + ret =3D update_domain_cpu_policy(d, &domctl->u.cpu_policy); + if ( ret ) /* Copy domctl->u.cpu_policy.err_* to guest. */ + copyback =3D true; + } + + domain_unpause(d); + break; + default: ret =3D iommu_do_domctl(domctl, d, u_domctl); break; diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 77f546cbb8..0471d3c680 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -658,17 +658,23 @@ struct xen_domctl_cpuid { }; =20 /* - * XEN_DOMCTL_get_cpu_policy (x86 specific) + * XEN_DOMCTL_{get,set}_cpu_policy (x86 specific) * - * Query the CPUID and MSR policies for a specific domain. + * Query or set the CPUID and MSR policies for a specific domain. */ struct xen_domctl_cpu_policy { uint32_t nr_leaves; /* IN/OUT: Number of leaves in/written to * 'cpuid_policy'. */ uint32_t nr_msrs; /* IN/OUT: Number of MSRs in/written to * 'msr_domain_policy' */ - XEN_GUEST_HANDLE_64(xen_cpuid_leaf_t) cpuid_policy; /* OUT */ - XEN_GUEST_HANDLE_64(xen_msr_entry_t) msr_policy; /* OUT */ + XEN_GUEST_HANDLE_64(xen_cpuid_leaf_t) cpuid_policy; /* IN/OUT */ + XEN_GUEST_HANDLE_64(xen_msr_entry_t) msr_policy; /* IN/OUT */ + uint32_t err_leaf, err_subleaf; /* OUT, set_policy only. If not ~0, + * indicates the leaf/subleaf which + * auditing objected to. */ + uint32_t err_msr_idx; /* OUT, set_policy only. If not ~0, + * indicates the MSR idx which + * auditing objected to. */ }; typedef struct xen_domctl_cpu_policy xen_domctl_cpu_policy_t; DEFINE_XEN_GUEST_HANDLE(xen_domctl_cpu_policy_t); @@ -1193,6 +1199,7 @@ struct xen_domctl { /* #define XEN_DOMCTL_set_gnttab_limits 80 - Moved into XEN_DOMCT= L_createdomain */ #define XEN_DOMCTL_vuart_op 81 #define XEN_DOMCTL_get_cpu_policy 82 +#define XEN_DOMCTL_set_cpu_policy 83 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 6800f2d9a0..b23772786a 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -715,6 +715,7 @@ static int flask_domctl(struct domain *d, int cmd) case XEN_DOMCTL_set_virq_handler: return current_has_perm(d, SECCLASS_DOMAIN, DOMAIN__SET_VIRQ_HANDL= ER); =20 + case XEN_DOMCTL_set_cpu_policy: case XEN_DOMCTL_set_cpuid: return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SET_CPUID); =20 diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/acc= ess_vectors index 76f3d60ddd..6f3f9493f8 100644 --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -207,6 +207,7 @@ class domain2 # source =3D the domain making the hypercall # target =3D the new target domain set_as_target +# XEN_DOMCTL_set_cpu_policy # XEN_DOMCTL_set_cpuid set_cpuid # XEN_DOMCTL_gettscinfo --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 26 04:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1568232404; cv=none; d=zoho.com; s=zohoarc; b=lvUVJN7VLMcX9CuIbPcewK2gG+Qa3nI6H4xrhOpCaYcPDT+w0rqs6i2YXvNA+i2dKfeVo4AKjIfS8u9w/Nfq6oVNvRtn4zm6PFEUK0IMPGUbyI6e1Mieny2UxD2BmAb3PJhspQB4Bg8ScbfIMqO4gieouQstJjrlj2LMoJRNLZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568232404; 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=u2XsJhxH/1GbuKhc5MMsFOAubiJY99HS2bTqDBz6+kI=; b=O9NnEt+dVcJzCu1mGlyT3tugAtRTqnHCsipdL3VPyh+lfSPnpKk+PF4/TFoTgtrn5LdZSV+eEtcVpYDoa461WvgOPoxteMJlbrGZD+9AyxIMJn2x7qq4wfhxZfsl+BPPfA2MuSvwWnY+lqjMx562cmRsQXqVbcNUBXR+KUSQz6c= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1568232404101824.6098687148955; Wed, 11 Sep 2019 13:06:44 -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 1i88rj-00030W-Ri; Wed, 11 Sep 2019 20:05:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i88ri-00030J-KR for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 20:05:22 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7be61c7e-d4cf-11e9-978d-bc764e2007e4; Wed, 11 Sep 2019 20:05:21 +0000 (UTC) X-Inumbo-ID: 7be61c7e-d4cf-11e9-978d-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568232321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5mwy1x2NvpEAJcMZSDwwXuBx23b+MiSxgOml7mKLXH8=; b=ZonA4OKyao3OBNU7aqKvlxaKsK+mlY6mwnmYOhG3kQIcKRGPqmfjmYUk dsFzw9irY9wtl311oFW3eowKIfoZQH2ufQVLZGoAzwP7dHxZZ5uTp6pcm 1xli73fbunqh9OiUlniXw2Gj/S5Ahr8tPi0+E5QbDl3mqQwG0QtTmGYjZ c=; Authentication-Results: esa4.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@mail.citrix.com 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 (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 9aRAf2ARsQVOzObqupFfxU3QpYt4Vs/I9oSKXX3xWLakzEzIq1AfhtKQmVi2gdYLMT/E5eos2L 6ebiRzc5rMuWKHDM3k09OXXPDqf0G8wouNIieQ/BF0g8mjHTivNEw1JN1LkUSSB6MySgF+f/yi 9qAudeJ2jE25M/musySF6AZ8rCeoEJkPGHf+56QOn0PlUgUFR9RZ5qiBsLcv8Eh13jQRO5OMBG F6nVfM1/f7cu0/AGYfhvAeOEkq90BAEYUeL7HiJika2RaqgoVBzq1NuYvICS/XrdQNWfXJiklp Upk= X-SBRS: 2.7 X-MesageID: 5742443 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,494,1559534400"; d="scan'208";a="5742443" From: Andrew Cooper To: Xen-devel Date: Wed, 11 Sep 2019 21:05:00 +0100 Message-ID: <20190911200504.5693-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 4/8] tools/libxc: Pre-cleanup for xc_cpuid_{set, apply_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 , Ian Jackson , 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" X-ZohoMail-DKIM: fail (Header signature does not verify) This patch is broken out just to simplify the following two. For xc_cpuid_set(), document how the 'k' works because it is quite subtle. Replace a memset() with weird calculation for a loop of 4 explicit NULL assigments. This mirrors the free()'s in the fail path. For xc_cpuid_apply_policy(), const-ify the featureset pointer. It isn't written to, and was never intended to be mutable. Drop three pieces of trailing whitespace. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Ian Jackson --- tools/libxc/include/xenctrl.h | 2 +- tools/libxc/xc_cpuid_x86.c | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index e47778535d..2419a47f22 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1800,7 +1800,7 @@ int xc_cpuid_set(xc_interface *xch, char **config_transformed); int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, - uint32_t *featureset, + const uint32_t *featureset, unsigned int nr_features); int xc_mca_op(xc_interface *xch, struct xen_mc *mc); int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags, diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index 33b9e9fc85..a2d29a0fae 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -1,5 +1,5 @@ /*************************************************************************= ***** - * xc_cpuid_x86.c=20 + * xc_cpuid_x86.c * * Compute cpuid of a domain. * @@ -332,7 +332,7 @@ static void cpuid(const unsigned int *input, unsigned i= nt *regs) =20 static int get_cpuid_domain_info(xc_interface *xch, uint32_t domid, struct cpuid_domain_info *info, - uint32_t *featureset, + const uint32_t *featureset, unsigned int nr_features) { struct xen_domctl domctl =3D {}; @@ -807,8 +807,7 @@ static void sanitise_featureset(struct cpuid_domain_inf= o *info) } =20 int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, - uint32_t *featureset, - unsigned int nr_features) + const uint32_t *featureset, unsigned int nr_feat= ures) { struct cpuid_domain_info info =3D {}; unsigned int input[2] =3D { 0, 0 }, regs[4]; @@ -898,7 +897,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t d= omid, * 'k' -> pass through host value * 's' -> pass through the first time and then keep the same value * across save/restore and migration. - *=20 + * * For 's' and 'x' the configuration is overwritten with the value applied. */ int xc_cpuid_set( @@ -909,7 +908,8 @@ int xc_cpuid_set( unsigned int i, j, regs[4], polregs[4]; struct cpuid_domain_info info =3D {}; =20 - memset(config_transformed, 0, 4 * sizeof(*config_transformed)); + for ( i =3D 0; i < 4; ++i ) + config_transformed[i] =3D NULL; =20 rc =3D get_cpuid_domain_info(xch, domid, &info, NULL, 0); if ( rc ) @@ -927,7 +927,7 @@ int xc_cpuid_set( regs[i] =3D polregs[i]; continue; } - =20 + config_transformed[i] =3D calloc(33, 1); /* 32 bits, NUL terminato= r. */ if ( config_transformed[i] =3D=3D NULL ) { @@ -935,6 +935,13 @@ int xc_cpuid_set( goto fail; } =20 + /* + * Notes for following this algorithm: + * + * While it will accept any leaf data, it only makes sense to use = on + * feature leaves. regs[] initially contains the host values. Th= is, + * with the fall-through chain is how the 'k' option works. + */ for ( j =3D 0; j < 32; j++ ) { unsigned char val =3D !!((regs[i] & (1U << (31 - j)))); --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 26 04:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1568232406; cv=none; d=zoho.com; s=zohoarc; b=lKplh8yMiDGBBlZIZuXO3Udz3j1j+hqEYaC2t6R4LTFM/9EeA1sJqOOe61VnRCs2qUL6NYUDbnTsmBKPK7jFBAgyjrHEfqd7uY2rtz+IOS+29Z32nSGlkGw2I48dxbYoBnWA2Q6p3f8sHsGv48Fjq5OcpvXnruru3Xq3r+RoMw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568232406; 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=3kOsVS40V1M19EDgyP0KY2yEFq7SkdJUKq8GCDMAwHg=; b=hMRsKqFEuq8vnqsFWS9GfQJy6nv5hrxwv7GAb8awPBOtBxhZCzjG0q1tuKjMNIa5uqn9unnBO4fPnLRV8RxUdCyNnUroizOSRbHqSJumv+8Yrv50kyMLkvoe1kMQa/MLQpc9T2jPIoIc6Mc+go/85uQqZ26dr7ZquhQWZB8dtuw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1568232406009162.9809909178565; Wed, 11 Sep 2019 13:06:46 -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 1i88rf-000301-GT; Wed, 11 Sep 2019 20:05:19 +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 1i88re-0002zv-4q for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 20:05:18 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 76dcce3b-d4cf-11e9-83dd-12813bfff9fa; Wed, 11 Sep 2019 20:05:13 +0000 (UTC) X-Inumbo-ID: 76dcce3b-d4cf-11e9-83dd-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568232314; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vf1AG29drMqw2LT/Z66r4aJJqf5+EsSaB0/oRaGhy1U=; b=Fb6x6l7GhTtLYwIetbfFRQlzkbgUyg6bqmtagtEDAUifZ/XM6EbUURgv UiLUDy5iGMPw1rvtvLxPukM15ApHR3IXdeIJyelWrGwdFF6mtvKF7k9WP Ka5Q7Q89WRiCS2PIfZUebHb41Yn1omUlRID0Su2LvPpJvynrG2fhYSrmD M=; 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@mail.citrix.com 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=162.221.158.21; 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 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; 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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: +nKyXPXKqy3lx81FteDEfZSU9DIo1LYIMo+nWZao9CWra4UpLmTBCdgMMtCiWqVUE0P0VfMQ9P Fwr7JQz2ywdM8lDwSJIs/4YM6nh8Cex8eJ8wv+1wZT1xEAMoEQeBM6TKQ9hoRadptEJYGeZtHU exFt891zTg7MDwErmVyJNoiJHeVhCtTOyBM8qZLOsObF+GLaWrN93Y9146dqCQX9sZEwCVU5Ti pzZ/83z1EkFCk1jCJSa1PCGIHrLObPrv9XqCjKtwfGl+a9/baIvSOOFfI+UhMhohuqdy7j19OU 1q4= X-SBRS: 2.7 X-MesageID: 5451849 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,494,1559534400"; d="scan'208";a="5451849" From: Andrew Cooper To: Xen-devel Date: Wed, 11 Sep 2019 21:05:01 +0100 Message-ID: <20190911200504.5693-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 5/8] tools/libxc: Rework xc_cpuid_set() to use {get, set}_cpu_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 , Ian Jackson , 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" X-ZohoMail-DKIM: fail (Header signature does not verify) The purpose of this change is to stop using xc_cpuid_do_domctl(), and to st= op basing decisions on a local CPUID instruction. This is not an appropriate = way to construct policy information for other domains. Obtain the host and domain-max policies from Xen, and mix the results as before. Provide rather more error logging than before. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Ian Jackson --- tools/libxc/xc_cpuid_x86.c | 95 ++++++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 84 insertions(+), 11 deletions(-) diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index a2d29a0fae..d1a2b61214 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -905,20 +905,80 @@ int xc_cpuid_set( const char **config, char **config_transformed) { int rc; - unsigned int i, j, regs[4], polregs[4]; - struct cpuid_domain_info info =3D {}; + unsigned int i, j, regs[4] =3D {}, polregs[4] =3D {}; + xc_dominfo_t di; + xen_cpuid_leaf_t *leaves =3D NULL; + unsigned int nr_leaves, policy_leaves, nr_msrs; + uint32_t err_leaf =3D -1, err_subleaf =3D -1, err_msr =3D -1; =20 for ( i =3D 0; i < 4; ++i ) config_transformed[i] =3D NULL; =20 - rc =3D get_cpuid_domain_info(xch, domid, &info, NULL, 0); + if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || + di.domid !=3D domid ) + { + ERROR("Failed to obtain d%d info", domid); + rc =3D -ESRCH; + goto fail; + } + + rc =3D xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs); if ( rc ) - goto out; + { + PERROR("Failed to obtain policy info size"); + rc =3D -errno; + goto fail; + } =20 - cpuid(input, regs); + rc =3D -ENOMEM; + if ( (leaves =3D calloc(nr_leaves, sizeof(*leaves))) =3D=3D NULL ) + { + ERROR("Unable to allocate memory for %u CPUID leaves", nr_leaves); + goto fail; + } =20 - memcpy(polregs, regs, sizeof(regs)); - xc_cpuid_policy(&info, input, polregs); + /* Get the domain's max policy. */ + nr_msrs =3D 0; + policy_leaves =3D nr_leaves; + rc =3D xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hv= m_max + : XEN_SYSCTL_cpu_policy_pv_m= ax, + &policy_leaves, leaves, &nr_msrs, NULL); + if ( rc ) + { + PERROR("Failed to obtain %s max policy", di.hvm ? "hvm" : "pv"); + rc =3D -errno; + goto fail; + } + for ( i =3D 0; i < policy_leaves; ++i ) + if ( leaves[i].leaf =3D=3D input[0] && leaves[i].subleaf =3D=3D in= put[1] ) + { + polregs[0] =3D leaves[i].a; + polregs[1] =3D leaves[i].b; + polregs[2] =3D leaves[i].c; + polregs[3] =3D leaves[i].d; + break; + } + + /* Get the host policy. */ + nr_msrs =3D 0; + policy_leaves =3D nr_leaves; + rc =3D xc_get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host, + &policy_leaves, leaves, &nr_msrs, NULL); + if ( rc ) + { + PERROR("Failed to obtain host policy"); + rc =3D -errno; + goto fail; + } + for ( i =3D 0; i < policy_leaves; ++i ) + if ( leaves[i].leaf =3D=3D input[0] && leaves[i].subleaf =3D=3D in= put[1] ) + { + regs[0] =3D leaves[i].a; + regs[1] =3D leaves[i].b; + regs[2] =3D leaves[i].c; + regs[3] =3D leaves[i].d; + break; + } =20 for ( i =3D 0; i < 4; i++ ) { @@ -969,9 +1029,21 @@ int xc_cpuid_set( } } =20 - rc =3D xc_cpuid_do_domctl(xch, domid, input, regs); - if ( rc =3D=3D 0 ) - goto out; + /* Feed the transformed leaf back up to Xen. */ + leaves[0] =3D (xen_cpuid_leaf_t){ input[0], input[1], + regs[0], regs[1], regs[2], regs[3] }; + rc =3D xc_set_domain_cpu_policy(xch, domid, 1, leaves, 0, NULL, + &err_leaf, &err_subleaf, &err_msr); + if ( rc ) + { + PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr= %#x)", + domid, err_leaf, err_subleaf, err_msr); + rc =3D -errno; + goto fail; + } + + /* Success! */ + goto out; =20 fail: for ( i =3D 0; i < 4; i++ ) @@ -981,6 +1053,7 @@ int xc_cpuid_set( } =20 out: - free_cpuid_domain_info(&info); + free(leaves); + return rc; } --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 26 04:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1568232409; cv=none; d=zoho.com; s=zohoarc; b=imEd14oHW9YUEuArr2R2WkVERIEND1ZZFArNcE1PqT9ysWgA97sjo8r4n3RjjKjcxrgKrYL447rSN2mlfT6B2Vbi9j19eaBRevnm9HnqtPv21bT423Vy0aIGsBXj3cRRjFl2u3Pk0LHWZhFm5lP0+y3NLre7CFOyNhHrtyBUEDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568232409; 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=a881Txzj9EsyxxqYqyy+A4TDEMLOEnViWZhBa47KwaM=; b=Edvq+QLJSzp2jOO3hDUBNRjp+dtsTrC1IcvlHhfh0hsG6841mjdIbiMTeyFkoURQjZywmwpZG5Ezbzr37KE5CWf/9pdfKgtrfCXmezzZQYjinWKycAg1p4lrLGxS0XgvMYf1nGm/mH57Jdz4U6nRObaO6A5Rb35CWJsKrvJWCjs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1568232409463630.9695844397347; Wed, 11 Sep 2019 13:06:49 -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 1i88rp-00032W-PL; Wed, 11 Sep 2019 20:05:29 +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 1i88ro-00031l-4w for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 20:05:28 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 77eb7678-d4cf-11e9-83dd-12813bfff9fa; Wed, 11 Sep 2019 20:05:14 +0000 (UTC) X-Inumbo-ID: 77eb7678-d4cf-11e9-83dd-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568232315; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GlV4lkCRyDHeXhLWqes45S1ALyFSuCNDXCGmddoW7LU=; b=Nm73tg88JszplMdPIiE5xRgo+BRSv3/ahFt08urFW9StiUX7kCN8zUAx 1c60xTMI7c8/tD+rRkrGftJXUFzk9bU6BroZ5FFFY0yhnhzhIaNkwKY0M i7Ql0aobpxQgOgbfHRrY9Gfwagn6v9Cbc+thM+RsYppmMXXDAjbzTFsQS U=; Authentication-Results: esa1.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@mail.citrix.com 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 (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: sB2upHIq7COupJ7AdIKNAWIp8qwjNY5AULf5XRGRUDzpU8k5caTFT3/Vw7EaL8QaDWQhoYbQfD 44vuCleTaTRTHFzuOAdbbw5LIWTLHyfbBVOnSiSif0GOOogtWhnXfS8hgVGMH8ksfuzuRM8+0l 8KdtuVB+PTVKOnq5YcLmV/GcjSq6bgCkY6iXRe3a2XkaClo+hEFqMuI/Jmqq8mC6bxUS/+tTZX 9qaGpjSUlMPi+xmj4rsaPLZOZhENiwAngyHT5VpAxQne2+xXwCj9LZdV6NeSa/Dg2N0KfVIqLA Io4= X-SBRS: 2.7 X-MesageID: 5506247 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,494,1559534400"; d="scan'208";a="5506247" From: Andrew Cooper To: Xen-devel Date: Wed, 11 Sep 2019 21:05:02 +0100 Message-ID: <20190911200504.5693-7-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 6/8] tools/libxc: Rework xc_cpuid_apply_policy() to use {get, set}_cpu_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 , Ian Jackson , 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" X-ZohoMail-DKIM: fail (Header signature does not verify) The purpose of this change is to stop using xc_cpuid_do_domctl(), and to st= op basing decisions on a local CPUID instruction. This is not a correct or appropriate way to construct policy information for other domains. The overwhelming majority of this logic is redundant with the policy logic = in Xen, but has a habit of becoming stale (e.g. c/s 97e4ebdcd76 resulting in AVX512_BF16 not ever actually being offered to guests). There are a few subtle side effects which need to remain in place. A successful call to xc_cpuid_apply_policy() must result in a call to xc_set_domain_cpu_policy() because that is currently the only way the ITSC/VMX/SVM bits become reflected in the guests CPUID view. Future cleanup will remove this side effect. The topology tweaks are local to libxc. Extend struct cpuid_policy with enough named fields to express the logic, but keep it identical to before. Fixing topology representation is another future area of work. No (expected) change in behaviour. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Ian Jackson The repositioning of xc_cpuid_apply_policy() relative to xc_cpuid_set() is simply to make the diff readable. It is completely illegible otherwise. --- tools/libxc/xc_cpuid_x86.c | 798 ++++++++++--------------------------= ---- xen/include/xen/lib/x86/cpuid.h | 11 +- 2 files changed, 197 insertions(+), 612 deletions(-) diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index d1a2b61214..c88acbac9e 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -34,18 +34,13 @@ enum { =20 #include =20 -#include -#include +#include =20 #define bitmaskof(idx) (1u << ((idx) & 31)) #define featureword_of(idx) ((idx) >> 5) #define clear_feature(idx, dst) ((dst) &=3D ~bitmaskof(idx)) #define set_feature(idx, dst) ((dst) |=3D bitmaskof(idx)) =20 -#define DEF_MAX_BASE 0x0000000du -#define DEF_MAX_INTELEXT 0x80000008u -#define DEF_MAX_AMDEXT 0x8000001cu - int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps) { DECLARE_SYSCTL; @@ -278,609 +273,6 @@ int xc_set_domain_cpu_policy(xc_interface *xch, uint3= 2_t domid, return ret; } =20 -struct cpuid_domain_info -{ - unsigned int vendor; /* X86_VENDOR_* */ - - bool hvm; - uint64_t xfeature_mask; - - /* - * Careful with featureset lengths. - * - * Code in this file requires featureset to have at least - * xc_get_cpu_featureset_size() entries. This is a libxc compiletime - * constant. - * - * The featureset length used by the hypervisor may be different. If = the - * hypervisor version is longer, XEN_SYSCTL_get_cpu_featureset will fa= il - * with -ENOBUFS, and libxc really does need rebuilding. If the - * hypervisor version is shorter, it is safe to zero-extend. - */ - uint32_t *featureset; - unsigned int nr_features; - - /* PV-only information. */ - bool pv64; - - /* HVM-only information. */ - bool pae; - bool nestedhvm; -}; - -static void cpuid(const unsigned int *input, unsigned int *regs) -{ - unsigned int count =3D (input[1] =3D=3D XEN_CPUID_INPUT_UNUSED) ? 0 : = input[1]; -#ifdef __i386__ - /* Use the stack to avoid reg constraint failures with some gcc flags = */ - asm ( - "push %%ebx; push %%edx\n\t" - "cpuid\n\t" - "mov %%ebx,4(%4)\n\t" - "mov %%edx,12(%4)\n\t" - "pop %%edx; pop %%ebx\n\t" - : "=3Da" (regs[0]), "=3Dc" (regs[2]) - : "0" (input[0]), "1" (count), "S" (regs) - : "memory" ); -#else - asm ( - "cpuid" - : "=3Da" (regs[0]), "=3Db" (regs[1]), "=3Dc" (regs[2]), "=3Dd" (re= gs[3]) - : "0" (input[0]), "2" (count) ); -#endif -} - -static int get_cpuid_domain_info(xc_interface *xch, uint32_t domid, - struct cpuid_domain_info *info, - const uint32_t *featureset, - unsigned int nr_features) -{ - struct xen_domctl domctl =3D {}; - xc_dominfo_t di; - unsigned int in[2] =3D { 0, ~0U }, regs[4]; - unsigned int i, host_nr_features =3D xc_get_cpu_featureset_size(); - int rc; - - cpuid(in, regs); - info->vendor =3D x86_cpuid_lookup_vendor(regs[1], regs[2], regs[3]); - - if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || - di.domid !=3D domid ) - return -ESRCH; - - info->hvm =3D di.hvm; - - info->featureset =3D calloc(host_nr_features, sizeof(*info->featureset= )); - if ( !info->featureset ) - return -ENOMEM; - - info->nr_features =3D host_nr_features; - - if ( featureset ) - { - /* - * The user supplied featureset may be shorter or longer than - * host_nr_features. Shorter is fine, and we will zero-extend. - * Longer is fine, so long as it only padded with zeros. - */ - unsigned int fslen =3D min(host_nr_features, nr_features); - - memcpy(info->featureset, featureset, - fslen * sizeof(*info->featureset)); - - /* Check for truncated set bits. */ - for ( i =3D fslen; i < nr_features; ++i ) - if ( featureset[i] !=3D 0 ) - return -EOPNOTSUPP; - } - else - { - rc =3D xc_get_cpu_featureset(xch, (info->hvm - ? XEN_SYSCTL_cpu_featureset_hvm - : XEN_SYSCTL_cpu_featureset_pv), - &host_nr_features, info->featureset); - if ( rc ) - return -errno; - } - - /* Get xstate information. */ - domctl.cmd =3D XEN_DOMCTL_getvcpuextstate; - domctl.domain =3D domid; - rc =3D do_domctl(xch, &domctl); - if ( rc ) - return -errno; - - info->xfeature_mask =3D domctl.u.vcpuextstate.xfeature_mask; - - if ( di.hvm ) - { - uint64_t val; - - rc =3D xc_hvm_param_get(xch, domid, HVM_PARAM_PAE_ENABLED, &val); - if ( rc ) - return -errno; - - info->pae =3D !!val; - - rc =3D xc_hvm_param_get(xch, domid, HVM_PARAM_NESTEDHVM, &val); - if ( rc ) - return -errno; - - info->nestedhvm =3D !!val; - } - else - { - unsigned int width; - - rc =3D xc_domain_get_guest_width(xch, domid, &width); - if ( rc ) - return -errno; - - info->pv64 =3D (width =3D=3D 8); - } - - return 0; -} - -static void free_cpuid_domain_info(struct cpuid_domain_info *info) -{ - free(info->featureset); -} - -static void amd_xc_cpuid_policy(const struct cpuid_domain_info *info, - const unsigned int *input, unsigned int *r= egs) -{ - switch ( input[0] ) - { - case 0x00000002: - case 0x00000004: - regs[0] =3D regs[1] =3D regs[2] =3D 0; - break; - - case 0x80000000: - if ( regs[0] > DEF_MAX_AMDEXT ) - regs[0] =3D DEF_MAX_AMDEXT; - break; - - case 0x80000008: - /* - * ECX[15:12] is ApicIdCoreSize: ECX[7:0] is NumberOfCores (minus = one). - * Update to reflect vLAPIC_ID =3D vCPU_ID * 2. - */ - regs[2] =3D ((regs[2] + (1u << 12)) & 0xf000u) | - ((regs[2] & 0xffu) << 1) | 1u; - break; - - case 0x8000000a: { - if ( !info->nestedhvm ) - { - regs[0] =3D regs[1] =3D regs[2] =3D regs[3] =3D 0; - break; - } - -#define SVM_FEATURE_NPT 0x00000001 /* Nested page table support= */ -#define SVM_FEATURE_LBRV 0x00000002 /* LBR virtualization suppor= t */ -#define SVM_FEATURE_SVML 0x00000004 /* SVM locking MSR support */ -#define SVM_FEATURE_NRIPS 0x00000008 /* Next RIP save on VMEXIT */ -#define SVM_FEATURE_TSCRATEMSR 0x00000010 /* TSC ratio MSR support */ -#define SVM_FEATURE_VMCBCLEAN 0x00000020 /* VMCB clean bits support */ -#define SVM_FEATURE_FLUSHBYASID 0x00000040 /* TLB flush by ASID support= */ -#define SVM_FEATURE_DECODEASSISTS 0x00000080 /* Decode assists support */ -#define SVM_FEATURE_PAUSEFILTER 0x00000400 /* Pause intercept filter */ - - /* Pass 1: Only passthrough SVM features which are - * available in hw and which are implemented - */ - regs[3] &=3D (SVM_FEATURE_NPT | SVM_FEATURE_LBRV | \ - SVM_FEATURE_NRIPS | SVM_FEATURE_PAUSEFILTER | \ - SVM_FEATURE_DECODEASSISTS); - - /* Pass 2: Always enable SVM features which are emulated */ - regs[3] |=3D SVM_FEATURE_VMCBCLEAN | SVM_FEATURE_TSCRATEMSR; - break; - } - - } -} - -static void intel_xc_cpuid_policy(const struct cpuid_domain_info *info, - const unsigned int *input, unsigned int = *regs) -{ - switch ( input[0] ) - { - case 0x00000004: - /* - * EAX[31:26] is Maximum Cores Per Package (minus one). - * Update to reflect vLAPIC_ID =3D vCPU_ID * 2. - */ - regs[0] =3D (((regs[0] & 0x7c000000u) << 1) | 0x04000000u | - (regs[0] & 0x3ffu)); - regs[3] &=3D 0x3ffu; - break; - - case 0x80000000: - if ( regs[0] > DEF_MAX_INTELEXT ) - regs[0] =3D DEF_MAX_INTELEXT; - break; - - case 0x80000005: - regs[0] =3D regs[1] =3D regs[2] =3D 0; - break; - - case 0x80000008: - /* Mask AMD Number of Cores information. */ - regs[2] =3D 0; - break; - } -} - -static void xc_cpuid_hvm_policy(const struct cpuid_domain_info *info, - const unsigned int *input, unsigned int *r= egs) -{ - switch ( input[0] ) - { - case 0x00000000: - if ( regs[0] > DEF_MAX_BASE ) - regs[0] =3D DEF_MAX_BASE; - break; - - case 0x00000001: - /* - * EBX[23:16] is Maximum Logical Processors Per Package. - * Update to reflect vLAPIC_ID =3D vCPU_ID * 2. - */ - regs[1] =3D (regs[1] & 0x0000ffffu) | ((regs[1] & 0x007f0000u) << = 1); - - regs[2] =3D info->featureset[featureword_of(X86_FEATURE_SSE3)]; - regs[3] =3D (info->featureset[featureword_of(X86_FEATURE_FPU)] | - bitmaskof(X86_FEATURE_HTT)); - break; - - case 0x00000007: /* Intel-defined CPU features */ - if ( input[1] =3D=3D 0 ) - { - regs[1] =3D info->featureset[featureword_of(X86_FEATURE_FSGSBA= SE)]; - regs[2] =3D info->featureset[featureword_of(X86_FEATURE_PREFET= CHWT1)]; - regs[3] =3D info->featureset[featureword_of(X86_FEATURE_AVX512= _4VNNIW)]; - } - else - { - regs[1] =3D 0; - regs[2] =3D 0; - regs[3] =3D 0; - } - regs[0] =3D 0; - break; - - case 0x0000000d: /* Xen automatically calculates almost everything. */ - if ( input[1] =3D=3D 1 ) - regs[0] =3D info->featureset[featureword_of(X86_FEATURE_XSAVEO= PT)]; - else - regs[0] =3D 0; - regs[1] =3D regs[2] =3D regs[3] =3D 0; - break; - - case 0x80000000: - /* Passthrough to cpu vendor specific functions */ - break; - - case 0x80000001: - regs[2] =3D (info->featureset[featureword_of(X86_FEATURE_LAHF_LM)]= & - ~bitmaskof(X86_FEATURE_CMP_LEGACY)); - regs[3] =3D info->featureset[featureword_of(X86_FEATURE_SYSCALL)]; - break; - - case 0x80000007: - /* - * Keep only TSCInvariant. This may be cleared by the hypervisor - * depending on guest TSC and migration settings. - */ - regs[0] =3D regs[1] =3D regs[2] =3D 0; - regs[3] &=3D 1u<<8; - break; - - case 0x80000008: - regs[0] &=3D 0x0000ffffu; - regs[1] =3D info->featureset[featureword_of(X86_FEATURE_CLZERO)]; - /* regs[2] handled in the per-vendor logic. */ - regs[3] =3D 0; - break; - - case 0x00000002: /* Intel cache info (dumped by AMD policy) */ - case 0x00000004: /* Intel cache info (dumped by AMD policy) */ - case 0x0000000a: /* Architectural Performance Monitor Features */ - case 0x80000002: /* Processor name string */ - case 0x80000003: /* ... continued */ - case 0x80000004: /* ... continued */ - case 0x80000005: /* AMD L1 cache/TLB info (dumped by Intel policy) */ - case 0x80000006: /* AMD L2/3 cache/TLB info ; Intel L2 cache features = */ - case 0x8000000a: /* AMD SVM feature bits */ - case 0x80000019: /* AMD 1G TLB */ - case 0x8000001a: /* AMD perf hints */ - case 0x8000001c: /* AMD lightweight profiling */ - break; - - default: - regs[0] =3D regs[1] =3D regs[2] =3D regs[3] =3D 0; - break; - } - - if ( info->vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON) ) - amd_xc_cpuid_policy(info, input, regs); - else - intel_xc_cpuid_policy(info, input, regs); -} - -static void xc_cpuid_pv_policy(const struct cpuid_domain_info *info, - const unsigned int *input, unsigned int *re= gs) -{ - switch ( input[0] ) - { - case 0x00000000: - if ( regs[0] > DEF_MAX_BASE ) - regs[0] =3D DEF_MAX_BASE; - break; - - case 0x00000001: - { - /* Host topology exposed to PV guest. Provide host value. */ - bool host_htt =3D regs[3] & bitmaskof(X86_FEATURE_HTT); - - /* - * Don't pick host's Initial APIC ID which can change from run - * to run. - */ - regs[1] &=3D 0x00ffffffu; - - regs[2] =3D info->featureset[featureword_of(X86_FEATURE_SSE3)]; - regs[3] =3D (info->featureset[featureword_of(X86_FEATURE_FPU)] & - ~bitmaskof(X86_FEATURE_HTT)); - - if ( host_htt ) - regs[3] |=3D bitmaskof(X86_FEATURE_HTT); - break; - } - - case 0x00000007: - if ( input[1] =3D=3D 0 ) - { - regs[1] =3D info->featureset[featureword_of(X86_FEATURE_FSGSBA= SE)]; - regs[2] =3D info->featureset[featureword_of(X86_FEATURE_PREFET= CHWT1)]; - regs[3] =3D info->featureset[featureword_of(X86_FEATURE_AVX512= _4VNNIW)]; - } - else - { - regs[1] =3D 0; - regs[2] =3D 0; - regs[3] =3D 0; - } - regs[0] =3D 0; - break; - - case 0x0000000d: /* Xen automatically calculates almost everything. */ - if ( input[1] =3D=3D 1 ) - regs[0] =3D info->featureset[featureword_of(X86_FEATURE_XSAVEO= PT)]; - else - regs[0] =3D 0; - regs[1] =3D regs[2] =3D regs[3] =3D 0; - break; - - case 0x80000000: - { - unsigned int max =3D (info->vendor & (X86_VENDOR_AMD | X86_VENDOR_= HYGON)) - ? DEF_MAX_AMDEXT : DEF_MAX_INTELEXT; - - if ( regs[0] > max ) - regs[0] =3D max; - break; - } - - case 0x80000001: - { - /* Host topology exposed to PV guest. Provide host CMP_LEGACY val= ue. */ - bool host_cmp_legacy =3D regs[2] & bitmaskof(X86_FEATURE_CMP_LEGAC= Y); - - regs[2] =3D (info->featureset[featureword_of(X86_FEATURE_LAHF_LM)]= & - ~bitmaskof(X86_FEATURE_CMP_LEGACY)); - regs[3] =3D info->featureset[featureword_of(X86_FEATURE_SYSCALL)]; - - if ( host_cmp_legacy ) - regs[2] |=3D bitmaskof(X86_FEATURE_CMP_LEGACY); - - break; - } - - case 0x80000008: - regs[0] &=3D 0x0000ffffu; - regs[1] =3D info->featureset[featureword_of(X86_FEATURE_CLZERO)]; - regs[2] =3D regs[3] =3D 0; - break; - - case 0x00000005: /* MONITOR/MWAIT */ - case 0x0000000b: /* Extended Topology Enumeration */ - case 0x8000000a: /* SVM revision and features */ - case 0x8000001b: /* Instruction Based Sampling */ - case 0x8000001c: /* Light Weight Profiling */ - case 0x8000001e: /* Extended topology reporting */ - regs[0] =3D regs[1] =3D regs[2] =3D regs[3] =3D 0; - break; - } -} - -static void xc_cpuid_policy(const struct cpuid_domain_info *info, - const unsigned int *input, unsigned int *regs) -{ - /* - * For hypervisor leaves (0x4000XXXX) only 0x4000xx00.EAX[7:0] bits (m= ax - * number of leaves) can be set by user. Hypervisor will enforce this = so - * all other bits are don't-care and we can set them to zero. - */ - if ( (input[0] & 0xffff0000) =3D=3D 0x40000000 ) - { - regs[0] =3D regs[1] =3D regs[2] =3D regs[3] =3D 0; - return; - } - - if ( info->hvm ) - xc_cpuid_hvm_policy(info, input, regs); - else - xc_cpuid_pv_policy(info, input, regs); -} - -static int xc_cpuid_do_domctl( - xc_interface *xch, uint32_t domid, - const unsigned int *input, const unsigned int *regs) -{ - DECLARE_DOMCTL; - - memset(&domctl, 0, sizeof (domctl)); - domctl.domain =3D domid; - domctl.cmd =3D XEN_DOMCTL_set_cpuid; - domctl.u.cpuid.input[0] =3D input[0]; - domctl.u.cpuid.input[1] =3D input[1]; - domctl.u.cpuid.eax =3D regs[0]; - domctl.u.cpuid.ebx =3D regs[1]; - domctl.u.cpuid.ecx =3D regs[2]; - domctl.u.cpuid.edx =3D regs[3]; - - return do_domctl(xch, &domctl); -} - -static void sanitise_featureset(struct cpuid_domain_info *info) -{ - const uint32_t fs_size =3D xc_get_cpu_featureset_size(); - uint32_t disabled_features[fs_size]; - static const uint32_t deep_features[] =3D INIT_DEEP_FEATURES; - unsigned int i, b; - - if ( info->hvm ) - { - /* HVM or PVH Guest */ - - if ( !info->pae ) - clear_bit(X86_FEATURE_PAE, info->featureset); - - if ( !info->nestedhvm ) - { - clear_bit(X86_FEATURE_SVM, info->featureset); - clear_bit(X86_FEATURE_VMX, info->featureset); - } - } - else - { - /* PV Guest */ - - if ( !info->pv64 ) - { - clear_bit(X86_FEATURE_LM, info->featureset); - if ( !(info->vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)) ) - clear_bit(X86_FEATURE_SYSCALL, info->featureset); - } - - clear_bit(X86_FEATURE_PSE, info->featureset); - clear_bit(X86_FEATURE_PSE36, info->featureset); - clear_bit(X86_FEATURE_PGE, info->featureset); - clear_bit(X86_FEATURE_PAGE1GB, info->featureset); - } - - if ( info->xfeature_mask =3D=3D 0 ) - clear_bit(X86_FEATURE_XSAVE, info->featureset); - - /* Disable deep dependencies of disabled features. */ - for ( i =3D 0; i < ARRAY_SIZE(disabled_features); ++i ) - disabled_features[i] =3D ~info->featureset[i] & deep_features[i]; - - for ( b =3D 0; b < sizeof(disabled_features) * CHAR_BIT; ++b ) - { - const uint32_t *dfs; - - if ( !test_bit(b, disabled_features) || - !(dfs =3D x86_cpuid_lookup_deep_deps(b)) ) - continue; - - for ( i =3D 0; i < ARRAY_SIZE(disabled_features); ++i ) - { - info->featureset[i] &=3D ~dfs[i]; - disabled_features[i] &=3D ~dfs[i]; - } - } -} - -int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, - const uint32_t *featureset, unsigned int nr_feat= ures) -{ - struct cpuid_domain_info info =3D {}; - unsigned int input[2] =3D { 0, 0 }, regs[4]; - unsigned int base_max, ext_max; - int rc; - - rc =3D get_cpuid_domain_info(xch, domid, &info, featureset, nr_feature= s); - if ( rc ) - goto out; - - cpuid(input, regs); - base_max =3D (regs[0] <=3D DEF_MAX_BASE) ? regs[0] : DEF_MAX_BASE; - input[0] =3D 0x80000000; - cpuid(input, regs); - - if ( info.vendor =3D=3D X86_VENDOR_AMD || info.vendor =3D=3D X86_VENDO= R_HYGON ) - ext_max =3D (regs[0] <=3D DEF_MAX_AMDEXT) ? regs[0] : DEF_MAX_AMDE= XT; - else - ext_max =3D (regs[0] <=3D DEF_MAX_INTELEXT) ? regs[0] : DEF_MAX_IN= TELEXT; - - sanitise_featureset(&info); - - input[0] =3D 0; - input[1] =3D XEN_CPUID_INPUT_UNUSED; - for ( ; ; ) - { - cpuid(input, regs); - xc_cpuid_policy(&info, input, regs); - - if ( regs[0] || regs[1] || regs[2] || regs[3] ) - { - rc =3D xc_cpuid_do_domctl(xch, domid, input, regs); - if ( rc ) - goto out; - } - - /* Intel cache descriptor leaves. */ - if ( input[0] =3D=3D 4 ) - { - input[1]++; - /* More to do? Then loop keeping %%eax=3D=3D0x00000004. */ - if ( (regs[0] & 0x1f) !=3D 0 ) - continue; - } - /* Extended Topology leaves. */ - else if ( input[0] =3D=3D 0xb ) - { - uint8_t level_type =3D regs[2] >> 8; - - input[1]++; - if ( level_type >=3D 1 && level_type <=3D 2 ) - continue; - } - - input[0]++; - if ( !(input[0] & 0x80000000u) && (input[0] > base_max ) ) - input[0] =3D 0x80000000u; - - input[1] =3D XEN_CPUID_INPUT_UNUSED; - if ( (input[0] =3D=3D 4) || (input[0] =3D=3D 7) || (input[0] =3D= =3D 0xb) ) - input[1] =3D 0; - else if ( input[0] =3D=3D 0xd ) - input[1] =3D 1; /* Xen automatically calculates almost everyth= ing. */ - - if ( (input[0] & 0x80000000u) && (input[0] > ext_max) ) - break; - } - - out: - free_cpuid_domain_info(&info); - return rc; -} - /* * Configure a single input with the informatiom from config. * @@ -1057,3 +449,191 @@ int xc_cpuid_set( =20 return rc; } + +int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, + const uint32_t *featureset, unsigned int nr_feat= ures) +{ + int rc; + xc_dominfo_t di; + unsigned int i, nr_leaves, nr_msrs; + xen_cpuid_leaf_t *leaves =3D NULL; + struct cpuid_policy *p =3D NULL; + uint32_t err_leaf =3D -1, err_subleaf =3D -1, err_msr =3D -1; + + if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || + di.domid !=3D domid ) + { + ERROR("Failed to obtain d%d info", domid); + rc =3D -ESRCH; + goto out; + } + + rc =3D xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs); + if ( rc ) + { + PERROR("Failed to obtain policy info size"); + rc =3D -errno; + goto out; + } + + rc =3D -ENOMEM; + if ( (leaves =3D calloc(nr_leaves, sizeof(*leaves))) =3D=3D NULL || + (p =3D calloc(1, sizeof(*p))) =3D=3D NULL ) + goto out; + + nr_msrs =3D 0; + rc =3D xc_get_domain_cpu_policy(xch, domid, &nr_leaves, leaves, + &nr_msrs, NULL); + if ( rc ) + { + PERROR("Failed to obtain d%d's policy", domid); + rc =3D -errno; + goto out; + } + + rc =3D x86_cpuid_copy_from_buffer(p, leaves, nr_leaves, + &err_leaf, &err_subleaf); + if ( rc ) + { + ERROR("Failed to deserialise CPUID (err leaf %#x, subleaf %#x) (%d= =3D %s)", + err_leaf, err_subleaf, -rc, strerror(-rc)); + goto out; + } + + if ( featureset ) + { + uint32_t disabled_features[FEATURESET_NR_ENTRIES], + feat[FEATURESET_NR_ENTRIES] =3D {}; + static const uint32_t deep_features[] =3D INIT_DEEP_FEATURES; + unsigned int i, b; + + /* + * The user supplied featureset may be shorter or longer than + * FEATURESET_NR_ENTRIES. Shorter is fine, and we will zero-exten= d. + * Longer is fine, so long as it only padded with zeros. + */ + unsigned int user_len =3D min(FEATURESET_NR_ENTRIES + 0u, nr_featu= res); + + /* Check for truncated set bits. */ + rc =3D -EOPNOTSUPP; + for ( i =3D user_len; i < nr_features; ++i ) + if ( featureset[i] !=3D 0 ) + goto out; + + memcpy(feat, featureset, sizeof(*featureset) * user_len); + + /* Disable deep dependencies of disabled features. */ + for ( i =3D 0; i < ARRAY_SIZE(disabled_features); ++i ) + disabled_features[i] =3D ~feat[i] & deep_features[i]; + + for ( b =3D 0; b < sizeof(disabled_features) * CHAR_BIT; ++b ) + { + const uint32_t *dfs; + + if ( !test_bit(b, disabled_features) || + !(dfs =3D x86_cpuid_lookup_deep_deps(b)) ) + continue; + + for ( i =3D 0; i < ARRAY_SIZE(disabled_features); ++i ) + { + feat[i] &=3D ~dfs[i]; + disabled_features[i] &=3D ~dfs[i]; + } + } + + cpuid_featureset_to_policy(feat, p); + } + + if ( !di.hvm ) + { + uint32_t host_featureset[FEATURESET_NR_ENTRIES]; + uint32_t len =3D ARRAY_SIZE(host_featureset); + + rc =3D xc_get_cpu_featureset(xch, XEN_SYSCTL_cpu_featureset_host, + &len, host_featureset); + if ( rc ) + { + /* Tolerate "buffer too small", as we've got the bits we need.= */ + if ( errno =3D=3D ENOBUFS ) + rc =3D 0; + else + { + PERROR("Failed to obtain host featureset"); + rc =3D -errno; + goto out; + } + } + + /* + * On hardware without CPUID Faulting, PV guests see real topology. + * As a consequence, they also need to see the host htt/cmp fields. + */ + p->basic.htt =3D test_bit(X86_FEATURE_HTT, host_featureset); + p->extd.cmp_legacy =3D test_bit(X86_FEATURE_CMP_LEGACY, host_featu= reset); + } + else + { + /* + * Topology for HVM guests is entirely controlled by Xen. For now= , we + * hardcode APIC_ID =3D vcpu_id * 2 to give the illusion of no SMT. + */ + p->basic.htt =3D true; + p->extd.cmp_legacy =3D false; + + p->basic.lppp *=3D 2; + + switch ( p->x86_vendor ) + { + case X86_VENDOR_INTEL: + for ( i =3D 0; (p->cache.subleaf[i].type && + i < ARRAY_SIZE(p->cache.raw)); ++i ) + { + p->cache.subleaf[i].cores_per_package =3D + (p->cache.subleaf[i].cores_per_package << 1) | 1; + p->cache.subleaf[i].threads_per_cache =3D 0; + } + break; + + case X86_VENDOR_AMD: + case X86_VENDOR_HYGON: + p->extd.nc =3D (p->extd.nc << 1) | 1; + p->extd.apic_id_size++; + break; + } + + /* + * These settings are necessary to cause earlier HVM_PARAM_NESTEDH= VM / + * XEN_DOMCTL_disable_migrate settings to be reflected correctly in + * CPUID. Xen will discard these bits if configuration hasn't been + * set for the domain. + */ + p->extd.itsc =3D true; + p->basic.vmx =3D true; + p->extd.svm =3D true; + } + + rc =3D x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves); + if ( rc ) + { + ERROR("Failed to serialise CPUID (%d =3D %s)", -rc, strerror(-rc)); + goto out; + } + + rc =3D xc_set_domain_cpu_policy(xch, domid, nr_leaves, leaves, 0, NULL, + &err_leaf, &err_subleaf, &err_msr); + if ( rc ) + { + PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr= %#x)", + domid, err_leaf, err_subleaf, err_msr); + rc =3D -errno; + goto out; + } + + rc =3D 0; + +out: + free(p); + free(leaves); + + return rc; +} diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpui= d.h index df5946b6b1..6c86c1a0d0 100644 --- a/xen/include/xen/lib/x86/cpuid.h +++ b/xen/include/xen/lib/x86/cpuid.h @@ -154,8 +154,12 @@ struct cpuid_policy union { struct cpuid_leaf raw[CPUID_GUEST_NR_CACHE]; struct cpuid_cache_leaf { - uint32_t type:5, - :27, :32, :32, :32; + uint32_t /* a */ type:5, level:3; + bool self_init:1, fully_assoc:1; + uint32_t :4, threads_per_cache:12, cores_per_package:6; + uint32_t /* b */ line_size:12, partitions:10, ways:10; + uint32_t /* c */ sets; + bool /* d */ wbinvd:1, inclusive:1, complex:1; } subleaf[CPUID_GUEST_NR_CACHE]; } cache; =20 @@ -259,7 +263,8 @@ struct cpuid_policy uint32_t e8b; struct { DECL_BITFIELD(e8b); }; }; - uint32_t /* c */:32, /* d */:32; + uint32_t nc:8, :4, apic_id_size:4, :16; + uint32_t /* d */:32; }; } extd; =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 26 04:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1568232408; cv=none; d=zoho.com; s=zohoarc; b=E0unT/QE1qUwlAfRBcof5fFM2XpRodoB33CHPc3mhvD/S96F1S5bU/Frv7kntXnFzr8ZAiSbhNmU/DaTAgDS3+2aQIFUAwLl+dBWwWN2HAFdPDVjl+7y0oNUiqQnu4pp0fqrTfdjyqauKBvBvYhGBJyNyPC81EMbv5CVWZiR9WY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568232408; 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=qo9p5LgzYiiQsiOJq8y9NGeiRBZ2NO1V8zCN4efS/28=; b=K7/DZ+74Tvwu+tFsAMRDWfaRY2CCJu54JFkA4RgZFsEYoZVaMHgzoUvdKgbXq62E/qUEBv8BbCFJP8E5Sbxw8yY9usD/PDcnyajbR+wUzsJYH891XcS24JfZHzDQZKQ3ru/i0Ps2uhAIoyTALwjJ/3KHjg2Zn5+nR+1955cWAnU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1568232408801633.0719520880895; Wed, 11 Sep 2019 13:06:48 -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 1i88ru-00034e-Ar; Wed, 11 Sep 2019 20:05:34 +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 1i88rt-000346-5Y for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 20:05:33 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 784cd580-d4cf-11e9-83dd-12813bfff9fa; Wed, 11 Sep 2019 20:05:15 +0000 (UTC) X-Inumbo-ID: 784cd580-d4cf-11e9-83dd-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568232316; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GifxMjGTHY9r+VAau+BqTozFP4UmkZ1smS1EjoSb2Gk=; b=d9V7Nu+PqRC5OS7q+sdlsF1x3Tfi7NadfjCP2Gq6axH1xOUMJuk7WsGM FSxF42PBbtYhcp/dKyMYBHECHRXcv6+sJrClcahhK5NidNjx60rk7Oa5t NzadMKAEkktSWwWoNLutgXsFeeU/IbNIcGOEqZsgTN8T4esgdDSKtwoSH Y=; Authentication-Results: esa1.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@mail.citrix.com 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 (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: QJ3TOWKBR+GY3A4AqH0bXAC9iMRHXNL4CY/sA6REK4lbe+9+XSgoSTMzQI3OPh9WJPCztASYHY zGnJ9fI4ETj2nzHk7Hegtb5pekW7+PZcRYfgfzLSaWutlfKaiMg+1RHakaVJOS0MnPg/8etmr9 oabfvsVI+5bwtsUBbzh5b3FSXyIaxsjBoALRh20RcWWVJ1ACszMF5Dimzc7hrdpqr0Cvy/5H0d CC1dOKA90IFxHfNHb8Nu1BmG9GVObaeOWBgrnQGbcCFtv9MnM2Z6o67LnGvqRm2bm066HXjcnV 5jw= X-SBRS: 2.7 X-MesageID: 5506248 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,494,1559534400"; d="scan'208";a="5506248" From: Andrew Cooper To: Xen-devel Date: Wed, 11 Sep 2019 21:05:03 +0100 Message-ID: <20190911200504.5693-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 7/8] x86/domctl: Drop XEN_DOMCTL_set_cpuid 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 , Daniel De Graaf , 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" X-ZohoMail-DKIM: fail (Header signature does not verify) With the final users moved over to using XEN_DOMCTL_set_cpumsr_policy, drop this domctl and associated infrastructure. Rename the preexisting set_cpuid XSM vector to set_cpu_policy, now that it = is back to having a single user. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Daniel De Graaf --- tools/flask/policy/modules/dom0.te | 2 +- tools/flask/policy/modules/xen.if | 2 +- xen/arch/x86/domctl.c | 101 --------------------------------= ---- xen/include/public/domctl.h | 11 +--- xen/xsm/flask/hooks.c | 3 +- xen/xsm/flask/policy/access_vectors | 3 +- 6 files changed, 5 insertions(+), 117 deletions(-) diff --git a/tools/flask/policy/modules/dom0.te b/tools/flask/policy/module= s/dom0.te index 9970f9dc08..272f6a4f75 100644 --- a/tools/flask/policy/modules/dom0.te +++ b/tools/flask/policy/modules/dom0.te @@ -38,7 +38,7 @@ allow dom0_t dom0_t:domain { getpodtarget setpodtarget set_misc_info set_virq_handler }; allow dom0_t dom0_t:domain2 { - set_cpuid gettsc settsc setscheduler set_vnumainfo + set_cpu_policy gettsc settsc setscheduler set_vnumainfo get_vnumainfo psr_cmt_op psr_alloc get_cpu_policy }; allow dom0_t dom0_t:resource { add remove }; diff --git a/tools/flask/policy/modules/xen.if b/tools/flask/policy/modules= /xen.if index de5fb331bf..8eb2293a52 100644 --- a/tools/flask/policy/modules/xen.if +++ b/tools/flask/policy/modules/xen.if @@ -50,7 +50,7 @@ define(`create_domain_common', ` getdomaininfo hypercall setvcpucontext getscheduler getvcpuinfo getaddrsize getaffinity setaffinity settime setdomainhandle getvcpucontext set_misc_info }; - allow $1 $2:domain2 { set_cpuid settsc setscheduler setclaim + allow $1 $2:domain2 { set_cpu_policy settsc setscheduler setclaim set_vnumainfo get_vnumainfo cacheflush psr_cmt_op psr_alloc soft_reset resource_map get_cpu_policy }; diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 99bc2fb10d..ec50a88156 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -206,94 +206,6 @@ static void domain_cpu_policy_changed(struct domain *d) } } =20 -static int update_domain_cpuid_info(struct domain *d, - const struct xen_domctl_cpuid *ctl) -{ - struct cpuid_policy *p =3D d->arch.cpuid; - const struct cpuid_leaf leaf =3D { ctl->eax, ctl->ebx, ctl->ecx, ctl->= edx }; - - /* - * Skip update for leaves we don't care about, to avoid the overhead of - * recalculate_cpuid_policy(). - */ - switch ( ctl->input[0] ) - { - case 0x00000000 ... ARRAY_SIZE(p->basic.raw) - 1: - if ( ctl->input[0] =3D=3D 4 && - ctl->input[1] >=3D ARRAY_SIZE(p->cache.raw) ) - return 0; - - if ( ctl->input[0] =3D=3D 7 && - ctl->input[1] >=3D ARRAY_SIZE(p->feat.raw) ) - return 0; - - if ( ctl->input[0] =3D=3D 0xb && - ctl->input[1] >=3D ARRAY_SIZE(p->topo.raw) ) - return 0; - - BUILD_BUG_ON(ARRAY_SIZE(p->xstate.raw) < 2); - if ( ctl->input[0] =3D=3D XSTATE_CPUID && - ctl->input[1] !=3D 1 ) /* Everything else automatically calcu= lated. */ - return 0; - break; - - case 0x40000000: case 0x40000100: - /* Only care about the max_leaf limit. */ - - case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1: - break; - - default: - return 0; - } - - /* Insert ctl data into cpuid_policy. */ - switch ( ctl->input[0] ) - { - case 0x00000000 ... ARRAY_SIZE(p->basic.raw) - 1: - switch ( ctl->input[0] ) - { - case 4: - p->cache.raw[ctl->input[1]] =3D leaf; - break; - - case 7: - p->feat.raw[ctl->input[1]] =3D leaf; - break; - - case 0xb: - p->topo.raw[ctl->input[1]] =3D leaf; - break; - - case XSTATE_CPUID: - p->xstate.raw[ctl->input[1]] =3D leaf; - break; - - default: - p->basic.raw[ctl->input[0]] =3D leaf; - break; - } - break; - - case 0x40000000: - p->hv_limit =3D ctl->eax; - break; - - case 0x40000100: - p->hv2_limit =3D ctl->eax; - break; - - case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1: - p->extd.raw[ctl->input[0] - 0x80000000] =3D leaf; - break; - } - - recalculate_cpuid_policy(d); - domain_cpu_policy_changed(d); - - return 0; -} - static int update_domain_cpu_policy(struct domain *d, xen_domctl_cpu_policy_t *xdpc) { @@ -951,19 +863,6 @@ long arch_do_domctl( break; } =20 - case XEN_DOMCTL_set_cpuid: - if ( d =3D=3D currd ) /* no domain_pause() */ - ret =3D -EINVAL; - else if ( d->creation_finished ) - ret =3D -EEXIST; /* No changing once the domain is running. */ - else - { - domain_pause(d); - ret =3D update_domain_cpuid_info(d, &domctl->u.cpuid); - domain_unpause(d); - } - break; - case XEN_DOMCTL_gettscinfo: if ( d =3D=3D currd ) /* no domain_pause() */ ret =3D -EINVAL; diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 0471d3c680..548b917bdb 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -648,14 +648,6 @@ struct xen_domctl_set_target { =20 #if defined(__i386__) || defined(__x86_64__) # define XEN_CPUID_INPUT_UNUSED 0xFFFFFFFF -/* XEN_DOMCTL_set_cpuid */ -struct xen_domctl_cpuid { - uint32_t input[2]; - uint32_t eax; - uint32_t ebx; - uint32_t ecx; - uint32_t edx; -}; =20 /* * XEN_DOMCTL_{get,set}_cpu_policy (x86 specific) @@ -1166,7 +1158,7 @@ struct xen_domctl { #define XEN_DOMCTL_set_target 46 #define XEN_DOMCTL_deassign_device 47 #define XEN_DOMCTL_unbind_pt_irq 48 -#define XEN_DOMCTL_set_cpuid 49 +/* #define XEN_DOMCTL_set_cpuid 49 - Obsolete - use set_c= pu_policy */ #define XEN_DOMCTL_get_device_group 50 /* #define XEN_DOMCTL_set_machine_address_size 51 - Obsolete */ /* #define XEN_DOMCTL_get_machine_address_size 52 - Obsolete */ @@ -1243,7 +1235,6 @@ struct xen_domctl { struct xen_domctl_vm_event_op vm_event_op; struct xen_domctl_mem_sharing_op mem_sharing_op; #if defined(__i386__) || defined(__x86_64__) - struct xen_domctl_cpuid cpuid; struct xen_domctl_cpu_policy cpu_policy; struct xen_domctl_vcpuextstate vcpuextstate; struct xen_domctl_vcpu_msrs vcpu_msrs; diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index b23772786a..fd8d23c185 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -716,8 +716,7 @@ static int flask_domctl(struct domain *d, int cmd) return current_has_perm(d, SECCLASS_DOMAIN, DOMAIN__SET_VIRQ_HANDL= ER); =20 case XEN_DOMCTL_set_cpu_policy: - case XEN_DOMCTL_set_cpuid: - return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SET_CPUID); + return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SET_CPU_POLI= CY); =20 case XEN_DOMCTL_gettscinfo: return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__GETTSC); diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/acc= ess_vectors index 6f3f9493f8..c055c14c26 100644 --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -208,8 +208,7 @@ class domain2 # target =3D the new target domain set_as_target # XEN_DOMCTL_set_cpu_policy -# XEN_DOMCTL_set_cpuid - set_cpuid + set_cpu_policy # XEN_DOMCTL_gettscinfo gettsc # XEN_DOMCTL_settscinfo --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 26 04:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1568232409; cv=none; d=zoho.com; s=zohoarc; b=OxC2dZpIhSXzE4V7K9HNVZRWmBMlrTRT24TTU9byHoZq9Y8LBa6qkaFD+rMt1zeoEndAA0vOLsM88mzd1MsOJFoLGpPVoND+IBekwOIj8i5WcVfKGVanYLorVktps80Mf14NjjbBbNR7VFVLOxk6ALxWSMnGKXNDlyup+xVUGSA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568232409; 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=DTMjmDAmcs+n2495QOPMMbtOB7Fy/jMSj7UYHs+iiCg=; b=eCLcXJFCyCA0Na7YzJY5m0tV9yNM/DJ0LG/hMoWbkwrNaO946KfNILfNKgDsSVqJpDRQqLDZcIMcT1M1hE7Jn1NcUopSBiFV56rDBO096m849NLfJPLEd1+PjxuHN0n9BskqZ/2XyTgUzuOP/Nogx8x2ZpAv7KlQFyS03PwNeKc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 15682324091491002.1750959621629; Wed, 11 Sep 2019 13:06:49 -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 1i88rz-00037x-NQ; Wed, 11 Sep 2019 20:05:39 +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 1i88ry-00036p-5L for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 20:05:38 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7928fc90-d4cf-11e9-83dd-12813bfff9fa; Wed, 11 Sep 2019 20:05:16 +0000 (UTC) X-Inumbo-ID: 7928fc90-d4cf-11e9-83dd-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568232317; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KfxSG6tk+37JqGd8jvH6e0+GTDL4sE5/HpeLBPpTwb0=; b=WuX1rwTzssXv9O2v7azQkJwJ9JE4rhx6HOVUd5UHe43TngzPgo1y5tjv px7tCMSz+fN/iDhjhLUnZLvtcc1hTZZTlI5xo4oURyDN4ZQHJ5VhzTWkD m4p7YGcRfzyLKPWKKXeGLyvZQLk6h+nZbzUUEHCyIT9riBkjSXSG8SD5m 4=; Authentication-Results: esa1.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@mail.citrix.com 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 (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: SjzUhlq534F1vTly/5WySxx/tew3DnAeD2PyBNLhkCbwEx//twfzXMGUUPk98kZhseDlKIDE7y Bc1eh3OdmpWVDDTAXnzCdj4a6uwqk6aEhuioPKHVu1P1AfYyh+Itn9PE0qNcR557RvWvBx8q++ lhcQhK9XvyDdYBxrk3cRKQ4JGEabBjKDwb59LfCWI9zPRP5uyhzHyyBQmqBQq0hPnnYnCxz6EC hI0PG0/C667zF+TM501gak+LO1Bgch6q/x83YhzINafz3XGCEmkrmJeQHdT9rBHhlYIg3FKK0W bfo= X-SBRS: 2.7 X-MesageID: 5506249 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,494,1559534400"; d="scan'208";a="5506249" From: Andrew Cooper To: Xen-devel Date: Wed, 11 Sep 2019 21:05:04 +0100 Message-ID: <20190911200504.5693-9-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 8/8] x86/cpuid: Enable CPUID Faulting for the control domain 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" X-ZohoMail-DKIM: fail (Header signature does not verify) The domain builder no longer uses CPUID instructions for policy decisions. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/cpu/common.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index 8de4a44c1a..2e883835b8 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -168,23 +168,8 @@ void ctxt_switch_levelling(const struct vcpu *next) */ if (nextd && is_idle_domain(nextd)) return; - /* - * We *should* be enabling faulting for the control domain. - * - * Unfortunately, the domain builder (having only ever been a - * PV guest) expects to be able to see host cpuid state in a - * native CPUID instruction, to correctly build a CPUID policy - * for HVM guests (notably the xstate leaves). - * - * This logic is fundimentally broken for HVM toolstack - * domains, and faulting causes PV guests to behave like HVM - * guests from their point of view. - * - * Future development plans will move responsibility for - * generating the maximum full cpuid policy into Xen, at which - * this problem will disappear. - */ - set_cpuid_faulting(nextd && !is_control_domain(nextd) && + + set_cpuid_faulting(nextd && (is_pv_domain(nextd) || next->arch.msrs-> misc_features_enables.cpuid_faulting)); --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 26 04:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1568314624; cv=none; d=zoho.com; s=zohoarc; b=c2NhxvU0oaEa07FWlXowBuEPQcFPbJB+4KC2RIdN4egwmMMbUNrLI4bSbBM6+i03id5+ZW9mnRb2bOItGXbyuT5aMn332Ks2EskeiY+yIbPmern1CclsLV5E7q9BfivUaCPeWKh6NJNhPS82fE/LcDazYDxxdOuzb17UJFvhjps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568314624; 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=ZRVcRXGIakYSdDxvqkBPxrSKdwEZ+zHKZZuWiegvy/c=; b=TqtzgJ6bskDROn42yp02ckJRxQ56O0bviXNL2nLAxPL7PCSBYNdSSl1rDDZnb4Amu6+tTqf9xT1xJDgo4V6p6oImE2u6wlMAosBa6CUtd0lClSMN4LtG/ZjVZp3URKVr9r+G/r+jW/0q7g/RpjUrEesM/swenCXb8iYkNYvQm40= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1568314624777817.7724275382221; Thu, 12 Sep 2019 11:57:04 -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 1i8UGB-00036A-Cv; Thu, 12 Sep 2019 18:56:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8UG9-00034p-Pm for xen-devel@lists.xenproject.org; Thu, 12 Sep 2019 18:56:01 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f6465aaa-d58e-11e9-b299-bc764e2007e4; Thu, 12 Sep 2019 18:56:01 +0000 (UTC) X-Inumbo-ID: f6465aaa-d58e-11e9-b299-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568314561; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VXhTF/AM4h7nMLziZQXRr8jU37dX02II11U8ivOUCQc=; b=TP2Nvf6JwtPLAugr9eD6NW3S4HzOrGX8Og9+CM+F0UQI2uBGjVQmspdR 1yF1v1b+tzmPUX27XP1PoKEli2qOw2ovjqDlLF6jHasz9grMkEmkKuHGb cMyz5dEK4wFjmYvRyD09lN5E6CLhEbhN7eZuYJb8KRaJaFW/12pOW83lh I=; Authentication-Results: esa1.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@mail.citrix.com 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 (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: k1T2AQqxd7aQxzYjlWN6jW3yz/XIkERzV0DdplUlur8RTZegbTjyE5qLBrBoFVdVizGHUUcIUF eekj3xQZUIbUcFtwS85G+mq/i+eaSbxzz0FDFzM6Wdk+rKFz+K1gRlHjO2SDIhZchmVcxeNPWF wiBV1LhCTmRVE4/1SRl2+r2hCquQEQKFhF8ITYTH+LvIu2ID5F+kQz3XA6YgJWI5zzsG2BQg8v 9+ksIQdWCZpVG03NFnLNREpLQ05l6mfll//JLng6+RLqHRQEx+Goa1ajbC7GYXNydVH7wM4Mm4 0Ok= X-SBRS: 2.7 X-MesageID: 5557408 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,498,1559534400"; d="scan'208";a="5557408" From: Andrew Cooper To: Xen-devel Date: Thu, 12 Sep 2019 19:55:56 +0100 Message-ID: <20190912185556.22173-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 0.5/8] libx86: Proactively initialise error pointers 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" X-ZohoMail-DKIM: fail (Header signature does not verify) This results in better behaviour for the caller. Suggested-by: Jan Beulich Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * New --- tools/tests/cpu-policy/test-cpu-policy.c | 4 ++-- xen/include/xen/lib/x86/cpuid.h | 6 +++--- xen/include/xen/lib/x86/msr.h | 4 ++-- xen/lib/x86/cpuid.c | 5 +++++ xen/lib/x86/msr.c | 3 +++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-pol= icy/test-cpu-policy.c index fe00cd4276..201358d210 100644 --- a/tools/tests/cpu-policy/test-cpu-policy.c +++ b/tools/tests/cpu-policy/test-cpu-policy.c @@ -283,7 +283,7 @@ static void test_cpuid_deserialise_failure(void) for ( size_t i =3D 0; i < ARRAY_SIZE(tests); ++i ) { const struct test *t =3D &tests[i]; - uint32_t err_leaf =3D ~0u, err_subleaf =3D ~0u; + uint32_t err_leaf, err_subleaf; int rc; =20 /* No writes should occur. Use NULL to catch errors. */ @@ -336,7 +336,7 @@ static void test_msr_deserialise_failure(void) for ( size_t i =3D 0; i < ARRAY_SIZE(tests); ++i ) { const struct test *t =3D &tests[i]; - uint32_t err_msr =3D ~0u; + uint32_t err_msr; int rc; =20 /* No writes should occur. Use NULL to catch errors. */ diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpui= d.h index df5946b6b1..79840f99ce 100644 --- a/xen/include/xen/lib/x86/cpuid.h +++ b/xen/include/xen/lib/x86/cpuid.h @@ -376,13 +376,13 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_polic= y *policy, * @param policy The cpuid_policy to unserialise into. * @param leaves The array of leaves to unserialise from. * @param nr_entries The number of entries in 'leaves'. - * @param err_leaf Optional hint filled on error. - * @param err_subleaf Optional hint filled on error. + * @param err_leaf Optional hint for error diagnostics. + * @param err_subleaf Optional hint for error diagnostics. * @returns -errno * * Reads at most CPUID_MAX_SERIALISED_LEAVES. May return -ERANGE if an * incoming leaf is out of range of cpuid_policy, in which case the option= al - * err_* pointers are filled to aid diagnostics. + * err_* pointers will identify the out-of-range indicies. * * No content validation of in-range leaves is performed. Synthesised dat= a is * recalculated. diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h index e83a8fbb0f..203c713320 100644 --- a/xen/include/xen/lib/x86/msr.h +++ b/xen/include/xen/lib/x86/msr.h @@ -54,14 +54,14 @@ int x86_msr_copy_to_buffer(const struct msr_policy *pol= icy, * @param policy The msr_policy object to unserialise into. * @param msrs The array of msrs to unserialise from. * @param nr_entries The number of entries in 'msrs'. - * @param err_msr Optional hint filled on error. + * @param err_msr Optional hint for error diagnostics. * @returns -errno * * Reads at most MSR_MAX_SERIALISED_ENTRIES. May fail for a number of rea= sons * based on the content in an individual 'msrs' entry, including the MSR i= ndex * not being valid in the policy, the flags field being nonzero, or if the * value provided would truncate when stored in the policy. In such cases, - * the optional err_* pointer is filled in to aid diagnostics. + * the optional err_* pointer will identify the problematic MSR. * * No content validation is performed on the data stored in the policy obj= ect. */ diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c index 266084e613..76b8511034 100644 --- a/xen/lib/x86/cpuid.c +++ b/xen/lib/x86/cpuid.c @@ -381,6 +381,11 @@ int x86_cpuid_copy_from_buffer(struct cpuid_policy *p, unsigned int i; xen_cpuid_leaf_t data; =20 + if ( err_leaf ) + *err_leaf =3D -1; + if ( err_subleaf ) + *err_subleaf =3D -1; + /* * A well formed caller is expected to pass an array with leaves in or= der, * and without any repetitions. However, due to per-vendor difference= s, diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c index 256b5ec632..171abf7008 100644 --- a/xen/lib/x86/msr.c +++ b/xen/lib/x86/msr.c @@ -55,6 +55,9 @@ int x86_msr_copy_from_buffer(struct msr_policy *p, xen_msr_entry_t data; int rc; =20 + if ( err_msr ) + *err_msr =3D -1; + /* * A well formed caller is expected to pass an array with entries in * order, and without any repetitions. However, due to per-vendor --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel