[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y7W/NinWOnJMtUk8@google.com>
Date: Wed, 4 Jan 2023 18:02:30 +0000
From: Sean Christopherson <seanjc@...gle.com>
To: mlevitsk@...hat.com
Cc: Paolo Bonzini <pbonzini@...hat.com>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org,
Alejandro Jimenez <alejandro.j.jimenez@...cle.com>,
Suravee Suthikulpanit <suravee.suthikulpanit@....com>,
Li RongQing <lirongqing@...du.com>
Subject: Re: [PATCH v4 28/32] KVM: SVM: Require logical ID to be power-of-2
for AVIC entry
On Thu, Dec 29, 2022, mlevitsk@...hat.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!
Powered by blists - more mailing lists