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

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


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 29 Jun 2021 11:00:52 +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:X-MS-Exchange-SenderADCheck; bh=wLgipyWsdCU1xKHlwrIa2KemOhIzT9rb6VhyMVYIw2A=; b=mQIYLLkbrDIvKzrSoWUY+T7qj7bJxMTeCktv+S9XlIwTG8kqHa7f7ghbFXBGjIV9m85ST4Z78xX1ZmYLZkoy0V31GuMpUQ8iZWulhijZsiGNpLdqM+aNnruP2Dg3BDMh7po5acqsh4rihgYfs3cPrO8NHUeCK6fSZIAkTpPJyqKmYaRmIcTkUS225o5VRNOwcF92eHv3gP8rfj9neHB93r8Qvu9kTMu/mQ+S4xYH+cFlHhVGJM5IlmPf0bCOMyJ/SnGetG5SpMtaV473tipoWq6ql6eiy8JTB3nEAZks+KcQfOTt0VU8tDRTuFoHbDTMzzObElr3th5xpgEkJ6Nfvg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hTUVqHU3wxTSTz8EqOpBKkc4xDF+UaqG/aH1LkcjAGzQFi7h/OtKiaKauBSHzuepWeAbIAOWlnyAJpVecZCd0G/5rzwPfRRDIZOYukU3wRByIcqtCWnjkqFpAeaDGH1wvza1AIHDe/4Y3JPVdpMSbkfgqmsRgke5UFXSSTUMLaCapGfKVS5iJGVMxQ12ft0qE6S/vxN0mFa9OSljmJ24UC2XBoj9Gb4sJnBEhqPvSPkMyQPuq9C+vdQtlAEfZewh3fXueLbW40pD0xTaWrbYC5QaC/xGPQzMMUf3XAaNp2zbl4rAYEroNtJneHmtPRM9OJMeE/DdnJcMQG9W56RPJQ==
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 29 Jun 2021 10:01:16 +0000
  • Ironport-hdrordr: A9a23:+vUBLK7aszhMINkvWAPXwSqBI+orL9Y04lQ7vn2ZFiY7TiXIra yTdaoguCMc6AxxZJkh8erwXZVoMkmsiqKdhrNhQYtKPTOWxVdASbsN0WKM+UyZJ8STzJ876U 4kSdkFNDSSNykIsS+Z2njALz9I+rDum8rJ9ISuukuFDzsaD52Ihz0JejpzeXcGIjWua6BJdq Z0qvA33AZJLh8sH7WG7zQ+Lqf+juyOsKijTQ8NBhYh5gXLpTS06ITiGxzd+hsFSTtAzZor7G CAymXCl+SemsD+7iWZ+37Y7pxQltek4txfBPaUgsxQDjn3kA6naKloRrXHljEop+OE7kosjb D30lkdFvU2z0mUUnC+oBPr1QWl+i0p8WXexViRhmamidDlRRohYvAxx75xQ1/80Q4Nrdt82K VE0yayrJxMFy7Nmyz7+pzhSwxqrEypunAv+NRjzEC3abFuLIO5kLZvu3+8SPw7bWTHAcEcYa lT5fjnlbNrmQjwVQGBgoEHq+bcLEjaHX+9MwI/U4KuomBrdN0Q9TpQ+CUlpAZ2yHsKcegO2w 31CNUdqFhwdL5hUUtcPpZNfSLlMB2AffrzWFjiaWgPQ5t3RU4l7aSHu4kI2A==
  • Ironport-sdr: rQWncyUDLPsgWgiEJuyLx81l2Jg63mleAi9+Gdgs3yk5homF9Mo2cEWFmP3908Qj5XWKnrhwgy PBOb5XEmM0VuwNmykFF8PhRVJ9gRXzCzhchfujbXaLn6xorAOIVPOEf45EHdPJz1US8yWxYseJ r6626L+k8NcKAR+cJNbhNDCzBWfXzI+SGkQg3BHlQrTbSIaYl8QiZCCx4YmouBk/X8b/6SZaLx V1+6joL0/GIutaDrUjLOH/xiRbgMvfxvuwaDOdRFO0APiwvvPKb0XI8AAPOw5oFOPgEOIxLb5z wCc=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 29/06/2021 10:09, Jan Beulich wrote:
> 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.

Oh - the pseudocode and the text don't match.  How helpful.

Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>




 


Rackspace

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