From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
qemu-devel@nongnu.org, patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH 1/5] hw/net/stellaris_enet: Restructure tx_fifo code to avoid buffer overrun
Date: Tue, 1 Apr 2014 18:00:51 +0100 [thread overview]
Message-ID: <20140401170051.GQ2411@work-vm> (raw)
In-Reply-To: <1396371187-8567-2-git-send-email-peter.maydell@linaro.org>
* Peter Maydell (peter.maydell@linaro.org) wrote:
> The current tx_fifo code has a corner case where the guest can overrun
> the fifo buffer: if automatic CRCs are disabled we allow the guest to write
> the CRC word even if there isn't actually space for it in the FIFO.
> The datasheet is unclear about exactly how the hardware deals with this
> situation; the most plausible answer seems to be that the CRC word is
> just lost.
>
> Implement this fix by separating the "can we stuff another word in the
> FIFO" logic from the "should we transmit the packet now" check. This
> also moves us closer to the real hardware, which has a number of ways
> it can be configured to trigger sending the packet, some of which we
> don't implement.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> hw/net/stellaris_enet.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c
> index d04e6a4..bd844cd 100644
> --- a/hw/net/stellaris_enet.c
> +++ b/hw/net/stellaris_enet.c
> @@ -253,10 +253,12 @@ static void stellaris_enet_write(void *opaque, hwaddr offset,
> s->tx_fifo[s->tx_fifo_len++] = value >> 24;
> }
> } else {
> - s->tx_fifo[s->tx_fifo_len++] = value;
> - s->tx_fifo[s->tx_fifo_len++] = value >> 8;
> - s->tx_fifo[s->tx_fifo_len++] = value >> 16;
> - s->tx_fifo[s->tx_fifo_len++] = value >> 24;
> + if (s->tx_fifo_len + 4 <= ARRAY_SIZE(s->tx_fifo)) {
> + s->tx_fifo[s->tx_fifo_len++] = value;
> + s->tx_fifo[s->tx_fifo_len++] = value >> 8;
> + s->tx_fifo[s->tx_fifo_len++] = value >> 16;
> + s->tx_fifo[s->tx_fifo_len++] = value >> 24;
> + }
> if (s->tx_fifo_len >= s->tx_frame_len) {
> /* We don't implement explicit CRC, so just chop it off. */
> if ((s->tctl & SE_TCTL_CRC) == 0)
> --
> 1.9.0
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2014-04-01 17:01 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-01 16:53 [Qemu-devel] [PATCH 0/5] stellaris_enet: overhaul TX handling Peter Maydell
2014-04-01 16:53 ` [Qemu-devel] [PATCH 1/5] hw/net/stellaris_enet: Restructure tx_fifo code to avoid buffer overrun Peter Maydell
2014-04-01 17:00 ` Dr. David Alan Gilbert [this message]
2014-04-01 16:53 ` [Qemu-devel] [PATCH 2/5] hw/net/stellaris_enet: Correct handling of packet padding Peter Maydell
2014-04-01 17:01 ` Dr. David Alan Gilbert
2014-04-01 16:53 ` [Qemu-devel] [PATCH 3/5] hw/net/stellaris_enet: Rewrite tx fifo handling code Peter Maydell
2014-04-01 17:26 ` Dr. David Alan Gilbert
2014-04-01 17:29 ` Peter Maydell
2014-04-01 17:35 ` Dr. David Alan Gilbert
2014-04-01 17:45 ` Dr. David Alan Gilbert
2014-04-01 17:48 ` Peter Maydell
2014-04-01 17:51 ` Dr. David Alan Gilbert
2014-04-01 16:53 ` [Qemu-devel] [PATCH 4/5] hw/net/stellaris_enet: Correctly implement the TR and THR registers Peter Maydell
2014-04-01 17:44 ` Dr. David Alan Gilbert
2014-04-01 18:08 ` Peter Maydell
2014-04-01 16:53 ` [Qemu-devel] [PATCH 5/5] hw/net/stellaris_enet: Fix debug format strings Peter Maydell
2014-04-01 17:47 ` Dr. David Alan Gilbert
2014-04-01 17:04 ` [Qemu-devel] [PATCH 0/5] stellaris_enet: overhaul TX handling 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=20140401170051.GQ2411@work-vm \
--to=dgilbert@redhat.com \
--cc=mst@redhat.com \
--cc=patches@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).