aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/hyperv
diff options
context:
space:
mode:
authorSepherosa Ziehau <sephe@FreeBSD.org>2016-07-15 07:45:30 +0000
committerSepherosa Ziehau <sephe@FreeBSD.org>2016-07-15 07:45:30 +0000
commit7c55724859295d99b2a0d1383b63d11ff4fcb023 (patch)
treefd3b8120ba6efaae83967c3eb35b106d66cec8c2 /sys/dev/hyperv
parent7bf59009649aabd17c5342766f083350e423651d (diff)
downloadsrc-7c55724859295d99b2a0d1383b63d11ff4fcb023.tar.gz
src-7c55724859295d99b2a0d1383b63d11ff4fcb023.zip
Notes
Diffstat (limited to 'sys/dev/hyperv')
-rw-r--r--sys/dev/hyperv/include/hyperv.h7
-rw-r--r--sys/dev/hyperv/include/vmbus.h3
-rw-r--r--sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c26
-rw-r--r--sys/dev/hyperv/utilities/hv_heartbeat.c8
-rw-r--r--sys/dev/hyperv/utilities/hv_kvp.c14
-rw-r--r--sys/dev/hyperv/utilities/hv_shutdown.c7
-rw-r--r--sys/dev/hyperv/utilities/hv_timesync.c6
-rw-r--r--sys/dev/hyperv/vmbus/hv_channel.c50
-rw-r--r--sys/dev/hyperv/vmbus/vmbus_reg.h3
9 files changed, 62 insertions, 62 deletions
diff --git a/sys/dev/hyperv/include/hyperv.h b/sys/dev/hyperv/include/hyperv.h
index 63b353db9187..4f2dc7aab81d 100644
--- a/sys/dev/hyperv/include/hyperv.h
+++ b/sys/dev/hyperv/include/hyperv.h
@@ -298,13 +298,6 @@ hv_set_channel_read_state(hv_vmbus_channel* channel, boolean_t on)
channel->ch_flags |= VMBUS_CHAN_FLAG_BATCHREAD;
}
-int hv_vmbus_channel_recv_packet(
- hv_vmbus_channel* channel,
- void* buffer,
- uint32_t buffer_len,
- uint32_t* buffer_actual_len,
- uint64_t* request_id);
-
int hv_vmbus_channel_recv_packet_raw(
hv_vmbus_channel* channel,
void* buffer,
diff --git a/sys/dev/hyperv/include/vmbus.h b/sys/dev/hyperv/include/vmbus.h
index 0dbfe6b5a85d..d5d05c6f2950 100644
--- a/sys/dev/hyperv/include/vmbus.h
+++ b/sys/dev/hyperv/include/vmbus.h
@@ -59,6 +59,9 @@ struct vmbus_gpa {
struct hv_vmbus_channel;
+int vmbus_chan_recv(struct hv_vmbus_channel *chan, void *data, int *dlen,
+ uint64_t *xactid);
+
int vmbus_chan_send(struct hv_vmbus_channel *chan, uint16_t type,
uint16_t flags, void *data, int dlen, uint64_t xactid);
int vmbus_chan_send_sglist(struct hv_vmbus_channel *chan,
diff --git a/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c b/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
index faf70b3fab1a..1031568c80a4 100644
--- a/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
+++ b/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
@@ -778,12 +778,10 @@ hv_storvsc_on_channel_callback(void *xchan)
struct hv_storvsc_request *request;
struct vstor_packet *vstor_packet;
- ret = hv_vmbus_channel_recv_packet(
- channel,
- packet,
- roundup2(VSTOR_PKT_SIZE, 8),
- &bytes_recvd,
- &request_id);
+ bytes_recvd = roundup2(VSTOR_PKT_SIZE, 8);
+ ret = vmbus_chan_recv(channel, packet, &bytes_recvd, &request_id);
+ KASSERT(ret != ENOBUFS, ("storvsc recvbuf is not large enough"));
+ /* XXX check bytes_recvd to make sure that it contains enough data */
while ((ret == 0) && (bytes_recvd > 0)) {
request = (struct hv_storvsc_request *)(uintptr_t)request_id;
@@ -817,12 +815,16 @@ hv_storvsc_on_channel_callback(void *xchan)
break;
}
}
- ret = hv_vmbus_channel_recv_packet(
- channel,
- packet,
- roundup2(VSTOR_PKT_SIZE, 8),
- &bytes_recvd,
- &request_id);
+
+ bytes_recvd = roundup2(VSTOR_PKT_SIZE, 8),
+ ret = vmbus_chan_recv(channel, packet, &bytes_recvd,
+ &request_id);
+ KASSERT(ret != ENOBUFS,
+ ("storvsc recvbuf is not large enough"));
+ /*
+ * XXX check bytes_recvd to make sure that it contains
+ * enough data
+ */
}
}
diff --git a/sys/dev/hyperv/utilities/hv_heartbeat.c b/sys/dev/hyperv/utilities/hv_heartbeat.c
index 5b73ca2a5f15..b1a9b4129d0f 100644
--- a/sys/dev/hyperv/utilities/hv_heartbeat.c
+++ b/sys/dev/hyperv/utilities/hv_heartbeat.c
@@ -52,7 +52,7 @@ hv_heartbeat_cb(void *context)
{
uint8_t* buf;
hv_vmbus_channel* channel;
- uint32_t recvlen;
+ int recvlen;
uint64_t requestid;
int ret;
@@ -64,8 +64,10 @@ hv_heartbeat_cb(void *context)
buf = softc->receive_buffer;
channel = softc->channel;
- ret = hv_vmbus_channel_recv_packet(channel, buf, PAGE_SIZE, &recvlen,
- &requestid);
+ recvlen = PAGE_SIZE;
+ ret = vmbus_chan_recv(channel, buf, &recvlen, &requestid);
+ KASSERT(ret != ENOBUFS, ("hvheartbeat recvbuf is not large enough"));
+ /* XXX check recvlen to make sure that it contains enough data */
if ((ret == 0) && recvlen > 0) {
diff --git a/sys/dev/hyperv/utilities/hv_kvp.c b/sys/dev/hyperv/utilities/hv_kvp.c
index 4b9b022a1b55..3e7d03a99348 100644
--- a/sys/dev/hyperv/utilities/hv_kvp.c
+++ b/sys/dev/hyperv/utilities/hv_kvp.c
@@ -626,8 +626,10 @@ hv_kvp_process_request(void *context, int pending)
kvp_buf = sc->util_sc.receive_buffer;
channel = sc->util_sc.channel;
- ret = hv_vmbus_channel_recv_packet(channel, kvp_buf, 2 * PAGE_SIZE,
- &recvlen, &requestid);
+ recvlen = 2 * PAGE_SIZE;
+ ret = vmbus_chan_recv(channel, kvp_buf, &recvlen, &requestid);
+ KASSERT(ret != ENOBUFS, ("hvkvp recvbuf is not large enough"));
+ /* XXX check recvlen to make sure that it contains enough data */
while ((ret == 0) && (recvlen > 0)) {
@@ -691,9 +693,11 @@ hv_kvp_process_request(void *context, int pending)
/*
* Try reading next buffer
*/
- recvlen = 0;
- ret = hv_vmbus_channel_recv_packet(channel, kvp_buf, 2 * PAGE_SIZE,
- &recvlen, &requestid);
+ recvlen = 2 * PAGE_SIZE;
+ ret = vmbus_chan_recv(channel, kvp_buf, &recvlen, &requestid);
+ KASSERT(ret != ENOBUFS, ("hvkvp recvbuf is not large enough"));
+ /* XXX check recvlen to make sure that it contains enough data */
+
hv_kvp_log_info("%s: read: context %p, ret =%d, recvlen=%d\n",
__func__, context, ret, recvlen);
}
diff --git a/sys/dev/hyperv/utilities/hv_shutdown.c b/sys/dev/hyperv/utilities/hv_shutdown.c
index dd39d0b65efc..9c64a85fedd8 100644
--- a/sys/dev/hyperv/utilities/hv_shutdown.c
+++ b/sys/dev/hyperv/utilities/hv_shutdown.c
@@ -67,8 +67,11 @@ hv_shutdown_cb(void *context)
softc = (hv_util_sc*)context;
buf = softc->receive_buffer;
channel = softc->channel;
- ret = hv_vmbus_channel_recv_packet(channel, buf, PAGE_SIZE,
- &recv_len, &request_id);
+
+ recv_len = PAGE_SIZE;
+ ret = vmbus_chan_recv(channel, buf, &recv_len, &request_id);
+ KASSERT(ret != ENOBUFS, ("hvshutdown recvbuf is not large enough"));
+ /* XXX check recv_len to make sure that it contains enough data */
if ((ret == 0) && recv_len > 0) {
diff --git a/sys/dev/hyperv/utilities/hv_timesync.c b/sys/dev/hyperv/utilities/hv_timesync.c
index 1071cddeaece..e2e432106fde 100644
--- a/sys/dev/hyperv/utilities/hv_timesync.c
+++ b/sys/dev/hyperv/utilities/hv_timesync.c
@@ -144,8 +144,10 @@ hv_timesync_cb(void *context)
channel = softc->util_sc.channel;
time_buf = softc->util_sc.receive_buffer;
- ret = hv_vmbus_channel_recv_packet(channel, time_buf,
- PAGE_SIZE, &recvlen, &requestId);
+ recvlen = PAGE_SIZE;
+ ret = vmbus_chan_recv(channel, time_buf, &recvlen, &requestId);
+ KASSERT(ret != ENOBUFS, ("hvtimesync recvbuf is not large enough"));
+ /* XXX check recvlen to make sure that it contains enough data */
if ((ret == 0) && recvlen > 0) {
icmsghdrp = (struct hv_vmbus_icmsg_hdr *) &time_buf[
diff --git a/sys/dev/hyperv/vmbus/hv_channel.c b/sys/dev/hyperv/vmbus/hv_channel.c
index 9221de20990a..d797da3c138d 100644
--- a/sys/dev/hyperv/vmbus/hv_channel.c
+++ b/sys/dev/hyperv/vmbus/hv_channel.c
@@ -736,45 +736,33 @@ vmbus_chan_send_prplist(struct hv_vmbus_channel *chan,
return error;
}
-/**
- * @brief Retrieve the user packet on the specified channel
- */
int
-hv_vmbus_channel_recv_packet(
- hv_vmbus_channel* channel,
- void* Buffer,
- uint32_t buffer_len,
- uint32_t* buffer_actual_len,
- uint64_t* request_id)
+vmbus_chan_recv(struct hv_vmbus_channel *chan, void *data, int *dlen0,
+ uint64_t *xactid)
{
- int ret;
- uint32_t user_len;
- uint32_t packet_len;
- hv_vm_packet_descriptor desc;
-
- *buffer_actual_len = 0;
- *request_id = 0;
+ struct vmbus_chanpkt_hdr pkt;
+ int error, dlen, hlen;
- ret = hv_ring_buffer_peek(&channel->inbound, &desc,
- sizeof(hv_vm_packet_descriptor));
- if (ret != 0)
- return (0);
-
- packet_len = desc.length8 << 3;
- user_len = packet_len - (desc.data_offset8 << 3);
+ error = hv_ring_buffer_peek(&chan->inbound, &pkt, sizeof(pkt));
+ if (error)
+ return error;
- *buffer_actual_len = user_len;
+ hlen = VMBUS_CHANPKT_GETLEN(pkt.cph_hlen);
+ dlen = VMBUS_CHANPKT_GETLEN(pkt.cph_tlen) - hlen;
- if (user_len > buffer_len)
- return (EINVAL);
+ if (*dlen0 < dlen) {
+ /* Return the size of this packet. */
+ *dlen0 = dlen;
+ return ENOBUFS;
+ }
- *request_id = desc.transaction_id;
+ *xactid = pkt.cph_xactid;
+ *dlen0 = dlen;
- /* Copy over the packet to the user buffer */
- ret = hv_ring_buffer_read(&channel->inbound, Buffer, user_len,
- (desc.data_offset8 << 3));
+ error = hv_ring_buffer_read(&chan->inbound, data, dlen, hlen);
+ KASSERT(!error, ("hv_ring_buffer_read failed"));
- return (0);
+ return 0;
}
/**
diff --git a/sys/dev/hyperv/vmbus/vmbus_reg.h b/sys/dev/hyperv/vmbus/vmbus_reg.h
index b9586529fd09..6608074a72d2 100644
--- a/sys/dev/hyperv/vmbus/vmbus_reg.h
+++ b/sys/dev/hyperv/vmbus/vmbus_reg.h
@@ -120,6 +120,9 @@ do { \
(pktlen) = (len) >> VMBUS_CHANPKT_SIZE_SHIFT; \
} while (0)
+#define VMBUS_CHANPKT_GETLEN(pktlen) \
+ (((int)(pktlen)) << VMBUS_CHANPKT_SIZE_SHIFT)
+
#define VMBUS_CHANPKT_TOTLEN(tlen) \
roundup2((tlen), VMBUS_CHANPKT_SIZE_ALIGN)