Message ID | 1458684557-15378-1-git-send-email-stephen@networkplumber.org (mailing list archive) |
---|---|
State | Accepted, archived |
Delegated to: | Thomas Monjalon |
Headers |
Return-Path: <dev-bounces@dpdk.org> 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 90AEA5954; Tue, 22 Mar 2016 23:09:05 +0100 (CET) Received: from mail-pf0-f171.google.com (mail-pf0-f171.google.com [209.85.192.171]) by dpdk.org (Postfix) with ESMTP id E024F594E for <dev@dpdk.org>; Tue, 22 Mar 2016 23:09:03 +0100 (CET) Received: by mail-pf0-f171.google.com with SMTP id u190so329369166pfb.3 for <dev@dpdk.org>; Tue, 22 Mar 2016 15:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=k+Leh83F6MD9Ib8mlWr8mG9zZKs6Cpu/56xnVsHSw5Q=; b=LKOtaUHpCIha+Pyw+otofF/ttlqEV5866H9kpDvbcOCPy7bOnezhhG71ZDFwhpD26o 9ldv64HLDrG6NkmP4T5va4nPwCDCgTr1NM9LvPiY/riOWDQrv9AyTYr5yL/pFp3NUE2X dxdos7rdgnIjUw5PE7sx5gKztX8fjwkJ6PWrsxbtWq4I6zjSE8EZwIBsygm3R+cG7a3q J30DlT3VYXiJZ/WS0SXgmRhra4O6U3hp9BYt6s9869Pa4nrZhPVtogbFdy9odoitF979 E4QifEBtvaiXRRtx1jWAbB/Cu7sHtQ+Bj7B5K5Ca1qrMiMG8DYGxwXR0YGrUKxNrL4a+ E8lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=k+Leh83F6MD9Ib8mlWr8mG9zZKs6Cpu/56xnVsHSw5Q=; b=lD6GCU+JEwK7ZWE4qpdHfyqlQz5BMx7FXabp4i1mQyxtc6p5/Vu25kasV+OWToau/3 kMbAuBr9wqDjwGr4IgQIiwno23jSZ48jy5qIYftfovhROHJcf+P1EB6/e8mB4eHv+An0 OqOqInzXUMYS6EsjL43502Mw0rYG8rb3oPPY0JD+0FqwE+P119zEMjGlrcIEkFHM3xFc Ar3ePJeqKXqLmuB6rC5KO5+xzva01U1keBti0Z9PGCkq41APJ4KgVmzkT7aHdswE7KKh B1cdddOQ/sHtooHn9LXyzbsFgD40oEeSEye2wOmeRBpXHnVnZWkGSfq5U665sICWrPVB Ae9A== X-Gm-Message-State: AD7BkJJs5GLVvaLr8ijZGsH4AVpekKkdUbtLN6S1x/bOYGzMYsvSC5L4znOZrTM09dCWAA== X-Received: by 10.67.3.67 with SMTP id bu3mr57134422pad.39.1458684542922; Tue, 22 Mar 2016 15:09:02 -0700 (PDT) Received: from xeon-e3.home.lan (static-50-53-65-230.bvtn.or.frontiernet.net. [50.53.65.230]) by smtp.gmail.com with ESMTPSA id v9sm50589250pfi.50.2016.03.22.15.09.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Mar 2016 15:09:01 -0700 (PDT) From: Stephen Hemminger <stephen@networkplumber.org> To: dev@dpdk.org Cc: Stephen Hemminger <stephen@networkplumber.org> Date: Tue, 22 Mar 2016 15:09:17 -0700 Message-Id: <1458684557-15378-1-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 Subject: [dpdk-dev] [PATCH] ethdev: fix rte_eth_dev_xstats_get with NULL X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK <dev.dpdk.org> List-Unsubscribe: <http://dpdk.org/ml/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://dpdk.org/ml/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <http://dpdk.org/ml/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org Sender: "dev" <dev-bounces@dpdk.org> |
Commit Message
Stephen Hemminger
March 22, 2016, 10:09 p.m. UTC
Normal usage of rte_eth_dev_xstats_get is to call twice. The
first time the function is called with portid, xstats = NULL
and n = 0; this returns the number of entries in the statistics
table that need to be allocated.
The problem is that the routine adds a count value to NULL (0)
and assumes that this is a valid pointer (it isn't). Device drivers
all have a check for NULL, and this no longer matches.
Bug was introduced by commit d4fef8b0d5e5
("ethdev: expose generic and driver specific stats in xstats")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/librte_ether/rte_ethdev.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
Hi Stephen, On 03/22/2016 11:09 PM, Stephen Hemminger wrote: > Normal usage of rte_eth_dev_xstats_get is to call twice. The > first time the function is called with portid, xstats = NULL > and n = 0; this returns the number of entries in the statistics > table that need to be allocated. > > The problem is that the routine adds a count value to NULL (0) > and assumes that this is a valid pointer (it isn't). Device drivers > all have a check for NULL, and this no longer matches. > > Bug was introduced by commit d4fef8b0d5e5 > ("ethdev: expose generic and driver specific stats in xstats") > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > --- > lib/librte_ether/rte_ethdev.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c > index db35102..8721a6b 100644 > --- a/lib/librte_ether/rte_ethdev.c > +++ b/lib/librte_ether/rte_ethdev.c > @@ -1495,8 +1495,9 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, > /* Retrieve the xstats from the driver at the end of the > * xstats struct. > */ > - xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count], > - (n > count) ? n - count : 0); > + xcount = (*dev->dev_ops->xstats_get)(dev, > + xstats ? xstats + count : NULL, > + (n > count) ? n - count : 0); > > if (xcount < 0) > return xcount; > Acked-by: Olivier Matz <olivier.matz@6wind.com> Just one comment: I think the driver should not rely on the pointer value, but on the count. From the documentation of rte_eth_xstats_get(), the function returns a: "positive value higher than n: error, the given statistics table is too small. The return value corresponds to the size that should be given to succeed. The entries in the table are not valid and shall not be used by the caller." So maybe it should be also fixed in the driver you are talking about. Thanks, Olivier
2016-03-23 09:51, Olivier Matz: > On 03/22/2016 11:09 PM, Stephen Hemminger wrote: > > Normal usage of rte_eth_dev_xstats_get is to call twice. The > > first time the function is called with portid, xstats = NULL > > and n = 0; this returns the number of entries in the statistics > > table that need to be allocated. > > > > The problem is that the routine adds a count value to NULL (0) > > and assumes that this is a valid pointer (it isn't). Device drivers > > all have a check for NULL, and this no longer matches. This check for NULL should be done after the check (n == 0). > > Bug was introduced by commit d4fef8b0d5e5 > > ("ethdev: expose generic and driver specific stats in xstats") > > > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> [...] > > --- a/lib/librte_ether/rte_ethdev.c > > +++ b/lib/librte_ether/rte_ethdev.c > > @@ -1495,8 +1495,9 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, > > /* Retrieve the xstats from the driver at the end of the > > * xstats struct. > > */ > > - xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count], > > - (n > count) ? n - count : 0); > > + xcount = (*dev->dev_ops->xstats_get)(dev, > > + xstats ? xstats + count : NULL, > > + (n > count) ? n - count : 0); > > > > if (xcount < 0) > > return xcount; > > Acked-by: Olivier Matz <olivier.matz@6wind.com> > > Just one comment: I think the driver should not rely on the pointer > value, but on the count. From the documentation of rte_eth_xstats_get(), > the function returns a: > > "positive value higher than n: error, the given statistics table > is too small. The return value corresponds to the size that should > be given to succeed. The entries in the table are not valid and > shall not be used by the caller." > > So maybe it should be also fixed in the driver you are talking about. In all known drivers, n is checked before xstats pointer. So there is no issue but the patch is still valid for unknown drivers. Applied, thanks
On Wed, 23 Mar 2016 11:19:12 +0100 Thomas Monjalon <thomas.monjalon@6wind.com> wrote: > 2016-03-23 09:51, Olivier Matz: > > On 03/22/2016 11:09 PM, Stephen Hemminger wrote: > > > Normal usage of rte_eth_dev_xstats_get is to call twice. The > > > first time the function is called with portid, xstats = NULL > > > and n = 0; this returns the number of entries in the statistics > > > table that need to be allocated. > > > > > > The problem is that the routine adds a count value to NULL (0) > > > and assumes that this is a valid pointer (it isn't). Device drivers > > > all have a check for NULL, and this no longer matches. > > This check for NULL should be done after the check (n == 0). > > > > Bug was introduced by commit d4fef8b0d5e5 > > > ("ethdev: expose generic and driver specific stats in xstats") > > > > > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > [...] > > > --- a/lib/librte_ether/rte_ethdev.c > > > +++ b/lib/librte_ether/rte_ethdev.c > > > @@ -1495,8 +1495,9 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, > > > /* Retrieve the xstats from the driver at the end of the > > > * xstats struct. > > > */ > > > - xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count], > > > - (n > count) ? n - count : 0); > > > + xcount = (*dev->dev_ops->xstats_get)(dev, > > > + xstats ? xstats + count : NULL, > > > + (n > count) ? n - count : 0); > > > > > > if (xcount < 0) > > > return xcount; > > > > Acked-by: Olivier Matz <olivier.matz@6wind.com> > > > > Just one comment: I think the driver should not rely on the pointer > > value, but on the count. From the documentation of rte_eth_xstats_get(), > > the function returns a: > > > > "positive value higher than n: error, the given statistics table > > is too small. The return value corresponds to the size that should > > be given to succeed. The entries in the table are not valid and > > shall not be used by the caller." > > > > So maybe it should be also fixed in the driver you are talking about. > > In all known drivers, n is checked before xstats pointer. > So there is no issue but the patch is still valid for unknown drivers. > > Applied, thanks Thanks, yes I was testing with a still not yet upstreamed driver.
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index db35102..8721a6b 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1495,8 +1495,9 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, /* Retrieve the xstats from the driver at the end of the * xstats struct. */ - xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count], - (n > count) ? n - count : 0); + xcount = (*dev->dev_ops->xstats_get)(dev, + xstats ? xstats + count : NULL, + (n > count) ? n - count : 0); if (xcount < 0) return xcount;