svn commit: r304788 - head/sys/dev/hyperv/utilities

Sepherosa Ziehau sephe at FreeBSD.org
Thu Aug 25 05:24:58 UTC 2016


Author: sephe
Date: Thu Aug 25 05:24:57 2016
New Revision: 304788
URL: https://svnweb.freebsd.org/changeset/base/304788

Log:
  hyperv/ic: Update total message size if negotiate message size grows.
  
  MFC after:	1 week
  Sponsored by:	Microsoft
  Differential Revision:	https://reviews.freebsd.org/D7627

Modified:
  head/sys/dev/hyperv/utilities/hv_heartbeat.c
  head/sys/dev/hyperv/utilities/hv_shutdown.c
  head/sys/dev/hyperv/utilities/hv_timesync.c
  head/sys/dev/hyperv/utilities/hv_util.c
  head/sys/dev/hyperv/utilities/hv_util.h

Modified: head/sys/dev/hyperv/utilities/hv_heartbeat.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_heartbeat.c	Thu Aug 25 05:22:53 2016	(r304787)
+++ head/sys/dev/hyperv/utilities/hv_heartbeat.c	Thu Aug 25 05:24:57 2016	(r304788)
@@ -80,7 +80,7 @@ vmbus_heartbeat_cb(struct vmbus_channel 
 	 */
 	switch (hdr->ic_type) {
 	case VMBUS_ICMSG_TYPE_NEGOTIATE:
-		error = vmbus_ic_negomsg(sc, data, dlen);
+		error = vmbus_ic_negomsg(sc, data, &dlen);
 		if (error)
 			return;
 		break;

Modified: head/sys/dev/hyperv/utilities/hv_shutdown.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_shutdown.c	Thu Aug 25 05:22:53 2016	(r304787)
+++ head/sys/dev/hyperv/utilities/hv_shutdown.c	Thu Aug 25 05:24:57 2016	(r304788)
@@ -87,7 +87,7 @@ hv_shutdown_cb(struct vmbus_channel *cha
 	    if (icmsghdrp->icmsgtype == HV_ICMSGTYPE_NEGOTIATE) {
 		int error;
 
-		error = vmbus_ic_negomsg(softc, buf, recv_len);
+		error = vmbus_ic_negomsg(softc, buf, &recv_len);
 		if (error)
 			return;
 	    } else {

Modified: head/sys/dev/hyperv/utilities/hv_timesync.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_timesync.c	Thu Aug 25 05:22:53 2016	(r304787)
+++ head/sys/dev/hyperv/utilities/hv_timesync.c	Thu Aug 25 05:24:57 2016	(r304788)
@@ -162,7 +162,7 @@ hv_timesync_cb(struct vmbus_channel *cha
 	    if (icmsghdrp->icmsgtype == HV_ICMSGTYPE_NEGOTIATE) {
 	    	int error;
 
-		error = vmbus_ic_negomsg(&softc->util_sc, time_buf, recvlen);
+		error = vmbus_ic_negomsg(&softc->util_sc, time_buf, &recvlen);
 		if (error)
 			return;
 	    } else {

Modified: head/sys/dev/hyperv/utilities/hv_util.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_util.c	Thu Aug 25 05:22:53 2016	(r304787)
+++ head/sys/dev/hyperv/utilities/hv_util.c	Thu Aug 25 05:24:57 2016	(r304788)
@@ -48,13 +48,16 @@
 
 #define VMBUS_IC_BRSIZE		(4 * PAGE_SIZE)
 
-CTASSERT(sizeof(struct vmbus_icmsg_negotiate) < VMBUS_IC_BRSIZE);
+#define VMBUS_IC_VERCNT		2
+#define VMBUS_IC_NEGOSZ		\
+	__offsetof(struct vmbus_icmsg_negotiate, ic_ver[VMBUS_IC_VERCNT])
+CTASSERT(VMBUS_IC_NEGOSZ < VMBUS_IC_BRSIZE);
 
 int
-vmbus_ic_negomsg(struct hv_util_sc *sc, void *data, int dlen)
+vmbus_ic_negomsg(struct hv_util_sc *sc, void *data, int *dlen0)
 {
 	struct vmbus_icmsg_negotiate *nego;
-	int cnt, major;
+	int cnt, major, dlen = *dlen0;
 
 	/*
 	 * Preliminary message size verification
@@ -87,9 +90,13 @@ vmbus_ic_negomsg(struct hv_util_sc *sc, 
 	nego->ic_msgver_cnt = 1;
 	nego->ic_ver[1] = VMBUS_IC_VERSION(major, 0);
 
-	/* Data contains two versions */
-	nego->ic_hdr.ic_dsize = __offsetof(struct vmbus_icmsg_negotiate,
-	    ic_ver[2]) - sizeof(struct vmbus_icmsg_hdr);
+	/* Update data size */
+	nego->ic_hdr.ic_dsize = VMBUS_IC_NEGOSZ -
+	    sizeof(struct vmbus_icmsg_hdr);
+
+	/* Update total size, if necessary */
+	if (dlen < VMBUS_IC_NEGOSZ)
+		*dlen0 = VMBUS_IC_NEGOSZ;
 
 	return 0;
 }

Modified: head/sys/dev/hyperv/utilities/hv_util.h
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_util.h	Thu Aug 25 05:22:53 2016	(r304787)
+++ head/sys/dev/hyperv/utilities/hv_util.h	Thu Aug 25 05:24:57 2016	(r304788)
@@ -54,6 +54,6 @@ struct vmbus_ic_desc {
 int		hv_util_attach(device_t dev, vmbus_chan_callback_t cb);
 int		hv_util_detach(device_t dev);
 int		vmbus_ic_probe(device_t dev, const struct vmbus_ic_desc descs[]);
-int		vmbus_ic_negomsg(struct hv_util_sc *, void *data, int dlen);
+int		vmbus_ic_negomsg(struct hv_util_sc *, void *data, int *dlen);
 
 #endif


More information about the svn-src-head mailing list