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

Re: [PATCH] x86emul: avoid using _PRE_EFLAGS() in a few cases


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 29 Jun 2021 11:09:13 +0200
  • 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-SenderADCheck; bh=rRaV8+fVhLodpx+ySjS6ObWyl/2MdwjAbxOYQphDkhs=; b=N/uqeCc+VODNx2L2goa0zbhmKzVuG1hyEO6lnZ3xAjC87JCcy+C23EZFF6uOt1U8Jh4oI8aHPGZ7fss2ok9htaXkPFbixM1oz/zU4Ds2JLgHKyPKuGHHG632en/TYzo2u/TN66cNxlLQGbNwJFBBV4L9L760oruWNIlEDKYPXLEz4HjJVVtDsy2GCfn8s+pqHwvwxTWN9rftOHc9oarz0G+Ud8H5cHryUGjuo24q9awpel0BP/Pa2/zVX4CXf3CxmG9vs0bT9WWToEZsccPH37/zob4XFVePJkkQRcojclCyIFVle5EmvLpsr2sh9ccYLqFAApLVfLWVIbdxpgiMgA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NXnwxiz46c1J7NcMNmiyt2dv+kkvOcbm1PAZuCiRGAmL8Fzrkbqtw+vtB4/nI+DJIm28LoHBG9o/srUqVX+KKCBxbCHqciNZRfxSXU8p0DCa7yCnUfCaJr3vSc7zThaeZoIXVmUWwLKna5d5LHf8dPrbPJzdr0onBHvyGtuPbS58aS99tEpKdq1Ll7Dm5M7IA54kfKSaU7qiMToa+76426Ge28jkKNO0s0QFTmBuwU4E/jLqiE3+51pKwByePwySv8NEtB2DATKZwUb2SqLxVoDZOYG8/AXx9iqitMFCEpLD03lWHhSEoS/oXXCRjelcV3TUAVcmSmbM/got3+PHmw==
  • Authentication-results: lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=none action=none header.from=suse.com;
  • Cc: Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 29 Jun 2021 09:09:36 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 28.06.2021 19:14, Andrew Cooper wrote:
> On 02/06/2021 15:37, Jan Beulich wrote:
>> The macro expanding to quite a few insns, replace its use by simply
>> clearing the status flags when the to be executed insn doesn't depend
>> on their initial state, in cases where this is easily possible. (There
>> are more cases where the uses are hidden inside macros, and where some
>> of the users of the macros want guest flags put in place before running
>> the insn, i.e. the macros can't be updated as easily.)
>>
>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> 
> Honestly, this is the first time I've looked into _PRE/_POST_EFLAGS() in
> detail.  Why is most of this not in C to begin with?

Ask Keir?

> The only bits which need to be in asm are the popf to establish the
> stub's flags context, and the pushf to save the resulting state. 
> Everything else is better off done by the compiler especially as it
> would remove a load of work on temporaries from the stack.

I'll try to find time to do something along these lines.

> Nevertheless, ...
> 
>> --- a/xen/arch/x86/x86_emulate/x86_emulate.c
>> +++ b/xen/arch/x86/x86_emulate/x86_emulate.c
>> @@ -6863,7 +6863,8 @@ x86_emulate(
>>          }
>>          opc[2] = 0xc3;
>>  
>> -        invoke_stub(_PRE_EFLAGS("[eflags]", "[mask]", "[tmp]"),
>> +        _regs.eflags &= ~EFLAGS_MASK;
>> +        invoke_stub("",
>>                      _POST_EFLAGS("[eflags]", "[mask]", "[tmp]"),
>>                      [eflags] "+g" (_regs.eflags),
>>                      [tmp] "=&r" (dummy), "+m" (*mmvalp)
>> @@ -8111,7 +8112,8 @@ x86_emulate(
>>          opc[2] = 0xc3;
>>  
>>          copy_VEX(opc, vex);
>> -        invoke_stub(_PRE_EFLAGS("[eflags]", "[mask]", "[tmp]"),
>> +        _regs.eflags &= ~EFLAGS_MASK;
>> +        invoke_stub("",
>>                      _POST_EFLAGS("[eflags]", "[mask]", "[tmp]"),
>>                      [eflags] "+g" (_regs.eflags),
>>                      "=a" (dst.val), [tmp] "=&r" (dummy)
> 
> ... this hunk is k{,or}test, which only modified ZF and CF according to
> the SDM.
> 
> The other flags are not listed as modified, which means they're
> preserved, unless you're planning to have Intel issue a correction to
> the SDM.

kortest has

"The OF, SF, AF, and PF flags are set to 0."

in its "Flags Affected" section. ktest has

"AF := OF := PF := SF := 0;"

in its "Operation" section.

Jan




 


Rackspace

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