Skip to content

Commit

Permalink
Fix segmentation fault problem when running on machines whose cpu num…
Browse files Browse the repository at this point in the history
…ber is over DPVS_MAX_LCORE.

Fixed issue iqiyi#991.

Signed-off-by: ywc689 <[email protected]>
  • Loading branch information
ywc689 committed Sep 13, 2024
1 parent 2c9b632 commit 166b977
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/inetaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,12 @@ static int __idev_add_mcast_init(void *args)
struct inet_device *idev;
union inet_addr all_nodes, all_routers;
struct rte_ether_addr eaddr_nodes, eaddr_routers;
bool is_master = (rte_lcore_id() == g_master_lcore_id);

lcoreid_t cid = rte_lcore_id();
bool is_master = (cid == g_master_lcore_id);
struct netif_port *dev = (struct netif_port *) args;

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;
idev = dev_get_idev(dev);

memset(&eaddr_nodes, 0, sizeof(eaddr_nodes));
Expand Down Expand Up @@ -1952,7 +1954,7 @@ static int ifa_sockopt_agent_get(sockoptid_t opt, const void *conf, size_t size,
struct inet_device *idev = NULL;
struct inet_addr_front *array = NULL;
const struct inet_addr_entry *entry = conf;
int len;
int len = 0;
int err;

if (entry->af != AF_INET && entry->af != AF_INET6 && entry->af != AF_UNSPEC) {
Expand Down
9 changes: 8 additions & 1 deletion src/ipset/ipset_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ ipset_flush_lcore(void *arg)
int i;
struct ipset *set;

if (rte_lcore_id() >= DPVS_MAX_LCORE)
return EDPVS_OK;

for (i = 0; i < IPSETS_TBL_SIZE; i++) {
list_for_each_entry(set, &this_ipsets_tbl[i], list)
set->type->destroy(set);
Expand All @@ -244,8 +247,12 @@ static int
ipset_lcore_init(void *arg)
{
int i;
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

if (!rte_lcore_is_enabled(rte_lcore_id()))
if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

this_ipsets_tbl = rte_zmalloc(NULL,
Expand Down
9 changes: 8 additions & 1 deletion src/ipv6/route6.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,14 @@ static int rt6_setup_lcore(void *arg)
int err;
bool global;
struct timeval tv;
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

tv.tv_sec = g_rt6_recycle_time,
tv.tv_usec = 0,
global = (rte_lcore_id() == rte_get_main_lcore());
global = (cid == rte_get_main_lcore());

INIT_LIST_HEAD(&this_rt6_dustbin.routes);
err = dpvs_timer_sched_period(&this_rt6_dustbin.tm, &tv, rt6_recycle, NULL, global);
Expand All @@ -152,6 +156,9 @@ static int rt6_destroy_lcore(void *arg)
{
struct route6 *rt6, *next;

if (rte_lcore_id() >= DPVS_MAX_LCORE)
return EDPVS_OK;

list_for_each_entry_safe(rt6, next, &this_rt6_dustbin.routes, hnode) {
if (rte_atomic32_read(&rt6->refcnt) <= 1) { /* need judge refcnt here? */
list_del(&rt6->hnode);
Expand Down
18 changes: 14 additions & 4 deletions src/ipvs/ip_vs_blklst.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,20 @@ static struct dpvs_sockopts blklst_sockopts = {
static int blklst_lcore_init(void *args)
{
int i;
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

if (!rte_lcore_is_enabled(rte_lcore_id()))
if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

this_num_blklsts = 0;
this_num_blklsts_ipset = 0;

this_blklst_tab = rte_malloc(NULL, sizeof(struct list_head) *
DPVS_BLKLST_TAB_SIZE, RTE_CACHE_LINE_SIZE);
this_blklst_tab = rte_malloc(NULL,
sizeof(struct list_head) * DPVS_BLKLST_TAB_SIZE,
RTE_CACHE_LINE_SIZE);
if (!this_blklst_tab)
return EDPVS_NOMEM;
for (i = 0; i < DPVS_BLKLST_TAB_SIZE; i++)
Expand All @@ -487,7 +492,12 @@ static int blklst_lcore_init(void *args)

static int blklst_lcore_term(void *args)
{
if (!rte_lcore_is_enabled(rte_lcore_id()))
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

dp_vs_blklst_flush_all();
Expand Down
15 changes: 12 additions & 3 deletions src/ipvs/ip_vs_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,11 +1192,15 @@ static void dp_vs_conn_put_nolock(struct dp_vs_conn *conn)
static int conn_init_lcore(void *arg)
{
int i;
lcoreid_t cid = rte_lcore_id();

if (!rte_lcore_is_enabled(rte_lcore_id()))
if (cid >= DPVS_MAX_LCORE)
return EDPVS_IDLE;

if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

if (!netif_lcore_is_fwd_worker(rte_lcore_id()))
if (!netif_lcore_is_fwd_worker(cid))
return EDPVS_IDLE;

this_conn_tbl = rte_malloc(NULL,
Expand All @@ -1218,7 +1222,12 @@ static int conn_init_lcore(void *arg)

static int conn_term_lcore(void *arg)
{
if (!rte_lcore_is_enabled(rte_lcore_id()))
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_IDLE;

if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

if (this_conn_tbl) {
Expand Down
18 changes: 14 additions & 4 deletions src/ipvs/ip_vs_whtlst.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,20 @@ static struct dpvs_sockopts whtlst_sockopts = {
static int whtlst_lcore_init(void *args)
{
int i;
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

if (!rte_lcore_is_enabled(rte_lcore_id()))
if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

this_num_whtlsts = 0;
this_num_whtlsts_ipset = 0;

this_whtlst_tab = rte_malloc(NULL, sizeof(struct list_head) *
DPVS_WHTLST_TAB_SIZE, RTE_CACHE_LINE_SIZE);
this_whtlst_tab = rte_malloc(NULL,
sizeof(struct list_head) * DPVS_WHTLST_TAB_SIZE,
RTE_CACHE_LINE_SIZE);
if (!this_whtlst_tab)
return EDPVS_NOMEM;
for (i = 0; i < DPVS_WHTLST_TAB_SIZE; i++)
Expand All @@ -550,7 +555,12 @@ static int whtlst_lcore_init(void *args)

static int whtlst_lcore_term(void *args)
{
if (!rte_lcore_is_enabled(rte_lcore_id()))
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

dp_vs_whtlst_flush_all();
Expand Down
13 changes: 11 additions & 2 deletions src/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,12 @@ static struct dpvs_sockopts route_sockopts = {
static int route_lcore_init(void *arg)
{
int i;
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

if (!rte_lcore_is_enabled(rte_lcore_id()))
if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

for (i = 0; i < LOCAL_ROUTE_TAB_SIZE; i++)
Expand All @@ -684,7 +688,12 @@ static int route_lcore_init(void *arg)

static int route_lcore_term(void *arg)
{
if (!rte_lcore_is_enabled(rte_lcore_id()))
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

return route_lcore_flush();
Expand Down
3 changes: 3 additions & 0 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ static int dpvs_job_loop(void *arg)
thres_time = BIG_LOOP_THRESH_MASTER;
#endif

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

/* skip irrelative job loops */
if (role == LCORE_ROLE_MAX)
return EDPVS_INVAL;
Expand Down
14 changes: 12 additions & 2 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,25 @@ static int timer_term_schedler(struct timer_scheduler *sched)

static int timer_lcore_init(void *arg)
{
if (!rte_lcore_is_enabled(rte_lcore_id()))
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

return timer_init_schedler(&RTE_PER_LCORE(timer_sched), rte_lcore_id());
}

static int timer_lcore_term(void *arg)
{
if (!rte_lcore_is_enabled(rte_lcore_id()))
lcoreid_t cid = rte_lcore_id();

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;

if (!rte_lcore_is_enabled(cid))
return EDPVS_DISABLED;

return timer_term_schedler(&RTE_PER_LCORE(timer_sched));
Expand Down

0 comments on commit 166b977

Please sign in to comment.