diff options
author | Deepak S <deepak.s@linux.intel.com> | 2018-02-15 10:00:55 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-02-15 10:00:55 +0000 |
commit | 4a2cd9100b43e1977e22b06a4d36bfb89959b186 (patch) | |
tree | 47ee50fc994db743f3fee89f1daacfa77bd531cc | |
parent | f1b7de05ac886a58a994676a4a5b6591eed5fc91 (diff) | |
parent | 26a2e095473ba20af7f2f81aafef002145184af9 (diff) |
Merge "Fix potential crash in rx and tx distribution"
-rw-r--r-- | VNFs/DPPD-PROX/rx_pkt.c | 5 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/task_base.h | 7 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/tx_pkt.c | 5 |
3 files changed, 13 insertions, 4 deletions
diff --git a/VNFs/DPPD-PROX/rx_pkt.c b/VNFs/DPPD-PROX/rx_pkt.c index fd0f7e5c..f6adeb4b 100644 --- a/VNFs/DPPD-PROX/rx_pkt.c +++ b/VNFs/DPPD-PROX/rx_pkt.c @@ -476,7 +476,10 @@ uint16_t rx_pkt_distr(struct task_base *tbase, struct rte_mbuf ***mbufs) { uint16_t ret = call_prev_rx_pkt(tbase, mbufs); - tbase->aux->rx_bucket[ret]++; + if (likely(ret < RX_BUCKET_SIZE)) + tbase->aux->rx_bucket[ret]++; + else + tbase->aux->rx_bucket[RX_BUCKET_SIZE - 1]++; return ret; } diff --git a/VNFs/DPPD-PROX/task_base.h b/VNFs/DPPD-PROX/task_base.h index f8c05242..00087ab6 100644 --- a/VNFs/DPPD-PROX/task_base.h +++ b/VNFs/DPPD-PROX/task_base.h @@ -143,6 +143,9 @@ struct task_base; #define MAX_RX_PKT_ALL 16384 +#define RX_BUCKET_SIZE (2 * MAX_RING_BURST + 1) /* Limit RX bucket size */ +#define TX_BUCKET_SIZE (MAX_RING_BURST +1) + #define MAX_STACKED_RX_FUCTIONS 16 typedef uint16_t (*rx_pkt_func) (struct task_base *tbase, struct rte_mbuf ***mbufs); @@ -164,8 +167,8 @@ struct task_base_aux { int rx_prev_idx; uint16_t (*rx_pkt_prev[MAX_STACKED_RX_FUCTIONS])(struct task_base *tbase, struct rte_mbuf ***mbufs); - uint32_t rx_bucket[MAX_RING_BURST + 1]; - uint32_t tx_bucket[MAX_RING_BURST + 1]; + uint32_t rx_bucket[RX_BUCKET_SIZE]; + uint32_t tx_bucket[TX_BUCKET_SIZE]; int (*tx_pkt_l2)(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out); int (*tx_pkt_orig)(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out); int (*tx_pkt_hw)(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out); diff --git a/VNFs/DPPD-PROX/tx_pkt.c b/VNFs/DPPD-PROX/tx_pkt.c index 9ada51ca..49f46898 100644 --- a/VNFs/DPPD-PROX/tx_pkt.c +++ b/VNFs/DPPD-PROX/tx_pkt.c @@ -704,7 +704,10 @@ int tx_pkt_dump(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkt task that xmits the packet, no atomic operation is needed. */ int tx_pkt_distr(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out) { - tbase->aux->tx_bucket[n_pkts]++; + if (likely(n_pkts < TX_BUCKET_SIZE)) + tbase->aux->tx_bucket[n_pkts]++; + else + tbase->aux->tx_bucket[TX_BUCKET_SIZE - 1]++; return tbase->aux->tx_pkt_orig(tbase, mbufs, n_pkts, out); } |