Skip to content

Commit

Permalink
Merge pull request iqiyi#568 from legend050709/devel
Browse files Browse the repository at this point in the history
dpvs: fix problem that dpvs crash when cpu id is larger than cpu cnt.
  • Loading branch information
ywc689 authored May 13, 2020
2 parents 85b4703 + 0ae5d90 commit 7504699
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/global_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extern dpvs_lcore_role_t g_lcore_role[DPVS_MAX_LCORE];
* anything else -1
* */
extern int g_lcore_index[DPVS_MAX_LCORE];
extern int g_lcore_num;

int global_data_init(void);
int global_data_term(void);
Expand Down
2 changes: 2 additions & 0 deletions src/global_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
uint64_t g_cycles_per_sec;
dpvs_lcore_role_t g_lcore_role[DPVS_MAX_LCORE];
int g_lcore_index[DPVS_MAX_LCORE];
int g_lcore_num;

int global_data_init(void)
{
int i;

g_cycles_per_sec = rte_get_timer_hz();
g_lcore_num = 0;

for (i = 0; i < DPVS_MAX_LCORE; i++) {
g_lcore_role[i] = LCORE_ROLE_IDLE;
Expand Down
13 changes: 10 additions & 3 deletions src/ipvs/ip_vs_laddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,17 @@ static int dp_vs_copy_percore_laddrs_stats(struct dp_vs_laddr_conf *master_laddr
return EDPVS_OK;
}

static void opt2cpu(sockoptid_t opt, sockoptid_t *new_opt, lcoreid_t *cid)
static int opt2cpu(sockoptid_t opt, sockoptid_t *new_opt, lcoreid_t *cid)
{
*cid = g_lcore_index[opt - SOCKOPT_GET_LADDR_GETALL];
int index = opt - SOCKOPT_GET_LADDR_GETALL;
if (index >= g_lcore_num) {
return -1;
}
*cid = g_lcore_index[index];
assert(*cid >=0 && *cid < DPVS_MAX_LCORE);

*new_opt = SOCKOPT_GET_LADDR_GETALL;
return 0;
}

static int laddr_sockopt_get(sockoptid_t opt, const void *conf, size_t size,
Expand All @@ -579,7 +584,9 @@ static int laddr_sockopt_get(sockoptid_t opt, const void *conf, size_t size,
lcoreid_t cid;

netif_get_slave_lcores(&num_lcores, NULL);
opt2cpu(opt, &new_opt, &cid);
if (opt2cpu(opt, &new_opt, &cid) < 0) {
return EDPVS_INVAL;
}
if (new_opt > SOCKOPT_GET_LADDR_GETALL)
return EDPVS_INVAL;

Expand Down
14 changes: 10 additions & 4 deletions src/ipvs/ip_vs_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,15 +1025,19 @@ static int dp_vs_service_set(sockoptid_t opt, const void *user, size_t len)
* for example : SOCKOPT_SVC_BASE is 200, SOCKOPT_SVC_GET_CMD_MAX is 204,
* old_opt 205 means core 1 get opt 200
*/
static inline void opt2cpu(sockoptid_t old_opt, sockoptid_t *new_opt, lcoreid_t *cid)
static inline int opt2cpu(sockoptid_t old_opt, sockoptid_t *new_opt, lcoreid_t *cid)
{
assert(old_opt >= SOCKOPT_SVC_BASE);
assert(old_opt <= SOCKOPT_SVC_MAX);

int index = (old_opt - SOCKOPT_SVC_BASE)/(SOCKOPT_SVC_GET_CMD_MAX - SOCKOPT_SVC_BASE + 1);
if (index >= g_lcore_num) {
return -1;
}
*new_opt = (old_opt - SOCKOPT_SVC_BASE)%(SOCKOPT_SVC_GET_CMD_MAX - SOCKOPT_SVC_BASE + 1)
+ SOCKOPT_SVC_BASE;
*cid = g_lcore_index[(old_opt - SOCKOPT_SVC_BASE)/(SOCKOPT_SVC_GET_CMD_MAX - SOCKOPT_SVC_BASE + 1)];
*cid = g_lcore_index[index];
assert(*cid >= 0 && *cid < DPVS_MAX_LCORE);
return 0;
}

/* copy service/dest/stats */
Expand Down Expand Up @@ -1204,7 +1208,9 @@ static int dp_vs_service_get(sockoptid_t opt, const void *user, size_t len, void
sockoptid_t new_opt;

netif_get_slave_lcores(&num_lcores, NULL);
opt2cpu(opt, &new_opt, &cid);
if (opt2cpu(opt, &new_opt, &cid) < 0) {
return EDPVS_INVAL;
}
if (new_opt > SOCKOPT_SVC_MAX)
return EDPVS_INVAL;

Expand Down
2 changes: 2 additions & 0 deletions src/netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,8 @@ static void build_lcore_index(void)
for (i = 0; i < DPVS_MAX_LCORE; i++)
if (g_lcore_role[i] == LCORE_ROLE_ISOLRX_WORKER)
g_lcore_index[idx++] = i;

g_lcore_num = idx;
}

static void lcore_role_init(void)
Expand Down

0 comments on commit 7504699

Please sign in to comment.