From patchwork Mon Jul 31 15:58:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 27287 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 48AB35699; Mon, 31 Jul 2017 17:58:35 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 20B65567E for ; Mon, 31 Jul 2017 17:58:33 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 31 Jul 2017 08:58:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,442,1498546800"; d="scan'208"; a="1201141724" Received: from silpixa00398672.ir.intel.com ([10.237.223.128]) by fmsmga002.fm.intel.com with ESMTP; 31 Jul 2017 08:58:20 -0700 From: Harry van Haaren To: dev@dpdk.org Cc: Harry van Haaren Date: Mon, 31 Jul 2017 16:58:27 +0100 Message-Id: <1501516707-87024-1-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] service: fix shifts to operate on 64 bit integers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This commit fixes shifts to an integer (1 << shift) which is assumed to be a 32-bit integer. In this case, the shift is variable and expected to be valid for 64-bit integers. Given that the expectation to work with 64 bits exists, we must ensure that the (1 << shift) one in that formula is actually a uin64_t. Simply defining a const uint64_t and using it ensures the compiler is aware of the intention. The issue would only manifest if there were greater than 31 services registered. Fixes: 21698354c832 ("service: introduce service cores concept") Signed-off-by: Harry van Haaren --- lib/librte_eal/common/rte_service.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c index e82b9ad..8c1cffa 100644 --- a/lib/librte_eal/common/rte_service.c +++ b/lib/librte_eal/common/rte_service.c @@ -285,8 +285,9 @@ rte_service_unregister(struct rte_service_spec *spec) s->internal_flags &= ~(SERVICE_F_REGISTERED); + const uint64_t one = 1; for (i = 0; i < RTE_MAX_LCORE; i++) - lcore_states[i].service_mask &= ~(1 << service_id); + lcore_states[i].service_mask &= ~(one << service_id); memset(&rte_services[service_id], 0, sizeof(struct rte_service_spec_impl)); @@ -319,6 +320,7 @@ rte_service_runner_func(void *arg) { RTE_SET_USED(arg); uint32_t i; + const uint64_t one = 1; const int lcore = rte_lcore_id(); struct core_state *cs = &lcore_states[lcore]; @@ -327,7 +329,7 @@ rte_service_runner_func(void *arg) for (i = 0; i < rte_service_count; i++) { struct rte_service_spec_impl *s = &rte_services[i]; if (s->runstate != RUNSTATE_RUNNING || - !(service_mask & (1 << i))) + !(service_mask & (one << i))) continue; /* check do we need cmpset, if MT safe or <= 1 core @@ -448,6 +450,7 @@ service_update(struct rte_service_spec *service, uint32_t lcore, { uint32_t i; int32_t sid = -1; + const uint64_t one = 1; for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { if ((struct rte_service_spec *)&rte_services[i] == service && @@ -465,16 +468,16 @@ service_update(struct rte_service_spec *service, uint32_t lcore, if (set) { if (*set) { - lcore_states[lcore].service_mask |= (1 << sid); + lcore_states[lcore].service_mask |= (one << sid); rte_services[sid].num_mapped_cores++; } else { - lcore_states[lcore].service_mask &= ~(1 << sid); + lcore_states[lcore].service_mask &= ~(one << sid); rte_services[sid].num_mapped_cores--; } } if (enabled) - *enabled = (lcore_states[lcore].service_mask & (1 << sid)); + *enabled = (lcore_states[lcore].service_mask & (one << sid)); rte_smp_wmb(); @@ -599,6 +602,7 @@ rte_service_lcore_start(uint32_t lcore) int32_t rte_service_lcore_stop(uint32_t lcore) { + const uint64_t one = 1; if (lcore >= RTE_MAX_LCORE) return -EINVAL; @@ -607,7 +611,7 @@ rte_service_lcore_stop(uint32_t lcore) uint32_t i; for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { - int32_t enabled = lcore_states[i].service_mask & (1 << i); + int32_t enabled = lcore_states[i].service_mask & (one << i); int32_t service_running = rte_services[i].runstate != RUNSTATE_STOPPED; int32_t only_core = rte_services[i].num_mapped_cores == 1;