On Wed 2026-11-18 01:01:49, Zack Rusin wrote:
> A VMware guest may be unable to save its own logs after a crash. Copy
> the newest kernel log records to the host's vmware.log before kdump,
> so they remain available if the capture kernel fails.
> 
> Register the sender on the platform panic notifier list and send the
> log through the low-bandwidth register interface. Allocate a fixed
> 8 KiB buffer during early init; 4 KiB can lose useful stack-trace
> context. The callback allocates no memory and emits no printk
> messages. Limit the transfer to the buffer size and make at most three
> attempts, retrying only if a VM checkpoint interrupts the transfer.
> 
> Enable logging by default only in guests without memory encryption;
> encrypted guests should send their log to the host only when an
> administrator opts in. The copy is best-effort diagnostics; kdump does
> not depend on it succeeding.
> 
> Suggested-by: Michael Kelley <[email protected]>
> Link: 
> https://lore.kernel.org/r/sn6pr02mb41574a11d309a0530c63e0fed4...@sn6pr02mb4157.namprd02.prod.outlook.com
> Link: 
> https://lore.kernel.org/r/[email protected]
> Co-developed-by: Bo Gan <[email protected]>
> Signed-off-by: Bo Gan <[email protected]>
> Co-developed-by: Alexey Makhalov <[email protected]>
> Signed-off-by: Alexey Makhalov <[email protected]>
> Signed-off-by: Zack Rusin <[email protected]>

I made just a quick review of the string manipulation and
kmsg_dump_get_buffer() API use. And it looks good to me:

Reviewed-by: Petr Mladek <[email protected]>

Note that I am not familiar with the vmware hypercalls so that
I did not check this part.

Some nits below.

> --- a/arch/x86/kernel/cpu/vmware.c
> +++ b/arch/x86/kernel/cpu/vmware.c
> @@ -52,6 +57,23 @@
> +#define VMWARE_LOG_BUF_SIZE          SZ_8K
> +#define VMWARE_LOG_ATTEMPTS          3
> +#define VMWARE_LOG_PREFIX            "log "
> +#define VMWARE_LOG_PREFIX_LEN                (sizeof(VMWARE_LOG_PREFIX) - 1)

[...]

> +static int vmware_log_send_once(const struct vmware_rpc_channel *channel,
> +                             const char *buffer, size_t length)
> +{
> +     u32 info;
> +
> +     vmware_hypercall5(VMWARE_CMD_MESSAGE | VMWARE_MSG_SENDSIZE, length,
> +                       (u32)channel->id << 16, channel->cookie_high,
> +                       channel->cookie_low, &info);
> +     if (!(info & VMWARE_MSG_STATUS_SUCCESS))
> +             return info & VMWARE_MSG_STATUS_CPT ? -EAGAIN : -EIO;
> +
> +     while (length) {
> +             size_t bytes = min_t(size_t, length, sizeof(u32));
> +             u32 word = 0;
> +
> +             memcpy(&word, buffer, bytes);
> +             vmware_hypercall5(VMWARE_CMD_MESSAGE | VMWARE_MSG_SENDPAYLOAD,
> +                               word, (u32)channel->id << 16,
> +                               channel->cookie_high, channel->cookie_low,
> +                               &info);
> +             if (!(info & VMWARE_MSG_STATUS_SUCCESS))
> +                     return info & VMWARE_MSG_STATUS_CPT ? -EAGAIN : -EIO;
> +
> +             buffer += bytes;
> +             length -= bytes;
> +     }
> +
> +     return 0;
> +}

[...]

> +static int vmware_panic_log_notify(struct notifier_block *nb,
> +                                unsigned long action, void *data)
> +{
> +     struct kmsg_dump_iter iter;
> +     char *buffer = page_address(vmware_panic_page);
> +     size_t length = 0;

I would add:

        BUILD_BUG_ON(VMWARE_LOG_PREFIX_LEN > VMWARE_LOG_BUF_SIZE);

just to be on the safe side.

> +
> +     if (!READ_ONCE(vmware_record_panic_msg))
> +             return NOTIFY_DONE;
> +
> +     memcpy(buffer, VMWARE_LOG_PREFIX, VMWARE_LOG_PREFIX_LEN);

I would feel more comfortable when the trailing '\0' gets copied as
well, e.g.

        strscpy(buffer, VMWARE_LOG_PREFIX);

It is not strictly needed because the length is counted
explicitly, strlen() is not used. Also vmware_log_rpc() does
not send the trailing '\0'.

So, it is a rather a defensive programming. The buffer might be handled
another way in the future, e.g. printed by some debug code, tracing, ...

> +     kmsg_dump_rewind(&iter);
> +     (void)kmsg_dump_get_buffer(&iter, true,
> +                                buffer + VMWARE_LOG_PREFIX_LEN,
> +                                VMWARE_LOG_BUF_SIZE - VMWARE_LOG_PREFIX_LEN,
> +                                &length);
> +     (void)vmware_log_rpc(buffer, length + VMWARE_LOG_PREFIX_LEN);
> +
> +     return NOTIFY_DONE;
> +}

Best Regards,
Petr

Reply via email to