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

Re: [PATCH v3 02/13] libs/guest: allow fetching a specific CPUID leaf from a cpu policy


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 4 May 2021 16:46:44 +0100
  • 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=y57z0yiUGcehdRjLSs/lStDkTVoQTegtPk6MNSkBBTA=; b=hgbKYYooSyvCWfdhLzl/b3IDb33GBWQxv6eQOoDcjtEi3+/p/m/dq+2wqsBfgUAEm28Fx/uMjMqYLWe7+1Izd+LQ0M+aG2TFZKOrHxb/kvxs3ZPXw3ltq5SZmLl6ZA2lTBFBXclmr06I7ByOs05qJtuN7uqPZ2FvB/3IxCVIv2BxzSAYMwVDifyAWhnebEkTXxtcZgW9S6wQc4I+3aU/Og1e17XlhRQ3kEluIUyy5xA5OmlUaZaZRqQ3F0pLqI9s2/JWlw2dfYoI1ZhRaXEniWQ73Klguj3NgvMW8PNIgY0CqyHQqCtQQ2/CKiE+6iN/3t0a2qy0UjmtaDekW6NZ0Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=am4fYg7iI+FM/tnmciYHS4o/APfSbmZXDw51u57Y1UM48seEvIb8Nag1TPVFZZPMFhCvrq7kqHqxnNz+rDhyeREQoTz2imxXQeEmDg11qlXrVntGbtceOWzAsJ5tcfL0ZnBGBN6yD3+TftxvFcvz3TNBRN6eNytj9WyRVygeEljbMVNHfsgi9hvvl8VXGOmX9FMBTXH+h2/2rTJKrxCICKyCDDX0PF9ySp7gF8NI0JFqJI/SBtr+uqhP1zabBpiAD+A4A6TGTPEYFGum8UnofJ1EJQSMWvJJqD5hcPQYzVzhEG+Pd+JRKZlW0pPOVtBXJVPJ/+J4/SvGmnioYd0uqA==
  • 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: Tue, 04 May 2021 15:47:00 +0000
  • Ironport-hdrordr: A9a23:B9c4Jale298zJ4A7JxzkB4fXgyHpDfMCj2dD5ilNYBxZY6Wkvu iUtrAyyQL0hDENWHsphNCHP+26TWnB8INuiLN/AZ6LZyOjnGezNolt4c/ZwzPmEzDj7eI178 tdWoBEIpnLAVB+5PyW3CCRGdwt2cTC1aiui/vXwXsFd3ARV4hLxW5Ce2SmO2dxQxRLAod8MZ Ka6NZOqTbIQwVrUu2QAH4ZU+/f4+DajZ6OW29KOzcL4BSD5AnYjoLSPAOf2n4lMw9n4bBnym Tdlhy826PLiYDB9jb590v+q6tbg8HgzNwrPr3BtuEwJi/3ggilIKRNMofyxQwdm+2k5FY0nN SkmX5JVK4cik/5RW27rQDg3APtyl8Vmgff4GSVnGf5pojBTC86YvAxwb5xSAfT6EYrobhHoc d29l+ZrJZeAFfhmynw9rHzJnZXv3e0unYrnKoviWVeW+IlGdtshLEYlXklc6soLWbf0sQKAe NuBMbT6LJ9alWBdU3UuWFp3ZiFQmkzNg3ueDlMhuWllxxt2FxpxUoRw8IS2l0a8ogmdpVC7+ PYdox1ibB1SNMMZ64VPpZOfeKHTkj2BT7cOmObJlrqUIsdPWjWlpLx6LIpoManZYIP15l3vJ jaSltXuSoTdivVeIyz9awO1iqIbHS2XDzrxM0bzYN+oKfASL3iNjDGR0spl8emvvUDEszWU/ u+I/ttcrzeBFqrPbwM8xz1WpFUJ3VbetYSoMwHV1WHpd+OKoCCjJ2YTN/j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BK50trniANIKJCIe4zr5XFA5PJH WOU=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 04/05/2021 14:47, Roger Pau Monné wrote:
> On Tue, May 04, 2021 at 12:59:43PM +0100, Andrew Cooper wrote:
>> On 30/04/2021 16:52, Roger Pau Monne wrote:
>>> @@ -822,3 +825,28 @@ 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 = ARRAY_SIZE(policy->leaves);
>>> +    xen_cpuid_leaf_t *tmp;
>>> +    int rc;
>>> +
>>> +    rc = xc_cpu_policy_serialise(xch, policy, policy->leaves, &nr_leaves,
>>> +                                 NULL, 0);
>>> +    if ( rc )
>>> +        return rc;
>> Sorry for not spotting this last time.
>>
>> You don't need to serialise.  You can look up leaf/subleaf in O(1) time
>> from cpuid_policy, which was a design goal of the structure originally.
>>
>> It is probably best to adapt most of the first switch statement in
>> guest_cpuid() to be a libx86 function.  The asserts aren't massively
>> interesting to keep, and instead of messing around with nospec, just
>> have the function return a pointer into the cpuid_policy (or NULL), and
>> have a single block_speculation() in Xen.
> libx86 already has array_access_nospec, so I think it's fine to just
> leave the code as-is instead of adding a block_speculation in Xen and
> dropping the array_access_nospec accessors?

The same libx86 function should be used to simplify
x86_cpuid_copy_from_buffer(), which has a similar opencoded construct
for looking up the leaf/subleaf.

You might need some macro trickery to make a const and non-const
versions, or have the main version non-const, and a const-qualified
inline helper which casts away constness on the input but replaces it on
the output.

The new code can't use array_access_nospec() because it is no longer
accessing the array - merely returning a pointer.  array_index_nospec()
might be an acceptable alternative.

>> We'll also want a unit test
>> to go with this new function to check that out-of-range leaves don't
>> result in out-of-bounds reads.
> Sure.
>
> Also, whats your opinion regarding xc_cpu_policy_get_msr, should I
> also split part of guest_rdmsr and place it in libx86 in order to
> fetch the MSRs present in msr_policy?

That's harder to say.  I'd like to avoid the serialise call, but the
current msr_policy structure currently uses uint32_t for space reasons,
so you can't just create a uint64_t pointer to it.

Perhaps we should bite the bullet and use uint64_t unilaterally, so we
can create a lookup_msr_by_index() or equiv.  The next big block of MSRs
going into the policy are the VT-x ones, and they'll need to be 64 bits
wide.

~Andrew




 


Rackspace

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