From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.228 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794203284; b=BsQri1LkEhCVSBMP3EsjsdQSbiCfWBM8Ns5dKOKXMWxFaSLV0lcbq1j7LL6s/EHwsjKU oLFnp6LAGsm5K8L1UWbBDvS95aXz8iHnOnyCepTZykEFkUyLMY/fK376obevdLebKB8fS f1TGgJdGQLjqL6k/+P6SaimPc3tDzJuuTDcITALw7wVgotn/eJUFvK//NgnbqapY3plqQ wn0nZfvB+j8WNMbsEBSaN7n/2eLH+7JO2YEN1iZUuR57s6Q5mbTeFWzNxhkxImSKUD42W zldJoOY8OTnk0Q5G44kIlN5klj+022SvswLE63F/xgRH84KhtcJh55UBGsjrRK3di0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794203284; h=DMARC-Filter:Received:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:X-Relaying-Domain: X-CFilter-Loop:Received:DKIM-Signature:X-Forwarded-Encrypted: X-Received:X-Received:Received:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-DetectorID-Processed; bh=fCikukdkGrAry2ag7Gz1Hec9v7vR97JxYrqyoEYaoh0=; b=UpN2sdKyA/L821X2oBn2t54wv3t/oHSiTWyzxb/IeZqy47s05VJSX2sioov+48g5hJMS FqJ4djkB6LHteWlG0n/eIZCdjonDOzJSa3tyJnRX2tymaGtrLRvA/BQTWa4urwFSMG1vn idBz+hDLRUHi/7TF3AhXFXap3GnuNEdB8N+VjeYcb3pipHkDSAL7uTTbGj+9bL7kbrpgO a0BM8VhgPOd8K0ham7nNlHAt4Dxs01yVwq5M9aVJeXT2D93HPi0ewdyeaYUXItc97KEUx jm7re/lY+2vqMUfBQroaRAFxmBqRLWgFgYbR7Um6sWfvBBcprDq5XqRINlem5TPViBQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=FPp21O02; arc=none smtp.remote-ip=209.85.210.228 Received: from mail-pf1-f228.google.com (mail-pf1-f228.google.com [209.85.210.228]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3302606A338 for ; Mon, 9 Nov 2026 05:48:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F3302606A338 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=FPp21O02 Received: by mail-pf1-f228.google.com with SMTP id d2e1a72fcca58-8b6399ebb41so407652b3a.0 for ; Sun, 08 Nov 2026 21:48:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794203283; x=1794808083; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fCikukdkGrAry2ag7Gz1Hec9v7vR97JxYrqyoEYaoh0=; b=SJyEemAPN0xNlPzeVmqtqJGJJLjakBmcRgsmfuMxQAxqfJSCAYB88FNOuxYgfzi/cT 2Behdgou28LgiImKKKlFEar+Rd3Zu/IXd3XxiSMukx1JsQEAYPmfIld2Cslssib20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kRxR023fTIvIT 724bO5cS7aoHeCSLC4PNoCGPA4wklEpmXd X-Received: by 2002:a17:90b:264b:b0:3ac:a204:aa27 with SMTP id 98e67ed59e1d1-3b12d5e30acmr2705497a91.66.1794203283322; Sun, 08 Nov 2026 21:48:03 -0800 (PST) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-13.dlp.protect.broadcom.com. [144.49.247.13]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-3b1278f06b5sm2877853a91.6.2026.11.08.21.48.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2026 21:48:03 -0800 (PST) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-dl1-f70.google.com with SMTP id a92af1059eb24-1b0d864826cso543819c88.1 for ; Sun, 08 Nov 2026 21:48:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1794203281; x=1794808081; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fCikukdkGrAry2ag7Gz1Hec9v7vR97JxYrqyoEYaoh0=; b=FPp21O02cjdZQ3rislYQXVMHnHE/sJpRZv7bUYOUWuT1EuQxAiXAoxgK97cBfqiFED mpoIRkzZ97thkFEAyfD9gyCyDmxffmmcqsycPNm60escG47u8DD0sgfdUzTn93MtSfcW b3yFiWljccbo2/z6F/uTAzcEq9dJJcI41tGhk= X-Forwarded-Encrypted: i=1; AL+hErH/2CASa7+JZEiv83lJ/QFSvzAHf8JYBjp1r3bP9BuhbkDG+vN5Djn/mQPFpqZrVOmNvz72USfkLqBRGmE=@vger.kernel.org X-Received: by 2002:a05:7022:b052:20b0:1ae:abd0:e2b6 with SMTP id a92af1059eb24-1b39ff033c5mr5293307c88.38.1794203281084; Sun, 08 Nov 2026 21:48:01 -0800 (PST) X-Received: by 2002:a05:7022:b052:20b0:1ae:abd0:e2b6 with SMTP id a92af1059eb24-1b39ff033c5mr5293257c88.38.1794203280452; Sun, 08 Nov 2026 21:48:00 -0800 (PST) Received: from vertex.localdomain (pool-173-49-113-140.phlapa.fios.verizon.net. [173.49.113.140]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b37314626dsm13745136c88.1.2026.11.08.21.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Nov 2026 21:47:59 -0800 (PST) From: Zack Rusin To: Andrew Morton , Petr Mladek , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young Cc: Borislav Petkov , Ajay Kaher , Alexey Makhalov , x86@kernel.org, Joel Granados , Thomas Gleixner , Ingo Molnar , Dave Hansen , "H. Peter Anvin" , virtualization@lists.linux.dev, bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, John Ogness , Steven Rostedt , Sergey Senozhatsky , Kees Cook , Jonathan Corbet , Bo Gan , Brennan Lamoreaux , kexec@lists.infradead.org, linux-doc@vger.kernel.org, "Guilherme G. Piccoli" , Maaz Mombasawala , Shuah Khan , Randy Dunlap , Stephen Brennan , Michael Kelley , Ian Forbes , Bradley Morgan Subject: [PATCH v3 2/4] x86/vmware: Add a bounded panic log sender Date: Mon, 9 Nov 2026 00:47:38 -0500 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e 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 Link: https://lore.kernel.org/r/SN6PR02MB41574A11D309A0530C63E0FED4842@SN6PR02MB4157.namprd02.prod.outlook.com Link: https://lore.kernel.org/r/20260309235250.2611115-3-alexey.makhalov@broadcom.com Co-developed-by: Bo Gan Signed-off-by: Bo Gan Co-developed-by: Alexey Makhalov Signed-off-by: Alexey Makhalov Signed-off-by: Zack Rusin --- v3: Register on the platform list instead of the pre-kdump list. The VMware code is otherwise unchanged from v2. arch/x86/include/asm/vmware.h | 1 + arch/x86/kernel/cpu/vmware.c | 173 ++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 4220dae14a2d..598d4cd448ec 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -57,6 +57,7 @@ #define VMWARE_HYPERVISOR_MAGIC 0x564d5868U #define VMWARE_CMD_GETVERSION 10 +#define VMWARE_CMD_MESSAGE 30 #define VMWARE_CMD_GETHZ 45 #define VMWARE_CMD_GETVCPU_INFO 68 #define VMWARE_CMD_STEALCLOCK 91 diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index f7ab9e7902cf..0c6f7248a665 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -24,11 +24,16 @@ #include #include #include +#include +#include +#include #include #include #include #include +#include #include +#include #include #include #include @@ -52,6 +57,23 @@ #define STEALCLOCK_DISABLED 0 #define STEALCLOCK_ENABLED 1 +#define VMWARE_MSG_STATUS_SUCCESS BIT(16) +#define VMWARE_MSG_STATUS_CPT BIT(20) + +#define VMWARE_RPCI_PROTOCOL 0x49435052 +#define VMWARE_GUESTMSG_COOKIE BIT(31) + +#define VMWARE_MSG_TYPE(n) ((n) << 16) +#define VMWARE_MSG_OPEN VMWARE_MSG_TYPE(0U) +#define VMWARE_MSG_SENDSIZE VMWARE_MSG_TYPE(1U) +#define VMWARE_MSG_SENDPAYLOAD VMWARE_MSG_TYPE(2U) +#define VMWARE_MSG_CLOSE VMWARE_MSG_TYPE(6U) + +#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) + struct vmware_steal_time { union { u64 clock; /* stolen time counter in units of vtsc */ @@ -64,6 +86,12 @@ struct vmware_steal_time { u64 reserved[7]; }; +struct vmware_rpc_channel { + u16 id; + u32 cookie_high; + u32 cookie_low; +}; + static unsigned long vmware_tsc_khz __ro_after_init; static u8 vmware_hypercall_mode __ro_after_init; @@ -142,6 +170,151 @@ static unsigned long vmware_get_tsc_khz(void) return vmware_tsc_khz; } +static int vmware_log_open(struct vmware_rpc_channel *channel) +{ + u32 info, id; + + vmware_hypercall6(VMWARE_CMD_MESSAGE | VMWARE_MSG_OPEN, + VMWARE_RPCI_PROTOCOL | VMWARE_GUESTMSG_COOKIE, 0, + &info, &id, &channel->cookie_high, + &channel->cookie_low); + if (!(info & VMWARE_MSG_STATUS_SUCCESS)) + return -EIO; + + channel->id = upper_16_bits(id); + return 0; +} + +static int vmware_log_close(const struct vmware_rpc_channel *channel) +{ + u32 info; + + vmware_hypercall5(VMWARE_CMD_MESSAGE | VMWARE_MSG_CLOSE, 0, + (u32)channel->id << 16, channel->cookie_high, + channel->cookie_low, &info); + + return info & VMWARE_MSG_STATUS_SUCCESS ? 0 : -EIO; +} + +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_log_send(const struct vmware_rpc_channel *channel, + const char *buffer, size_t length) +{ + int attempt, ret; + + for (attempt = 0; attempt < VMWARE_LOG_ATTEMPTS; attempt++) { + ret = vmware_log_send_once(channel, buffer, length); + if (ret != -EAGAIN) + return ret; + } + + return -EAGAIN; +} + +static int vmware_log_rpc(const char *buffer, size_t length) +{ + struct vmware_rpc_channel channel; + int close_ret, ret; + + ret = vmware_log_open(&channel); + if (ret) + return ret; + + ret = vmware_log_send(&channel, buffer, length); + close_ret = vmware_log_close(&channel); + if (!ret && close_ret) + ret = close_ret; + + return ret; +} + +static struct page *vmware_panic_page; +static bool vmware_record_panic_msg; + +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; + + if (!READ_ONCE(vmware_record_panic_msg)) + return NOTIFY_DONE; + + memcpy(buffer, VMWARE_LOG_PREFIX, VMWARE_LOG_PREFIX_LEN); + 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; +} + +static struct notifier_block vmware_panic_log_nb = { + .notifier_call = vmware_panic_log_notify, +}; + +static int __init vmware_panic_log_init(void) +{ + int ret; + + if (!IS_ENABLED(CONFIG_PRINTK) || + !hypervisor_is_type(X86_HYPER_VMWARE)) + return 0; + + vmware_record_panic_msg = + !cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT); + + vmware_panic_page = alloc_pages(GFP_KERNEL, + get_order(VMWARE_LOG_BUF_SIZE)); + if (!vmware_panic_page) { + pr_err("failed to allocate panic log buffer\n"); + return 0; + } + + ret = atomic_notifier_chain_register(&panic_notifiers_platform_list, + &vmware_panic_log_nb); + if (ret) { + pr_err("failed to register panic log notifier: %d\n", ret); + __free_pages(vmware_panic_page, get_order(VMWARE_LOG_BUF_SIZE)); + vmware_panic_page = NULL; + } + + return 0; +} +early_initcall(vmware_panic_log_init); + #ifdef CONFIG_PARAVIRT static struct cyc2ns_data vmware_cyc2ns __ro_after_init; static bool vmw_sched_clock __initdata = true;