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

Re: [PATCH RFC 0/9] x86: Merge cpuid and msr policy


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Mon, 3 Apr 2023 11:55:57 +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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+TRfRo/vwqJdd2nOP6GwL6ag6RGk2ZLD1LhaZ3gY2CE=; b=BNM8qhWvgePd+lyTkhUFo4sV0i3QRTXtIzIqwp6Yp45sEh7orI9+O2SX81L5UsEWqLLhqaQ0FLfPh0Ma8i/QN1MflKPsZvZOgh73vzKrT81PNU1TxVkIc3DVPOwT+D37hgxgyuUAlzKdqAgQCFhRsct7AF3QluMeNM1Mnhy7TiCW0E7bhrTIxiC7LezbFrvkbQ0cplm0xszuvtkApZXVhIGV+A+OYnXi61WWNx+FY0sbg5ApyPkYdijJLPniH8/g7TqOQJb15dK8Ds2/7TklXOsF0/6vhGRbntnT4fzdavksxvGk7C3UlS+62T0pV2y24cDgk+MOYPLolNlERizc/g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ofzh/HacUYVN6GmR/MBDtmIrO9ju3Y/Oo+PBlrBXc+jFxq8cjxSj4pn93q6MXIb01xPo+nYhT0eLVwE40oyZUdT8hp3EJCo6w7TjVdyq2MhC8WZHIJbrA4UhDQt4Qiw6jRmMJy4i4rhmqNXAhvVR9s+zoXRjg4mPF4EGwYwtJrNm0IpEnWcWhmC7osYXPN0Y9vLiuIcJqDQYNe4JfmgXqaOIbbJSH/1azSkN5jx4uf+VLaYdxiCPkE2vF87fHo2zyAIXdc1oiUR2J86UIWuoQEkEHPALXhpRUurbSJu6jZyDWIg0D/sR5dbYT5FIEqbT+6JmyhOMLwoLIqBTJ7cgTw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Jan Beulich <JBeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Mon, 03 Apr 2023 10:56:24 +0000
  • Ironport-data: A9a23:sy9aWKtGLD34cGRB3kIilS1r4OfnVHtfMUV32f8akzHdYApBsoF/q tZmKTzUOKzcamWkL490advk8R5Tv5PSyIJgTgZlpCs0RX8b+JbJXdiXEBz9bniYRiHhoOCLz O1FM4Wdc5pkJpP4jk3wWlQ0hSAkjclkfpKlVKiffHg3HVQ+IMsYoUoLs/YjhYJ1isSODQqIu Nfjy+XSI1bg0DNvWo4uw/vrRChH4bKj6Fv0gnRkPaoQ5AOGzCFMZH4iDfrZw0XQE9E88tGSH 44v/JnhlkvF8hEkDM+Sk7qTWiXmlZaLYGBiIlIPM0STqkAqSh4ai87XB9JFAatjsB2bnsgZ9 Tl4ncfYpTHFnEH7sL91vxFwS0mSNEDdkVPNCSDXXce7lyUqf5ZwqhnH4Y5f0YAwo45K7W9yG fMwcj0nZzuIqvuP8L/mS7kwuYMDLsfCI9ZK0p1g5Wmx4fcOZ7nmGvyPz/kImTA6i4ZJAOrUY NcfZXx3dhPcbhZTO1ARTpUjgOOvgXq5eDpdwL6XjfNvvy6Pk0osgP60boq9lt+iHK25mm6xo G7c8nu/KRYdLNGFkhKO8262h/+JliT+MG4XPOTgraI13AfLnQT/DjVPD2GnvPK9kHXvZPNRD XMk4Ckkv5cboRnDot7VGkfQTGS/lg4RXZ9cHvM37CmJy7HI+ECJC24cVDlDZdc68sgsSlQC9 HWEgtfoDjxHq6CORDSW8bL8hSy2ETgYKykFfyBscOcey9zqoYV2hBSfSN9mSfexloesR2G2x C2Wpi8jgblVldQMy6iw4VHAhXSru4TNSQk2oA7QWwpJ8z9EWWJsXKTwgXCz0BqKBN/xooWp1 JTcp/Wj0Q==
  • Ironport-hdrordr: A9a23:bgSiy6yApGpvZvMI2d8+KrPw+r1zdoMgy1knxilNoH1uA7Olfq WV98jzuiWUtN9vYgBHpTntAsW9qDDnhOdICPAqTMqftVDdyReVxeJZnPXfKl/bexEWrdQtrZ uIGpIWYLfN5D5B4voSizPULz9P+re6GN3Bv5ak8564d3AJV0kdhz0JbTpzancGJzWv9fECZe ChDz181l6dkN0sH6GGOkU=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 30/03/2023 3:43 pm, Roger Pau Monné wrote:
> On Thu, Mar 30, 2023 at 01:59:37PM +0100, Andrew Cooper wrote:
>> On 30/03/2023 12:07 pm, Roger Pau Monné wrote:
>>> On Wed, Mar 29, 2023 at 09:51:28PM +0100, Andrew Cooper wrote:
>>>> tl;dr to add MSR_ARCH_CAPS features sensibly, cpu_{featureset<->policy}() 
>>>> need
>>>> to not operate on objects of differing lifetimes, so structs
>>>> {cpuid,msr}_policy need merging and cpu_policy is the obvious name.
>>> So the problem is that there's a chance we might get a cpu_policy
>>> object that contains a valid (allocated) cpuid object, but not an msr
>>> one?
>> No - not cpu_policy.  It is that we can get a cpuid_policy and an
>> msr_policy that aren't at the same point in their lifecycle.
>>
>> ... which is exactly what happens right now for the raw/host msr right
>> now if you featureset_to_policy() to include MSR data.
> I see, but that's mostly because we handle the featureset_to_policy()
> in two different places for CPUID vs MSR, those need to be unified
> into a single helper that does both at the same point.
>
> I assume not having such pointers in side of cpu_policy makes it
> clearer that both msr and cpuid should be handled at the same time,
> but ultimately this would imply passing a cpu_policy object to
> featureset_to_policy() so that both CPUID and MSR sub-structs are
> filled from the same featureset.
>
> Sorry, maybe I'm being a bit dull here, just would like to understand
> the motivation of the change.

That's pretty much it.  Forcing them to be one object removes a class of
errors, and makes the resulting code easier to follow.

(Based on having tried to do the non-merged approach first, and deciding
that it's not code I'm willing to try putting upstream...)

>> Merging the two together into cpu_policy causes there to be a single
>> object lifecycle.
>>
>>
>> It's probably worth repeating the advise from the footnote in
>> https://lwn.net/Articles/193245/ again.  Get your datastructures right,
>> and the code takes care of itself.  Don't get them right, and the code
>> tends to be unmaintainable.
>>
>>
>>>> But this does mean that we now have
>>>>
>>>>   cpu_policy->basic.$X
>>>>   cpu_policy->feat.$Y
>>>>   cpu_policy->arch_caps.$Z
>>> I'm not sure I like the fact that we now can't differentiate between
>>> policy fields related to MSRs or CPUID leafs.
>>>
>>> Isn't there a chance we might in the future get some name space
>>> collision by us having decided to unify both?
>> The names are chosen by me so far, and the compiler will tell us if
>> things actually collide.
>>
>> And renaming the existing field is a perfectly acceptable way of
>> resolving a conflict which arises in the future.
>>
>> But yes - this was the whole point of asking the question.
> I think I would prefer to keep the cpu_policy->{cpuid,msr}.
> distinction if it doesn't interfere with further work.

Unfortunately that's the opposite of what Jan asked for.  What I have
done, based on the prior conversation is:

struct arch_domain {
    ...

    /*
     * The domain's CPU Policy.  "cpu_policy" is considered the canonical
     * pointer, but the "cpuid" and "msr" aliases exist so the most
     * appropriate one can be used for local code clarity.
     */
    union {
        struct cpu_policy *cpu_policy;
        struct cpu_policy *cpuid;
        struct cpu_policy *msr;
    };

So all the cases where you do have d->arch.cpuid.feat.$X, this continues
to work.

The cases where you pull a cpu_policy out into a local variable, there
will be no cpuid or msr infix, but these cases already have no cpuid/msr
part to their naming.

~Andrew



 


Rackspace

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