From nobody Sat Oct 4 00:26:51 2025 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 77E812D7DFE for ; Thu, 21 Aug 2025 21:42:14 +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=1755812538; cv=none; b=A2XWpOVFlqYfsi9m6Es7DJVZQkEf37H3dgmb1/VKi6e0lmCvPQlNZNBiBWwQf9yl8/AbsmUdAJrLHclceZ5FOmZ5MzZKOQWZCzAl58Cxb53sEWeq4bX9gKy5W4wWGVAVbfZ8PDWlGJVdnmpMdPzZcTDEfANFpEj4S/SYDz6ibvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755812538; c=relaxed/simple; bh=Lf+JcUrsNjdiwcKVM3wf6UYm00YOlpl+4ht+XtJ8Ntg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LD4rsmv64dWKvGec9hK2lQ8an7593phG/choDRMWDNgdcZtycwHPOLKZz8i/WtOaVEjpKL7B6jCq+7bxQOh2RaqVrrULxZhqtXC9LFlkpBA9WX3UApZEHvkLO2ce00LL64g6SaO7slwDlGZfjzbDM63CWyjL/+Tzj8ScU5f9F60= 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=isnLLP9G; 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="isnLLP9G" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-323266ce853so2753046a91.0 for ; Thu, 21 Aug 2025 14:42:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755812534; x=1756417334; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=gJ2zh7tgefquuiklp07IWePdGx5BpIIKUsroXgrxPYI=; b=isnLLP9GMOxDI4pszypZItzhuoV3F1eoXuW5TE6AQR3H+woAtctUeBoTr/CGmJDpbn P2jNVW0DKBDfwHZqz1LsZzAYaxBySPAvjzXStpOsrJ26UrBDz2Za3qFNXG7YwPIuWyeh xVmby6zeszLM28e2mwVgYaVEsjaDItIHIjhXABRhxh+F2o2dw/rcIssowejR98Q9snDg YVpHuwMv4Ttnf81qTULg8SI/Izs1x2QhpZPYskHyJiuVJwB0i9Wr1M6auSuT5bp/lzyY +hCTFTxdQ1YAdzpZpsm/nkEm2DCF4DbDG9jW59BVp7x0LextQHEZWGF090epeNNciXUo iI/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755812534; x=1756417334; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gJ2zh7tgefquuiklp07IWePdGx5BpIIKUsroXgrxPYI=; b=h+jVnUiN67m0AY/u9vVVLPy6IgybQpK0ZPPHhGI4ABvu0i+8bLW3alEKVMO+hIOgQa pRmKRyIr32NipOX8xHTCcspuhv7/21JsSR4eVwbnf1OC+IrIqBQ+oF1UQ/5S5C4cKz+o fJ4H0bnA2BCOLG7S6GSAXxauExTjNVBU03fzVIGqCjCWp4eoWRwzNdVii2ZUhdJMC8Dr TEJ1kskOS666IBYL+dEUe1ZAjQScFLB0jBAg9bicN1c1x/OGMwq1Iqm+RCQ68p9g52zb HlQ0cept6p5xuvWxGNZJFVbKb+s1MKNsjI7pMVF4d/4gSfD/tz1iRTvduNVUbcUOsWbI gUTw== X-Forwarded-Encrypted: i=1; AJvYcCX6Fu5gbV/EPV/f1cM0SP8UTFRn+2gHmCf78c91en09ZkRpbsVZtupqRG6dhHXJe8fr0teU3bH1N4/yeB4=@vger.kernel.org X-Gm-Message-State: AOJu0Yzhv4eOqgFquiy4c+eXZ8gnnJpLxYWB6NhvnWCm7NiFxwremzl9 JCZL4CU1XHj+S+Uz6gMUc/k3oQqga1tSwHPzhnc7FBUUuQqTzVK7KUiBiklTty4suH1haOz4phB RDvxE3A== X-Google-Smtp-Source: AGHT+IGi9CWLKQ/i7jqh6MrVWtFDstjvtqVw8+zufZV9X09f0xN95sYay6f9DBRcFZnQf0iZ7OsfNQWPI2o= X-Received: from pjxx7.prod.google.com ([2002:a17:90b:58c7:b0:31e:998f:7b79]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4b8d:b0:31f:12d:ee4d with SMTP id 98e67ed59e1d1-32517d19c3amr1120471a91.26.1755812533785; Thu, 21 Aug 2025 14:42:13 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:42:07 -0700 In-Reply-To: <20250821214209.3463350-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821214209.3463350-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821214209.3463350-2-seanjc@google.com> Subject: [PATCH 1/3] KVM: x86: Move kvm_irq_delivery_to_apic() from irq.c to lapic.c From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move kvm_irq_delivery_to_apic() to lapic.c as it is specific to local APIC emulation. This will allow burying more local APIC code in lapic.c, e.g. the various "lowest priority" helpers. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/irq.c | 57 -------------------------------------------- arch/x86/kvm/irq.h | 4 ---- arch/x86/kvm/lapic.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ arch/x86/kvm/lapic.h | 3 +++ 4 files changed, 60 insertions(+), 61 deletions(-) diff --git a/arch/x86/kvm/irq.c b/arch/x86/kvm/irq.c index 16da89259011..a6b122f732be 100644 --- a/arch/x86/kvm/irq.c +++ b/arch/x86/kvm/irq.c @@ -195,63 +195,6 @@ bool kvm_arch_irqchip_in_kernel(struct kvm *kvm) return irqchip_in_kernel(kvm); } =20 -int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, - struct kvm_lapic_irq *irq, struct dest_map *dest_map) -{ - int r =3D -1; - struct kvm_vcpu *vcpu, *lowest =3D NULL; - unsigned long i, dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)]; - unsigned int dest_vcpus =3D 0; - - if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r, dest_map)) - return r; - - if (irq->dest_mode =3D=3D APIC_DEST_PHYSICAL && - irq->dest_id =3D=3D 0xff && kvm_lowest_prio_delivery(irq)) { - pr_info("apic: phys broadcast and lowest prio\n"); - irq->delivery_mode =3D APIC_DM_FIXED; - } - - memset(dest_vcpu_bitmap, 0, sizeof(dest_vcpu_bitmap)); - - kvm_for_each_vcpu(i, vcpu, kvm) { - if (!kvm_apic_present(vcpu)) - continue; - - if (!kvm_apic_match_dest(vcpu, src, irq->shorthand, - irq->dest_id, irq->dest_mode)) - continue; - - if (!kvm_lowest_prio_delivery(irq)) { - if (r < 0) - r =3D 0; - r +=3D kvm_apic_set_irq(vcpu, irq, dest_map); - } else if (kvm_apic_sw_enabled(vcpu->arch.apic)) { - if (!kvm_vector_hashing_enabled()) { - if (!lowest) - lowest =3D vcpu; - else if (kvm_apic_compare_prio(vcpu, lowest) < 0) - lowest =3D vcpu; - } else { - __set_bit(i, dest_vcpu_bitmap); - dest_vcpus++; - } - } - } - - if (dest_vcpus !=3D 0) { - int idx =3D kvm_vector_to_index(irq->vector, dest_vcpus, - dest_vcpu_bitmap, KVM_MAX_VCPUS); - - lowest =3D kvm_get_vcpu(kvm, idx); - } - - if (lowest) - r =3D kvm_apic_set_irq(lowest, irq, dest_map); - - return r; -} - static void kvm_msi_to_lapic_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, struct kvm_lapic_irq *irq) diff --git a/arch/x86/kvm/irq.h b/arch/x86/kvm/irq.h index 5e62c1f79ce6..34f4a78a7a01 100644 --- a/arch/x86/kvm/irq.h +++ b/arch/x86/kvm/irq.h @@ -121,8 +121,4 @@ void __kvm_migrate_timers(struct kvm_vcpu *vcpu); =20 int apic_has_pending_timer(struct kvm_vcpu *vcpu); =20 -int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, - struct kvm_lapic_irq *irq, - struct dest_map *dest_map); - #endif diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index ed636c1f5e58..129ade22efca 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1251,6 +1251,63 @@ bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, s= truct kvm_lapic_irq *irq, return ret; } =20 +int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, + struct kvm_lapic_irq *irq, struct dest_map *dest_map) +{ + int r =3D -1; + struct kvm_vcpu *vcpu, *lowest =3D NULL; + unsigned long i, dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)]; + unsigned int dest_vcpus =3D 0; + + if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r, dest_map)) + return r; + + if (irq->dest_mode =3D=3D APIC_DEST_PHYSICAL && + irq->dest_id =3D=3D 0xff && kvm_lowest_prio_delivery(irq)) { + pr_info("apic: phys broadcast and lowest prio\n"); + irq->delivery_mode =3D APIC_DM_FIXED; + } + + memset(dest_vcpu_bitmap, 0, sizeof(dest_vcpu_bitmap)); + + kvm_for_each_vcpu(i, vcpu, kvm) { + if (!kvm_apic_present(vcpu)) + continue; + + if (!kvm_apic_match_dest(vcpu, src, irq->shorthand, + irq->dest_id, irq->dest_mode)) + continue; + + if (!kvm_lowest_prio_delivery(irq)) { + if (r < 0) + r =3D 0; + r +=3D kvm_apic_set_irq(vcpu, irq, dest_map); + } else if (kvm_apic_sw_enabled(vcpu->arch.apic)) { + if (!kvm_vector_hashing_enabled()) { + if (!lowest) + lowest =3D vcpu; + else if (kvm_apic_compare_prio(vcpu, lowest) < 0) + lowest =3D vcpu; + } else { + __set_bit(i, dest_vcpu_bitmap); + dest_vcpus++; + } + } + } + + if (dest_vcpus !=3D 0) { + int idx =3D kvm_vector_to_index(irq->vector, dest_vcpus, + dest_vcpu_bitmap, KVM_MAX_VCPUS); + + lowest =3D kvm_get_vcpu(kvm, idx); + } + + if (lowest) + r =3D kvm_apic_set_irq(lowest, irq, dest_map); + + return r; +} + /* * Add a pending IRQ into lapic. * Return 1 if successfully added and 0 if discarded. diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 8b00e29741de..edfed763cf89 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -119,6 +119,9 @@ void kvm_inhibit_apic_access_page(struct kvm_vcpu *vcpu= ); =20 bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, struct kvm_lapic_irq *irq, int *r, struct dest_map *dest_map); +int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, + struct kvm_lapic_irq *irq, + struct dest_map *dest_map); void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high); =20 int kvm_apic_set_base(struct kvm_vcpu *vcpu, u64 value, bool host_initiate= d); --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:26:51 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 374692E7BC5 for ; Thu, 21 Aug 2025 21:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755812537; cv=none; b=bpKomhcGPMU+goe8CYBEwOf3Bm3AMbXSLbSYbcgzuA/x9HxbMrsISUWpWvUf7d1BffP/e8yr4MXQy+3+m10RerdL7BMsbNICoEdp4Vd1RGW3SFb9V4IOnI+xGX4gvg4VJ3uZyL/OrsLVG8kfYAxKk1PGeh3k7FJd/Gp/PqXMR3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755812537; c=relaxed/simple; bh=ca0kzC2BdLl1IEbdeerqiPG0LW2JuMEFuPZUqCrU+ms=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TjLcOoqpOwMutnFjp3hWybDbe2okF6gl6t7iyOczvcWVtJvRnvi2d7wBVowBoXE+mzYpMCgYyRgSDOJdnO9dEpTJo4QusTflcJ0EFzwQOyeqJdouW+5DnJmMgm6seGHNl7cCBo4cwVU0xstatL+1vbJAxr/NfXVKJ52k2wZGGVk= 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=xRk9hRog; arc=none smtp.client-ip=209.85.216.73 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="xRk9hRog" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3250e3b161bso397329a91.0 for ; Thu, 21 Aug 2025 14:42:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755812535; x=1756417335; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=OSS0ebn8BjSjAcdAaIlZpHKKhuVPmoJB9rSKcDaaT3k=; b=xRk9hRogFuhksiNliH3yTfYBamDqqOV7UcEq/ryVYLU0BEgZjPdOthzK+hT2ZwCVLy jybyGSngD00jNuOQjTesHkdutWbL1hcxI4QMxzIDo2i+mTWIWaJAPRkMwI99EiPe6IOw BP2+32/L9DXz10Bp2af2W4Wx0sIvOgd8nLt5o9LNWoKy0UhV/LFBN5ZJb3V8WlkWinb3 hZcdLP7738x/nK05RktcDIEdZvJkIDFnr1rCdI9oqirJKi2I/XIRgWQR8q1P4XHK63+K f06wTnx+cZsopEtYAqSRJM90Mm6MVEnZ/7P+Nzg2VntegHK3NQpVjaeZOiN/sZvyOZUP tOsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755812535; x=1756417335; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OSS0ebn8BjSjAcdAaIlZpHKKhuVPmoJB9rSKcDaaT3k=; b=g8XH4UScZPNgIx5zqj9NW1edsty5eg0nWfXr+676gHjoeIra1v+VA0D6GmTZulKigp TpN7phYSK1eVH1GovJ0JWgwF3fFNhfEboK57mGEED/U5cAKc3/1x6NiQz7unEzXopLIH n4Gsrm6s/4qiCD5exxyJ6dL+9ZXyQrUDub4gjhi6uGtIro9YO9CQXO30YqouQ+Ymyndf p6hrB3+a0G8Ys6QzBsskRQcP5q0IFK6gUD8xoj7+vlskeGBIbIVO8wRpI2GU6M8F4VEN lF8xwS5b44tFSQh2uJw1fH5kmx4SFSGh2PjhLSvDwe9doGqHcHsf46b+T3jvMF+rGm7e Xa5g== X-Forwarded-Encrypted: i=1; AJvYcCUu9XRzYdJNrZrg3z1AjM8I+aGfWMp7xqgYjRDsIbjBQTzyiWEByu0sy6f/IiWcUU35rypDQ3LphVF/b60=@vger.kernel.org X-Gm-Message-State: AOJu0YwrSFDtogat07NIl1lmWM61N7q3quig6nTzHu8Hd9fkv7HRN/t4 MNSsPhZgcLw2fDit1Vns3TIKCQi6k796ZrNisRwkZK4sV3b0H+bbAfxpD5Y+mmgr+wbK1Txw9u0 DUt7X5A== X-Google-Smtp-Source: AGHT+IGNgc8k2e72ps969uvmThUfuYJmfxHpoyG6JUsRaulQAD2cbnF2fFqr89qAQwVjqG1aUuTvd/V3mKo= X-Received: from pjboh13.prod.google.com ([2002:a17:90b:3a4d:b0:31f:26b:cc66]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:51cd:b0:31e:f193:1822 with SMTP id 98e67ed59e1d1-32517745f63mr1046195a91.28.1755812535571; Thu, 21 Aug 2025 14:42:15 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:42:08 -0700 In-Reply-To: <20250821214209.3463350-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821214209.3463350-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821214209.3463350-3-seanjc@google.com> Subject: [PATCH 2/3] KVM: x86: Make "lowest priority" helpers local to lapic.c From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make various helpers for resolving lowest priority IRQs local to lapic.c now that kvm_irq_delivery_to_apic() lives in lapic.c as well. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/lapic.c | 19 ++++++++++++------- arch/x86/kvm/lapic.h | 9 --------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 129ade22efca..1a8bc81973e3 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1063,8 +1063,8 @@ bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, struc= t kvm_lapic *source, } EXPORT_SYMBOL_GPL(kvm_apic_match_dest); =20 -int kvm_vector_to_index(u32 vector, u32 dest_vcpus, - const unsigned long *bitmap, u32 bitmap_size) +static int kvm_vector_to_index(u32 vector, u32 dest_vcpus, + const unsigned long *bitmap, u32 bitmap_size) { int idx =3D find_nth_bit(bitmap, bitmap_size, vector % dest_vcpus); =20 @@ -1099,6 +1099,16 @@ static bool kvm_apic_is_broadcast_dest(struct kvm *k= vm, struct kvm_lapic **src, return false; } =20 +static bool kvm_lowest_prio_delivery(struct kvm_lapic_irq *irq) +{ + return (irq->delivery_mode =3D=3D APIC_DM_LOWEST || irq->msi_redir_hint); +} + +static int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *= vcpu2) +{ + return vcpu1->arch.apic_arb_prio - vcpu2->arch.apic_arb_prio; +} + /* Return true if the interrupt can be handled by using *bitmap as index m= ask * for valid destinations in *dst array. * Return false if kvm_apic_map_get_dest_lapic did nothing useful. @@ -1451,11 +1461,6 @@ void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struc= t kvm_lapic_irq *irq, rcu_read_unlock(); } =20 -int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2) -{ - return vcpu1->arch.apic_arb_prio - vcpu2->arch.apic_arb_prio; -} - static bool kvm_ioapic_handles_vector(struct kvm_lapic *apic, int vector) { return test_bit(vector, apic->vcpu->arch.ioapic_handled_vectors); diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index edfed763cf89..50123fe7f58f 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -105,7 +105,6 @@ void kvm_apic_set_version(struct kvm_vcpu *vcpu); void kvm_apic_after_set_mcg_cap(struct kvm_vcpu *vcpu); bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, int shorthand, unsigned int dest, int dest_mode); -int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2); void kvm_apic_clear_irr(struct kvm_vcpu *vcpu, int vec); bool __kvm_apic_update_irr(unsigned long *pir, void *regs, int *max_irr); bool kvm_apic_update_irr(struct kvm_vcpu *vcpu, unsigned long *pir, int *m= ax_irr); @@ -225,12 +224,6 @@ static inline bool kvm_apic_init_sipi_allowed(struct k= vm_vcpu *vcpu) !kvm_x86_call(apic_init_signal_blocked)(vcpu); } =20 -static inline bool kvm_lowest_prio_delivery(struct kvm_lapic_irq *irq) -{ - return (irq->delivery_mode =3D=3D APIC_DM_LOWEST || - irq->msi_redir_hint); -} - static inline int kvm_lapic_latched_init(struct kvm_vcpu *vcpu) { return lapic_in_kernel(vcpu) && test_bit(KVM_APIC_INIT, &vcpu->arch.apic-= >pending_events); @@ -245,8 +238,6 @@ void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct k= vm_lapic_irq *irq, =20 bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *i= rq, struct kvm_vcpu **dest_vcpu); -int kvm_vector_to_index(u32 vector, u32 dest_vcpus, - const unsigned long *bitmap, u32 bitmap_size); void kvm_lapic_switch_to_sw_timer(struct kvm_vcpu *vcpu); void kvm_lapic_switch_to_hv_timer(struct kvm_vcpu *vcpu); void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu); --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:26:51 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 ACDEC2D7DFC for ; Thu, 21 Aug 2025 21:42:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755812539; cv=none; b=LU/KRLgGC26KIj+vbPQjc3dxb/0u2KVbgJEOwY834lkBz79oM59fPgg4lBhkiHnw2hp4qgheirNUcBSCOiiHMpxYHpD2koTAkK7Xbuw/wGL7/ZbV2/fooWMeVuJHm3OeBiLG5MOZsku72CWhUc6qQOnhbikGgF2+0Jl+78aM52k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755812539; c=relaxed/simple; bh=jO/gj25JzhDalfYTefJGdFK+irEJClGBRvjVRqOnfsk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EkIm8qYRc0RNTGTEaNOl0I8odNzUlI1Tzknm62kUUlvNA9wDKyTWAZZq+ryR6uZdUIQqZhVXvtbATnMIdlJKAkRIIujsCaUhGThH9XQRC4+ayqe8/GPd+Fo6txP7Qv9Mmi0IY7AbRERaOB57ACEx7QhjHUuNEtmdCsDOTmKPIbU= 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=06Tufx1W; arc=none smtp.client-ip=209.85.214.201 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="06Tufx1W" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-24458264c5aso16542535ad.3 for ; Thu, 21 Aug 2025 14:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755812537; x=1756417337; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=e8pkHcdgPqI0ISkr0EzZdXVU8MYoR6lkGEb75P/NGP4=; b=06Tufx1WuMNaTrR661jIZWG5iTeBq6DmlLsWZccwUdqBAxCPtMD4VbklqCE0qEsEMz hcV7sb3dadXFg0cjkWijsvNore2DrVAEoj1hN2La7XS3WDszAtKQpH949aKgAlNaGKm2 0ZsTuwoKpStjSr668nf1Os1TzzUeTs7jMzY++uP8wTyuYvTnvbiY2yaHdZjKhss5K5lt jlHgoynlK0EpshLmIaCeJGcfgWvlEaE3rgIMMyFUNfbTaGnHmXPOk3ukYpKJanUcYonZ CpxMhO2d2XKWQKTUgs5coTy+wLglDsArvymPI/35GApyq5cD4RuDbd8qAHJ6XwxG4kEe c5/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755812537; x=1756417337; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=e8pkHcdgPqI0ISkr0EzZdXVU8MYoR6lkGEb75P/NGP4=; b=c6bGSz4W8MyfKkCv2K/ih5Rh254L3OhRMzaJdxtnPytFVG4InlReoUGhMX3WY4z1Kc rWpJQ1Kt8QD3992st6vfvVvQbza3x/aC2G3VZ/QX4TfkYvyL45DhHc5bOq0lw3xc3c1x p2E1xf6lLKsfAff5ws8NwbhznbI7AxFplGJxtb51yehfu/yZKUZivctoo3DqT0YSeEwY ZyJ+SdJKM3TK0YG1agDVA9CrKZraNvPm1ZGC2w4lwI1lux6eMkJgpSiojBsCHDk7GH08 UehhtOh4f/OFA7CHfWI3Uwu6JijmdyoLubJssgghV+nJC9JWa42xDo7sMGjaxKX/0tQ4 VN+g== X-Forwarded-Encrypted: i=1; AJvYcCVlSZ5uZU7UrYZjkAZN88ukW7wLoU03IpzXxbB1WouiwHBxR5t0C0AuPSnFzZ0zoqFCHfPDbU6UWmrRK/8=@vger.kernel.org X-Gm-Message-State: AOJu0YzSEPGeD25cyGEN7Quzmo2RfDv6jNKYfWr+axG/zaCx4k4rlExT 5SA0rhhd3ZtZUAnH1Mq40xiMVy/TyB9H5HFizlPlO3jil0PxnfsO5uULk3l+aKEeKTxvIie1vPF DyG6lgg== X-Google-Smtp-Source: AGHT+IFT6Sn/6lo/x/nO8mYo4e+XE4zjzpgAf9RzlJKpSlQeT3lTnfh3y0Zb8gxOWD92wxfJvI93w2u+hBs= X-Received: from pjbsi8.prod.google.com ([2002:a17:90b:5288:b0:320:e3b2:68de]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2a8b:b0:246:3964:63dc with SMTP id d9443c01a7336-2463964650fmr4102925ad.47.1755812537064; Thu, 21 Aug 2025 14:42:17 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:42:09 -0700 In-Reply-To: <20250821214209.3463350-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821214209.3463350-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821214209.3463350-4-seanjc@google.com> Subject: [PATCH 3/3] KVM: x86: Move vector_hashing into lapic.c From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the vector_hashing module param into lapic.c now that all usage is contained within the local APIC emulation code. Opportunistically drop the accessor and append "_enabled" to the variable to help capture that it's a boolean module param. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/lapic.c | 8 ++++++-- arch/x86/kvm/x86.c | 8 -------- arch/x86/kvm/x86.h | 1 - 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 1a8bc81973e3..6fac6fb86c19 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -74,6 +74,10 @@ module_param(lapic_timer_advance, bool, 0444); #define LAPIC_TIMER_ADVANCE_NS_MAX 5000 /* step-by-step approximation to mitigate fluctuation */ #define LAPIC_TIMER_ADVANCE_ADJUST_STEP 8 + +static bool __read_mostly vector_hashing_enabled =3D true; +module_param_named(vector_hashing, vector_hashing_enabled, bool, 0444); + static int kvm_lapic_msr_read(struct kvm_lapic *apic, u32 reg, u64 *data); static int kvm_lapic_msr_write(struct kvm_lapic *apic, u32 reg, u64 data); =20 @@ -1152,7 +1156,7 @@ static inline bool kvm_apic_map_get_dest_lapic(struct= kvm *kvm, if (!kvm_lowest_prio_delivery(irq)) return true; =20 - if (!kvm_vector_hashing_enabled()) { + if (!vector_hashing_enabled) { lowest =3D -1; for_each_set_bit(i, bitmap, 16) { if (!(*dst)[i]) @@ -1293,7 +1297,7 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct = kvm_lapic *src, r =3D 0; r +=3D kvm_apic_set_irq(vcpu, irq, dest_map); } else if (kvm_apic_sw_enabled(vcpu->arch.apic)) { - if (!kvm_vector_hashing_enabled()) { + if (!vector_hashing_enabled) { if (!lowest) lowest =3D vcpu; else if (kvm_apic_compare_prio(vcpu, lowest) < 0) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7ba2cdfdac44..554b36de700c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -164,9 +164,6 @@ module_param(kvmclock_periodic_sync, bool, 0444); static u32 __read_mostly tsc_tolerance_ppm =3D 250; module_param(tsc_tolerance_ppm, uint, 0644); =20 -static bool __read_mostly vector_hashing =3D true; -module_param(vector_hashing, bool, 0444); - bool __read_mostly enable_vmware_backdoor =3D false; module_param(enable_vmware_backdoor, bool, 0444); EXPORT_SYMBOL_GPL(enable_vmware_backdoor); @@ -13552,11 +13549,6 @@ bool kvm_arch_has_noncoherent_dma(struct kvm *kvm) } EXPORT_SYMBOL_GPL(kvm_arch_has_noncoherent_dma); =20 -bool kvm_vector_hashing_enabled(void) -{ - return vector_hashing; -} - bool kvm_arch_no_poll(struct kvm_vcpu *vcpu) { return (vcpu->arch.msr_kvm_poll_control & 1) =3D=3D 0; diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index eb3088684e8a..786e36fcd0fb 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -431,7 +431,6 @@ void kvm_deliver_exception_payload(struct kvm_vcpu *vcp= u, =20 int kvm_mtrr_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data); int kvm_mtrr_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata); -bool kvm_vector_hashing_enabled(void); void kvm_fixup_and_inject_pf_error(struct kvm_vcpu *vcpu, gva_t gva, u16 e= rror_code); int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_t= ype, void *insn, int insn_len); --=20 2.51.0.261.g7ce5a0a67e-goog