qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Patrick Venture <venture@google.com>,
	peter.maydell@linaro.org, clg@kaod.org,
	steven_lee@aspeedtech.com, leetroy@gmail.com,
	jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au,
	joel@jms.id.au
Cc: jasowang@redhat.com, qemu-arm@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH] hw/net: ftgmac100: copy eth_hdr for alignment
Date: Mon, 3 Mar 2025 12:17:32 +0100	[thread overview]
Message-ID: <0256b5de-12f9-4c13-bbff-e7fcf593f542@linaro.org> (raw)
In-Reply-To: <20250227154253.1653236-1-venture@google.com>

Hi Patrick,

On 27/2/25 16:42, Patrick Venture wrote:
> eth_hdr requires 2 byte alignment
> 
> Signed-off-by: Patrick Venture <venture@google.com>
> ---
>   hw/net/ftgmac100.c | 15 ++++++++++++---
>   1 file changed, 12 insertions(+), 3 deletions(-)


> @@ -1028,6 +1032,7 @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,
>   {
>       FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc));
>       FTGMAC100Desc bd;
> +    struct eth_header eth_hdr = {};
>       uint32_t flags = 0;
>       uint64_t addr;
>       uint32_t crc;
> @@ -1036,7 +1041,11 @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,
>       uint32_t buf_len;
>       size_t size = len;
>       uint32_t first = FTGMAC100_RXDES0_FRS;
> -    uint16_t proto = be16_to_cpu(PKT_GET_ETH_HDR(buf)->h_proto);

The LD/ST API deals with unaligned fields, would that help?

     uint16_t proto = lduw_be_p(&PKT_GET_ETH_HDR(buf)->h_proto);

> +    uint16_t proto;
> +
> +    memcpy(&eth_hdr, PKT_GET_ETH_HDR(buf),
> +           (sizeof(eth_hdr) > len) ? len : sizeof(eth_hdr));
> +    proto = be16_to_cpu(eth_hdr.h_proto);
>       int max_frame_size = ftgmac100_max_frame_size(s, proto);



  parent reply	other threads:[~2025-03-03 11:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-27 15:42 [PATCH] hw/net: ftgmac100: copy eth_hdr for alignment Patrick Venture
2025-02-28  5:54 ` Andrew Jeffery
2025-02-28 18:18   ` Patrick Venture
2025-03-03 11:17 ` Philippe Mathieu-Daudé [this message]
2025-03-03 11:46   ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0256b5de-12f9-4c13-bbff-e7fcf593f542@linaro.org \
    --to=philmd@linaro.org \
    --cc=andrew@codeconstruct.com.au \
    --cc=clg@kaod.org \
    --cc=jamin_lin@aspeedtech.com \
    --cc=jasowang@redhat.com \
    --cc=joel@jms.id.au \
    --cc=leetroy@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=steven_lee@aspeedtech.com \
    --cc=venture@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).