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

Re: [Xen-devel] [PATCH v2 02/25] x86/cpuid: Introduce struct cpuid_policy



On 09/01/17 15:15, Jan Beulich wrote:
>>>> On 09.01.17 at 12:03, <andrew.cooper3@xxxxxxxxxx> wrote:
>> @@ -67,6 +80,58 @@ static void __init sanitise_featureset(uint32_t *fs)
>>                            (fs[FEATURESET_e1d] & ~CPUID_COMMON_1D_FEATURES));
>>  }
>>  
>> +static void __init calculate_raw_policy(void)
>> +{
>> +    struct cpuid_policy *p = &raw_policy;
>> +    unsigned int i;
>> +
>> +    cpuid_leaf(0, &p->basic.raw[0]);
>> +    for ( i = 1; i < min(ARRAY_SIZE(p->basic.raw),
>> +                         p->basic.max_leaf + 1ul); ++i )
>> +    {
>> +        switch ( i )
>> +        {
>> +        case 0x2: case 0x4: case 0x7: case 0xd:
>> +            /* Multi-invocation leaves.  Deferred. */
>> +            continue;
>> +        }
>> +
>> +        cpuid_leaf(i, &p->basic.raw[i]);
>> +    }
>> +
>> +    if ( p->basic.max_leaf >= 7 )
>> +    {
>> +        cpuid_count_leaf(7, 0, &p->feat.raw[0]);
>> +
>> +        for ( i = 1; i < min(ARRAY_SIZE(p->feat.raw),
>> +                             p->feat.max_subleaf + 1ul); ++i )
>> +            cpuid_count_leaf(7, i, &p->feat.raw[i]);
>> +    }
>> +
>> +    if ( p->basic.max_leaf >= 0xd )
>> +    {
>> +        uint64_t xstates;
>> +
>> +        cpuid_count_leaf(0xd, 0, &p->xstate.raw[0]);
>> +        cpuid_count_leaf(0xd, 1, &p->xstate.raw[1]);
>> +
>> +        xstates = ((uint64_t)(p->xstate.xcr0_high | p->xstate.xss_high) << 
>> 32) |
>> +            (p->xstate.xcr0_low | p->xstate.xss_low);
>> +
>> +        for ( i = 2; i < 63; ++i )
> Perhaps better to use ARRAY_SIZE() (or min()) here, too?
>
>> +        {
>> +            if ( xstates & (1ul << i) )
>> +                cpuid_count_leaf(0xd, i, &p->xstate.raw[i]);
>> +        }
> Also, overall in this code block I think you should really use
> XSTATE_CPUID instead of 0xd.

Will do for both.

>
>> +    }
>> +
>> +    /* Extended leaves. */
>> +    cpuid_leaf(0x80000000, &p->extd.raw[0]);
>> +    for ( i = 1; i < min(ARRAY_SIZE(p->extd.raw),
>> +                         p->extd.max_leaf + 1 - 0x80000000ul); ++i )
> Would it be worthwhile to make the code resilient to max_leaf not
> having the high bit set?

I'm tempted not to.  If we didn't have sensible higher leaves, we would
have failed the LM check in head.S and failed to boot.

~Andrew

>
> Once again in any event
> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
>
> Jan
>
>


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

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