KVM: arm64: vgic-its: Enhance debugging with debugfs and tracepoints
cover KVM: arm64: vgic-its: Enhance debugging with debugfs and tracepoints
This patch introduces two significant enhancements to the debugging capabilities of the KVM VGIC ITS for ARM64 systems:
* Debugfs Interface for ITS Tables:
A new debugfs interface is added, accessible at /sys/kernel/debug/kvm/<vm_name>/vgic-its-state@<its_base_address>. This interface exposes the internal ITS tables, allowing developers to inspect the mappings between Event IDs, Interrupt IDs, and their associated target processors. The information is presented in a clear, tabular format, making it easy to understand the current state of the ITS configuration.
* Tracepoints for ITS Commands:
Tracepoints have been added to cover all major ITS commands. These tracepoints provide detailed information about each command execution, including device IDs, event IDs, collection IDs, and other relevant parameters. This allows for fine-grained monitoring of ITS activity and facilitates debugging of complex interrupt routing scenarios.
Motivation:
The ITS is a critical component for interrupt routing in virtualized environments, but its complexity can make it difficult to debug and optimize. The current lack of visibility into its internal state hinders the ability to diagnose issues related to interrupt delivery, performance bottlenecks, and configuration errors.
This patch addresses these challenges by providing tools to:
* Inspect ITS Table Mappings:
The debugfs interface allows developers to directly examine the ITS tables, verify the correctness of mappings, and identify potential misconfigurations.
* Monitor ITS Command Execution:
The tracepoints provide a detailed log of ITS command activity, making it easier to understand the flow of interrupt routing and pinpoint the root cause of issues.
* Improve Debuggability:
By combining the static view of the ITS tables with the dynamic information from tracepoints, developers gain a comprehensive understanding of the ITS's behavior.
Implementation Details:
The debugfs interface is implemented using the seq_file interface to present the ITS table data in a user-friendly format. Tracepoints are defined using TRACE_EVENT and DECLARE_EVENT_CLASS macros for efficient tracing. Tracepoints are strategically placed within each ITS command handler function to capture relevant information. The patch includes necessary modifications to the KVM Makefile and VGIC header files to incorporate the new functionality.
---
Jing Zhang (2):
KVM: arm64: vgic-its: Add debugfs interface to expose ITS tables
KVM: arm64: vgic-its: Add tracepoints for VGIC ITS commands
arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/vgic/trace.h | 135 ++++++++++++++++ arch/arm64/kvm/vgic/vgic-its-debug.c | 234 +++++++++++++++++++++++++++ arch/arm64/kvm/vgic/vgic-its.c | 58 ++++--- arch/arm64/kvm/vgic/vgic.h | 33 ++++ 5 files changed, 430 insertions(+), 32 deletions(-) create mode 100644 arch/arm64/kvm/vgic/vgic-its-debug.c
base-commit: 9d89551994a430b50c4fffcb1e617a057fa76e20
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
RFC PATCH 1/2 KVM: arm64: vgic-its: Add debugfs interface to expose ITS tables
This commit introduces a debugfs interface to display the contents of the VGIC Interrupt Translation Service (ITS) tables.
The ITS tables map Device/Event IDs to Interrupt IDs and target processors. Exposing this information through debugfs allows for easier inspection and debugging of the interrupt routing configuration.
The debugfs interface presents the ITS table data in a tabular format:
Device ID: 0, Event ID Range: [0 - 65535]
EVENT_ID INTID HWINTID TARGET COL_ID HW
-----------------------------------------------
0 32 0 0 0 0
1 33 0 0 0 0
2 34 0 0 0 0
... ... ... ... ... ..The output is generated using the seq_file interface, allowing for efficient handling of potentially large ITS tables.
This interface is read-only and does not allow modification of the ITS tables. It is intended for debugging and informational purposes only.
--- arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/vgic/vgic-its-debug.c | 234 +++++++++++++++++++++++++++ arch/arm64/kvm/vgic/vgic-its.c | 39 +---- arch/arm64/kvm/vgic/vgic.h | 33 ++++ 4 files changed, 276 insertions(+), 32 deletions(-) create mode 100644 arch/arm64/kvm/vgic/vgic-its-debug.c
arch/arm64/kvm/Makefile +1 -1
@@ -23,7 +23,7 @@ kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \ vgic/vgic-v3.o vgic/vgic-v4.o \ vgic/vgic-mmio.o vgic/vgic-mmio-v2.o \ vgic/vgic-mmio-v3.o vgic/vgic-kvm-device.o \ - vgic/vgic-its.o vgic/vgic-debug.o + vgic/vgic-its.o vgic/vgic-debug.o vgic/vgic-its-debug.o kvm-$(CONFIG_HW_PERF_EVENTS) += pmu-emul.o pmu.o kvm-$(CONFIG_ARM64_PTR_AUTH) += pauth.o
arch/arm64/kvm/vgic/vgic-its-debug.c new file +234 -0
234 lines not on this page · raw message
arch/arm64/kvm/vgic/vgic-its.c +8 -31
@@ -154,36 +154,6 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid,return irq; } -struct its_device { -struct list_head dev_list; - -/* the head for the list of ITTEs */ -struct list_head itt_head; -u32 num_eventid_bits; -gpa_t itt_addr; -u32 device_id; -}; - -#define COLLECTION_NOT_MAPPED ((u32)~0) - -struct its_collection { -struct list_head coll_list; - -u32 collection_id; -u32 target_addr; -}; - -#define its_is_collection_mapped (coll) ((coll) && \ - ((coll)->target_addr != COLLECTION_NOT_MAPPED)) - -struct its_ite { -struct list_head ite_list; - -struct vgic_irq *irq; -struct its_collection *collection; -u32 event_id; -}; -/** * struct vgic_its_abi - ITS abi ops and settings * @cte_esz: collection table entry size
@@ -1938,6 +1908,8 @@ static void vgic_its_destroy(struct kvm_device *kvm_dev)mutex_lock (&its->its_lock); +vgic_its_debug_destroy (kvm_dev); +vgic_its_free_device_list (kvm, its);vgic_its_free_collection_list (kvm, its);vgic_its_invalidate_cache (its);
@@ -2771,7 +2743,12 @@ static int vgic_its_set_attr(struct kvm_device *dev,if (ret)return ret; -return vgic_register_its_iodev (dev->kvm, its, addr); + ret =vgic_register_its_iodev (dev->kvm, its, addr); +if (ret) +return ret; + +return vgic_its_debug_init (dev); + }case KVM_DEV_ARM_VGIC_GRP_CTRL :return vgic_its_ctrl (dev->kvm, its, attr->attr);
arch/arm64/kvm/vgic/vgic.h +33 -0
@@ -172,6 +172,36 @@ struct vgic_reg_attr {gpa_t addr; }; +struct its_device { +struct list_head dev_list; + +/* the head for the list of ITTEs */ +struct list_head itt_head; +u32 num_eventid_bits; +gpa_t itt_addr; +u32 device_id; +}; + +#define COLLECTION_NOT_MAPPED ((u32)~0) + +struct its_collection { +struct list_head coll_list; + +u32 collection_id; +u32 target_addr; +}; + +#define its_is_collection_mapped (coll) ((coll) && \ + ((coll)->target_addr != COLLECTION_NOT_MAPPED)) + +struct its_ite { +struct list_head ite_list; + +struct vgic_irq *irq; +struct its_collection *collection; +u32 event_id; +}; +int vgic_v3_parse_attr (struct kvm_device *dev,struct kvm_device_attr *attr,struct vgic_reg_attr *reg_attr); int vgic_v2_parse_attr(struct kvm_device *dev, struct kvm_device_attr *attr,
@@ -353,4 +383,7 @@ static inline bool kvm_has_gicv3(struct kvm *kvm) return kvm_has_feat(kvm, ID_AA64PFR0_EL1, GIC, IMP); } +int vgic_its_debug_init (struct kvm_device *dev); +void vgic_its_debug_destroy (struct kvm_device *dev); +#endif
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
RFC PATCH 2/2 KVM: arm64: vgic-its: Add tracepoints for VGIC ITS commands
In reply to Jing ZhangThis commit adds tracepoints to the KVM VGIC ITS on ARM64 to improve observability and debuggability. The following ITS commands now have associated tracepoints: MAPI, DISCARD, CLEAR, INT, INV, MAPD, MAPC, MOVI, MOVALL, and INVALL.
Each tracepoint captures essential information such as device ID, event ID, and other relevant parameters, allowing for detailed monitoring of ITS operations.
These tracepoints are useful for:
* Debugging interrupt routing issues. * Performance analysis and optimization. * Understanding ITS behavior. * Root-causing interrupt handling errors.
This enhancement provides crucial insights into interrupt handling in ARM64 virtualized environments, aiding in development, debugging, and maintenance.
--- arch/arm64/kvm/vgic/trace.h | 135 +++++++++++++++++++++++++++++++++ arch/arm64/kvm/vgic/vgic-its.c | 19 +++++ 2 files changed, 154 insertions(+)
arch/arm64/kvm/vgic/trace.h +135 -0
@@ -27,6 +27,141 @@ TRACE_EVENT(vgic_update_irq_pending, __entry->vcpu_id, __entry->irq, __entry->level) ); +DECLARE_EVENT_CLASS (vgic_its_cmd_class, + TP_PROTO(__u32 device_id, __u32 event_id), +TP_ARGS (device_id, event_id), + +TP_STRUCT__entry ( + __field( __u32, device_id ) +__field ( __u32, event_id ) + ), + +TP_fast_assign ( + __entry->device_id = device_id; + __entry->event_id = event_id; + ), + +TP_printk ("Device ID: %u, Event ID: %u" , + __entry->device_id, __entry->event_id) +); + +DEFINE_EVENT (vgic_its_cmd_class, vgic_its_cmd_mapi, + TP_PROTO(__u32 device_id, __u32 event_id), +TP_ARGS (device_id, event_id)); + +DEFINE_EVENT (vgic_its_cmd_class, vgic_its_cmd_discard, + TP_PROTO(__u32 device_id, __u32 event_id), +TP_ARGS (device_id, event_id)); + +DEFINE_EVENT (vgic_its_cmd_class, vgic_its_cmd_clear, + TP_PROTO(__u32 device_id, __u32 event_id), +TP_ARGS (device_id, event_id)); + +DEFINE_EVENT (vgic_its_cmd_class, vgic_its_cmd_int, + TP_PROTO(__u32 device_id, __u32 event_id), +TP_ARGS (device_id, event_id)); + +DEFINE_EVENT (vgic_its_cmd_class, vgic_its_cmd_inv, + TP_PROTO(__u32 device_id, __u32 event_id), +TP_ARGS (device_id, event_id)); + +TRACE_EVENT (vgic_its_cmd_mapd, + TP_PROTO(__u32 device_id, bool valid, __u8 num_eventid_bits, __u64 itt_addr), +TP_ARGS (device_id, valid, num_eventid_bits, itt_addr), + +TP_STRUCT__entry ( + __field( __u32, device_id ) + __field( bool, valid ) + __field( __u8, num_eventid_bits ) +__field ( __u64, itt_addr ) + ), + +TP_fast_assign ( + __entry->device_id = device_id; + __entry->valid = valid; + __entry->num_eventid_bits = num_eventid_bits; + __entry->itt_addr = itt_addr; + ), + +TP_printk ("Device ID: %u, valid: %d, num_eventid_bits: %u, itt_addr: %llx" , + __entry->device_id, __entry->valid, + __entry->num_eventid_bits, __entry->itt_addr) +); + +TRACE_EVENT (vgic_its_cmd_mapc, + TP_PROTO(__u32 collection_id, bool valid), +TP_ARGS (collection_id, valid), + +TP_STRUCT__entry ( + __field( __u32, collection_id ) +__field ( bool, valid ) + ), + +TP_fast_assign ( + __entry->collection_id = collection_id; + __entry->valid = valid; + ), + +TP_printk ("Collection ID: %u, valid: %d" , + __entry->collection_id, __entry->valid) +); + +TRACE_EVENT (vgic_its_cmd_movi, + TP_PROTO(__u32 device_id, __u32 event_id, __u32 collection_id), +TP_ARGS (device_id, event_id, collection_id), + +TP_STRUCT__entry ( + __field( __u32, device_id ) + __field( __u32, event_id ) +__field ( __u32, collection_id ) + ), + +TP_fast_assign ( + __entry->device_id = device_id; + __entry->event_id = event_id; + __entry->collection_id = collection_id; + ), + +TP_printk ("Device ID: %u, Event ID: %u, Collection ID: %u" , + __entry->device_id, __entry->event_id, __entry->collection_id) +); + +TRACE_EVENT (vgic_its_cmd_movall, + TP_PROTO(int vcpu_source, int vcpu_target), +TP_ARGS (vcpu_source, vcpu_target), + +TP_STRUCT__entry ( + __field( int, vcpu_source ) +__field ( int, vcpu_target ) + ), + +TP_fast_assign ( + __entry->vcpu_source = vcpu_source; + __entry->vcpu_target = vcpu_target; + ), + +TP_printk ("Source VCPU: %d, Target VCPU: %d" , + __entry->vcpu_source, __entry->vcpu_target) +); + +TRACE_EVENT (vgic_its_cmd_invall, + TP_PROTO(__u32 collection_id, int vcpu_id), +TP_ARGS (collection_id, vcpu_id), + +TP_STRUCT__entry ( + __field( __u32, collection_id ) +__field ( int, vcpu_id ) + ), + +TP_fast_assign ( + __entry->collection_id = collection_id; + __entry->vcpu_id = vcpu_id; + ), + +TP_printk ("Collection ID: %u, VCPU ID: %d" , + __entry->collection_id, __entry->vcpu_id) +); +#endif /* _TRACE_VGIC_H */ #undef TRACE_INCLUDE_PATH
arch/arm64/kvm/vgic/vgic-its.c +19 -0
@@ -22,6 +22,7 @@#include "vgic.h" #include "vgic-mmio.h" +#include "trace.h" static struct kvm_device_ops kvm_arm_vgic_its_ops;
@@ -795,6 +796,8 @@ static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its,u32 event_id =its_cmd_get_id (its_cmd);struct its_ite *ite; +trace_vgic_its_cmd_discard (device_id, event_id); + ite =find_ite (its, device_id, event_id);if (ite &&its_is_collection_mapped (ite->collection)) {struct its_device *device =find_its_device (its, device_id);
@@ -829,6 +832,8 @@ static int vgic_its_cmd_handle_movi(struct kvm *kvm, struct vgic_its *its,struct its_ite *ite;struct its_collection *collection; +trace_vgic_its_cmd_movi (device_id, event_id, coll_id); + ite =find_ite (its, device_id, event_id);if (!ite)return E_ITS_MOVI_UNMAPPED_INTERRUPT ;
@@ -1035,6 +1040,8 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,struct vgic_irq *irq;int lpi_nr; +trace_vgic_its_cmd_mapi (device_id, event_id); + device =find_its_device (its, device_id);if (!device)return E_ITS_MAPTI_UNMAPPED_DEVICE ;
@@ -1161,6 +1168,8 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,struct its_device *device;gpa_t gpa; +trace_vgic_its_cmd_mapd (device_id, valid, num_eventid_bits, itt_addr); +if (!vgic_its_check_id (its, its->baser_device_table, device_id, &gpa))return E_ITS_MAPD_DEVICE_OOR ;
@@ -1204,6 +1213,8 @@ static int vgic_its_cmd_handle_mapc(struct kvm *kvm, struct vgic_its *its, valid =its_cmd_get_validbit (its_cmd); coll_id =its_cmd_get_collection (its_cmd); +trace_vgic_its_cmd_mapc (coll_id, valid); +if (!valid) {vgic_its_free_collection (its, coll_id);vgic_its_invalidate_cache (its);
@@ -1248,6 +1259,7 @@ static int vgic_its_cmd_handle_clear(struct kvm *kvm, struct vgic_its *its,u32 event_id =its_cmd_get_id (its_cmd);struct its_ite *ite; +trace_vgic_its_cmd_clear (device_id, event_id); ite =find_ite (its, device_id, event_id);if (!ite)
@@ -1278,6 +1290,7 @@ static int vgic_its_cmd_handle_inv(struct kvm *kvm, struct vgic_its *its,u32 event_id =its_cmd_get_id (its_cmd);struct its_ite *ite; +trace_vgic_its_cmd_inv (device_id, event_id); ite =find_ite (its, device_id, event_id);if (!ite)
@@ -1338,6 +1351,8 @@ static int vgic_its_cmd_handle_invall(struct kvm *kvm, struct vgic_its *its, vcpu =collection_to_vcpu (kvm, collection);vgic_its_invall (vcpu); +trace_vgic_its_cmd_invall (coll_id, vcpu->vcpu_id); +return 0 ; }
@@ -1364,6 +1379,8 @@ static int vgic_its_cmd_handle_movall(struct kvm *kvm, struct vgic_its *its,if (!vcpu1 || !vcpu2)return E_ITS_MOVALL_PROCNUM_OOR ; +trace_vgic_its_cmd_movall (vcpu1->vcpu_id, vcpu2->vcpu_id); +if (vcpu1 == vcpu2)return 0 ;
@@ -1392,6 +1409,8 @@ static int vgic_its_cmd_handle_int(struct kvm *kvm, struct vgic_its *its,u32 msi_data =its_cmd_get_id (its_cmd);u64 msi_devid =its_cmd_get_deviceid (its_cmd); +trace_vgic_its_cmd_int (msi_devid, msi_data); +return vgic_its_trigger_msi (kvm, its, msi_devid, msi_data); }
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog