From nobody Sun Oct 5 21:44:02 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 423C829A333 for ; Tue, 29 Jul 2025 17:42:48 +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=1753810970; cv=none; b=nEOcx/snj1clC1PdSceqIO00b44QZQ55UYqYnEYSu+ThmAer2eCYC1hUj3IbTar/cjpeKVBpO4DHGd+VQgJvd8YlM6C9crie6HT+1oNlrNgYHgZCE376AciuN2aXiibOOPxnHp8w+NKSvvSdqu52eMrRzY02+DUKE20Qd/bcXZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753810970; c=relaxed/simple; bh=HV9KqRi+UXjwAqAgOTdxJCi1FXQpzwK52ESSl7WIzoE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Csc9FLr+mW0pF6uceczGFYBzoap9ZHq5bziDOdY2PuqqKXB55cZ0aW9MNEnZ1ZNqdQbIoXL69nnGuT2BfrMYVOJML5vIjaI2O6ADAxyoo1gayTM+uxz2OSUDKYyKjt4G89FnQBa5SGY+/mNnNDa/CAq8vNqb+UK4uEelzg1JnZQ= 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=B+T6beBJ; 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="B+T6beBJ" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-31edd69d754so2580145a91.1 for ; Tue, 29 Jul 2025 10:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753810967; x=1754415767; 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=/DbcrgN3ecCQw7+uhqZKGmeiF8XPifOJ/SE5LpRMvY8=; b=B+T6beBJCIROfoaUDBFuJg8RdG42r7WuLLVlB6YC3vivIqfdMgazrvMqewOfD396AD IOtnxq6FS2xJV/AIY0AA/6G4Zw8Ws64WeS5VcU99QwYirxwR/xTvHSnhPZtFs4i3B6zD BhG76wSZLsL24ECylzHzXSl7gSIjcIr3l/0KJvtnmjI4iEYROKjWAcaUrSS5kg/IdJ7P DZDTJ/OsnIbgXzxYrIxndd0rFCS8eygs8fIFtEBQ357xnuuExIdZCZZ1NhWODEdOYo+9 qZYnF1hntozS+T/GsT5MVCyt/dJo2G0TKhFzjfsjW7eqdLqmfhe+LNORfPEa48NnsC6V rHiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753810967; x=1754415767; 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=/DbcrgN3ecCQw7+uhqZKGmeiF8XPifOJ/SE5LpRMvY8=; b=vjfbUZeYvqyuFrULb86ImXf+2GSwnUEpqCOS7V0U1+AH1nvamfiRkmM53TMHH36WWh gpQWxPsfb6lK+eJeb99/tsURcZeUxcpQuyhgNaFqWdyusM+vrFIEj9TL8W8ESoGIJEb0 J32qZZqgmWMk2fYIo/8mB1GlIsX7wocuE3iIBAxt5KlrruU1cXr9mieDtahikSbH+ZCY FW4P/dTKiBHuWNHYLL92QLlJ6u2rysrJx/9U3AUWcWK0uH0yNlKtwj/3v9RA8OrTLTR0 D17uhB/+LG/NSm2kjB3jF/xxEyJ0n7BkqvZDMeY3l4vTB8A8IGkvelBM2o4E9H3k8mIE cNNg== X-Forwarded-Encrypted: i=1; AJvYcCUkYkgyBWlTB2A3gsFSeG9xID5CO66SvAEQEI9BPn8/MWXG6wBc2NborkcsRDXsm1Qj6n8QO8pcHeJopbw=@vger.kernel.org X-Gm-Message-State: AOJu0YwJdln/FN4yHGnpuhUKX7oYx+gpunGBn88yLO6TsZOFnhiFNe72 bvxJqJ6l7P8pKlY7kuHQV7U63hxxpKfcMP03HheFSTEow4oW/1no7hbRpn8EuCfL7RR/8yKJKKO QYEKEKw== X-Google-Smtp-Source: AGHT+IFH+wIDKMsSmrwhy/nAH7BTEpi34izfhqEJk0uofVTDFy3OPhYpSTuENnjPuH/IjmdxV+EpZXPT7WQ= X-Received: from pjqx17.prod.google.com ([2002:a17:90a:b011:b0:314:29b4:453]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4a92:b0:31f:150:e02b with SMTP id 98e67ed59e1d1-31f5dd6fd0fmr572556a91.4.1753810966810; Tue, 29 Jul 2025 10:42:46 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 29 Jul 2025 10:42:35 -0700 In-Reply-To: <20250729174238.593070-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: <20250729174238.593070-1-seanjc@google.com> X-Mailer: git-send-email 2.50.1.552.g942d659e1b-goog Message-ID: <20250729174238.593070-4-seanjc@google.com> Subject: [PATCH 3/6] KVM: x86: Move kvm_intr_is_single_vcpu() to lapic.c From: Sean Christopherson To: Madhavan Srinivasan , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Andy Lutomirski , Xin Li , "H. Peter Anvin" , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Borislav Petkov , Josh Poimboeuf , Jarkko Sakkinen , Vitaly Kuznetsov , Dave Hansen , "Kirill A. Shutemov" , Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Holger Dengler Cc: linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-sgx@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev, linux-s390@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move kvm_intr_is_single_vcpu() to lapic.c, drop its export, and make its "fast" helper local to lapic.c. kvm_intr_is_single_vcpu() is only usable if the local APIC is in-kernel, i.e. it most definitely belongs in the local APIC code. No functional change intended. Fixes: 2f5fb6b965b3 ("KVM: x86: Dedup AVIC vs. PI code for identifying targ= et vCPU") Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 3 --- arch/x86/kvm/irq.c | 28 ---------------------------- arch/x86/kvm/lapic.c | 32 ++++++++++++++++++++++++++++++-- arch/x86/kvm/lapic.h | 4 ++-- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index f19a76d3ca0e..99c07a37bf80 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2392,9 +2392,6 @@ void __user *__x86_set_memory_region(struct kvm *kvm,= int id, gpa_t gpa, bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu); bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu); =20 -bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq, - struct kvm_vcpu **dest_vcpu); - static inline bool kvm_irq_is_postable(struct kvm_lapic_irq *irq) { /* We can only post Fixed and LowPrio IRQs */ diff --git a/arch/x86/kvm/irq.c b/arch/x86/kvm/irq.c index 16da89259011..a1a388c00187 100644 --- a/arch/x86/kvm/irq.c +++ b/arch/x86/kvm/irq.c @@ -411,34 +411,6 @@ int kvm_set_routing_entry(struct kvm *kvm, return 0; } =20 -bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq, - struct kvm_vcpu **dest_vcpu) -{ - int r =3D 0; - unsigned long i; - struct kvm_vcpu *vcpu; - - if (kvm_intr_is_single_vcpu_fast(kvm, irq, dest_vcpu)) - return true; - - kvm_for_each_vcpu(i, vcpu, kvm) { - if (!kvm_apic_present(vcpu)) - continue; - - if (!kvm_apic_match_dest(vcpu, NULL, irq->shorthand, - irq->dest_id, irq->dest_mode)) - continue; - - if (++r =3D=3D 2) - return false; - - *dest_vcpu =3D vcpu; - } - - return r =3D=3D 1; -} -EXPORT_SYMBOL_GPL(kvm_intr_is_single_vcpu); - void kvm_scan_ioapic_irq(struct kvm_vcpu *vcpu, u32 dest_id, u16 dest_mode, u8 vector, unsigned long *ioapic_handled_vectors) { diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 8172c2042dd6..20f7a7d0c422 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1228,8 +1228,9 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, s= truct kvm_lapic *src, * interrupt. * - Otherwise, use remapped mode to inject the interrupt. */ -bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *i= rq, - struct kvm_vcpu **dest_vcpu) +static bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, + struct kvm_lapic_irq *irq, + struct kvm_vcpu **dest_vcpu) { struct kvm_apic_map *map; unsigned long bitmap; @@ -1256,6 +1257,33 @@ bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, s= truct kvm_lapic_irq *irq, return ret; } =20 +bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq, + struct kvm_vcpu **dest_vcpu) +{ + int r =3D 0; + unsigned long i; + struct kvm_vcpu *vcpu; + + if (kvm_intr_is_single_vcpu_fast(kvm, irq, dest_vcpu)) + return true; + + kvm_for_each_vcpu(i, vcpu, kvm) { + if (!kvm_apic_present(vcpu)) + continue; + + if (!kvm_apic_match_dest(vcpu, NULL, irq->shorthand, + irq->dest_id, irq->dest_mode)) + continue; + + if (++r =3D=3D 2) + return false; + + *dest_vcpu =3D vcpu; + } + + return r =3D=3D 1; +} + /* * 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 72de14527698..b9e44956c162 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -240,8 +240,8 @@ void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu); void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct kvm_lapic_irq *irq, unsigned long *vcpu_bitmap); =20 -bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *i= rq, - struct kvm_vcpu **dest_vcpu); +bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq, + 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); --=20 2.50.1.552.g942d659e1b-goog