mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	virtio_net: get build_skb() buf by data ptr
In the case of merge, the page passed into page_to_skb() may be a head page, not the page where the current data is located. So when trying to get the buf where the data is located, we should get buf based on headroom instead of offset. This patch solves this problem. But if you don't use this patch, the original code can also run, because if the page is not the page of the current data, the calculated tailroom will be less than 0, and will not enter the logic of build_skb() . The significance of this patch is to modify this logical problem, allowing more situations to use build_skb(). Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Acked-by: Jason Wang <jasowang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									5c37711d9f
								
							
						
					
					
						commit
						8fb7da9e99
					
				
					 1 changed files with 6 additions and 11 deletions
				
			
		| 
						 | 
					@ -401,18 +401,13 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
 | 
				
			||||||
	/* If headroom is not 0, there is an offset between the beginning of the
 | 
						/* If headroom is not 0, there is an offset between the beginning of the
 | 
				
			||||||
	 * data and the allocated space, otherwise the data and the allocated
 | 
						 * data and the allocated space, otherwise the data and the allocated
 | 
				
			||||||
	 * space are aligned.
 | 
						 * space are aligned.
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * Buffers with headroom use PAGE_SIZE as alloc size, see
 | 
				
			||||||
 | 
						 * add_recvbuf_mergeable() + get_mergeable_buf_len()
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (headroom) {
 | 
						truesize = headroom ? PAGE_SIZE : truesize;
 | 
				
			||||||
		/* Buffers with headroom use PAGE_SIZE as alloc size,
 | 
						tailroom = truesize - len - headroom;
 | 
				
			||||||
		 * see add_recvbuf_mergeable() + get_mergeable_buf_len()
 | 
						buf = p - headroom;
 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		truesize = PAGE_SIZE;
 | 
					 | 
				
			||||||
		tailroom = truesize - len - offset;
 | 
					 | 
				
			||||||
		buf = page_address(page);
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		tailroom = truesize - len;
 | 
					 | 
				
			||||||
		buf = p;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	len -= hdr_len;
 | 
						len -= hdr_len;
 | 
				
			||||||
	offset += hdr_padded_len;
 | 
						offset += hdr_padded_len;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue