Received: by 10.192.165.148 with SMTP id m20csp4831093imm; Tue, 8 May 2018 15:27:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq8ZYw06PZF5BCzNhW4qUBYsIO7aTzLsFSWVFHtvvSYoJpROr6QHrhuKjEnG+ntLZQBAOpZ X-Received: by 2002:a17:902:343:: with SMTP id 61-v6mr44243367pld.39.1525818432135; Tue, 08 May 2018 15:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525818432; cv=none; d=google.com; s=arc-20160816; b=ewoqhd/qo6L12011EkQuSKDO3fQ865/4K4a8DQh0ncAKPkJuV7ZSmmuTTD4Z8oMndK d6Oed5RjfTvfUZjiQninE1fHXszBvxZx/MqnQzTDKDEf4fjO6wS/JwasODH65ywXqLUZ wmDfmMeBFUJVUknUBAEt4qvXqwYCRqrx7jchwEM8FvTVBVo6XWwAKtVRu92Qpy0UzftF u9djVojnFFFa8pxbrsoT03u+r6nWhSc1fi14D3Urni+1sLNZMYyFILym/Zb7wbQKdenw YfUfHJ3wmgP+++TGxyjYA/f8Wiz0kB4ZsWZXzQD6seVmPViMwp6c1Qth27aUUvbOJDuw mgDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:msip_labels :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=E1euTv2mWKInLEKULRsECHZWoP5pQxhjJ7Cyt/GC3oA=; b=NwTY6/CHIxrT+w+NyYHRguUOlIA3CAGTaFYqJIvvrhK6E9RqVvMV9Cyh18CutPj7AE 6HN0BgiJ/zHj8JvPD8ylqQiTqHXjaarcR8J+Knx9oU8tFhgkh/kmPXe1nR9OTo7QFV9k 5mH+CiVjxnMgB+Pb7RxJjDIuZKFZh7a2zS1mIN8yKYdbVkougqsI7yIkxApu5l64nt4W qAGeAKlRyxRIfOYWJYjBa53t1BpKsg/OE6tu1e4ATcAIrttXNlvCGgkSIizxx4U3u9Oy YDL47ozVfIGRcb5nQyTtOLPqBqcQRNqAn0LJDLRCmfsJbWh7scbp3uUSexUL7HMdMDcd VTwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=myQhsqJa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l4-v6si25009088plb.213.2018.05.08.15.26.57; Tue, 08 May 2018 15:27:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=myQhsqJa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932760AbeEHW0i (ORCPT + 99 others); Tue, 8 May 2018 18:26:38 -0400 Received: from mail-pu1apc01on0108.outbound.protection.outlook.com ([104.47.126.108]:20255 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932314AbeEHW0g (ORCPT ); Tue, 8 May 2018 18:26:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=E1euTv2mWKInLEKULRsECHZWoP5pQxhjJ7Cyt/GC3oA=; b=myQhsqJaxj5b6UMCwyobUYzrP1FBn2i0gt5JZpbx887sTSBmkRW7dvmwFwY/p6ObKmmXRqZs0swrdlAa9cDVmSSCuEzP34OzwMHgK9n4MpIS4a+neasBbMxOLKZ86bV8Zj+GDLaMAbp63K3OU0f9DrEaQw5f2qpJvuKvZ8WPJis= Received: from KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM (10.170.167.17) by KL1P15301MB0087.APCP153.PROD.OUTLOOK.COM (10.170.165.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.776.4; Tue, 8 May 2018 22:26:22 +0000 Received: from KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM ([10.170.167.17]) by KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM ([10.170.167.17]) with mapi id 15.20.0755.012; Tue, 8 May 2018 22:26:21 +0000 From: Dexuan Cui To: "'gregkh@linuxfoundation.org'" , "'driverdev-devel@linuxdriverproject.org'" , KY Srinivasan , Stephen Hemminger , "Michael Kelley (EOSG)" CC: "'linux-kernel@vger.kernel.org'" , "'olaf@aepfle.de'" , "'apw@canonical.com'" , "'jasowang@redhat.com'" , "'vkuznets@redhat.com'" , "'marcelo.cerri@canonical.com'" , Jork Loeser Subject: [PATCH] Drivers: hv: vmbus: enable VMBus protocol version 5.0 Thread-Topic: [PATCH] Drivers: hv: vmbus: enable VMBus protocol version 5.0 Thread-Index: AdPnGpZjEjN6JH3ySGSQrnm2yoYh9w== Date: Tue, 8 May 2018 22:26:21 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=True; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Owner=decui@microsoft.com; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2018-05-08T22:26:18.1825905Z; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=General; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Application=Microsoft Azure Information Protection; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Extended_MSFT_Method=Automatic; Sensitivity=General authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-originating-ip: [131.107.159.5] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;KL1P15301MB0087;7:1ITn5nU5oSIio4I1mCTmrcJyoCAUcYPsecCeRWYMt21yJKDRUX4v6Yy7QpGQ85agzYl2p4XrwGw6l8Zjr6iKtJP4mbGrnPgAT8SNhJ7Ilp9MZlODpUQGIEFDt6V4GUCwpa/3R6SCGdlfF8+WvVNLcvymlKLbB9Kj+kJInPmWg480TEww1Zv0B30iDscvzoMtgtrdyY1Sk70lwtJ+gfIXkoen6lW8NE8CK2i4oyFs7pbtTN6913oRrqioWp0qjFbQ;20:/jURTARTfOg12QRCVt6cUX1r+AORw+srIEm7kI2uJw4SZ0qU+zRnOppznemPC6TfAhvZEb6qx/oAq5FtgzmMsb9QRAIuIZc+laNPA259HIiSBEgitf5+G6WuvySkMboCXj8DiKgJG/5FsrgW78UIn/JqDk/sNYFo//Fw73QgW5g= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(48565401081)(2017052603328)(7193020);SRVR:KL1P15301MB0087; x-ms-traffictypediagnostic: KL1P15301MB0087: x-o365ent-eop-header: Message processed by - O365_ENT: Allow from ranges (Engineering ONLY) x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(21532816269658); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231254)(944501410)(52105095)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011);SRVR:KL1P15301MB0087;BCL:0;PCL:0;RULEID:;SRVR:KL1P15301MB0087; x-forefront-prvs: 0666E15D35 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(396003)(376002)(366004)(346002)(39860400002)(24433001)(199004)(189003)(6436002)(25786009)(10090500001)(66066001)(7696005)(9686003)(102836004)(4326008)(107886003)(1511001)(55016002)(2900100001)(476003)(486006)(6506007)(59450400001)(53936002)(81156014)(6636002)(1857600001)(8676002)(74316002)(81166006)(10290500003)(316002)(22452003)(8936002)(5660300001)(106356001)(305945005)(14454004)(105586002)(3660700001)(54906003)(110136005)(3280700002)(68736007)(7736002)(97736004)(99286004)(86612001)(33656002)(86362001)(8990500004)(77096007)(3846002)(6116002)(26005)(478600001)(186003)(2906002)(491001);DIR:OUT;SFP:1102;SCL:1;SRVR:KL1P15301MB0087;H:KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 5IBIqYzi85ILiH5fp7TNopVNM/YED3g3kXbkAA9R1bWaXbq0WNUH8cANtY/kNGx5ieuAQtJp3TuyhKYcfikgJkqJYkTaPOf81JDB0sBSWw61kef7RdQAwodiMAR2M4VShSwzZuVROtouN2XUgS1xSWyHyKTPceBTk6IMZzjYEOA9kMZIrHZQlxY0D3CcX9ch spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: f9a280bf-8ae4-474a-d9bb-08d5b532b9f2 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9a280bf-8ae4-474a-d9bb-08d5b532b9f2 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 May 2018 22:26:21.0821 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1P15301MB0087 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With VMBus protocol 5.0, we're able to better support new features, e.g. running two or more VMBus drivers simultaneously in a single VM -- note: we can't simply load the current VMBus driver twice, instead, a secondary VMBus driver must be implemented. This patch adds the support for the new VMBus protocol, which is available on new Windows hosts, by: 1) We still use SINT2 for compatibility; 2) We must use Connection ID 4 for the Initiate Contact Message, and for subsequent messages, we must use the Message Connection ID field in the host-returned VersionResponse Message. Notes for developers of the secondary VMBus driver: 1) Must use VMBus protocol 5.0 as well; 2) Must use a different SINT number that is not in use. 3) Must use Connection ID 4 for the Initiate Contact Message, and for subsequent messages, must use the Message Connection ID field in the host-returned VersionResponse Message. 4) It's possible that the primary VMBus driver using protocol version 4.0 can work with a secondary VMBus driver using protocol version 5.0, but it's recommended that both should use 5.0 for new Hyper-V features in the future= . Signed-off-by: Dexuan Cui Cc: Stephen Hemminger Cc: K. Y. Srinivasan Cc: Michael Kelley --- drivers/hv/connection.c | 44 ++++++++++++++++++++++++++++++++++++++++++-= - drivers/hv/hyperv_vmbus.h | 3 +++ include/linux/hyperv.h | 26 ++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 7285518..19e0468 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -63,6 +63,9 @@ static __u32 vmbus_get_next_version(__u32 current_version= ) case (VERSION_WIN10): return VERSION_WIN8_1; =20 + case (VERSION_WIN10_V5): + return VERSION_WIN10; + case (VERSION_WS2008): default: return VERSION_INVAL; @@ -80,9 +83,29 @@ static int vmbus_negotiate_version(struct vmbus_channel_= msginfo *msginfo, =20 msg =3D (struct vmbus_channel_initiate_contact *)msginfo->msg; =20 + memset(msg, 0, sizeof(*msg)); msg->header.msgtype =3D CHANNELMSG_INITIATE_CONTACT; msg->vmbus_version_requested =3D version; - msg->interrupt_page =3D virt_to_phys(vmbus_connection.int_page); + + /* + * VMBus protocol 5.0 (VERSION_WIN10_V5) requires that we must use + * VMBUS_MESSAGE_CONNECTION_ID_4 for the Initiate Contact Message, + * and for subsequent messages, we must use the Message Connection ID + * field in the host-returned Version Response Message. And, with + * VERSION_WIN10_V5, we don't use msg->interrupt_page, but we tell + * the host explicitly that we still use VMBUS_MESSAGE_SINT(2) for + * compatibility. + * + * On old hosts, we should always use VMBUS_MESSAGE_CONNECTION_ID (1). + */ + if (version >=3D VERSION_WIN10_V5) { + msg->msg_sint =3D VMBUS_MESSAGE_SINT; + vmbus_connection.msg_conn_id =3D VMBUS_MESSAGE_CONNECTION_ID_4; + } else { + msg->interrupt_page =3D virt_to_phys(vmbus_connection.int_page); + vmbus_connection.msg_conn_id =3D VMBUS_MESSAGE_CONNECTION_ID; + } + msg->monitor_page1 =3D virt_to_phys(vmbus_connection.monitor_pages[0]); msg->monitor_page2 =3D virt_to_phys(vmbus_connection.monitor_pages[1]); /* @@ -137,6 +160,10 @@ static int vmbus_negotiate_version(struct vmbus_channe= l_msginfo *msginfo, /* Check if successful */ if (msginfo->response.version_response.version_supported) { vmbus_connection.conn_state =3D CONNECTED; + + if (version >=3D VERSION_WIN10_V5) + vmbus_connection.msg_conn_id =3D + msginfo->response.version_response.msg_conn_id; } else { return -ECONNREFUSED; } @@ -354,13 +381,14 @@ void vmbus_on_event(unsigned long data) */ int vmbus_post_msg(void *buffer, size_t buflen, bool can_sleep) { + struct vmbus_channel_message_header *hdr; union hv_connection_id conn_id; int ret =3D 0; int retries =3D 0; u32 usec =3D 1; =20 conn_id.asu32 =3D 0; - conn_id.u.id =3D VMBUS_MESSAGE_CONNECTION_ID; + conn_id.u.id =3D vmbus_connection.msg_conn_id; =20 /* * hv_post_message() can have transient failures because of @@ -373,6 +401,18 @@ int vmbus_post_msg(void *buffer, size_t buflen, bool c= an_sleep) switch (ret) { case HV_STATUS_INVALID_CONNECTION_ID: /* + * See vmbus_negotiate_version(): VMBus protocol 5.0 + * requires that we must use + * VMBUS_MESSAGE_CONNECTION_ID_4 for the Initiate + * Contact message, but on old hosts that only + * support VMBus protocol 4.0 or lower, here we get + * HV_STATUS_INVALID_CONNECTION_ID and we should + * return an error immediately without retrying. + */ + hdr =3D (struct vmbus_channel_message_header *)buffer; + if (hdr->msgtype =3D=3D CHANNELMSG_INITIATE_CONTACT) + return -EINVAL; + /* * We could get this if we send messages too * frequently. */ diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index f761bef3..72eaba3 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -187,6 +187,7 @@ struct hv_input_post_message { =20 enum { VMBUS_MESSAGE_CONNECTION_ID =3D 1, + VMBUS_MESSAGE_CONNECTION_ID_4 =3D 4, VMBUS_MESSAGE_PORT_ID =3D 1, VMBUS_EVENT_CONNECTION_ID =3D 2, VMBUS_EVENT_PORT_ID =3D 2, @@ -302,6 +303,8 @@ struct vmbus_connection { */ int connect_cpu; =20 + u32 msg_conn_id; + atomic_t offer_in_progress; =20 enum vmbus_connect_state conn_state; diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 192ed8f..11b5612 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -163,6 +163,7 @@ static inline u32 hv_get_bytes_to_write(const struct hv= _ring_buffer_info *rbi) * 2 . 4 (Windows 8) * 3 . 0 (Windows 8 R2) * 4 . 0 (Windows 10) + * 5 . 0 (Newer Windows 10) */ =20 #define VERSION_WS2008 ((0 << 16) | (13)) @@ -170,10 +171,11 @@ static inline u32 hv_get_bytes_to_write(const struct = hv_ring_buffer_info *rbi) #define VERSION_WIN8 ((2 << 16) | (4)) #define VERSION_WIN8_1 ((3 << 16) | (0)) #define VERSION_WIN10 ((4 << 16) | (0)) +#define VERSION_WIN10_V5 ((5 << 16) | (0)) =20 #define VERSION_INVAL -1 =20 -#define VERSION_CURRENT VERSION_WIN10 +#define VERSION_CURRENT VERSION_WIN10_V5 =20 /* Make maximum size of pipe payload of 16K */ #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384) @@ -570,7 +572,14 @@ struct vmbus_channel_initiate_contact { struct vmbus_channel_message_header header; u32 vmbus_version_requested; u32 target_vcpu; /* The VCPU the host should respond to */ - u64 interrupt_page; + union { + u64 interrupt_page; + struct { + u8 msg_sint; + u8 padding1[3]; + u32 padding2; + }; + }; u64 monitor_page1; u64 monitor_page2; } __packed; @@ -585,6 +594,19 @@ struct vmbus_channel_tl_connect_request { struct vmbus_channel_version_response { struct vmbus_channel_message_header header; u8 version_supported; + + u8 connection_state; + u16 padding; + + /* + * On new hosts that support VMBus protocol 5.0, we must use + * VMBUS_MESSAGE_CONNECTION_ID_4 for the Initiate Contact Message, + * and for subsequent messages, we must use the Message Connection ID + * field in the host-returned Version Response Message. + * + * On old hosts, we should always use VMBUS_MESSAGE_CONNECTION_ID (1). + */ + u32 msg_conn_id; } __packed; =20 enum vmbus_channel_state { --=20 2.7.4