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

Re: [PATCH for-4.19 v2] x86/spec-ctrl: Support for SRSO_US_NO and SRSO_MSR_FIX


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 27 Jun 2024 10:28:29 +0200
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 27 Jun 2024 08:28:55 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 26.06.2024 22:20, Andrew Cooper wrote:
> On 20/06/2024 9:39 am, Jan Beulich wrote:
>> On 19.06.2024 21:10, Andrew Cooper wrote:
>>> --- a/docs/misc/xen-command-line.pandoc
>>> +++ b/docs/misc/xen-command-line.pandoc
>>> @@ -2390,7 +2390,7 @@ By default SSBD will be mitigated at runtime (i.e 
>>> `ssbd=runtime`).
>>>  >              {ibrs,ibpb,ssbd,psfd,
>>>  >              eager-fpu,l1d-flush,branch-harden,srb-lock,
>>>  >              unpriv-mmio,gds-mit,div-scrub,lock-harden,
>>> ->              bhi-dis-s}=<bool> ]`
>>> +>              bhi-dis-s,bp-spec-reduce}=<bool> ]`
>>>  
>>>  Controls for speculative execution sidechannel mitigations.  By default, 
>>> Xen
>>>  will pick the most appropriate mitigations based on compiled in support,
>>> @@ -2539,6 +2539,13 @@ boolean can be used to force or prevent Xen from 
>>> using speculation barriers to
>>>  protect lock critical regions.  This mitigation won't be engaged by 
>>> default,
>>>  and needs to be explicitly enabled on the command line.
>>>  
>>> +On hardware supporting SRSO_MSR_FIX, the `bp-spec-reduce=` option can be 
>>> used
>>> +to force or prevent Xen from using MSR_BP_CFG.BP_SPEC_REDUCE to mitigate 
>>> the
>>> +SRSO (Speculative Return Stack Overflow) vulnerability.
>> Upon my request to add "... against HVM guests" here you replied "Ok.", yet
>> then you didn't make the change? Even a changelog entry says you supposedly
>> added this, so perhaps simply lost in a refresh?
> 
> Yes, and later in the thread you (correctly) pointed out that it's not
> only for HVM guests.
> 
> The PV aspect, discussed in the following sentence, is very relevant and
> makes it not specific to HVM guests.

Hmm, yes, sorry, I apparently lost track of that again.

>>> --- a/xen/arch/x86/cpu/amd.c
>>> +++ b/xen/arch/x86/cpu/amd.c
>>> @@ -1009,16 +1009,33 @@ static void cf_check fam17_disable_c6(void *arg)
>>>     wrmsrl(MSR_AMD_CSTATE_CFG, val & mask);
>>>  }
>>>  
>>> -static void amd_check_erratum_1485(void)
>>> +static void amd_check_bp_cfg(void)
>>>  {
>>> -   uint64_t val, chickenbit = (1 << 5);
>>> +   uint64_t val, new = 0;
>>>  
>>> -   if (cpu_has_hypervisor || boot_cpu_data.x86 != 0x19 || !is_zen4_uarch())
>>> +   /*
>>> +    * AMD Erratum #1485.  Set bit 5, as instructed.
>>> +    */
>>> +   if (!cpu_has_hypervisor && boot_cpu_data.x86 == 0x19 && is_zen4_uarch())
>>> +           new |= (1 << 5);
>>> +
>>> +   /*
>>> +    * On hardware supporting SRSO_MSR_FIX, activate BP_SPEC_REDUCE by
>>> +    * default.  This lets us do two things:
>>> +         *
>>> +         * 1) Avoid IBPB-on-entry to mitigate SRSO attacks from HVM guests.
>>> +         * 2) Lets us advertise SRSO_US_NO to PV guests.
>>> +    */
>>> +   if (boot_cpu_has(X86_FEATURE_SRSO_MSR_FIX) && opt_bp_spec_reduce)
>>> +           new |= BP_CFG_SPEC_REDUCE;
>>> +
>>> +   /* Avoid reading BP_CFG if we don't intend to change anything. */
>>> +   if (!new)
>>>             return;
>>>  
>>>     rdmsrl(MSR_AMD64_BP_CFG, val);
>>>  
>>> -   if (val & chickenbit)
>>> +   if ((val & new) == new)
>>>             return;
>> You explained that you want to avoid making this more complex, upon my
>> question towards tweaking this to also deal with us possibly clearing
>> flags. I'm okay with that, but I did ask that you add at least half a
>> sentence to actually clarify this to future readers (which might include
>> myself).
> 
> "I wrote it this way because it is sufficient and simple, but you can
> change it in the future if you really need to" is line noise wherever
> it's written.
> 
> It literally goes without saying, for every line the entire codebase.

Well. Elsewhere we go to the lengths of trying to cover for unexpected
states. So to me this goes beyond "sufficient and simple". But anyway.

>> However, as an unrelated aspect: According to the respective part of the
>> comment you add to  calculate_pv_max_policy(), do we need the IBPB when
>> BP_SPEC_REDUCE is active?
> 
> To what are you referring?

The fact that for HVM the change to ibpb_calculations() results in no
entry-IBPB when we have SRSO_MSR_FIX and opt_bp_spec_reduce is true.
To me the comment you add to calculate_pv_max_policy() suggests a
sufficient similarity. IOW ...

> SRSO is about Return predictions becoming poisoned by other
> predictions.  The best way to mount an SRSO attack is with forged
> near-branch predictions.
> 
> For SRSO safety, we use IBPB to flush the Branch *Type* information from
> the BTB.  Fam17h happened to have this property, but Fam19h needed it
> retrofitting in a microcode update, with the prior "Indirect Branch
> Targets only, explicitly retaining the Branch Type information" being
> retroactively named SBPB.
> 
> This does not interact with the use of IBPB for it's
> architecturally-given purpose.

... why is there an interaction for HVM but not for PV? (Sorry, I'm
apparently lost here to a certain degree.)

Jan



 


Rackspace

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