From: "Gaëtan Rivet" <grive@u256.net>
To: "Andrew Rybchenko" <andrew.rybchenko@oktetlabs.ru>,
"Stephen Hemminger" <stephen@networkplumber.org>
Cc: "Thomas Monjalon" <thomas@monjalon.net>, dev@dpdk.org, matan@nvidia.com
Subject: Re: [dpdk-dev] [PATCH 2/2] net/failsafe: fix primary/secondary mutex
Date: Mon, 14 Jun 2021 16:43:40 +0200 [thread overview]
Message-ID: <a84ea056-3831-4541-bd16-40efb522de93@www.fastmail.com> (raw)
In-Reply-To: <be4eed62-73c0-3773-456d-6c6a6275ed97@oktetlabs.ru>
On Wed, Jun 9, 2021, at 12:04, Andrew Rybchenko wrote:
> On 6/8/21 11:48 PM, Stephen Hemminger wrote:
> > On Tue, 8 Jun 2021 18:55:17 +0300
> > Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru> wrote:
> >
> >> On 6/8/21 6:42 PM, Stephen Hemminger wrote:
> >>> On Tue, 8 Jun 2021 11:00:37 +0300
> >>> Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru> wrote:
> >>>
> >>>> On 4/19/21 8:08 PM, Thomas Monjalon wrote:
> >>>>> About the title, better to speak about multi-process,
> >>>>> it is less confusing than primary/secondary.
> >>>>>
> >>>>> 15/03/2021 20:27, Stephen Hemminger:
> >>>>>> Set mutex used in failsafe driver to protect when used by
> >>>>>> both primary and secondary process. Without this fix, the failsafe
> >>>>>> lock is not really locking when there are multiple secondary processes.
> >>>>>>
> >>>>>> Bugzilla ID: 662
> >>>>>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> >>>>>> Fixes: 655fcd68c7d2 ("net/failsafe: fix hotplug races")
> >>>>>> Cc: matan@mellanox.com
> >>>>>
> >>>>> The correct order for above lines is:
> >>>>>
> >>>>> Bugzilla ID: 662
> >>>>> Fixes: 655fcd68c7d2 ("net/failsafe: fix hotplug races")
> >>>>>
> >>>>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> >>>>>
> >>>>>> ---
> >>>>>> --- a/drivers/net/failsafe/failsafe.c
> >>>>>> +++ b/drivers/net/failsafe/failsafe.c
> >>>>>> @@ -140,6 +140,11 @@ fs_mutex_init(struct fs_priv *priv)
> >>>>>> ERROR("Cannot initiate mutex attributes - %s", strerror(ret));
> >>>>>> return ret;
> >>>>>> }
> >>>>>> + /* Allow mutex to protect primary/secondary */
> >>>>>> + ret = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
> >>>>>> + if (ret)
> >>>>>> + ERROR("Cannot set mutex shared - %s", strerror(ret));
> >>>>>
> >>>>> Why not returning an error here?
> >>>>
> >>>> +1
> >>>>
> >>>> I think it would be safer to return an error here.
> >>>
> >>> Ok but it never happens.
> >>>
> >>
> >> May I ask why? 'man pthread_mutexattr_setpshared' says that it
> >> is possible.
> >>
> >
> > The glibc implementation of pthread_mutexattr_setpshared is:
> >
> >
> > int
> > pthread_mutexattr_setpshared (pthread_mutexattr_t *attr, int pshared)
> > {
> > struct pthread_mutexattr *iattr;
> >
> > int err = futex_supports_pshared (pshared);
> > if (err != 0)
> > return err;
> >
> > iattr = (struct pthread_mutexattr *) attr;
> >
> > if (pshared == PTHREAD_PROCESS_PRIVATE)
> > iattr->mutexkind &= ~PTHREAD_MUTEXATTR_FLAG_PSHARED;
> > else
> > iattr->mutexkind |= PTHREAD_MUTEXATTR_FLAG_PSHARED;
> >
> > return 0;
> > }
> >
> > And
> >
> > /* FUTEX_SHARED is always supported by the Linux kernel. */
> > static __always_inline int
> > futex_supports_pshared (int pshared)
> > {
> > if (__glibc_likely (pshared == PTHREAD_PROCESS_PRIVATE))
> > return 0;
> > else if (pshared == PTHREAD_PROCESS_SHARED)
> > return 0;
> > else
> > return EINVAL;
> > }
> >
> >
> > There for the code as written can not return an error.
> > The check was only because someone could report a bogus
> > issue from a broken c library.
> >
>
> Many thanks for detailed description.
> I thought that it is better to follow API
> definition and it is not that hard to check
> return code and handle it. Yes, glibc is not
> the only C library.
>
On principle the API spec should be respected without assuming a specific
implementation.
Another way to think about it is that a future dev having zero knowledge of
this thread, reading this code and checking the POSIX manual, will also need to
check that usual c lib implementations are unlikely to generate an error before
concluding that this code is alright. It should not be necessary.
--
Gaetan Rivet
next prev parent reply other threads:[~2021-06-14 14:45 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-15 19:27 [dpdk-dev] [PATCH 0/2] Mark shared pthread mutex Stephen Hemminger
2021-03-15 19:27 ` [dpdk-dev] [PATCH 1/2] ethdev: make flow API primary/secondary process safe Stephen Hemminger
2021-03-16 23:48 ` Suanming Mou
2021-03-17 0:13 ` Stephen Hemminger
2021-03-17 0:32 ` Suanming Mou
2021-04-14 13:06 ` Ferruh Yigit
2021-04-15 2:55 ` Suanming Mou
2021-04-15 3:17 ` Stephen Hemminger
2021-04-15 7:42 ` Ferruh Yigit
2021-04-15 20:04 ` Stephen Hemminger
2021-04-16 0:57 ` Suanming Mou
2021-04-16 3:19 ` Ajit Khaparde
2021-04-16 1:41 ` fengchengwen
2021-04-16 8:12 ` Ferruh Yigit
2021-04-16 8:18 ` Ferruh Yigit
2021-04-19 17:14 ` Thomas Monjalon
2021-04-19 17:45 ` Stephen Hemminger
2021-04-19 18:09 ` Thomas Monjalon
2021-06-08 8:07 ` Andrew Rybchenko
2021-03-15 19:27 ` [dpdk-dev] [PATCH 2/2] net/failsafe: fix primary/secondary mutex Stephen Hemminger
2021-04-14 13:10 ` Ferruh Yigit
2021-04-16 8:19 ` Ferruh Yigit
2021-04-19 17:08 ` Thomas Monjalon
2021-06-08 8:00 ` Andrew Rybchenko
2021-06-08 15:42 ` Stephen Hemminger
2021-06-08 15:55 ` Andrew Rybchenko
2021-06-08 20:48 ` Stephen Hemminger
2021-06-09 10:04 ` Andrew Rybchenko
2021-06-14 14:43 ` Gaëtan Rivet [this message]
2022-10-17 10:40 ` [External] : " Madhuker Mythri
2021-03-15 19:45 ` [dpdk-dev] [PATCH 0/2] Mark shared pthread mutex Stephen Hemminger
2021-03-16 16:28 ` Stephen Hemminger
2021-04-16 8:25 ` Ferruh Yigit
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=a84ea056-3831-4541-bd16-40efb522de93@www.fastmail.com \
--to=grive@u256.net \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=matan@nvidia.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.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).