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

Ping: [PATCH] tools/xen-detect: avoid possible pitfall with cpuid()


  • To: Wei Liu <wl@xxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 4 Jan 2022 10:52:54 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=57bJ3dDNbUyOxeviYmSM+5AL7AXbY2dKPdH8ElXnINw=; b=HXb/AYDNowdfC9hyls29zHdCgCEInp9ywTnuqvENet2j3FMIYsw4XmIp3ezjVB07xt3fUdJ+HKB8nqF2ENXrVwPkeGnKjLWPPFA7rQlBJQDyqw76wcza0/lN8QqzWxQGq7Bxu63uFiD2r2eaGo+iPMLHEZYc+Yz5OeW6J5A5H3/mRkJSuVXwxFlNfzVJ3P26XHZ87Ivp9HZYLIeal3b+FlzGzvuIrvK7gsDpQAtrIyAr6TofjVEWLsRwh98Zcw5u2S0iPvNr0ZGO8Hf2vXVwQSXnK14JUeVAAoA9jaY1eMktyjGdTlCSzpqmxYQp5DBP9MnnN7t9cmsbFE+X11RYgw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZjZAUJXKL3SO0IKz6msVZGe6KX8Kqc4St5PsuIRt1sZcMxLZudNm/G+vG7v4N9/MHJKpSiWDvgIh7KYFit5fvfBAb4ueZWd3aczGEY28OyHqiOJlmfV9mfnws/hnVPgeG2PwQK5PYGmhQLygpHf0K/d+SJzqqZPXr/SjVOMz9xWbv9L18cC/Dx3/apxMoR0+8Upi6eNsW88I8AtgSv0JwbxbhqlbSWCVT2awuSR1ATjsvHElWlNAMgUDTD++SFOgbQ2dWgagqFDuS458ydvVs6dyIvDvHOqSjoTCLZf4fU0LbZqgK8PqboZ8nXVmzlgsbM+FbvlWGq6SYCUPopYK0g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 04 Jan 2022 09:53:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 03.12.2021 13:09, Jan Beulich wrote:
> The 64-bit form forces %ecx to 0 while the 32-bit one so far didn't - it
> only ended up that way when "pv_context" is zero. While presently no
> leaf queried by callers has separate subleaves, let's avoid chancing it.
> 
> While there
> - replace references to operands by number,
> - relax constraints where possible,
> - limit PUSH/POP to just the registers not also used as input,
> all where applicable also for the 64-bit variant.
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

Any chance of getting an ack or otherwise here? (Anthony, I realize you've
not been on the Cc list originally, as the patch we sent before the
maintainership adjustment.)

Jan

> ---
> I'm pretty sure %edx also wouldn't need to be subject to PUSH/POP here,
> but I didn't want to go more "against" the comment than obviously
> justifiable by the input registers used. In fact I've observed gcc to
> pick %edx for putting "pv_context" in.
> 
> --- a/tools/misc/xen-detect.c
> +++ b/tools/misc/xen-detect.c
> @@ -52,17 +52,19 @@ static void cpuid(uint32_t idx, uint32_t
>  #ifdef __i386__
>      /* Use the stack to avoid reg constraint failures with some gcc flags */
>      asm volatile (
> -        "push %%eax; push %%ebx; push %%ecx; push %%edx\n\t"
> -        "test %1,%1 ; jz 1f ; ud2a ; .ascii \"xen\" ; 1: cpuid\n\t"
> -        "mov %%eax,(%2); mov %%ebx,4(%2)\n\t"
> -        "mov %%ecx,8(%2); mov %%edx,12(%2)\n\t"
> -        "pop %%edx; pop %%ecx; pop %%ebx; pop %%eax\n\t"
> -        : : "a" (idx), "c" (pv_context), "S" (regs) : "memory" );
> +        "push %%ebx; push %%edx\n\t"
> +        "test %[pv],%[pv] ; jz 1f ; ud2a ; .ascii \"xen\" ; 1: cpuid\n\t"
> +        "mov %%eax,(%[regs]); mov %%ebx,4(%[regs])\n\t"
> +        "mov %%ecx,8(%[regs]); mov %%edx,12(%[regs])\n\t"
> +        "pop %%edx; pop %%ebx\n\t"
> +        : "+a" (idx), "=c" (idx /* dummy */)
> +        : "c" (0), [pv] "r" (pv_context), [regs] "SD" (regs)
> +        : "memory" );
>  #else
>      asm volatile (
> -        "test %5,%5 ; jz 1f ; ud2a ; .ascii \"xen\" ; 1: cpuid\n\t"
> +        "test %[pv],%[pv] ; jz 1f ; ud2a ; .ascii \"xen\" ; 1: cpuid\n\t"
>          : "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
> -        : "0" (idx), "1" (pv_context), "2" (0) );
> +        : "0" (idx), "2" (0), [pv] "r" (pv_context) );
>  #endif
>  }
>  
> 
> 




 


Rackspace

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