From patchwork Thu May 3 09:31:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?N=C3=A9lio_Laranjeiro?= X-Patchwork-Id: 39289 X-Patchwork-Delegate: shahafs@mellanox.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6BFA92C18; Thu, 3 May 2018 11:30:41 +0200 (CEST) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id 0BF092BA7 for ; Thu, 3 May 2018 11:30:40 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id f6so27181918wmc.4 for ; Thu, 03 May 2018 02:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NXjgCktN0MsmM/ZL+OTgiZTHRXNLxFVL0j0orH+2Ayk=; b=mYg00iRNCux1CH4yKHZqiqLCcnXDKDhdiEgrjUahtbttXIdY3JSUCZpn7YLdXZPJ74 FNbp+wGcnCAiBpfyudEQ0hfxOQ9VlojSSwJlPb7GCvpn06EZX8OMX/MvuDWXEDao+gVt QZpWik7O33Mak/oulp+9m9HfgSFjpVAgPGOb9v/s+OeDdHGvp6qNysbAvLZPf0gFwEDm ptVy7ahaE1aCRRcwh2EEeknBBdXUW1KFg/ULTJh+qzw1Gs/srHhp9MnYpa5W7OyncLq7 P2JreeGvhDsAz67mnKAzqggtAaZiEngI5sckqZrbkd0NJb86UT6V47o7JkCWXQKtWbaU 5XDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NXjgCktN0MsmM/ZL+OTgiZTHRXNLxFVL0j0orH+2Ayk=; b=fy8+ybmlG36/uNO02EmqoaUHrXsWkrBgCkHVxYR1joHJMUnyfR8tw8Y1kS4U7m52HA 9emng+ajQJ29Jslo4SVogZwpQRj/BDDqyiHEsye50RyIbJOx7pCTnwjFyotZ7vecRZIE m0HV5LSWPQBq5HYB4zqkQtIA1m/MA0f4X9wTW7WM8ougCuMir/9e7jYzOXj+1VnNIy9p T+CfzJI2lZfgM7gnas21NAdWesD0XrAk6t0sghToNIxbgSb28mYRDhzwOYF6XLbkmnLg 4SKiIPSbc5APPhNTvzr1KBFLGrOSxNp5yUa27egff48xA8r4O/ET/c6ZlYta1x/J5msQ MSiw== X-Gm-Message-State: ALQs6tBfuYcQ1KiznJdx46EJ8yljcc6HM0kwS+m7Q8RRTIDRaLDkerN1 0rg1lkmwJIbZ98Ghq7LOcL0+Cy7L1A== X-Google-Smtp-Source: AB8JxZqA2tBPcEapQMBdYru/ESm/t4CW2CnUFEdbd+ki5SDiN9ae3XBANHJVuupj1AJ3+Wg4lRlJIg== X-Received: by 10.28.62.79 with SMTP id l76mr13303524wma.145.1525339839540; Thu, 03 May 2018 02:30:39 -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 a14-v6sm16527557wra.84.2018.05.03.02.30.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 02:30:39 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Adrien Mazarguil , Yongseok Koh Cc: stable@dpdk.org Date: Thu, 3 May 2018 11:31:38 +0200 Message-Id: <1adabe63b3dfc733aaad6e9b6e149da73e95c5db.1525339843.git.nelio.laranjeiro@6wind.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2] net/mlx5: fix flow validation 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" Item spec and last are wrongly compared to the NIC capability causing a validation failure when the mask is null. This validation function should only verify the user is not configuring unsupported matching fields. Fixes: 2097d0d1e2cc ("net/mlx5: support basic flow items and actions") Cc: stable@dpdk.org Signed-off-by: Nelio Laranjeiro --- Changes in v2: - Simplify verification by testing only item->mask and item->last. - add a comment to explain the loop verification. --- drivers/net/mlx5/mlx5_flow.c | 77 ++++++++++++------------------------ 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 129311d50..38811bbce 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -538,7 +538,7 @@ struct ibv_spec_header { }; /** - * Check support for a given item. + * Check item is fully supported by the NIC matching capability. * * @param item[in] * Item specification. @@ -555,60 +555,33 @@ static int mlx5_flow_item_validate(const struct rte_flow_item *item, const uint8_t *mask, unsigned int size) { - if (!item->spec && (item->mask || item->last)) { - rte_errno = EINVAL; - return -rte_errno; - } - if (item->spec && !item->mask) { - unsigned int i; - const uint8_t *spec = item->spec; - - for (i = 0; i < size; ++i) - if ((spec[i] | mask[i]) != mask[i]) { - rte_errno = EINVAL; - return -rte_errno; - } - } - if (item->last && !item->mask) { - unsigned int i; - const uint8_t *spec = item->last; - - for (i = 0; i < size; ++i) - if ((spec[i] | mask[i]) != mask[i]) { - rte_errno = EINVAL; - return -rte_errno; - } - } - if (item->mask) { - unsigned int i; - const uint8_t *spec = item->spec; - - for (i = 0; i < size; ++i) - if ((spec[i] | mask[i]) != mask[i]) { - rte_errno = EINVAL; - return -rte_errno; - } - } - if (item->spec && item->last) { - uint8_t spec[size]; - uint8_t last[size]; - const uint8_t *apply = mask; - unsigned int i; - int ret; + unsigned int i; + const uint8_t *spec = item->spec; + const uint8_t *last = item->last; + const uint8_t *m = item->mask ? item->mask : mask; - if (item->mask) - apply = item->mask; - for (i = 0; i < size; ++i) { - spec[i] = ((const uint8_t *)item->spec)[i] & apply[i]; - last[i] = ((const uint8_t *)item->last)[i] & apply[i]; - } - ret = memcmp(spec, last, size); - if (ret != 0) { - rte_errno = EINVAL; - return -rte_errno; - } + if (!spec && (item->mask || last)) + goto error; + if (!spec) + return 0; + /* + * Single-pass check to make sure that: + * - item->mask is supported, no bits are set outside mask. + * - Both masked item->spec and item->last are equal (no range + * supported). + */ + for (i = 0; i < size; i++) { + if (!m[i]) + continue; + if ((m[i] | mask[i]) != mask[i]) + goto error; + if (last && ((spec[i] & m[i]) != (last[i] & m[i]))) + goto error; } return 0; +error: + rte_errno = ENOTSUP; + return -rte_errno; } /**