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

Re: [Xen-devel] [PATCH] x86/CPUID: don't override tool stack decision to hide STIBP


  • To: Jan Beulich <JBeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 25 May 2018 14:52:43 +0100
  • Autocrypt: addr=andrew.cooper3@xxxxxxxxxx; prefer-encrypt=mutual; keydata= xsFNBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1+1I4jsRQQh2m6OTADHIqg2E ofTYAEh7R5HfPx0EXoEDMdRjOeKn8+vvkAwhviWXTHlG3R1QkbE5M/oywnZ83udJmi+lxjJ5 YhQ5IzomvJ16H0Bq+TLyVLO/VRksp1VR9HxCzItLNCS8PdpYYz5TC204ViycobYU65WMpzWe LFAGn8jSS25XIpqv0Y9k87dLbctKKA14Ifw2kq5OIVu2FuX+3i446JOa2vpCI9GcjCzi3oHV e00bzYiHMIl0FICrNJU0Kjho8pdo0m2uxkn6SYEpogAy9pnatUlO+erL4LqFUO7GXSdBRbw5 gNt25XTLdSFuZtMxkY3tq8MFss5QnjhehCVPEpE6y9ZjI4XB8ad1G4oBHVGK5LMsvg22PfMJ ISWFSHoF/B5+lHkCKWkFxZ0gZn33ju5n6/FOdEx4B8cMJt+cWwARAQABzSlBbmRyZXcgQ29v cGVyIDxhbmRyZXcuY29vcGVyM0BjaXRyaXguY29tPsLBegQTAQgAJAIbAwULCQgHAwUVCgkI CwUWAgMBAAIeAQIXgAUCWKD95wIZAQAKCRBlw/kGpdefoHbdD/9AIoR3k6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xxxxxxxxxxxxxxxxxx>
  • Delivery-date: Fri, 25 May 2018 13:52:57 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Openpgp: preference=signencrypt

On 25/05/18 08:17, Jan Beulich wrote:
>>>> On 24.05.18 at 18:44, <andrew.cooper3@xxxxxxxxxx> wrote:
>> On 22/05/18 11:33, Jan Beulich wrote:
>>> Other than in the feature sets, where we indeed want to offer the
>>> feature even if not enumerated on hardware, we shouldn't dictate the
>>> feature being available if tool stack or host admin have decided not
>>> to expose it (for whatever [questionable?] reason).
>>>
>>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>>> ---
>>> This is effectively accompanying the discussion rooted at the 4.8/4.7
>>> patch at
>>> https://lists.xenproject.org/archives/html/xen-devel/2018-05/msg01028.html 
>>> dealing with a feature leveling issue.
>>>
>>> --- a/xen/arch/x86/cpuid.c
>>> +++ b/xen/arch/x86/cpuid.c
>>> @@ -642,14 +642,6 @@ void recalculate_cpuid_policy(struct dom
>>>      recalculate_xstate(p);
>>>      recalculate_misc(p);
>>>  
>>> -    /*
>>> -     * Override STIBP to match IBRS.  Guests can safely use STIBP
>>> -     * functionality on non-HT hardware, but can't necesserily protect
>>> -     * themselves from SP2/Spectre/Branch Target Injection if STIBP is 
>>> hidden
>>> -     * on HT-capable hardware.
>>> -     */
>>> -    p->feat.stibp = p->feat.ibrsb;
>> You've deleted a comment explaining why this is needed for safety
>> reasons, without addressing the safety argument.  Simply "because we
>> shouldn't override the toolstack" isn't a reasonable argument.
> It very much is: Policy decisions belong, as far as possible, in the tool
> stack rather than the hypervisor, and in the admin's hands rather than
> pre-programmed tool stack behavior.

Policy decisions, absolutely, but a patch like this needs justify why it
is deleting a safety check.  One valid justification would be "the
safety property this override is trying to achieve is actually already
safe because of $X".

>
>> With the SP2 microcode, we have the following situations which can occur:
>>  * No mitigations
>>  * IBRSB visible
>>  * IBRSB and STIBP visible
>>
>> IBSRB enumerates MSR_SPEC_CTRL, MSR_SPEC_CTRL.IBRS, and MSR_PRED_CMD.
>> STIBP enumerates MSR_SPEC_CTRL.STIBP
>>
>> SPEC_CTRL.STIBP is specified as usable (albeit, as a nop) even if STIBP
>> isn't enumerated.  This is deliberately and explicitly for heterogeneous
>> migration scenarios, as it won't be a nop on other processors.  In
>> practice, this is so hypervisors can offer the feature unilaterally, and
>> have it usable on non-HT hardware.
>>
>> However, to safely level it, dom0 needs to see it set in the information
>> used to construct the guest policies.  In principle, this should just be
>> in the guest policy which needs adjusting.
>>
>> However, due to still not having got the CPUID policy improvements
>> finished, dom0 is still excluded from cpuid faulting for the exclusive
>> benefit of the CPUID logic in the domain builder, because it uses native
>> CPUID to construct the guests CPUID policy.  Therefore, dom0 is unable
>> to create a safe CPUID policy for the guest, and Xen must override the
>> setting.
> I don't understand this. Both xc_cpuid_{hvm,pv}_policy() have
>
>     case 0x00000007: /* Intel-defined CPU features */
>         if ( input[1] == 0 )
>         {
>             regs[1] = info->featureset[featureword_of(X86_FEATURE_FSGSBASE)];
>             regs[2] = 
> info->featureset[featureword_of(X86_FEATURE_PREFETCHWT1)];
>             regs[3] = 
> info->featureset[featureword_of(X86_FEATURE_AVX512_4VNNIW)];
>         }
>
> Where is the use of native CPUID here?

Oh - I'd completely forgotten I'd fixed up the xc_cpuid_set() path
(which libxl uses for cpuid=[]) as well as the xc_cpuid_apply_policy()
path which is used for "I'd like a default setup please".

Therefore, c/s 3e0c8272f200457d9a735070b66a0da808ac3924 looks to be the
point after which libxc becomes safe (WRT to these native CPUID
concerns), so long as the featureset do have a IBRSB -> STIBP override
visible in them.

In staging at the moment, the IBRSB -> STIBP override is performed in
guest_common_feature_adjustments(), but this gets rather more
complicated on older branches.  Perhaps the easiest way to test is with
`cpuid=no-stibp` and looking at xen-cpuid.

Here is a sample from one of my test boxes:

[root@fusebot ~]# xen-cpuid 
nr_features: 10
                      KEY 1d       1c       e1d      e1c      Da1      7b0      
7c0      e7d      e8b      7d0      

Static sets:
Known                     
bfebfbff:fffef3ff:ee500800:2469bfff:0000000f:fdbfffff:0040401f:00000500:00001001:8c00000c
Special                   
10000200:88200000:00000000:00000002:00000000:00002040:00000010:00000000:00000000:08000000
PV Mask                   
1fc9cbf5:f6f83203:e2500800:042109e3:00000007:fdaf0b39:00404003:00000000:00001001:8c00000c
HVM Shadow Mask           
1fcbfbff:f7f83223:ea500800:042189f7:0000000f:fdbf4bbb:00404007:00000000:00001001:8c00000c
HVM Hap Mask              
1fcbfbff:f7fa3223:ee500800:042189f7:0000000f:fdbf4fbb:0040400f:00000000:00001001:8c00000c

Dynamic sets:
Raw                       
bfebfbff:7ffafbff:2c100800:00000021:00000001:000027ab:00000000:00000100:00000000:8c000000
Host                      
bfebfbff:77faf3ff:2c100800:00000021:00000001:000027ab:00000000:00000100:00000000:84000000
PV                        
1fc9cbf5:f6f83203:20100800:00000021:00000001:00000329:00000000:00000000:00001000:8c000000
HVM                       
1fcbfbff:f7fa3223:2c100800:00000021:00000001:000007ab:00000000:00000000:00001000:8c000000

In the raw dynamic set, we see IBRSB, STIBP (and SSBD, seeing as I've
got some microcode).  STIBP is clear in the Host policy (because of the
cpuid= override), yet still set in the PV and HVM featuresets.

Therefore, a default guest constructed on non-HT hardware will see STIBP
visible, per the intention of its special case.

However, if you are going to make this change, then you're missing the
following hunk:

diff --git a/xen/include/public/arch-x86/cpufeatureset.h 
b/xen/include/public/arch-x86/cpufeatureset.h
index c721c12..f1a5ed9 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -243,7 +243,7 @@ XEN_CPUFEATURE(IBPB,          8*32+12) /*A  IBPB support 
only (no IBRS, used by
 XEN_CPUFEATURE(AVX512_4VNNIW, 9*32+ 2) /*A  AVX512 Neural Network Instructions 
*/
 XEN_CPUFEATURE(AVX512_4FMAPS, 9*32+ 3) /*A  AVX512 Multiply Accumulation 
Single Precision */
 XEN_CPUFEATURE(IBRSB,         9*32+26) /*A  IBRS and IBPB support (used by 
Intel) */
-XEN_CPUFEATURE(STIBP,         9*32+27) /*A! STIBP */
+XEN_CPUFEATURE(STIBP,         9*32+27) /*A  STIBP */
 XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*   IA32_ARCH_CAPABILITIES MSR */
 XEN_CPUFEATURE(SSBD,          9*32+31) /*A  MSR_SPEC_CTRL.SSBD available */
 

which is the signal that:

...
 * Special: '!'
 *   This bit has special properties and is not a straight indication of a
 *   piece of new functionality.  Xen will handle these differently,
 *   and may override toolstack settings completely.
...

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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