On Thu, Jul 13, 2023 at 04:14:30PM +0100, Andrew Cooper wrote:
> On 11/07/2023 10:22 am, Roger Pau Monne wrote:
> > diff --git a/tools/libs/guest/xg_cpuid_x86.c
> > b/tools/libs/guest/xg_cpuid_x86.c
> > index 5b035223f4f5..5e5c8124dd74 100644
> > --- a/tools/libs/guest/xg_cpuid_x86.c
> > +++ b/tools/libs/guest/xg_cpuid_x86.c
> > @@ -423,10 +423,169 @@ static int xc_cpuid_xend_policy(
> > return rc;
> > }
> >
> > +static int compare_msr(const void *l, const void *r)
> > +{
> > + const xen_msr_entry_t *lhs = l;
> > + const xen_msr_entry_t *rhs = r;
> > +
> > + if ( lhs->idx == rhs->idx )
> > + return 0;
> > +
> > + return lhs->idx < rhs->idx ? -1 : 1;
>
> The sum total of logic here is just
>
> return lhs->idx - rhs->idx;
>
> (I think. Double check which way around the subtraction works.)
Since MSR index is a 32bit value, what about one index being ~0u and
the other 0u: the result would then wrongly be -1 ((int)(~0u - 0u)),
when it should instead be a positive value to denote the left hand
side is greater than the right hand side.
Thanks, Roger.