From: Qiang Liu <[email protected]> When the guest responds unexpectedly to balloon resize requests, the actual applied delta cannot be observed from the guest side.
Add a "virtio_balloon" trace system with three tracepoints: config_change (target / resulting size / delta), and inflate and deflate (requested / applied page units / resulting size). Signed-off-by: Qiang Liu <[email protected]> --- MAINTAINERS | 1 + drivers/virtio/virtio_balloon.c | 13 ++++ include/trace/events/virtio_balloon.h | 87 +++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 include/trace/events/virtio_balloon.h diff --git a/MAINTAINERS b/MAINTAINERS index e4ca41cdd872..0ef6f34471de 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -29590,6 +29590,7 @@ M: David Hildenbrand <[email protected]> L: [email protected] S: Maintained F: drivers/virtio/virtio_balloon.c +F: include/trace/events/virtio_balloon.h F: include/uapi/linux/virtio_balloon.h VIRTIO BLOCK AND SCSI DRIVERS diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index ab3e3d887e00..2d0b16383661 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -19,6 +19,8 @@ #include <linux/wait.h> #include <linux/mm.h> #include <linux/page_reporting.h> +#define CREATE_TRACE_POINTS +#include <trace/events/virtio_balloon.h> /* * Balloon device works in 4K page units. So each page is pointed to by @@ -285,6 +287,8 @@ static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num) /* Did we get any? */ if (vb->num_pfns != 0) tell_host(vb, vb->inflate_vq); + + trace_virtio_balloon_inflate(num, num_allocated_pages, vb->num_pages); mutex_unlock(&vb->balloon_lock); return num_allocated_pages; @@ -333,6 +337,8 @@ static unsigned int leak_balloon(struct virtio_balloon *vb, size_t num) if (vb->num_pfns != 0) tell_host(vb, vb->deflate_vq); release_pages_balloon(vb, &pages); + + trace_virtio_balloon_deflate(num, num_freed_pages, vb->num_pages); mutex_unlock(&vb->balloon_lock); return num_freed_pages; } @@ -567,11 +573,18 @@ static void update_balloon_size_func(struct work_struct *work) diff = towards_target(vb); if (diff) { + unsigned long target = vb->num_pages + diff; + unsigned long before = vb->num_pages; + if (diff > 0) diff -= fill_balloon(vb, diff); else diff += leak_balloon(vb, -diff); update_balloon_size(vb); + + trace_virtio_balloon_config_change(target, vb->num_pages, + (long)vb->num_pages - + (long)before); } if (diff) diff --git a/include/trace/events/virtio_balloon.h b/include/trace/events/virtio_balloon.h new file mode 100644 index 000000000000..f733fc360d8b --- /dev/null +++ b/include/trace/events/virtio_balloon.h @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM virtio_balloon + +#if !defined(_TRACE_VIRTIO_BALLOON_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_VIRTIO_BALLOON_H + +#include <linux/tracepoint.h> + +/* + * All page counts reported by these events are in balloon page units, i.e. + * the 4K units the virtio balloon device operates on. Divide by + * VIRTIO_BALLOON_PAGES_PER_PAGE to obtain the number of guest pages. + */ + +TRACE_EVENT(virtio_balloon_config_change, + + TP_PROTO(unsigned long target, unsigned long num_pages, long delta), + + TP_ARGS(target, num_pages, delta), + + TP_STRUCT__entry( + __field(unsigned long, target) + __field(unsigned long, num_pages) + __field(long, delta) + ), + + TP_fast_assign( + __entry->target = target; + __entry->num_pages = num_pages; + __entry->delta = delta; + ), + + TP_printk("target=%lu num_pages=%lu delta=%ld", + __entry->target, __entry->num_pages, __entry->delta) +); + +TRACE_EVENT(virtio_balloon_inflate, + + TP_PROTO(unsigned long requested, unsigned long inflated, + unsigned long num_pages), + + TP_ARGS(requested, inflated, num_pages), + + TP_STRUCT__entry( + __field(unsigned long, requested) + __field(unsigned long, inflated) + __field(unsigned long, num_pages) + ), + + TP_fast_assign( + __entry->requested = requested; + __entry->inflated = inflated; + __entry->num_pages = num_pages; + ), + + TP_printk("requested=%lu inflated=%lu num_pages=%lu", + __entry->requested, __entry->inflated, __entry->num_pages) +); + +TRACE_EVENT(virtio_balloon_deflate, + + TP_PROTO(unsigned long requested, unsigned long deflated, + unsigned long num_pages), + + TP_ARGS(requested, deflated, num_pages), + + TP_STRUCT__entry( + __field(unsigned long, requested) + __field(unsigned long, deflated) + __field(unsigned long, num_pages) + ), + + TP_fast_assign( + __entry->requested = requested; + __entry->deflated = deflated; + __entry->num_pages = num_pages; + ), + + TP_printk("requested=%lu deflated=%lu num_pages=%lu", + __entry->requested, __entry->deflated, __entry->num_pages) +); + +#endif /* _TRACE_VIRTIO_BALLOON_H */ + +/* This part must be outside protection */ +#include <trace/define_trace.h> -- 2.43.0 No virus found Checked by Hillstone Network AntiVirus
