From: Andrew Cooper <andrew.cooper3@citrix.com>
To: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Kevin Tian <kevin.tian@intel.com>, Wei Liu <wei.liu2@citrix.com>,
Jun Nakajima <jun.nakajima@intel.com>,
Jan Beulich <JBeulich@suse.com>,
Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH 3/9] x86/vmx: Factor locate_msr_entry() out of vmx_find_msr() and vmx_add_msr()
Date: Thu, 24 May 2018 11:59:07 +0100 [thread overview]
Message-ID: <7cfa0f81-6e1f-4d99-be54-5030d96c20f2@citrix.com> (raw)
In-Reply-To: <20180524105317.sbaahqpm3atgh2ok@MacBook-Pro-de-Roger.local>
On 24/05/18 11:53, Roger Pau Monné wrote:
> On Wed, May 23, 2018 at 05:55:50PM +0100, Andrew Cooper wrote:
>> On 23/05/18 17:39, Roger Pau Monné wrote:
>>> On Tue, May 22, 2018 at 12:20:40PM +0100, Andrew Cooper wrote:
>>>> Instead of having multiple algorithms searching the MSR lists, implement a
>>>> single one. It has the semantics required by vmx_add_msr(), to identify the
>>>> position in which an MSR should live, if it isn't already present.
>>>>
>>>> There will be a marginal improvement for vmx_find_msr() by avoiding the
>>>> function pointer calls to vmx_msr_entry_key_cmp(), and a major improvement for
>>>> vmx_add_msr() by using a binary search instead of a linear search.
>>>>
>>>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>>>> ---
>>>> CC: Jan Beulich <JBeulich@suse.com>
>>>> CC: Jun Nakajima <jun.nakajima@intel.com>
>>>> CC: Kevin Tian <kevin.tian@intel.com>
>>>> CC: Wei Liu <wei.liu2@citrix.com>
>>>> CC: Roger Pau Monné <roger.pau@citrix.com>
>>>> ---
>>>> xen/arch/x86/hvm/vmx/vmcs.c | 42 ++++++++++++++++++++++++++++--------------
>>>> 1 file changed, 28 insertions(+), 14 deletions(-)
>>>>
>>>> diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c
>>>> index f557857..e4acdc1 100644
>>>> --- a/xen/arch/x86/hvm/vmx/vmcs.c
>>>> +++ b/xen/arch/x86/hvm/vmx/vmcs.c
>>>> @@ -1276,24 +1276,36 @@ static int construct_vmcs(struct vcpu *v)
>>>> return 0;
>>>> }
>>>>
>>>> -static int vmx_msr_entry_key_cmp(const void *key, const void *elt)
>>>> +/*
>>>> + * Search an MSR list looking for an MSR entry, or the slot in which it should
>>>> + * live (to keep the data sorted) if an entry is not found.
>>>> + *
>>>> + * The return pointer is guarenteed to be bounded by start and end. However,
>>>> + * it may point at end, and may be invalid for the caller to dereference.
>>>> + */
>>>> +static struct vmx_msr_entry *locate_msr_entry(
>>>> + struct vmx_msr_entry *start, struct vmx_msr_entry *end, uint32_t msr)
>>>> {
>>>> - const u32 *msr = key;
>>>> - const struct vmx_msr_entry *entry = elt;
>>>> + while ( start < end )
>>>> + {
>>>> + struct vmx_msr_entry *mid = start + (end - start) / 2;
>>>>
>>>> - if ( *msr > entry->index )
>>>> - return 1;
>>>> - if ( *msr < entry->index )
>>>> - return -1;
>>>> + if ( msr < mid->index )
>>>> + end = mid;
>>>> + else if ( msr > mid->index )
>>>> + start = mid + 1;
>>>> + else
>>>> + return mid;
>>>> + }
>>> This is basically an open coded version of bsearch, isn't there anyway
>>> to adapt the current bsearch so that it could be used for both
>>> vmx_find_msr and vmx_add_msr?
>>>
>>> I know there will be a performance penalty for using a function
>>> pointer for the comparator function, but this looks like code
>>> duplication to me.
>> A third use appears in a later patch. bsearch() doesn't have the
>> described property on a miss, which is necessary to maintain the lists.
> I would consider adding a flag to the list of parameters so that
> bsearch returned the position where the item should be added in case
> of a miss. You could then wrap it inside of locate_msr_entry, or get
> rid of this helper altogether.
bsearch() is specified by POSIX, and C89/99, amongst other standards.
Changing its API is not something I'm going to do.
~Andrew
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-05-24 10:59 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-22 11:20 [PATCH 0/9] x86/vmx: Don't leak EFER.NXE into guest context Andrew Cooper
2018-05-22 11:20 ` [PATCH 1/9] x86/vmx: API improvements for MSR load/save infrastructure Andrew Cooper
2018-05-23 16:01 ` Roger Pau Monné
2018-05-23 17:02 ` Andrew Cooper
2018-05-27 3:26 ` Tian, Kevin
2018-05-22 11:20 ` [PATCH 2/9] x86/vmx: Internal cleanup " Andrew Cooper
2018-05-23 16:28 ` Roger Pau Monné
2018-05-23 16:54 ` Andrew Cooper
2018-05-24 14:45 ` Jan Beulich
2018-05-27 3:30 ` Tian, Kevin
2018-05-22 11:20 ` [PATCH 3/9] x86/vmx: Factor locate_msr_entry() out of vmx_find_msr() and vmx_add_msr() Andrew Cooper
2018-05-23 16:39 ` Roger Pau Monné
2018-05-23 16:55 ` Andrew Cooper
2018-05-24 10:53 ` Roger Pau Monné
2018-05-24 10:59 ` Andrew Cooper [this message]
2018-05-24 12:16 ` Roger Pau Monné
2018-05-27 3:38 ` Tian, Kevin
2018-05-22 11:20 ` [PATCH 4/9] x86/vmx: Support remote access to the MSR lists Andrew Cooper
2018-05-24 11:50 ` Roger Pau Monné
2018-05-24 12:03 ` Andrew Cooper
2018-05-24 14:53 ` Jan Beulich
2018-05-27 3:47 ` Tian, Kevin
2018-05-28 15:15 ` Andrew Cooper
2018-05-22 11:20 ` [PATCH 5/9] x86/vmx: Fix handing of MSR_DEBUGCTL on VMExit Andrew Cooper
2018-05-22 12:53 ` Andrew Cooper
2018-05-24 12:14 ` Roger Pau Monné
2018-05-24 12:39 ` Andrew Cooper
2018-05-24 13:53 ` Jan Beulich
2018-05-24 15:08 ` Jan Beulich
2018-05-24 15:51 ` Andrew Cooper
2018-05-27 3:56 ` Tian, Kevin
2018-05-28 15:30 ` Andrew Cooper
2018-05-22 11:20 ` [PATCH 6/9] x86/vmx: Pass an MSR value into vmx_msr_add() Andrew Cooper
2018-05-24 15:12 ` Jan Beulich
2018-05-30 18:09 ` Andrew Cooper
2018-05-22 11:20 ` [PATCH 7/9] x86/vmx: Support load-only guest MSR list entries Andrew Cooper
2018-05-24 15:19 ` Jan Beulich
2018-05-24 15:37 ` Roger Pau Monné
2018-05-22 11:20 ` [PATCH 8/9] x86/vmx: Support removing MSRs from the host/guest load/save lists Andrew Cooper
2018-05-24 15:42 ` Roger Pau Monné
2018-05-24 15:45 ` Andrew Cooper
2018-05-22 11:20 ` [PATCH 9/9] x86/vmx: Don't leak EFER.NXE into guest context Andrew Cooper
2018-05-24 16:01 ` Roger Pau Monné
2018-05-24 16:48 ` Andrew Cooper
2018-05-25 7:27 ` Jan Beulich
2018-05-25 8:03 ` Andrew Cooper
2018-05-25 6:23 ` Tim Deegan
2018-05-25 7:49 ` Jan Beulich
2018-05-25 8:36 ` Andrew Cooper
2018-05-25 11:36 ` Jan Beulich
2018-05-25 11:48 ` Andrew Cooper
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=7cfa0f81-6e1f-4d99-be54-5030d96c20f2@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=roger.pau@citrix.com \
--cc=wei.liu2@citrix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).