Skip to content

Commit

Permalink
patch: add patched for dpdk-stable-17.11.6 and dpdk-stable-18.11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ywc689 committed Nov 13, 2019
1 parent 2882b79 commit 35280c0
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
From 648ff9e42e58a4fe6587dce05b534fb746ae438f Mon Sep 17 00:00:00 2001
From: ywc689 <[email protected]>
Date: Fri, 28 Jun 2019 17:48:12 +0800
Subject: [PATCH 1/2] net: support variable IP header len for checksum API.

IPv4 checksum APIs use fixe IP header length, it will failed if there is
any IP option. Now calculating header length by "ihl" field, so that we
can support options.
---
dpdk-stable-17.11.6/lib/librte_net/rte_ip.h | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/dpdk-stable-17.11.6/lib/librte_net/rte_ip.h b/dpdk-stable-17.11.6/lib/librte_net/rte_ip.h
index 8d4907f..0d504f6 100644
--- a/dpdk-stable-17.11.6/lib/librte_net/rte_ip.h
+++ b/dpdk-stable-17.11.6/lib/librte_net/rte_ip.h
@@ -314,7 +314,7 @@ struct ipv4_hdr {
rte_ipv4_cksum(const struct ipv4_hdr *ipv4_hdr)
{
uint16_t cksum;
- cksum = rte_raw_cksum(ipv4_hdr, sizeof(struct ipv4_hdr));
+ cksum = rte_raw_cksum(ipv4_hdr, (ipv4_hdr->version_ihl & 0xf) * 4);
return (cksum == 0xffff) ? cksum : (uint16_t)~cksum;
}

@@ -356,7 +356,7 @@ struct ipv4_hdr {
} else {
psd_hdr.len = rte_cpu_to_be_16(
(uint16_t)(rte_be_to_cpu_16(ipv4_hdr->total_length)
- - sizeof(struct ipv4_hdr)));
+ - (ipv4_hdr->version_ihl & 0xf) * 4));
}
return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr));
}
@@ -379,13 +379,14 @@ struct ipv4_hdr {
rte_ipv4_udptcp_cksum(const struct ipv4_hdr *ipv4_hdr, const void *l4_hdr)
{
uint32_t cksum;
- uint32_t l3_len, l4_len;
+ uint32_t l3_len, l4_len, iphlen;

l3_len = rte_be_to_cpu_16(ipv4_hdr->total_length);
- if (l3_len < sizeof(struct ipv4_hdr))
- return 0;
+ iphlen = (ipv4_hdr->version_ihl & 0xf) * 4;

- l4_len = l3_len - sizeof(struct ipv4_hdr);
+ if (l3_len < iphlen)
+ return 0;
+ l4_len = l3_len - iphlen;

cksum = rte_raw_cksum(l4_hdr, l4_len);
cksum += rte_ipv4_phdr_cksum(ipv4_hdr, 0);
--
1.8.3.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
From dd72a3e2a760131f156f61a37df8826514f1ed4c Mon Sep 17 00:00:00 2001
From: ywc689 <[email protected]>
Date: Fri, 28 Jun 2019 17:52:13 +0800
Subject: [PATCH 2/2] kni: use netlink event for multicast (driver part)

kni driver send netlink event every time hw-multicast list updated by
kernel, the user kni app should capture the event and update multicast
to kni device.

original way is using rte_kni_request to pass hw-multicast to user kni
module. that method works but finally memory corruption found, which is
to kni device.
---
.../lib/librte_eal/linuxapp/kni/kni_net.c | 68 ++++++++++++++++++++++
1 file changed, 68 insertions(+)

diff --git a/dpdk-stable-17.11.6/lib/librte_eal/linuxapp/kni/kni_net.c b/dpdk-stable-17.11.6/lib/librte_eal/linuxapp/kni/kni_net.c
index db9f489..fab94d1 100644
--- a/dpdk-stable-17.11.6/lib/librte_eal/linuxapp/kni/kni_net.c
+++ b/dpdk-stable-17.11.6/lib/librte_eal/linuxapp/kni/kni_net.c
@@ -35,6 +35,8 @@
#include <linux/skbuff.h>
#include <linux/kthread.h>
#include <linux/delay.h>
+#include <linux/inetdevice.h>
+#include <net/netlink.h>

#include <exec-env/rte_kni_common.h>
#include <kni_fifo.h>
@@ -579,9 +581,75 @@
return 0;
}

+static size_t
+kni_nlmsg_size(void)
+{
+ return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
+ + nla_total_size(4) /* IFA_ADDRESS */
+ + nla_total_size(4) /* IFA_LOCAL */
+ + nla_total_size(4) /* IFA_BROADCAST */
+ + nla_total_size(IFNAMSIZ) /* IFA_LABEL */
+ + nla_total_size(4) /* IFA_FLAGS */
+ + nla_total_size(sizeof(struct ifa_cacheinfo)); /* IFA_CACHEINFO */
+}
+
static void
kni_net_set_rx_mode(struct net_device *dev)
{
+ /*
+ * send event to notify user (DPDK KNI app) that multicast list changed,
+ * so that it can monitor multicast join/leave and set HW mc-addrs to
+ * kni dev accordinglly.
+ *
+ * this event is just an notification, we do not save any mc-addr here
+ * (so attribute space for us). user kni app should get maddrs after
+ * receive this notification.
+ *
+ * I was expecting kernel send some rtnl event for multicast join/leave,
+ * but it doesn't. By checking the call-chain of SIOCADDMULTI (ip maddr,
+ * manages only hardware multicast) and IP_ADD_MEMBERSHIP (ip_mc_join_group,
+ * used to for IPv4 multicast), no rtnl event sent.
+ *
+ * so as workaround, modify kni driver here to send RTM_NEWADDR.
+ * it may not suitalbe to use this event for mcast, but that should works.
+ * hope that won't affect other listener to this event.
+ *
+ * previous solution was using rte_kni_request to pass hw-maddr list to user.
+ * it "works" for times but finally memory corruption found, which is
+ * not easy to address (lock was added and reviewed). That's why we use
+ * netlink event instead.
+ */
+ struct sk_buff *skb;
+ struct net *net = dev_net(dev);
+ struct nlmsghdr *nlh;
+ struct ifaddrmsg *ifm;
+
+ skb = nlmsg_new(kni_nlmsg_size(), GFP_ATOMIC);
+ if (!skb)
+ return;
+
+ /* no other event for us ? */
+ nlh = nlmsg_put(skb, 0, 0, RTM_NEWADDR, sizeof(*ifm), 0);
+ if (!nlh) {
+ kfree_skb(skb);
+ return;
+ }
+
+ /* just send an notification so no other info */
+ ifm = nlmsg_data(nlh);
+ memset(ifm, 0, sizeof(*ifm));
+ ifm->ifa_family = AF_UNSPEC;
+ ifm->ifa_prefixlen = 0;
+ ifm->ifa_flags = 0;
+ ifm->ifa_scope = RT_SCOPE_NOWHERE;
+ ifm->ifa_index = 0;
+
+ nlmsg_end(skb, nlh);
+
+ /* other group ? */
+ pr_debug("%s: rx-mode/multicast-list changed\n", __func__);
+ rtnl_notify(skb, net, 0, RTNLGRP_NOTIFY, NULL, GFP_ATOMIC);
+ return;
}

static int
--
1.8.3.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
From 5dac8928f844b4b6cfaeab6c1174b60b7409279b Mon Sep 17 00:00:00 2001
From: ywc689 <[email protected]>
Date: Fri, 28 Jun 2019 16:27:08 +0800
Subject: [PATCH 1/3] net: support variable IP header len for checksum API.

IPv4 checksum APIs use fixe IP header length, it will failed if there is
any IP option. Now calculating header length by "ihl" field, so that we
can support options.
---
dpdk-stable-18.11.2/lib/librte_net/rte_ip.h | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/dpdk-stable-18.11.2/lib/librte_net/rte_ip.h b/dpdk-stable-18.11.2/lib/librte_net/rte_ip.h
index f9b9090..635bdcc 100644
--- a/dpdk-stable-18.11.2/lib/librte_net/rte_ip.h
+++ b/dpdk-stable-18.11.2/lib/librte_net/rte_ip.h
@@ -252,7 +252,7 @@ struct ipv4_hdr {
rte_ipv4_cksum(const struct ipv4_hdr *ipv4_hdr)
{
uint16_t cksum;
- cksum = rte_raw_cksum(ipv4_hdr, sizeof(struct ipv4_hdr));
+ cksum = rte_raw_cksum(ipv4_hdr, (ipv4_hdr->version_ihl & 0xf) * 4);
return (cksum == 0xffff) ? cksum : (uint16_t)~cksum;
}

@@ -294,7 +294,7 @@ struct ipv4_hdr {
} else {
psd_hdr.len = rte_cpu_to_be_16(
(uint16_t)(rte_be_to_cpu_16(ipv4_hdr->total_length)
- - sizeof(struct ipv4_hdr)));
+ - (ipv4_hdr->version_ihl & 0xf) * 4));
}
return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr));
}
@@ -317,13 +317,14 @@ struct ipv4_hdr {
rte_ipv4_udptcp_cksum(const struct ipv4_hdr *ipv4_hdr, const void *l4_hdr)
{
uint32_t cksum;
- uint32_t l3_len, l4_len;
+ uint32_t l3_len, l4_len, iphlen;

l3_len = rte_be_to_cpu_16(ipv4_hdr->total_length);
- if (l3_len < sizeof(struct ipv4_hdr))
- return 0;
+ iphlen = (ipv4_hdr->version_ihl & 0xf) * 4;

- l4_len = l3_len - sizeof(struct ipv4_hdr);
+ if (l3_len < iphlen)
+ return 0;
+ l4_len = l3_len - iphlen;

cksum = rte_raw_cksum(l4_hdr, l4_len);
cksum += rte_ipv4_phdr_cksum(ipv4_hdr, 0);
--
1.8.3.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
From 7a54416e9370be6d573d6b9429002c0712a5851f Mon Sep 17 00:00:00 2001
From: ywc689 <[email protected]>
Date: Fri, 28 Jun 2019 16:52:24 +0800
Subject: [PATCH 2/3] kni: use netlink event for multicast (driver part)

kni driver send netlink event every time hw-multicast list updated by
kernel, the user kni app should capture the event and update multicast
to kni device.

original way is using rte_kni_request to pass hw-multicast to user kni
module. that method works but finally memory corruption found, which is
to kni device.
---
dpdk-stable-18.11.2/kernel/linux/kni/kni_net.c | 70 ++++++++++++++++++++++++++
1 file changed, 70 insertions(+)

diff --git a/dpdk-stable-18.11.2/kernel/linux/kni/kni_net.c b/dpdk-stable-18.11.2/kernel/linux/kni/kni_net.c
index 7371b6d..edc1416 100644
--- a/dpdk-stable-18.11.2/kernel/linux/kni/kni_net.c
+++ b/dpdk-stable-18.11.2/kernel/linux/kni/kni_net.c
@@ -16,6 +16,8 @@
#include <linux/skbuff.h>
#include <linux/kthread.h>
#include <linux/delay.h>
+#include <linux/inetdevice.h>
+#include <net/netlink.h>

#include <exec-env/rte_kni_common.h>
#include <kni_fifo.h>
@@ -103,6 +105,7 @@
ret_val = wait_event_interruptible_timeout(kni->wq,
kni_fifo_count(kni->resp_q), 3 * HZ);
if (signal_pending(current) || ret_val <= 0) {
+ pr_err("%s: wait_event_interruptible timeout\n", __func__);
ret = -ETIME;
goto fail;
}
@@ -605,9 +608,75 @@ void kni_net_release_fifo_phy(struct kni_dev *kni)
return -EOPNOTSUPP;
}

+static size_t
+kni_nlmsg_size(void)
+{
+ return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
+ + nla_total_size(4) /* IFA_ADDRESS */
+ + nla_total_size(4) /* IFA_LOCAL */
+ + nla_total_size(4) /* IFA_BROADCAST */
+ + nla_total_size(IFNAMSIZ) /* IFA_LABEL */
+ + nla_total_size(4) /* IFA_FLAGS */
+ + nla_total_size(sizeof(struct ifa_cacheinfo)); /* IFA_CACHEINFO */
+}
+
static void
kni_net_set_rx_mode(struct net_device *dev)
{
+ /*
+ * send event to notify user (DPDK KNI app) that multicast list changed,
+ * so that it can monitor multicast join/leave and set HW mc-addrs to
+ * kni dev accordinglly.
+ *
+ * this event is just an notification, we do not save any mc-addr here
+ * (so attribute space for us). user kni app should get maddrs after
+ * receive this notification.
+ *
+ * I was expecting kernel send some rtnl event for multicast join/leave,
+ * but it doesn't. By checking the call-chain of SIOCADDMULTI (ip maddr,
+ * manages only hardware multicast) and IP_ADD_MEMBERSHIP (ip_mc_join_group,
+ * used to for IPv4 multicast), no rtnl event sent.
+ *
+ * so as workaround, modify kni driver here to send RTM_NEWADDR.
+ * it may not suitalbe to use this event for mcast, but that should works.
+ * hope that won't affect other listener to this event.
+ *
+ * previous solution was using rte_kni_request to pass hw-maddr list to user.
+ * it "works" for times but finally memory corruption found, which is
+ * not easy to address (lock was added and reviewed). That's why we use
+ * netlink event instead.
+ */
+ struct sk_buff *skb;
+ struct net *net = dev_net(dev);
+ struct nlmsghdr *nlh;
+ struct ifaddrmsg *ifm;
+
+ skb = nlmsg_new(kni_nlmsg_size(), GFP_ATOMIC);
+ if (!skb)
+ return;
+
+ /* no other event for us ? */
+ nlh = nlmsg_put(skb, 0, 0, RTM_NEWADDR, sizeof(*ifm), 0);
+ if (!nlh) {
+ kfree_skb(skb);
+ return;
+ }
+
+ /* just send an notification so no other info */
+ ifm = nlmsg_data(nlh);
+ memset(ifm, 0, sizeof(*ifm));
+ ifm->ifa_family = AF_UNSPEC;
+ ifm->ifa_prefixlen = 0;
+ ifm->ifa_flags = 0;
+ ifm->ifa_scope = RT_SCOPE_NOWHERE;
+ ifm->ifa_index = 0;
+
+ nlmsg_end(skb, nlh);
+
+ /* other group ? */
+ pr_debug("%s: rx-mode/multicast-list changed\n", __func__);
+ rtnl_notify(skb, net, 0, RTNLGRP_NOTIFY, NULL, GFP_ATOMIC);
+ return;
}

static int
@@ -727,6 +796,7 @@ void kni_net_release_fifo_phy(struct kni_dev *kni)
kni = netdev_priv(netdev);
ret = kni_net_process_request(kni, &req);

+ pr_info("%s request returns %d!\n", __func__, ret);
return (ret == 0 ? req.result : ret);
}

--
1.8.3.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From 408cda4311b0c10b441fbf8b67614d7873ec718a Mon Sep 17 00:00:00 2001
From: ywc689 <[email protected]>
Date: Fri, 28 Jun 2019 17:02:40 +0800
Subject: [PATCH 3/3] driver:kni: enable flow_item type comparsion in
flow_fdir_cmp

the existence is checked before adding/deleting a fdir flow, but
the flow type is not compared in 'flow_fdir_cmp', which resulting
in the failure or unwanted behavior in adding/deleting two same
fdir flows with flow type(such as ipv4 tcp/udp) different only.
---
dpdk-stable-18.11.2/drivers/net/mlx5/mlx5_flow.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/dpdk-stable-18.11.2/drivers/net/mlx5/mlx5_flow.c b/dpdk-stable-18.11.2/drivers/net/mlx5/mlx5_flow.c
index 222cd81..d99edce 100644
--- a/dpdk-stable-18.11.2/drivers/net/mlx5/mlx5_flow.c
+++ b/dpdk-stable-18.11.2/drivers/net/mlx5/mlx5_flow.c
@@ -2668,6 +2668,11 @@ struct rte_flow *
static int
flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
{
+ unsigned i;
+ for (i = 0; i < sizeof(f1->items)/sizeof(f1->items[0]); i++) {
+ if (f1->items[i].type != f2->items[i].type)
+ return 1;
+ }
if (FLOW_FDIR_CMP(f1, f2, attr) ||
FLOW_FDIR_CMP(f1, f2, l2) ||
FLOW_FDIR_CMP(f1, f2, l2_mask) ||
--
1.8.3.1

0 comments on commit 35280c0

Please sign in to comment.