From nobody Mon Jun 29 21:05:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF169C433FE for ; Wed, 2 Feb 2022 18:18:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346607AbiBBSS0 (ORCPT ); Wed, 2 Feb 2022 13:18:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53240 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346443AbiBBSSU (ORCPT ); Wed, 2 Feb 2022 13:18:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643825899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xt9mcVUpdJQpnjeJRK6diyxmq8i9URv9SvRl8wszf7c=; b=UYE19WjFnzyxTEHoXH4U0BmBdQoc/NSVbW9NsHctMNsRnD9jWo5p7VB9/+wHCDTwr6QtU6 zB3gtfzMsxVbRPaEz51JtDrZGWVbj4MLAChJrAdDhSH6wUQdGCCgrPJTB9HxdZdFvWs4eM E6uXzxT0IbYL3TudRA5E1AMWiZcxM7I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-451-kF07KXLyNimRWKg7kCHZxA-1; Wed, 02 Feb 2022 13:18:16 -0500 X-MC-Unique: kF07KXLyNimRWKg7kCHZxA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 220C71006AA3; Wed, 2 Feb 2022 18:18:15 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id C05747744F; Wed, 2 Feb 2022 18:18:14 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com Subject: [PATCH 1/5] KVM: x86: use static_call_cond for optional callbacks Date: Wed, 2 Feb 2022 13:18:09 -0500 Message-Id: <20220202181813.1103496-2-pbonzini@redhat.com> In-Reply-To: <20220202181813.1103496-1-pbonzini@redhat.com> References: <20220202181813.1103496-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" SVM implements neither update_emulated_instruction nor set_apic_access_page_addr. Remove an "if" by calling them with static_call_cond(). Signed-off-by: Paolo Bonzini --- arch/x86/kvm/x86.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 862d654caedf..a527cffd0a2b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8421,8 +8421,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gp= a_t cr2_or_gpa, kvm_rip_write(vcpu, ctxt->eip); if (r && (ctxt->tf || (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP))) r =3D kvm_vcpu_do_singlestep(vcpu); - if (kvm_x86_ops.update_emulated_instruction) - static_call(kvm_x86_update_emulated_instruction)(vcpu); + static_call_cond(kvm_x86_update_emulated_instruction)(vcpu); __kvm_set_rflags(vcpu, ctxt->eflags); } =20 @@ -9838,10 +9837,7 @@ static void kvm_vcpu_reload_apic_access_page(struct = kvm_vcpu *vcpu) if (!lapic_in_kernel(vcpu)) return; =20 - if (!kvm_x86_ops.set_apic_access_page_addr) - return; - - static_call(kvm_x86_set_apic_access_page_addr)(vcpu); + static_call_cond(kvm_x86_set_apic_access_page_addr)(vcpu); } =20 void __kvm_request_immediate_exit(struct kvm_vcpu *vcpu) --=20 2.31.1 From nobody Mon Jun 29 21:05:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88685C433EF for ; Wed, 2 Feb 2022 18:18:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346596AbiBBSS2 (ORCPT ); Wed, 2 Feb 2022 13:18:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48161 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346446AbiBBSSU (ORCPT ); Wed, 2 Feb 2022 13:18:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643825899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Km7sFont8AeGrnOT2/QC+/8Ywtf1kDR067FynIPPUaY=; b=CbYztZtv5sruBpRDTbM7UREQatgGx1rSjaynD9CEXzOtaOuuc1wesOzuZv+AO6nc8WGpdP f/E0uBfB2dQCmq7d/7/cPBdM5jMQL9Kv5R46jhnTfG0yPe8aFy7QsadYrRegS8/cCRJyez 1kkaKJmwO1K4Bsc9dcyMSQSNF/E4kNI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-499-I9vHjKyDMgaYYlyQWf87jA-1; Wed, 02 Feb 2022 13:18:16 -0500 X-MC-Unique: I9vHjKyDMgaYYlyQWf87jA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A3080112F980; Wed, 2 Feb 2022 18:18:15 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CD297745C; Wed, 2 Feb 2022 18:18:15 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com Subject: [PATCH 2/5] KVM: x86: mark NULL-able kvm_x86_ops Date: Wed, 2 Feb 2022 13:18:10 -0500 Message-Id: <20220202181813.1103496-3-pbonzini@redhat.com> In-Reply-To: <20220202181813.1103496-1-pbonzini@redhat.com> References: <20220202181813.1103496-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The original use of KVM_X86_OP_NULL, which was to mark calls that do not follow a specific naming convention, is not in use anymore. Repurpose it to identify calls that are invoked within conditionals or with static_call_cond. Those that are _not_, i.e. those that are defined with KVM_X86_OP, must be defined by both vendor modules or some kind of NULL pointer dereference is bound to happen at runtime. In the case of apicv_post_status_restore, rather than changing the kvm-x86-ops.h declaration, I decided to use static_call_cond; there's no absolute requirement for vendor modules to support APIC virtualization. Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/kvm-x86-ops.h | 30 ++++++++++++++---------------- arch/x86/kvm/lapic.c | 4 ++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-= x86-ops.h index 9e37dc3d8863..a842f10f5778 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -6,16 +6,14 @@ BUILD_BUG_ON(1) /* * KVM_X86_OP() and KVM_X86_OP_NULL() are used to help generate * "static_call()"s. They are also intended for use when defining - * the vmx/svm kvm_x86_ops. KVM_X86_OP() can be used for those - * functions that follow the [svm|vmx]_func_name convention. - * KVM_X86_OP_NULL() can leave a NULL definition for the - * case where there is no definition or a function name that - * doesn't match the typical naming convention is supplied. + * the vmx/svm kvm_x86_ops. KVM_X86_OP_NULL() can be used for those + * functions that can have a NULL definition, for example if + * "static_call_cond()" will be used at the call sites. */ -KVM_X86_OP_NULL(hardware_enable) -KVM_X86_OP_NULL(hardware_disable) -KVM_X86_OP_NULL(hardware_unsetup) -KVM_X86_OP_NULL(cpu_has_accelerated_tpr) +KVM_X86_OP(hardware_enable) +KVM_X86_OP(hardware_disable) +KVM_X86_OP(hardware_unsetup) +KVM_X86_OP(cpu_has_accelerated_tpr) KVM_X86_OP(has_emulated_msr) KVM_X86_OP(vcpu_after_set_cpuid) KVM_X86_OP(vm_init) @@ -33,7 +31,7 @@ KVM_X86_OP(get_segment_base) KVM_X86_OP(get_segment) KVM_X86_OP(get_cpl) KVM_X86_OP(set_segment) -KVM_X86_OP_NULL(get_cs_db_l_bits) +KVM_X86_OP(get_cs_db_l_bits) KVM_X86_OP(set_cr0) KVM_X86_OP_NULL(post_set_cr3) KVM_X86_OP(is_valid_cr4) @@ -57,8 +55,8 @@ KVM_X86_OP(flush_tlb_gva) KVM_X86_OP(flush_tlb_guest) KVM_X86_OP(vcpu_pre_run) KVM_X86_OP(vcpu_run) -KVM_X86_OP_NULL(handle_exit) -KVM_X86_OP_NULL(skip_emulated_instruction) +KVM_X86_OP(handle_exit) +KVM_X86_OP(skip_emulated_instruction) KVM_X86_OP_NULL(update_emulated_instruction) KVM_X86_OP(set_interrupt_shadow) KVM_X86_OP(get_interrupt_shadow) @@ -73,7 +71,7 @@ KVM_X86_OP(get_nmi_mask) KVM_X86_OP(set_nmi_mask) KVM_X86_OP(enable_nmi_window) KVM_X86_OP(enable_irq_window) -KVM_X86_OP(update_cr8_intercept) +KVM_X86_OP_NULL(update_cr8_intercept) KVM_X86_OP(check_apicv_inhibit_reasons) KVM_X86_OP(refresh_apicv_exec_ctrl) KVM_X86_OP(hwapic_irr_update) @@ -88,7 +86,7 @@ KVM_X86_OP(set_tss_addr) KVM_X86_OP(set_identity_map_addr) KVM_X86_OP(get_mt_mask) KVM_X86_OP(load_mmu_pgd) -KVM_X86_OP_NULL(has_wbinvd_exit) +KVM_X86_OP(has_wbinvd_exit) KVM_X86_OP(get_l2_tsc_offset) KVM_X86_OP(get_l2_tsc_multiplier) KVM_X86_OP(write_tsc_offset) @@ -96,7 +94,7 @@ KVM_X86_OP(write_tsc_multiplier) KVM_X86_OP(get_exit_info) KVM_X86_OP(check_intercept) KVM_X86_OP(handle_exit_irqoff) -KVM_X86_OP_NULL(request_immediate_exit) +KVM_X86_OP(request_immediate_exit) KVM_X86_OP(sched_in) KVM_X86_OP_NULL(update_cpu_dirty_logging) KVM_X86_OP_NULL(vcpu_blocking) @@ -123,7 +121,7 @@ KVM_X86_OP(apic_init_signal_blocked) KVM_X86_OP_NULL(enable_direct_tlbflush) KVM_X86_OP_NULL(migrate_timers) KVM_X86_OP(msr_filter_changed) -KVM_X86_OP_NULL(complete_emulated_msr) +KVM_X86_OP(complete_emulated_msr) KVM_X86_OP(vcpu_deliver_sipi_vector) =20 #undef KVM_X86_OP diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 0da7d0960fcb..09bbb6a01c1d 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2369,7 +2369,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init= _event) vcpu->arch.pv_eoi.msr_val =3D 0; apic_update_ppr(apic); if (vcpu->arch.apicv_active) { - static_call(kvm_x86_apicv_post_state_restore)(vcpu); + static_call_cond(kvm_x86_apicv_post_state_restore)(vcpu); static_call(kvm_x86_hwapic_irr_update)(vcpu, -1); static_call(kvm_x86_hwapic_isr_update)(vcpu, -1); } @@ -2634,7 +2634,7 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct = kvm_lapic_state *s) kvm_apic_update_apicv(vcpu); apic->highest_isr_cache =3D -1; if (vcpu->arch.apicv_active) { - static_call(kvm_x86_apicv_post_state_restore)(vcpu); + static_call_cond(kvm_x86_apicv_post_state_restore)(vcpu); static_call(kvm_x86_hwapic_irr_update)(vcpu, apic_find_highest_irr(apic)); static_call(kvm_x86_hwapic_isr_update)(vcpu, --=20 2.31.1 From nobody Mon Jun 29 21:05:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8EB4C433F5 for ; Wed, 2 Feb 2022 18:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346578AbiBBSSW (ORCPT ); Wed, 2 Feb 2022 13:18:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42800 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242423AbiBBSSS (ORCPT ); Wed, 2 Feb 2022 13:18:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643825898; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BDwDrTJibr0ixLq4IwTrhHp/x9KXkNMTG4kmC+Qy0og=; b=JH1ZdcP/MaIF3mza0dHux/tld3s9NIv85hZN5vFLLVK86HybHmPOCRIJK3AhG07ZRE9RlB nf01ejp3XqTUZJQ5KkcSgFFvkGHF+894wz4ANfXeVdd/vpCMEeuKsVimkVPr5//XBgx6rl krqF4hEQQbrJQLFiT7aUow35zunW8hg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-210-UcQvy9JTOwCeUo0EFRFVkQ-1; Wed, 02 Feb 2022 13:18:17 -0500 X-MC-Unique: UcQvy9JTOwCeUo0EFRFVkQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 21647180FD60; Wed, 2 Feb 2022 18:18:16 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFC567744F; Wed, 2 Feb 2022 18:18:15 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com Subject: [PATCH 3/5] KVM: x86: warn on incorrectly NULL static calls Date: Wed, 2 Feb 2022 13:18:11 -0500 Message-Id: <20220202181813.1103496-4-pbonzini@redhat.com> In-Reply-To: <20220202181813.1103496-1-pbonzini@redhat.com> References: <20220202181813.1103496-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the newly corrected KVM_X86_OP annotations to warn about possible NULL pointer dereferences as soon as the vendor module is loaded. Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/kvm_host.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index c371ee7e45f7..61faeb57889c 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1544,9 +1544,10 @@ extern struct kvm_x86_ops kvm_x86_ops; =20 static inline void kvm_ops_static_call_update(void) { -#define KVM_X86_OP(func) \ +#define KVM_X86_OP_NULL(func) \ static_call_update(kvm_x86_##func, kvm_x86_ops.func); -#define KVM_X86_OP_NULL KVM_X86_OP +#define KVM_X86_OP(func) \ + WARN_ON(!kvm_x86_ops.func); KVM_X86_OP_NULL(func) #include } =20 --=20 2.31.1 From nobody Mon Jun 29 21:05:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8071AC433F5 for ; Wed, 2 Feb 2022 18:18:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346620AbiBBSSa (ORCPT ); Wed, 2 Feb 2022 13:18:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46315 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346559AbiBBSSV (ORCPT ); Wed, 2 Feb 2022 13:18:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643825900; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EfsD89RXkHNrOo3rdM2WwXKnhzWTYXgov/7DgzmxMHk=; b=P+KKlIg5DCTtL0+X0AHMgj4ijkx7E8eGL7YlM8APWLHw/CmEO/Q0Sc/K0OqwcNkkJNiPY5 mKUGn6fe56ZiC8wBT5g/Dj+Qv96ws5YDCC1WUU3acdhuKslovfu0GK/wGTj5dIvH/mgyds RdpUJW7M0j+sziY5Z3a4VEuplwsGaGc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-282-WiEVCwneMGS54nEoUOwXMg-1; Wed, 02 Feb 2022 13:18:17 -0500 X-MC-Unique: WiEVCwneMGS54nEoUOwXMg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9DEA1180FD62; Wed, 2 Feb 2022 18:18:16 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E1E87745F; Wed, 2 Feb 2022 18:18:16 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com Subject: [PATCH 4/5] KVM: x86: change hwapic_{irr,isr}_update to NULLable calls Date: Wed, 2 Feb 2022 13:18:12 -0500 Message-Id: <20220202181813.1103496-5-pbonzini@redhat.com> In-Reply-To: <20220202181813.1103496-1-pbonzini@redhat.com> References: <20220202181813.1103496-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" SVM does not need them, so mark them as optional. Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/kvm-x86-ops.h | 4 ++-- arch/x86/kvm/lapic.c | 18 +++++++----------- arch/x86/kvm/svm/avic.c | 8 -------- arch/x86/kvm/svm/svm.c | 2 -- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-= x86-ops.h index a842f10f5778..843bd9efd2ae 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -74,8 +74,8 @@ KVM_X86_OP(enable_irq_window) KVM_X86_OP_NULL(update_cr8_intercept) KVM_X86_OP(check_apicv_inhibit_reasons) KVM_X86_OP(refresh_apicv_exec_ctrl) -KVM_X86_OP(hwapic_irr_update) -KVM_X86_OP(hwapic_isr_update) +KVM_X86_OP_NULL(hwapic_irr_update) +KVM_X86_OP_NULL(hwapic_isr_update) KVM_X86_OP_NULL(guest_apic_has_interrupt) KVM_X86_OP(load_eoi_exitmap) KVM_X86_OP(set_virtual_apic_mode) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 09bbb6a01c1d..fd10dd070d26 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -492,8 +492,7 @@ static inline void apic_clear_irr(int vec, struct kvm_l= apic *apic) if (unlikely(vcpu->arch.apicv_active)) { /* need to update RVI */ kvm_lapic_clear_vector(vec, apic->regs + APIC_IRR); - static_call(kvm_x86_hwapic_irr_update)(vcpu, - apic_find_highest_irr(apic)); + static_call_cond(kvm_x86_hwapic_irr_update)(vcpu, apic_find_highest_irr(= apic)); } else { apic->irr_pending =3D false; kvm_lapic_clear_vector(vec, apic->regs + APIC_IRR); @@ -523,7 +522,7 @@ static inline void apic_set_isr(int vec, struct kvm_lap= ic *apic) * just set SVI. */ if (unlikely(vcpu->arch.apicv_active)) - static_call(kvm_x86_hwapic_isr_update)(vcpu, vec); + static_call_cond(kvm_x86_hwapic_isr_update)(vcpu, vec); else { ++apic->isr_count; BUG_ON(apic->isr_count > MAX_APIC_VECTOR); @@ -571,8 +570,7 @@ static inline void apic_clear_isr(int vec, struct kvm_l= apic *apic) * and must be left alone. */ if (unlikely(vcpu->arch.apicv_active)) - static_call(kvm_x86_hwapic_isr_update)(vcpu, - apic_find_highest_isr(apic)); + static_call_cond(kvm_x86_hwapic_isr_update)(vcpu, apic_find_highest_isr(= apic)); else { --apic->isr_count; BUG_ON(apic->isr_count < 0); @@ -2370,8 +2368,8 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init= _event) apic_update_ppr(apic); if (vcpu->arch.apicv_active) { static_call_cond(kvm_x86_apicv_post_state_restore)(vcpu); - static_call(kvm_x86_hwapic_irr_update)(vcpu, -1); - static_call(kvm_x86_hwapic_isr_update)(vcpu, -1); + static_call_cond(kvm_x86_hwapic_irr_update)(vcpu, -1); + static_call_cond(kvm_x86_hwapic_isr_update)(vcpu, -1); } =20 vcpu->arch.apic_arb_prio =3D 0; @@ -2635,10 +2633,8 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct= kvm_lapic_state *s) apic->highest_isr_cache =3D -1; if (vcpu->arch.apicv_active) { static_call_cond(kvm_x86_apicv_post_state_restore)(vcpu); - static_call(kvm_x86_hwapic_irr_update)(vcpu, - apic_find_highest_irr(apic)); - static_call(kvm_x86_hwapic_isr_update)(vcpu, - apic_find_highest_isr(apic)); + static_call_cond(kvm_x86_hwapic_irr_update)(vcpu, apic_find_highest_irr(= apic)); + static_call_cond(kvm_x86_hwapic_isr_update)(vcpu, apic_find_highest_isr(= apic)); } kvm_make_request(KVM_REQ_EVENT, vcpu); if (ioapic_in_kernel(vcpu->kvm)) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 99f907ec5aa8..b49ee6f34fe7 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -592,14 +592,6 @@ void avic_set_virtual_apic_mode(struct kvm_vcpu *vcpu) return; } =20 -void avic_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr) -{ -} - -void avic_hwapic_isr_update(struct kvm_vcpu *vcpu, int max_isr) -{ -} - static int avic_set_pi_irte_mode(struct kvm_vcpu *vcpu, bool activate) { int ret =3D 0; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 7f70f456a5a5..ab50d73b1e2e 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4540,8 +4540,6 @@ static struct kvm_x86_ops svm_x86_ops __initdata =3D { .refresh_apicv_exec_ctrl =3D avic_refresh_apicv_exec_ctrl, .check_apicv_inhibit_reasons =3D avic_check_apicv_inhibit_reasons, .load_eoi_exitmap =3D avic_load_eoi_exitmap, - .hwapic_irr_update =3D avic_hwapic_irr_update, - .hwapic_isr_update =3D avic_hwapic_isr_update, .apicv_post_state_restore =3D avic_apicv_post_state_restore, =20 .set_tss_addr =3D svm_set_tss_addr, --=20 2.31.1 From nobody Mon Jun 29 21:05:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E4DDC433FE for ; Wed, 2 Feb 2022 18:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346643AbiBBSSc (ORCPT ); Wed, 2 Feb 2022 13:18:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44613 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346563AbiBBSSV (ORCPT ); Wed, 2 Feb 2022 13:18:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643825901; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HCkmVYi4zqDPYm75x/aIL8dnazRAyGfaINH0ttQQ4CU=; b=CNPZfnpKDCF5LQeEaglsrWuYvyAd03aqqEcpntKCOOKdota5+LX8VctEHCU+6BwOKI1YwL GtL7aa4YuY0X1COwLUK9ZqQv7x6vlogiKD+Qe4GO9Z3OYal8M9IPXmW/RP0LNyXl9c2rwC QxtNDvqcTSCY5BM++Bqvzoi4f7RAZkE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-356-oxKSJTTWM8yqPx13UbJ2Eg-1; Wed, 02 Feb 2022 13:18:18 -0500 X-MC-Unique: oxKSJTTWM8yqPx13UbJ2Eg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31931835B4B; Wed, 2 Feb 2022 18:18:17 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0C727744F; Wed, 2 Feb 2022 18:18:16 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com Subject: [PATCH 5/5] KVM: x86: allow defining return-0 static calls Date: Wed, 2 Feb 2022 13:18:13 -0500 Message-Id: <20220202181813.1103496-6-pbonzini@redhat.com> In-Reply-To: <20220202181813.1103496-1-pbonzini@redhat.com> References: <20220202181813.1103496-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" A few vendor callbacks are only used by VMX, but they return an integer or bool value. Introduce KVM_X86_OP_RET0 for them: a NULL value in struct kvm_x86_ops will be changed to __static_call_return0. Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/kvm-x86-ops.h | 13 +++++++------ arch/x86/include/asm/kvm_host.h | 4 ++++ arch/x86/kvm/svm/avic.c | 5 ----- arch/x86/kvm/svm/svm.c | 26 -------------------------- arch/x86/kvm/x86.c | 2 +- 5 files changed, 12 insertions(+), 38 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-= x86-ops.h index 843bd9efd2ae..89fa5dd21f34 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -13,7 +13,7 @@ BUILD_BUG_ON(1) KVM_X86_OP(hardware_enable) KVM_X86_OP(hardware_disable) KVM_X86_OP(hardware_unsetup) -KVM_X86_OP(cpu_has_accelerated_tpr) +KVM_X86_OP_RET0(cpu_has_accelerated_tpr) KVM_X86_OP(has_emulated_msr) KVM_X86_OP(vcpu_after_set_cpuid) KVM_X86_OP(vm_init) @@ -76,15 +76,15 @@ KVM_X86_OP(check_apicv_inhibit_reasons) KVM_X86_OP(refresh_apicv_exec_ctrl) KVM_X86_OP_NULL(hwapic_irr_update) KVM_X86_OP_NULL(hwapic_isr_update) -KVM_X86_OP_NULL(guest_apic_has_interrupt) +KVM_X86_OP_RET0(guest_apic_has_interrupt) KVM_X86_OP(load_eoi_exitmap) KVM_X86_OP(set_virtual_apic_mode) KVM_X86_OP_NULL(set_apic_access_page_addr) KVM_X86_OP(deliver_interrupt) KVM_X86_OP_NULL(sync_pir_to_irr) -KVM_X86_OP(set_tss_addr) -KVM_X86_OP(set_identity_map_addr) -KVM_X86_OP(get_mt_mask) +KVM_X86_OP_RET0(set_tss_addr) +KVM_X86_OP_RET0(set_identity_map_addr) +KVM_X86_OP_RET0(get_mt_mask) KVM_X86_OP(load_mmu_pgd) KVM_X86_OP(has_wbinvd_exit) KVM_X86_OP(get_l2_tsc_offset) @@ -102,7 +102,7 @@ KVM_X86_OP_NULL(vcpu_unblocking) KVM_X86_OP_NULL(pi_update_irte) KVM_X86_OP_NULL(pi_start_assignment) KVM_X86_OP_NULL(apicv_post_state_restore) -KVM_X86_OP_NULL(dy_apicv_has_pending_interrupt) +KVM_X86_OP_RET0(dy_apicv_has_pending_interrupt) KVM_X86_OP_NULL(set_hv_timer) KVM_X86_OP_NULL(cancel_hv_timer) KVM_X86_OP(setup_mce) @@ -126,3 +126,4 @@ KVM_X86_OP(vcpu_deliver_sipi_vector) =20 #undef KVM_X86_OP #undef KVM_X86_OP_NULL +#undef KVM_X86_OP_RET0 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 61faeb57889c..e7e5bd9a984d 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1540,6 +1540,7 @@ extern struct kvm_x86_ops kvm_x86_ops; #define KVM_X86_OP(func) \ DECLARE_STATIC_CALL(kvm_x86_##func, *(((struct kvm_x86_ops *)0)->func)); #define KVM_X86_OP_NULL KVM_X86_OP +#define KVM_X86_OP_RET0 KVM_X86_OP #include =20 static inline void kvm_ops_static_call_update(void) @@ -1548,6 +1549,9 @@ static inline void kvm_ops_static_call_update(void) static_call_update(kvm_x86_##func, kvm_x86_ops.func); #define KVM_X86_OP(func) \ WARN_ON(!kvm_x86_ops.func); KVM_X86_OP_NULL(func) +#define KVM_X86_OP_RET0(func) \ + static_call_update(kvm_x86_##func, kvm_x86_ops.func ? : \ + (typeof(kvm_x86_ops.func)) __static_call_return0); #include } =20 diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index b49ee6f34fe7..c82457793fc8 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -707,11 +707,6 @@ int svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int v= ec) return 0; } =20 -bool avic_dy_apicv_has_pending_interrupt(struct kvm_vcpu *vcpu) -{ - return false; -} - static void svm_ir_list_del(struct vcpu_svm *svm, struct amd_iommu_pi_data= *pi) { unsigned long flags; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index ab50d73b1e2e..5f75f50b861c 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3479,16 +3479,6 @@ static void svm_enable_nmi_window(struct kvm_vcpu *v= cpu) svm->vmcb->save.rflags |=3D (X86_EFLAGS_TF | X86_EFLAGS_RF); } =20 -static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr) -{ - return 0; -} - -static int svm_set_identity_map_addr(struct kvm *kvm, u64 ident_addr) -{ - return 0; -} - static void svm_flush_tlb_current(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm =3D to_svm(vcpu); @@ -3863,11 +3853,6 @@ static int __init svm_check_processor_compat(void) return 0; } =20 -static bool svm_cpu_has_accelerated_tpr(void) -{ - return false; -} - /* * The kvm parameter can be NULL (module initialization, or invocation bef= ore * VM creation). Be sure to check the kvm parameter before using it. @@ -3890,11 +3875,6 @@ static bool svm_has_emulated_msr(struct kvm *kvm, u3= 2 index) return true; } =20 -static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) -{ - return 0; -} - static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm =3D to_svm(vcpu); @@ -4470,7 +4450,6 @@ static struct kvm_x86_ops svm_x86_ops __initdata =3D { .hardware_unsetup =3D svm_hardware_unsetup, .hardware_enable =3D svm_hardware_enable, .hardware_disable =3D svm_hardware_disable, - .cpu_has_accelerated_tpr =3D svm_cpu_has_accelerated_tpr, .has_emulated_msr =3D svm_has_emulated_msr, =20 .vcpu_create =3D svm_vcpu_create, @@ -4542,10 +4521,6 @@ static struct kvm_x86_ops svm_x86_ops __initdata =3D= { .load_eoi_exitmap =3D avic_load_eoi_exitmap, .apicv_post_state_restore =3D avic_apicv_post_state_restore, =20 - .set_tss_addr =3D svm_set_tss_addr, - .set_identity_map_addr =3D svm_set_identity_map_addr, - .get_mt_mask =3D svm_get_mt_mask, - .get_exit_info =3D svm_get_exit_info, =20 .vcpu_after_set_cpuid =3D svm_vcpu_after_set_cpuid, @@ -4570,7 +4545,6 @@ static struct kvm_x86_ops svm_x86_ops __initdata =3D { .nested_ops =3D &svm_nested_ops, =20 .deliver_interrupt =3D svm_deliver_interrupt, - .dy_apicv_has_pending_interrupt =3D avic_dy_apicv_has_pending_interrupt, .pi_update_irte =3D avic_pi_update_irte, .setup_mce =3D svm_setup_mce, =20 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a527cffd0a2b..2daca3dd128a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -129,6 +129,7 @@ struct kvm_x86_ops kvm_x86_ops __read_mostly; DEFINE_STATIC_CALL_NULL(kvm_x86_##func, \ *(((struct kvm_x86_ops *)0)->func)); #define KVM_X86_OP_NULL KVM_X86_OP +#define KVM_X86_OP_RET0 KVM_X86_OP #include EXPORT_STATIC_CALL_GPL(kvm_x86_get_cs_db_l_bits); EXPORT_STATIC_CALL_GPL(kvm_x86_cache_reg); @@ -12057,7 +12058,6 @@ void kvm_arch_flush_shadow_memslot(struct kvm *kvm, static inline bool kvm_guest_apic_has_interrupt(struct kvm_vcpu *vcpu) { return (is_guest_mode(vcpu) && - kvm_x86_ops.guest_apic_has_interrupt && static_call(kvm_x86_guest_apic_has_interrupt)(vcpu)); } =20 --=20 2.31.1