* [PATCH 1/2] x86/vmware: Log kmsg dump on panic
@ 2024-08-14 21:07 Alexey Makhalov
2024-08-14 21:07 ` [PATCH 2/2] x86/vmware: Fix steal time clock under SEV Alexey Makhalov
0 siblings, 1 reply; 5+ messages in thread
From: Alexey Makhalov @ 2024-08-14 21:07 UTC (permalink / raw)
To: linux-kernel, virtualization, bp, hpa, dave.hansen, mingo, tglx
Cc: x86, ajay.kaher, bo.gan, bcm-kernel-feedback-list, Alexey Makhalov
Improve debugability of VMware Linux guests by dumping
kernel messages during a panic to VM log file (vmware.log).
Co-developed-by: Bo Gan <bo.gan@broadcom.com>
Signed-off-by: Bo Gan <bo.gan@broadcom.com>
Signed-off-by: Alexey Makhalov <alexey.makhalov@broadcom.com>
---
arch/x86/include/asm/vmware.h | 1 +
arch/x86/kernel/cpu/vmware.c | 132 ++++++++++++++++++++++++++++++++++
2 files changed, 133 insertions(+)
diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h
index c9cf43d5ef23..433755b41a27 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 00189cdeb775..9883766715fe 100644
--- a/arch/x86/kernel/cpu/vmware.c
+++ b/arch/x86/kernel/cpu/vmware.c
@@ -28,6 +28,7 @@
#include <linux/cpu.h>
#include <linux/reboot.h>
#include <linux/static_call.h>
+#include <linux/kmsg_dump.h>
#include <asm/div64.h>
#include <asm/x86_init.h>
#include <asm/hypervisor.h>
@@ -139,6 +140,13 @@ static unsigned long vmware_get_tsc_khz(void)
return vmware_tsc_khz;
}
+static void kmsg_dumper_vmware_log(struct kmsg_dumper *dumper,
+ enum kmsg_dump_reason reason);
+
+static struct kmsg_dumper kmsg_dumper = {
+ .dump = kmsg_dumper_vmware_log
+};
+
#ifdef CONFIG_PARAVIRT
static struct cyc2ns_data vmware_cyc2ns __ro_after_init;
static bool vmw_sched_clock __initdata = true;
@@ -436,6 +444,8 @@ static void __init vmware_platform_setup(void)
#endif
vmware_set_capabilities();
+
+ kmsg_dump_register(&kmsg_dumper);
}
static u8 __init vmware_select_hypercall(void)
@@ -587,3 +597,125 @@ const __initconst struct hypervisor_x86 x86_hyper_vmware = {
.runtime.sev_es_hcall_finish = vmware_sev_es_hcall_finish,
#endif
};
+
+#define VMWARE_HB_CMD_MESSAGE 0
+#define MESSAGE_STATUS_SUCCESS (0x01 << 16)
+#define MESSAGE_STATUS_CPT (0x10 << 16)
+#define MESSAGE_STATUS_HB (0x80 << 16)
+
+#define RPCI_PROTOCOL_NUM 0x49435052 /* 'RPCI' */
+#define GUESTMSG_FLAG_COOKIE 0x80000000
+
+#define MESSAGE_TYPE_OPEN (0 << 16)
+#define MESSAGE_TYPE_SENDSIZE (1 << 16)
+#define MESSAGE_TYPE_SEND (2 << 16)
+#define MESSAGE_TYPE_CLOSE (6 << 16)
+
+struct vmw_msg {
+ u32 id;
+ u32 cookie_high;
+ u32 cookie_low;
+};
+
+static int
+vmware_log_open(struct vmw_msg *msg)
+{
+ u32 info;
+
+ vmware_hypercall6(VMWARE_CMD_MESSAGE | MESSAGE_TYPE_OPEN,
+ RPCI_PROTOCOL_NUM | GUESTMSG_FLAG_COOKIE,
+ 0, &info, &msg->id, &msg->cookie_high,
+ &msg->cookie_low);
+
+ if ((info & MESSAGE_STATUS_SUCCESS) == 0)
+ return 1;
+
+ msg->id &= 0xffff0000UL;
+ return 0;
+}
+
+static int
+vmware_log_close(struct vmw_msg *msg)
+{
+ u32 info;
+
+ vmware_hypercall5(VMWARE_CMD_MESSAGE | MESSAGE_TYPE_CLOSE, 0, msg->id,
+ msg->cookie_high, msg->cookie_low, &info);
+
+ if ((info & MESSAGE_STATUS_SUCCESS) == 0)
+ return 1;
+ return 0;
+}
+
+static int
+vmware_log_send(struct vmw_msg *msg, const char *string)
+{
+ u32 info;
+ u32 len = strlen(string);
+
+retry:
+ vmware_hypercall5(VMWARE_CMD_MESSAGE | MESSAGE_TYPE_SENDSIZE, len,
+ msg->id, msg->cookie_high, msg->cookie_low, &info);
+
+ if (!(info & MESSAGE_STATUS_SUCCESS))
+ return 1;
+
+ /* HB port can't access encrypted memory. */
+ if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT) && (info & MESSAGE_STATUS_HB)) {
+ vmware_hypercall_hb_out(
+ VMWARE_HB_CMD_MESSAGE | MESSAGE_STATUS_SUCCESS,
+ len, msg->id, (uintptr_t) string, msg->cookie_low,
+ msg->cookie_high, &info);
+ } else {
+ do {
+ u32 word;
+ size_t s = min_t(u32, len, sizeof(word));
+
+ memcpy(&word, string, s);
+ len -= s;
+ string += s;
+
+ vmware_hypercall5(VMWARE_CMD_MESSAGE | MESSAGE_TYPE_SEND,
+ word, msg->id, msg->cookie_high,
+ msg->cookie_low, &info);
+ } while (len && (info & MESSAGE_STATUS_SUCCESS));
+ }
+
+ if ((info & MESSAGE_STATUS_SUCCESS) == 0) {
+ if (info & MESSAGE_STATUS_CPT)
+ /* A checkpoint occurred. Retry. */
+ goto retry;
+ return 1;
+ }
+ return 0;
+}
+STACK_FRAME_NON_STANDARD(vmware_log_send);
+
+/**
+ * kmsg_dumper_vmware_log - dumps kmsg to vmware.log file on the host
+ */
+static void kmsg_dumper_vmware_log(struct kmsg_dumper *dumper,
+ enum kmsg_dump_reason reason)
+{
+ struct vmw_msg msg;
+ struct kmsg_dump_iter iter;
+ static char line[1024];
+ size_t len = 0;
+
+ /* Line prefix to send to VM log file. */
+ line[0] = 'l';
+ line[1] = 'o';
+ line[2] = 'g';
+ line[3] = ' ';
+
+ kmsg_dump_rewind(&iter);
+ while (kmsg_dump_get_line(&iter, true, line + 4, sizeof(line) - 4,
+ &len)) {
+ line[len + 4] = '\0';
+ if (vmware_log_open(&msg))
+ return;
+ if (vmware_log_send(&msg, line))
+ return;
+ vmware_log_close(&msg);
+ }
+}
--
2.39.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] x86/vmware: Fix steal time clock under SEV
2024-08-14 21:07 [PATCH 1/2] x86/vmware: Log kmsg dump on panic Alexey Makhalov
@ 2024-08-14 21:07 ` Alexey Makhalov
2024-08-15 10:58 ` kernel test robot
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Alexey Makhalov @ 2024-08-14 21:07 UTC (permalink / raw)
To: linux-kernel, virtualization, bp, hpa, dave.hansen, mingo, tglx
Cc: x86, ajay.kaher, bo.gan, bcm-kernel-feedback-list, Alexey Makhalov
Shared memory containing steal time counter should be set to
decrypted when SEV is active.
Co-developed-by: Bo Gan <bo.gan@broadcom.com>
Signed-off-by: Bo Gan <bo.gan@broadcom.com>
Signed-off-by: Alexey Makhalov <alexey.makhalov@broadcom.com>
---
arch/x86/kernel/cpu/vmware.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
index 9883766715fe..f20bdc3128f3 100644
--- a/arch/x86/kernel/cpu/vmware.c
+++ b/arch/x86/kernel/cpu/vmware.c
@@ -306,9 +306,30 @@ static struct notifier_block vmware_pv_reboot_nb = {
.notifier_call = vmware_pv_reboot_notify,
};
+static void __init sev_map_percpu_data(void)
+{
+ int cpu;
+
+ if (cc_vendor != CC_VENDOR_AMD ||
+ !cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
+ return;
+
+ for_each_possible_cpu(cpu) {
+ early_set_memory_decrypted(
+ (unsigned long)&per_cpu(vmw_steal_time, cpu),
+ sizeof(vmw_steal_time));
+ }
+}
+
#ifdef CONFIG_SMP
static void __init vmware_smp_prepare_boot_cpu(void)
{
+ /*
+ * Map the per-cpu variables as decrypted before vmware_guest_cpu_init()
+ * shares the guest physical address with the hypervisor.
+ */
+ sev_map_percpu_data();
+
vmware_guest_cpu_init();
native_smp_prepare_boot_cpu();
}
@@ -371,6 +392,7 @@ static void __init vmware_paravirt_ops_setup(void)
vmware_cpu_down_prepare) < 0)
pr_err("vmware_guest: Failed to install cpu hotplug callbacks\n");
#else
+ sev_map_percpu_data();
vmware_guest_cpu_init();
#endif
}
--
2.39.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] x86/vmware: Fix steal time clock under SEV
2024-08-14 21:07 ` [PATCH 2/2] x86/vmware: Fix steal time clock under SEV Alexey Makhalov
@ 2024-08-15 10:58 ` kernel test robot
2024-08-15 12:51 ` kernel test robot
2024-08-15 23:52 ` [PATCH v2 " Alexey Makhalov
2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2024-08-15 10:58 UTC (permalink / raw)
To: Alexey Makhalov, linux-kernel, virtualization, bp, hpa,
dave.hansen, mingo, tglx
Cc: llvm, oe-kbuild-all, x86, ajay.kaher, bo.gan,
bcm-kernel-feedback-list, Alexey Makhalov
Hi Alexey,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/x86/vmware]
[also build test ERROR on linus/master v6.11-rc3 next-20240815]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Alexey-Makhalov/x86-vmware-Fix-steal-time-clock-under-SEV/20240815-050918
base: tip/x86/vmware
patch link: https://lore.kernel.org/r/20240814210731.761010-2-alexey.makhalov%40broadcom.com
patch subject: [PATCH 2/2] x86/vmware: Fix steal time clock under SEV
config: i386-randconfig-003-20240815 (https://download.01.org/0day-ci/archive/20240815/202408151826.9369lzwV-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240815/202408151826.9369lzwV-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408151826.9369lzwV-lkp@intel.com/
All errors (new ones prefixed by >>):
>> arch/x86/kernel/cpu/vmware.c:313:6: error: use of undeclared identifier 'cc_vendor'
313 | if (cc_vendor != CC_VENDOR_AMD ||
| ^
>> arch/x86/kernel/cpu/vmware.c:313:19: error: use of undeclared identifier 'CC_VENDOR_AMD'
313 | if (cc_vendor != CC_VENDOR_AMD ||
| ^
2 errors generated.
vim +/cc_vendor +313 arch/x86/kernel/cpu/vmware.c
308
309 static void __init sev_map_percpu_data(void)
310 {
311 int cpu;
312
> 313 if (cc_vendor != CC_VENDOR_AMD ||
314 !cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
315 return;
316
317 for_each_possible_cpu(cpu) {
318 early_set_memory_decrypted(
319 (unsigned long)&per_cpu(vmw_steal_time, cpu),
320 sizeof(vmw_steal_time));
321 }
322 }
323
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] x86/vmware: Fix steal time clock under SEV
2024-08-14 21:07 ` [PATCH 2/2] x86/vmware: Fix steal time clock under SEV Alexey Makhalov
2024-08-15 10:58 ` kernel test robot
@ 2024-08-15 12:51 ` kernel test robot
2024-08-15 23:52 ` [PATCH v2 " Alexey Makhalov
2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2024-08-15 12:51 UTC (permalink / raw)
To: Alexey Makhalov, linux-kernel, virtualization, bp, hpa,
dave.hansen, mingo, tglx
Cc: oe-kbuild-all, x86, ajay.kaher, bo.gan, bcm-kernel-feedback-list,
Alexey Makhalov
Hi Alexey,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/x86/vmware]
[also build test ERROR on linus/master v6.11-rc3 next-20240815]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Alexey-Makhalov/x86-vmware-Fix-steal-time-clock-under-SEV/20240815-050918
base: tip/x86/vmware
patch link: https://lore.kernel.org/r/20240814210731.761010-2-alexey.makhalov%40broadcom.com
patch subject: [PATCH 2/2] x86/vmware: Fix steal time clock under SEV
config: i386-randconfig-001-20240815 (https://download.01.org/0day-ci/archive/20240815/202408152054.7LIuKvYe-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240815/202408152054.7LIuKvYe-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408152054.7LIuKvYe-lkp@intel.com/
All errors (new ones prefixed by >>):
arch/x86/kernel/cpu/vmware.c: In function 'sev_map_percpu_data':
>> arch/x86/kernel/cpu/vmware.c:313:13: error: 'cc_vendor' undeclared (first use in this function)
313 | if (cc_vendor != CC_VENDOR_AMD ||
| ^~~~~~~~~
arch/x86/kernel/cpu/vmware.c:313:13: note: each undeclared identifier is reported only once for each function it appears in
>> arch/x86/kernel/cpu/vmware.c:313:26: error: 'CC_VENDOR_AMD' undeclared (first use in this function); did you mean 'X86_VENDOR_AMD'?
313 | if (cc_vendor != CC_VENDOR_AMD ||
| ^~~~~~~~~~~~~
| X86_VENDOR_AMD
vim +/cc_vendor +313 arch/x86/kernel/cpu/vmware.c
308
309 static void __init sev_map_percpu_data(void)
310 {
311 int cpu;
312
> 313 if (cc_vendor != CC_VENDOR_AMD ||
314 !cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
315 return;
316
317 for_each_possible_cpu(cpu) {
318 early_set_memory_decrypted(
319 (unsigned long)&per_cpu(vmw_steal_time, cpu),
320 sizeof(vmw_steal_time));
321 }
322 }
323
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] x86/vmware: Fix steal time clock under SEV
2024-08-14 21:07 ` [PATCH 2/2] x86/vmware: Fix steal time clock under SEV Alexey Makhalov
2024-08-15 10:58 ` kernel test robot
2024-08-15 12:51 ` kernel test robot
@ 2024-08-15 23:52 ` Alexey Makhalov
2 siblings, 0 replies; 5+ messages in thread
From: Alexey Makhalov @ 2024-08-15 23:52 UTC (permalink / raw)
To: linux-kernel, virtualization, bp, hpa, dave.hansen, mingo, tglx
Cc: x86, ajay.kaher, bo.gan, bcm-kernel-feedback-list, Alexey Makhalov
Shared memory containing steal time counter should be set to
decrypted when SEV is active.
Co-developed-by: Bo Gan <bo.gan@broadcom.com>
Signed-off-by: Bo Gan <bo.gan@broadcom.com>
Signed-off-by: Alexey Makhalov <alexey.makhalov@broadcom.com>
---
arch/x86/kernel/cpu/vmware.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
index 9883766715fe..b4e57d6ec2f5 100644
--- a/arch/x86/kernel/cpu/vmware.c
+++ b/arch/x86/kernel/cpu/vmware.c
@@ -36,6 +36,7 @@
#include <asm/apic.h>
#include <asm/vmware.h>
#include <asm/svm.h>
+#include <asm/coco.h>
#undef pr_fmt
#define pr_fmt(fmt) "vmware: " fmt
@@ -306,9 +307,30 @@ static struct notifier_block vmware_pv_reboot_nb = {
.notifier_call = vmware_pv_reboot_notify,
};
+static void __init sev_map_percpu_data(void)
+{
+ int cpu;
+
+ if (cc_vendor != CC_VENDOR_AMD ||
+ !cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
+ return;
+
+ for_each_possible_cpu(cpu) {
+ early_set_memory_decrypted(
+ (unsigned long)&per_cpu(vmw_steal_time, cpu),
+ sizeof(vmw_steal_time));
+ }
+}
+
#ifdef CONFIG_SMP
static void __init vmware_smp_prepare_boot_cpu(void)
{
+ /*
+ * Map the per-cpu variables as decrypted before vmware_guest_cpu_init()
+ * shares the guest physical address with the hypervisor.
+ */
+ sev_map_percpu_data();
+
vmware_guest_cpu_init();
native_smp_prepare_boot_cpu();
}
@@ -371,6 +393,7 @@ static void __init vmware_paravirt_ops_setup(void)
vmware_cpu_down_prepare) < 0)
pr_err("vmware_guest: Failed to install cpu hotplug callbacks\n");
#else
+ sev_map_percpu_data();
vmware_guest_cpu_init();
#endif
}
--
2.39.4
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-08-15 23:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-14 21:07 [PATCH 1/2] x86/vmware: Log kmsg dump on panic Alexey Makhalov
2024-08-14 21:07 ` [PATCH 2/2] x86/vmware: Fix steal time clock under SEV Alexey Makhalov
2024-08-15 10:58 ` kernel test robot
2024-08-15 12:51 ` kernel test robot
2024-08-15 23:52 ` [PATCH v2 " Alexey Makhalov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®