From 7ba00c001bd9a1b1349ce69506c132d213012cb0 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Fri, 15 Sep 2017 14:19:39 +0100 Subject: [PATCH 1/3] kernel: Update 4.12.x kernel patches These are the recommended patches for 4.12 for Hyper-V sockets and LCOW. Based on: https://github.com/Microsoft/opengcs/pull/138 This also includes a cherry-pick from upstream which fixes the ext4/nvdimm/pax failures we have seen since 4.11.2. Signed-off-by: Rolf Neugebauer --- ...en-reset-onchannel_callback-on-error.patch | 8 +- ...to-error_clean_msglist-in-vmbus_open.patch | 8 +- ...y-enqueue-dequeue-a-channel-on-vmbus.patch | 6 +- ...ts-Hyper-V-transport-for-Virtual-Soc.patch | 9 +- ...nly-try-to-load-on-VMware-hypervisor.patch | 10 +- ...sock-add-the-support-of-auto-loading.patch | 8 +- ...07-tools-hv_sock-2-simple-test-cases.patch | 430 ++++++++++++++++++ ...ck-fix-a-race-in-hvs_stream_dequeue.patch} | 11 +- ...x-vsock_dequeue-enqueue_accept-race.patch} | 13 +- ...ivers-hv-vmbus-Fix-rescind-handling.patch} | 6 +- ...-fix-hv_percpu_channel_deq-enq-race.patch} | 6 +- ...-vmbus-onoffer-onoffer_rescind-sync.patch} | 6 +- ...ary-workaround-for-the-pending_send_.patch | 133 ++++++ ...dded-vsock-transport-support-to-9pfs.patch | 151 ------ ...ssed-signaling-in-hv_signal_on_read.patch} | 6 +- ...d-double-FINs-if-shutdown-is-called.patch} | 18 +- ...hv_sock-device-only-after-the-RESCIN.patch | 49 ++ ...-handling-when-mounted-with-o-dax-ro.patch | 61 +++ ...D_MIN_NAMESPACE_SIZE-from-4MB-to-4K.patch} | 4 +- 19 files changed, 726 insertions(+), 217 deletions(-) create mode 100644 kernel/patches-4.12.x/0007-tools-hv_sock-2-simple-test-cases.patch rename kernel/patches-4.12.x/{0007-hv_sock-fix-a-race-in-hvs_stream_dequeue.patch => 0008-hvsock-fix-a-race-in-hvs_stream_dequeue.patch} (88%) rename kernel/patches-4.12.x/{0008-vsock-fix-vsock_dequeue-enqueue_accept-race.patch => 0009-hvsock-fix-vsock_dequeue-enqueue_accept-race.patch} (75%) rename kernel/patches-4.12.x/{0009-Drivers-hv-vmbus-Fix-rescind-handling.patch => 0010-Drivers-hv-vmbus-Fix-rescind-handling.patch} (97%) rename kernel/patches-4.12.x/{0010-vmbus-fix-hv_percpu_channel_deq-enq-race.patch => 0011-vmbus-fix-hv_percpu_channel_deq-enq-race.patch} (97%) rename kernel/patches-4.12.x/{0011-vmbus-add-vmbus-onoffer-onoffer_rescind-sync.patch => 0012-vmbus-add-vmbus-onoffer-onoffer_rescind-sync.patch} (95%) create mode 100644 kernel/patches-4.12.x/0013-hv-sock-a-temporary-workaround-for-the-pending_send_.patch delete mode 100644 kernel/patches-4.12.x/0014-Added-vsock-transport-support-to-9pfs.patch rename kernel/patches-4.12.x/{0012-vmbus-fix-the-missed-signaling-in-hv_signal_on_read.patch => 0014-vmbus-fix-the-missed-signaling-in-hv_signal_on_read.patch} (85%) rename kernel/patches-4.12.x/{0013-hv_sock-avoid-double-FINs-if-shutdown-is-called.patch => 0015-hv-sock-avoid-double-FINs-if-shutdown-is-called.patch} (59%) create mode 100644 kernel/patches-4.12.x/0016-vmbus-destroy-a-hv_sock-device-only-after-the-RESCIN.patch create mode 100644 kernel/patches-4.12.x/0017-ext4-fix-fault-handling-when-mounted-with-o-dax-ro.patch rename kernel/patches-4.12.x/{0015-NVDIMM-reducded-ND_MIN_NAMESPACE_SIZE-from-4MB-to-4K.patch => 0018-NVDIMM-reducded-ND_MIN_NAMESPACE_SIZE-from-4MB-to-4K.patch} (84%) diff --git a/kernel/patches-4.12.x/0001-vmbus-vmbus_open-reset-onchannel_callback-on-error.patch b/kernel/patches-4.12.x/0001-vmbus-vmbus_open-reset-onchannel_callback-on-error.patch index e540a1c5b..592d5e455 100644 --- a/kernel/patches-4.12.x/0001-vmbus-vmbus_open-reset-onchannel_callback-on-error.patch +++ b/kernel/patches-4.12.x/0001-vmbus-vmbus_open-reset-onchannel_callback-on-error.patch @@ -1,7 +1,7 @@ -From d34b8dad5cbb125d4d0260e439ea0d02cd93b7f8 Mon Sep 17 00:00:00 2001 +From 5b154016aac757cacc1131d4e99b308ef1c2938f Mon Sep 17 00:00:00 2001 From: Dexuan Cui -Date: Wed, 26 Jul 2017 12:31:50 -0600 -Subject: [PATCH 01/15] vmbus: vmbus_open(): reset onchannel_callback on error +Date: Fri, 5 May 2017 16:57:12 -0600 +Subject: [PATCH 01/18] vmbus: vmbus_open(): reset onchannel_callback on error No real issue is observed without the patch, but let's add this just in case. @@ -11,7 +11,7 @@ Cc: K. Y. Srinivasan Cc: Haiyang Zhang Cc: Stephen Hemminger Origin: git@github.com:dcui/linux.git -(cherry picked from commit b20ffd850ad9763a10b563680ab4aa0c1c8894ac) +(cherry picked from commit 5181302de497cb7d5de37bbc84e01eca676f20d8) --- drivers/hv/channel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/patches-4.12.x/0002-vmbus-remove-goto-error_clean_msglist-in-vmbus_open.patch b/kernel/patches-4.12.x/0002-vmbus-remove-goto-error_clean_msglist-in-vmbus_open.patch index c9f2a22e0..dc694a897 100644 --- a/kernel/patches-4.12.x/0002-vmbus-remove-goto-error_clean_msglist-in-vmbus_open.patch +++ b/kernel/patches-4.12.x/0002-vmbus-remove-goto-error_clean_msglist-in-vmbus_open.patch @@ -1,7 +1,7 @@ -From 02167ba1cbb35d954c029846f753b1c38daf0c4e Mon Sep 17 00:00:00 2001 +From a07c4b74416d7b4ee63e30e3a9e0e4553fc7d535 Mon Sep 17 00:00:00 2001 From: Dexuan Cui -Date: Wed, 26 Jul 2017 12:31:53 -0600 -Subject: [PATCH 02/15] vmbus: remove "goto error_clean_msglist" in +Date: Fri, 5 May 2017 16:57:20 -0600 +Subject: [PATCH 02/18] vmbus: remove "goto error_clean_msglist" in vmbus_open() This is just a cleanup patch to simplify the code a little. @@ -12,7 +12,7 @@ Cc: K. Y. Srinivasan Cc: Haiyang Zhang Cc: Stephen Hemminger Origin: git@github.com:dcui/linux.git -(cherry picked from commit 981ae0c39f4a01eaa8e9db4b0e431028005ea1e0) +(cherry picked from commit 866488f04fc4d8ff513697db2f80263e90277291) --- drivers/hv/channel.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/kernel/patches-4.12.x/0003-vmbus-dynamically-enqueue-dequeue-a-channel-on-vmbus.patch b/kernel/patches-4.12.x/0003-vmbus-dynamically-enqueue-dequeue-a-channel-on-vmbus.patch index d436a0b6d..e1d185fd4 100644 --- a/kernel/patches-4.12.x/0003-vmbus-dynamically-enqueue-dequeue-a-channel-on-vmbus.patch +++ b/kernel/patches-4.12.x/0003-vmbus-dynamically-enqueue-dequeue-a-channel-on-vmbus.patch @@ -1,7 +1,7 @@ -From a021d948658c20f25abb7f4ae5fce42bdbe2869b Mon Sep 17 00:00:00 2001 +From df4d0b9a1259b50b6cbec75465ed9f7d5e192188 Mon Sep 17 00:00:00 2001 From: Dexuan Cui Date: Fri, 5 May 2017 16:57:23 -0600 -Subject: [PATCH 03/15] vmbus: dynamically enqueue/dequeue a channel on +Subject: [PATCH 03/18] vmbus: dynamically enqueue/dequeue a channel on vmbus_open/close MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 @@ -23,7 +23,7 @@ Cc: K. Y. Srinivasan Cc: Haiyang Zhang Cc: Stephen Hemminger Origin: git@github.com:dcui/linux.git -(cherry picked from commit 1df677b35ff010d0def33f5420773015815cf843) +(cherry picked from commit fdd8e16c855a6c7238c654d7217dcf51c5533307) --- drivers/hv/channel.c | 12 +++++++++--- drivers/hv/channel_mgmt.c | 50 +++++++++++++++++++++-------------------------- diff --git a/kernel/patches-4.12.x/0004-hv_sock-implements-Hyper-V-transport-for-Virtual-Soc.patch b/kernel/patches-4.12.x/0004-hv_sock-implements-Hyper-V-transport-for-Virtual-Soc.patch index 052b3a84c..6ee415da5 100644 --- a/kernel/patches-4.12.x/0004-hv_sock-implements-Hyper-V-transport-for-Virtual-Soc.patch +++ b/kernel/patches-4.12.x/0004-hv_sock-implements-Hyper-V-transport-for-Virtual-Soc.patch @@ -1,7 +1,7 @@ -From 1c7e06eb20a24ff9f8ef3058458cb2df485afe8b Mon Sep 17 00:00:00 2001 +From 4460bb325ac6a9c22d452480fce5695c3ed86a76 Mon Sep 17 00:00:00 2001 From: Dexuan Cui -Date: Wed, 26 Jul 2017 12:31:56 -0600 -Subject: [PATCH 04/15] hv_sock: implements Hyper-V transport for Virtual +Date: Fri, 5 May 2017 16:57:26 -0600 +Subject: [PATCH 04/18] hv_sock: implements Hyper-V transport for Virtual Sockets (AF_VSOCK) Hyper-V Sockets (hv_sock) supplies a byte-stream based communication @@ -34,9 +34,8 @@ Cc: Stefan Hajnoczi Cc: Vitaly Kuznetsov Cc: Cathy Avery Cc: Rolf Neugebauer -Cc: Marcelo Cerri Origin: git@github.com:dcui/linux.git -(cherry picked from commit ca99361977429c3128fce64dcfe1093e4ab65247) +(cherry picked from commit b02ea409f1fceeaac6fd971db5d095ecc903de2d) --- MAINTAINERS | 1 + net/vmw_vsock/Kconfig | 12 + diff --git a/kernel/patches-4.12.x/0005-VMCI-only-try-to-load-on-VMware-hypervisor.patch b/kernel/patches-4.12.x/0005-VMCI-only-try-to-load-on-VMware-hypervisor.patch index d4e5adfed..b2b11e21f 100644 --- a/kernel/patches-4.12.x/0005-VMCI-only-try-to-load-on-VMware-hypervisor.patch +++ b/kernel/patches-4.12.x/0005-VMCI-only-try-to-load-on-VMware-hypervisor.patch @@ -1,7 +1,7 @@ -From f8cbe9d1fd7c7eb028a65b2a2eb0945d056b8522 Mon Sep 17 00:00:00 2001 +From 2b76165d8dceee83252646abcc9a933228e5e82a Mon Sep 17 00:00:00 2001 From: Dexuan Cui -Date: Wed, 26 Jul 2017 12:31:58 -0600 -Subject: [PATCH 05/15] VMCI: only try to load on VMware hypervisor +Date: Fri, 5 May 2017 16:57:29 -0600 +Subject: [PATCH 05/18] VMCI: only try to load on VMware hypervisor Without the patch, vmw_vsock_vmci_transport.ko and vmw_vmci.ko can automatically load when an application creates an AF_VSOCK socket. @@ -13,7 +13,7 @@ there is a -EBUSY conflict when both vmw_vsock_vmci_transport.ko and hv_sock.ko try to call vsock_core_init(). On the other hand, hv_sock.ko can only load on Hyper-V, because it -depends on hv_vmbus.ko, which detects Hyper-V in hv_acpi_init(). +depends on hv_vmbus.ko, which deteces Hyper-V in hv_acpi_init(). KVM's vsock_virtio_transport doesn't have the issue because it doesn't define MODULE_ALIAS_NETPROTO(PF_VSOCK). @@ -28,7 +28,7 @@ Cc: K. Y. Srinivasan Cc: Haiyang Zhang Cc: Stephen Hemminger Origin: git@github.com:dcui/linux.git -(cherry picked from commit 52d06e92fca7e91c5a774a5491239597f43261a3) +(cherry picked from commit 27e512021e36c67dd1c773a52b23d71896c80602) --- drivers/misc/vmw_vmci/vmci_driver.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/patches-4.12.x/0006-hv_sock-add-the-support-of-auto-loading.patch b/kernel/patches-4.12.x/0006-hv_sock-add-the-support-of-auto-loading.patch index b1b35187d..7d04a9f73 100644 --- a/kernel/patches-4.12.x/0006-hv_sock-add-the-support-of-auto-loading.patch +++ b/kernel/patches-4.12.x/0006-hv_sock-add-the-support-of-auto-loading.patch @@ -1,7 +1,7 @@ -From c242464f783f61a4859d8f900ee5fa088ac001a6 Mon Sep 17 00:00:00 2001 +From 9e8143f9768911c7b65d2df5cc05bbd7c2c290b4 Mon Sep 17 00:00:00 2001 From: Dexuan Cui -Date: Wed, 26 Jul 2017 12:32:00 -0600 -Subject: [PATCH 06/15] hv_sock: add the support of auto-loading +Date: Fri, 5 May 2017 16:57:35 -0600 +Subject: [PATCH 06/18] hv_sock: add the support of auto-loading After we disable VMWare virtual sockets driver's auto-loading on Hyper-V, we can enable hv_sock's auto-loading now. @@ -11,7 +11,7 @@ Cc: K. Y. Srinivasan Cc: Haiyang Zhang Cc: Stephen Hemminger Origin: git@github.com:dcui/linux.git -(cherry picked from commit 6c9b2ebd7fc79eb00bc524b8eae11a218faa1769) +(cherry picked from commit e2c1d1b8e8d17cc9b423688d59ad486c5f38deca) --- net/vmw_vsock/hyperv_transport.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/patches-4.12.x/0007-tools-hv_sock-2-simple-test-cases.patch b/kernel/patches-4.12.x/0007-tools-hv_sock-2-simple-test-cases.patch new file mode 100644 index 000000000..9da4b7f6b --- /dev/null +++ b/kernel/patches-4.12.x/0007-tools-hv_sock-2-simple-test-cases.patch @@ -0,0 +1,430 @@ +From d4aaf1f9808733b09c58962f73106918f16de7ef Mon Sep 17 00:00:00 2001 +From: Dexuan Cui +Date: Fri, 5 May 2017 18:52:02 -0600 +Subject: [PATCH 07/18] tools: hv_sock: 2 simple test cases. + +Please read this document first: +https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/make-integration-service + +And you may want to have a look at +https://github.com/dcui/linux/commit/691aff936c0fa6fc24e2662c0e8cc6ab65509600#diff-2cf9109d84c1ba75b09e40090f4a2176R100 + +Signed-off-by: Dexuan Cui +Origin: git@github.com:dcui/linux.git +(cherry picked from commit e015b0a767dcab79b8b8361516f3f4322cdc90a7) +--- + tools/hv/hv_sock/test-001/client_in_vm.c | 38 +++++++++ + tools/hv/hv_sock/test-001/server_on_host.c | 128 +++++++++++++++++++++++++++++ + tools/hv/hv_sock/test-002/client_on_host.c | 127 ++++++++++++++++++++++++++++ + tools/hv/hv_sock/test-002/server_in_vm.c | 85 +++++++++++++++++++ + 4 files changed, 378 insertions(+) + create mode 100644 tools/hv/hv_sock/test-001/client_in_vm.c + create mode 100644 tools/hv/hv_sock/test-001/server_on_host.c + create mode 100644 tools/hv/hv_sock/test-002/client_on_host.c + create mode 100644 tools/hv/hv_sock/test-002/server_in_vm.c + +diff --git a/tools/hv/hv_sock/test-001/client_in_vm.c b/tools/hv/hv_sock/test-001/client_in_vm.c +new file mode 100644 +index 000000000000..2e2371b13fa7 +--- /dev/null ++++ b/tools/hv/hv_sock/test-001/client_in_vm.c +@@ -0,0 +1,38 @@ ++/* The program runs in Linux VM. */ ++ ++#include ++#include ++#include ++#include ++ ++int main() ++{ ++ int fd; ++ ++ struct sockaddr_vm sa = { ++ .svm_family = AF_VSOCK, ++ .svm_reserved1 = 0, ++ .svm_cid = VMADDR_CID_ANY, ++ }; ++ ++ /* Connecting to the host's 00000808-facb-11e6-bd58-64006a7986d3 */ ++ sa.svm_port = 0x808; ++ ++ fd = socket(AF_VSOCK, SOCK_STREAM, 0); ++ if (fd < 0) { ++ perror("socket"); ++ return -1; ++ } ++ ++ if (connect(fd, (struct sockaddr*)&sa, sizeof(sa)) != 0) { ++ perror("connect"); ++ return -1; ++ } ++ ++ printf("Connected to the host.\n"); ++ ++ close(fd); ++ printf("Closed the connection.\n"); ++ ++ return 0; ++} +diff --git a/tools/hv/hv_sock/test-001/server_on_host.c b/tools/hv/hv_sock/test-001/server_on_host.c +new file mode 100644 +index 000000000000..22c48e8d3789 +--- /dev/null ++++ b/tools/hv/hv_sock/test-001/server_on_host.c +@@ -0,0 +1,128 @@ ++/* The program runs on Windows 10 or Windows Server 2016 host or newer. */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#pragma comment(lib, "ws2_32.lib") ++ ++#ifndef AF_HYPERV ++#define AF_HYPERV 34 ++#define HV_PROTOCOL_RAW 1 ++ ++typedef struct _SOCKADDR_HV ++{ ++ ADDRESS_FAMILY Family; ++ USHORT Reserved; ++ GUID VmId; ++ GUID ServiceId; ++} SOCKADDR_HV, *PSOCKADDR_HV; ++ ++DEFINE_GUID(HV_GUID_SELF, 0x00000000, 0x0000, 0x0000, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); ++#endif /* AF_HYPERV */ ++ ++#define VMADDR_PORT_ANY 0xFFFFFFFF ++ ++/* 00000000-facb-11e6-bd58-64006a7986d3 */ ++DEFINE_GUID(HVSOCK_LINUX_TEMPLATE, 0x00000000, 0xfacb, 0x11e6, ++ 0xbd, 0x58, 0x64, 0x00, 0x6a, 0x79, 0x86, 0xd3); ++ ++static const GUID VsockServiceIdTemplate = HVSOCK_LINUX_TEMPLATE; ++ ++bool TryConvertVsockPortToServiceId(uint32_t port, GUID *serviceId) ++{ ++ if (port == VMADDR_PORT_ANY) ++ return false; ++ ++ *serviceId = VsockServiceIdTemplate; ++ serviceId->Data1 = port; ++ return true; ++} ++ ++bool TryConvertServiceIdToVsockPort(const GUID *serviceId, uint32_t *port) ++{ ++ if (memcmp(&serviceId->Data2, &VsockServiceIdTemplate.Data2, ++ sizeof(GUID) - sizeof(uint32_t)) != 0 || ++ serviceId->Data1 == VMADDR_PORT_ANY) { ++ return false; ++ } ++ ++ *port = serviceId->Data1; ++ return true; ++} ++ ++int CreateListenSocket(uint32_t port, SOCKET *result_fd) ++{ ++ SOCKADDR_HV localAddr; ++ SOCKET fd; ++ int ret; ++ ++ fd = socket(AF_HYPERV, SOCK_STREAM, HV_PROTOCOL_RAW); ++ if (fd == INVALID_SOCKET) { ++ printf("socket() failed: error = %d\n", WSAGetLastError()); ++ return -1; ++ } ++ ++ memset(&localAddr, 0, sizeof(SOCKADDR_HV)); ++ localAddr.Family = AF_HYPERV; ++ localAddr.VmId = HV_GUID_SELF; ++ TryConvertVsockPortToServiceId(port, &localAddr.ServiceId); ++ ++ ret = bind(fd, (SOCKADDR *)&localAddr, sizeof(SOCKADDR_HV)); ++ if (ret == SOCKET_ERROR) { ++ printf("bind() failed: error = %d\n", WSAGetLastError()); ++ goto err; ++ } ++ ++ ret = listen(fd, 10); ++ if (ret == SOCKET_ERROR) { ++ printf("listen() failed: error = %d\n", WSAGetLastError()); ++ goto err; ++ } ++ ++ *result_fd = fd; ++ printf("Listening on fd = 0x%d, local port = 0x%x\n", fd, port); ++ return 0; ++err: ++ closesocket(fd); ++ return -1; ++} ++ ++int main() ++{ ++ WSADATA wsaData; ++ SOCKADDR_HV remoteAddr; ++ int remoteAddrLen; ++ SOCKET fd; ++ SOCKET children[100]; ++ int i, ret; ++ ++ // Initialize Winsock ++ ret = WSAStartup(MAKEWORD(2, 2), &wsaData); ++ if (ret != NO_ERROR) { ++ printf("WSAStartup() failed with error: %d\n", ret); ++ return -1; ++ } ++ ++ // We'll listen on 00000808-facb-11e6-bd58-64006a7986d3 ++ if (CreateListenSocket(0x808, &fd) < 0) { ++ printf("failed to listen!\n"); ++ ret = -1; ++ goto out; ++ } ++ ++ for (i = 0; i < ARRAYSIZE(children); i++) { ++ remoteAddrLen = sizeof(SOCKADDR_HV); ++ children[i] = accept(fd, (sockaddr *)&remoteAddr, &remoteAddrLen); ++ closesocket(children[i]); ++ printf("Got a connection and closed it.\n"); ++ } ++ ++ closesocket(fd); ++out: ++ WSACleanup(); ++ return ret; ++} +diff --git a/tools/hv/hv_sock/test-002/client_on_host.c b/tools/hv/hv_sock/test-002/client_on_host.c +new file mode 100644 +index 000000000000..ed5ae99fbfba +--- /dev/null ++++ b/tools/hv/hv_sock/test-002/client_on_host.c +@@ -0,0 +1,127 @@ ++/* The program runs on Windows 10 or Windows Server 2016 host or newer. */ ++ ++#include ++#include ++#include ++#include ++#include ++#include /* for UuidFromStringA() */ ++#pragma comment(lib, "ws2_32.lib") ++#pragma comment(lib, "rpcrt4.lib") ++ ++#ifndef AF_HYPERV ++#define AF_HYPERV 34 ++#define HV_PROTOCOL_RAW 1 ++ ++typedef struct _SOCKADDR_HV ++{ ++ ADDRESS_FAMILY Family; ++ USHORT Reserved; ++ GUID VmId; ++ GUID ServiceId; ++}SOCKADDR_HV, *PSOCKADDR_HV; ++ ++DEFINE_GUID(HV_GUID_SELF, 0x00000000, 0x0000, 0x0000, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); ++#endif /* AF_HYPERV */ ++ ++#define VMADDR_PORT_ANY 0xFFFFFFFF ++ ++/* 00000000-facb-11e6-bd58-64006a7986d3 */ ++DEFINE_GUID(HVSOCK_LINUX_TEMPLATE, 0x00000000, 0xfacb, 0x11e6, ++ 0xbd, 0x58, 0x64, 0x00, 0x6a, 0x79, 0x86, 0xd3); ++ ++static const GUID VsockServiceIdTemplate = HVSOCK_LINUX_TEMPLATE; ++ ++bool TryConvertVsockPortToServiceId(uint32_t port, GUID *serviceId) ++{ ++ if (port == VMADDR_PORT_ANY) ++ return false; ++ ++ *serviceId = VsockServiceIdTemplate; ++ serviceId->Data1 = port; ++ return true; ++} ++ ++bool TryConvertServiceIdToVsockPort(const GUID *serviceId, uint32_t *port) ++{ ++ if (memcmp(&serviceId->Data2, &VsockServiceIdTemplate.Data2, ++ sizeof(GUID) - sizeof(uint32_t)) != 0 || ++ serviceId->Data1 == VMADDR_PORT_ANY) { ++ return false; ++ } ++ ++ *port = serviceId->Data1; ++ return true; ++} ++ ++int ConnectToVM(const SOCKADDR_HV *remoteAddr, SOCKET *result_fd) ++{ ++ SOCKADDR_HV localAddr; ++ SOCKET fd; ++ uint32_t port; ++ int ret; ++ ++ fd = socket(AF_HYPERV, SOCK_STREAM, HV_PROTOCOL_RAW); ++ if (fd == INVALID_SOCKET) { ++ printf("socket() failed with error: %d\n", WSAGetLastError()); ++ return -1; ++ } ++ ++ ret = connect(fd, (SOCKADDR *)remoteAddr, sizeof(SOCKADDR_HV)); ++ if (ret == SOCKET_ERROR) { ++ printf("connect() failed: error = %d\n", WSAGetLastError()); ++ closesocket(fd); ++ return -1; ++ } ++ ++ *result_fd = fd; ++ printf("Connected to the VM: fd = 0x%x\n", fd); ++ return 0; ++} ++ ++int main() ++{ ++ const char *msg = "***Hello! This message is from the host!***\n"; ++ WSADATA wsaData; ++ SOCKADDR_HV remoteAddr; ++ SOCKET fd; ++ int ret; ++ ++ // Initialize Winsock ++ ret = WSAStartup(MAKEWORD(2, 2), &wsaData); ++ if (ret != NO_ERROR) { ++ printf("WSAStartup() failed with error: %d\n", ret); ++ return -1; ++ } ++ ++ memset(&remoteAddr, 0, sizeof(SOCKADDR_HV)); ++ remoteAddr.Family = AF_HYPERV; ++ ++ // The Linux VM is listening in Vsock port 0x2017 ++ TryConvertVsockPortToServiceId(0x2017, &remoteAddr.ServiceId); ++ ++ // This is the "remote" VM's VMID got by the PowerShell command ++ // "Get-VM -Name | ft id". ++ // ++ // Change it for your own VM. ++ if (UuidFromStringA((RPC_CSTR)"c2624c46-1212-484a-8e28-83dd15fef815", ++ &remoteAddr.VmId) != RPC_S_OK) { ++ printf("Failed to parse the remote VMID: %d\n", GetLastError()); ++ ret = -1; ++ goto out; ++ } ++ ++ if (ConnectToVM(&remoteAddr, &fd) < 0) { ++ printf("Failed to connect to the VM!\n"); ++ ret = -1; ++ goto out; ++ } ++ ret = send(fd, msg, strlen(msg), 0); ++ printf("Sent a msg to the VM: msg_len = %d.\nExited.\n", ret); ++ ++ closesocket(fd); ++out: ++ WSACleanup(); ++ return ret; ++} +diff --git a/tools/hv/hv_sock/test-002/server_in_vm.c b/tools/hv/hv_sock/test-002/server_in_vm.c +new file mode 100644 +index 000000000000..fb4370c53152 +--- /dev/null ++++ b/tools/hv/hv_sock/test-002/server_in_vm.c +@@ -0,0 +1,85 @@ ++/* The program runs in Linux VM. */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++int main() ++{ ++ uint32_t port = 0x2017; ++ ++ int listen_fd; ++ int client_fd; ++ ++ struct sockaddr_vm sa_listen = { ++ .svm_family = AF_VSOCK, ++ .svm_reserved1 = 0, ++ .svm_cid = VMADDR_CID_ANY, ++ }; ++ ++ struct sockaddr_vm sa_client; ++ socklen_t socklen_client; ++ ++ char buf[4096]; ++ int len; ++ ++ /* We'll listen on 00002017-facb-11e6-bd58-64006a7986d3 */ ++ sa_listen.svm_port = port; ++ ++ listen_fd = socket(AF_VSOCK, SOCK_STREAM, 0); ++ if (listen_fd < 0) { ++ perror("socket()"); ++ exit(-1); ++ } ++ ++ if (bind(listen_fd, (struct sockaddr *)&sa_listen, ++ sizeof(sa_listen)) != 0) { ++ perror("bind()"); ++ goto err; ++ } ++ ++ if (listen(listen_fd, 10) != 0) { ++ perror("listen()"); ++ goto err; ++ } ++ ++ printf("Listening on port 0x%x...\n", port); ++ ++ socklen_client = sizeof(sa_client); ++ client_fd = accept(listen_fd, (struct sockaddr*)&sa_client, ++ &socklen_client); ++ if (client_fd < 0) { ++ perror("accept()"); ++ goto err; ++ } ++ ++ printf("Got a connection from the host: cid=0x%x, port=0x%x.\n", ++ sa_client.svm_cid, sa_client.svm_port); ++ ++ do { ++ printf("Reading data from the connection...\n"); ++ len = read(client_fd, buf, sizeof(buf)); ++ if (len > 0) { ++ printf("Read %d bytes:\n", len); ++ fflush(stdout); ++ write(STDOUT_FILENO, buf, len); ++ } ++ } while (len > 0); ++ ++ printf("The other end closed the connection.\n"); ++ ++ close(client_fd); ++ close(listen_fd); ++ return 0; ++err: ++ close(listen_fd); ++ return -1; ++} +-- +2.14.1 + diff --git a/kernel/patches-4.12.x/0007-hv_sock-fix-a-race-in-hvs_stream_dequeue.patch b/kernel/patches-4.12.x/0008-hvsock-fix-a-race-in-hvs_stream_dequeue.patch similarity index 88% rename from kernel/patches-4.12.x/0007-hv_sock-fix-a-race-in-hvs_stream_dequeue.patch rename to kernel/patches-4.12.x/0008-hvsock-fix-a-race-in-hvs_stream_dequeue.patch index 0c618d5c9..8fafe48a5 100644 --- a/kernel/patches-4.12.x/0007-hv_sock-fix-a-race-in-hvs_stream_dequeue.patch +++ b/kernel/patches-4.12.x/0008-hvsock-fix-a-race-in-hvs_stream_dequeue.patch @@ -1,7 +1,7 @@ -From 0a248a2bce10f2b4552a1c2f33f25a350d8ebe66 Mon Sep 17 00:00:00 2001 +From 863597627dc80b37b08c06a8c64a579af91421a4 Mon Sep 17 00:00:00 2001 From: Dexuan Cui -Date: Wed, 26 Jul 2017 12:32:03 -0600 -Subject: [PATCH 07/15] hv_sock: fix a race in hvs_stream_dequeue() +Date: Tue, 16 May 2017 22:14:03 +0800 +Subject: [PATCH 08/18] hvsock: fix a race in hvs_stream_dequeue() If hv_pkt_iter_next() returns a non-NULL pointer, we must update the recv_data_len/data_off info, otherwise the received data will @@ -11,11 +11,8 @@ Thank Rolf for finding this! Reported-by: Rolf Neugebauer Signed-off-by: Dexuan Cui -Cc: K. Y. Srinivasan -Cc: Haiyang Zhang -Cc: Stephen Hemminger Origin: git@github.com:dcui/linux.git -(cherry picked from commit f06df7f9be11c903fbb03c03adebb67fd222157d) +(cherry picked from commit b9cc90e62104bd001b05d897f84cb7d30d1780bb) --- net/vmw_vsock/hyperv_transport.c | 50 +++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/kernel/patches-4.12.x/0008-vsock-fix-vsock_dequeue-enqueue_accept-race.patch b/kernel/patches-4.12.x/0009-hvsock-fix-vsock_dequeue-enqueue_accept-race.patch similarity index 75% rename from kernel/patches-4.12.x/0008-vsock-fix-vsock_dequeue-enqueue_accept-race.patch rename to kernel/patches-4.12.x/0009-hvsock-fix-vsock_dequeue-enqueue_accept-race.patch index 5b612a7e6..57478b46a 100644 --- a/kernel/patches-4.12.x/0008-vsock-fix-vsock_dequeue-enqueue_accept-race.patch +++ b/kernel/patches-4.12.x/0009-hvsock-fix-vsock_dequeue-enqueue_accept-race.patch @@ -1,16 +1,11 @@ -From 7c7818b98fe1d107a54ef5336b6d919d920d5b3a Mon Sep 17 00:00:00 2001 +From 7a238699091e5294d43d930e9f9df0d79ba2be28 Mon Sep 17 00:00:00 2001 From: Dexuan Cui -Date: Wed, 26 Jul 2017 12:32:06 -0600 -Subject: [PATCH 08/15] vsock: fix vsock_dequeue/enqueue_accept race - -We should add a lock to protect the concurrent access to the list. +Date: Fri, 19 May 2017 21:49:59 +0800 +Subject: [PATCH 09/18] hvsock: fix vsock_dequeue/enqueue_accept race Signed-off-by: Dexuan Cui -Cc: K. Y. Srinivasan -Cc: Haiyang Zhang -Cc: Stephen Hemminger Origin: git@github.com:dcui/linux.git -(cherry picked from commit 719999b4908874178002a7a4850396e111780f59) +(cherry picked from commit 022c888e809721a67ecd3072e6331cbdaab45536) --- net/vmw_vsock/af_vsock.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/patches-4.12.x/0009-Drivers-hv-vmbus-Fix-rescind-handling.patch b/kernel/patches-4.12.x/0010-Drivers-hv-vmbus-Fix-rescind-handling.patch similarity index 97% rename from kernel/patches-4.12.x/0009-Drivers-hv-vmbus-Fix-rescind-handling.patch rename to kernel/patches-4.12.x/0010-Drivers-hv-vmbus-Fix-rescind-handling.patch index 234dd88b9..fe90c41a2 100644 --- a/kernel/patches-4.12.x/0009-Drivers-hv-vmbus-Fix-rescind-handling.patch +++ b/kernel/patches-4.12.x/0010-Drivers-hv-vmbus-Fix-rescind-handling.patch @@ -1,7 +1,7 @@ -From 75c1cf1fd1506de61867f3a53e38a27d8a904513 Mon Sep 17 00:00:00 2001 +From a8c2b06a582725545e8baf67357bb81a225bdc72 Mon Sep 17 00:00:00 2001 From: "K. Y. Srinivasan" Date: Sun, 30 Apr 2017 16:21:18 -0700 -Subject: [PATCH 09/15] Drivers: hv: vmbus: Fix rescind handling +Subject: [PATCH 10/18] Drivers: hv: vmbus: Fix rescind handling Fix the rescind handling. This patch addresses the following rescind scenario that is currently not handled correctly: @@ -17,7 +17,7 @@ Long Li for working with me on this patch. Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Origin: git@github.com:dcui/linux.git -(cherry picked from commit be1ce15dfbdfe3f42c8ed23c5904674d5d90b545) +(cherry picked from commit 81304747d9bcba135c9a9d534f3a3190bca92339) --- drivers/hv/channel.c | 8 ++++-- drivers/hv/channel_mgmt.c | 69 ++++++++++++++++++++++++++++++++++++----------- diff --git a/kernel/patches-4.12.x/0010-vmbus-fix-hv_percpu_channel_deq-enq-race.patch b/kernel/patches-4.12.x/0011-vmbus-fix-hv_percpu_channel_deq-enq-race.patch similarity index 97% rename from kernel/patches-4.12.x/0010-vmbus-fix-hv_percpu_channel_deq-enq-race.patch rename to kernel/patches-4.12.x/0011-vmbus-fix-hv_percpu_channel_deq-enq-race.patch index 7bdb222bc..8cfbe7dde 100644 --- a/kernel/patches-4.12.x/0010-vmbus-fix-hv_percpu_channel_deq-enq-race.patch +++ b/kernel/patches-4.12.x/0011-vmbus-fix-hv_percpu_channel_deq-enq-race.patch @@ -1,11 +1,11 @@ -From 87521124dac07e6a31aae1650646e70dfc9c4722 Mon Sep 17 00:00:00 2001 +From 5fe9cf6bd66c8359d51bd36a5bffe9d57b5dec4c Mon Sep 17 00:00:00 2001 From: Dexuan Cui Date: Mon, 5 Jun 2017 16:13:18 +0800 -Subject: [PATCH 10/15] vmbus: fix hv_percpu_channel_deq/enq race +Subject: [PATCH 11/18] vmbus: fix hv_percpu_channel_deq/enq race Signed-off-by: Dexuan Cui Origin: git@github.com:dcui/linux.git -(cherry picked from commit 8457502df9dd379ddbdfa42a8c9a6421bb3482f1) +(cherry picked from commit db40d92a09ff6b84b6c47e96d0a8d1cb1f83cd36) --- drivers/hv/channel_mgmt.c | 32 +++++++++++++++++++++---- drivers/hv/connection.c | 11 +++++++++ diff --git a/kernel/patches-4.12.x/0011-vmbus-add-vmbus-onoffer-onoffer_rescind-sync.patch b/kernel/patches-4.12.x/0012-vmbus-add-vmbus-onoffer-onoffer_rescind-sync.patch similarity index 95% rename from kernel/patches-4.12.x/0011-vmbus-add-vmbus-onoffer-onoffer_rescind-sync.patch rename to kernel/patches-4.12.x/0012-vmbus-add-vmbus-onoffer-onoffer_rescind-sync.patch index 69791e2c7..c8523673a 100644 --- a/kernel/patches-4.12.x/0011-vmbus-add-vmbus-onoffer-onoffer_rescind-sync.patch +++ b/kernel/patches-4.12.x/0012-vmbus-add-vmbus-onoffer-onoffer_rescind-sync.patch @@ -1,11 +1,11 @@ -From 5427bcb5e34615568731ff5633e7ab4cf0446a5f Mon Sep 17 00:00:00 2001 +From 3f99e5ffa5d5e3b6517f6e9c5049a7512f39437c Mon Sep 17 00:00:00 2001 From: Dexuan Cui Date: Mon, 5 Jun 2017 21:32:00 +0800 -Subject: [PATCH 11/15] vmbus: add vmbus onoffer/onoffer_rescind sync. +Subject: [PATCH 12/18] vmbus: add vmbus onoffer/onoffer_rescind sync. Signed-off-by: Dexuan Cui Origin: git@github.com:dcui/linux.git -(cherry picked from commit 1b91aa6d0e745d9765e3d90058928829f0b0bd40) +(cherry picked from commit 0465d97030768485eec5a69a98963e3da7402826) --- drivers/hv/channel_mgmt.c | 25 +++++++++++++++++++------ drivers/hv/hyperv_vmbus.h | 1 + diff --git a/kernel/patches-4.12.x/0013-hv-sock-a-temporary-workaround-for-the-pending_send_.patch b/kernel/patches-4.12.x/0013-hv-sock-a-temporary-workaround-for-the-pending_send_.patch new file mode 100644 index 000000000..aec0d0382 --- /dev/null +++ b/kernel/patches-4.12.x/0013-hv-sock-a-temporary-workaround-for-the-pending_send_.patch @@ -0,0 +1,133 @@ +From f39071cd6c497ef5cab9418f30655042f63f68a7 Mon Sep 17 00:00:00 2001 +From: Dexuan Cui +Date: Wed, 21 Jun 2017 22:30:42 +0800 +Subject: [PATCH 13/18] hv-sock: a temporary workaround for the + pending_send_size issue + +While I'm trying to find out the root cause, I believe this can work +as a good temporary workround for internal uses... + +Signed-off-by: Dexuan Cui +Origin: git@github.com:dcui/linux.git +(cherry picked from commit 7592de58cbf8d199d721503385c20a02743425a9) +--- + net/vmw_vsock/af_vsock.c | 7 +++++-- + net/vmw_vsock/hyperv_transport.c | 30 ++++++++++++++++++++++++------ + 2 files changed, 29 insertions(+), 8 deletions(-) + +diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c +index b7b2c66d91fd..4ebc1131c32d 100644 +--- a/net/vmw_vsock/af_vsock.c ++++ b/net/vmw_vsock/af_vsock.c +@@ -1544,7 +1544,7 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, + struct sock *sk; + struct vsock_sock *vsk; + ssize_t total_written; +- long timeout; ++ long timeout, timeout_once; + int err; + struct vsock_transport_send_notify_data send_data; + DEFINE_WAIT_FUNC(wait, woken_wake_function); +@@ -1613,7 +1613,7 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, + } + + release_sock(sk); +- timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, timeout); ++ timeout_once = wait_woken(&wait, TASK_INTERRUPTIBLE, 1); + lock_sock(sk); + if (signal_pending(current)) { + err = sock_intr_errno(timeout); +@@ -1623,6 +1623,9 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, + err = -EAGAIN; + remove_wait_queue(sk_sleep(sk), &wait); + goto out_err; ++ } else { ++ if (timeout_once == 0) ++ timeout--; + } + } + remove_wait_queue(sk_sleep(sk), &wait); +diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c +index 30154836acd0..b8bf1446ae13 100644 +--- a/net/vmw_vsock/hyperv_transport.c ++++ b/net/vmw_vsock/hyperv_transport.c +@@ -268,7 +268,7 @@ static void hvs_channel_cb(void *ctx) + sk->sk_data_ready(sk); + + /* Mark it writable only if there is enough space */ +- if (hvs_channel_writable_bytes(chan) >= HVS_SEND_BUF_SIZE) ++ if (hv_get_bytes_to_write(&chan->outbound) > 0) + sk->sk_write_space(sk); + } + +@@ -350,9 +350,11 @@ static void hvs_open_connection(struct vmbus_channel *chan) + set_per_channel_state(chan, conn_from_host ? new : sk); + vmbus_set_chn_rescind_callback(chan, hvs_close_connection); + ++#if 0 + /* See hvs_channel_cb() and hvs_notify_poll_out() */ + set_channel_pending_send_size(chan, + HVS_PKT_LEN(HVS_SEND_BUF_SIZE) + 1); ++#endif + + if (conn_from_host) { + new->sk_state = SS_CONNECTED; +@@ -542,7 +544,7 @@ static ssize_t hvs_stream_enqueue(struct vsock_sock *vsk, struct msghdr *msg, + struct hvsock *hvs = vsk->trans; + struct vmbus_channel *chan = hvs->chan; + struct hvs_send_buf *send_buf; +- size_t to_write, max_writable, ret; ++ ssize_t to_write, max_writable, ret; + + BUILD_BUG_ON(sizeof(*send_buf) != PAGE_SIZE_4K); + +@@ -551,8 +553,8 @@ static ssize_t hvs_stream_enqueue(struct vsock_sock *vsk, struct msghdr *msg, + return -ENOMEM; + + max_writable = hvs_channel_writable_bytes(chan); +- to_write = min_t(size_t, len, max_writable); +- to_write = min_t(size_t, to_write, HVS_SEND_BUF_SIZE); ++ to_write = min_t(ssize_t, len, max_writable); ++ to_write = min_t(ssize_t, to_write, HVS_SEND_BUF_SIZE); + + ret = memcpy_from_msg(send_buf->data, msg, to_write); + if (ret < 0) +@@ -595,8 +597,22 @@ static s64 hvs_stream_has_data(struct vsock_sock *vsk) + static s64 hvs_stream_has_space(struct vsock_sock *vsk) + { + struct hvsock *hvs = vsk->trans; ++ s64 ret; + +- return hvs_channel_writable_bytes(hvs->chan); ++ ret = hvs_channel_writable_bytes(hvs->chan); ++ if (ret > 0) { ++ set_channel_pending_send_size(hvs->chan, 0); ++ } else { ++ /* See hvs_channel_cb() and hvs_notify_poll_out() */ ++ set_channel_pending_send_size(hvs->chan, ++ HVS_PKT_LEN(HVS_SEND_BUF_SIZE) + 1); ++ ++ ret = hvs_channel_writable_bytes(hvs->chan); ++ if (ret > 0) ++ set_channel_pending_send_size(hvs->chan, 0); ++ } ++ ++ return ret; + } + + static u64 hvs_stream_rcvhiwat(struct vsock_sock *vsk) +@@ -646,8 +662,10 @@ int hvs_notify_poll_in(struct vsock_sock *vsk, size_t target, bool *readable) + static + int hvs_notify_poll_out(struct vsock_sock *vsk, size_t target, bool *writable) + { ++ struct hvsock *hvs = vsk->trans; ++ + /* Report writable only if there is enough space */ +- *writable = hvs_stream_has_space(vsk) >= HVS_SEND_BUF_SIZE; ++ *writable = hvs_channel_writable_bytes(hvs->chan) > 0; + + return 0; + } +-- +2.14.1 + diff --git a/kernel/patches-4.12.x/0014-Added-vsock-transport-support-to-9pfs.patch b/kernel/patches-4.12.x/0014-Added-vsock-transport-support-to-9pfs.patch deleted file mode 100644 index 037fd5eef..000000000 --- a/kernel/patches-4.12.x/0014-Added-vsock-transport-support-to-9pfs.patch +++ /dev/null @@ -1,151 +0,0 @@ -From 44570fbde0c9eceb4c9e890bb084197a7f186c84 Mon Sep 17 00:00:00 2001 -From: Cheng-mean Liu -Date: Tue, 11 Jul 2017 16:50:36 -0700 -Subject: [PATCH 14/15] Added vsock transport support to 9pfs - -Signed-off-by: Cheng-mean Liu -Origin: https://github.com/Microsoft/opengcs/blob/master/kernelconfig/4.11/patch_9pfs_vsock-transport.patch ---- - net/9p/trans_fd.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- - 1 file changed, 84 insertions(+), 1 deletion(-) - -diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c -index 7bc2208b6cc4..dc34352145df 100644 ---- a/net/9p/trans_fd.c -+++ b/net/9p/trans_fd.c -@@ -44,8 +44,9 @@ - #include - #include - #include -- - #include /* killme */ -+//#include -+#include - - #define P9_PORT 564 - #define MAX_SOCK_BUF (64*1024) -@@ -155,6 +156,7 @@ struct p9_trans_fd { - struct p9_conn conn; - }; - -+ - static void p9_poll_workfn(struct work_struct *work); - - static DEFINE_SPINLOCK(p9_poll_lock); -@@ -740,6 +742,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts) - opts->wfd = ~0; - opts->privport = 0; - -+ - if (!params) - return 0; - -@@ -1035,6 +1038,72 @@ p9_fd_create(struct p9_client *client, const char *addr, char *args) - return 0; - } - -+static int -+p9_fd_create_vsock(struct p9_client *client, const char *addr, char *args) -+{ -+ int err; -+ struct socket *csocket; -+ struct sockaddr_vm server_socket_addr; -+ struct p9_fd_opts opts; -+ -+ err = parse_opts(args, &opts); -+ if (err < 0) -+ return err; -+ -+ csocket = NULL; -+ -+ // for debugging purpose only -+ pr_err("%s:%s\n", __func__, addr); -+ // kgdb_breakpoint(); -+ -+ // create socket -+ err = __sock_create(current->nsproxy->net_ns, -+ AF_VSOCK, -+ SOCK_STREAM, -+ 0, -+ &csocket, 1); -+ if (err) { -+ pr_err("%s:__sock_create (%d): problem creating socket (err=%d)\n", -+ __func__, task_pid_nr(current), err); -+ return err; -+ } -+ -+ // server socket address information -+ memset((char *)&server_socket_addr, 0, sizeof(struct sockaddr_vm)); -+ server_socket_addr.svm_family = AF_VSOCK; -+ server_socket_addr.svm_reserved1 = 0; -+ server_socket_addr.svm_cid = VMADDR_CID_HOST; -+ -+ /* Connecting to the host's 0000pppp-facb-11e6-bd58-64006a7986d3 */ -+ server_socket_addr.svm_port = opts.port; -+ -+ pr_err("%s:opts.port=(%d)(0x%x)\n", __func__, opts.port, opts.port); -+ pr_err("%s: service_id:(hex) 0000%x%x-facb-11e6-bd58-64006a7986d3\n", -+ __func__, -+ (__u8)((opts.port & 0xff00) >> 8), -+ (__u8)(opts.port & 0x00ff)); -+ -+ pr_err("%s: connecting", __func__); -+ err = csocket->ops->connect(csocket, -+ (struct sockaddr *)&server_socket_addr, -+ sizeof(struct sockaddr_vm), 0); -+ if (err < 0) { -+ pr_err("%s:connect (%d): problem connecting socket to %s (err = %d)\n", -+ __func__, task_pid_nr(current), addr, err); -+ sock_release(csocket); -+ return err; -+ } -+ -+ pr_err("%s: open socket", __func__); -+ err = p9_socket_open(client, csocket); -+ if (err < 0) { -+ pr_err("%s: p9_socket_open failed\n", __func__); -+ } -+ -+ pr_err("Leaving %s\n", __func__); -+ return err; -+} -+ - static struct p9_trans_module p9_tcp_trans = { - .name = "tcp", - .maxsize = MAX_SOCK_BUF, -@@ -1071,6 +1140,18 @@ static struct p9_trans_module p9_fd_trans = { - .owner = THIS_MODULE, - }; - -+static struct p9_trans_module p9_vsock_trans = { -+ .name = "vsock", -+ .maxsize = MAX_SOCK_BUF, -+ .def = 0, -+ .create = p9_fd_create_vsock, -+ .close = p9_fd_close, -+ .request = p9_fd_request, -+ .cancel = p9_fd_cancel, -+ .cancelled = p9_fd_cancelled, -+ .owner = THIS_MODULE, -+}; -+ - /** - * p9_poll_proc - poll worker thread - * @a: thread state and arguments -@@ -1108,6 +1189,7 @@ int p9_trans_fd_init(void) - v9fs_register_trans(&p9_tcp_trans); - v9fs_register_trans(&p9_unix_trans); - v9fs_register_trans(&p9_fd_trans); -+ v9fs_register_trans(&p9_vsock_trans); - - return 0; - } -@@ -1118,4 +1200,5 @@ void p9_trans_fd_exit(void) - v9fs_unregister_trans(&p9_tcp_trans); - v9fs_unregister_trans(&p9_unix_trans); - v9fs_unregister_trans(&p9_fd_trans); -+ v9fs_unregister_trans(&p9_vsock_trans); - } --- -2.14.1 - diff --git a/kernel/patches-4.12.x/0012-vmbus-fix-the-missed-signaling-in-hv_signal_on_read.patch b/kernel/patches-4.12.x/0014-vmbus-fix-the-missed-signaling-in-hv_signal_on_read.patch similarity index 85% rename from kernel/patches-4.12.x/0012-vmbus-fix-the-missed-signaling-in-hv_signal_on_read.patch rename to kernel/patches-4.12.x/0014-vmbus-fix-the-missed-signaling-in-hv_signal_on_read.patch index 6b3e644e2..ec0439611 100644 --- a/kernel/patches-4.12.x/0012-vmbus-fix-the-missed-signaling-in-hv_signal_on_read.patch +++ b/kernel/patches-4.12.x/0014-vmbus-fix-the-missed-signaling-in-hv_signal_on_read.patch @@ -1,7 +1,7 @@ -From af7743fa98a12e9cafdc85daf2ed58e6f8d22c36 Mon Sep 17 00:00:00 2001 +From fb708e2a42ad325401c2b056fd834ffe1de1ae94 Mon Sep 17 00:00:00 2001 From: Dexuan Cui Date: Wed, 28 Jun 2017 23:50:38 +0800 -Subject: [PATCH 12/15] vmbus: fix the missed signaling in hv_signal_on_read() +Subject: [PATCH 14/18] vmbus: fix the missed signaling in hv_signal_on_read() There is an off-by-one bug here, which can cause host-to-guest write to stall. @@ -13,7 +13,7 @@ But when cached_write_sz == pending_sz, we must signal the host. Signed-off-by: John Starks Signed-off-by: Dexuan Cui Origin: git@github.com:dcui/linux.git -(cherry picked from commit c49aced6328557e6c1f5cf6f58e1fae96fb58fa0) +(cherry picked from commit 02d07a9dcdb042f33248fd3aeb1e5c2eca6d3d49) --- include/linux/hyperv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/patches-4.12.x/0013-hv_sock-avoid-double-FINs-if-shutdown-is-called.patch b/kernel/patches-4.12.x/0015-hv-sock-avoid-double-FINs-if-shutdown-is-called.patch similarity index 59% rename from kernel/patches-4.12.x/0013-hv_sock-avoid-double-FINs-if-shutdown-is-called.patch rename to kernel/patches-4.12.x/0015-hv-sock-avoid-double-FINs-if-shutdown-is-called.patch index fa4ece89b..813f68424 100644 --- a/kernel/patches-4.12.x/0013-hv_sock-avoid-double-FINs-if-shutdown-is-called.patch +++ b/kernel/patches-4.12.x/0015-hv-sock-avoid-double-FINs-if-shutdown-is-called.patch @@ -1,23 +1,19 @@ -From b203b317bfe37f32d1c34e388b50900cec44d941 Mon Sep 17 00:00:00 2001 +From a2bb72bc520dccdd5482d66fb394f551fbc0a4bb Mon Sep 17 00:00:00 2001 From: Dexuan Cui -Date: Wed, 26 Jul 2017 12:32:08 -0600 -Subject: [PATCH 13/15] hv_sock: avoid double FINs if shutdown() is called +Date: Fri, 7 Jul 2017 09:15:29 +0800 +Subject: [PATCH 15/18] hv-sock: avoid double FINs if shutdown() is called -The host expects a single FIN according to Hyperv-V team. -With the patch, the connection may not be cleanly closed. +The host expects a single FIN. Signed-off-by: Dexuan Cui -Cc: K. Y. Srinivasan -Cc: Haiyang Zhang -Cc: Stephen Hemminger Origin: git@github.com:dcui/linux.git -(cherry picked from commit 82235a6f52a493a18f61c4f7f7deffc8558d5c5e) +(cherry picked from commit f315dfcf9c3b4b32f43a21664762cbacd8f05d6a) --- net/vmw_vsock/hyperv_transport.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c -index 30154836acd0..693dfb7944a6 100644 +index b8bf1446ae13..50e4bc822c69 100644 --- a/net/vmw_vsock/hyperv_transport.c +++ b/net/vmw_vsock/hyperv_transport.c @@ -95,6 +95,9 @@ struct hvsock { @@ -30,7 +26,7 @@ index 30154836acd0..693dfb7944a6 100644 }; /* In the VM, we support Hyper-V Sockets with AF_VSOCK, and the endpoint is -@@ -423,6 +426,9 @@ static int hvs_shutdown(struct vsock_sock *vsk, int mode) +@@ -425,6 +428,9 @@ static int hvs_shutdown(struct vsock_sock *vsk, int mode) hvs = vsk->trans; diff --git a/kernel/patches-4.12.x/0016-vmbus-destroy-a-hv_sock-device-only-after-the-RESCIN.patch b/kernel/patches-4.12.x/0016-vmbus-destroy-a-hv_sock-device-only-after-the-RESCIN.patch new file mode 100644 index 000000000..07e3c097d --- /dev/null +++ b/kernel/patches-4.12.x/0016-vmbus-destroy-a-hv_sock-device-only-after-the-RESCIN.patch @@ -0,0 +1,49 @@ +From 8191f7c4947b305af3dc6a5f545b4db0db9fb408 Mon Sep 17 00:00:00 2001 +From: Dexuan Cui +Date: Tue, 29 Aug 2017 14:23:39 -0700 +Subject: [PATCH 16/18] vmbus: destroy a hv_sock device only after the + RESCIND_OFFER is received + +It looks the host/guest interactive protocol for hv_sock has been changed +since Windows Server TP5, and now Linux VM should only destroy the channel +after the host agrees: the host always sends a RESCIND_OFFER message to the +VM for this). + +Without the patch, the host's recv() can return -1 when Linux closes a +hv_sock connection, and as a result, the host app can potentially lose the +last portion of the data transferred through the hv_sock connection. + +Signed-off-by: Dexuan Cui +Origin: git@github.com:dcui/linux.git +(cherry picked from commit d6f7158fdbac10f9935a506451e3d54d2d50a7c7) +--- + drivers/hv/channel_mgmt.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c +index a12b1eabc15e..83d4292e4351 100644 +--- a/drivers/hv/channel_mgmt.c ++++ b/drivers/hv/channel_mgmt.c +@@ -905,6 +905,9 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) + if (channel->device_obj) { + if (channel->chn_rescind_callback) { + channel->chn_rescind_callback(channel); ++ ++ vmbus_device_unregister(channel->device_obj); ++ + return; + } + /* +@@ -955,9 +958,6 @@ void vmbus_hvsock_device_unregister(struct vmbus_channel *channel) + vmbus_connection.work_queue_rescind, &work); + flush_work(&work); + +- channel->rescind = true; +- vmbus_device_unregister(channel->device_obj); +- + /* Unblock the rescind handling */ + atomic_dec(&vmbus_connection.offer_in_progress); + } +-- +2.14.1 + diff --git a/kernel/patches-4.12.x/0017-ext4-fix-fault-handling-when-mounted-with-o-dax-ro.patch b/kernel/patches-4.12.x/0017-ext4-fix-fault-handling-when-mounted-with-o-dax-ro.patch new file mode 100644 index 000000000..77e24869c --- /dev/null +++ b/kernel/patches-4.12.x/0017-ext4-fix-fault-handling-when-mounted-with-o-dax-ro.patch @@ -0,0 +1,61 @@ +From 6362088c562dbd61f4fce28793440466bbedc635 Mon Sep 17 00:00:00 2001 +From: Randy Dodgen +Date: Thu, 24 Aug 2017 15:26:01 -0400 +Subject: [PATCH 17/18] ext4: fix fault handling when mounted with -o dax,ro + +If an ext4 filesystem is mounted with both the DAX and read-only +options, executables on that filesystem will fail to start (claiming +'Segmentation fault') due to the fault handler returning +VM_FAULT_SIGBUS. + +This is due to the DAX fault handler (see ext4_dax_huge_fault) +attempting to write to the journal when FAULT_FLAG_WRITE is set. This is +the wrong behavior for write faults which will lead to a COW page; in +particular, this fails for readonly mounts. + +This change avoids journal writes for faults that are expected to COW. + +It might be the case that this could be better handled in +ext4_iomap_begin / ext4_iomap_end (called via iomap_ops inside +dax_iomap_fault). These is some overlap already (e.g. grabbing journal +handles). + +Signed-off-by: Randy Dodgen +Signed-off-by: Theodore Ts'o +Reviewed-by: Jan Kara +Reviewed-by: Ross Zwisler +Origin: https://github.com/torvalds/linux +(cherry picked from commit fd96b8da68d32a9403726db09b229f4b5ac849c7) +--- + fs/ext4/file.c | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +diff --git a/fs/ext4/file.c b/fs/ext4/file.c +index 407fc5aa32a7..d8b9cb1109aa 100644 +--- a/fs/ext4/file.c ++++ b/fs/ext4/file.c +@@ -260,7 +260,20 @@ static int ext4_dax_huge_fault(struct vm_fault *vmf, + handle_t *handle = NULL; + struct inode *inode = file_inode(vmf->vma->vm_file); + struct super_block *sb = inode->i_sb; +- bool write = vmf->flags & FAULT_FLAG_WRITE; ++ ++ /* ++ * We have to distinguish real writes from writes which will result in a ++ * COW page; COW writes should *not* poke the journal (the file will not ++ * be changed). Doing so would cause unintended failures when mounted ++ * read-only. ++ * ++ * We check for VM_SHARED rather than vmf->cow_page since the latter is ++ * unset for pe_size != PE_SIZE_PTE (i.e. only in do_cow_fault); for ++ * other sizes, dax_iomap_fault will handle splitting / fallback so that ++ * we eventually come back with a COW page. ++ */ ++ bool write = (vmf->flags & FAULT_FLAG_WRITE) && ++ (vmf->vma->vm_flags & VM_SHARED); + + if (write) { + sb_start_pagefault(sb); +-- +2.14.1 + diff --git a/kernel/patches-4.12.x/0015-NVDIMM-reducded-ND_MIN_NAMESPACE_SIZE-from-4MB-to-4K.patch b/kernel/patches-4.12.x/0018-NVDIMM-reducded-ND_MIN_NAMESPACE_SIZE-from-4MB-to-4K.patch similarity index 84% rename from kernel/patches-4.12.x/0015-NVDIMM-reducded-ND_MIN_NAMESPACE_SIZE-from-4MB-to-4K.patch rename to kernel/patches-4.12.x/0018-NVDIMM-reducded-ND_MIN_NAMESPACE_SIZE-from-4MB-to-4K.patch index 3a531251b..ae4fd365e 100644 --- a/kernel/patches-4.12.x/0015-NVDIMM-reducded-ND_MIN_NAMESPACE_SIZE-from-4MB-to-4K.patch +++ b/kernel/patches-4.12.x/0018-NVDIMM-reducded-ND_MIN_NAMESPACE_SIZE-from-4MB-to-4K.patch @@ -1,7 +1,7 @@ -From 6654360f103281d1390fd9a8c4770096c8bfa584 Mon Sep 17 00:00:00 2001 +From 5440b60ad788331d76da618d163ba57a9463c75d Mon Sep 17 00:00:00 2001 From: Cheng-mean Liu Date: Tue, 11 Jul 2017 16:58:26 -0700 -Subject: [PATCH 15/15] NVDIMM: reducded ND_MIN_NAMESPACE_SIZE from 4MB to 4KB +Subject: [PATCH 18/18] NVDIMM: reducded ND_MIN_NAMESPACE_SIZE from 4MB to 4KB (page size) Signed-off-by: Cheng-mean Liu From adb92ca672f73ba9a29081fc0e7bb63d075c4ae7 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Fri, 15 Sep 2017 14:44:33 +0100 Subject: [PATCH 2/3] pkg/init-lcow: Update to the latest version This includes fixes to the intermittent on pull as well as other fixes. Signed-off-by: Rolf Neugebauer --- pkg/init-lcow/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/init-lcow/Dockerfile b/pkg/init-lcow/Dockerfile index f0b4c2415..3cafdfdec 100644 --- a/pkg/init-lcow/Dockerfile +++ b/pkg/init-lcow/Dockerfile @@ -9,7 +9,7 @@ RUN rm -rf /out/etc/apk /out/lib/apk /out/var/cache FROM linuxkit/alpine:349a817bdd6b293ca623ab97acf5377ccdeac7d2 AS build ENV OPENGCS_REPO=https://github.com/Microsoft/opengcs -ENV OPENGCS_COMMIT=203a54283e0b0d58c1bc9d8d0f0b4bea8503fe37 +ENV OPENGCS_COMMIT=de29646b8dfadfc443e1467bd4b493e9068fb582 RUN apk add --no-cache build-base curl git go musl-dev ENV GOPATH=/go PATH=$PATH:/go/bin RUN git clone $OPENGCS_REPO /go/src/github.com/Microsoft/opengcs && \ From f547ac7259f6203419357d3dbb927710e871a9c1 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Fri, 15 Sep 2017 14:50:23 +0100 Subject: [PATCH 3/3] blueprint: Update LCOW blueprint - Use the new 4.12.13 kernel as it now seems to work - Update LCOW to latest rev of OpenGCS Signed-off-by: Rolf Neugebauer --- blueprints/lcow.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/blueprints/lcow.yml b/blueprints/lcow.yml index c37ed12e7..163cb74a6 100644 --- a/blueprints/lcow.yml +++ b/blueprints/lcow.yml @@ -1,14 +1,9 @@ -# We specifically pick 4.11.1 here as newer 4.11.x kernel have some -# interactions with the current Hyper-V NVDIMM implementation. -# Specifically, Linux commit 5a3651b4a92c ("ext4: return to starting -# transaction in ext4_dax_huge_fault()") seems to trigger silent failures -# when running the Hyper-V container VM. kernel: - image: linuxkit/kernel:4.11.1-ce8345023d3f2dff16f8edeeca9331b26a199949 + image: linuxkit/kernel:4.12.13 cmdline: "console=ttyS0" tar: none init: - - linuxkit/init-lcow:b1f58571eadf48ec46a8265a087f7869a3189b21 + - linuxkit/init-lcow:b5d156bfc1318a1c7b94320c87d634e5fd0da091 - linuxkit/runc:a1b564248a0d0b118c11e61db9f84ecf41dd2d2a trust: org: