From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>,
Kent Gibson <warthog618@gmail.com>,
Linus Walleij <linus.walleij@linaro.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 07/11] gpiolib: rework the locking mechanism for lineevent kfifo
Date: Thu, 5 Dec 2019 10:31:20 +0100 [thread overview]
Message-ID: <CAMpxmJU-X3JiVZ2+fVq5Y6jipJUkhVSMUyJjFnmjdkny0LRO9Q@mail.gmail.com> (raw)
In-Reply-To: <CAHp75Vf7+XY8rnrbMfMgNO25EHSemjZVUgvFFp+zvj4vvJ1B8g@mail.gmail.com>
śr., 4 gru 2019 o 23:25 Andy Shevchenko <andy.shevchenko@gmail.com> napisał(a):
>
> On Wed, Dec 4, 2019 at 6:01 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> >
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > The read_lock mutex is supposed to prevent collisions between reading
> > and writing to the line event kfifo but it's actually only taken when
> > the events are being read from it.
> >
> > Drop the mutex entirely and reuse the spinlock made available to us in
> > the waitqueue struct. Take the lock whenever the fifo is modified or
> > inspected. Drop the call to kfifo_to_user() and instead first extract
> > the new element from kfifo when the lock is taken and only then pass
> > it on to the user after the spinlock is released.
> >
>
> My comments below.
>
> > + spin_lock(&le->wait.lock);
> > if (!kfifo_is_empty(&le->events))
> > events = EPOLLIN | EPOLLRDNORM;
> > + spin_unlock(&le->wait.lock);
>
> Sound like a candidate to have kfifo_is_empty_spinlocked().
Yeah, I noticed but I thought I'd just add it later separately - it's
always easier to merge self-contained series.
>
>
> > struct lineevent_state *le = filep->private_data;
> > - unsigned int copied;
> > + struct gpioevent_data event;
> > int ret;
>
> > + if (count < sizeof(event))
> > return -EINVAL;
>
> This still has an issue with compatible syscalls. See patch I have
> sent recently.
> I dunno how you see is the better way: a) apply mine and rebase your
> series, or b) otherwise.
> I can do b) if you think it shouldn't be backported.
>
Looking at your patch it seems to me it's best to rebase yours on top
of this one - where I simply do copy_to_user() we can add a special
case for 32-bit user-space. I can try to do this myself for v3 if you
agree.
Bart
> Btw, either way we have a benifits for the following one (I see you
> drop kfifo_to_user() and add event variable on stack).
>
> > + return sizeof(event);
>
> Also see comments in my patch regarding the event handling.
>
> --
> With Best Regards,
> Andy Shevchenko
next prev parent reply other threads:[~2019-12-05 9:31 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-04 15:59 [PATCH v2 00/11] gpiolib: add an ioctl() for monitoring line status changes Bartosz Golaszewski
2019-12-04 15:59 ` [PATCH v2 01/11] gpiolib: use 'unsigned int' instead of 'unsigned' in gpio_set_config() Bartosz Golaszewski
2019-12-04 22:18 ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 02/11] gpiolib: have a single place of calling set_config() Bartosz Golaszewski
2019-12-04 22:18 ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 03/11] gpiolib: convert the type of hwnum to unsigned int in gpiochip_get_desc() Bartosz Golaszewski
2019-12-04 22:19 ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 04/11] gpiolib: use gpiochip_get_desc() in linehandle_create() Bartosz Golaszewski
2019-12-04 22:20 ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 05/11] gpiolib: use gpiochip_get_desc() in lineevent_create() Bartosz Golaszewski
2019-12-04 22:20 ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 06/11] gpiolib: use gpiochip_get_desc() in gpio_ioctl() Bartosz Golaszewski
2019-12-04 16:25 ` Rainer Sickinger
2019-12-04 22:21 ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 07/11] gpiolib: rework the locking mechanism for lineevent kfifo Bartosz Golaszewski
2019-12-04 22:25 ` Andy Shevchenko
2019-12-05 9:31 ` Bartosz Golaszewski [this message]
2019-12-05 10:22 ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 08/11] gpiolib: emit a debug message when adding events to a full kfifo Bartosz Golaszewski
2019-12-04 22:28 ` Andy Shevchenko
2019-12-19 16:22 ` Bartosz Golaszewski
2019-12-04 15:59 ` [PATCH v2 09/11] gpiolib: provide a dedicated function for setting lineinfo Bartosz Golaszewski
2019-12-04 22:30 ` Andy Shevchenko
2019-12-05 9:28 ` Bartosz Golaszewski
2019-12-05 10:20 ` Andy Shevchenko
2019-12-05 13:45 ` Bartosz Golaszewski
2019-12-05 16:47 ` Andy Shevchenko
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=CAMpxmJU-X3JiVZ2+fVq5Y6jipJUkhVSMUyJjFnmjdkny0LRO9Q@mail.gmail.com \
--to=bgolaszewski@baylibre.com \
--cc=andy.shevchenko@gmail.com \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=warthog618@gmail.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).