From nobody Mon Apr 27 09:13:37 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 CD2D6C433EF for ; Tue, 14 Jun 2022 23:05:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357812AbiFNXF4 (ORCPT ); Tue, 14 Jun 2022 19:05:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344435AbiFNXFx (ORCPT ); Tue, 14 Jun 2022 19:05:53 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F03644C79C for ; Tue, 14 Jun 2022 16:05:52 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id y1-20020a17090a390100b001e66bb0fcefso264577pjb.0 for ; Tue, 14 Jun 2022 16:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=3d7tD77H5O2xlb02j7y43iDUfTOkQ/XeZFOmeDGAico=; b=tR5DLGM9/pa1X/VPkRpGjyP5Rnk93Bm7RSfQjLOY2sNbFAo4+DUaz+VhvYZeMv15+l ZMimhzuqcXRgXz1jmiLiyGAPdYLgvUT9AZRNWYSojENt4OH8Ir7O8632yquqN7j5OGpF UVDHGhnmxG69JwO74Q940WYXAHK52i9UA9N4f7CemEYZ2TWpxckxki/9n5NOaOKItMMO Be5B++qiW36YDr3SUpquYrUQwJRG5EUW8QPW/21fca1JPEt2QVlTjuQj8gWTiDoFThPL ConxYO/fY73tlZP6GfjZOM2rczcqOMOENFX5uGvuqoA6PVzMLG/3y1Ni9/q5OOXq4bNj 9cpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=3d7tD77H5O2xlb02j7y43iDUfTOkQ/XeZFOmeDGAico=; b=C3YiWJLi+S7CoFi1QOHyvHV+4jVJseFw0lKlJHrKpBuJu4WLquupqPD48XO+VDyVUs XK63c7AnPynmMzB3X8HaXK9eaheAsjKfYbGZADYrhSISGn8C7xPiZYxmx6HD4XeLhZ2p yF5lYAQO64MNor8hzKEACxcVM5OBaQbjsJVUOxyyFnJYmC6PRbsRou/VhPuB0z5m1OX1 ttlhpGwQy0TaeaH0QtMzj0FAaWIDonnOMdO0tlr8jftIpfmmPkdw7Jf25wlHb6i0yWyQ tsPrgWOLhPDCW4ujDF3NLEoy9KLHoCT1gK/9VUtKTjVw1ImPZTWf5aO3GUT0z9h/GxCb 045Q== X-Gm-Message-State: AJIora+i0atxpQNlCdEHyh21KXS7T/cL0GFngoGD9PeFBy40bSBiECsK LpEDokNdK8Z/WprnOLa9pY6EXq5bHnA= X-Google-Smtp-Source: AGRyM1tnSW/muwqIZhXYnOKJRS3lRWAomzqILjlJIGjgy36gfPaXSzFNyMBMb/S1SX6iVfNJDsd8fuf8hhY= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:db0a:b0:165:1299:29ea with SMTP id m10-20020a170902db0a00b00165129929eamr6314130plx.15.1655247952491; Tue, 14 Jun 2022 16:05:52 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 23:05:44 +0000 In-Reply-To: <20220614230548.3852141-1-seanjc@google.com> Message-Id: <20220614230548.3852141-2-seanjc@google.com> Mime-Version: 1.0 References: <20220614230548.3852141-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH 1/5] KVM: SVM: Drop unused AVIC / kvm_x86_ops declarations From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop a handful of unused AVIC function declarations whose implementations were removed during the conversion to optional static calls. No functional change intended. Fixes: abb6d479e226 ("KVM: x86: make several APIC virtualization callbacks = optional") Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 128993feb4c6..d51de3c9264a 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -617,12 +617,8 @@ int avic_init_vcpu(struct vcpu_svm *svm); void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu); void avic_vcpu_put(struct kvm_vcpu *vcpu); void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu); -void avic_set_virtual_apic_mode(struct kvm_vcpu *vcpu); void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu); bool avic_check_apicv_inhibit_reasons(enum kvm_apicv_inhibit reason); -void avic_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr); -void avic_hwapic_isr_update(struct kvm_vcpu *vcpu, int max_isr); -bool avic_dy_apicv_has_pending_interrupt(struct kvm_vcpu *vcpu); int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, bool set); void avic_vcpu_blocking(struct kvm_vcpu *vcpu); --=20 2.36.1.476.g0c4daa206d-goog From nobody Mon Apr 27 09:13:37 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 41663C43334 for ; Tue, 14 Jun 2022 23:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357931AbiFNXGA (ORCPT ); Tue, 14 Jun 2022 19:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241086AbiFNXF4 (ORCPT ); Tue, 14 Jun 2022 19:05:56 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A26850B22 for ; Tue, 14 Jun 2022 16:05:55 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-313aa142909so37914327b3.5 for ; Tue, 14 Jun 2022 16:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=Q0TMDImt0VZIwoPHETcXPRYJP1DNJYILBSqC8/vVqok=; b=ta6l7+kTFeFE/qN7zdZPFqpwGtgLYrdwSjJiqgmRnVFGTXIyVpPzxGcSXf253gMO7n 4fSoAa8H20nrv07KWry3VP/e9oSBkHFnbT3PyD8Z7VNdux8gstqBWuLrOhnUnvJLNDf4 61M1JwCnBvS49Zj2Vy/t/B/uc/DAu/c0ODC/nVk//TseedPRU8rhEf5GAjBhfHYs0Psk 1MalQWgrLMaeXWGvM4PWLU8rABpXuZM0O1zOm/X6vNIhE7zrwIwzYL6t9txu+lJJR9x+ Ne2s/UebFJLUGrDjnbKniKsBmu6o0CtqRkijJvUQCMcBjtrIpkpNyaejSBC261h7X0WZ GLHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=Q0TMDImt0VZIwoPHETcXPRYJP1DNJYILBSqC8/vVqok=; b=IB2D50XWp1OJSKlaLlqnT2DWSbMlVgzf1xBDiF+eET7JnpjhxjVLURVTAPXGQSFlRN fFJO/zVtDT3wSOYGHFj/lwtCmMizKVZ3YBWhQfIPUNSSwRDvTExV6WFlGSvhfGT2LSrU aFm/lh4RdqGSYl2AQLUZ63gEL0zHCzx1jB2kB6yz1BI0TMz50+snO8Re4GugwajvHAK6 gLAqqrr61jpR8nvppkaq8czFC4uYHWO9rJ7y15RIxhtTaQ1/hi6kbDLrIoR7jZ5iGR3s JKXBbm+KXwVKg6/8B7QXwF0iP9jbc91f+IL/ZerfR8F1g+Uk/7b4FNu9i+Z3ixssuB/O qHwQ== X-Gm-Message-State: AJIora8Aa+R075qi/ff5G1Y7UU05xOn8ssLLespQ179+qvKfo54P+RDY yX+nbeh29t5OwM2g0AC8aPwFsYcvGlE= X-Google-Smtp-Source: AGRyM1t82T1S2GRktx74IasIBtL1fM8tTA7F1HMXvd4jCUMFFB76wqNkMJJXE1FLGKmcV6+LqgVfC7FVpi4= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a81:10cf:0:b0:313:aa13:ed0a with SMTP id 198-20020a8110cf000000b00313aa13ed0amr8678346ywq.40.1655247954233; Tue, 14 Jun 2022 16:05:54 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 23:05:45 +0000 In-Reply-To: <20220614230548.3852141-1-seanjc@google.com> Message-Id: <20220614230548.3852141-3-seanjc@google.com> Mime-Version: 1.0 References: <20220614230548.3852141-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH 2/5] KVM: x86: Drop @vcpu parameter from kvm_x86_ops.hwapic_isr_update() From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop the unused @vcpu parameter from hwapic_isr_update(). AMD/AVIC is unlikely to implement the helper, and VMX/APICv doesn't need the vCPU as it operates on the current VMCS. The result is somewhat odd, but allows for a decent amount of (future) cleanup in the APIC code. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/lapic.c | 8 ++++---- arch/x86/kvm/vmx/vmx.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 7e98b2876380..16acc54d49a7 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1517,7 +1517,7 @@ struct kvm_x86_ops { bool (*check_apicv_inhibit_reasons)(enum kvm_apicv_inhibit reason); void (*refresh_apicv_exec_ctrl)(struct kvm_vcpu *vcpu); void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr); - void (*hwapic_isr_update)(struct kvm_vcpu *vcpu, int isr); + void (*hwapic_isr_update)(int isr); bool (*guest_apic_has_interrupt)(struct kvm_vcpu *vcpu); void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap); void (*set_virtual_apic_mode)(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index a413a1d8df4c..cc0da5671eb9 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -556,7 +556,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_cond(kvm_x86_hwapic_isr_update)(vcpu, vec); + static_call_cond(kvm_x86_hwapic_isr_update)(vec); else { ++apic->isr_count; BUG_ON(apic->isr_count > MAX_APIC_VECTOR); @@ -604,7 +604,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_cond(kvm_x86_hwapic_isr_update)(vcpu, apic_find_highest_isr(= apic)); + static_call_cond(kvm_x86_hwapic_isr_update)(apic_find_highest_isr(apic)); else { --apic->isr_count; BUG_ON(apic->isr_count < 0); @@ -2457,7 +2457,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init= _event) if (vcpu->arch.apicv_active) { static_call_cond(kvm_x86_apicv_post_state_restore)(vcpu); static_call_cond(kvm_x86_hwapic_irr_update)(vcpu, -1); - static_call_cond(kvm_x86_hwapic_isr_update)(vcpu, -1); + static_call_cond(kvm_x86_hwapic_isr_update)(-1); } =20 vcpu->arch.apic_arb_prio =3D 0; @@ -2737,7 +2737,7 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct = kvm_lapic_state *s) if (vcpu->arch.apicv_active) { static_call_cond(kvm_x86_apicv_post_state_restore)(vcpu); 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)); + static_call_cond(kvm_x86_hwapic_isr_update)(apic_find_highest_isr(apic)); } kvm_make_request(KVM_REQ_EVENT, vcpu); if (ioapic_in_kernel(vcpu->kvm)) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 5e14e4c40007..42f8924a90f4 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6556,7 +6556,7 @@ static void vmx_set_apic_access_page_addr(struct kvm_= vcpu *vcpu) put_page(page); } =20 -static void vmx_hwapic_isr_update(struct kvm_vcpu *vcpu, int max_isr) +static void vmx_hwapic_isr_update(int max_isr) { u16 status; u8 old; --=20 2.36.1.476.g0c4daa206d-goog From nobody Mon Apr 27 09:13:37 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 CE045C43334 for ; Tue, 14 Jun 2022 23:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357845AbiFNXGD (ORCPT ); Tue, 14 Jun 2022 19:06:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357981AbiFNXF5 (ORCPT ); Tue, 14 Jun 2022 19:05:57 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72AD8532F8 for ; Tue, 14 Jun 2022 16:05:56 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id t11-20020a17090a2f8b00b001ea6a226d21so150637pjd.8 for ; Tue, 14 Jun 2022 16:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=x+rg0+A6Uvzv4O8bM/KpC5UOBIeWkz1gC/gNgA/d0ks=; b=XFTfkEarEGnyykkOT0u0agNc/6QpqWNtnqb9/RKSiEtwGP8BKrXAsWy+hU/1yehVXR oRtT3j15BCcJBCZ3E9ZvxtyMZ9nx1piGZ72rlxNY3o1llI8eC07PMpkX7IWLYduAxS6i 9vqGCNOQaM0MXcyIBc+2s1VoJBK/syksHErOrNe1hMnNWilr1qaEMX1bxiQwuOTn129H wPXbeKnSJlv+QkPh/vBICpkgIARmLgr7itKtSSTm+7HZvDM6UUxbzYaqQPGt78Z33Olk +BAhgpVdLzQG6DBzmMNxPrX/wKOivd0SWleDRfi0MOitmJjxn8my1BMMZlhgRggGufSs 89Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=x+rg0+A6Uvzv4O8bM/KpC5UOBIeWkz1gC/gNgA/d0ks=; b=1hKjrHqKherxUACOUUNmZQzyDEa+XckZFG4WbyN69kwqFRtxzfrsgzqfQw5JFxKaAQ fyrFuEQEuH1nZ4UxIYsm/V8/zVAjLMZ0TGGguUItlkwk9GeZoFSufJ+JSx0nwpW6PvgZ t/07TmzfKuIJUIdG8ceZ7en0ym5CPPR+EOj67vZ/uTIgx+Y2eptdkcHhbQpLNWGxyrGw v5BNJ6Mb6zywIAEjK73xytZzGCVGcTSF2iJW/Mll8LPNxhCALn+BitWgWDwUcLQbgabK Zf0uaNIgw4mL0wKrAmtl9lpAXgjZNyqa4cJvHH5O1sd56fwVRdbI//qG78yP1iImgElM TQiA== X-Gm-Message-State: AOAM5336G0Ffxs5FGb0Fd4mXq4Ra76DxAnm7v3Kiv3z8kL22zeqSgp4J L3YU2pwdp7oZsJvSY+8x8CbjDEAlYFk= X-Google-Smtp-Source: ABdhPJy5VbrZHfaAAh6R1wY2dPzoNT6FYr+2b31ONeNPOhZXZdZVHBF4dat+mSDiL0l51ntrw462jxpVsTo= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a62:be14:0:b0:505:a43b:cf6e with SMTP id l20-20020a62be14000000b00505a43bcf6emr7006035pff.33.1655247955887; Tue, 14 Jun 2022 16:05:55 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 23:05:46 +0000 In-Reply-To: <20220614230548.3852141-1-seanjc@google.com> Message-Id: <20220614230548.3852141-4-seanjc@google.com> Mime-Version: 1.0 References: <20220614230548.3852141-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH 3/5] KVM: x86: Check for in-kernel xAPIC when querying APICv for directed yield From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_vcpu_apicv_active() to check if APICv is active when seeing if a vCPU is a candidate for directed yield due to a pending ACPIv interrupt. This will allow moving apicv_active into kvm_lapic without introducing a potential NULL pointer deref (kvm_vcpu_apicv_active() effectively adds a pre-check on the vCPU having an in-kernel APIC). No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2318a99139fa..cd554a62eb0f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12375,7 +12375,8 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu) =20 bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu) { - if (vcpu->arch.apicv_active && static_call(kvm_x86_dy_apicv_has_pending_i= nterrupt)(vcpu)) + if (kvm_vcpu_apicv_active(vcpu) && + static_call(kvm_x86_dy_apicv_has_pending_interrupt)(vcpu)) return true; =20 return false; --=20 2.36.1.476.g0c4daa206d-goog From nobody Mon Apr 27 09:13:37 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 D4D6BC43334 for ; Tue, 14 Jun 2022 23:06:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358335AbiFNXGH (ORCPT ); Tue, 14 Jun 2022 19:06:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358020AbiFNXF7 (ORCPT ); Tue, 14 Jun 2022 19:05:59 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 405C053707 for ; Tue, 14 Jun 2022 16:05:58 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id lw3-20020a17090b180300b001e31fad7d5aso233251pjb.6 for ; Tue, 14 Jun 2022 16:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=KWr09iwAJ/KttgqIlP4t5XmU0ORDiZrVc0OMsoock5w=; b=DHObAgnnQHwa+00TuGwYe7H4vaPoWsux/hV/LYPQtLGYVUQ1+RhtX8gV9ntqANAuq9 G4FNduqGphohOqWcpzK8skDDkHEh0eV1NoVEgTg5NfChJpwmj/r9Bg0h64nUvmwho70J xWL8yHesixCPMH9hG1Gl0ODmE/4rKOuFXH5rRCsfCdJRBEbTxz4LG+vE4FMm1okVmuFg 6UmyoOn+6ot8qPh1HkPqkUxeptz4rlSg89UHhxJRZ6KlwaHjS3v0cb1+2MZyutM7oxMx ttpc1Sc9ejsbJCK3teeJxCXsHzBcOp86wQaxBsPsMZDvehZKyX5L2z/kAUs7e2L7JPpV TL1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=KWr09iwAJ/KttgqIlP4t5XmU0ORDiZrVc0OMsoock5w=; b=rX+KtW6JXMTwZhx0lR7dVwQURap40Ks2dS0FZFeLx3u9nN9Ke6ipwcp9j8xyQwP+iC 2a70wqI4acItIaofh6hweCSfwW0ZZG6DNHOwRmRD6T8QgTnFCiLHq40mNPBvGwf5pZzO j0oHlP6WuHn5blmHXyFn6PW5Ca5E6bvLrmKl/oCeCDWCXmHtykhiI19bw+lLiaZNmuFA qXcvjrjsIlOaNfo3a+aXY8fpJs12+AY+sdmSPKw1DYQor46RRc/r0xrvgCT+SwR5VzUP Lv11MHb34c7R+deLEjWTrrVeZLzI3gg1S6vjCNAlK+Jm6nZSeoLP5qumeu9NgEdA24cz yc3Q== X-Gm-Message-State: AOAM531pW3i2WJsE3CYv+P+l5B5pCtPulQDMlCc8mN5X8keLTwOGy5mB 09uZoiHvoPA6XC7P8oiMwgsN/Hifjk8= X-Google-Smtp-Source: ABdhPJy1xXw/IzHpxrHsb7SF+iyYh7z6yjUME6vryiFL9y5RInArNreeD7KczVr92OuPX+k8YMIa4Ii5icA= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:ec83:b0:168:e5ad:8071 with SMTP id x3-20020a170902ec8300b00168e5ad8071mr6446332plg.102.1655247957748; Tue, 14 Jun 2022 16:05:57 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 23:05:47 +0000 In-Reply-To: <20220614230548.3852141-1-seanjc@google.com> Message-Id: <20220614230548.3852141-5-seanjc@google.com> Mime-Version: 1.0 References: <20220614230548.3852141-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH 4/5] KVM: x86: Move "apicv_active" into "struct kvm_lapic" From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the per-vCPU apicv_active flag into KVM's local APIC instance. APICv is fully dependent on an in-kernel local APIC, but that's not at all clear when reading the current code due to the flag being stored in the generic kvm_vcpu_arch struct. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/lapic.c | 30 ++++++++++-------------------- arch/x86/kvm/lapic.h | 3 ++- arch/x86/kvm/svm/svm.c | 5 +++-- arch/x86/kvm/vmx/vmx.c | 3 ++- arch/x86/kvm/x86.c | 11 ++++++----- 6 files changed, 23 insertions(+), 30 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 16acc54d49a7..1038ccb7056a 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -663,7 +663,6 @@ struct kvm_vcpu_arch { u64 efer; u64 apic_base; struct kvm_lapic *apic; /* kernel irqchip context */ - bool apicv_active; bool load_eoi_exitmap_pending; DECLARE_BITMAP(ioapic_handled_vectors, 256); unsigned long apic_attention; diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index cc0da5671eb9..43c42a580295 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -519,14 +519,11 @@ static inline int apic_find_highest_irr(struct kvm_la= pic *apic) =20 static inline void apic_clear_irr(int vec, struct kvm_lapic *apic) { - struct kvm_vcpu *vcpu; - - vcpu =3D apic->vcpu; - - if (unlikely(vcpu->arch.apicv_active)) { + if (unlikely(apic->apicv_active)) { /* need to update RVI */ kvm_lapic_clear_vector(vec, apic->regs + APIC_IRR); - static_call_cond(kvm_x86_hwapic_irr_update)(vcpu, apic_find_highest_irr(= apic)); + static_call_cond(kvm_x86_hwapic_irr_update)(apic->vcpu, + apic_find_highest_irr(apic)); } else { apic->irr_pending =3D false; kvm_lapic_clear_vector(vec, apic->regs + APIC_IRR); @@ -543,19 +540,15 @@ EXPORT_SYMBOL_GPL(kvm_apic_clear_irr); =20 static inline void apic_set_isr(int vec, struct kvm_lapic *apic) { - struct kvm_vcpu *vcpu; - if (__apic_test_and_set_vector(vec, apic->regs + APIC_ISR)) return; =20 - vcpu =3D apic->vcpu; - /* * With APIC virtualization enabled, all caching is disabled * because the processor can modify ISR under the hood. Instead * just set SVI. */ - if (unlikely(vcpu->arch.apicv_active)) + if (unlikely(apic->apicv_active)) static_call_cond(kvm_x86_hwapic_isr_update)(vec); else { ++apic->isr_count; @@ -590,12 +583,9 @@ static inline int apic_find_highest_isr(struct kvm_lap= ic *apic) =20 static inline void apic_clear_isr(int vec, struct kvm_lapic *apic) { - struct kvm_vcpu *vcpu; if (!__apic_test_and_clear_vector(vec, apic->regs + APIC_ISR)) return; =20 - vcpu =3D apic->vcpu; - /* * We do get here for APIC virtualization enabled if the guest * uses the Hyper-V APIC enlightenment. In this case we may need @@ -603,7 +593,7 @@ static inline void apic_clear_isr(int vec, struct kvm_l= apic *apic) * on the other hand isr_count and highest_isr_cache are unused * and must be left alone. */ - if (unlikely(vcpu->arch.apicv_active)) + if (unlikely(apic->apicv_active)) static_call_cond(kvm_x86_hwapic_isr_update)(apic_find_highest_isr(apic)); else { --apic->isr_count; @@ -1584,7 +1574,7 @@ static bool lapic_timer_int_injected(struct kvm_vcpu = *vcpu) int vec =3D reg & APIC_VECTOR_MASK; void *bitmap =3D apic->regs + APIC_ISR; =20 - if (vcpu->arch.apicv_active) + if (apic->apicv_active) bitmap =3D apic->regs + APIC_IRR; =20 if (apic_test_vector(vec, bitmap)) @@ -1701,7 +1691,7 @@ static void apic_timer_expired(struct kvm_lapic *apic= , bool from_timer_fn) if (apic_lvtt_tscdeadline(apic) || ktimer->hv_timer_in_use) ktimer->expired_tscdeadline =3D ktimer->tscdeadline; =20 - if (!from_timer_fn && vcpu->arch.apicv_active) { + if (!from_timer_fn && apic->apicv_active) { WARN_ON(kvm_get_running_vcpu() !=3D vcpu); kvm_apic_inject_pending_timer_irqs(apic); return; @@ -2379,7 +2369,7 @@ void kvm_apic_update_apicv(struct kvm_vcpu *vcpu) { struct kvm_lapic *apic =3D vcpu->arch.apic; =20 - if (vcpu->arch.apicv_active) { + if (apic->apicv_active) { /* irr_pending is always true when apicv is activated. */ apic->irr_pending =3D true; apic->isr_count =3D 1; @@ -2454,7 +2444,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init= _event) =20 vcpu->arch.pv_eoi.msr_val =3D 0; apic_update_ppr(apic); - if (vcpu->arch.apicv_active) { + if (apic->apicv_active) { static_call_cond(kvm_x86_apicv_post_state_restore)(vcpu); static_call_cond(kvm_x86_hwapic_irr_update)(vcpu, -1); static_call_cond(kvm_x86_hwapic_isr_update)(-1); @@ -2734,7 +2724,7 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct = kvm_lapic_state *s) kvm_lapic_set_reg(apic, APIC_TMCCT, 0); kvm_apic_update_apicv(vcpu); apic->highest_isr_cache =3D -1; - if (vcpu->arch.apicv_active) { + if (apic->apicv_active) { static_call_cond(kvm_x86_apicv_post_state_restore)(vcpu); static_call_cond(kvm_x86_hwapic_irr_update)(vcpu, apic_find_highest_irr(= apic)); static_call_cond(kvm_x86_hwapic_isr_update)(apic_find_highest_isr(apic)); diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 65bb2a8cf145..e09ad97f3250 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -48,6 +48,7 @@ struct kvm_lapic { struct kvm_timer lapic_timer; u32 divide_count; struct kvm_vcpu *vcpu; + bool apicv_active; bool sw_enabled; bool irr_pending; bool lvt0_in_nmi_mode; @@ -204,7 +205,7 @@ static inline int apic_x2apic_mode(struct kvm_lapic *ap= ic) =20 static inline bool kvm_vcpu_apicv_active(struct kvm_vcpu *vcpu) { - return vcpu->arch.apic && vcpu->arch.apicv_active; + return vcpu->arch.apic && vcpu->arch.apic->apicv_active; } =20 static inline bool kvm_apic_has_events(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index c6cca0ce127b..255f5c6f3aab 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3465,12 +3465,13 @@ void svm_complete_interrupt_delivery(struct kvm_vcp= u *vcpu, int delivery_mode, int trig_mode, int vector) { /* - * vcpu->arch.apicv_active must be read after vcpu->mode. + * apic->apicv_active must be read after vcpu->mode. * Pairs with smp_store_release in vcpu_enter_guest. */ bool in_guest_mode =3D (smp_load_acquire(&vcpu->mode) =3D=3D IN_GUEST_MOD= E); =20 - if (!READ_ONCE(vcpu->arch.apicv_active)) { + /* Note, this is called iff the local APIC is in-kernel. */ + if (!READ_ONCE(vcpu->arch.apic->apicv_active)) { /* Process the interrupt via inject_pending_event */ kvm_make_request(KVM_REQ_EVENT, vcpu); kvm_vcpu_kick(vcpu); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 42f8924a90f4..0e24f2cc3177 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4089,7 +4089,8 @@ static int vmx_deliver_posted_interrupt(struct kvm_vc= pu *vcpu, int vector) if (!r) return 0; =20 - if (!vcpu->arch.apicv_active) + /* Note, this is called iff the local APIC is in-kernel. */ + if (!vcpu->arch.apic->apicv_active) return -1; =20 if (pi_test_and_set_pir(vector, &vmx->pi_desc)) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index cd554a62eb0f..9cea051ca62e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9440,7 +9440,7 @@ static void update_cr8_intercept(struct kvm_vcpu *vcp= u) if (!lapic_in_kernel(vcpu)) return; =20 - if (vcpu->arch.apicv_active) + if (vcpu->arch.apic->apicv_active) return; =20 if (!vcpu->arch.apic->vapic_addr) @@ -9893,6 +9893,7 @@ void kvm_make_scan_ioapic_request(struct kvm *kvm) =20 void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu) { + struct kvm_lapic *apic =3D vcpu->arch.apic; bool activate; =20 if (!lapic_in_kernel(vcpu)) @@ -9903,10 +9904,10 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu) =20 activate =3D kvm_vcpu_apicv_activated(vcpu); =20 - if (vcpu->arch.apicv_active =3D=3D activate) + if (apic->apicv_active =3D=3D activate) goto out; =20 - vcpu->arch.apicv_active =3D activate; + apic->apicv_active =3D activate; kvm_apic_update_apicv(vcpu); static_call(kvm_x86_refresh_apicv_exec_ctrl)(vcpu); =20 @@ -9916,7 +9917,7 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu) * still active when the interrupt got accepted. Make sure * inject_pending_event() is called to check for that. */ - if (!vcpu->arch.apicv_active) + if (!apic->apicv_active) kvm_make_request(KVM_REQ_EVENT, vcpu); =20 out: @@ -11359,7 +11360,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) * will ensure the vCPU gets the correct state before VM-Entry. */ if (enable_apicv) { - vcpu->arch.apicv_active =3D true; + vcpu->arch.apic->apicv_active =3D true; kvm_make_request(KVM_REQ_APICV_UPDATE, vcpu); } } else --=20 2.36.1.476.g0c4daa206d-goog From nobody Mon Apr 27 09:13:37 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 69C01C433EF for ; Tue, 14 Jun 2022 23:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358371AbiFNXGM (ORCPT ); Tue, 14 Jun 2022 19:06:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240980AbiFNXGC (ORCPT ); Tue, 14 Jun 2022 19:06:02 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 181F55372A for ; Tue, 14 Jun 2022 16:06:00 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id q199-20020a25d9d0000000b00664af83bee9so6910832ybg.9 for ; Tue, 14 Jun 2022 16:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=H1M2DYWsU+c15TLt1rKOqiFcg/EmzWXN7tpVE5HWvKo=; b=hnm/tdKp9LufbwDqkyMs0iWVJf+Gw8tXJ3WDXdLICoF74ya747HGVKeg04szV2++GJ Bnf/AfSd/48fnuZpiS1m2wnOxdIjjrHs09jRAvNicZxLIXQtmfySs4uKTaK8o2rwOan+ ds2Prcxy00KS3z6hMAwmUw+GW5KGMI/gsSmhp+XRisrqsRigiGOStyjlIGU/nRF1gHGh r9UTxBOOfCmUHeVNGFCm/i0Q9f9joIb2YgvEM5OSJsgh0G+fg88TVOx4lE+ODStf9LY9 PNph9y63sNqjDEmh33o419vilVnuolLcf3u3rKe2nOC3uxIw5C6hTwHM1xhEC0jELNdr KiOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=H1M2DYWsU+c15TLt1rKOqiFcg/EmzWXN7tpVE5HWvKo=; b=O3qNZklUPK+f0FFQ5KpI37VilDPCnj8Icl0P+E3Qxc5SViDZK+6Pxa3uXeKfn7jNN3 laq1WpCx1hxGit7ihPLF3NL+0u7GRT/4+WvqZfFVeoGjY3+1K2rj6Ow41VxoG7YQDj27 OyfHLOXMSgeRFDXbZ2MSg6++q9U5TOGJ2NI7CGftrqeE5qrQUuQKe93NMBw+ioa4pCJz GFb88CSVBVA/St7Gc7jNvg7+HXt7z58qZ6J1YOm2z1ewk7tXsMNFZU0IWXcg2X5b39ic c0PYBpEnVVk/emICeCF2tY8vO3+gHupDsX1aTSbeMMj8dPz9giyJKqFs3zqIN4TUiFej 3Xvw== X-Gm-Message-State: AJIora+/+BT53YfHagFOHLlcFL/S1t1OOe/m7NecDZtLcbCWCk0FxOZu GDAzqEaYbrNt3zeh07GdHUr6RAj7cJQ= X-Google-Smtp-Source: AGRyM1uf72yhsevkLoSbOoEFneoBn6zDkIxHTWYSbWOkx+hZlvZNe06qxNyNzgTjR5AQlVipmTyw8USIA68= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a25:3bd0:0:b0:664:2ec8:34c0 with SMTP id i199-20020a253bd0000000b006642ec834c0mr7448093yba.405.1655247959351; Tue, 14 Jun 2022 16:05:59 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 23:05:48 +0000 In-Reply-To: <20220614230548.3852141-1-seanjc@google.com> Message-Id: <20220614230548.3852141-6-seanjc@google.com> Mime-Version: 1.0 References: <20220614230548.3852141-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH 5/5] KVM: x86: Use lapic_in_kernel() to query in-kernel APIC in APICv helper From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use lapic_in_kernel() in kvm_vcpu_apicv_active() to take advantage of the kvm_has_noapic_vcpu static branch. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/lapic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index e09ad97f3250..6207b64b1281 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -205,7 +205,7 @@ static inline int apic_x2apic_mode(struct kvm_lapic *ap= ic) =20 static inline bool kvm_vcpu_apicv_active(struct kvm_vcpu *vcpu) { - return vcpu->arch.apic && vcpu->arch.apic->apicv_active; + return lapic_in_kernel(vcpu) && vcpu->arch.apic->apicv_active; } =20 static inline bool kvm_apic_has_events(struct kvm_vcpu *vcpu) --=20 2.36.1.476.g0c4daa206d-goog