Skip to content

Commit 4f98616

Browse files
mhklinuxkuba-moo
authored andcommitted
hv_netvsc: Use vmbus_sendpacket_mpb_desc() to send VMBus messages
netvsc currently uses vmbus_sendpacket_pagebuffer() to send VMBus messages. This function creates a series of GPA ranges, each of which contains a single PFN. However, if the rndis header in the VMBus message crosses a page boundary, the netvsc protocol with the host requires that both PFNs for the rndis header must be in a single "GPA range" data structure, which isn't possible with vmbus_sendpacket_pagebuffer(). As the first step in fixing this, add a new function netvsc_build_mpb_array() to build a VMBus message with multiple GPA ranges, each of which may contain multiple PFNs. Use vmbus_sendpacket_mpb_desc() to send this VMBus message to the host. There's no functional change since higher levels of netvsc don't maintain or propagate knowledge of contiguous PFNs. Based on its input, netvsc_build_mpb_array() still produces a separate GPA range for each PFN and the behavior is the same as with vmbus_sendpacket_pagebuffer(). But the groundwork is laid for a subsequent patch to provide the necessary grouping. Cc: <stable@vger.kernel.org> # 6.1.x Signed-off-by: Michael Kelley <mhklinux@outlook.com> Link: https://patch.msgid.link/20250513000604.1396-3-mhklinux@outlook.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 380b75d commit 4f98616

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

drivers/net/hyperv/netvsc.c

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,42 @@ static int netvsc_dma_map(struct hv_device *hv_dev,
10551055
return 0;
10561056
}
10571057

1058+
/* Build an "array" of mpb entries describing the data to be transferred
1059+
* over VMBus. After the desc header fields, each "array" entry is variable
1060+
* size, and each entry starts after the end of the previous entry. The
1061+
* "offset" and "len" fields for each entry imply the size of the entry.
1062+
*
1063+
* The pfns are in HV_HYP_PAGE_SIZE, because all communication with Hyper-V
1064+
* uses that granularity, even if the system page size of the guest is larger.
1065+
* Each entry in the input "pb" array must describe a contiguous range of
1066+
* guest physical memory so that the pfns are sequential if the range crosses
1067+
* a page boundary. The offset field must be < HV_HYP_PAGE_SIZE.
1068+
*/
1069+
static inline void netvsc_build_mpb_array(struct hv_page_buffer *pb,
1070+
u32 page_buffer_count,
1071+
struct vmbus_packet_mpb_array *desc,
1072+
u32 *desc_size)
1073+
{
1074+
struct hv_mpb_array *mpb_entry = &desc->range;
1075+
int i, j;
1076+
1077+
for (i = 0; i < page_buffer_count; i++) {
1078+
u32 offset = pb[i].offset;
1079+
u32 len = pb[i].len;
1080+
1081+
mpb_entry->offset = offset;
1082+
mpb_entry->len = len;
1083+
1084+
for (j = 0; j < HVPFN_UP(offset + len); j++)
1085+
mpb_entry->pfn_array[j] = pb[i].pfn + j;
1086+
1087+
mpb_entry = (struct hv_mpb_array *)&mpb_entry->pfn_array[j];
1088+
}
1089+
1090+
desc->rangecount = page_buffer_count;
1091+
*desc_size = (char *)mpb_entry - (char *)desc;
1092+
}
1093+
10581094
static inline int netvsc_send_pkt(
10591095
struct hv_device *device,
10601096
struct hv_netvsc_packet *packet,
@@ -1097,6 +1133,9 @@ static inline int netvsc_send_pkt(
10971133

10981134
packet->dma_range = NULL;
10991135
if (packet->page_buf_cnt) {
1136+
struct vmbus_channel_packet_page_buffer desc;
1137+
u32 desc_size;
1138+
11001139
if (packet->cp_partial)
11011140
pb += packet->rmsg_pgcnt;
11021141

@@ -1106,11 +1145,12 @@ static inline int netvsc_send_pkt(
11061145
goto exit;
11071146
}
11081147

1109-
ret = vmbus_sendpacket_pagebuffer(out_channel,
1110-
pb, packet->page_buf_cnt,
1111-
&nvmsg, sizeof(nvmsg),
1112-
req_id);
1113-
1148+
netvsc_build_mpb_array(pb, packet->page_buf_cnt,
1149+
(struct vmbus_packet_mpb_array *)&desc,
1150+
&desc_size);
1151+
ret = vmbus_sendpacket_mpb_desc(out_channel,
1152+
(struct vmbus_packet_mpb_array *)&desc,
1153+
desc_size, &nvmsg, sizeof(nvmsg), req_id);
11141154
if (ret)
11151155
netvsc_dma_unmap(ndev_ctx->device_ctx, packet);
11161156
} else {

0 commit comments

Comments
 (0)