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

Re: [PATCH v1 2/2] x86/cpuid: Detect null segment behaviour on Zen2 CPUs

  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 7 Sep 2021 14:27:41 +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; bh=XZiBBNReedoay/JRiVqq7EKaNRkuz+H44YkjqwhFLpg=; b=TTxAnMzYVzcYhnw+diGSR0GrKhYPz6lTsR4ZSmTAAoZxUn7LRXyezDtIcD5jnG/pNh2cvzVSX/0hM16h+0DyS4NYnGU3yb6OGQbQnrniLUNRzH/VXBRAz2jA4NrnhNTH2+FVVhNp2UTrwdmq8PfSqQiYZ644jd0gZ7BXIlBbR6qUUI4wg/qN42IleflceiZVUA+LNEKCjhd3dbUb7BZdbqX2ZQdeqfGHZBoyv8625eixB8PLSngL0PHmXUA7+dUCEz3fJFFp3ZVs9ZmDgxfbBru2iTLstdSW5ehocDBVwVR4wQlo5lQ8Eg7g6JbFAvdO77ajj3N5JFPNT8hLyqcSHw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ReJT8obGyqBoZtAvo00onIB41y5N3PnJpvki1+Iferprxd5zgPdO66QS1QH47UhQP6eGVYxIKxCkn46sTNxmqHfegMxJD/+SkHWCgRlO4FAsCr9EfRgT7zFVbzeTdea85uoh1RqJ1h2Dpvvk5HgJHs54por3fLVPnV+SGiwK41ayQe8pqQ1tTwRY/J7WN0ZYT1mGXLYdIe3jgvYfhgowasX9UUyIQkvkix7o1MEs+mTjx05iCGEKH4F+puku18qjHPIsjqsMignaP80xIk9NHqPS5S7vzAHpJeDd54nAqzyeg6sh3RAS3uWZHHqBqQ2a+d7z4ROan/iR0AwQBw8fvQ==
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Pu Wen <puwen@xxxxxxxx>, Andy Lutomirski <luto@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Jane Malalane <jane.malalane@xxxxxxxxxx>
  • Delivery-date: Tue, 07 Sep 2021 13:27:58 +0000
  • Ironport-hdrordr: A9a23:qUSAQa0UlK89prBUkz3azQqjBIEkLtp133Aq2lEZdPUCSL3gqy nOpoV/6feX4Ax6ZJhEo7290ca7LU80maQb3WBzB8bBYOCFgguVxdpZnO3fKlTbckWUygc678 ldmsNFeb7N5DZB7PoTT2ODYq4dKHXsytHNuQ9+pU0dKj1XVw==
  • Ironport-sdr: MBMbwhs+Qt/PsEDFcEedgW9L1WQkFHYIvRJ6XzlE5+EdqVBgdsQceh28n0zFOzZAzvR7PZkWvh wCmDq2qYH+uwhbGSrOZplbCaaHlJKjJRrfjDyKIglgUFoSGeY+/zU7Y/2eVaGYeJuwgb+tAyl5 0hVa8zI+t2QFFB9Y6g25MVX8jWcGoXw1kIIw1aBJoxiI5/fepwoZCQB6mCotGIt7ogY0+6aH83 r1TKVQW0EhI235a5VDUQTGCZxBBxulybwSAft5ezLa5lJsHsPCAdAfdovkt9PrOTq3fCVW9RO0 60gMJrPgclpU5Gu3rJ4+Xnlx
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 07/09/2021 07:09, Jan Beulich wrote:
> On 06.09.2021 20:07, Andrew Cooper wrote:
>> On 06/09/2021 16:17, Jan Beulich wrote:
>>> On 06.09.2021 14:00, Jane Malalane wrote:
>>>> --- a/xen/arch/x86/cpu/amd.c
>>>> +++ b/xen/arch/x86/cpu/amd.c
>>>> @@ -681,6 +681,19 @@ void amd_init_lfence(struct cpuinfo_x86 *c)
>>>>                      c->x86_capability);
>>>>  }
>>>> +void detect_zen2_null_seg_behaviour(void)
>>> This can in principle be marked __init.
>>>> +{
>>>> +  uint64_t base;
>>>> +
>>>> +  wrmsrl(MSR_FS_BASE, 1);
>>>> +  asm volatile ( "mov %0, %%fs" :: "rm" (0) );
>>> While I don't strictly mind the "m" part of the constraint to remain
>>> there (in the hope for compilers actually to support this), iirc it's
>>> not useful to have when the value is a constant: Last time I checked,
>>> the compiler would not instantiate an anonymous (stack) variable to
>>> fulfill this constraint (as can be seen when dropping the "r" part of
>>> the constraint).
>> This is "rm" because it is what we use elsewhere in Xen for selectors,
>> and because it is the correct constraints based on the legal instruction
>> encodings.
> grep-ing for "%%[defgs]s" reveals:
> efi_arch_post_exit_boot(), svm_ctxt_switch_to(),

These are writing multiple selectors in one go, and a register
constraint is the only sane option.

> and do_set_segment_base() all use just "r".

I had missed this one.

>  This grep has not produced
> any use of "rm". What are you talking about?

TRY_LOAD_SEG(), pv_emul_read_descriptor() for both lar and lsl,
do_double_fault() for another lsl, lldt(), ltr().

So ok - not everything, but most.

>> If you want to work around what you perceive to be bugs in compilers
>> then submit a independent change yourself.
> I don't perceive this as a bug; perhaps a desirable feature. I also
> did start my response with "While I don't strictly mind the "m"
> part ..." - was this not careful enough to indicate I'm not going
> to insist on the change, but I'd prefer it to be made?

No, because a maintainer saying "I'd prefer this to be changed" is still
an instruction to the submitter to make the change.

But the request is inappropriate.  "Last time I checked, the compiler
would" presumably means you've checked GCC and not Clang, and therefore
any conclusions about the behaviour are incomplete.

Unless there is a real concrete compiler bug to work around, "rm" is the
appropriate constraint to use, all other things being equal.  If the
complier is merely doing something dumb with the flexibility it has been
permitted, then fix the compiler and the problem will resolve itself the
proper way.

>>>> @@ -731,6 +744,11 @@ static void init_amd(struct cpuinfo_x86 *c)
>>>>    else /* Implicily "== 0x10 || >= 0x12" by being 64bit. */
>>>>            amd_init_lfence(c);
>>>> +  /* Probe for NSCB on Zen2 CPUs when not virtualised */
>>>> +  if (!cpu_has_hypervisor && !cpu_has_nscb && c == &boot_cpu_data &&
>>>> +      c->x86 == 0x17 && c->x86_model >= 30 && c->x86_model <= 0x5f)
>>> DYM 0x30 here?
>> 0x30, although it turns out that some of the mobile Zen2 CPUs exceed
>> 0x60 in terms of model number.
>> As Zen3 changes the family number to 0x19, I'd just drop the upper bound.
> Minor note: Even if it didn't, the !cpu_has_nscb would also be enough
> to avoid the probing there.

There is actually a problem.  From a non-AMD source, I've found the
Sucor Z+ CPU which is a Fam17h Model 0x50 Zen1.

So instead I'm going to recommend dropping all model checks and just
keeping the family checks.  This will extend the probe function to Zen1
too, but it is once on boot, trivial in terms of complexity, and really
not worth the time/effort it has taken to discover that the model list
wasn't correct to start with.




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