All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Jiri Kosina <jikos@kernel.org>
Cc: Marcel Holtmann <marcel@holtmann.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>
Subject: Re: [GIT PULL] HID fixes
Date: Thu, 9 Jan 2020 15:36:13 -0800	[thread overview]
Message-ID: <CAHk-=wh_-q=MPtYmcb4gUHtQ2M96BVrzoDo3pauU-Ps9Q5uPtg@mail.gmail.com> (raw)
In-Reply-To: <nycvar.YFH.7.76.2001092137460.31058@cbobk.fhfr.pm>

On Thu, Jan 9, 2020 at 12:38 PM Jiri Kosina <jikos@kernel.org> wrote:
>
> From: Jiri Kosina <jkosina@suse.cz>
> Subject: [PATCH] HID: hidraw, uhid: Always report EPOLLOUT

This looks fine, and certainly fixes the immediate problem.

However, this part could still be maybe be improved on:

>  static __poll_t hidraw_poll(struct file *file, poll_table *wait)
>  {
>         struct hidraw_list *list = file->private_data;
> +       __poll_t mask = EPOLLOUT | EPOLLWRNORM; /* hidraw is always writable */
>
>         poll_wait(file, &list->hidraw->wait, wait);
>         if (list->head != list->tail)
> -               return EPOLLIN | EPOLLRDNORM;
> +               mask |= EPOLLIN | EPOLLRDNORM;
>         if (!list->hidraw->exist)
>                 return EPOLLERR | EPOLLHUP;
> -       return EPOLLOUT | EPOLLWRNORM;
> +       return mask;
>  }

Notice the error condition.

I didn't actually _check_ what happens for errors, but *usually* error
conditions mean that

 (a) if there is data to be read, that is done before the error anyway

 (b) that even if there isn't data, the thing is "readable" and
"writable" in the sense that the op will return immediately (with an
error)

 (c) and most importantly - people may not be actually waiting for
EPOLLERR / EPOLLHUP at all.

Now, for "select()" we actually always turn EPOLLERR into "it's
readable _and_ writable". So if a user program uses "select()" to poll
for something, it will see it as being ready for IO in the error
condition.

But if somebody actually uses poll(), and asks for "let me know when
it is either readable or writable", look at what  happens above if
there is a pending error.

You'll basically tell the user that it's neither readable nor
writable, even if you otherwise would have set "EPOLLIN" in the mask.

So at a minimum, please do

          if (!list->hidraw->exist)
                  mask |= EPOLLERR | EPOLLHUP;

but quite possibly it may be a good idea to consider error conditions
to also mean EPOLLIN | EPOLLOUT, since _presumably_ that error will
also cause read/write to return immediately.

But again, I didn't actually verify that last part.

The exact semantics of EPOLLERR and EPOLLHUP really aren't 100% clear.
Should they set EPOLLIN and EPOLLOUT too - there may not be any data,
but at least a read or write won't block? Maybe? So that last
suggestion is questionable, but doing the "mask |=" part really is
unquestionably a better idea, since at least you don't want an error
to _hide_ existing data that is readable.

Now, good source code presumably notices EPOLLERR and handles it. So
it _shouldn't_ matter what the kernel does if an error occurs. I
haven't checked what people _actually_ do, tnough. I worry sometimes
that user space just looks at EPOLLIN sees it not being set, and gets
stuck in a busy loop polling in case of errors.

And since errors presumably don't actually happen much in real life,
it might not get a lot of coverage.

                 Linus

  reply	other threads:[~2020-01-09 23:36 UTC|newest]

Thread overview: 113+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-09 14:23 [GIT PULL] HID fixes Jiri Kosina
2020-01-09 19:14 ` Linus Torvalds
2020-01-09 19:25   ` Dmitry Torokhov
2020-01-09 19:37   ` Jiri Kosina
2020-01-09 20:38     ` Jiri Kosina
2020-01-09 23:36       ` Linus Torvalds [this message]
2020-01-09 23:41         ` Linus Torvalds
2020-01-10 14:31           ` Jiri Kosina
2020-01-09 19:15 ` pr-tracker-bot
  -- strict thread matches above, loose matches on Subject: below --
2024-02-15 12:38 Jiri Kosina
2024-02-15 19:50 ` pr-tracker-bot
2023-12-12 22:51 Jiri Kosina
2023-12-13  1:21 ` pr-tracker-bot
2023-11-23 19:22 Jiri Kosina
2023-11-24  1:51 ` pr-tracker-bot
2023-10-11 12:00 Benjamin Tissoires
2023-10-11 20:58 ` pr-tracker-bot
2023-10-05 20:41 Jiri Kosina
2023-10-06  3:50 ` pr-tracker-bot
2023-07-11 13:59 Benjamin Tissoires
2023-07-12 23:28 ` pr-tracker-bot
2023-06-01 10:27 Jiri Kosina
2023-06-01 21:15 ` pr-tracker-bot
2023-04-12 22:03 Jiri Kosina
2023-04-13  0:44 ` pr-tracker-bot
2023-03-09 15:07 Benjamin Tissoires
2023-03-09 19:07 ` pr-tracker-bot
2023-02-09 14:31 Benjamin Tissoires
2023-02-09 18:10 ` pr-tracker-bot
2023-01-18 20:17 Jiri Kosina
2023-01-18 22:47 ` pr-tracker-bot
2022-12-21 15:18 Benjamin Tissoires
2022-12-21 17:53 ` pr-tracker-bot
2022-11-11 10:04 Jiri Kosina
2022-11-11 18:03 ` pr-tracker-bot
2022-10-21 12:17 Benjamin Tissoires
2022-10-22  1:28 ` pr-tracker-bot
2022-08-31 10:54 Jiri Kosina
2022-08-31 17:20 ` pr-tracker-bot
2022-03-09 10:42 Jiri Kosina
2022-03-09 22:16 ` pr-tracker-bot
2022-02-15 15:35 Jiri Kosina
2022-02-15 19:19 ` pr-tracker-bot
2022-01-21 14:17 Jiri Kosina
2022-01-21 14:27 ` pr-tracker-bot
2021-12-21 14:40 Jiri Kosina
2021-12-21 17:39 ` pr-tracker-bot
2021-12-09 10:15 Jiri Kosina
2021-12-09 19:35 ` pr-tracker-bot
2021-11-24  7:10 Jiri Kosina
2021-11-24 18:31 ` pr-tracker-bot
2021-09-27 13:54 Jiri Kosina
2021-09-27 17:25 ` pr-tracker-bot
2021-07-30 12:06 Jiri Kosina
2021-07-30 18:11 ` pr-tracker-bot
2021-06-01 21:58 Jiri Kosina
2021-06-02  3:58 ` pr-tracker-bot
2021-04-15 13:51 Jiri Kosina
2021-04-15 18:15 ` pr-tracker-bot
2021-01-28  8:38 Jiri Kosina
2021-01-28 18:16 ` pr-tracker-bot
2021-01-14 12:33 Jiri Kosina
2021-01-14 21:55 ` pr-tracker-bot
2020-11-22 21:18 Jiri Kosina
2020-11-22 22:40 ` pr-tracker-bot
2020-09-02 18:58 Jiri Kosina
2020-09-02 20:08 ` pr-tracker-bot
2020-08-25  8:14 Jiri Kosina
2020-08-25 19:16 ` pr-tracker-bot
2020-07-17 12:01 Jiri Kosina
2020-07-17 17:40 ` pr-tracker-bot
2020-03-17 13:41 Jiri Kosina
2020-03-17 17:10 ` pr-tracker-bot
2020-02-27 14:46 Jiri Kosina
2020-02-27 19:40 ` pr-tracker-bot
2019-11-07 19:32 Jiri Kosina
2019-11-07 20:00 ` pr-tracker-bot
2019-08-20 12:53 Jiri Kosina
2019-08-20 18:55 ` pr-tracker-bot
2019-08-06 10:59 Jiri Kosina
2019-08-06 18:55 ` pr-tracker-bot
2019-06-27  9:37 Jiri Kosina
2019-06-28  0:45 ` pr-tracker-bot
2019-04-03 13:39 Jiri Kosina
2019-04-03 16:25 ` pr-tracker-bot
2019-01-22  9:46 Jiri Kosina
2019-01-22 18:55 ` pr-tracker-bot
2018-12-10 16:05 Jiri Kosina
2018-12-10 20:20 ` pr-tracker-bot
2018-11-24 20:19 Jiri Kosina
2018-11-24 23:15 ` pr-tracker-bot
2018-11-07 10:31 Jiri Kosina
2018-11-07 17:07 ` Linus Torvalds
2018-10-03  8:55 Jiri Kosina
2018-10-03 11:50 ` Greg Kroah-Hartman
2018-09-11  7:49 Jiri Kosina
2018-07-09 12:54 Jiri Kosina
2018-06-19 12:00 Jiri Kosina
2018-06-20  1:51 ` Linus Torvalds
2018-06-20  4:19   ` Jiri Kosina
2018-06-20  7:06     ` Hans de Goede
2018-06-20  7:12       ` Linus Torvalds
2018-06-20  7:15         ` Jiri Kosina
2018-06-20  7:35           ` Benjamin Tissoires
2018-04-19  8:05 Jiri Kosina
2017-10-12 12:46 Jiri Kosina
2017-10-05  8:58 Jiri Kosina
2017-06-20  9:01 Jiri Kosina
2017-03-31  8:01 Jiri Kosina
2017-01-31 12:13 Jiri Kosina
2017-01-19 13:29 Jiri Kosina
2016-11-07 10:01 Jiri Kosina
2015-02-23 22:37 Jiri Kosina

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='CAHk-=wh_-q=MPtYmcb4gUHtQ2M96BVrzoDo3pauU-Ps9Q5uPtg@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=benjamin.tissoires@redhat.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel@holtmann.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.