]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: x86: Print names of apicv inhibit reasons in traces
authorAlejandro Jimenez <alejandro.j.jimenez@oracle.com>
Mon, 6 May 2024 22:53:20 +0000 (22:53 +0000)
committerSean Christopherson <seanjc@google.com>
Wed, 5 Jun 2024 13:18:27 +0000 (06:18 -0700)
Use the tracing infrastructure helper __print_flags() for printing flag
bitfields, to enhance the trace output by displaying a string describing
each of the inhibit reasons set.

The kvm_apicv_inhibit_changed tracepoint currently shows the raw bitmap
value, requiring the user to consult the source file where the inhibit
reasons are defined to decode the trace output.

Signed-off-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Link: https://lore.kernel.org/r/20240506225321.3440701-2-alejandro.j.jimenez@oracle.com
Co-developed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/trace.h
arch/x86/kvm/x86.c

index a0d642a5e079e149e0395f3801906dddeb6f8c7f..8323a7f619b0f8d03278bc8f855492902bbe64bb 100644 (file)
@@ -1277,8 +1277,27 @@ enum kvm_apicv_inhibit {
         * mapping between logical ID and vCPU.
         */
        APICV_INHIBIT_REASON_LOGICAL_ID_ALIASED,
+
+       NR_APICV_INHIBIT_REASONS,
 };
 
+#define __APICV_INHIBIT_REASON(reason)                 \
+       { BIT(APICV_INHIBIT_REASON_##reason), #reason }
+
+#define APICV_INHIBIT_REASONS                          \
+       __APICV_INHIBIT_REASON(DISABLE),                \
+       __APICV_INHIBIT_REASON(HYPERV),                 \
+       __APICV_INHIBIT_REASON(ABSENT),                 \
+       __APICV_INHIBIT_REASON(BLOCKIRQ),               \
+       __APICV_INHIBIT_REASON(PHYSICAL_ID_ALIASED),    \
+       __APICV_INHIBIT_REASON(APIC_ID_MODIFIED),       \
+       __APICV_INHIBIT_REASON(APIC_BASE_MODIFIED),     \
+       __APICV_INHIBIT_REASON(NESTED),                 \
+       __APICV_INHIBIT_REASON(IRQWIN),                 \
+       __APICV_INHIBIT_REASON(PIT_REINJ),              \
+       __APICV_INHIBIT_REASON(SEV),                    \
+       __APICV_INHIBIT_REASON(LOGICAL_ID_ALIASED)
+
 struct kvm_arch {
        unsigned long n_used_mmu_pages;
        unsigned long n_requested_mmu_pages;
index e19fed438a670a1cc5e2aa4ddfd8969c9679179f..e445fc3b092589e0d0537efc0cecf5dbafdae101 100644 (file)
@@ -1375,6 +1375,10 @@ TRACE_EVENT(kvm_hv_stimer_cleanup,
                  __entry->vcpu_id, __entry->timer_index)
 );
 
+#define kvm_print_apicv_inhibit_reasons(inhibits)      \
+       (inhibits), (inhibits) ? " " : "",              \
+       (inhibits) ? __print_flags(inhibits, "|", APICV_INHIBIT_REASONS) : ""
+
 TRACE_EVENT(kvm_apicv_inhibit_changed,
            TP_PROTO(int reason, bool set, unsigned long inhibits),
            TP_ARGS(reason, set, inhibits),
@@ -1391,9 +1395,10 @@ TRACE_EVENT(kvm_apicv_inhibit_changed,
                __entry->inhibits = inhibits;
        ),
 
-       TP_printk("%s reason=%u, inhibits=0x%lx",
+       TP_printk("%s reason=%u, inhibits=0x%lx%s%s",
                  __entry->set ? "set" : "cleared",
-                 __entry->reason, __entry->inhibits)
+                 __entry->reason,
+                 kvm_print_apicv_inhibit_reasons(__entry->inhibits))
 );
 
 TRACE_EVENT(kvm_apicv_accept_irq,
index 09e3460bcbc53cb21a10c36ccd316bb41aa27918..e5a61270b3ae3f629691054d918d6a9542c2ca9a 100644 (file)
@@ -10037,6 +10037,10 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_apicv_activated);
 static void set_or_clear_apicv_inhibit(unsigned long *inhibits,
                                       enum kvm_apicv_inhibit reason, bool set)
 {
+       const struct trace_print_flags apicv_inhibits[] = { APICV_INHIBIT_REASONS };
+
+       BUILD_BUG_ON(ARRAY_SIZE(apicv_inhibits) != NR_APICV_INHIBIT_REASONS);
+
        if (set)
                __set_bit(reason, inhibits);
        else