patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH 1/2] vhost: fix TCP csum not set
       [not found] <1496817697-49130-1-git-send-email-jianfeng.tan@intel.com>
@ 2017-06-07  6:41 ` Jianfeng Tan
  2017-06-07 19:25   ` Maxime Coquelin
  2017-06-07  6:41 ` [dpdk-stable] [PATCH 2/2] vhost: fix IP csum not calculated Jianfeng Tan
  1 sibling, 1 reply; 5+ messages in thread
From: Jianfeng Tan @ 2017-06-07  6:41 UTC (permalink / raw)
  To: dev; +Cc: Jianfeng Tan, stable, Yuanhan Liu, Maxime Coquelin, Jiayu Hu

As PKT_TX_TCP_SEG flag in mbuf->ol_flags implies PKT_TX_TCP_CKSUM,
applications, e.g., testpmd, don't set PKT_TX_TCP_CKSUM when TSO
is set.

This leads to that packets get dropped in VM tcp stack layer because
of bad TCP csum.

To fix this, we make sure TCP NEEDS_CSUM info is set into virtio net
header when PKT_TX_TCP_SEG is set, so that VM tcp stack will not
check the TCP csum.

Fixes: 859b480d5afd ("vhost: add guest offload setting")
Cc: stable@dpdk.org

Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Cc: Jiayu Hu <jiayu.hu@intel.com>
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 lib/librte_vhost/virtio_net.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 48219e0..0a7e023 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -114,11 +114,16 @@ update_shadow_used_ring(struct vhost_virtqueue *vq,
 static void
 virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
 {
-	if (m_buf->ol_flags & PKT_TX_L4_MASK) {
+	uint64_t csum_l4 = m_buf->ol_flags & PKT_TX_L4_MASK;
+
+	if (m_buf->ol_flags & PKT_TX_TCP_SEG)
+		csum_l4 |= PKT_TX_TCP_CKSUM;
+
+	if (csum_l4) {
 		net_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
 		net_hdr->csum_start = m_buf->l2_len + m_buf->l3_len;
 
-		switch (m_buf->ol_flags & PKT_TX_L4_MASK) {
+		switch (csum_l4) {
 		case PKT_TX_TCP_CKSUM:
 			net_hdr->csum_offset = (offsetof(struct tcp_hdr,
 						cksum));
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-stable] [PATCH 2/2] vhost: fix IP csum not calculated
       [not found] <1496817697-49130-1-git-send-email-jianfeng.tan@intel.com>
  2017-06-07  6:41 ` [dpdk-stable] [PATCH 1/2] vhost: fix TCP csum not set Jianfeng Tan
@ 2017-06-07  6:41 ` Jianfeng Tan
  2017-06-07 19:28   ` Maxime Coquelin
  1 sibling, 1 reply; 5+ messages in thread
From: Jianfeng Tan @ 2017-06-07  6:41 UTC (permalink / raw)
  To: dev; +Cc: Jianfeng Tan, stable, Yuanhan Liu, Maxime Coquelin, Jiayu Hu

There is no way to bypass IP checksum verification in Linux
kernel, no matter skb->ip_summed is assigned as CHECKSUM_UNNECESSARY
or CHECKSUM_PARTIAL.

So any packets with bad IP checksum will be dropped at VM IP layer.

To correct, we check this flag PKT_TX_IP_CKSUM to calculate IP csum.

Fixes: 859b480d5afd ("vhost: add guest offload setting")
Cc: stable@dpdk.org

Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Cc: Jiayu Hu <jiayu.hu@intel.com>
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 lib/librte_vhost/virtio_net.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 0a7e023..cf7c5ac 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -143,6 +143,15 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
 		ASSIGN_UNLESS_EQUAL(net_hdr->flags, 0);
 	}
 
+	/* IP cksum verification cannot be bypassed, then calculate here */
+	if (m_buf->ol_flags & PKT_TX_IP_CKSUM) {
+		struct ipv4_hdr *ipv4_hdr;
+
+		ipv4_hdr = rte_pktmbuf_mtod_offset(m_buf, struct ipv4_hdr *,
+						   m_buf->l2_len);
+		ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
+	}
+
 	if (m_buf->ol_flags & PKT_TX_TCP_SEG) {
 		if (m_buf->ol_flags & PKT_TX_IPV4)
 			net_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [PATCH 1/2] vhost: fix TCP csum not set
  2017-06-07  6:41 ` [dpdk-stable] [PATCH 1/2] vhost: fix TCP csum not set Jianfeng Tan
@ 2017-06-07 19:25   ` Maxime Coquelin
  2017-07-01 23:27     ` [dpdk-stable] [dpdk-dev] " Yuanhan Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Maxime Coquelin @ 2017-06-07 19:25 UTC (permalink / raw)
  To: Jianfeng Tan, dev; +Cc: stable, Yuanhan Liu, Jiayu Hu



On 06/07/2017 08:41 AM, Jianfeng Tan wrote:
> As PKT_TX_TCP_SEG flag in mbuf->ol_flags implies PKT_TX_TCP_CKSUM,
> applications, e.g., testpmd, don't set PKT_TX_TCP_CKSUM when TSO
> is set.
> 
> This leads to that packets get dropped in VM tcp stack layer because
> of bad TCP csum.
> 
> To fix this, we make sure TCP NEEDS_CSUM info is set into virtio net
> header when PKT_TX_TCP_SEG is set, so that VM tcp stack will not
> check the TCP csum.
> 
> Fixes: 859b480d5afd ("vhost: add guest offload setting")
> Cc: stable@dpdk.org
> 
> Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Cc: Jiayu Hu <jiayu.hu@intel.com>
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
> ---
>   lib/librte_vhost/virtio_net.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
> index 48219e0..0a7e023 100644
> --- a/lib/librte_vhost/virtio_net.c
> +++ b/lib/librte_vhost/virtio_net.c
> @@ -114,11 +114,16 @@ update_shadow_used_ring(struct vhost_virtqueue *vq,
>   static void
>   virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
>   {
> -	if (m_buf->ol_flags & PKT_TX_L4_MASK) {
> +	uint64_t csum_l4 = m_buf->ol_flags & PKT_TX_L4_MASK;
> +
> +	if (m_buf->ol_flags & PKT_TX_TCP_SEG)
> +		csum_l4 |= PKT_TX_TCP_CKSUM;
> +
> +	if (csum_l4) {
>   		net_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
>   		net_hdr->csum_start = m_buf->l2_len + m_buf->l3_len;
>   
> -		switch (m_buf->ol_flags & PKT_TX_L4_MASK) {
> +		switch (csum_l4) {
>   		case PKT_TX_TCP_CKSUM:
>   			net_hdr->csum_offset = (offsetof(struct tcp_hdr,
>   						cksum));
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [PATCH 2/2] vhost: fix IP csum not calculated
  2017-06-07  6:41 ` [dpdk-stable] [PATCH 2/2] vhost: fix IP csum not calculated Jianfeng Tan
@ 2017-06-07 19:28   ` Maxime Coquelin
  0 siblings, 0 replies; 5+ messages in thread
From: Maxime Coquelin @ 2017-06-07 19:28 UTC (permalink / raw)
  To: Jianfeng Tan, dev; +Cc: stable, Yuanhan Liu, Jiayu Hu



On 06/07/2017 08:41 AM, Jianfeng Tan wrote:
> There is no way to bypass IP checksum verification in Linux
> kernel, no matter skb->ip_summed is assigned as CHECKSUM_UNNECESSARY
> or CHECKSUM_PARTIAL.
> 
> So any packets with bad IP checksum will be dropped at VM IP layer.
> 
> To correct, we check this flag PKT_TX_IP_CKSUM to calculate IP csum.
> 
> Fixes: 859b480d5afd ("vhost: add guest offload setting")
> Cc: stable@dpdk.org
> 
> Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Cc: Jiayu Hu <jiayu.hu@intel.com>
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
> ---
>   lib/librte_vhost/virtio_net.c | 9 +++++++++
>   1 file changed, 9 insertions(+)


Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime

> 
> diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
> index 0a7e023..cf7c5ac 100644
> --- a/lib/librte_vhost/virtio_net.c
> +++ b/lib/librte_vhost/virtio_net.c
> @@ -143,6 +143,15 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
>   		ASSIGN_UNLESS_EQUAL(net_hdr->flags, 0);
>   	}
>   
> +	/* IP cksum verification cannot be bypassed, then calculate here */
> +	if (m_buf->ol_flags & PKT_TX_IP_CKSUM) {
> +		struct ipv4_hdr *ipv4_hdr;
> +
> +		ipv4_hdr = rte_pktmbuf_mtod_offset(m_buf, struct ipv4_hdr *,
> +						   m_buf->l2_len);
> +		ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
> +	}
> +
>   	if (m_buf->ol_flags & PKT_TX_TCP_SEG) {
>   		if (m_buf->ol_flags & PKT_TX_IPV4)
>   			net_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH 1/2] vhost: fix TCP csum not set
  2017-06-07 19:25   ` Maxime Coquelin
@ 2017-07-01 23:27     ` Yuanhan Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Yuanhan Liu @ 2017-07-01 23:27 UTC (permalink / raw)
  To: Maxime Coquelin; +Cc: Jianfeng Tan, dev, stable, Jiayu Hu

On Wed, Jun 07, 2017 at 09:25:38PM +0200, Maxime Coquelin wrote:
> 
> 
> On 06/07/2017 08:41 AM, Jianfeng Tan wrote:
> >As PKT_TX_TCP_SEG flag in mbuf->ol_flags implies PKT_TX_TCP_CKSUM,
> >applications, e.g., testpmd, don't set PKT_TX_TCP_CKSUM when TSO
> >is set.
> >
> >This leads to that packets get dropped in VM tcp stack layer because
> >of bad TCP csum.
> >
> >To fix this, we make sure TCP NEEDS_CSUM info is set into virtio net
> >header when PKT_TX_TCP_SEG is set, so that VM tcp stack will not
> >check the TCP csum.
> >
> >Fixes: 859b480d5afd ("vhost: add guest offload setting")
> >Cc: stable@dpdk.org
> >
> >Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> >Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> >Cc: Jiayu Hu <jiayu.hu@intel.com>
> >Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
> 
> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Series applied to dpdk-next-virtio.

Thanks!

	--yliu

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-07-01 23:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1496817697-49130-1-git-send-email-jianfeng.tan@intel.com>
2017-06-07  6:41 ` [dpdk-stable] [PATCH 1/2] vhost: fix TCP csum not set Jianfeng Tan
2017-06-07 19:25   ` Maxime Coquelin
2017-07-01 23:27     ` [dpdk-stable] [dpdk-dev] " Yuanhan Liu
2017-06-07  6:41 ` [dpdk-stable] [PATCH 2/2] vhost: fix IP csum not calculated Jianfeng Tan
2017-06-07 19:28   ` Maxime Coquelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).