Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1119383pxb; Fri, 22 Apr 2022 20:22:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYacIwCqStxeJ/fiKaEuVARPWM4CNMqxmgLFWCLWbXvdzuyQ41kTGzzcvGMzcp70onxVAR X-Received: by 2002:a63:9203:0:b0:386:3b37:76b5 with SMTP id o3-20020a639203000000b003863b3776b5mr6633550pgd.234.1650684179518; Fri, 22 Apr 2022 20:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650684179; cv=none; d=google.com; s=arc-20160816; b=sOei7cYJUE+RIY3Oibm8MJEji9dPLeCIg5XGaNmCt9Ma5DBZ4ye0rXwdRkWObkdmMq NnccfviKEqI46Y5BUoAslJ0Fw3c6S5Yub06Y5Lzyfjb+qS7yrNCU8BRBcGR6XrtG2QeO 5sEv2s7iuspEM2GHYZcUP1Bw5ZoGkubhEgklMOvB/uMvGLNQbkKdbvbnXEh9BZ6KQ1JY yNZrNZ0+a9xAJJGdnSc/Mkav6DEQyMjgk9maynyj91KAL04A8hBUctBRdNkGiogNJMON 1/unQUNtFLbWTLP0u2BcwWkeTFpA+YhyEL4wqkoTdDoB5pNvS1vSyhfuwseVVhqlROLL 9xDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=YP3aW6zH/fPatigZ4/X2xyENnpxrIf5NXRWAQXh1KLg=; b=ZqnkaYCWry2IfzJQlro8Bh3FKcsuS3bgWOPihYOSvsDeC5zJyPI77rFfBtWE3mk7Nu 6cedS/9kHS+XA5Go+YJJWdW9ZBgyQHeBhDQuWO3PzqmM7MvC6M5QJ77dbtDgBVoJiY3T GQkoxL3Oo+u8c1UH8Oy6JQGlS2oAivGYemUg+KD2O29+TLmu7Y1JUlYgrusWuVN0PG2g m9WuOBF1BI/VCGTJOmimTYdIoBQRakctYZ4SCe3Ioot2XNM3e2GpmPlPGvnJMHqlyWYX 1lJS4ZcD8lgN6qNKIJutvMIFaug1LtU/efrGAoxjGO/kUdL5zpDMT3niXfkBrx1P9vkZ izzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rpke6V8t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s37-20020a635265000000b003aa1ecf8d44si472424pgl.123.2022.04.22.20.22.41; Fri, 22 Apr 2022 20:22:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rpke6V8t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231947AbiDWCRt (ORCPT + 99 others); Fri, 22 Apr 2022 22:17:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbiDWCR2 (ORCPT ); Fri, 22 Apr 2022 22:17:28 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD419223C60 for ; Fri, 22 Apr 2022 19:14:28 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id z132-20020a63338a000000b003844e317066so5957865pgz.19 for ; Fri, 22 Apr 2022 19:14:28 -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=YP3aW6zH/fPatigZ4/X2xyENnpxrIf5NXRWAQXh1KLg=; b=rpke6V8tq81cNiJq2YbH/e/SKEreh+ccqI6cvAcxsFxbZzVRTwQBkT2K5IOGGNpyTN MMuqFixY9wazTtMwAPYIiiGJw+nln9T28cLoEEUeVw9SqanV79u1LJyrDFDKgDqM6uTZ vTje6rQXKM/H9sY9rS0xXC/TTEZ/rgYIBX++3JfGU/cHxcBePPr86shcjIhBkGd9GtDq aRMPPAMPdaE1k+5PrQJWUWiMkg/4ccEbBCTQPNtAGPI+DF/BfSBtwJFs1fgNP/UY+21x 6pz9pIYewZSt1A2Px7+30nUzMeF0gm6zzika0ZhX1EhsfoUyEJMpkQ3kfy34jfmuD5qk zBuQ== 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=YP3aW6zH/fPatigZ4/X2xyENnpxrIf5NXRWAQXh1KLg=; b=liSlGoHNuCaZteS0h5VppLU42ZZZUzOwQLeeFtnToiKSEPSj9y+Tv5IRlT2wIDKNaE KMZ0BhzKuc8cVqxWDt3skUward0lkSjrd5mlMsPBLjqrklfeF/+IYS+8yWpV2ommQJXT w0I95Kpa/quBd7VRrInuEyWZ0q+29XiJQ/Y0Qw9lFcYRZlJ3zJdSEbUVZvYyP9Ik6JyF MC+lHylsfCjkQm13GgNcYx8byESc6ZUONb2TAIU8hLLo2WrIThfKU3zwtA/ZGHD72oP3 OiHaIKNX3rYpGM23SbBsm+KkUfEVkQ3lHbJC6E9HASAsWoiDe8lp6CvFE6Ys200Yggho K9Qg== X-Gm-Message-State: AOAM530tnp9mkrOmP53LAYgVfc0wQ2LDA/8Hxrs8KTBKVNacTQD44skZ aUHWpDCyJVWieHAvSVhGMrr1nkeue7U= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:ccc9:b0:15b:c265:b7a0 with SMTP id z9-20020a170902ccc900b0015bc265b7a0mr6812946ple.107.1650680068213; Fri, 22 Apr 2022 19:14:28 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 23 Apr 2022 02:14:09 +0000 In-Reply-To: <20220423021411.784383-1-seanjc@google.com> Message-Id: <20220423021411.784383-10-seanjc@google.com> Mime-Version: 1.0 References: <20220423021411.784383-1-seanjc@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v2 09/11] KVM: x86: Differentiate Soft vs. Hard IRQs vs. reinjected in tracepoint 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, Maxim Levitsky , "Maciej S . Szmigiero" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the IRQ injection tracepoint, differentiate between Hard IRQs and Soft "IRQs", i.e. interrupts that are reinjected after incomplete delivery of a software interrupt from an INTn instruction. Tag reinjected interrupts as such, even though the information is usually redundant since soft interrupts are only ever reinjected by KVM. Though rare in practice, a hard IRQ can be reinjected. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm/svm.c | 5 +++-- arch/x86/kvm/trace.h | 16 +++++++++++----- arch/x86/kvm/vmx/vmx.c | 4 ++-- arch/x86/kvm/x86.c | 4 ++-- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index f164c6c1514a..ae088c6fb287 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1400,7 +1400,7 @@ struct kvm_x86_ops { u32 (*get_interrupt_shadow)(struct kvm_vcpu *vcpu); void (*patch_hypercall)(struct kvm_vcpu *vcpu, unsigned char *hypercall_addr); - void (*inject_irq)(struct kvm_vcpu *vcpu); + void (*inject_irq)(struct kvm_vcpu *vcpu, bool reinjected); void (*inject_nmi)(struct kvm_vcpu *vcpu); void (*queue_exception)(struct kvm_vcpu *vcpu); void (*cancel_injection)(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index b8fb07eeeca5..4a912623b961 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3427,7 +3427,7 @@ static void svm_inject_nmi(struct kvm_vcpu *vcpu) ++vcpu->stat.nmi_injections; } -static void svm_inject_irq(struct kvm_vcpu *vcpu) +static void svm_inject_irq(struct kvm_vcpu *vcpu, bool reinjected) { struct vcpu_svm *svm = to_svm(vcpu); u32 type; @@ -3442,7 +3442,8 @@ static void svm_inject_irq(struct kvm_vcpu *vcpu) type = SVM_EVTINJ_TYPE_INTR; } - trace_kvm_inj_virq(vcpu->arch.interrupt.nr); + trace_kvm_inj_virq(vcpu->arch.interrupt.nr, + vcpu->arch.interrupt.soft, reinjected); ++vcpu->stat.irq_injections; svm->vmcb->control.event_inj = vcpu->arch.interrupt.nr | diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h index 385436d12024..e1b089285c55 100644 --- a/arch/x86/kvm/trace.h +++ b/arch/x86/kvm/trace.h @@ -333,18 +333,24 @@ TRACE_EVENT_KVM_EXIT(kvm_exit); * Tracepoint for kvm interrupt injection: */ TRACE_EVENT(kvm_inj_virq, - TP_PROTO(unsigned int irq), - TP_ARGS(irq), + TP_PROTO(unsigned int vector, bool soft, bool reinjected), + TP_ARGS(vector, soft, reinjected), TP_STRUCT__entry( - __field( unsigned int, irq ) + __field( unsigned int, vector ) + __field( bool, soft ) + __field( unsigned int, reinjected ) ), TP_fast_assign( - __entry->irq = irq; + __entry->vector = vector; + __entry->soft = soft; + __entry->reinjected = reinjected; ), - TP_printk("irq %u", __entry->irq) + TP_printk("%s 0x%x%s", + __entry->soft ? "Soft/INTn" : "IRQ", __entry->vector, + __entry->reinjected ? " [reinjected]" : "") ); #define EXS(x) { x##_VECTOR, "#" #x } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index cf8581978bce..a0083464682d 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4566,13 +4566,13 @@ static void vmx_enable_nmi_window(struct kvm_vcpu *vcpu) exec_controls_setbit(to_vmx(vcpu), CPU_BASED_NMI_WINDOW_EXITING); } -static void vmx_inject_irq(struct kvm_vcpu *vcpu) +static void vmx_inject_irq(struct kvm_vcpu *vcpu, bool reinjected) { struct vcpu_vmx *vmx = to_vmx(vcpu); uint32_t intr; int irq = vcpu->arch.interrupt.nr; - trace_kvm_inj_virq(irq); + trace_kvm_inj_virq(irq, vcpu->arch.interrupt.soft, reinjected); ++vcpu->stat.irq_injections; if (vmx->rmode.vm86_active) { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c3ee8dc00d3a..0a154b54b8aa 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9433,7 +9433,7 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool *req_immediate_exit) static_call(kvm_x86_inject_nmi)(vcpu); can_inject = false; } else if (vcpu->arch.interrupt.injected) { - static_call(kvm_x86_inject_irq)(vcpu); + static_call(kvm_x86_inject_irq)(vcpu, true); can_inject = false; } } @@ -9524,7 +9524,7 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool *req_immediate_exit) goto out; if (r) { kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu), false); - static_call(kvm_x86_inject_irq)(vcpu); + static_call(kvm_x86_inject_irq)(vcpu, false); WARN_ON(static_call(kvm_x86_interrupt_allowed)(vcpu, true) < 0); } if (kvm_cpu_has_injectable_intr(vcpu)) -- 2.36.0.rc2.479.g8af0fa9b8e-goog