From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by dpdk.org (Postfix) with ESMTP id AE729F3E for ; Mon, 30 Apr 2018 16:54:43 +0200 (CEST) Received: by mail-wm0-f49.google.com with SMTP id a67so6077856wmf.3 for ; Mon, 30 Apr 2018 07:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/w1+P912g0O5yMmyZ0+Amd+yfFRukXhwRjwW01Bl8CE=; b=tGjzENy1xcJzeDzdl4FXeSmuXWKc26tuePzTAoVlGX1Tyzy0NPNVpBpJKKqaKL5E22 oZBN7JH87ID8+EJr6gDhdfz5bUa81/WmaC+40KGs6l9ceF/ruG8eNn8RJy/veXdXNEeZ ONCyeq2DWjcaROZQxUEKsDQPuZ+XQ0zuzryfcOFEz7y61krelLfgO/nHniJsyi/qmlk5 mE7uzR3bkbgH7LC9iRsVHiI0Q09nICiYA4QrcXgNVEr8D581ZAot65Pc5jmieSJECoya ryoZh4/YB0vLIUBGRpDII/oBmiZBellFAuoaXQCcJBFoBPHkcftr134mXG39v6i9f5ND OrZA== 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=/w1+P912g0O5yMmyZ0+Amd+yfFRukXhwRjwW01Bl8CE=; b=UaW28IiL57eFHt2eKW/3x3e6rOeGv/G2Fu6yD5GwUjAqFV/gwTdG/1Ng9j7RClONb6 QoYT7ku9cydYoVIs46TPdln9YZiTTBTWNyYUYpY/xnCv5lgW6t3nh/rgWuw+UjNFHoeo DTSIOAeZ8F1g71eW1Usst72X/peF6vrl2FVj/VFEUaM0apP6KdHEsd4W2weVHUnF0CGT z07QvRJj822fSKRiM4g+PRrogCWGbnEZg8znZMzUTd+frRvHHu1zqQy/bF9aUzsclcm6 BdyT573RKChlYN0cVOlM166Pslc3w/24/YNJq9gc+8vbyt6aWZw5+GjYKNJWu0RQWA+J n9Vg== X-Gm-Message-State: ALQs6tB8WPdrfXikzTrM6mObhEUJEvtEGY1V7Ty/9f/fyA22x2X9ehos k+IODs1jkkQIQijA4VQj2qI= X-Google-Smtp-Source: AB8JxZoFHOTz0s0WTeWh2SeyMpkxLV2lfrSLMlxta0xK13c0yLm+L82QzJixnqPUX1X7AR5xRCHjBw== X-Received: by 10.28.134.69 with SMTP id i66mr8234242wmd.40.1525100083358; Mon, 30 Apr 2018 07:54:43 -0700 (PDT) Received: from localhost ([2a00:23c5:be9a:5200:ce4c:82c0:d567:ecbb]) by smtp.gmail.com with ESMTPSA id e7-v6sm7862217wrn.88.2018.04.30.07.54.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Apr 2018 07:54:42 -0700 (PDT) From: luca.boccassi@gmail.com To: Adrien Mazarguil Cc: Nelio Laranjeiro , Ferruh Yigit , dpdk stable Date: Mon, 30 Apr 2018 15:53:44 +0100 Message-Id: <20180430145402.23057-25-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180430145402.23057-1-luca.boccassi@gmail.com> References: <20180430144223.18657-85-luca.boccassi@gmail.com> <20180430145402.23057-1-luca.boccassi@gmail.com> Subject: [dpdk-stable] patch 'ethdev: fix shallow copy of flow API RSS action' has been queued to stable release 18.02.2 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Apr 2018 14:54:43 -0000 Hi, FYI, your patch has been queued to stable release 18.02.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 05/02/18. So please shout if anyone has objections. Thanks. Luca Boccassi --- >>From 4249e5cfb8bed6622e915d115366bb666d472370 Mon Sep 17 00:00:00 2001 From: Adrien Mazarguil Date: Thu, 19 Apr 2018 12:07:44 +0200 Subject: [PATCH] ethdev: fix shallow copy of flow API RSS action [ upstream commit 972bf3610611264182782281b08dae9e4d39a327 ] The rss_conf field is defined as a pointer to struct rte_eth_rss_conf. Even assuming it is permanently allocated and a pointer copy is safe, pointed data may change and not reflect an applied flow rule anymore. This patch aligns with testpmd by making a deep copy instead. Fixes: 18da437b5f63 ("ethdev: add flow rule copy function") Signed-off-by: Adrien Mazarguil Acked-by: Nelio Laranjeiro Acked-by: Ferruh Yigit --- lib/librte_ether/rte_flow.c | 145 +++++++++++++++++++++++++++++++------------- 1 file changed, 102 insertions(+), 43 deletions(-) diff --git a/lib/librte_ether/rte_flow.c b/lib/librte_ether/rte_flow.c index 38f2d27be..ba6feddee 100644 --- a/lib/librte_ether/rte_flow.c +++ b/lib/librte_ether/rte_flow.c @@ -255,60 +255,119 @@ rte_flow_error_set(struct rte_flow_error *error, return -code; } -/** Compute storage space needed by item specification. */ -static void -flow_item_spec_size(const struct rte_flow_item *item, - size_t *size, size_t *pad) +/** Pattern item specification types. */ +enum item_spec_type { + ITEM_SPEC, + ITEM_LAST, + ITEM_MASK, +}; + +/** Compute storage space needed by item specification and copy it. */ +static size_t +flow_item_spec_copy(void *buf, const struct rte_flow_item *item, + enum item_spec_type type) { - if (!item->spec) { - *size = 0; + size_t size = 0; + const void *item_spec = + type == ITEM_SPEC ? item->spec : + type == ITEM_LAST ? item->last : + type == ITEM_MASK ? item->mask : + NULL; + + if (!item_spec) goto empty; - } switch (item->type) { union { const struct rte_flow_item_raw *raw; - } spec; + } src; + union { + struct rte_flow_item_raw *raw; + } dst; - /* Not a fall-through */ case RTE_FLOW_ITEM_TYPE_RAW: - spec.raw = item->spec; - *size = offsetof(struct rte_flow_item_raw, pattern) + - spec.raw->length * sizeof(*spec.raw->pattern); + src.raw = item_spec; + dst.raw = buf; + size = offsetof(struct rte_flow_item_raw, pattern) + + src.raw->length * sizeof(*src.raw->pattern); + if (dst.raw) + memcpy(dst.raw, src.raw, size); break; default: - *size = rte_flow_desc_item[item->type].size; + size = rte_flow_desc_item[item->type].size; + if (buf) + memcpy(buf, item_spec, size); break; } empty: - *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size; + return RTE_ALIGN_CEIL(size, sizeof(double)); } -/** Compute storage space needed by action configuration. */ -static void -flow_action_conf_size(const struct rte_flow_action *action, - size_t *size, size_t *pad) +/** Compute storage space needed by action configuration and copy it. */ +static size_t +flow_action_conf_copy(void *buf, const struct rte_flow_action *action) { - if (!action->conf) { - *size = 0; + size_t size = 0; + + if (!action->conf) goto empty; - } switch (action->type) { union { const struct rte_flow_action_rss *rss; - } conf; + } src; + union { + struct rte_flow_action_rss *rss; + } dst; + size_t off; - /* Not a fall-through. */ case RTE_FLOW_ACTION_TYPE_RSS: - conf.rss = action->conf; - *size = offsetof(struct rte_flow_action_rss, queue) + - conf.rss->num * sizeof(*conf.rss->queue); + src.rss = action->conf; + dst.rss = buf; + off = 0; + if (dst.rss) + *dst.rss = (struct rte_flow_action_rss){ + .num = src.rss->num, + }; + off += offsetof(struct rte_flow_action_rss, queue); + if (src.rss->num) { + size = sizeof(*src.rss->queue) * src.rss->num; + if (dst.rss) + memcpy(dst.rss->queue, src.rss->queue, size); + off += size; + } + off = RTE_ALIGN_CEIL(off, sizeof(double)); + if (dst.rss) { + dst.rss->rss_conf = (void *)((uintptr_t)dst.rss + off); + *(struct rte_eth_rss_conf *)(uintptr_t) + dst.rss->rss_conf = (struct rte_eth_rss_conf){ + .rss_key_len = src.rss->rss_conf->rss_key_len, + .rss_hf = src.rss->rss_conf->rss_hf, + }; + } + off += sizeof(*src.rss->rss_conf); + if (src.rss->rss_conf->rss_key_len) { + off = RTE_ALIGN_CEIL(off, sizeof(double)); + size = sizeof(*src.rss->rss_conf->rss_key) * + src.rss->rss_conf->rss_key_len; + if (dst.rss) { + ((struct rte_eth_rss_conf *)(uintptr_t) + dst.rss->rss_conf)->rss_key = + (void *)((uintptr_t)dst.rss + off); + memcpy(dst.rss->rss_conf->rss_key, + src.rss->rss_conf->rss_key, + size); + } + off += size; + } + size = off; break; default: - *size = rte_flow_desc_action[action->type].size; + size = rte_flow_desc_action[action->type].size; + if (buf) + memcpy(buf, action->conf, size); break; } empty: - *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size; + return RTE_ALIGN_CEIL(size, sizeof(double)); } /** Store a full rte_flow description. */ @@ -320,7 +379,6 @@ rte_flow_copy(struct rte_flow_desc *desc, size_t len, { struct rte_flow_desc *fd = NULL; size_t tmp; - size_t pad; size_t off1 = 0; size_t off2 = 0; size_t size = 0; @@ -345,24 +403,26 @@ store: dst = memcpy(fd->data + off1, item, sizeof(*item)); off1 += sizeof(*item); - flow_item_spec_size(item, &tmp, &pad); if (item->spec) { if (fd) - dst->spec = memcpy(fd->data + off2, - item->spec, tmp); - off2 += tmp + pad; + dst->spec = fd->data + off2; + off2 += flow_item_spec_copy + (fd ? fd->data + off2 : NULL, item, + ITEM_SPEC); } if (item->last) { if (fd) - dst->last = memcpy(fd->data + off2, - item->last, tmp); - off2 += tmp + pad; + dst->last = fd->data + off2; + off2 += flow_item_spec_copy + (fd ? fd->data + off2 : NULL, item, + ITEM_LAST); } if (item->mask) { if (fd) - dst->mask = memcpy(fd->data + off2, - item->mask, tmp); - off2 += tmp + pad; + dst->mask = fd->data + off2; + off2 += flow_item_spec_copy + (fd ? fd->data + off2 : NULL, item, + ITEM_MASK); } off2 = RTE_ALIGN_CEIL(off2, sizeof(double)); } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END); @@ -387,12 +447,11 @@ store: dst = memcpy(fd->data + off1, action, sizeof(*action)); off1 += sizeof(*action); - flow_action_conf_size(action, &tmp, &pad); if (action->conf) { if (fd) - dst->conf = memcpy(fd->data + off2, - action->conf, tmp); - off2 += tmp + pad; + dst->conf = fd->data + off2; + off2 += flow_action_conf_copy + (fd ? fd->data + off2 : NULL, action); } off2 = RTE_ALIGN_CEIL(off2, sizeof(double)); } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END); -- 2.14.2