From: Yamasaki Yuu Subject: [PATCH 6/7] hyperv: add hv_channel_skip() To: tech@openbsd.org Date: Wed, 11 Nov 2026 11:46:51 +0900 hv_channel_recv() fails with EINVAL and leaves a packet in the ring when it doesn't fit into the caller's buffer, so the channel stalls on that packet. Add hv_channel_skip() to discard the next packet without copying it out. hvkbd(4) uses it to drop oversized messages. --- sys/dev/pv/hyperv.c | 39 +++++++++++++++++++++++++++++++++++++++ sys/dev/pv/hypervvar.h | 1 + 2 files changed, 40 insertions(+) diff --git sys/dev/pv/hyperv.c sys/dev/pv/hyperv.c index 065cf1aa693..e28cbf73eb4 100644 --- sys/dev/pv/hyperv.c +++ sys/dev/pv/hyperv.c @@ -1584,6 +1584,45 @@ hv_channel_recv(struct hv_channel *ch, void *data, uint32_t datalen, return (rv); } +/* + * Discard the next packet in the receive ring without copying it out, + * e.g. when it doesn't fit into the buffer passed to hv_channel_recv(). + */ +int +hv_channel_skip(struct hv_channel *ch) +{ + struct hv_ring_data *rrd = &ch->ch_rrd; + struct vmbus_chanpkt_hdr cph; + uint32_t avail, pktlen; + int rv; + + mtx_enter(&rrd->rd_lock); + + if ((rv = hv_ring_peek(rrd, &cph, sizeof(cph))) != 0) { + mtx_leave(&rrd->rd_lock); + return (rv); + } + + /* The packet is followed by the 64-bit ring indices. */ + pktlen = VMBUS_CHANPKT_GETLEN(cph.cph_tlen) + sizeof(uint64_t); + hv_ring_avail(rrd, NULL, &avail); + if (avail < pktlen) { + mtx_leave(&rrd->rd_lock); + return (EAGAIN); + } + + rrd->rd_cons += pktlen; + if (rrd->rd_cons >= rrd->rd_dsize) + rrd->rd_cons -= rrd->rd_dsize; + + virtio_membar_sync(); + rrd->rd_ring->br_rindex = rrd->rd_cons; + + mtx_leave(&rrd->rd_lock); + + return (0); +} + static inline void hv_ring_mask(struct hv_ring_data *rd) { diff --git sys/dev/pv/hypervvar.h sys/dev/pv/hypervvar.h index 94dc3366b3d..bbe145bc14b 100644 --- sys/dev/pv/hypervvar.h +++ sys/dev/pv/hypervvar.h @@ -221,5 +221,6 @@ int hv_channel_send_prpl(struct hv_channel *, struct vmbus_gpa_range *, uint32_t, void *, uint32_t, uint64_t); int hv_channel_recv(struct hv_channel *, void *, uint32_t, uint32_t *, uint64_t *, int); +int hv_channel_skip(struct hv_channel *); #endif /* _DEV_PV_HYPERVVAR_H_ */