From: Stephen Hemminger <stephen@networkplumber.org>
To: Don Provan <dprovan@bivio.net>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH] eth_dev: make ether dev_ops const
Date: Tue, 7 Apr 2015 11:46:04 -0700 [thread overview]
Message-ID: <CAOaVG17SciajyWdWNcZbodHDKZ_peRpfC25yUvYh4Cf6Y6=YyQ@mail.gmail.com> (raw)
In-Reply-To: <CY1PR0101MB0987C29CCC2BC22B33C77A5AA0FD0@CY1PR0101MB0987.prod.exchangelabs.com>
On Tue, Apr 7, 2015 at 10:21 AM, Don Provan <dprovan@bivio.net> wrote:
> -----Original Message-----
> >From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> >Sent: Monday, April 06, 2015 11:05 AM
> >To: dev@dpdk.org
> >Subject: [dpdk-dev] [PATCH] eth_dev: make ether dev_ops const
> >
> >Ethernet device function tables should be immutable for correctness and
> security. Special case for the test code driver.
> ...
> >diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c index
> f163562..f579558 100644
> >--- a/app/test/virtual_pmd.c
> >+++ b/app/test/virtual_pmd.c
> ...
> >+/* This driver uses private mutable eth_dev_ops for each
> >+ * instance so it is safe to override const here.
> >+ */
> >+#pragma GCC diagnostic push
> >+#pragma GCC diagnostic ignored "-Wcast-qual"
> > void
> > virtual_ethdev_start_fn_set_success(uint8_t port_id, uint8_t success) {
> > struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
> >+ struct eth_dev_ops *dev_ops
> >+ = (struct eth_dev_ops *) vrtl_eth_dev->dev_ops;
> ...
>
> If this is really safe, then you should be able to accomplish it
> without disabling a bunch of protection. I suggest adding a
> pointer that isn't const to the private data block and adjusting
> the allocated dispatch table through that instead of through
> the pointer to the immutable dispatch table you've established
> in struct rte_eth_dev. That reinforces the fact that modifying
> the dispatch table is a private matter within the driver while
> showing structurally exactly why it's safe to change it.
>
> And it's not nearly so ugly.
>
> -don provan
> dprovan@bivio.net
>
>
In this case it is safe, but only because this dummy driver used in testing
does non-standard things.
It copies a base template for ops into a allocated area of memory, then
modifies it.
Not the best design, but did not want to hold back the ethernet dev_ops.
Probably the private pointer is a better way.
next prev parent reply other threads:[~2015-04-07 18:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-06 18:04 Stephen Hemminger
2015-04-07 17:21 ` Don Provan
2015-04-07 18:46 ` Stephen Hemminger [this message]
2015-04-08 5:45 ` [dpdk-dev] working with pthreads and Processes in parallel Nissim Nisimov
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='CAOaVG17SciajyWdWNcZbodHDKZ_peRpfC25yUvYh4Cf6Y6=YyQ@mail.gmail.com' \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=dprovan@bivio.net \
/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).