From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C249F145B27 for ; Thu, 5 Mar 2026 22:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772749754; cv=none; b=VXRojzpZBspF/O7IS/scDh/AAF9akHxK8+KVrGpV5RvrzDUDXZuhsajgh6J685W4peV9pQQE64iwv95oTn1iM80wJFsnKMshltV6Y077O2lB/FwSdJ/JT9Rs6ZSFycziZN7y6zE/5fp+5w9UhnTVLDgZMjKqvUS3Nl6mPbAhjJA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772749754; c=relaxed/simple; bh=Hli/PWdMOCVUCM+gNtsmZJ7Kt3KS8LqRkIlXgOXduV8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WID3wCPAtLRiLcB3NQBPHMrLuoQyR8MMTSYZ+ycmw0X4c9ONf6PLrujWqwN2n1v7TvnuA/miBwVbknoVDttBzoXqfeXSP74gaIr688hsvZjVTITL4jFE4GyY8i1+XUXPLrSlrv6SJOub7kQywna6cJ9WHxmDiGVkQAQVDVuZtlw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vbrs2SxY; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vbrs2SxY" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-359918118ebso12639504a91.2 for ; Thu, 05 Mar 2026 14:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772749753; x=1773354553; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=/o1sMjKw1NNm8NoRHmNtAwKcjHmALv2lhSG4zF2E0Pk=; b=vbrs2SxYuwpgv592ilUvPRcbFSiPSWwM1A/5JDKF1hmPOHi+T0Omvw+jaUBOE9fZMW YWv7UmZf/lPG5EXeFBMQ8xqGMt7h9IcOUGsmV7qs2QCKhw8jm/jZ4l0PL4PxgqtdjCmd GQdyQ7u9fgYPhWyxbPBivkXaxe+aGb7XatcGSYegE+FQ+hpgO0mPYjlLfmDM+IJSAwDv dWGwe3V7eBs7tixbtYBZdJdubgh2+amZ6um9ujZcvc7MSCxXJEYm2LJPmOcWwn1bguig XHeCARW2jKrbA8vbzJbhBMlXtLzxITUI4bGUHhUPJ9bILEQspUpn7Vr6m8TyOF+OkUlr ojCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772749753; x=1773354553; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=/o1sMjKw1NNm8NoRHmNtAwKcjHmALv2lhSG4zF2E0Pk=; b=tIPyFu7mJrKiuyYsu6w7GlvreAWGj4L6zwyy3H1Dup/VMlzo7sQwdW3XDsjClXypvR LsXs39wNKHZQSplS8e34MKgzqUeYRo5/EQvBTD3VzPxStbXbn0G5ZFN8wVLJSuacYZfk 7XDRzpTsskgORjLzVR7Ke8MGYFWsaiZffvdDupFgrXO4i1b8icfbIJJPZHZ69YBamCiY IsuCB6e/Z3sfPW57v+wKGjboH3To/zEc6NU1RK2hiaEIdU8dkSOqvooiLT0tyxqv+bEK xgjRtxtWsNrXYwEmBDzcpK5977SmFAiq9OKkxQcMjJqA3o3lFfKuvxYciqkwD5gt+3fx Pcyg== X-Forwarded-Encrypted: i=1; AJvYcCWXQL4P2rNlz4ZS+NNpm6n63yx0Im6N4Erw8hZ+WBSy8UDbqPqpvSCk+KC830oErNrnDjI=@vger.kernel.org X-Gm-Message-State: AOJu0YwC803til8nSmclMeTW+SleIFwGZZ8abVE0kddGEGwKUaD7w4oz t0L1zRtf8shBEiPnnLW5AZ+IfEgtl660C3bylMCVQd+pGlP9TLFS05YuL4u+PIX7Z0gA7jbdowD w9+4A0g== X-Received: from pjbgd21.prod.google.com ([2002:a17:90b:fd5:b0:359:92db:6c34]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2c86:b0:356:2872:9c5d with SMTP id 98e67ed59e1d1-359a6a6648fmr7125618a91.24.1772749752983; Thu, 05 Mar 2026 14:29:12 -0800 (PST) Date: Thu, 5 Mar 2026 14:29:11 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250804064405.4802-1-thijs@raymakers.nl> Message-ID: Subject: Re: [PATCH v3] KVM: x86: use array_index_nospec with indices that come from guest From: Sean Christopherson To: Jim Mattson Cc: David Woodhouse , Thijs Raymakers , kvm@vger.kernel.org, Anel Orazgaliyeva , stable , Paolo Bonzini , Greg Kroah-Hartman Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 05, 2026, Jim Mattson wrote: > On Thu, Mar 5, 2026 at 12:31=E2=80=AFPM David Woodhouse wrote: > > > > On Mon, 2025-08-04 at 08:44 +0200, Thijs Raymakers wrote: > > > min and dest_id are guest-controlled indices. Using array_index_nospe= c() > > > after the bounds checks clamps these values to mitigate speculative e= xecution > > > 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_bitma= p, struct kvm_apic_map *map, > > > if (min > map->max_apic_id) > > > return 0; > > > > > > + min =3D 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 =3D map->phys_map[min + i]->vcpu; > > count +=3D 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. >=20 > Heh. Me too! LOL, OMG, get off your high horses you two and someone send a damn patch! = =20