Commit 11d8620e authored by Boqun Feng's avatar Boqun Feng Committed by Wei Liu

hv_netvsc: Use HV_HYP_PAGE_SIZE for Hyper-V communication

When communicating with Hyper-V, HV_HYP_PAGE_SIZE should be used since
that's the page size used by Hyper-V and Hyper-V expects all
page-related data using the unit of HY_HYP_PAGE_SIZE, for example, the
"pfn" in hv_page_buffer is actually the HV_HYP_PAGE (i.e. the Hyper-V
page) number.

In order to support guest whose page size is not 4k, we need to make
hv_netvsc always use HV_HYP_PAGE_SIZE for Hyper-V communication.
Signed-off-by: default avatarBoqun Feng <boqun.feng@gmail.com>
Reviewed-by: default avatarMichael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/20200916034817.30282-8-boqun.feng@gmail.comSigned-off-by: default avatarWei Liu <wei.liu@kernel.org>
parent 106dee08
...@@ -794,7 +794,7 @@ static void netvsc_copy_to_send_buf(struct netvsc_device *net_device, ...@@ -794,7 +794,7 @@ static void netvsc_copy_to_send_buf(struct netvsc_device *net_device,
} }
for (i = 0; i < page_count; i++) { for (i = 0; i < page_count; i++) {
char *src = phys_to_virt(pb[i].pfn << PAGE_SHIFT); char *src = phys_to_virt(pb[i].pfn << HV_HYP_PAGE_SHIFT);
u32 offset = pb[i].offset; u32 offset = pb[i].offset;
u32 len = pb[i].len; u32 len = pb[i].len;
......
...@@ -373,32 +373,29 @@ static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb, ...@@ -373,32 +373,29 @@ static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb,
return txq; return txq;
} }
static u32 fill_pg_buf(struct page *page, u32 offset, u32 len, static u32 fill_pg_buf(unsigned long hvpfn, u32 offset, u32 len,
struct hv_page_buffer *pb) struct hv_page_buffer *pb)
{ {
int j = 0; int j = 0;
/* Deal with compound pages by ignoring unused part hvpfn += offset >> HV_HYP_PAGE_SHIFT;
* of the page. offset = offset & ~HV_HYP_PAGE_MASK;
*/
page += (offset >> PAGE_SHIFT);
offset &= ~PAGE_MASK;
while (len > 0) { while (len > 0) {
unsigned long bytes; unsigned long bytes;
bytes = PAGE_SIZE - offset; bytes = HV_HYP_PAGE_SIZE - offset;
if (bytes > len) if (bytes > len)
bytes = len; bytes = len;
pb[j].pfn = page_to_pfn(page); pb[j].pfn = hvpfn;
pb[j].offset = offset; pb[j].offset = offset;
pb[j].len = bytes; pb[j].len = bytes;
offset += bytes; offset += bytes;
len -= bytes; len -= bytes;
if (offset == PAGE_SIZE && len) { if (offset == HV_HYP_PAGE_SIZE && len) {
page++; hvpfn++;
offset = 0; offset = 0;
j++; j++;
} }
...@@ -421,23 +418,26 @@ static u32 init_page_array(void *hdr, u32 len, struct sk_buff *skb, ...@@ -421,23 +418,26 @@ static u32 init_page_array(void *hdr, u32 len, struct sk_buff *skb,
* 2. skb linear data * 2. skb linear data
* 3. skb fragment data * 3. skb fragment data
*/ */
slots_used += fill_pg_buf(virt_to_page(hdr), slots_used += fill_pg_buf(virt_to_hvpfn(hdr),
offset_in_page(hdr), offset_in_hvpage(hdr),
len, &pb[slots_used]); len,
&pb[slots_used]);
packet->rmsg_size = len; packet->rmsg_size = len;
packet->rmsg_pgcnt = slots_used; packet->rmsg_pgcnt = slots_used;
slots_used += fill_pg_buf(virt_to_page(data), slots_used += fill_pg_buf(virt_to_hvpfn(data),
offset_in_page(data), offset_in_hvpage(data),
skb_headlen(skb), &pb[slots_used]); skb_headlen(skb),
&pb[slots_used]);
for (i = 0; i < frags; i++) { for (i = 0; i < frags; i++) {
skb_frag_t *frag = skb_shinfo(skb)->frags + i; skb_frag_t *frag = skb_shinfo(skb)->frags + i;
slots_used += fill_pg_buf(skb_frag_page(frag), slots_used += fill_pg_buf(page_to_hvpfn(skb_frag_page(frag)),
skb_frag_off(frag), skb_frag_off(frag),
skb_frag_size(frag), &pb[slots_used]); skb_frag_size(frag),
&pb[slots_used]);
} }
return slots_used; return slots_used;
} }
...@@ -453,8 +453,8 @@ static int count_skb_frag_slots(struct sk_buff *skb) ...@@ -453,8 +453,8 @@ static int count_skb_frag_slots(struct sk_buff *skb)
unsigned long offset = skb_frag_off(frag); unsigned long offset = skb_frag_off(frag);
/* Skip unused frames from start of page */ /* Skip unused frames from start of page */
offset &= ~PAGE_MASK; offset &= ~HV_HYP_PAGE_MASK;
pages += PFN_UP(offset + size); pages += HVPFN_UP(offset + size);
} }
return pages; return pages;
} }
...@@ -462,12 +462,12 @@ static int count_skb_frag_slots(struct sk_buff *skb) ...@@ -462,12 +462,12 @@ static int count_skb_frag_slots(struct sk_buff *skb)
static int netvsc_get_slots(struct sk_buff *skb) static int netvsc_get_slots(struct sk_buff *skb)
{ {
char *data = skb->data; char *data = skb->data;
unsigned int offset = offset_in_page(data); unsigned int offset = offset_in_hvpage(data);
unsigned int len = skb_headlen(skb); unsigned int len = skb_headlen(skb);
int slots; int slots;
int frag_slots; int frag_slots;
slots = DIV_ROUND_UP(offset + len, PAGE_SIZE); slots = DIV_ROUND_UP(offset + len, HV_HYP_PAGE_SIZE);
frag_slots = count_skb_frag_slots(skb); frag_slots = count_skb_frag_slots(skb);
return slots + frag_slots; return slots + frag_slots;
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
static void rndis_set_multicast(struct work_struct *w); static void rndis_set_multicast(struct work_struct *w);
#define RNDIS_EXT_LEN PAGE_SIZE #define RNDIS_EXT_LEN HV_HYP_PAGE_SIZE
struct rndis_request { struct rndis_request {
struct list_head list_ent; struct list_head list_ent;
struct completion wait_event; struct completion wait_event;
...@@ -215,18 +215,17 @@ static int rndis_filter_send_request(struct rndis_device *dev, ...@@ -215,18 +215,17 @@ static int rndis_filter_send_request(struct rndis_device *dev,
packet->page_buf_cnt = 1; packet->page_buf_cnt = 1;
pb[0].pfn = virt_to_phys(&req->request_msg) >> pb[0].pfn = virt_to_phys(&req->request_msg) >>
PAGE_SHIFT; HV_HYP_PAGE_SHIFT;
pb[0].len = req->request_msg.msg_len; pb[0].len = req->request_msg.msg_len;
pb[0].offset = pb[0].offset = offset_in_hvpage(&req->request_msg);
(unsigned long)&req->request_msg & (PAGE_SIZE - 1);
/* Add one page_buf when request_msg crossing page boundary */ /* Add one page_buf when request_msg crossing page boundary */
if (pb[0].offset + pb[0].len > PAGE_SIZE) { if (pb[0].offset + pb[0].len > HV_HYP_PAGE_SIZE) {
packet->page_buf_cnt++; packet->page_buf_cnt++;
pb[0].len = PAGE_SIZE - pb[0].len = HV_HYP_PAGE_SIZE -
pb[0].offset; pb[0].offset;
pb[1].pfn = virt_to_phys((void *)&req->request_msg pb[1].pfn = virt_to_phys((void *)&req->request_msg
+ pb[0].len) >> PAGE_SHIFT; + pb[0].len) >> HV_HYP_PAGE_SHIFT;
pb[1].offset = 0; pb[1].offset = 0;
pb[1].len = req->request_msg.msg_len - pb[1].len = req->request_msg.msg_len -
pb[0].len; pb[0].len;
......
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