Skip to content

Commit 3229012

Browse files
shreeya-patel98PlaidCat
authored andcommitted
hv_netvsc: Use vmbus_sendpacket_mpb_desc() to send VMBus messages
jira LE-3555 commit-author Michael Kelley <mhklinux@outlook.com> commit 4f98616 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> (cherry picked from commit 4f98616) Signed-off-by: Shreeya Patel <spatel@ciq.com> Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 2cb0555 commit 3229012

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
@@ -1054,6 +1054,42 @@ static int netvsc_dma_map(struct hv_device *hv_dev,
10541054
return 0;
10551055
}
10561056

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

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

@@ -1105,11 +1144,12 @@ static inline int netvsc_send_pkt(
11051144
goto exit;
11061145
}
11071146

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

0 commit comments

Comments
 (0)