From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id 9AF7A23D for ; Wed, 25 Jul 2018 10:46:23 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id t6-v6so6559006wrn.7 for ; Wed, 25 Jul 2018 01:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=5IUQzyOFnFijeqVzi+ffbywRKt+pFHsijA1HsevEF78=; b=IjQfe8ZDaGMEm/EW/tHQ/DWvusm1QC+zXKDmjwQzz5mLUzYosYFGoBB5DmfrXmmX1G srIRfViU6oj/nUDDp22ek4dYwpQR7zBdCHOOniZZtHlu1BCIBsDoMRgImktRVfq3oD07 OE0UIZbYzzA2MrsNtCBtMTQWKcg5ouGPAnTXKZpfRvCkpZddqTx5Wsl8CdPKVIGAivUz vQcAvNf2gRToEhtu9tpKbvMKfOW4k3UWSYkyQ7Gk4iA/4G8uJuTR2Mu9dxJAwLeKkbm1 VeAUf1ihoSrZcwGFXq5qXCk/qVHkhYp5vBCJSg8DqVq1TwLGKhJO86wEOlOAhh2txR+t gQig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=5IUQzyOFnFijeqVzi+ffbywRKt+pFHsijA1HsevEF78=; b=pE7ox9yB0fhB3i+zDBD2OBXhCXATGZXfHbaFOLrkSyo1iM6v0TxL8h4vSIVAlKEmil sIzLermgYCFSxCddeNcpSQwsa6u79oyeIWCo+9J+Iim4wxp5R31Dn+lTHQR1kRL3nkE1 T85I41DCgru3sv0CeXkRbgOri9eDevEG4EI8oQjg266YYPJcUnTj5y5LhtCuiPH0c4UO SUhFNdIOlBBEtyHL7ZnmushNNqa8zflEQVGgX4nAtmvhwINv8hT7oPrwLg3wgFZUcYnm kvT2y5+9fYC1zKTD9EesCOKf9xaTSDH9RLt6JteEDKe92M3UnbDenWsddesAQDjjdm/B rOZA== X-Gm-Message-State: AOUpUlHtq4gGseq1kR+XZKQYvFfwrFZaJX2dyzRAYIgnk/zsZakfB8/e uRcr05qOUfWf9GG+xdZJqdM1subXyA== X-Google-Smtp-Source: AAOMgpfhHDPUtfaLHRnFidLRNrBxis8G7uaTAuC4HA9WbDfePEYEoZ6yKFWNCJC9r/o2CB4oQLVYCw== X-Received: by 2002:adf:dd07:: with SMTP id a7-v6mr14408411wrm.2.1532508383180; Wed, 25 Jul 2018 01:46:23 -0700 (PDT) Received: from laranjeiro-vm.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id r1-v6sm13099908wrs.39.2018.07.25.01.46.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jul 2018 01:46:22 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Shahaf Shuler , Yongseok Koh Date: Wed, 25 Jul 2018 10:46:14 +0200 Message-Id: X-Mailer: git-send-email 2.18.0 Subject: [dpdk-dev] [PATCH] net/mlx5: fix count query when flow has not counters 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: , X-List-Received-Date: Wed, 25 Jul 2018 08:46:23 -0000 Querying a counters on a flow without counter is ending with a segmentation fault. Fixes: 60bd8c9747e8 ("net/mlx5: add count flow action") Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_flow.c | 56 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 6fa4e30ae..efaa8b4fb 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -3192,32 +3192,40 @@ mlx5_flow_query_count(struct rte_flow *flow __rte_unused, struct rte_flow_error *error) { #ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT - struct rte_flow_query_count *qc = data; - uint64_t counters[2] = {0, 0}; - struct ibv_query_counter_set_attr query_cs_attr = { - .cs = flow->counter->cs, - .query_flags = IBV_COUNTER_SET_FORCE_UPDATE, - }; - struct ibv_counter_set_data query_out = { - .out = counters, - .outlen = 2 * sizeof(uint64_t), - }; - int err = mlx5_glue->query_counter_set(&query_cs_attr, &query_out); + if (flow->modifier & MLX5_FLOW_MOD_COUNT) { + struct rte_flow_query_count *qc = data; + uint64_t counters[2] = {0, 0}; + struct ibv_query_counter_set_attr query_cs_attr = { + .cs = flow->counter->cs, + .query_flags = IBV_COUNTER_SET_FORCE_UPDATE, + }; + struct ibv_counter_set_data query_out = { + .out = counters, + .outlen = 2 * sizeof(uint64_t), + }; + int err = mlx5_glue->query_counter_set(&query_cs_attr, + &query_out); - if (err) - return rte_flow_error_set(error, err, - RTE_FLOW_ERROR_TYPE_UNSPECIFIED, - NULL, - "cannot read counter"); - qc->hits_set = 1; - qc->bytes_set = 1; - qc->hits = counters[0] - flow->counter->hits; - qc->bytes = counters[1] - flow->counter->bytes; - if (qc->reset) { - flow->counter->hits = counters[0]; - flow->counter->bytes = counters[1]; + if (err) + return rte_flow_error_set + (error, err, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "cannot read counter"); + qc->hits_set = 1; + qc->bytes_set = 1; + qc->hits = counters[0] - flow->counter->hits; + qc->bytes = counters[1] - flow->counter->bytes; + if (qc->reset) { + flow->counter->hits = counters[0]; + flow->counter->bytes = counters[1]; + } + return 0; } - return 0; + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "flow does not have counter"); #endif return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, -- 2.18.0