Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Jubran, Samih" <sameehj@amazon.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"Woodhouse, David" <dwmw@amazon.co.uk>,
"Machulsky, Zorik" <zorik@amazon.com>,
"Matushevsky, Alexander" <matua@amazon.com>,
"Bshara, Saeed" <saeedb@amazon.com>,
"Wilson, Matt" <msw@amazon.com>,
"Liguori, Anthony" <aliguori@amazon.com>,
"Bshara, Nafea" <nafea@amazon.com>,
"Tzalik, Guy" <gtzalik@amazon.com>,
"Belgazal, Netanel" <netanel@amazon.com>,
"Saidi, Ali" <alisaidi@amazon.com>,
"Herrenschmidt, Benjamin" <benh@amazon.com>,
"Kiyanovski, Arthur" <akiyano@amazon.com>,
"Dagan, Noam" <ndagan@amazon.com>
Subject: RE: [PATCH V2 net-next 1/4] net: ena: ethtool: use unsigned long for pointer arithmetics
Date: Thu, 20 Aug 2020 12:13:15 +0000 [thread overview]
Message-ID: <91c86d46b724411d9f788396816be30d@EX13D11EUB002.ant.amazon.com> (raw)
In-Reply-To: <20200819141716.GE2403519@lunn.ch>
> -----Original Message-----
> From: Andrew Lunn <andrew@lunn.ch>
> Sent: Wednesday, August 19, 2020 5:17 PM
> To: Jubran, Samih <sameehj@amazon.com>
> Cc: davem@davemloft.net; netdev@vger.kernel.org; Woodhouse, David
> <dwmw@amazon.co.uk>; Machulsky, Zorik <zorik@amazon.com>;
> Matushevsky, Alexander <matua@amazon.com>; Bshara, Saeed
> <saeedb@amazon.com>; Wilson, Matt <msw@amazon.com>; Liguori,
> Anthony <aliguori@amazon.com>; Bshara, Nafea <nafea@amazon.com>;
> Tzalik, Guy <gtzalik@amazon.com>; Belgazal, Netanel
> <netanel@amazon.com>; Saidi, Ali <alisaidi@amazon.com>; Herrenschmidt,
> Benjamin <benh@amazon.com>; Kiyanovski, Arthur
> <akiyano@amazon.com>; Dagan, Noam <ndagan@amazon.com>
> Subject: RE: [EXTERNAL] [PATCH V2 net-next 1/4] net: ena: ethtool: use
> unsigned long for pointer arithmetics
>
> CAUTION: This email originated from outside of the organization. Do not click
> links or open attachments unless you can confirm the sender and know the
> content is safe.
>
>
>
> On Wed, Aug 19, 2020 at 01:43:46PM +0000, sameehj@amazon.com wrote:
> > From: Sameeh Jubran <sameehj@amazon.com>
> >
> > unsigned long is the type for doing maths on pointers.
>
> Maths on pointers is perfectly valid. The real issue here is you have all your
> types mixed up.
The stat_offset field has the bytes from the start of the struct, the math is perfectly valid IMO¸
I have also went for the extra step and tested it using prints.
>
> > - ptr = (u64 *)((uintptr_t)&ring->tx_stats +
> > - (uintptr_t)ena_stats->stat_offset);
> > + ptr = (u64 *)((unsigned long)&ring->tx_stats +
> > + ena_stats->stat_offset);
>
> struct ena_ring {
> ...
> union {
> struct ena_stats_tx tx_stats;
> struct ena_stats_rx rx_stats;
> };
>
> struct ena_stats_tx {
> u64 cnt;
> u64 bytes;
> u64 queue_stop;
> u64 prepare_ctx_err;
> u64 queue_wakeup;
> ...
> }
>
> &ring->tx_stats will give you a struct *ena_stats_tx. Arithmetic on that,
> adding 1 for example, takes you forward a full ena_stats_tx structure. Not
> what you want.
>
> &ring->tx_stats.cnt however, will give you a u64 *. Adding 1 to that will give
> you bytes, etc.
If I understand you well, the alternative approach you are suggesting is:
ptr = &ring->tx_stats.cnt + ena_stats->stat_offset;
of course we need to convert the stat_offset field to be in 8 bytes resolution instead.
This approach has a potential bug hidden in it. If in the future
someone decides to expand the "ena_stats_tx" struct and add a field preceding cnt,
cnt will no longer be the beginning of the struct, which will cause a bug."
Therefore, if you have another way to do this, please share it. Otherwise I'd
rather leave this code as it is for the sake of robustness.
>
> Andrew
next prev parent reply other threads:[~2020-08-20 12:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-19 13:43 [PATCH V2 net-next 0/4] Enhance current features in ena driver sameehj
2020-08-19 13:43 ` [PATCH V2 net-next 1/4] net: ena: ethtool: use unsigned long for pointer arithmetics sameehj
2020-08-19 14:17 ` Andrew Lunn
2020-08-20 12:13 ` Jubran, Samih [this message]
2020-08-26 15:36 ` Maciej Fijalkowski
2020-09-06 10:47 ` Shay Agroskin
2020-09-06 16:45 ` Jakub Kicinski
2020-08-26 10:48 ` Jubran, Samih
2020-08-19 13:43 ` [PATCH V2 net-next 2/4] net: ena: ethtool: Add new device statistics sameehj
2020-08-19 14:18 ` Andrew Lunn
2020-08-19 13:43 ` [PATCH V2 net-next 3/4] net: ena: ethtool: add stats printing to XDP queues sameehj
2020-08-19 13:43 ` [PATCH V2 net-next 4/4] net: ena: xdp: add queue counters for xdp actions sameehj
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=91c86d46b724411d9f788396816be30d@EX13D11EUB002.ant.amazon.com \
--to=sameehj@amazon.com \
--cc=akiyano@amazon.com \
--cc=aliguori@amazon.com \
--cc=alisaidi@amazon.com \
--cc=andrew@lunn.ch \
--cc=benh@amazon.com \
--cc=davem@davemloft.net \
--cc=dwmw@amazon.co.uk \
--cc=gtzalik@amazon.com \
--cc=matua@amazon.com \
--cc=msw@amazon.com \
--cc=nafea@amazon.com \
--cc=ndagan@amazon.com \
--cc=netanel@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=saeedb@amazon.com \
--cc=zorik@amazon.com \
--subject='RE: [PATCH V2 net-next 1/4] net: ena: ethtool: use unsigned long for pointer arithmetics' \
/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
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).