All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Jim Mattson <jmattson@google.com>,
	Thijs Raymakers <thijs@raymakers.nl>,
	kvm@vger.kernel.org,  Anel Orazgaliyeva <anelkz@amazon.de>,
	stable <stable@kernel.org>,  Paolo Bonzini <pbonzini@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v3] KVM: x86: use array_index_nospec with indices that come from guest
Date: Thu, 5 Mar 2026 17:54:04 -0800	[thread overview]
Message-ID: <aaozvNtzczwlyz_3@google.com> (raw)
In-Reply-To: <FFDA9F60-F0AD-4A92-8203-40DE82A921A7@infradead.org>

On Thu, Mar 05, 2026, David Woodhouse wrote:
> On 5 March 2026 23:29:11 CET, Sean Christopherson <seanjc@google.com> wrote:
> >On Thu, Mar 05, 2026, Jim Mattson wrote:
> >> On Thu, Mar 5, 2026 at 12:31 PM David Woodhouse <dwmw2@infradead.org> wrote:
> >> >
> >> > On Mon, 2025-08-04 at 08:44 +0200, Thijs Raymakers wrote:
> >> > > min and dest_id are guest-controlled indices. Using array_index_nospec()
> >> > > after the bounds checks clamps these values to mitigate speculative execution
> >> > > side-channels.
> >> > >
> >> >
> >> > (commit c87bd4dd43a6)
> >> >
> >> > Is this sufficient in the __pv_send_ipi() case?
> >> >
> >> > > --- a/arch/x86/kvm/lapic.c
> >> > > +++ b/arch/x86/kvm/lapic.c
> >> > > @@ -852,6 +852,8 @@ static int __pv_send_ipi(unsigned long *ipi_bitmap, struct kvm_apic_map *map,
> >> > >       if (min > map->max_apic_id)
> >> > >               return 0;
> >> > >
> >> > > +     min = array_index_nospec(min, map->max_apic_id + 1);
> >> > > +
> >> > >       for_each_set_bit(i, ipi_bitmap,
> >> > >               min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {
> >> > >               if (map->phys_map[min + i]) {
> >> >                         vcpu = map->phys_map[min + i]->vcpu;
> >> >                         count += kvm_apic_set_irq(vcpu, irq, NULL);
> >> >                 }
> >> >         }
> >> >
> >> > Do we need to protect [min + i] in the loop, rather than just [min]?
> >> >
> >> > The end condition for the for_each_set_bit() loop does mean that it
> >> > won't actually execute past max_apic_id but is that sufficient to
> >> > protect against *speculative* execution?
> >> >
> >> > I have a variant of this which uses array_index_nospec(min+i, ...)
> >> > *inside* the loop.
> >> 
> >> Heh. Me too!
> >
> >LOL, OMG, get off your high horses you two and someone send a damn patch!  
> 
> Heh, happy to, but it was actually a genuine question. Our pre-embargo
> patches did it in the loop but the most likely explanation seemed to be that
> upstream changed it as a valid optimization (because somehow the loop wasn't
> vulnerable?), and that we *can* drop the old patches in favour of the
> upstream one.
> 
> If no such reason exists for why the patch got changed, I'm happy to post the
> delta.

AFAIK, there was no such justification.  I'm pretty sure the only upstream version
I've ever seen is what ended up in-tree.

Speculation stuff definitely isn't my area of expertise.  Honestly, you, Jim, and
a few others are who I'd go bug for answers for this sort of thing, so unless
someone chimes in with a strong argument for the current code, I say we go with
the more conservative approach.

  reply	other threads:[~2026-03-06  1:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-04  6:44 [PATCH v3] KVM: x86: use array_index_nospec with indices that come from guest Thijs Raymakers
2025-08-12 10:37 ` David Woodhouse
2025-08-12 19:48   ` Jim Mattson
2025-08-19 23:11 ` Sean Christopherson
2026-03-05 20:30 ` David Woodhouse
2026-03-05 22:22   ` Jim Mattson
2026-03-05 22:29     ` Sean Christopherson
2026-03-05 22:42       ` David Woodhouse
2026-03-06  1:54         ` Sean Christopherson [this message]
2026-03-06  8:05           ` David Woodhouse
2026-03-06 12:02             ` Thijs Raymakers
2026-03-06 10:45   ` Paolo Bonzini

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=aaozvNtzczwlyz_3@google.com \
    --to=seanjc@google.com \
    --cc=anelkz@amazon.de \
    --cc=dwmw2@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=stable@kernel.org \
    --cc=thijs@raymakers.nl \
    /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.