From patchwork Wed Jun 5 01:08:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 54372 X-Patchwork-Delegate: ferruh.yigit@amd.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 76D8E1B9B1; Wed, 5 Jun 2019 03:09:08 +0200 (CEST) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id 4D5711B96E for ; Wed, 5 Jun 2019 03:09:02 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id t16so4962237pfe.11 for ; Tue, 04 Jun 2019 18:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CCKgU1fyOL7NcaEBiG1gbUG5kxFXLa91ltl+8qLR0Jw=; b=rYWBG4HN4yTmCDznob+58c+u+4lfKUs+Mq5IV0zX01PLQ2lizaCVLgRZyHEdkuLuqp ElPp4ccQHFMWCAP3RwFQQWnjaK5H9iJ0+dLI5VaA26/SnzPSZ+8+UBO1aJU2trt6/XOT lXpS9t13ZmOrYup5NfraVt1JKpjodd/nnYUtqE6P8wmQOhJgXPNQi0sViZax3KCGnqur YHoxpyKV5VLsNocPOBm+W3b+7+uLdBLcTn4jayCeKNgnP8Il2l/Swler2PBY5erfZ7nL yfyYpxzp4cpwem7rX4cp/RsKLe+XDAmsnq/Pz77wXg84jJrrb1gdTqmTYj1xccGyhz7P AaDQ== 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:mime-version:content-transfer-encoding; bh=CCKgU1fyOL7NcaEBiG1gbUG5kxFXLa91ltl+8qLR0Jw=; b=MftyRUruyVTP1EWn0ekwqQX672IeRdagbnggbMUBbfTnwg8XAZot5sHvFdFwErLl/M jT5FKAzzQU9ub7fWzqY90fKOUkYt5cmmCpPdcAMcWZ2DbXYB36L/c+o/JCV4gVVA2GcR lgByvm/t7ZP29v5DT8VvOW4uBxmCsL4fRvmHuM0eL1mvACFTqK7piIkLdd0DrL9ELvaW p6nudfXqW3Mo4W89NSfzRnb96MSTbNxWozR7Wq+fxJ2CwfjlB9aXxz+NJAvMrJw2aSOZ x/E+nq4kiW3a/36X+SJw0AnaqX1qRv5V9J4vvZEY3zKF7BC8GkIheM+pDToxyOnzXGon UyuA== X-Gm-Message-State: APjAAAWRKOQuYg8b7KEVj1fS+frLIrZTBs0EYHB9azUcswK7OgSvgM4x 7RdKO7grh9vTz0sqrpD500V//YzZm94= X-Google-Smtp-Source: APXvYqzXPEh8IFX7IRYvYnDTy2zAKw0hz6k98TQr6Ca0OVE7w4Tj8/4HimxLmRVBu/Az+/rIQujftQ== X-Received: by 2002:a17:90a:1706:: with SMTP id z6mr19425256pjd.108.1559696941204; Tue, 04 Jun 2019 18:09:01 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 12sm8645936pfi.60.2019.06.04.18.09.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 18:09:00 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Bruce Richardson , Stephen Hemminger Date: Tue, 4 Jun 2019 18:08:51 -0700 Message-Id: <20190605010852.28395-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190605010852.28395-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190605010852.28395-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 5/6] net/ether: mark ethernet addresses as being 2-byte aligned 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" From: Bruce Richardson When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them. .../include/rte_ether.h:149:2: warning: converting a packed ‘const struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member] 149 | const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea; | ^~~~~ Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations. Signed-off-by: Bruce Richardson Signed-off-by: Stephen Hemminger Reviewed-by: Andrew Rybchenko --- lib/librte_net/rte_ether.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index feb35a33c94b..d7b76ddf63eb 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -58,7 +58,8 @@ extern "C" { * See http://standards.ieee.org/regauth/groupmac/tutorial.html */ struct rte_ether_addr { - uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */ + uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2); + /**< Addr bytes in tx order */ } __attribute__((__packed__)); #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */ @@ -81,8 +82,8 @@ struct rte_ether_addr { static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, const struct rte_ether_addr *ea2) { - const unaligned_uint16_t *w1 = (const uint16_t *)ea1; - const unaligned_uint16_t *w2 = (const uint16_t *)ea2; + const uint16_t *w1 = (const uint16_t *)ea1; + const uint16_t *w2 = (const uint16_t *)ea2; return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0; } @@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, */ static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea) { - const unaligned_uint16_t *w = (const uint16_t *)ea; + const uint16_t *w = (const uint16_t *)ea; return (w[0] | w[1] | w[2]) == 0; } @@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea) */ static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea) { - const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea; + const uint16_t *ea_words = (const uint16_t *)ea; return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF && ea_words[2] == 0xFFFF);