Browse code

linux,linux-esx: kmsg dumper to vmware.log NFS client do not bind reserved ports

Change-Id: I4ee944da640e30d3a6073581940166f99bd1495e
Reviewed-on: http://photon-jenkins.eng.vmware.com/670
Tested-by: jenkins-photon <wangnan2015@hotmail.com>
Reviewed-by: Sharath George

Alexey Makhalov authored on 2016/03/30 10:15:31
Showing 5 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 From d5e7229bec41406a4040a1ac9131e24cb1f8768d Mon Sep 17 00:00:00 2001
2 2
 From: Alexey Makhalov <amakhalov@vmware.com>
3 3
 Date: Wed, 30 Sep 2015 23:00:00 +0000
4
-Subject: [PATCH 01/11] Measure correct boot time.
4
+Subject: [PATCH 01/12] Measure correct boot time.
5 5
 
6 6
 ---
7 7
  arch/x86/Kconfig          |  8 ++++++++
... ...
@@ -98,7 +98,7 @@ index 5650655..c386186 100644
98 98
 From 500436e32d4dffae5d78f12be72c2e6784ab8cfb Mon Sep 17 00:00:00 2001
99 99
 From: Alexey Makhalov <amakhalov@vmware.com>
100 100
 Date: Fri, 2 Oct 2015 20:00:06 +0000
101
-Subject: [PATCH 02/11] PV io_delay for VMware guest.
101
+Subject: [PATCH 02/12] PV io_delay for VMware guest.
102 102
 
103 103
 ---
104 104
  arch/x86/kernel/cpu/vmware.c | 13 +++++++++++++
... ...
@@ -149,7 +149,7 @@ index 628a059..8fdd031 100644
149 149
 From adff5db39b45d8adef2b4579ec46ab1bb721a81f Mon Sep 17 00:00:00 2001
150 150
 From: Alexey Makhalov <amakhalov@vmware.com>
151 151
 Date: Wed, 7 Oct 2015 22:53:18 +0000
152
-Subject: [PATCH 03/11] Improved tsc based sched_clock & clocksource.
152
+Subject: [PATCH 03/12] Improved tsc based sched_clock & clocksource.
153 153
 
154 154
 ---
155 155
  arch/x86/Kconfig             |  1 +
... ...
@@ -327,7 +327,7 @@ index c0a2051..284a7ba 100644
327 327
 From 3bd5760c3b1f6cb39568361561d7d1e5440f1109 Mon Sep 17 00:00:00 2001
328 328
 From: Alexey Makhalov <amakhalov@vmware.com>
329 329
 Date: Mon, 12 Oct 2015 22:43:38 +0000
330
-Subject: [PATCH 04/11] Move read_boot_clock64 into pv_time_ops.
330
+Subject: [PATCH 04/12] Move read_boot_clock64 into pv_time_ops.
331 331
 
332 332
 ---
333 333
  arch/x86/Kconfig                      | 14 ++++++--
... ...
@@ -635,7 +635,7 @@ index 284a7ba..615aeb4 100644
635 635
 From aa93eaec3f709633007ab6ce3ddbb8aaa455b557 Mon Sep 17 00:00:00 2001
636 636
 From: Alexey Makhalov <amakhalov@vmware.com>
637 637
 Date: Thu, 5 Nov 2015 21:02:52 +0000
638
-Subject: [PATCH 05/11] Fix clocksource_vmware issue in VM version <= 10
638
+Subject: [PATCH 05/12] Fix clocksource_vmware issue in VM version <= 10
639 639
 
640 640
 ---
641 641
  arch/x86/kernel/cpu/vmware.c | 48 +++++++++++++++++++++++++++++++++++++++++---
... ...
@@ -733,7 +733,7 @@ index 1bf1fe3..0b89bb9 100644
733 733
 From 245c6ff168fabde177b5b6023356b6005b0efbef Mon Sep 17 00:00:00 2001
734 734
 From: Alexey Makhalov <amakhalov@vmware.com>
735 735
 Date: Tue, 10 Nov 2015 11:46:57 +0000
736
-Subject: [PATCH 06/11] Get lapic timer frequency from HV, skip calibration
736
+Subject: [PATCH 06/12] Get lapic timer frequency from HV, skip calibration
737 737
 
738 738
 ---
739 739
  arch/x86/kernel/cpu/vmware.c | 48 +++++---------------------------------------
... ...
@@ -823,7 +823,7 @@ index 0b89bb9..b16618b 100644
823 823
 From 23055114ca27a04044ebbe38853834e0aa869da0 Mon Sep 17 00:00:00 2001
824 824
 From: Alexey Makhalov <amakhalov@vmware.com>
825 825
 Date: Tue, 15 Dec 2015 21:31:18 +0000
826
-Subject: [PATCH 07/11] Skip rdrand reseed
826
+Subject: [PATCH 07/12] Skip rdrand reseed
827 827
 
828 828
 ---
829 829
  arch/x86/kernel/cpu/common.c | 2 ++
... ...
@@ -868,7 +868,7 @@ index 136ac74..0685891 100644
868 868
 From bd806a16d202bf9dc41fbe3f8e39545e704adf9e Mon Sep 17 00:00:00 2001
869 869
 From: Alexey Makhalov <amakhalov@vmware.com>
870 870
 Date: Thu, 3 Dec 2015 00:46:46 +0000
871
-Subject: [PATCH 08/11] STA implementation. first version.
871
+Subject: [PATCH 08/12] STA implementation. first version.
872 872
 
873 873
 ---
874 874
  arch/x86/kernel/cpu/vmware.c | 163 +++++++++++++++++++++++++++++++++++++++++++
... ...
@@ -1093,7 +1093,7 @@ index b16618b..cf1fb64 100644
1093 1093
 From 8496145f4f5fcd430e5d8f493066a8e54aaaf96b Mon Sep 17 00:00:00 2001
1094 1094
 From: Alexey Makhalov <amakhalov@vmware.com>
1095 1095
 Date: Wed, 13 Jan 2016 22:54:04 +0000
1096
-Subject: [PATCH 09/11] STA. updated version
1096
+Subject: [PATCH 09/12] STA. updated version
1097 1097
 
1098 1098
 ---
1099 1099
  arch/x86/kernel/cpu/vmware.c | 34 ++++++++++++++++++++++++----------
... ...
@@ -1182,7 +1182,7 @@ index cf1fb64..196703c 100644
1182 1182
 From a8f165433de453994aef84a9d6bf1704a18b3a95 Mon Sep 17 00:00:00 2001
1183 1183
 From: Alexey Makhalov <amakhalov@vmware.com>
1184 1184
 Date: Tue, 15 Mar 2016 22:29:23 +0000
1185
-Subject: [PATCH 10/11] STA: version with a single backdoor command.
1185
+Subject: [PATCH 10/12] STA: version with a single backdoor command.
1186 1186
 
1187 1187
 ---
1188 1188
  arch/x86/kernel/cpu/vmware.c | 35 +++++++++++++++--------------------
... ...
@@ -1273,7 +1273,7 @@ index 196703c..743b8ad 100644
1273 1273
 From 27b9b08cf68f55fbfa297eb047f7d1309e0a60cf Mon Sep 17 00:00:00 2001
1274 1274
 From: Alexey Makhalov <amakhalov@vmware.com>
1275 1275
 Date: Fri, 25 Mar 2016 01:14:17 +0000
1276
-Subject: [PATCH 11/11] Remove delays for smpboot
1276
+Subject: [PATCH 11/12] Remove delays for smpboot
1277 1277
 
1278 1278
 ---
1279 1279
  arch/x86/kernel/smpboot.c | 6 +++---
... ...
@@ -1313,3 +1313,196 @@ index b1f3ed9..8f0be52 100644
1313 1313
 -- 
1314 1314
 1.9.1
1315 1315
 
1316
+
1317
+From 3fe2ad9c5031e059849ba0970ccee95ce07f8239 Mon Sep 17 00:00:00 2001
1318
+From: Alexey Makhalov <amakhalov@vmware.com>
1319
+Date: Tue, 29 Mar 2016 21:14:46 +0000
1320
+Subject: [PATCH 12/12] kmsg_dumper to vmware.log
1321
+
1322
+---
1323
+ arch/x86/kernel/cpu/vmware.c | 143 +++++++++++++++++++++++++++++++++++++++++--
1324
+ 1 file changed, 139 insertions(+), 4 deletions(-)
1325
+
1326
+diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
1327
+index 743b8ad..e9f7d52 100644
1328
+--- a/arch/x86/kernel/cpu/vmware.c
1329
+@@ -30,10 +30,12 @@
1330
+ #include <linux/sched.h>
1331
+ #include <linux/cpu.h>
1332
+ #include <asm/pci_x86.h>
1333
++#include <linux/kmsg_dump.h>
1334
+ 
1335
+-#define CPUID_VMWARE_INFO_LEAF	0x40000000
1336
+-#define VMWARE_HYPERVISOR_MAGIC	0x564D5868
1337
+-#define VMWARE_HYPERVISOR_PORT	0x5658
1338
++#define CPUID_VMWARE_INFO_LEAF		0x40000000
1339
++#define VMWARE_HYPERVISOR_MAGIC		0x564D5868
1340
++#define VMWARE_HYPERVISOR_PORT		0x5658
1341
++#define VMWARE_HYPERVISOR_HB_PORT	0x5659
1342
+ 
1343
+ #define VMWARE_PORT_CMD_GETVERSION	10
1344
+ #define VMWARE_PORT_CMD_GETHZ		45
1345
+@@ -44,7 +46,8 @@
1346
+ # define STEALCLOCK_IS_NOT_AVALIABLE	-1
1347
+ # define STEALCLOCK_IS_DISABLED		0
1348
+ # define STEALCLOCK_IS_ENABLED		1
1349
+-
1350
++#define VMWARE_PORT_CMD_MESSAGE		30
1351
++#define VMWARE_HB_PORT_CMD_MESSAGE	0
1352
+ 
1353
+ #define VMWARE_PORT(cmd, eax, ebx, ecx, edx)				\
1354
+ 	VMWARE_PORT2(cmd, eax, ebx, ecx, edx, UINT_MAX)
1355
+@@ -303,6 +306,13 @@ static void __init paravirt_ops_setup(void)
1356
+ 
1357
+ }
1358
+ 
1359
++static void kmsg_dumper_vmware_log(struct kmsg_dumper *dumper,
1360
++				enum kmsg_dump_reason reason);
1361
++
1362
++static struct kmsg_dumper kmsg_dumper = {
1363
++	.dump = kmsg_dumper_vmware_log
1364
++};
1365
++
1366
+ static void __init vmware_platform_setup(void)
1367
+ {
1368
+ 	uint32_t eax, ebx, ecx, edx;
1369
+@@ -348,6 +358,7 @@ static void __init vmware_platform_setup(void)
1370
+ 	/* PCI BIOS service won't work from a PV guest. */
1371
+ 	pci_probe &= ~PCI_PROBE_BIOS;
1372
+ #endif
1373
++	kmsg_dump_register(&kmsg_dumper);
1374
+ }
1375
+ 
1376
+ /*
1377
+@@ -410,3 +421,127 @@ const __refconst struct hypervisor_x86 x86_hyper_vmware = {
1378
+ 	.x2apic_available	= vmware_legacy_x2apic_available,
1379
+ };
1380
+ EXPORT_SYMBOL(x86_hyper_vmware);
1381
++
1382
++#define MESSAGE_STATUS_SUCCESS  (0x01 << 16)
1383
++#define MESSAGE_STATUS_CPT      (0x10 << 16)
1384
++#define MESSAGE_STATUS_HB       (0x80 << 16)
1385
++
1386
++#define RPCI_PROTOCOL_NUM       0x49435052 /* 'RPCI' */
1387
++#define GUESTMSG_FLAG_COOKIE    0x80000000
1388
++
1389
++#define MESSAGE_TYPE_OPEN	(0 << 16)
1390
++#define MESSAGE_TYPE_SENDSIZE	(1 << 16)
1391
++#define MESSAGE_TYPE_CLOSE	(6 << 16)
1392
++
1393
++typedef struct {
1394
++	uint32_t id;
1395
++	uint32_t cookieHigh;
1396
++	uint32_t cookieLow;
1397
++} vmw_msg;
1398
++
1399
++static int
1400
++vmware_log_open(vmw_msg *msg) {
1401
++	uint32_t result, info, dx, si, di;
1402
++	__asm__ __volatile__ ("inl (%%dx)"
1403
++		:	"=a" (result),
1404
++			"=c" (info),
1405
++			"=d" (dx),
1406
++			"=S" (si),
1407
++			"=D" (di)
1408
++		:       "a"  (VMWARE_HYPERVISOR_MAGIC),
1409
++			"c"  (VMWARE_PORT_CMD_MESSAGE | MESSAGE_TYPE_OPEN),
1410
++			"d"  (VMWARE_HYPERVISOR_PORT),
1411
++			"b"  (RPCI_PROTOCOL_NUM | GUESTMSG_FLAG_COOKIE));
1412
++
1413
++	if ((info & MESSAGE_STATUS_SUCCESS) == 0)
1414
++		return 1;
1415
++
1416
++	msg->id = dx & 0xffff0000;
1417
++	msg->cookieHigh = si;
1418
++	msg->cookieLow = di;
1419
++	return 0;
1420
++}
1421
++
1422
++static int
1423
++vmware_log_close(vmw_msg *msg) {
1424
++	uint32_t result, info;
1425
++	__asm__ __volatile__ ("inl (%%dx)"
1426
++		:	"=a" (result),
1427
++			"=c" (info)
1428
++		:       "a"  (VMWARE_HYPERVISOR_MAGIC),
1429
++			"c"  (VMWARE_PORT_CMD_MESSAGE | MESSAGE_TYPE_CLOSE),
1430
++			"d"  (VMWARE_HYPERVISOR_PORT | msg->id),
1431
++			"b"  (0),
1432
++			"S"  (msg->cookieHigh),
1433
++			"D"  (msg->cookieLow));
1434
++
1435
++	if ((info & MESSAGE_STATUS_SUCCESS) == 0)
1436
++		return 1;
1437
++	return 0;
1438
++}
1439
++
1440
++static int
1441
++vmware_log_send(vmw_msg *msg, const char *string) {
1442
++	uint32_t result, info;
1443
++	uint32_t len = strlen(string);
1444
++
1445
++retry:
1446
++	__asm__ __volatile__ ("inl (%%dx)"
1447
++		:	"=a" (result),
1448
++			"=c" (info)
1449
++		:       "a"  (VMWARE_HYPERVISOR_MAGIC),
1450
++			"c"  (VMWARE_PORT_CMD_MESSAGE | MESSAGE_TYPE_SENDSIZE),
1451
++			"d"  (VMWARE_HYPERVISOR_PORT | msg->id),
1452
++			"b"  (len),
1453
++			"S"  (msg->cookieHigh),
1454
++			"D"  (msg->cookieLow));
1455
++
1456
++	if ((info & MESSAGE_STATUS_SUCCESS) == 0 ||
1457
++	    (info & MESSAGE_STATUS_HB) == 0)
1458
++		/* Expected success + high-bandwidth. Give up. */
1459
++		return 1;
1460
++
1461
++	__asm__ __volatile__ ("pushq %%rbp\n\t"
1462
++			      "movl %[rbp], %%ebp\n\t"
1463
++			      "cld\n\t"
1464
++			      "rep; outsb\n\t"
1465
++			      "popq %%rbp\n\t"
1466
++		:	"=a" (result),
1467
++			"=b" (info)
1468
++		:       "a"  (VMWARE_HYPERVISOR_MAGIC),
1469
++			"c"  (len),
1470
++			"d"  (VMWARE_HYPERVISOR_HB_PORT | msg->id),
1471
++			"b"  (VMWARE_HB_PORT_CMD_MESSAGE | MESSAGE_STATUS_SUCCESS),
1472
++			"S"  (string),
1473
++		  [rbp] "r"  (msg->cookieHigh),
1474
++			"D"  (msg->cookieLow));
1475
++
1476
++	if ((info & MESSAGE_STATUS_SUCCESS) == 0) {
1477
++		if (info & MESSAGE_STATUS_CPT)
1478
++			/* A checkpoint occurred. Retry. */
1479
++			goto retry;
1480
++		return 1;
1481
++	}
1482
++	return 0;
1483
++}
1484
++
1485
++static void kmsg_dumper_vmware_log(struct kmsg_dumper *dumper,
1486
++				enum kmsg_dump_reason reason)
1487
++{
1488
++	vmw_msg msg;
1489
++	static char line[1024];
1490
++	size_t len = 0;
1491
++
1492
++	line[0] = 'l';
1493
++	line[1] = 'o';
1494
++	line[2] = 'g';
1495
++	line[3] = ' ';
1496
++
1497
++	while (kmsg_dump_get_line(dumper, true, line + 4, sizeof(line) - 4, &len)) {
1498
++		line[len + 4] = '\0';
1499
++		if (vmware_log_open(&msg) ||
1500
++		    vmware_log_send(&msg, line) ||
1501
++		    vmware_log_close(&msg))
1502
++			break;
1503
++	}
1504
++}
1505
+-- 
1506
+1.9.1
1507
+
1316 1508
new file mode 100644
... ...
@@ -0,0 +1,46 @@
0
+From ffc0634118254dde4449900a65fc8bdb3d7a52d0 Mon Sep 17 00:00:00 2001
1
+From: Alexey Makhalov <amakhalov@vmware.com>
2
+Date: Fri, 25 Mar 2016 21:51:12 +0000
3
+Subject: [PATCH] sunrpc: xs_bind uses ip_local_reserved_ports
4
+
5
+---
6
+ net/sunrpc/xprtsock.c | 7 ++++++-
7
+ 1 file changed, 6 insertions(+), 1 deletion(-)
8
+
9
+diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
10
+index 0030376..c58db46 100644
11
+--- a/net/sunrpc/xprtsock.c
12
+@@ -1690,9 +1690,11 @@ static unsigned short xs_next_srcport(struct sock_xprt *transport, unsigned shor
13
+ static int xs_bind(struct sock_xprt *transport, struct socket *sock)
14
+ {
15
+ 	struct sockaddr_storage myaddr;
16
+-	int err, nloop = 0;
17
++	int err = -EADDRINUSE;
18
++	int nloop = 0;
19
+ 	unsigned short port = xs_get_srcport(transport);
20
+ 	unsigned short last;
21
++	struct net *net = transport->xprt.xprt_net;
22
+ 
23
+ 	/*
24
+ 	 * If we are asking for any ephemeral port (i.e. port == 0 &&
25
+@@ -1714,6 +1716,8 @@ static int xs_bind(struct sock_xprt *transport, struct socket *sock)
26
+ 
27
+ 	memcpy(&myaddr, &transport->srcaddr, transport->xprt.addrlen);
28
+ 	do {
29
++		if (inet_is_local_reserved_port(net, port))
30
++			goto next_port;
31
+ 		rpc_set_port((struct sockaddr *)&myaddr, port);
32
+ 		err = kernel_bind(sock, (struct sockaddr *)&myaddr,
33
+ 				transport->xprt.addrlen);
34
+@@ -1721,6 +1725,7 @@ static int xs_bind(struct sock_xprt *transport, struct socket *sock)
35
+ 			transport->srcport = port;
36
+ 			break;
37
+ 		}
38
++next_port:
39
+ 		last = port;
40
+ 		port = xs_next_srcport(transport, port);
41
+ 		if (port > last)
42
+-- 
43
+1.9.1
44
+
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:       Kernel
3 3
 Name:          linux-esx
4 4
 Version:       4.2.0
5
-Release:       18%{?dist}
5
+Release:       19%{?dist}
6 6
 License:       GPLv2
7 7
 URL:           http://www.kernel.org/
8 8
 Group:         System Environment/Kernel
... ...
@@ -25,6 +25,7 @@ Patch10:       02-pci-probe.patch
25 25
 Patch11:       03-poweroff.patch
26 26
 Patch12:       04-quiet-boot.patch
27 27
 Patch13:       05-pv-ops.patch
28
+Patch14:       06-sunrpc.patch
28 29
 BuildRequires: bc 
29 30
 BuildRequires: kbd
30 31
 BuildRequires: kmod
... ...
@@ -73,6 +74,7 @@ The Linux package contains the Linux kernel doc files
73 73
 %patch11 -p1
74 74
 %patch12 -p1
75 75
 %patch13 -p1
76
+%patch14 -p1
76 77
 
77 78
 %build
78 79
 make mrproper
... ...
@@ -138,6 +140,9 @@ ln -sf %{name}-%{version}-%{release}.cfg /boot/photon.cfg
138 138
 /usr/src/%{name}-headers-%{version}-%{release}
139 139
 
140 140
 %changelog
141
+*   Tue Mar 29 2016 Alexey Makhalov <amakhalov@vmware.com> 4.2.0-19
142
+-   Support kmsg dumping to vmware.log on panic
143
+-   sunrpc: xs_bind uses ip_local_reserved_ports
141 144
 *   Thu Mar 24 2016 Alexey Makhalov <amakhalov@vmware.com> 4.2.0-18
142 145
 -   Apply photon8 config (+stack protector regular)
143 146
 -   pv-ops patch: added STA support
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:        Kernel
3 3
 Name:           linux
4 4
 Version:    	4.2.0
5
-Release:    	23%{?dist}
5
+Release:    	24%{?dist}
6 6
 License:    	GPLv2
7 7
 URL:        	http://www.kernel.org/
8 8
 Group:        	System Environment/Kernel
... ...
@@ -20,6 +20,8 @@ Patch5:         sysctl-sched_weighted_cpuload_uses_rla.patch
20 20
 Patch6:         watchdog-Disable-watchdog-on-virtual-machines.patch
21 21
 Patch7:         SUNRPC-Ensure-that-we-wait-for-connections-to-comple.patch
22 22
 Patch8:         SUNRPC-Do-not-reuse-srcport-for-TIME_WAIT-socket.patch
23
+Patch9:         06-sunrpc.patch
24
+Patch10:        vmware-log-kmsg-dump-on-panic.patch
23 25
 BuildRequires:  bc
24 26
 BuildRequires:  kbd
25 27
 BuildRequires:  kmod
... ...
@@ -84,6 +86,8 @@ Kernel driver for oprofile, a statistical profiler for Linux systems
84 84
 %patch6 -p1
85 85
 %patch7 -p1
86 86
 %patch8 -p1
87
+%patch9 -p1
88
+%patch10 -p1
87 89
 
88 90
 %build
89 91
 make mrproper
... ...
@@ -174,6 +178,9 @@ ln -sf %{name}-%{version}-%{release}.cfg /boot/photon.cfg
174 174
 /lib/modules/%{version}/kernel/arch/x86/oprofile/
175 175
 
176 176
 %changelog
177
+*   Tue Mar 29 2016 Alexey Makhalov <amakhalov@vmware.com> 4.2.0-24
178
+-   Support kmsg dumping to vmware.log on panic
179
+-   sunrpc: xs_bind uses ip_local_reserved_ports
177 180
 *   Mon Mar 28 2016 Harish Udaiya Kumar <hudaiyakumar@vmware.com> 4.2.0-23
178 181
 -   Enabled Regular stack protection in Linux kernel in config
179 182
 *   Thu Mar 17 2016 Harish Udaiya Kumar <hudaiyakumar@vmware.com> 4.2.0-22
... ...
@@ -189,7 +196,7 @@ ln -sf %{name}-%{version}-%{release}.cfg /boot/photon.cfg
189 189
 -   Added rpcsec_gss_krb5 and nfs_fscache
190 190
 *   Mon Feb 22 2016 Alexey Makhalov <amakhalov@vmware.com> 4.2.0-17
191 191
 -   Added sysctl param to control weighted_cpuload() behavior
192
-*   Sun Feb 18 2016 Divya Thaluru <dthaluru@vmware.com> 4.2.0-16
192
+*   Thu Feb 18 2016 Divya Thaluru <dthaluru@vmware.com> 4.2.0-16
193 193
 -   Disabling network renaming
194 194
 *   Sun Feb 14 2016 Alexey Makhalov <amakhalov@vmware.com> 4.2.0-15
195 195
 -   veth patch: don’t modify ip_summed
196 196
new file mode 100644
... ...
@@ -0,0 +1,179 @@
0
+diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
1
+index 628a059..a964013 100644
2
+--- a/arch/x86/kernel/cpu/vmware.c
3
+@@ -26,16 +26,20 @@
4
+ #include <asm/div64.h>
5
+ #include <asm/x86_init.h>
6
+ #include <asm/hypervisor.h>
7
++#include <linux/kmsg_dump.h>
8
+ 
9
+-#define CPUID_VMWARE_INFO_LEAF	0x40000000
10
+-#define VMWARE_HYPERVISOR_MAGIC	0x564D5868
11
+-#define VMWARE_HYPERVISOR_PORT	0x5658
12
++#define CPUID_VMWARE_INFO_LEAF		0x40000000
13
++#define VMWARE_HYPERVISOR_MAGIC		0x564D5868
14
++#define VMWARE_HYPERVISOR_PORT		0x5658
15
++#define VMWARE_HYPERVISOR_HB_PORT	0x5659
16
+ 
17
+ #define VMWARE_PORT_CMD_GETVERSION	10
18
+ #define VMWARE_PORT_CMD_GETHZ		45
19
+ #define VMWARE_PORT_CMD_GETVCPU_INFO	68
20
+ #define VMWARE_PORT_CMD_LEGACY_X2APIC	3
21
+ #define VMWARE_PORT_CMD_VCPU_RESERVED	31
22
++#define VMWARE_PORT_CMD_MESSAGE		30
23
++#define VMWARE_HB_PORT_CMD_MESSAGE	0
24
+ 
25
+ #define VMWARE_PORT(cmd, eax, ebx, ecx, edx)				\
26
+ 	__asm__("inl (%%dx)" :						\
27
+@@ -75,6 +79,13 @@ static unsigned long vmware_get_tsc_khz(void)
28
+ 	return tsc_hz;
29
+ }
30
+ 
31
++static void kmsg_dumper_vmware_log(struct kmsg_dumper *dumper,
32
++				enum kmsg_dump_reason reason);
33
++
34
++static struct kmsg_dumper kmsg_dumper = {
35
++	.dump = kmsg_dumper_vmware_log
36
++};
37
++
38
+ static void __init vmware_platform_setup(void)
39
+ {
40
+ 	uint32_t eax, ebx, ecx, edx;
41
+@@ -86,6 +97,8 @@ static void __init vmware_platform_setup(void)
42
+ 	else
43
+ 		printk(KERN_WARNING
44
+ 		       "Failed to get TSC freq from the hypervisor\n");
45
++
46
++	kmsg_dump_register(&kmsg_dumper);
47
+ }
48
+ 
49
+ /*
50
+@@ -145,3 +158,127 @@ const __refconst struct hypervisor_x86 x86_hyper_vmware = {
51
+ 	.x2apic_available	= vmware_legacy_x2apic_available,
52
+ };
53
+ EXPORT_SYMBOL(x86_hyper_vmware);
54
++
55
++#define MESSAGE_STATUS_SUCCESS  (0x01 << 16)
56
++#define MESSAGE_STATUS_CPT      (0x10 << 16)
57
++#define MESSAGE_STATUS_HB       (0x80 << 16)
58
++
59
++#define RPCI_PROTOCOL_NUM       0x49435052 /* 'RPCI' */
60
++#define GUESTMSG_FLAG_COOKIE    0x80000000
61
++
62
++#define MESSAGE_TYPE_OPEN	(0 << 16)
63
++#define MESSAGE_TYPE_SENDSIZE	(1 << 16)
64
++#define MESSAGE_TYPE_CLOSE	(6 << 16)
65
++
66
++typedef struct {
67
++	uint32_t id;
68
++	uint32_t cookieHigh;
69
++	uint32_t cookieLow;
70
++} vmw_msg;
71
++
72
++static int
73
++vmware_log_open(vmw_msg *msg) {
74
++	uint32_t result, info, dx, si, di;
75
++	__asm__ __volatile__ ("inl (%%dx)"
76
++		:	"=a" (result),
77
++			"=c" (info),
78
++			"=d" (dx),
79
++			"=S" (si),
80
++			"=D" (di)
81
++		:       "a"  (VMWARE_HYPERVISOR_MAGIC),
82
++			"c"  (VMWARE_PORT_CMD_MESSAGE | MESSAGE_TYPE_OPEN),
83
++			"d"  (VMWARE_HYPERVISOR_PORT),
84
++			"b"  (RPCI_PROTOCOL_NUM | GUESTMSG_FLAG_COOKIE));
85
++
86
++	if ((info & MESSAGE_STATUS_SUCCESS) == 0)
87
++		return 1;
88
++
89
++	msg->id = dx & 0xffff0000;
90
++	msg->cookieHigh = si;
91
++	msg->cookieLow = di;
92
++	return 0;
93
++}
94
++
95
++static int
96
++vmware_log_close(vmw_msg *msg) {
97
++	uint32_t result, info;
98
++	__asm__ __volatile__ ("inl (%%dx)"
99
++		:	"=a" (result),
100
++			"=c" (info)
101
++		:       "a"  (VMWARE_HYPERVISOR_MAGIC),
102
++			"c"  (VMWARE_PORT_CMD_MESSAGE | MESSAGE_TYPE_CLOSE),
103
++			"d"  (VMWARE_HYPERVISOR_PORT | msg->id),
104
++			"b"  (0),
105
++			"S"  (msg->cookieHigh),
106
++			"D"  (msg->cookieLow));
107
++
108
++	if ((info & MESSAGE_STATUS_SUCCESS) == 0)
109
++		return 1;
110
++	return 0;
111
++}
112
++
113
++static int
114
++vmware_log_send(vmw_msg *msg, const char *string) {
115
++	uint32_t result, info;
116
++	uint32_t len = strlen(string);
117
++
118
++retry:
119
++	__asm__ __volatile__ ("inl (%%dx)"
120
++		:	"=a" (result),
121
++			"=c" (info)
122
++		:       "a"  (VMWARE_HYPERVISOR_MAGIC),
123
++			"c"  (VMWARE_PORT_CMD_MESSAGE | MESSAGE_TYPE_SENDSIZE),
124
++			"d"  (VMWARE_HYPERVISOR_PORT | msg->id),
125
++			"b"  (len),
126
++			"S"  (msg->cookieHigh),
127
++			"D"  (msg->cookieLow));
128
++
129
++	if ((info & MESSAGE_STATUS_SUCCESS) == 0 ||
130
++	    (info & MESSAGE_STATUS_HB) == 0)
131
++		/* Expected success + high-bandwidth. Give up. */
132
++		return 1;
133
++
134
++	__asm__ __volatile__ ("pushq %%rbp\n\t"
135
++			      "movl %[rbp], %%ebp\n\t"
136
++			      "cld\n\t"
137
++			      "rep; outsb\n\t"
138
++			      "popq %%rbp\n\t"
139
++		:	"=a" (result),
140
++			"=b" (info)
141
++		:       "a"  (VMWARE_HYPERVISOR_MAGIC),
142
++			"c"  (len),
143
++			"d"  (VMWARE_HYPERVISOR_HB_PORT | msg->id),
144
++			"b"  (VMWARE_HB_PORT_CMD_MESSAGE | MESSAGE_STATUS_SUCCESS),
145
++			"S"  (string),
146
++		  [rbp] "r"  (msg->cookieHigh),
147
++			"D"  (msg->cookieLow));
148
++
149
++	if ((info & MESSAGE_STATUS_SUCCESS) == 0) {
150
++		if (info & MESSAGE_STATUS_CPT)
151
++			/* A checkpoint occurred. Retry. */
152
++			goto retry;
153
++		return 1;
154
++	}
155
++	return 0;
156
++}
157
++
158
++static void kmsg_dumper_vmware_log(struct kmsg_dumper *dumper,
159
++				enum kmsg_dump_reason reason)
160
++{
161
++	vmw_msg msg;
162
++	static char line[1024];
163
++	size_t len = 0;
164
++
165
++	line[0] = 'l';
166
++	line[1] = 'o';
167
++	line[2] = 'g';
168
++	line[3] = ' ';
169
++
170
++	while (kmsg_dump_get_line(dumper, true, line + 4, sizeof(line) - 4, &len)) {
171
++		line[len + 4] = '\0';
172
++		if (vmware_log_open(&msg) ||
173
++		    vmware_log_send(&msg, line) ||
174
++		    vmware_log_close(&msg))
175
++			break;
176
++	}
177
++}