From: Liangxing Wang Date: Thu, 16 Feb 2023 09:31:01 +0000 (+0000) Subject: vcl: fix incorrect ldp worker in ldp_epoll_pwait() X-Git-Tag: v23.10-rc0~234 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=7c7231fc30d9da81bc1311966fe8b9d8720c1623;p=vpp.git vcl: fix incorrect ldp worker in ldp_epoll_pwait() For some apps(e.g. wrk2) upon vpp hoststack, ldp_epoll_pwait() is called. In this function, epoll fd was created on one thread, but it is now used on another thread. The vcl worker index is still invalid, so the fetched ldp worker is also invalid and can corrupt some already allocated memory. Just as the ldp_epoll_pwait_eventfd(), make sure the vcl worker is valid before getting the ldp worker in ldp_epoll_pwait(). Type: fix Signed-off-by: Liangxing Wang Change-Id: I2ec23a4b5d5b0879a06642ffd80f95e948af4274 --- diff --git a/src/vcl/ldp.c b/src/vcl/ldp.c index ade19a73a94..71ce94bdd18 100644 --- a/src/vcl/ldp.c +++ b/src/vcl/ldp.c @@ -2385,7 +2385,7 @@ static inline int ldp_epoll_pwait (int epfd, struct epoll_event *events, int maxevents, int timeout, const sigset_t * sigmask) { - ldp_worker_ctx_t *ldpw = ldp_worker_get_current (); + ldp_worker_ctx_t *ldpw; double time_to_wait = (double) 0, max_time; int libc_epfd, rv = 0; vls_handle_t ep_vlsh; @@ -2398,6 +2398,10 @@ ldp_epoll_pwait (int epfd, struct epoll_event *events, int maxevents, return -1; } + if (PREDICT_FALSE (vppcom_worker_index () == ~0)) + vls_register_vcl_worker (); + + ldpw = ldp_worker_get_current (); if (epfd == ldpw->vcl_mq_epfd) return libc_epoll_pwait (epfd, events, maxevents, timeout, sigmask);