[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 09/21] libs/guest: allow fetching a specific CPUID leaf from a cpu policy


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Thu, 8 Apr 2021 17:53:04 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5mHiU/9g+uKx083BG3uqnISBZrvhcoCpPsdv1/QY3bk=; b=F2erjNj6SEWEL2HUNA2ICDGAlkHWs6pUcO3dFJRHKZ1SmRNs+DyBJRxqaWQMNjqxFbaQ3Wta6zfabhZWDwT9g92X+UXq2RtKh0YRPy09wqKKfrcs6jFBz4yt8cUlItI4AAHvWLIqbS8HFDXk9cZ2RKOST0ao30XIopqa8drxs2et93al+zpuodDWakpC9gJYKyNvduRVvZA4tzRKJH/wuHMoTmcnZoym9LVXwWC1sm4f0CqkoRZ6gKDGC9jI7WCf38FXJ/vdcGWfXtz/HkbJQt+FjxMcOobyQeRGChGnP34VXucgT3k0j8BOZI3RPcMfxxbF70UvIencBlCnYaTjwQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=flg/6oLmIRx1go6ZkbihDtFibqDgH6HOCPwtRkCrNwYCD+rv4YrrUwcjy85MnRwpUdD/+ss24lJ/8H7F67VIPP9sbZvgHKMTVo87PxwtW7ys3bGhFRCYj3qs1RsVsX4dXlj3oaQWlLUpVyYH8vsLxz8/wMorlic75BDHU1q43BYpvsW2fL7SkpH3y498wwBqWo1nQHepJcZu7E5nWmLQkHC52fnB2yk0ae5I5rs6kHnjgn6XYS0B+8GR8unFu77LLgHo5c4QUF3Is2m7ogdnNCQ3jENQ2c99+Zcil/bbV9v31s2ByA00GzVJwcABEzhUmHcST6jq+IT5Jai7HbFzhg==
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Thu, 08 Apr 2021 15:53:19 +0000
  • Ironport-hdrordr: A9a23:H9xnsa/6xF9K8qi+3hJuk+ECdb1zdoIgy1knxilNYDRIb82VkN 2vlvwH1RnyzA0cQm0khMroAsS9aFnb8oN45pRUAKe6UGDdyQ6VBaxBza+n+T3vHCXi6vVQvJ 0LT4FSAMD9ZGIUse/U+w+9euxP/PCi0ISFwdjT1G1sSwYCUdAD0y5cBhyAGkN7AClqbKBYKL Om6sBKpyWtdB0sB6zWOlA/U/XevNqOrZr6YHc9bCIP0hWEjj+j9dfBYnul9yoZOgkv/Z4StV Lrvia8zaWlvvG9xHbnphXuxqUTovTN4J9uAMSNj+IcNznjjB25Db4RJoGqjXQOj8yErHosjd nQszcsVv4Dl0/5TyWOjjbGnynmzTo05HfpxTaj8ATeiP28fh0WIY5lp+tiA3/kwntlhv5Q+u Z3+ljckJxtARbJjE3GlqD1fiAvrGWYiz4fi+IJ5kYvNrc2WftqgqE02lhaK5sEFDKS0vFdLM BeSPvR4/tbajqhHhbkl1gqxNStW0I6FQudTn4DvdSI0yNXkGoR9Tpg+PAi
  • Ironport-sdr: SRe07+MtLgJcvxu5IuTCZ/S6BeF7zteNFUxrEN3nkVSE0SUnGRyVBe/9JNgBNxbinw2k///+bA rjEb10dWH9rDaHLZ3pmE2XCI5KC1iNGwaVhNFEocBEhqOY+IliCMzSmLl9JeLwS/s8zFKq0qsG 1sbcCqQWR8gxnKJYNWpPRBr6j6KDysqC5d5s4udLDiEIzjbX7X2fs34KTOi4h3WGNwdc4jGHsK hqXu2vI+dC3pW8v1yzE77NxWa3osT3uMCKK2WaA7sheT5FaGTuzVJXZvBjvFRqFRgL1Rne25zW M2U=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Thu, Apr 01, 2021 at 03:47:20PM +0100, Andrew Cooper wrote:
> On 23/03/2021 09:58, Roger Pau Monne wrote:
> > diff --git a/tools/libs/guest/xg_cpuid_x86.c 
> > b/tools/libs/guest/xg_cpuid_x86.c
> > index 48351f1c4c6..a1e1bf10d5c 100644
> > --- a/tools/libs/guest/xg_cpuid_x86.c
> > +++ b/tools/libs/guest/xg_cpuid_x86.c
> > @@ -883,3 +883,45 @@ int xc_cpu_policy_serialise(xc_interface *xch, const 
> > xc_cpu_policy_t p,
> >      errno = 0;
> >      return 0;
> >  }
> > +
> > +int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t 
> > policy,
> > +                            uint32_t leaf, uint32_t subleaf,
> > +                            xen_cpuid_leaf_t *out)
> > +{
> > +    unsigned int nr_leaves, nr_msrs, i;
> > +    xen_cpuid_leaf_t *leaves;
> > +    int rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs);
> > +
> > +    if ( rc )
> > +    {
> > +        PERROR("Failed to obtain policy info size");
> > +        return -1;
> > +    }
> > +
> > +    leaves = calloc(nr_leaves, sizeof(*leaves));
> > +    if ( !leaves )
> > +    {
> > +        PERROR("Failed to allocate resources");
> > +        errno = ENOMEM;
> > +        return -1;
> > +    }
> > +
> > +    rc = xc_cpu_policy_serialise(xch, policy, leaves, &nr_leaves, NULL, 0);
> > +    if ( rc )
> > +        goto out;
> > +
> > +    for ( i = 0; i < nr_leaves; i++ )
> > +        if ( leaves[i].leaf == leaf && leaves[i].subleaf == subleaf )
> > +        {
> > +            *out = leaves[i];
> > +            goto out;
> > +        }
> 
> Please adapt find_leaf(), probably by dropping xc_xend_cpuid and passing
> in leaf/subleaf parameters.
> 
> Serialised leaves are sorted and there are plenty of them, so a log
> search is better.
> 
> How frequent is this call going to be for the same policy?  With the
> arrays embedded in a policy, they're still around, and serialise is an
> expensive operation.
> 
> I wonder if it makes sense to try and keep both forms in sync, so we can
> avoid redundant calls like this?

I think we would then need to call xc_cpu_policy_serialise whenever we
update the CPUID policy in order to re-generate the full serialized
version, as I expect changes to a specific leaf can affect others
leaves, and thus the helpers should not try to update the serialized
version manually.

Hence I'm not sure it's worth to try to keep both versions in sync, as
it seems easier to load the policy, modify the policy object and then
serialize back only when needed to upload to Xen or to export.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.