From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Eddie Dong <eddie.dong@intel.com>, Feng Wu <feng.wu@intel.com>,
"Ian.Campbell@citrix.com" <Ian.Campbell@citrix.com>,
Jun Nakajima <jun.nakajima@intel.com>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH v1 1/6] x86: Add support for STAC/CLAC instructions
Date: Tue, 22 Apr 2014 10:43:03 +0100 [thread overview]
Message-ID: <535639A7.7070006@citrix.com> (raw)
In-Reply-To: <53563F4D020000780000A927@nat28.tlf.novell.com>
On 22/04/14 09:07, Jan Beulich wrote:
>>>> On 22.04.14 at 09:41, <feng.wu@intel.com> wrote:
>>> From: Jan Beulich [mailto:JBeulich@suse.com]
>>> That said, the macro contents itself is horrible too: A control register
>>> access and two conditional branches in code intended to be used in
>>> fast paths? Definitely not an option. Even the simplest possible
>>> solution - adding a global flag to be checked here - would already be
>>> questionable. Hence I think you should at least consider porting over
>>> proper instruction patching abstraction from Linux.
>>>
>> Jan, I did some investigation about how to handle this two instructions
>> in Linux, basically, it uses the alternatives mechanism to handle these
>> kind of cases. Let's take the following definition of ASM_STAC in Linux for
>> example:
>>
>> #define ASM_CLAC \
>> 661: ASM_NOP3 ; \
>> .pushsection .altinstr_replacement, "ax" ; \
>> 662: __ASM_CLAC ; \
>> .popsection ; \
>> .pushsection .altinstructions, "a" ; \
>> altinstruction_entry 661b, 662b, X86_FEATURE_SMAP, 3, 3 ; \
>> .popsection
>>
>> ASM_CLAC is defined as NOP by default, it puts the real CLAC instruction in
>> section "altinstr_replacement" and
>> the needed information to " altinstructions " section, which is useful to
>> replace the default
>> definition by the alternative one. Here is the routine call path:
>> start_kernel () --> check_bugs() --> alternative_instructions().
>>
>> In function alternative_instructions(), it will check the related features
>> in CPU, if it exists, the alternative definition will
>> overwrite the default one. So there is no conditional branches after this
>> replacement when the Macro is being used.
>>
>> Do you think we need to port this whole mechanism to Xen to support
>> CLAC/STAC? I am not sure if it is a little overkilled.
> Obviously we could use this machinery for other things. But whether it's
> needed here depends on the alternatives.
>
>> BTW, from the Linux implementation, I think we don't need to check the 'cr4'
>> for the macros, we just need
>> to check whether the feature exists in the CPU. So is it acceptable to use
>> the original code by eliminating the cr4 check?
> That _might_ be acceptable if you bring it down to just the three
> really necessary instructions: BT, JNC, CLAC/STAC. But the "might"
> has to stand - this, after all, remains an addition of a conditional
> branch (and for the performance of STAC/CLAC I haven't seen any
> documentation so far either) to several fast paths, and hence the
> patching alternative can't be discarded as the potentially better one.
>
> Jan
copy_{to,from}_guest() are already long paths (particularly for HVM) so
a single extra conditional is not going to be too bad (and as after boot
it will remain constant, the branch predictor will have a reliable time
with it). It would certainly be fine for a v1 to get SMAP support working.
~Andrew
next prev parent reply other threads:[~2014-04-22 9:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-15 13:01 [PATCH v1 1/6] x86: Add support for STAC/CLAC instructions Feng Wu
2014-04-15 8:40 ` Jan Beulich
2014-04-22 7:41 ` Wu, Feng
2014-04-22 8:07 ` Jan Beulich
2014-04-22 8:46 ` Wu, Feng
2014-04-22 9:17 ` Jan Beulich
2014-04-22 12:19 ` Wu, Feng
2014-04-22 13:09 ` Konrad Rzeszutek Wilk
2014-04-23 13:43 ` Wu, Feng
2014-04-23 14:52 ` Is: alternative_asm as dependency for STAC/CLAC/new features? Was:Re: " Konrad Rzeszutek Wilk
2014-04-23 15:59 ` Is: alternative_asm as dependency for STAC/CLAC/new features? Jan Beulich
2014-04-22 9:43 ` Andrew Cooper [this message]
2014-04-22 9:48 ` [PATCH v1 1/6] x86: Add support for STAC/CLAC instructions Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=535639A7.7070006@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=JBeulich@suse.com \
--cc=eddie.dong@intel.com \
--cc=feng.wu@intel.com \
--cc=jun.nakajima@intel.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.