From: Marius Zachmann <mail@mariuszachmann.de>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Wilken Gottwalt <wilken.gottwalt@posteo.net>,
Aleksandr Mezin <mezin.alexander@gmail.com>,
linux-hwmon@vger.kernel.org, Jiri Kosina <jikos@kernel.org>
Subject: Re: corsair-cpro and hidraw
Date: Fri, 18 Jun 2021 14:22:57 +0200 [thread overview]
Message-ID: <36091016.oId77RFrrH@marius> (raw)
In-Reply-To: <20210618121300.GB1202484@roeck-us.net>
On 18.06.21 at 14:13:00 CEST, Guenter Roeck wrote
> On Fri, Jun 18, 2021 at 09:06:02AM +0200, Marius Zachmann wrote:
> > On 18.06.21 at 08:47:37 CEST, Wilken Gottwalt wrote
> > > On Fri, 18 Jun 2021 08:18:23 +0200
> > > Marius Zachmann <mail@mariuszachmann.de> wrote:
> > >
> > > > On 18.06.21 at 07:45:00 CEST, Wilken Gottwalt wrote
> > > > > On Fri, 18 Jun 2021 05:56:29 +0600
> > > > > Aleksandr Mezin <mezin.alexander@gmail.com> wrote:
> > > > >
> > > > > > I've looked through corsair-psu sources, and I think filtering in
> > > > > > raw_event won't be enough.
> > > > > >
> > > > > > For example, in corsairpsu_request, there are 2 commands, and they
> > > > > > should be executed consecutively:
> > > > > > 1) corsairpsu_usb_cmd(priv, 2, PSU_CMD_SELECT_RAIL, rail, NULL);
> > > > > > 2) corsairpsu_usb_cmd(priv, 3, cmd, 0, data);
> > > > > >
> > > > > > If the userspace will squeeze another PSU_CMD_SELECT_RAIL between (1)
> > > > > > and (2), the driver will get data for a wrong rail (and with the
> > > > > > current code won't even notice it).
> > > > > >
> > > > > > So unless there is a way to "lock" hidraw (and it seems that there
> > > > > > isn't - looking at the code, hidraw calls the low-level hid driver
> > > > > > directly, as far as I understand), it won't work correctly.
> > > > > >
> > > > > > And if a driver can't work correctly with hidraw enabled - maybe it
> > > > > > shouldn't enable hidraw? So that the user can 1) notice that something
> > > > > > is wrong 2) blacklist or unbind the driver (or userspace tools that
> > > > > > use hidraw can unbind automatically). Otherwise everything seems to be
> > > > > > silently broken.
> > > > > >
> > > > > > On the other hand, maybe races between the kernel driver and userspace
> > > > > > tools are unlikely, because the driver doesn't talk to the device
> > > > > > continuously - only when sysfs reads happen.
> > > > >
> > > > > I never noticed any issues of that kind. I actually did quite a lot of
> > > > > userspace testing. A result of this a userspace tool you can find here:
> > > > > https://github.com/wgottwalt/corsair-psu/tree/main/tools/rmi-hxi-query
> > > > >
> > > > > Though, if you find a way to trigger such a race condition I have no
> > > > > problem to remove the hidraw part.
> > > > >
> > > > > greetings
> > > > > Will
> > > >
> > > > It is possible. Making a userspace tool with just a loop of read/writes
> > > > will get you wrong readings in the driver sometimes.
> > >
> > > Hmm, did you read the comments in the driver? I warn about writing nonsense
> > > values to the micro-controller because you can make it stall. If I let you
> > > access the device by hidraw I assume you know what you are doing. You
> > > actually can damage your PSU by this, something I also warn about. I even
> > > mention that I may remove the hidraw feature in future versions.
> >
> > Sorry for the confusion. I did not test with corsair-psu. (Do not have
> > the hardware) I tested with corsair-cpro. Reading temps with userspace and
> > reading fan speed with the driver simultaneously.
> > But you are right. This is also not, what a userspace tool should do this
> > fast and if it doesn't, races are really unlikely.
> >
>
> Same there: Make userspace and kernel mutually exclusive if parallel access
> is shown to be problematic. "Mutually exclusive" means disable userspace
> access completely while the driver is loaded, not some cross-subsystem
> mutex.
>
> Guenter
>
For now I did not get a bug report nor did anyone seem to have a real problem.
It is mostly a theoretical issue.
I am not unhappy about how it is.
Maybe until a real problem occurs, we should just do nothing?
Greetings
Marius
next prev parent reply other threads:[~2021-06-18 12:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-17 3:11 corsair-cpro and hidraw Aleksandr Mezin
2021-06-17 4:33 ` Aleksandr Mezin
2021-06-17 6:27 ` Marius Zachmann
2021-06-17 7:11 ` Aleksandr Mezin
2021-06-17 13:14 ` Guenter Roeck
2021-06-17 23:56 ` Aleksandr Mezin
2021-06-18 5:45 ` Wilken Gottwalt
2021-06-18 6:18 ` Marius Zachmann
2021-06-18 6:47 ` Wilken Gottwalt
2021-06-18 7:06 ` Marius Zachmann
2021-06-18 12:13 ` Guenter Roeck
2021-06-18 12:22 ` Marius Zachmann [this message]
2021-06-18 19:41 ` Guenter Roeck
2021-06-18 12:10 ` Guenter Roeck
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=36091016.oId77RFrrH@marius \
--to=mail@mariuszachmann.de \
--cc=jikos@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mezin.alexander@gmail.com \
--cc=wilken.gottwalt@posteo.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