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

Re: [PATCH] x86/CPUID: surface suitable value in EBX of XSTATE subleaf 1


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Tue, 23 Aug 2022 10:48:43 +0000
  • Accept-language: en-GB, en-US
  • 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=zSfumwv/IKvHoPMZnfYJUIerLEilmwpX7wYrFNOzSxo=; b=V8X/0o5Fmj5r9Cf/6UhGBpuTts61q6fVSvZ26Rgmi2yEW75PYvF1p3wUsSfYwdLWyZCUWNN/reYkV6JwDDxxiacuEnpOtj4n2y4OphLweShBK+hPpkmx1C1fAyHMz7jgtbUka/7Q26FvoxWw3WbhlUgebnLx8cC6kmAOxXuwMc/oW1HsesPbk8/UEhEfSsqXBK/y0y3MXOFQhg+Zcv35HiJ96xEo7Pp90gOs2m1y4AKVtsmtp5X+64PVDUmyPr5YdRbGFci0gLLmWjbsfUjQuEJs2JzovZrflbaPpj5YzAv8SCrpsH037U+71OJMRsuwRBMHSMmP94fPk1LiQrQrHw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K6el0hIu5eHPny8bJvQ650YXws4ONTlgASPnstSD95X9IPF5L+X0YNwkJGMpeWtJBqjJfEeMe76oapuxcO8XThGyZuKVwGd1qCaE8xC1olHnlNTn9ELfB4MUzuEw4wQLzy7S7lvuy7DPTw9t4oqG6+w9dCch5upiCos37twt6ex7ZgA+7st94ijnBHU4mkoVUGPFQXLd1zHwrMGYtstz7d6FF9z9Thpn1jYOsHsPfCe3gQTErBiTk4G5wlCiEx7ZJw5FrEwynu9yrLFB67obDFFpd2IPqgBMM1TJI2Uj6Xt7LbDurd3lr8591ZlWIdYdwZyFRvSNZbChvT2LA6dwkg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Wei Liu <wl@xxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 23 Aug 2022 10:49:02 +0000
  • Ironport-data: A9a23:M187ta/2K+5b7C/y0CMkDrUDVH+TJUtcMsCJ2f8bNWPcYEJGY0x3x mMdWj/SMqqNNmXzLt4ga9/j9EMB6MXSn4JhTgE5/iE8E34SpcT7XtnIdU2Y0wF+jyHgoOCLy +1EN7Es+ehtFie0Si+Fa+Sn9z8kvU2xbuKUIPbePSxsThNTRi4kiBZy88Y0mYctitWia++3k YqaT/b3ZRn0gFaYDkpOs/jZ8EM156yo0N8llgdWic5j7Qe2e0Y9VPrzFYnpR1PkT49dGPKNR uqr5NlVKUuAon/Bovv8+lrKWhViroz6ZGBiuVIPM0SWuTBQpzRa70oOHKF0hXG7Kdm+t4sZJ N1l7fRcQOqyV0HGsLx1vxJwS0mSMUDakVNuzLfWXcG7liX7n3XQL/pGF0AvZNFH1dtNRmRN8 8cmazcgNDqivrfjqF67YrEEasULCuDOZdlallQ+iDbTALAhXIzJRLjM6ZlAxjAsi8tSHPHYI c0EdT5oaxeGaBpKUrsVIMtmwKH02T+iInsB9wv9SakfugA/yCRY1rT3PcWTUduNXchPxW6Tp 37c/nS/CRYfXDCa4WXaoyv82bGS9c/9cI4cKr+RpvFyvB7J5E8jGhkwT2Sgq/bs3yZSXPoac ST44BEGr6I/6UiqRdnVRACjrTiPuRt0c8VUO/037keK0KW8ywOQHG0NVDNCQN0gqs4tRDYu2 0OJntXmHjhmuvueTnf13qubqSOaPSkTMHMYYikFXU0J7rHLsIw1yx7CUNtnOKq0lcHuXyH9x SiQqyozjKlVitQEv5hX5njCijOo45TMEAg841yNWnr/t1wgIom4e4av9F7Xq+5aK5qURUWAu 35CnNWC6OcJDteGkynlrPgxIYxFLs2taFX06WOD1bF7n9hx0xZPpbxt3Qw=
  • Ironport-hdrordr: A9a23:s/PIUKmKkSiN6J10rW914EMq+jDpDfOPimdD5ihNYBxZY6Wkfp +V8cjzhCWftN9OYhodcIi7SdK9qXO1z+8X3WGIVY3SETUOy1HYVr2KirGSjwEIeheOvNK1sJ 0NT0EQMqyWMbEXt6fHCUyDYq4dKbq8ge+VbIXlvhFQpGhRAskOgTuRSDzra3GeLzM2Z6bRYa Dsgvav0ADQHEj/AP7aOlA1G8z44/HbnpPvZhALQzQ97hOVsD+u4LnmVzCFwxY3SVp0sPYf2F mAtza8yrSosvm9xBOZ/XTU9Y5qlNzozcYGLNCQi/ISNi7nhm+TFcRcsvy5zXMISdOUmRMXee r30lMd1gNImjTsl1SO0FnQMs/boXATAjHZuAalaDDY0LHErXoBerZ8bMRiA1XkAgMbza9BOO gg5RPni7NHSRzHhyjz/N7OSlVjkVe1u2MrlaoJg2VYSpZ2Us4ZkWUzxjIjLH47JlON1Kk3VO 11SM3M7vdfdl2XK3jfo2l02dSpGnA+BA2PTEQOstGcl2E+pgEz82IIgMgE2nsQ/pM0TJdJo+ zCL6RzjblLCssbd7h0CusNSda+TmbNXRXPOmSPJkmPLtBOB1vd75rspLkl7uCjf5IFiJM0hZ TaSVtd8XU/fkr/YPf+qKGjMiq9NVlVcQ6duv22vaIJy4EUbICbQhGrWRQpj9aqpekZD4nSR+ uzUagmccPeEQ==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYtrt8/1v0WOY/4kiCtfQ8qrAcS628L8cAgAAH3wCAABa0AA==
  • Thread-topic: [PATCH] x86/CPUID: surface suitable value in EBX of XSTATE subleaf 1

On 23/08/2022 10:27, Jan Beulich wrote:
> On 23.08.2022 10:59, Andrew Cooper wrote:
>> On 23/08/2022 07:42, Jan Beulich wrote:
>>> exposed to PV domains.
>>>
>>> Considering that the size reported is that of the compacted save area,
>>> I view Linux'es assumption as appropriate (short of the SDM properly
>>> considering the case). Therefore we need to populate the field also when
>>> only XSAVEC is supported for a guest.
>> This is a mess.  The SDM is fairly clear (but only in Vol1) that this
>> leaf is specific to XSAVES.
> The way it's written my assumption is that they simply didn't care about
> XSAVEC when writing this, or they were assuming that both features would
> always be supported together (yet even if they are in Intel's hardware,
> the architecture should spell out things as if both were entirely
> independent, or it should specify that one takes the other as a prereq).

Real hardware has XSAVEC == XSAVES on Intel (Skylake) and AMD (Zen1). 
Despite an attempt to separate the parts of the ISA, they are
inextricably linked.

It is only under virt that we get XSAVEC without XSAVES.

>>> Fixes: 460b9a4b3630 ("x86/xsaves: enable xsaves/xrstors for hvm guest")
>>> Fixes: 8d050ed1097c ("x86: don't expose XSAVES capability to PV guests")
>>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>> CC Marek.  Looks like Jan has found the issue you reported on IRC.
>>
>> Jan: Be aware that I submitted
>> https://lore.kernel.org/lkml/20220810221909.12768-1-andrew.cooper3@xxxxxxxxxx/
>> to Linux to correct some of the diagnostics.
>>> --- a/xen/arch/x86/cpuid.c
>>> +++ b/xen/arch/x86/cpuid.c
>>> @@ -1142,7 +1142,7 @@ void guest_cpuid(const struct vcpu *v, u
>>>          switch ( subleaf )
>>>          {
>>>          case 1:
>>> -            if ( p->xstate.xsaves )
>>> +            if ( p->xstate.xsavec || p->xstate.xsaves )
>> If we're doing this, then it wants to be xsavec only, with the comment
>> being extended to explain why.
> Why would that be? Both insns use compacted format, and neither is
> dependent upon the other in terms of being supported. IOW XSAVES alone
> and XSAVEC alone enabled for a domain should still lead through this
> path.

Hmm.  Because my fixes to compaction handling haven't been committed
yet, and in particular one the one which makes XSAVES strictly depend on
XSAVEC.

In which case this hunk is correct for Xen as it currently is, and will
be need to be adjusted when I rebase the compaction series.

>> But this is going to further complicate my several-year-old series
>> trying to get Xen's XSTATE handling into a position where we can start
>> to offer supervisor states.
> Where do you see further complication? The necessary fiddling with XSS
> here would of course be dependent upon p->xstate.xsaves alone (or,
> maybe better, on the set of enabled features in XSS being non-empty),
> but that's simply another (inner) if().
>
> As an aside, I actually wonder what use the supplied size is to user
> mode code when any XSS-controlled feature is enabled: They'd allocate
> a needlessly large block of memory, as they would only be able to use
> XSAVEC.

This field is an already known kernel=>user infoleak.  There are threads
about it on LKML.

But it does highlight another problem.  This change does not fix Linux
on AMD Zen3 hardware, where the kernel will find the CPUID value larger
than it can calculate the size to be, because Xen's use of CET-SS will
show up in the CPUID value.

Linux needs an adjustment from != to <= for this check.

~Andrew

 


Rackspace

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