|
|
Subscribe / Log in / New account

User-space access to WMI functions

By Jonathan Corbet
June 19, 2017
Windows Management Instrumentation (WMI) is a vaguely defined mechanism for the control of platform-specific devices; laptop functions like special buttons, LEDs, and the backlight are often controlled through WMI interfaces. On Linux, access to WMI functions is restricted to the kernel, while Windows allows user space to use them as well. A recent proposal to make WMI functions available to user space in Linux as well spawned a slow-moving conversation that turned on a couple of interesting questions — only one of which was anticipated in the proposal itself.

Darren Hart, the kernel's x86 platform-driver maintainer, proposed making WMI functions available to user space in early May. The reasoning behind this change took a while to come out, but can be found in this message that was posted one month later. The problem that Hart is trying to solve is the result of a good change in the market: vendors of laptops and similar devices are starting to acquire an interest in supporting Linux, and they are finding the current scheme hard to work with.

Getting Linux working well on a contemporary laptop means ensuring that all of the special buttons work as expected, the backlight can be dimmed, the audio volume can be controlled, the radios can be turned on and off, etc. Each laptop vendor has its own way of connecting these features to WMI functions; as a result, the kernel has to be taught about each new laptop design before it will work as intended. The changes required are typically small to the point of being trivial, but they are indeed required, and it seems that some vendors are finding the process of getting those changes into the mainline cumbersome. It takes too long (a claim that Greg Kroah-Hartman questioned), and requires working with those pesky kernel developers.

Hart would like to see that platform-support code move to user space, eliminating the need to get changes into the kernel to support a new device. It would, he said, open the flood gates to interesting new developments and "allow vendors to 'own their own destiny' and innovate and support their platforms independently". He also argued that moving this code to user space would avoid cluttering the kernel with platform-support code that nobody will care about 18 months in the future.

He did have one concern, though, having to do with backward compatibility. The existing kernel-space drivers make use of WMI functions now; allowing user space to play with the same functions is likely to lead to confusion at best. So the proposal included a blacklist mechanism allowing the kernel to block access to any WMI function that it is using. So far, so good, but there is a potential problem: if a new feature is added to the kernel that involves using a WMI function that had not been used before, blocking access to that function might break a user-space application that started using it before the kernel did. Hart's question was: would this sort of ABI change run afoul of the kernel's no-regressions policy?

This question was discussed and a potential solution emerged, but many of the developers were interested in a separate question. Andy Lutomirski probably expressed their concern best:

I should add that one thing that's really, really nice about Linux is that, when you install it on a supported laptop, it works. On Windows, you end up with a horrible pile of bloated, buggy, unsupported userspace crapware to make random buttons work.

While I'm all for improving the manageability situation on Linux, let's please make sure we don't regress the ordinary laptop functionality story and make it as bad as it is on Windows. We're currently in a surprising situation in which laptops frequently work *better* on Linux than Windows, and I think we should preserve that.

In other words, the idea of moving platform support to a user-space blob — perhaps a proprietary blob at that — proved to be surprisingly unappealing to a number of developers on the list. From this point of view, the fact that Windows allows user-space access to WMI functions is not an argument in favor of Linux doing the same; indeed, it could be an argument for doing the opposite. Hart responded that user-space code will not necessarily be of lower quality than kernel code, and that making this functionality available to user space may increase the pool of developers who are able to work on platform support. In particular, he said, some of the people who report platform bugs now could maybe fix them if the relevant code were in user space.

This has the look of the sort of conversation that repeats over the years without any real conclusions, but there were a few things that came out of this one. The first is that there is little interest in changing the status quo if it would inhibit the addition of support for future platforms to the kernel. The ability to run Linux on a laptop without having to chase down some vendor's platform-support blob is worth keeping. So any mechanism giving access to user space would have to allow the addition of support for future platforms, regardless of what might have been done in user space.

There was no definitive conclusion on the backward-compatibility issue, but there was a proposal for a potential solution to the problem. Rather than blocking access to a given WMI function, a platform driver could intercept accesses and ensure that they are properly carried out. So, for example, if the kernel gains the ability to adjust the backlight brightness on a given platform, it will need to intercept access to the WMI function(s) it uses. If a user-space application attempts to use one of those functions, the kernel-space driver can look at what the application is trying to do, cause it to happen, and adjust its own internal state accordingly. If this interception is implemented correctly, it should ensure that a user-space brightness application written before the kernel gained that ability will continue to function afterward.

The final conclusion was that there has been enough discussion of ideas without the code to accompany them. Once the proposal has been implemented, it will be easier to see what the implications are. Hart has accepted the assignment to get some code posted for review. At that point there will almost certainly be another lengthy discussion on the topic.

Index entries for this article
KernelWindows Management Instrumentation (WMI)


to post comments

User-space access to WMI functions

Posted Jun 19, 2017 21:08 UTC (Mon) by cathectic (subscriber, #40543) [Link]

The alternative would be that WMI is used as the original spec intended - with standardised GUIDs for the functions, rather than each vendor implementing their own that necessitates them all maintaining separate driver stacks in the first place just to do common things - i.e. why does each vendor need a different way to turn on wireless, lights, etc.

It also feels like it somewhat defeats the point of the kernel being an abstraction layer for all this 'basic' stuff anyway (e.g. rfkill, backlight, etc).

User-space access to WMI functions

Posted Jun 19, 2017 21:33 UTC (Mon) by jhoblitt (subscriber, #77733) [Link] (3 responses)

As an end-user, I have mixed feelings about this proposal. On one hand, I've come to enjoy generally having a functioning set of drivers "out of the box", be they bundled with the core kernel or firmware blobs bundled by the distro. Notable exceptions to this are needing to manually add a yum repo for nvidia driver and the occasional gymnastics to extract a firmware blob of a windows drivers for something like a broadcom bluetooth interface. The former is a difficult vendor that has largely been worked around by community packaging effort. The later is a crap-tacular experience that is likely beyond the technical abilities or threshold of effort for most end-users. I really want hw vendors to work with the Linux community AND make firmware payloads freely redistributable [by distros]. I definitely *DO NOT* want to have to track down and install a laptop vendor's model-specific state of the art tcl/tk app to control screen brightness, which almost certainly been properly packaged for my distro of choice.

That said, it does seem a bit heavy weight to require a new mainline kernel release to trickle out in order to add support for a couple of custom buttons. I don't have any technical objection to user-space driver frameworks. It is almost certainly in the general Linux communities best interests to encourage hw vendors to contribute support back upstream for their own equipment. If the user-space route is to be embraced, I'd like to see it be a udev/hwdb-like solution that is:

a) a single de facto framework which vendors can contribute configuration data to
b) is treated as "core" system service that is started early and works as part of a minimal/install/rescue environment
c) only results in the bare minimum of Debian forks

User-space access to WMI functions

Posted Jun 19, 2017 21:57 UTC (Mon) by luto (guest, #39314) [Link]

> That said, it does seem a bit heavy weight to require a new mainline kernel release to trickle out in order to add support for a couple of custom buttons.

This would only work for WMI buttons and not for, say, intel-hid buttons or other weird ACPI buttons.

User-space access to WMI functions

Posted Jun 20, 2017 2:54 UTC (Tue) by marduk (subscriber, #3831) [Link] (1 responses)

> a) a single de facto framework which vendors can contribute configuration data to
> b) is treated as "core" system service that is started early and works as part of a minimal/install/rescue environment
> c) only results in the bare minimum of Debian forks

Sounds like a job for systemd.

User-space access to WMI functions

Posted Jun 20, 2017 5:41 UTC (Tue) by zdzichu (subscriber, #17118) [Link]

Not sure if that was sarcastic, but hardwaredb part of systemd suite already contains stuff like that: https://github.com/systemd/systemd/tree/master/hwdb
See for example 60-keyboard.hwdb, it contains information how to map various vendor's keyboard extensions into standardized set of known keys.

User-space access to WMI functions

Posted Jun 19, 2017 21:50 UTC (Mon) by flussence (guest, #85566) [Link] (5 responses)

> It would, he said, open the flood gates to interesting new developments and "allow vendors to 'own their own destiny' and innovate and support their platforms independently".
I have a lot of unflattering words for this, but I'll constrain myself to just two: “hopelessly naïve”. Or “Windows Systray”.

User-space access to WMI functions

Posted Jun 19, 2017 21:56 UTC (Mon) by juliank (guest, #45896) [Link] (4 responses)

Yeah, the whole idea is nuts. We'll end up with tons of userspace blobs, like Android.

User-space access to WMI functions

Posted Jun 19, 2017 22:32 UTC (Mon) by dysphemism (guest, #109434) [Link] (3 responses)

A userspace driver has no review and trivial access to the filesystem
and socket() and connect(). Someone will inevitably write a Python
interface so that even skids can play.

No thanks.

Please keep the bar high enough that review is required. Having said
that, I do understand that I don't have to do any of the work :-)

User-space access to WMI functions

Posted Jun 20, 2017 2:04 UTC (Tue) by jhoblitt (subscriber, #77733) [Link] (2 responses)

I'm sorry but code review is not the exclusive domain of the kernel. And, frankly, there is serious lack of acceptance testing in the LKML world.

Are we discussing a technological or sociological issue?

User-space access to WMI functions

Posted Jun 20, 2017 7:16 UTC (Tue) by juliank (guest, #45896) [Link]

A sociological one.

User-space access to WMI functions

Posted Jun 22, 2017 19:11 UTC (Thu) by pbonzini (subscriber, #60935) [Link]

In many cases the question is not does it work, it is what does it do. You only need one pair of eyes for that, but you badly need it given the Windows precedent.

User-space access to WMI functions

Posted Jun 19, 2017 22:35 UTC (Mon) by zblaxell (subscriber, #26385) [Link] (2 responses)

> allow vendors to 'own their own destiny' and innovate and support their platforms independently...
> ...proved to be surprisingly unappealing

How can that be surprising? This is basic understanding-the-customer stuff. Display brightness control is not an area where users want hardware vendors to be creative or diverse, or isolate their support costs to themselves. Display brightness control is an area where users want hardware to work consistently and predictably as they move their software and data from one ephemeral device to another, and enjoy the greater (or lesser) range of possible brightness values from a more capable (or less expensive) display without having to fight with a new and unfamiliar UI. Vendors would do better to follow each other (or even keep their own designs consistent from one model to the next) than to invent yet another incompatible display brightness control.

Sometimes full WMI support isn't desirable. I've found it quite useful to be able to rip out WMI functions that are supported (like the WiFi kill switch, which on some laptops is positioned exactly where my fingers keep bumping into it every few minutes). It could be easier to do that sort of thing in userspace if there was a sane framework in place, but it would clearly be harder to do that sort of thing if all the WMI functions were controlled by a binary blob.

Notwithstanding the above, the idea isn't entirely terrible. It would be nice to have a userspace rapid prototyping framework, so a medium-skilled user could poke around the function table and discover which function controls the display brightness on a brand new laptop...assuming that there aren't functions in WMI that erase the BIOS or something.

Medium-skilled users used to blindly fire IO writes to ISA registers to figure that sort of thing out on their machines. Now that we have all these discoverable interfaces like ACPI and WMI which can make this sort of probing much easier and safer, but for some reason we've buried them all deeply in the kernel and refuse to allow userspace to get to them.

User-space access to WMI functions

Posted Jun 20, 2017 0:05 UTC (Tue) by k8to (guest, #15413) [Link]

I think the cupidity of userspace has grown immensely since the days of msdos.

Joke?

Posted Jun 20, 2017 3:49 UTC (Tue) by bnorris (subscriber, #92090) [Link]

> How can that be surprising?

Perhaps I'm misreading here, but I took that as dry sarcasm. One hint to me is the interjection that you snipped from the quote: "perhaps a proprietary blob at that".

User-space access to WMI functions

Posted Jun 20, 2017 6:20 UTC (Tue) by mjthayer (guest, #39183) [Link] (2 responses)

> The changes required are typically small to the point of being trivial, but they are indeed required, and it seems that some vendors are finding the process of getting those changes into the mainline cumbersome.

If distributions are interested in supporting the hardware the vendor also has the option of just writing a "good enough" kernel patch and dropping it somewhere they can find it. Distributions would be likely to integrate it into their own kernels with a minimum of fuss and presumably one of them would make the effort to get it upstream to lower their own maintenance effort. The vendor just has to be willing to accept that they will have little control over the driver after they let someone else do the integration, but that may actually be a bonus rather than a problem.

> In other words, the idea of moving platform support to a user-space blob — perhaps a proprietary blob at that — proved to be surprisingly unappealing to a number of developers on the list.

There seems to be an assumption that there is no way to discourage user-space binary-only drivers. Is that really the case? Linux makes it very clear that user-space binaries using Linux kernel interfaces are not considered to be GPL-derived works of the kernel. Would the situation change if the Linux developers made clear that user-space drivers which use particular advertised interfaces are not covered by this? Clearly there would always be a few people willing to try to push the boundaries and possibly risk testing it in court, just as there are with kernel drivers, but I suspect that many people would prefer to just go along with it.

User-space access to WMI functions

Posted Jun 20, 2017 6:33 UTC (Tue) by luto (guest, #39314) [Link] (1 responses)

> Linux makes it very clear that user-space binaries using Linux kernel interfaces are not considered to be GPL-derived works of the kernel. Would the situation change if the Linux developers made clear that user-space drivers which use particular advertised interfaces are not covered by this?

I don't think copyright law works like this. The ACPI-WMI interface quite clearly originates with Microsoft, and MOF (the rather complicated language that nominally specifies the protocol layered on top of ACPI-WMI) comes from the Open Management Group® (http://www.omg.org/mof/). Trying to say that a program that uses these interfaces and happens to be ported to run on a Linux kernel instead of on Windows is a derived work of Linux and therefore subject to the GPL seems like a serious stretch. At the very least, anyone could write a GPL-compatible shim that exposes a non-Linux-specific ACPI-WMI or MOF interface and then link their entirely-not-Linux-derived blob against it.

Using shims to get around the GPL

Posted Jun 20, 2017 14:27 UTC (Tue) by deltasquared (guest, #99235) [Link]

This makes me wonder if VMware haven't tried something like this in order to evade the GPL on the linux kernel, or if nvidia do it in their kernel-space modules to avoid having to deal with similar legal trouble.
(Disclaimer: this is just some thoughts off the top of my head, it's been a while since I've looked closely at either matter.)

User-space access to WMI functions

Posted Jun 22, 2017 16:26 UTC (Thu) by hadess (subscriber, #24252) [Link] (1 responses)

Please, God, no.

What's likely to happen if this were done, for the very simple case of backlights, is:
- we'd have very low-quality, probably insecure or just utterly broken glue code provided by vendors, most likely proprietary just in case somebody tries to steal their awful technology
- desktops would start adding hardware specific code in their backlight controlling code
- desktops would realise that they need a solution to hide all that WMI stuff, you'd end up with at least 2 or 3 separate implementations, at the very least one for Android and one for "D-Bus-y" Linux. Infrastructure would need to be recreated, APIs redefined. In the meanwhile, non-WMI backlights and buttons still live happily in the kernel, getting their drivers reviewed.
- somebody gets sick of the user-space library, realising there's no competitive advantage to a bloody backlight driver, starts sending kernel patches to implement the backlight directly in the kernel from the reverse engineered information.

We already have common APIs to offer user-space for buttons and backlights. As for the past 20-odd years, giving hardware and specs away is likely going to make the hardware support better than blobs of executables dumped as tarballs on a forum.

User-space access to WMI functions

Posted Jun 23, 2017 8:17 UTC (Fri) by dgm (subscriber, #49227) [Link]

Hear, hear.

Chicken and Egg

Posted Jun 29, 2017 12:48 UTC (Thu) by ras (subscriber, #33059) [Link]

> Each laptop vendor has its own way of connecting these features to WMI functions; as a result, the kernel has to be taught about each new laptop design before it will work as intended.

Which has lead to the kernel containing 42K LOC in the kernel to implement some pretty trivial flotsam and jetsam because the hardware vendors never bothered to standardise on a common set of scan codes and registers. If Microsoft's lenient driver model hadn't let them get away with this pain free for so long, maybe we wouldn't be in this position now.

Changing things so we don't push some of the inconvenience this continual churn creates back onto the hardware vendors who create it doesn't sound like a good idea to me.

User-space access to WMI functions

Posted Aug 25, 2017 22:39 UTC (Fri) by dvhart (guest, #19636) [Link]

Several good thoughts and comments here, most generally echoed in the various mailing list threads as well. One additional piece of context is the initial motivation. The idea behind exporting WMI to userspace was to support Web Based Enterprise Management (WBEM) tools, which is more inline with the intent of WMI in the first place - as opposed to all the other things like LEDs, hotkeys, and radios that have crept in.

WBEM involves SMM. ASL (WMI) accessing SMM, providing a limited access opregion, is arguably an improvement from the OS accessing SMM and providing it full access to physical memory (see the existing Linux kernel dcdbas driver).

There are a number of comments lamenting the choice of the OEMs to implement certain features through WMI. I think it's fair to say that few people appreciate that more than the x86 platform drivers team :-) For the vast majority of these things, we have very little input and are working with platforms that were designed for a fundamentally different software ecosystem.

Finally, from all the discussion, it is clear that caution is required. As we move closer to a design and implementation, we are looking carefully at how to enable vendors who are actively trying to collaborate with the Linux kernel developers to support their platforms, while not opening up pandora's box on other platforms.


Copyright © 2017, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds