From: Olivier Matz <olivier.matz@6wind.com>
To: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
Matan Azrad <matan@nvidia.com>, Ray Kinsella <mdr@ashroe.eu>,
Anatoly Burakov <anatoly.burakov@intel.com>
Subject: Re: [dpdk-dev] [PATCH v4 1/4] mempool: add event callbacks
Date: Fri, 15 Oct 2021 15:40:26 +0200 [thread overview]
Message-ID: <YWmEytDgYTXHl8kg@platinum> (raw)
In-Reply-To: <CH0PR12MB50919D5CDBC88411E4D7147DB9B99@CH0PR12MB5091.namprd12.prod.outlook.com>
On Fri, Oct 15, 2021 at 01:07:42PM +0000, Dmitry Kozlyuk wrote:
[...]
> > > +static void
> > > +mempool_event_callback_invoke(enum rte_mempool_event event,
> > > + struct rte_mempool *mp)
> > > +{
> > > + struct mempool_callback_list *list;
> > > + struct rte_tailq_entry *te;
> > > + void *tmp_te;
> > > +
> > > + rte_mcfg_tailq_read_lock();
> > > + list = RTE_TAILQ_CAST(callback_tailq.head, mempool_callback_list);
> > > + RTE_TAILQ_FOREACH_SAFE(te, list, next, tmp_te) {
> > > + struct mempool_callback *cb = te->data;
> > > + rte_mcfg_tailq_read_unlock();
> > > + cb->func(event, mp, cb->user_data);
> > > + rte_mcfg_tailq_read_lock();
> >
> > I think it is dangerous to unlock the list before invoking the callback.
> > During that time, another thread can remove the next mempool callback, and
> > the next iteration will access to a freed element, causing an undefined
> > behavior.
> >
> > Is it a problem to keep the lock held during the callback invocation?
> >
> > I see that you have a test for this, and that you wrote a comment in the
> > documentation:
> >
> > * rte_mempool_event_callback_register() may be called from within the
> > callback,
> > * but the callbacks registered this way will not be invoked for the same
> > event.
> > * rte_mempool_event_callback_unregister() may only be safely called
> > * to remove the running callback.
> >
> > But is there a use-case for this?
> > If no, I'll tend to say that we can document that it is not allowed to
> > create, free or list mempools or register cb from the callback.
>
> There is no use-case, but I'd argue for releasing the lock.
> This lock is taken by rte_xxx_create() functions in many libraries,
> so the restriction is wider and, worse, it is not strictly limited.
Yes... I honnestly don't understand why every library uses the same
lock rte_mcfg_tailq if the only code that accesses the list is in the
library itself. Maybe I'm missing something.
I have the impression that having only one mempool lock for all usages in
mempool would be simpler and more specific. It would allow to keep the lock held
while invoking the callbacks without blocking accesses to the other libs, and
would also solve the problem described below.
> > [...]
> > > +int
> > > +rte_mempool_event_callback_unregister(rte_mempool_event_callback *func,
> > > + void *user_data)
> > > +{
> > > + struct mempool_callback_list *list;
> > > + struct rte_tailq_entry *te = NULL;
> > > + struct mempool_callback *cb;
> > > + int ret;
> > > +
> > > + if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
> > > + rte_errno = EPERM;
> > > + return -1;
> > > + }
> >
> > The help of the register function says
> > * Callbacks will be invoked in the process that creates the mempool.
>
> BTW, this is another bug, it should be "populates", not "creates".
>
> > So registration is allowed from primary or secondary process. Can't a
> > secondary process destroys the callback it has loaded?
> >
> > > +
> > > + rte_mcfg_mempool_read_lock();
> > > + rte_mcfg_tailq_write_lock();
> >
> > I don't understand why there are 2 locks here.
> >
> > After looking at the code, I think the locking model is already
> > incorrect in current mempool code:
> >
> > rte_mcfg_tailq_write_lock() is used in create and free to protect the
> > access to the mempool tailq
> >
> > rte_mcfg_mempool_write_lock() is used in create(), to protect from
> > concurrent creation (with same name for instance), but I doubt it
> > is absolutly needed, because memzone_reserve is already protected.
> >
> > rte_mcfg_mempool_read_lock() is used in dump functions, but to me
> > it should use rte_mcfg_tailq_read_lock() instead.
> > Currently, doing a dump and a free concurrently can cause a crash
> > because they are not using the same lock.
> >
> > In your case, I suggest to use only one lock to protect the callback
> > list. I think it can be rte_mcfg_tailq_*_lock().
>
> Thanks, I will double-check the locking.
next prev parent reply other threads:[~2021-10-15 13:40 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-18 9:07 [dpdk-dev] [PATCH 0/4] net/mlx5: implicit mempool registration Dmitry Kozlyuk
2021-08-18 9:07 ` [dpdk-dev] [PATCH 1/4] mempool: add event callbacks Dmitry Kozlyuk
2021-10-12 3:12 ` Jerin Jacob
2021-08-18 9:07 ` [dpdk-dev] [PATCH 2/4] mempool: add non-IO flag Dmitry Kozlyuk
2021-08-18 9:07 ` [dpdk-dev] [PATCH 3/4] common/mlx5: add mempool registration facilities Dmitry Kozlyuk
2021-08-18 9:07 ` [dpdk-dev] [PATCH 4/4] net/mlx5: support mempool registration Dmitry Kozlyuk
2021-09-29 14:52 ` [dpdk-dev] [PATCH 0/4] net/mlx5: implicit " dkozlyuk
2021-09-29 14:52 ` [dpdk-dev] [PATCH v2 1/4] mempool: add event callbacks dkozlyuk
2021-10-05 16:34 ` Thomas Monjalon
2021-09-29 14:52 ` [dpdk-dev] [PATCH v2 2/4] mempool: add non-IO flag dkozlyuk
2021-10-05 16:39 ` Thomas Monjalon
2021-10-12 6:06 ` Andrew Rybchenko
2021-09-29 14:52 ` [dpdk-dev] [PATCH v2 3/4] common/mlx5: add mempool registration facilities dkozlyuk
2021-09-29 14:52 ` [dpdk-dev] [PATCH v2 4/4] net/mlx5: support mempool registration dkozlyuk
2021-10-12 0:04 ` [dpdk-dev] [PATCH v3 0/4] net/mlx5: implicit " Dmitry Kozlyuk
2021-10-12 0:04 ` [dpdk-dev] [PATCH v3 1/4] mempool: add event callbacks Dmitry Kozlyuk
2021-10-12 6:33 ` Andrew Rybchenko
2021-10-12 9:37 ` Dmitry Kozlyuk
2021-10-12 9:46 ` Andrew Rybchenko
2021-10-12 0:04 ` [dpdk-dev] [PATCH v3 2/4] mempool: add non-IO flag Dmitry Kozlyuk
2021-10-12 3:37 ` Jerin Jacob
2021-10-12 6:42 ` Andrew Rybchenko
2021-10-12 12:40 ` Dmitry Kozlyuk
2021-10-12 12:53 ` Andrew Rybchenko
2021-10-12 13:11 ` Dmitry Kozlyuk
2021-10-12 0:04 ` [dpdk-dev] [PATCH v3 3/4] common/mlx5: add mempool registration facilities Dmitry Kozlyuk
2021-10-12 0:04 ` [dpdk-dev] [PATCH v3 4/4] net/mlx5: support mempool registration Dmitry Kozlyuk
2021-10-13 11:01 ` [dpdk-dev] [PATCH v4 0/4] net/mlx5: implicit " Dmitry Kozlyuk
2021-10-13 11:01 ` [dpdk-dev] [PATCH v4 1/4] mempool: add event callbacks Dmitry Kozlyuk
2021-10-15 8:52 ` Andrew Rybchenko
2021-10-15 9:13 ` Dmitry Kozlyuk
2021-10-19 13:08 ` Dmitry Kozlyuk
2021-10-15 12:12 ` Olivier Matz
2021-10-15 13:07 ` Dmitry Kozlyuk
2021-10-15 13:40 ` Olivier Matz [this message]
2021-10-13 11:01 ` [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag Dmitry Kozlyuk
2021-10-15 9:01 ` Andrew Rybchenko
2021-10-15 9:18 ` Dmitry Kozlyuk
2021-10-15 9:33 ` Andrew Rybchenko
2021-10-15 9:38 ` Dmitry Kozlyuk
2021-10-15 9:43 ` Olivier Matz
2021-10-15 9:58 ` Dmitry Kozlyuk
2021-10-15 12:11 ` Olivier Matz
2021-10-15 9:25 ` David Marchand
2021-10-15 10:42 ` Dmitry Kozlyuk
2021-10-15 11:41 ` David Marchand
2021-10-15 12:13 ` Olivier Matz
2021-10-15 13:19 ` Olivier Matz
2021-10-15 13:27 ` Dmitry Kozlyuk
2021-10-15 13:43 ` Olivier Matz
2021-10-19 13:08 ` Dmitry Kozlyuk
2021-10-13 11:01 ` [dpdk-dev] [PATCH v4 3/4] common/mlx5: add mempool registration facilities Dmitry Kozlyuk
2021-10-13 11:01 ` [dpdk-dev] [PATCH v4 4/4] net/mlx5: support mempool registration Dmitry Kozlyuk
2021-10-15 16:02 ` [dpdk-dev] [PATCH v5 0/4] net/mlx5: implicit " Dmitry Kozlyuk
2021-10-15 16:02 ` [dpdk-dev] [PATCH v5 1/4] mempool: add event callbacks Dmitry Kozlyuk
2021-10-20 9:29 ` Kinsella, Ray
2021-10-15 16:02 ` [dpdk-dev] [PATCH v5 2/4] mempool: add non-IO flag Dmitry Kozlyuk
2021-10-15 16:02 ` [dpdk-dev] [PATCH v5 3/4] common/mlx5: add mempool registration facilities Dmitry Kozlyuk
2021-10-20 9:30 ` Kinsella, Ray
2021-10-15 16:02 ` [dpdk-dev] [PATCH v5 4/4] net/mlx5: support mempool registration Dmitry Kozlyuk
2021-10-16 20:00 ` [dpdk-dev] [PATCH v6 0/4] net/mlx5: implicit " Dmitry Kozlyuk
2021-10-16 20:00 ` [dpdk-dev] [PATCH v6 1/4] mempool: add event callbacks Dmitry Kozlyuk
2021-10-16 20:00 ` [dpdk-dev] [PATCH v6 2/4] mempool: add non-IO flag Dmitry Kozlyuk
2021-10-16 20:00 ` [dpdk-dev] [PATCH v6 3/4] common/mlx5: add mempool registration facilities Dmitry Kozlyuk
2021-10-16 20:00 ` [dpdk-dev] [PATCH v6 4/4] net/mlx5: support mempool registration Dmitry Kozlyuk
2021-10-18 10:01 ` [dpdk-dev] [PATCH v7 0/4] net/mlx5: implicit " Dmitry Kozlyuk
2021-10-18 10:01 ` [dpdk-dev] [PATCH v7 1/4] mempool: add event callbacks Dmitry Kozlyuk
2021-10-18 10:01 ` [dpdk-dev] [PATCH v7 2/4] mempool: add non-IO flag Dmitry Kozlyuk
2021-10-18 10:01 ` [dpdk-dev] [PATCH v7 3/4] common/mlx5: add mempool registration facilities Dmitry Kozlyuk
2021-10-18 10:01 ` [dpdk-dev] [PATCH v7 4/4] net/mlx5: support mempool registration Dmitry Kozlyuk
2021-10-18 14:40 ` [dpdk-dev] [PATCH v8 0/4] net/mlx5: implicit " Dmitry Kozlyuk
2021-10-18 14:40 ` [dpdk-dev] [PATCH v8 1/4] mempool: add event callbacks Dmitry Kozlyuk
2021-10-18 14:40 ` [dpdk-dev] [PATCH v8 2/4] mempool: add non-IO flag Dmitry Kozlyuk
2021-10-29 3:30 ` Jiang, YuX
2021-10-18 14:40 ` [dpdk-dev] [PATCH v8 3/4] common/mlx5: add mempool registration facilities Dmitry Kozlyuk
2021-10-18 14:40 ` [dpdk-dev] [PATCH v8 4/4] net/mlx5: support mempool registration Dmitry Kozlyuk
2021-10-18 22:43 ` [dpdk-dev] [PATCH v9 0/4] net/mlx5: implicit " Dmitry Kozlyuk
2021-10-18 22:43 ` [dpdk-dev] [PATCH v9 1/4] mempool: add event callbacks Dmitry Kozlyuk
2021-10-18 22:43 ` [dpdk-dev] [PATCH v9 2/4] mempool: add non-IO flag Dmitry Kozlyuk
2021-10-18 22:43 ` [dpdk-dev] [PATCH v9 3/4] common/mlx5: add mempool registration facilities Dmitry Kozlyuk
2021-10-18 22:43 ` [dpdk-dev] [PATCH v9 4/4] net/mlx5: support mempool registration Dmitry Kozlyuk
2021-10-19 14:36 ` [dpdk-dev] [PATCH v9 0/4] net/mlx5: implicit " Thomas Monjalon
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=YWmEytDgYTXHl8kg@platinum \
--to=olivier.matz@6wind.com \
--cc=anatoly.burakov@intel.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=dkozlyuk@nvidia.com \
--cc=matan@nvidia.com \
--cc=mdr@ashroe.eu \
/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).