Commit 99f1c460 authored by Michael Kelley's avatar Michael Kelley Committed by Paolo Abeni

hv_netvsc: Fix missed pagebuf entries in netvsc_dma_map/unmap()

netvsc_dma_map() and netvsc_dma_unmap() currently check the cp_partial
flag and adjust the page_count so that pagebuf entries for the RNDIS
portion of the message are skipped when it has already been copied into
a send buffer. But this adjustment has already been made by code in
netvsc_send(). The duplicate adjustment causes some pagebuf entries to
not be mapped. In a normal VM, this doesn't break anything because the
mapping doesn’t change the PFN. But in a Confidential VM,
dma_map_single() does bounce buffering and provides a different PFN.
Failing to do the mapping causes the wrong PFN to be passed to Hyper-V,
and various errors ensue.

Fix this by removing the duplicate adjustment in netvsc_dma_map() and
netvsc_dma_unmap().

Fixes: 846da38d ("net: netvsc: Add Isolation VM support for netvsc driver")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarMichael Kelley <mikelley@microsoft.com>
Reviewed-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Link: https://lore.kernel.org/r/1675135986-254490-1-git-send-email-mikelley@microsoft.comSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 917d5e04
...@@ -987,9 +987,6 @@ static void netvsc_copy_to_send_buf(struct netvsc_device *net_device, ...@@ -987,9 +987,6 @@ static void netvsc_copy_to_send_buf(struct netvsc_device *net_device,
void netvsc_dma_unmap(struct hv_device *hv_dev, void netvsc_dma_unmap(struct hv_device *hv_dev,
struct hv_netvsc_packet *packet) struct hv_netvsc_packet *packet)
{ {
u32 page_count = packet->cp_partial ?
packet->page_buf_cnt - packet->rmsg_pgcnt :
packet->page_buf_cnt;
int i; int i;
if (!hv_is_isolation_supported()) if (!hv_is_isolation_supported())
...@@ -998,7 +995,7 @@ void netvsc_dma_unmap(struct hv_device *hv_dev, ...@@ -998,7 +995,7 @@ void netvsc_dma_unmap(struct hv_device *hv_dev,
if (!packet->dma_range) if (!packet->dma_range)
return; return;
for (i = 0; i < page_count; i++) for (i = 0; i < packet->page_buf_cnt; i++)
dma_unmap_single(&hv_dev->device, packet->dma_range[i].dma, dma_unmap_single(&hv_dev->device, packet->dma_range[i].dma,
packet->dma_range[i].mapping_size, packet->dma_range[i].mapping_size,
DMA_TO_DEVICE); DMA_TO_DEVICE);
...@@ -1028,9 +1025,7 @@ static int netvsc_dma_map(struct hv_device *hv_dev, ...@@ -1028,9 +1025,7 @@ static int netvsc_dma_map(struct hv_device *hv_dev,
struct hv_netvsc_packet *packet, struct hv_netvsc_packet *packet,
struct hv_page_buffer *pb) struct hv_page_buffer *pb)
{ {
u32 page_count = packet->cp_partial ? u32 page_count = packet->page_buf_cnt;
packet->page_buf_cnt - packet->rmsg_pgcnt :
packet->page_buf_cnt;
dma_addr_t dma; dma_addr_t dma;
int i; int i;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment