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 1AA3D44093; Wed, 22 May 2024 05:30:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1C42D40685; Wed, 22 May 2024 05:30:33 +0200 (CEST) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id F31164028B for ; Wed, 22 May 2024 05:30:28 +0200 (CEST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1ee12baa01cso6745365ad.0 for ; Tue, 21 May 2024 20:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716348628; x=1716953428; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xunUODDUTHEH8MqFIV+5R9tfv8wlmNo4clzAhy6RGAs=; b=FsCfeOAL0OUkrcqzjOfBRtr3bQBsu00rAkkFKUlOpr3hBBzIscGwSe4vW2W2WzEXb4 +n9iItqgzBzGBfjDNJgmMLmKGVG8rLyYkse1cvNHMmFEkO2hkNPJCCFr1217daKJzvm8 lwEqxrI+YJXECqrKStPuK9pCnhDc0OZBvroErgpYbXSnv6G/IPxgeJGnv2QuNl0copSx wDJNI0ku6CtI95a2S6+aXUS/nl7kdiqu8lA92OFnyi0LqdQlESaE8CrZOzhV8YxrnEu9 A6MdFY5BIKx4uzLk2cjTqw/DjnYKgWkbw+WV8uNh6bYFeeCuKqkaiFa26Zdn5fq7M6ic pMng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716348628; x=1716953428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xunUODDUTHEH8MqFIV+5R9tfv8wlmNo4clzAhy6RGAs=; b=RVF3XhlXL4HRC6cu/zPs3ZFS0D0ROkvHegZ8yFCUSk8Z0Ckwir+M+b+VooWh+ECTAc vdtw49xN49pmdDL5OdHNpfZ4pTkCCC2FTsi5bAd+mZvSKPu4ERO/W0vtdal5IuUnl0ui 8YsxApxLebd+cVLpbFPuHk7/oMyYGAdMQV8S1x70CJCHTiNT4TBfe8Ft0FjGQQP27L6i AQHildeNdLOYxQC3F7SyalZ79WzUZ8mlvmTHxJP2TF+Fqy+uknrXi7ysaajdjqGOH4Db JVtRhbUdleJ2sUcyhktKDC4wusZjXn5zYW5vJDPa4k+4Kw5rCEz44Xq7h5XbFAFST4dX 2f6A== X-Gm-Message-State: AOJu0YwOOSg+aNRf64eUfqA7X+lpUbggy+umNyYedhslnskv9KEQz782 v4sSk19kLsNt/6/PsYrZEwNMWIec4p+rtG926TXlFGDhsOpbsBtFtyMmzoJwo4iXGLAjrXyPRsS rgiU= X-Google-Smtp-Source: AGHT+IHLuZ2Kj4K7/37XEfo1bMp/qKEei2GQ35s6oT1YGsm7sm3cpfRqtVhZkVS7k/c6gZR0UoSzLQ== X-Received: by 2002:a17:902:ec86:b0:1f2:f983:b844 with SMTP id d9443c01a7336-1f31ca4b6b7mr9704205ad.65.1716348627912; Tue, 21 May 2024 20:30:27 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f323c70dafsm2264325ad.260.2024.05.21.20.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 20:30:27 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Ori Kam Subject: [PATCH v5 03/32] ethdev: replace uses of rte_memcpy Date: Tue, 21 May 2024 20:27:30 -0700 Message-ID: <20240522033009.143100-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522033009.143100-1-stephen@networkplumber.org> References: <20240403163432.437275-1-stephen@networkplumber.org> <20240522033009.143100-1-stephen@networkplumber.org> 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 Replace use of rte_memcpy in ethdev. Most of these were fixed size, and the others were not in the fast path. Where possible replace memcpy() with structure assignment which has same effect is type safe. Signed-off-by: Stephen Hemminger ethdev: struct assign --- lib/ethdev/rte_ethdev.c | 12 ++--- lib/ethdev/rte_flow.c | 101 +++++++++++++++++++--------------------- 2 files changed, 53 insertions(+), 60 deletions(-) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index f1c658f49e..27d2416466 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -618,7 +617,7 @@ rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner) rte_spinlock_lock(rte_mcfg_ethdev_get_lock()); if (eth_dev_shared_data_prepare() != NULL) { - rte_memcpy(owner, ðdev->data->owner, sizeof(*owner)); + *owner = ethdev->data->owner; ret = 0; } else { ret = -ENOMEM; @@ -1316,15 +1315,14 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, dev->data->dev_configured = 0; /* Store original config, as rollback required on failure */ - memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf)); + orig_conf = dev->data->dev_conf; /* * Copy the dev_conf parameter into the dev structure. * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get */ if (dev_conf != &dev->data->dev_conf) - memcpy(&dev->data->dev_conf, dev_conf, - sizeof(dev->data->dev_conf)); + dev->data->dev_conf = *dev_conf; /* Backup mtu for rollback */ old_mtu = dev->data->mtu; @@ -1601,7 +1599,7 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, eth_dev_rx_queue_config(dev, 0); eth_dev_tx_queue_config(dev, 0); rollback: - memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf)); + dev->data->dev_conf = orig_conf; if (old_mtu != dev->data->mtu) dev->data->mtu = old_mtu; @@ -3843,7 +3841,7 @@ rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf) return -EINVAL; } - memcpy(dev_conf, &dev->data->dev_conf, sizeof(struct rte_eth_conf)); + *dev_conf = dev->data->dev_conf; rte_ethdev_trace_conf_get(port_id, dev_conf); diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index 7ab1100ea0..776352b984 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -62,7 +62,8 @@ rte_flow_conv_copy(void *buf, const void *data, const size_t size, size_t sz = rte_type ? desc[type].size : sizeof(void *); if (buf == NULL || data == NULL) return 0; - rte_memcpy(buf, data, (size > sz ? sz : size)); + + memcpy(buf, data, (size > sz ? sz : size)); if (rte_type && desc[type].desc_fn) sz += desc[type].desc_fn(size > 0 ? buf : NULL, data); return sz; @@ -73,11 +74,10 @@ rte_flow_item_flex_conv(void *buf, const void *data) { struct rte_flow_item_flex *dst = buf; const struct rte_flow_item_flex *src = data; - if (buf) { - dst->pattern = rte_memcpy - ((void *)((uintptr_t)(dst + 1)), src->pattern, - src->length); - } + + if (buf) + dst->pattern = memcpy((void *)((uintptr_t)(dst + 1)), + src->pattern, src->length); return src->length; } @@ -643,16 +643,18 @@ rte_flow_conv_item_spec(void *buf, const size_t size, mask.raw = item->mask ? item->mask : &rte_flow_item_raw_mask; src.raw = data; dst.raw = buf; - rte_memcpy(dst.raw, - (&(struct rte_flow_item_raw){ - .relative = src.raw->relative, - .search = src.raw->search, - .reserved = src.raw->reserved, - .offset = src.raw->offset, - .limit = src.raw->limit, - .length = src.raw->length, - }), - size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size); + + memcpy(dst.raw, + (&(struct rte_flow_item_raw){ + .relative = src.raw->relative, + .search = src.raw->search, + .reserved = src.raw->reserved, + .offset = src.raw->offset, + .limit = src.raw->limit, + .length = src.raw->length, + }), + size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size); + off = sizeof(*dst.raw); if (type == RTE_FLOW_CONV_ITEM_SPEC || (type == RTE_FLOW_CONV_ITEM_MASK && @@ -664,9 +666,8 @@ rte_flow_conv_item_spec(void *buf, const size_t size, if (tmp) { off = RTE_ALIGN_CEIL(off, sizeof(*dst.raw->pattern)); if (size >= off + tmp) - dst.raw->pattern = rte_memcpy - ((void *)((uintptr_t)dst.raw + off), - src.raw->pattern, tmp); + dst.raw->pattern = memcpy((void *)((uintptr_t)dst.raw + off), + src.raw->pattern, tmp); off += tmp; } break; @@ -716,32 +717,31 @@ rte_flow_conv_action_conf(void *buf, const size_t size, case RTE_FLOW_ACTION_TYPE_RSS: src.rss = action->conf; dst.rss = buf; - rte_memcpy(dst.rss, - (&(struct rte_flow_action_rss){ - .func = src.rss->func, - .level = src.rss->level, - .types = src.rss->types, - .key_len = src.rss->key_len, - .queue_num = src.rss->queue_num, - }), - size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size); + memcpy(dst.rss, + (&(struct rte_flow_action_rss){ + .func = src.rss->func, + .level = src.rss->level, + .types = src.rss->types, + .key_len = src.rss->key_len, + .queue_num = src.rss->queue_num, + }), + size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size); + off = sizeof(*dst.rss); if (src.rss->key_len && src.rss->key) { off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->key)); tmp = sizeof(*src.rss->key) * src.rss->key_len; if (size >= (uint64_t)off + (uint64_t)tmp) - dst.rss->key = rte_memcpy - ((void *)((uintptr_t)dst.rss + off), - src.rss->key, tmp); + dst.rss->key = memcpy((void *)((uintptr_t)dst.rss + off), + src.rss->key, tmp); off += tmp; } if (src.rss->queue_num) { off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->queue)); tmp = sizeof(*src.rss->queue) * src.rss->queue_num; if (size >= (uint64_t)off + (uint64_t)tmp) - dst.rss->queue = rte_memcpy - ((void *)((uintptr_t)dst.rss + off), - src.rss->queue, tmp); + dst.rss->queue = memcpy((void *)((uintptr_t)dst.rss + off), + src.rss->queue, tmp); off += tmp; } break; @@ -983,20 +983,15 @@ rte_flow_conv_rule(struct rte_flow_conv_rule *dst, size_t off; int ret; - rte_memcpy(dst, - (&(struct rte_flow_conv_rule){ - .attr = NULL, - .pattern = NULL, - .actions = NULL, - }), - size > sizeof(*dst) ? sizeof(*dst) : size); + memcpy(dst, &(struct rte_flow_conv_rule) { }, + size > sizeof(*dst) ? sizeof(*dst) : size); + off = sizeof(*dst); if (src->attr_ro) { off = RTE_ALIGN_CEIL(off, sizeof(double)); if (size && size >= off + sizeof(*dst->attr)) - dst->attr = rte_memcpy - ((void *)((uintptr_t)dst + off), - src->attr_ro, sizeof(*dst->attr)); + dst->attr = memcpy((void *)((uintptr_t)dst + off), + src->attr_ro, sizeof(*dst->attr)); off += sizeof(*dst->attr); } if (src->pattern_ro) { @@ -1098,7 +1093,7 @@ rte_flow_conv(enum rte_flow_conv_op op, attr = src; if (size > sizeof(*attr)) size = sizeof(*attr); - rte_memcpy(dst, attr, size); + memcpy(dst, attr, size); ret = sizeof(*attr); break; case RTE_FLOW_CONV_OP_ITEM: @@ -1180,14 +1175,14 @@ rte_flow_copy(struct rte_flow_desc *desc, size_t len, if (ret < 0) return 0; ret += sizeof(*desc) - sizeof(*dst); - rte_memcpy(desc, - (&(struct rte_flow_desc){ - .size = ret, - .attr = *attr, - .items = dst_size ? dst->pattern : NULL, - .actions = dst_size ? dst->actions : NULL, - }), - len > sizeof(*desc) ? sizeof(*desc) : len); + memcpy(desc, + (&(struct rte_flow_desc){ + .size = ret, + .attr = *attr, + .items = dst_size ? dst->pattern : NULL, + .actions = dst_size ? dst->actions : NULL, + }), + len > sizeof(*desc) ? sizeof(*desc) : len); rte_flow_trace_copy(desc, len, attr, items, actions, ret); -- 2.43.0