Re: [PATCH] virt: vboxguest: send the heartbeat at the interval

From: Hans de Goede

Date: Tue Oct 27 2026 - 12:47:08 EST


Hi,

On 27-Oct-26 17:34, Greg Kroah-Hartman wrote:
> From: Josef Bacik <josef@xxxxxxxxxxxxxx>
>
> The host tells the guest how often it expects a heartbeat.
> vbg_heartbeat_timer() re-arms its timer with
>
> mod_timer(&gdev->heartbeat_timer, msecs_to_jiffies(interval));
>
> But the second argument of mod_timer() is a point in time, not a delay.
> An interval, taken as a point in time, lies in the past, so the timer
> expires again on the next tick. Whatever the host has asked for, the
> guest sends a heartbeat 100 to 1000 times a second, depending on HZ, and
> each of them is a request to the host, that is a VM exit from the timer
> softirq.
>
> On 32 bit, where jiffies starts five minutes before it wraps around,
> these small values lie in the future at first. That also goes for the 0
> with which vbg_heartbeat_init() means to start the timer at once: if the
> driver is loaded during boot, the first heartbeat is only sent five
> minutes after boot.
>
> Add jiffies in both places. Every VirtualBox guest now sends its
> heartbeat at the interval which the host has asked for.
>
> Fixes: 0ba002bc4393 ("virt: Add vboxguest driver for Virtual Box Guest integration")
> Cc: stable <stable@xxxxxxxxxx>
> Cc: Hans de Goede <hansg@xxxxxxxxxx>
> Cc: Arnd Bergmann <arnd@xxxxxxxx>
> Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <johannes.goede@xxxxxxxxxxxxxxxx>

Regards,

Hans


> ---
> drivers/virt/vboxguest/vboxguest_core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/virt/vboxguest/vboxguest_core.c b/drivers/virt/vboxguest/vboxguest_core.c
> index b5dc0d01facd..be6a8cc4e712 100644
> --- a/drivers/virt/vboxguest/vboxguest_core.c
> +++ b/drivers/virt/vboxguest/vboxguest_core.c
> @@ -422,7 +422,7 @@ static void vbg_heartbeat_timer(struct timer_list *t)
>
> vbg_req_perform(gdev, gdev->guest_heartbeat_req);
> mod_timer(&gdev->heartbeat_timer,
> - msecs_to_jiffies(gdev->heartbeat_interval_ms));
> + jiffies + msecs_to_jiffies(gdev->heartbeat_interval_ms));
> }
>
> /**
> @@ -482,7 +482,7 @@ static int vbg_heartbeat_init(struct vbg_dev *gdev)
>
> vbg_info("%s: Setting up heartbeat to trigger every %d milliseconds\n",
> __func__, gdev->heartbeat_interval_ms);
> - mod_timer(&gdev->heartbeat_timer, 0);
> + mod_timer(&gdev->heartbeat_timer, jiffies);
>
> return 0;
> }