From: Daniel Mrzyglod Date: Fri, 5 Jun 2015 14:55:10 +0000 (+0200) Subject: port: fix unaligned access to metadata X-Git-Tag: spdx-start~9010 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=1129992baa61d72c5;p=dpdk.git port: fix unaligned access to metadata Fix RTE_MBUF_METADATA macros to allow for unaligned accesses to meta-data fields. Forcing aligned accesses is not really required, so this is removing an unneeded constraint. This issue was met during testing of the new version of the ip_pipeline application. There is no performance impact. This change has no ABI impact, as the previous code that uses aligned accesses continues to run without any issues. Signed-off-by: Daniel Mrzyglod Acked-by: Cristian Dumitrescu --- diff --git a/lib/librte_pipeline/rte_pipeline.c b/lib/librte_pipeline/rte_pipeline.c index 36d92c9f5f..b777cf1c20 100644 --- a/lib/librte_pipeline/rte_pipeline.c +++ b/lib/librte_pipeline/rte_pipeline.c @@ -175,14 +175,6 @@ rte_pipeline_check_params(struct rte_pipeline_params *params) return -EINVAL; } - /* offset_port_id */ - if (params->offset_port_id & 0x3) { - RTE_LOG(ERR, PIPELINE, - "%s: Incorrect value for parameter offset_port_id\n", - __func__); - return -EINVAL; - } - return 0; } diff --git a/lib/librte_port/rte_port.h b/lib/librte_port/rte_port.h index d84e5a1285..1b99b0a913 100644 --- a/lib/librte_port/rte_port.h +++ b/lib/librte_port/rte_port.h @@ -54,23 +54,23 @@ extern "C" { * Macros to allow accessing metadata stored in the mbuf headroom * just beyond the end of the mbuf data structure returned by a port */ -#define RTE_MBUF_METADATA_UINT8(mbuf, offset) \ - (((uint8_t *)&(mbuf)[1])[offset]) -#define RTE_MBUF_METADATA_UINT16(mbuf, offset) \ - (((uint16_t *)&(mbuf)[1])[offset/sizeof(uint16_t)]) -#define RTE_MBUF_METADATA_UINT32(mbuf, offset) \ - (((uint32_t *)&(mbuf)[1])[offset/sizeof(uint32_t)]) -#define RTE_MBUF_METADATA_UINT64(mbuf, offset) \ - (((uint64_t *)&(mbuf)[1])[offset/sizeof(uint64_t)]) - #define RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset) \ - (&RTE_MBUF_METADATA_UINT8(mbuf, offset)) + (&((uint8_t *) &(mbuf)[1])[offset]) #define RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset) \ - (&RTE_MBUF_METADATA_UINT16(mbuf, offset)) + ((uint16_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)) #define RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset) \ - (&RTE_MBUF_METADATA_UINT32(mbuf, offset)) + ((uint32_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)) #define RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset) \ - (&RTE_MBUF_METADATA_UINT64(mbuf, offset)) + ((uint64_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)) + +#define RTE_MBUF_METADATA_UINT8(mbuf, offset) \ + (*RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)) +#define RTE_MBUF_METADATA_UINT16(mbuf, offset) \ + (*RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset)) +#define RTE_MBUF_METADATA_UINT32(mbuf, offset) \ + (*RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset)) +#define RTE_MBUF_METADATA_UINT64(mbuf, offset) \ + (*RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset)) /**@}*/ /* diff --git a/lib/librte_table/rte_table_array.c b/lib/librte_table/rte_table_array.c index c0310700f9..b00ca67e93 100644 --- a/lib/librte_table/rte_table_array.c +++ b/lib/librte_table/rte_table_array.c @@ -66,10 +66,8 @@ rte_table_array_create(void *params, int socket_id, uint32_t entry_size) /* Check input parameters */ if ((p == NULL) || (p->n_entries == 0) || - (!rte_is_power_of_2(p->n_entries)) || - ((p->offset & 0x3) != 0)) { + (!rte_is_power_of_2(p->n_entries))) return NULL; - } /* Memory allocation */ total_cl_size = (sizeof(struct rte_table_array) + diff --git a/lib/librte_table/rte_table_hash_ext.c b/lib/librte_table/rte_table_hash_ext.c index 66e416bb31..73beeaf384 100644 --- a/lib/librte_table/rte_table_hash_ext.c +++ b/lib/librte_table/rte_table_hash_ext.c @@ -149,19 +149,6 @@ check_params_create(struct rte_table_hash_ext_params *params) return -EINVAL; } - /* signature offset */ - if ((params->signature_offset & 0x3) != 0) { - RTE_LOG(ERR, TABLE, "%s: signature_offset invalid value\n", - __func__); - return -EINVAL; - } - - /* key offset */ - if ((params->key_offset & 0x7) != 0) { - RTE_LOG(ERR, TABLE, "%s: key_offset invalid value\n", __func__); - return -EINVAL; - } - return 0; } diff --git a/lib/librte_table/rte_table_hash_key16.c b/lib/librte_table/rte_table_hash_key16.c index f87ea0e5b3..67a4249d9d 100644 --- a/lib/librte_table/rte_table_hash_key16.c +++ b/lib/librte_table/rte_table_hash_key16.c @@ -89,18 +89,6 @@ check_params_create_lru(struct rte_table_hash_key16_lru_params *params) { return -EINVAL; } - /* signature offset */ - if ((params->signature_offset & 0x3) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid signature_offset\n", __func__); - return -EINVAL; - } - - /* key offset */ - if ((params->key_offset & 0x7) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid key_offset\n", __func__); - return -EINVAL; - } - /* f_hash */ if (params->f_hash == NULL) { RTE_LOG(ERR, TABLE, @@ -307,18 +295,6 @@ check_params_create_ext(struct rte_table_hash_key16_ext_params *params) { return -EINVAL; } - /* signature offset */ - if ((params->signature_offset & 0x3) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid signature offset\n", __func__); - return -EINVAL; - } - - /* key offset */ - if ((params->key_offset & 0x7) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid key offset\n", __func__); - return -EINVAL; - } - /* f_hash */ if (params->f_hash == NULL) { RTE_LOG(ERR, TABLE, diff --git a/lib/librte_table/rte_table_hash_key32.c b/lib/librte_table/rte_table_hash_key32.c index 6790594944..1fdb75d0d4 100644 --- a/lib/librte_table/rte_table_hash_key32.c +++ b/lib/librte_table/rte_table_hash_key32.c @@ -89,18 +89,6 @@ check_params_create_lru(struct rte_table_hash_key32_lru_params *params) { return -EINVAL; } - /* signature offset */ - if ((params->signature_offset & 0x3) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid signature offset\n", __func__); - return -EINVAL; - } - - /* key offset */ - if ((params->key_offset & 0x7) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid key offset\n", __func__); - return -EINVAL; - } - /* f_hash */ if (params->f_hash == NULL) { RTE_LOG(ERR, TABLE, "%s: f_hash function pointer is NULL\n", @@ -309,18 +297,6 @@ check_params_create_ext(struct rte_table_hash_key32_ext_params *params) { return -EINVAL; } - /* signature offset */ - if ((params->signature_offset & 0x3) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid signature offset\n", __func__); - return -EINVAL; - } - - /* key offset */ - if ((params->key_offset & 0x7) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid key offset\n", __func__); - return -EINVAL; - } - /* f_hash */ if (params->f_hash == NULL) { RTE_LOG(ERR, TABLE, "%s: f_hash function pointer is NULL\n", diff --git a/lib/librte_table/rte_table_hash_key8.c b/lib/librte_table/rte_table_hash_key8.c index 6803eb2ef7..4dfa3c835e 100644 --- a/lib/librte_table/rte_table_hash_key8.c +++ b/lib/librte_table/rte_table_hash_key8.c @@ -86,18 +86,6 @@ check_params_create_lru(struct rte_table_hash_key8_lru_params *params) { return -EINVAL; } - /* signature offset */ - if ((params->signature_offset & 0x3) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid signature_offset\n", __func__); - return -EINVAL; - } - - /* key offset */ - if ((params->key_offset & 0x7) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid key_offset\n", __func__); - return -EINVAL; - } - /* f_hash */ if (params->f_hash == NULL) { RTE_LOG(ERR, TABLE, "%s: f_hash function pointer is NULL\n", @@ -300,18 +288,6 @@ check_params_create_ext(struct rte_table_hash_key8_ext_params *params) { return -EINVAL; } - /* signature offset */ - if ((params->signature_offset & 0x3) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid signature_offset\n", __func__); - return -EINVAL; - } - - /* key offset */ - if ((params->key_offset & 0x7) != 0) { - RTE_LOG(ERR, TABLE, "%s: invalid key_offset\n", __func__); - return -EINVAL; - } - /* f_hash */ if (params->f_hash == NULL) { RTE_LOG(ERR, TABLE, "%s: f_hash function pointer is NULL\n", diff --git a/lib/librte_table/rte_table_hash_lru.c b/lib/librte_table/rte_table_hash_lru.c index c9a8afd7d4..b5393f0735 100644 --- a/lib/librte_table/rte_table_hash_lru.c +++ b/lib/librte_table/rte_table_hash_lru.c @@ -126,19 +126,6 @@ check_params_create(struct rte_table_hash_lru_params *params) return -EINVAL; } - /* signature offset */ - if ((params->signature_offset & 0x3) != 0) { - RTE_LOG(ERR, TABLE, "%s: signature_offset invalid value\n", - __func__); - return -EINVAL; - } - - /* key offset */ - if ((params->key_offset & 0x7) != 0) { - RTE_LOG(ERR, TABLE, "%s: key_offset invalid value\n", __func__); - return -EINVAL; - } - return 0; } diff --git a/lib/librte_table/rte_table_lpm.c b/lib/librte_table/rte_table_lpm.c index 64c684d03f..3f60672ec4 100644 --- a/lib/librte_table/rte_table_lpm.c +++ b/lib/librte_table/rte_table_lpm.c @@ -87,10 +87,6 @@ rte_table_lpm_create(void *params, int socket_id, uint32_t entry_size) __func__); return NULL; } - if ((p->offset & 0x3) != 0) { - RTE_LOG(ERR, TABLE, "%s: Invalid offset\n", __func__); - return NULL; - } entry_size = RTE_ALIGN(entry_size, sizeof(uint64_t)); diff --git a/lib/librte_table/rte_table_lpm_ipv6.c b/lib/librte_table/rte_table_lpm_ipv6.c index ce4ddc0b04..df83ecf939 100644 --- a/lib/librte_table/rte_table_lpm_ipv6.c +++ b/lib/librte_table/rte_table_lpm_ipv6.c @@ -93,10 +93,6 @@ rte_table_lpm_ipv6_create(void *params, int socket_id, uint32_t entry_size) __func__); return NULL; } - if ((p->offset & 0x3) != 0) { - RTE_LOG(ERR, TABLE, "%s: Invalid offset\n", __func__); - return NULL; - } entry_size = RTE_ALIGN(entry_size, sizeof(uint64_t));