From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 23692A034C; Thu, 18 Aug 2022 14:30:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B7A5640694; Thu, 18 Aug 2022 14:30:21 +0200 (CEST) Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by mails.dpdk.org (Postfix) with ESMTP id CFD3440156 for ; Thu, 18 Aug 2022 14:30:19 +0200 (CEST) Received: by mail-ej1-f50.google.com with SMTP id tl27so2979528ejc.1 for ; Thu, 18 Aug 2022 05:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=r8iia76t6CbUQmJbr6pVhwEZb3ypfeYUxbG6QfphapQ=; b=cM3b2ZxLjIjSjLvQ8lrz1SjCMLWo+ROo76SFDa7jWR5Psfx7mB5lI6AG4ELrhC4Fmh dCIKCYoEvg3zSqPrdlFZZPcPvqIuja5BFRzrnJ1HrDOpsIRp+yv5ADKO9k5ZAe8ZFcs9 7fVNjLH2BPjTqhDfGB/NwUhXjESD89l2odQ41XAusngbblSUAehhJBI2HLd7k6PPz3jt paAhvXuxNwSt/Bs/53oarz+JrdS8Ll5T/A+5eXKpiQSrSLNw1hiSMMwY72dblGjXMRtu UExULfLT+O1enIlWWtT5tKKrR7AI5GUoLa80E5IhWHiZUHyGcCpYsG1v/9CO+2IuMbuh zrOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=r8iia76t6CbUQmJbr6pVhwEZb3ypfeYUxbG6QfphapQ=; b=WEr4+9oDEbTy4Z2nqLPc4AhqMuZX7bJZBqg4xTBURrbIPQvxRNoidBd6N1OiXsCPRf 2Qgj+fa2p5ZRlZyD8Zz/87HqC4kibnl4WFRGJfIidV/CBNOOeXdLUxtk46BQXTYg5gus UpyUT6awq/siJT04BvWyy0IO6lGG7OO3JTaWPL0CPiQeraXECTbCXReJZt7vvKPuIWM4 v9A7xlgV7Zr5XwxuInl3lSPpRq0/znmQOgb00G5j+jN1ElCFJJPNhcbTQk3RyZDhxn3U d0AkstNfPvQ1DSOUaR7BXZTP6xT8VpoLFsUNVJ1xyp1FiihOqbzBXHWxVd2DPIK8NIoc bnHw== X-Gm-Message-State: ACgBeo0lNa8731jdgS3q0B1MWUk00p1xuxfJ/heVJgtD3rfnFlNNyyVS 5ity0tHyLxgQtKuPuNV7RsXnoQ== X-Google-Smtp-Source: AA6agR5359aiPFwkXIl/TlORx3gMnzHBwchnj4mnunYyB99wZo7WdqFomgIMRuk+osR/r8f2D+xD2A== X-Received: by 2002:a17:907:9495:b0:734:e049:3d15 with SMTP id dm21-20020a170907949500b00734e0493d15mr1813861ejc.187.1660825819487; Thu, 18 Aug 2022 05:30:19 -0700 (PDT) Received: from bts2.localdomain ([182.191.83.208]) by smtp.gmail.com with ESMTPSA id ku18-20020a170907789200b0071cef8bafc3sm770795ejc.1.2022.08.18.05.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 05:30:18 -0700 (PDT) From: "huzaifa.rahman" To: matan@nvidia.com Cc: dev@dpdk.org, viacheslavo@nvidia.com, "huzaifa.rahman" Subject: [PATCH] mlx5: initially reading xstats does not cause seg fault Date: Thu, 18 Aug 2022 12:30:14 +0000 Message-Id: <20220818123014.2515261-1-huzaifa.rahman@emumba.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Bugzilla ID: 296 the size of counters array in mlx5_xstats_get() was smaller than the memory we are setting for this array in mlx5_os_read_dev_counters(). due to which the extra memory is corrupted and thus corrupting the seemingly unrelated variables. this happens at the first run only because the n function arg of mlx5_xstats_get() which is used to init counters array is initialized by adding the preceding statistics which in our case (i.e first run) is zero. after the initialization in mlx5_os_stats_init() the mlx5_stats_n is populated and thus from then onward the counters array size is correct my changes will only affect the flow of the first run when we need to initialize stats in mlx5_os_stats_init(). the size of the counters array is set according the mlx5_stats_n variable. by doing this we will avoid the memset corrupting other variables` memory Signed-off-by: huzaifa.rahman --- drivers/net/mlx5/mlx5_stats.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c index f64fa3587b..bccfec10fb 100644 --- a/drivers/net/mlx5/mlx5_stats.c +++ b/drivers/net/mlx5/mlx5_stats.c @@ -40,7 +40,6 @@ mlx5_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats, { struct mlx5_priv *priv = dev->data->dev_private; unsigned int i; - uint64_t counters[n]; struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; uint16_t mlx5_stats_n = xstats_ctrl->mlx5_stats_n; @@ -51,8 +50,11 @@ mlx5_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats, stats_n = mlx5_os_get_stats_n(dev); if (stats_n < 0) return stats_n; - if (xstats_ctrl->stats_n != stats_n) + if (xstats_ctrl->stats_n != stats_n) { mlx5_os_stats_init(dev); + n = xstats_ctrl->mlx5_stats_n; + } + uint64_t counters[n]; ret = mlx5_os_read_dev_counters(dev, counters); if (ret) return ret; -- 2.25.1