From patchwork Fri Apr 5 16:53:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139137 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4F2D443E0C; Fri, 5 Apr 2024 18:56:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5253440697; Fri, 5 Apr 2024 18:55:43 +0200 (CEST) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id 0F0FC4067B for ; Fri, 5 Apr 2024 18:55:40 +0200 (CEST) Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6ed04c91ffcso493598b3a.1 for ; Fri, 05 Apr 2024 09:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1712336139; x=1712940939; 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=HqCX3ZeCIbrSXg/su8fvSSeIPWYt0aa2LrZC7JCKR8IbVLgDTf7Ds0vNsOnzjtc8gg 9f/3+tHStGFnzwoa9eL0AnLHdSPFaU+L1xVEXHmlghko1ss+SxX/UVywotMxpWecAhyP 7Ik/RELakOCPgKCGEjFDqnyx6HalUlqKbk0C4fmi4Xn49bdhvRkCk//+UnEj11CD0ExV 1Xd64sNQml64JU8Pp5UC8SXdnFVL+DTjxNbMXan5xC8+UxWExKmWaK4ug0VO6NnRlrQn NexEYIJx3qyIlbQPzjOsS+BxqLASfz5ycNicJrLTNxfblHa3MckRtBk7BlkaPeqx9d8C 2dPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712336139; x=1712940939; 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=VFuPOxWtabYfsOPYFj2kVX1yMo24jMsOhai2BdrPqPGIesA84bVDxQolySSMwAVXDi cKrxHnXD8R3mWILQXFjIDqLa/MApQub5GekSDW9i0dUkoZLZC74mMwpfHksEseYaV1UF P3i38Oj1mKrSPyOmewJHTgkr8L7HneiRBG59A85FsbfeaMFWYGq1sa28e3ktXimBpRTP pb2+iWt93KZ6CvNzcPCu9Cz7sjxJEBlfqw4PVWS1L2S5Pix0+2CyLckggJiOP+dHCVwZ /vI/6q9wHkg4uLPOF6mqLMp4Zxs7S/5wrK6GHgzvBWudTX4j44cjz6pfBB/elI9xOj1f isbA== X-Gm-Message-State: AOJu0YzuH3aqkJWqLHEPwR+ulvW0sf0G36f+J+1mfIPNzsC6Bo0QVYHA lP6989UaghjodEsz0gefHtjeLQ33d+xHDPcMNBGcUDeFKbnDAm7c9otQtNrvHH1GTvB0JsykEVs GVyM= X-Google-Smtp-Source: AGHT+IEDLJtdhfnn78/xE26bWBBKcn5V6d+Na1UVRBsMJt5Vo8lzwZlYNRvQ/iJp1KN7n9BOO69naQ== X-Received: by 2002:a05:6a20:9595:b0:1a7:427a:ecfd with SMTP id iu21-20020a056a20959500b001a7427aecfdmr2487642pzb.54.1712336139235; Fri, 05 Apr 2024 09:55:39 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id c2-20020aa781c2000000b006e6c0f8ce1bsm1728555pfn.47.2024.04.05.09.55.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 09:55:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Ori Kam Subject: [PATCH v4 03/30] ethdev: replace uses of rte_memcpy Date: Fri, 5 Apr 2024 09:53:14 -0700 Message-ID: <20240405165518.367503-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240405165518.367503-1-stephen@networkplumber.org> References: <20240403163432.437275-1-stephen@networkplumber.org> <20240405165518.367503-1-stephen@networkplumber.org> MIME-Version: 1.0 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);