Hi

On Tue, Jun 30, 2026 at 10:24 AM yujun <[email protected]> wrote:
>
> When a SPICE client sends a VDAgentMonitorsConfig message with
> VD_AGENT_CONFIG_MONITORS_FLAG_PHYSICAL_SIZE set, vdagentd stores the
> full payload including the VDAgentMonitorMM entries. On agent reconnect,
> update_active_session_connection() forwards the cached configuration
> with a size that omits the physical size entries.
>
> Extract a monitors_config_size() helper and use it both when validating
> incoming client monitor configuration and when forwarding the cached
> configuration to a reconnecting agent.
>
> Fixes: 3660acf (Fix VDAGentMonitorConfig size calculation)
> Signed-off-by: yujun <[email protected]>

lgtm
Reviewed-by: Marc-André Lureau <[email protected]>

can you open a MR on gitlab:
https://gitlab.freedesktop.org/spice/linux/vd_agent/-/merge_requests

> ---
>  src/vdagentd/vdagentd.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
> index 27a6f15..5214df7 100644
> --- a/src/vdagentd/vdagentd.c
> +++ b/src/vdagentd/vdagentd.c
> @@ -136,6 +136,17 @@ static void virtio_msg_uint16_from_le(uint8_t *_msg, 
> uint32_t size, uint32_t off
>          msg[i] = GUINT16_FROM_LE(msg[i]);
>  }
>
> +static uint32_t monitors_config_size(const VDAgentMonitorsConfig *config)
> +{
> +    uint32_t size = sizeof(VDAgentMonitorsConfig) +
> +                    config->num_of_monitors * sizeof(VDAgentMonConfig);
> +
> +    if (config->flags & VD_AGENT_CONFIG_MONITORS_FLAG_PHYSICAL_SIZE) {
> +        size += config->num_of_monitors * sizeof(VDAgentMonitorMM);
> +    }
> +    return size;
> +}
> +
>  /* vdagentd <-> spice-client communication handling */
>  static void send_capabilities(VirtioPort *vport,
>      uint32_t request)
> @@ -206,11 +217,7 @@ static void do_client_monitors(VirtioPort *vport, int 
> port_nr,
>      uint32_t size;
>
>      /* Store monitor config to send to agents when they connect */
> -    size = sizeof(VDAgentMonitorsConfig) +
> -           new_monitors->num_of_monitors * sizeof(VDAgentMonConfig);
> -    if (new_monitors->flags & VD_AGENT_CONFIG_MONITORS_FLAG_PHYSICAL_SIZE) {
> -        size += new_monitors->num_of_monitors * sizeof(VDAgentMonitorMM);
> -    }
> +    size = monitors_config_size(new_monitors);
>      if (message_header->size != size) {
>          syslog(LOG_ERR, "invalid message size for VDAgentMonitorsConfig");
>          return;
> @@ -943,8 +950,7 @@ static void 
> update_active_session_connection(UdscsConnection *new_conn)
>
>      if (active_session_conn && mon_config)
>          udscs_write(active_session_conn, VDAGENTD_MONITORS_CONFIG, 0, 0,
> -                    (uint8_t *)mon_config, sizeof(VDAgentMonitorsConfig) +
> -                    mon_config->num_of_monitors * sizeof(VDAgentMonConfig));
> +                    (uint8_t *)mon_config, monitors_config_size(mon_config));
>
>      release_clipboards();
>
> --
> 2.25.1
>

Reply via email to