From: David Miller <davem@davemloft.net>
To: o.freyermuth@googlemail.com
Cc: romieu@fr.zoreil.com, netdev@vger.kernel.org
Subject: Re: Memory corruption with r8169 across several device revisions and kernels
Date: Tue, 23 Jan 2018 10:28:23 -0500 (EST) [thread overview]
Message-ID: <20180123.102823.1267642153979326760.davem@davemloft.net> (raw)
In-Reply-To: <3ceebc43-6baf-2b4c-af10-70522e97385e@googlemail.com>
From: Oliver Freyermuth <o.freyermuth@googlemail.com>
Date: Mon, 22 Jan 2018 23:55:58 +0100
> Checking through the driver sources, I find rtnl_link_stats64 can
> not be the culprit, since it has rx_packets and only after
> tx_packets. However, struct rtl8169_counters looks like:
>
> struct rtl8169_counters {
> __le64 tx_packets;
> __le64 rx_packets;
> __le64 tx_errors;
> __le32 rx_errors;
> __le16 rx_missed;
> __le16 align_errors;
> __le32 tx_one_collision;
> __le32 tx_multi_collision;
> __le64 rx_unicast;
> __le64 rx_broadcast;
> __le32 rx_multicast;
> __le16 tx_aborted;
> __le16 tx_underun;
> };
>
> This looks like it could very well match the structure found in
> memory, so something would be broken related to rtl8169_do_counters,
> in the DMA transfer.
>
> Does this help - can I provide more info? I get the feeling this
> affects many tens of thousands of systems and just has been hidden
> due to network stats being read rarely...
Looking at how these DMA counters are handled, there appears to be a
requirement that the memory buffer is 64-byte aligned.
This is because the low bits in the counter address register are used
for various commands, for example:
/* ResetCounterCommand */
CounterReset = 0x1,
/* DumpCounterCommand */
CounterDump = 0x8,
Looking at the FreeBSD driver, the requirement seems to be 64-bytes of
alignment. (see RL_DUMP_ALIGN define)
However, nothing is being done in r8169.c to enforce this alignment at
counter allocation time:
tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters),
&tp->counters_phys_addr,
There is no alignment guaranteed by this allocation interface. On a
lot of platforms you get PAGE_SIZE aligned buffers, but this is not
a universal thing at all.
Therefore the driver needs to allocate "size + (64 - 1)" bytes and do
the 64-byte alignment of the CPU pointer and the DMA address by hand.
next prev parent reply other threads:[~2018-01-23 15:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-20 20:18 Memory corruption with r8169 across several device revisions and kernels Oliver Freyermuth
2018-01-21 20:48 ` Francois Romieu
2018-01-21 20:50 ` Oliver Freyermuth
2018-01-22 0:09 ` Francois Romieu
2018-01-22 0:44 ` Oliver Freyermuth
2018-01-22 22:55 ` Oliver Freyermuth
2018-01-23 15:28 ` David Miller [this message]
2018-01-23 15:47 ` Oliver Freyermuth
2018-01-24 5:31 ` Andreas Hartmann
2018-01-24 7:05 ` Andreas Hartmann
2018-01-23 22:13 ` Francois Romieu
2018-01-24 1:21 ` Oliver Freyermuth
2018-01-24 1:33 ` David Miller
2018-01-26 0:53 ` [PATCH net 1/1] r8169: fix memory corruption on retrieval of hardware statistics Francois Romieu
2018-01-26 2:34 ` David Miller
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=20180123.102823.1267642153979326760.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=o.freyermuth@googlemail.com \
--cc=romieu@fr.zoreil.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).