From nobody Sun Feb 8 02:26:46 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 2299E27A133 for ; Mon, 12 Jan 2026 23:28:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768260491; cv=none; b=enBYMpQsUJXmlrFClpjYAx9jCyE2VILRx3iO6DwEBJE5cnPZKPdPEWfaevoSeCYwU4nbTheBcAQrQibzA30i9OVeZM0IxNI+D8TK0ZogzRfXC0kA0IZGdJuU+Sja0sceK+Gn4mU0GAiSzIVVCqeBuzO/nCS0ClGxUGyudMBfkM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768260491; c=relaxed/simple; bh=i1FgT2KkBAzlGWwTWhQV19SVFPmH3tqhTRqToUB+FL0=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=AtvZAVVgFQKsiO4e1/LoMA2IgjS8Xesrz2itMrk1x90wQxwKXIgdqI2Ha63SYYV3uPrYICprq3q/q4xRo8ex1Jukh2bfG8WfbqWVeDwTnukl86uKBCoGxxRwkLO70YRmfEwuE9l435Hz0qpUO7QS3qksLqQ8u28WWfSlRLU78sU= 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=WSPQicZb; arc=none smtp.client-ip=209.85.214.202 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="WSPQicZb" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2a351686c17so72212395ad.0 for ; Mon, 12 Jan 2026 15:28:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768260488; x=1768865288; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=Al+fnSBeR94EhBCD4DhJYbBsNosAL5fZnJy+evBGpLU=; b=WSPQicZbCBGSVR7fEzI8HBhCArmA/xwHaZ9JhX5bTyn3wPY1Qb48wD79nM+vNsZcqk c85aGJmveW9NuIuxSaXXc6qjb8Jd1IHkv361P7ks3jwlIuAQlmxg1yiCnleJpxZD19wU r6U4kmp6RcTtQJj8/dc+HmM6pq+SPofLRfPHayPcYQjnsaiwLZWX8ohwUmBrRD5WmVQ6 7WUeorx80Erzg/5P2Af3uqQiUelT9ysrlqFFPRAHtQp1+RfeM7+BtQTBCk5Ocf5ktRFg wpmC/vmhM9mY++KNU+roQgB2U8ZnLRIiYXceYeb6m8gCklRwUEAaOyG/9geybZtfGZUl VcvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768260488; x=1768865288; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Al+fnSBeR94EhBCD4DhJYbBsNosAL5fZnJy+evBGpLU=; b=k1K3KQR8kxkAjGCSrWgQY3j4SWyCVHpI6f+mF1uaz1PV9hqz3jVUOQOGosI886OPsV Qekhg6BUHOoKzKaJawY/w0lplWDrllLZQv9FE+WsgdBz4Su1rxpXARHKX61+YrFsMgvF Nqp45l5ER+0wqgklevWRRN5ArwWzC7zgiuCOeE74sg44+kJ63pEijqtl9QD5CofaW0JK +1CMB4DM4VT1b0HYP6Kx2BGG4d60Vvm47+MrEGYhx6/PmwpFwirWxo7ItXgkQ1avz58Q vpnmsFHVqYfiV/TVGrvt3E7Au6BW4rDBX1K/w5p1Mu+pj76UDI4G6HdEX/o32DZ1Qlf3 PU/g== X-Forwarded-Encrypted: i=1; AJvYcCWR4qdUycNmiQQg3IsQvfg+G+xJxl5q7Gwdp62/RMT/F7tD0aMZ4Zky2494EwnoTOTy/inOsMp9ifG7rP8=@vger.kernel.org X-Gm-Message-State: AOJu0YzUqrop3sMD3q4sGqBKOwzYTDpsozk1IahBVyk+ZvhHCrovWRaO ZNMNkDNwj4axzm0LH2F2KqiIKResWoGx9OQTTK7DAFUGvRzlD3HM/PzY14y+sQQoHdyWB7OU+zS Wg71B9w== X-Google-Smtp-Source: AGHT+IGOIbN80r8vWHNwzUMJvpuio0e8RSJ09Va0qih/FIvZBUT+/83z+mkvfCiT1PFbxkM+F9xoI79gr+w= X-Received: from plaq12.prod.google.com ([2002:a17:903:204c:b0:2a0:9081:40]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:388e:b0:2a2:f0cd:4351 with SMTP id d9443c01a7336-2a3ee4e85f6mr168852835ad.37.1768260488524; Mon, 12 Jan 2026 15:28:08 -0800 (PST) Reply-To: Sean Christopherson Date: Mon, 12 Jan 2026 15:28:05 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260112232805.1512361-1-seanjc@google.com> Subject: [PATCH] KVM: SVM: Check vCPU ID against max x2AVIC ID if and only if x2AVIC is enabled From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Naveen N Rao , Suravee Suthikulpanit Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When allocating the AVIC backing page, only check one of the max AVIC vs. x2AVIC ID based on whether or not x2AVIC is enabled. Doing so fixes a bug where KVM incorrectly inhibits AVIC if x2AVIC is _disabled_ and any vCPU with a non-zero APIC ID is created, as x2avic_max_physical_id is left '0' when x2AVIC is disabled. Fixes: 940fc47cfb0d ("KVM: SVM: Add AVIC support for 4k vCPUs in x2AVIC mod= e") Cc: stable@vger.kernel.org Cc: Naveen N Rao (AMD) Cc: Suravee Suthikulpanit Signed-off-by: Sean Christopherson Reviewed-by: Naveen N Rao (AMD) --- arch/x86/kvm/svm/avic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 6b77b2033208..0f6c8596719b 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -376,6 +376,7 @@ void avic_init_vmcb(struct vcpu_svm *svm, struct vmcb *= vmcb) =20 static int avic_init_backing_page(struct kvm_vcpu *vcpu) { + u32 max_id =3D x2avic_enabled ? x2avic_max_physical_id : AVIC_MAX_PHYSICA= L_ID; struct kvm_svm *kvm_svm =3D to_kvm_svm(vcpu->kvm); struct vcpu_svm *svm =3D to_svm(vcpu); u32 id =3D vcpu->vcpu_id; @@ -388,8 +389,7 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu) * avic_vcpu_load() expects to be called if and only if the vCPU has * fully initialized AVIC. */ - if ((!x2avic_enabled && id > AVIC_MAX_PHYSICAL_ID) || - (id > x2avic_max_physical_id)) { + if (id > max_id) { kvm_set_apicv_inhibit(vcpu->kvm, APICV_INHIBIT_REASON_PHYSICAL_ID_TOO_BI= G); vcpu->arch.apic->apicv_active =3D false; return 0; base-commit: 9448598b22c50c8a5bb77a9103e2d49f134c9578 --=20 2.52.0.457.g6b5491de43-goog