lkml.org 
[lkml]   [2023]   [Jan]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4 28/32] KVM: SVM: Require logical ID to be power-of-2 for AVIC entry
On Thu, Dec 29, 2022, mlevitsk@redhat.com wrote:
> On Fri, 2022-12-09 at 00:00 +0200, Maxim Levitsky wrote:
> > On Sat, 2022-10-01 at 00:59 +0000, Sean Christopherson wrote:
> > > + } else {
> > > + cluster = (ldr >> 4) << 2;
> > > + if (cluster >= 0xf)
> > > return NULL;
> > > - } else { /* cluster */
> > > - int cluster = (dlid & 0xf0) >> 4;
> > > - int apic = ffs(dlid & 0x0f) - 1;
> > > -
> > > - if ((apic < 0) || (apic > 7) ||
> > > - (cluster >= 0xf))
> > > - return NULL;
> > > - index = (cluster << 2) + apic;
> > > + ldr &= 0xf;
> > > }
> > > + if (!ldr || !is_power_of_2(ldr))
> > > + return NULL;
> > > +
> > > + index = __ffs(ldr);
> > > + if (WARN_ON_ONCE(index > 7))
> > > + return NULL;
> > > + index += (cluster << 2);
> > >
> > > logical_apic_id_table = (u32 *) page_address(kvm_svm->avic_logical_id_table_page);
> > >
> >
> > Looks good.
>
> I hate to say it but this patch has a bug:
>
> We have both 'cluster = (ldr >> 4) << 2' and then 'index += (cluster << 2)'
>
> One of the shifts has to go.

The first shift is wrong. The "cluster >= 0xf" check needs to be done on the actual
cluster. The "<< 2", a.k.a. "* 4", is specific to indexing the AVIC table.

Thanks!

\
 
 \ /
  Last update: 2023-03-26 23:27    [W:0.172 / U:1.012 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site