From: "Jan Beulich" Subject: Re: [PATCH 3/4] VMX: use proper instruction mnemonics if assembler supports them Date: Mon, 26 Aug 2013 10:41:16 +0100 Message-ID: <521B3EDC02000078000EE4E5@nat28.tlf.novell.com> References: <521786A002000078000EE064@nat28.tlf.novell.com> <521787C602000078000EE07F@nat28.tlf.novell.com> <52193148.2090601@citrix.com> <521B36AA02000078000EE496@nat28.tlf.novell.com> <521B1F15.1030104@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VDtIX-000757-SI for xen-devel@lists.xenproject.org; Mon, 26 Aug 2013 09:41:22 +0000 In-Reply-To: <521B1F15.1030104@citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: xen-devel , Keir Fraser , Eddie Dong , Jun Nakajima List-Id: xen-devel@lists.xenproject.org >>> On 26.08.13 at 11:25, Andrew Cooper wrote: > On 26/08/2013 10:06, Jan Beulich wrote: >> The constraints aren't the problem - the use of sizeof(value) inside >> the macro is. You can't pass both pointers to 32-bit and 64-bit data >> items into the function, and then have the function guess what the >> type is to be. > > Ok (wrt the explanation), but I am not sure the result is correct. > > VMREAD has a single encoding, 0f 78, and the size of the reg/mem operand > depends on long mode or not (where compat mode forces a #UD). > > From SDM Vol 3 30.3 "VMREAD": > > "If the VMCS field specified by the source operand is shorter than this > effective operand size, the high bits of the destination operand are > cleared to 0. If the VMCS field is longer, then the high bits of the > field are not read." > > So passing a pointer to a 32bit value into this function/macro in long > mode will result in the adjacent 32 bits being clobbered, which should > best be avoided. Well spotted (and hence the __vmread_safe() construct is buggy altogether). Since I know I had looked at the instruction page to see whether it has 32- and 64-bit variants, I can only blame this at their inconsistent documentation: Vol 2, where all the other instructions live anyway, never uses the description field to outline the modes in which a certain encoding is valid - they have a separate column for this purpose. And I (mis-)interpreted the absence of that column... Anyway - v3 will need to be cut, and then I'll of course see to make this a function instead of a macro. Luckily the patch in its entirety is not incorrect, as the two users of __vmread_safe() use 64-bit values. But as soon as the concept was extended to __vmread() the bug would have become obvious (and likely even at compile time already). Jan