|
|
Subscribe / Log in / New account

DVB, header files, and user-space regressions

By Jake Edge
August 25, 2021

A regression that was recently reported for 5.14 in the media subsystem is a bit of a strange beast. The kernel's user-space binary interface (ABI) was not changed, which is the usual test for a patch to get reverted, but the report still led to a reversion. The change did lead to problems building a user-space application because it moved some header files to staging/ as part of a cleanup for a deprecated—though apparently still functioning—driver for a Digital Video Broadcasting (DVB) device. There are a few different issues tangled together here, but the reversion of a regression in the user-space API (and not ABI) is a new wrinkle.

Soeren Moch reported the regression in a lengthy message on August 11. Parts of the message were aimed at Linus Torvalds and requested the reversion of three patches committed by media subsystem maintainer Mauro Carvalho Chehab. Those patches moved the av7110 driver to staging and followed up by moving some documentation and header files there as well. But that broke the ability to build parts of the Video Disk Recorder (VDR) application, which is shipped with multiple Linux distributions, Moch said.

He pointed to a Red Hat bug that had been filed by another member of the VDR community as evidence of the problem. VDR uses header files from the uapi/linux/dvb directory; when those got moved, VDR would no longer build on the kernel used for the upcoming Fedora 35. Beyond that, Moch disagreed with moving "the long existing and working av7110 driver" to staging/.

Much of the email was addressed to Chehab; it complained about the deprecation of the existing DVB API [Update: As noted in the comments, this is the "full-featured" DVB API implemented by av7110 and used by VDR.], the removal of av7110 support, and Chehab's unwillingness to merge another driver that also implements the API. There are, Moch said, working devices and existing DVB streams that can be accessed using those drivers. He took issue with Chehab's commit message on the patch moving av7110:

Your commit message "the decoder supports only MPEG2, with is not compatible with several modern DVB streams" is at least misleading. The most popular satellite TV provider in Germany (Astra) still transmits most of the interesting programs MPEG-2 encoded, so also this is actively used and no reason to retire this card.

But Chehab sees things differently; the av7110 hardware stopped being produced 15 years ago and the DVB API that the driver implements is not useful for today's hardware:

The API that got removed was written to control the av7110 MPEG-2 decoder, and was never integrated at the DVB core: the av7110 had a driver-specific implementation inside its code.

Besides that, the API was never fully documented: there are several ioctls from the now removed API that never had any in-kernel implementation, nor had and descriptions at the specs. None of the current upstream maintainers have any [clue] about what such ioctls are supposed to do, nor do we have any av7110 hardware to test it.

There is a clear disagreement about some of that, and Moch repeatedly offers to maintain the av7110 driver going forward. He would also like to see his saa716x driver, which also implements the DVB API, get merged and said he would maintain that as well. According to Moch, there is an active community that is using the hardware with VDR and the DVB API fits its needs well. But Chehab said:

Keeping av7110 in-kernel has been a waste of limited upstream development resources. A couple of years ago, we needed to fix the av7110 API due to year-2038 issues. From time to time, we get bugs affecting it (even security ones), as the code has been bit-rotting for a long time. The most recent one probably broke the driver without nobody noticing it for a couple of Kernel reviews, as mentioned above.

Moch disputes that characterization and had some strongly worded complaints about Chehab's handling of the media subsystem, part of which he addressed to Torvalds. There is clearly a long-running dispute being aired in the thread; Torvalds stepped in to clarify a few things. He said that the regression policy is solely aimed at the ABI of the kernel, which did not change: "old programs continue to work". He also lamented that VDR was using the kernel headers directly; that is not how it is supposed to work:

We very much try to discourage user space applications from using the kernel header files directly - even projects like glibc etc are supposed to _copy_ them, not include the kernel headers.

Exactly because re-organization and changes to the kernel tree shouldn't be something that then causes random problems elsewhere that are so hard to test - and synchronize - from the kernel standpoint (or from the standpoint of the other end).

On the other hand, though, the header files in question were in the uapi directory: "while it is annoying how user space programs used them this way, I think it's also not entirely unreasonable". So he reverted the header-file move, while leaving the other changes (moving av7110 and the DVB API documentation to staging/) intact. He suggested that VDR and any other application using the header files copy them into their tree. He agreed with Chehab that moving av7110 out of the main tree was the right move:

I'm not convinced that it makes sense to move the av7110 driver back from staging - it may continue to work, but it _is_ old and there is no maintenance - and I would certainly suggest that any other out-of-tree driver that uses these old interfaces that nothing else implements shouldn't do so, considering that nothing else implements them.

Both Torvalds and Chehab seem to ignore or discount Moch's offer to maintain the driver, though he presumably can do so in staging/. Keeping the driver working is a good way to ensure that it does not get removed altogether. Moch's questions about the eventual fate of av7110 remain unanswered, however:

How long can this driver stay in staging? Would you move the driver back from staging when I do proper maintenance for it? Is it normal linux policy to remove drivers after a certain period of time, even if a driver still has users and someone that volunteers to maintain it?

So, for now at least, users of VDR will be able to build it for recent kernels; moving forward, copying the header files should ensure that it continues to build. If the driver gets removed, though, users will also need to build the driver in order to make things work. Chehab said that he is open to discussing an API for DVB, "but such API should support modern embedded hardware, and should be designed to allow it to be extended to support to future needs". That could lead to a reworked saa716x driver that would be acceptable for inclusion in the mainline, but even that hardware is quite old and it is not clear that the VDR community is interested in making those kinds of changes.

It is somewhat surprising to see a working driver with an active community getting this treatment, but Chehab is adamant that the DVB API is deprecated as part of the media subsystem. In the thread, there is a strong undercurrent of displeasure with the treatment of the DVB API over the years and with Chehab's handling of it, but Linux maintainers have a wide remit over their subsystems. The two "sides" seem pretty dug in, at this point, so it may take some other interested parties stepping up to find some kind of workable solution—or the VDR community will need to continue using drivers that are either in staging/ or out of the mainline entirely.

This event does demonstrate a bit of an expansion of the regression policy for the kernel. Even though he was not happy about the use of the header files, Torvalds did not want to break an existing user-space application, thus the revert. One wonders how many other applications or libraries have not gotten the memo about not using the kernel user-space API header files directly, however. That could lead to problems with reorganizations and cleanups down the road.



to post comments

DVB, header files, and user-space regressions

Posted Aug 25, 2021 19:13 UTC (Wed) by dullfire (guest, #111432) [Link] (2 responses)

If Moch is offering to maintain the driver that should more or less be the end of it (unless there's some history of problem, or another articulatible reason). Maybe say the driver needs to be update to support a new ABI (if such a thing even exists, not familiar with that subsystem) before it's moved out of staging (even if the old ABI isn't remove, or is moved into a separate module).

The overlooking of the offer to maintain seems... very odd to me.

DVB, header files, and user-space regressions

Posted Aug 25, 2021 19:23 UTC (Wed) by johill (subscriber, #25196) [Link]

From my reading of the article, it's not really that simple.

As far as I can tell, the driver is the only user of the DVB API that some at least would like to see removed, and thus getting rid of the driver is a necessary step. So removing the driver likely isn't the end of the road here - the goal is removing the other code that's old possibly has bad interactions with the rest of the system, and whatnot. I don't know what that code does, but if you look at what we've had to do with wireless extensions in WiFi ... those things are not fun.

Now, if somebody now were to maintain the driver in staging/ you could institute the same policy as elsewhere: if must use the APIs today considered correct to leave there.

It doesn't seem like that was on offer though, mostly it seemed to be "maintain the driver as is", with explicitly disagreement on the (eventual) removal of the DVB API.

DVB, header files, and user-space regressions

Posted Sep 2, 2021 13:42 UTC (Thu) by mrugiero (guest, #153040) [Link]

The overlooking is odd, yeah, but I don't think the _offer_ to maintain is enough. He should start by actually maintaining it in staging so he can claim he'll keep doing it, otherwise it's just words.
Anybody can take a reservation, the important part is holding the reservation.

DVB, header files, and user-space regressions

Posted Aug 25, 2021 19:53 UTC (Wed) by mss (subscriber, #138799) [Link] (6 responses)

Strictly, as far as I understand, it's not the whole DVB API that's getting deprecated as it is still used by _a lot_ of DVB drivers in the kernel.

Rather, it's only a part of it, for so called "full-featured" devices, that was used just by the av7110 driver, that was moved to staging recently.

DVB, header files, and user-space regressions

Posted Aug 26, 2021 1:29 UTC (Thu) by jake (editor, #205) [Link]

> Strictly, as far as I understand, it's not the whole DVB API that's getting deprecated
> as it is still used by _a lot_ of DVB drivers in the kernel.

Yeah, that's a good point and I should have been clearer in the article, which I updated to hopefully help with that.

thanks!

jake

DVB, header files, and user-space regressions

Posted Aug 26, 2021 12:55 UTC (Thu) by mchehab (subscriber, #41156) [Link] (4 responses)

> Strictly, as far as I understand, it's not the whole DVB API that's getting deprecated as it is still used by _a lot_ of DVB drivers in the kernel.

Yes. The DVB API, used by all drivers is OK, and has been actively maintained.

The problem is related to the DVB API extension (called "full-featured") which brings support to start/stop in-hardware audio/video decoding. The API has problems that are known since 2005. There was an attempt to fix it back then by the API developers: https://www.linuxtv.org/downloads/legacy/linux-dvb-api-v4...). Unfortunately the company that was sponsoring the DVB API on that time bankrupted and such work stopped abruptly.

Quoting the 2005 document:

> 2.1 Present situation
>
> First of all, PCs and embedded platforms are divering. For PCs, new cards are only available as ”budget” cards, which means that they only provide the full, raw, unmodified TS to the system and put the burden of handling the data to the main CPU.
> On embedded platforms, however, dedicated STB/IDTV chipsets demultiplex the data for direct application use and specialized hardware or firmware on DSPs relieves the main CPU greatly.

Chapter 2.2 describes the known issues back in 2005. Some were never addressed:

> Linux DVB API Version 3 problems
>
> The Linux DVB API Version 3 was focussed on the popular Siemens PCI DVB card.
> ...
> The Linux DVB API Version 3 has very limited support for modern hardware.
> ...
> Because of the architectual problems of the core, the inconsitency of the API and the lack of zero-copy DMA it’s not possible to simply extend the existing API. A complete new design is inevitable.

It was offered in the past to merge the (also old) saa716x driver upstream, with the condition that the API would be redesigned, but the downstream maintainer of the driver didn't want to change the API.

DVB, header files, and user-space regressions

Posted Aug 26, 2021 14:17 UTC (Thu) by farnz (subscriber, #17727) [Link] (2 responses)

I'm coming in clueless here (joys of not looking at this stuff in the last 5 years), but I recall there being work done on the Media Controller API to let you (e.g.) take audio and video streams from a demuxer, and feed them in-kernel to an appropriate ALSA audio device (that does decode and/or output to connectors) and V4L2 memory-to-memory decoder or output device.

Am I remembering that work properly? If so, would it work to have a V4L2 video decoder and an ALSA device for the SA716x and AV7110 chips, plus a suitable link in the Media Controller API to tell userspace that the chip prefers to be fed data from its own demux?

DVB, header files, and user-space regressions

Posted Aug 27, 2021 0:02 UTC (Fri) by pj (subscriber, #4506) [Link]

@farnz I agree: is the original maintainer's position really that "these in-use devices that we have code for are just too old to support" ? Given the age of other device drivers in the kernel that seems... unusual, to say the least. I mean, I could understand advocating that it should be ported to some more modern API like V4L2 or something, but straight "you're hardware's too old, go away" seems like a poor attitude.

DVB, header files, and user-space regressions

Posted Aug 27, 2021 9:58 UTC (Fri) by mchehab (subscriber, #41156) [Link]

> Am I remembering that work properly?

Yes.

In order to understand the issue, some explanation is needed.

A MPEG-TS may contain multiple elementary streams. On a "full-featured" hardware, there is a hardware demux, which is set via the normal DVB ("budget") API to filter audio, video and data elementary streams (ES) on its multiple outputs. Each demux filter output containing a video ES that will be decoded should then be wired to a video decoder. The same happens with audio ES and with OSD (On Screen Display) ES.

The deprecated "full-featured" API, as implemented on av7110, assumes that at most one audio and one video ES will be decoded on a given time. Such assumption works with TMS320AV7110 chipset (a.k.a. "av7110"), as the hardware has internally a single A/V codec set, and an independent video and audio output hardware, and an On Screen Display (OSD) generator on it, hardwired to handle an OSD elementary stream.

On modern devices and chipsets, there are multiple tuning stages ("frontend"), decoders and demuxes that are not hardwired nor grouped altogether. They typically have an Image Signal Processor (ISP) integrated with a GPU, and all other things, including OSD and programming guide are decoded by the CPU, and then sent to the displayed at the GPU. They can also do Picture in Picture. So, multiple video ES can be shown at the same time. Such hardare also allow any combination from frontend<x> to demux<y> to audio or video codec <z>. There's no way to control such hardware with the "full-featured" API, nor to expand it to fit such model.

That's where the media controller API takes place: it was designed to allow setting up the connections between multiple hardware/firmware blocks. With it, each demux output becomes visible, so it is easy to setup a pipeline from the tuner up to the audio/video outputs.

By using me media controller API, on chipsets where the A/V codecs need to be controlled and the display output needs to be composed, standard APIs should be used, e. g. V4L2 for codecs, ALSA for audio, DRM for video.

It doesn't sound too hard to convert a simple hardware like av7110 to use the media controller instead. On such hardware, there's no need for ALSA/V4L/DRM APIs, as there's nothing that can be controlled there. Yet, to do that, the developer needs to have such hardware and a PC with old PCI slots, plus a separate monitor (or stream capture hardware) with a RCA video input. On the other hand, there's not much value on doing that nowadays, as av7110 supports only MPEG2 for video and existing hardware probably comes supports only the first generation of the DVB standard. So, while it would be nice to do such work, there's not much value in practice, as probably there aren't much av7110 users anymore.

In any case, the driver is currently in staging. If someone is willing to do that, just send the patches. Once the driver got converted to the media controller, it can be moved back to mainstream.

The same applies to saa716x: if it gets converted to use the media controller and stop depending on the legacy full-featured API, it can also be merged upstream.

DVB, header files, and user-space regressions

Posted Sep 22, 2021 17:03 UTC (Wed) by fratti (guest, #105722) [Link]

I'd like to thank you for moving the headers to staging, if even just for a short while; this uncovered two unneeded includes in mpv that we inherited from code written in 2002: https://github.com/mpv-player/mpv/pull/9234#issuecomment-...

DVB, header files, and user-space regressions

Posted Aug 26, 2021 8:08 UTC (Thu) by pm215 (subscriber, #98099) [Link] (2 responses)

If the kernel doesn't want userspace code to just-include-uapi, it would probably be a good idea to make the Right Thing easier, and perhaps the Wrong Thing harder. Right now, the Wrong Thing (just-include) is trivially simple, and unless you need some new feature that hasn't yet made it down to distros you probably won't notice the difficulties. The Right Thing is pretty awkward, and has very little support from the kernel side for doing it AFAIK. QEMU's update-linux-headers script is nearly 250 lines long, and needs periodic tweaks when some kernel header A we were copying now includes header B and we need to take a copy of B too. And if you need to 'sanitize' struct declarations so they'll compile on other OSes, or you wanted ABI info for some architecture other than the host, or, heaven forbid, you're not using C at all, these are all awkward at best.

And copying header files doesn't protect you from the incompatibility reported in this article, it just delays it. Existing source trees of your userspace program continue to build, which is nice, but next time you need to update the headers from the kernel for some reason you find you now need to maintain some frankenstein's-header mixture of up-to-date header and the old pre-removal header. (And if you're unlucky it took you long enough to notice that the old API bits are now firmly gone and not 'ok, let's revert' recoverable...)

DVB, header files, and user-space regressions

Posted Aug 26, 2021 9:18 UTC (Thu) by edeloget (subscriber, #88392) [Link] (1 responses)

That's only true of you blindly (automatically) copy the header ; given the fact that it's only one header (or a limited number of headers) one can do it by hand, pushing a correct header (with #ifdef guards to support the various kernel releases) in the software distribution itself. This has been done thousands of time -- it's not very elegant but it works well if you don't have to cope with a large number of headers.

DVB, header files, and user-space regressions

Posted Aug 26, 2021 16:48 UTC (Thu) by pm215 (subscriber, #98099) [Link]

"It works if you do this non-elegant thing by hand" is exactly the kind of "not as easy as the Wrong Thing" that I'm suggesting it would be nice if people didn't need to do...

DVB, header files, and user-space regressions

Posted Aug 27, 2021 7:51 UTC (Fri) by bmork (subscriber, #88411) [Link] (1 responses)

FWIW, the description Soeren Moch gives of the media subsystem and the (lack of) handling of DVB related patches matches my experinence with the subsystem from 10+ years ago. Mauro was busy with reinventing APIs and moving stuff around in an endless churn, while completely ignoring even the most obviously correct patches for months. Or years. Or decades...

I gave up and moved on after this bloody damn obvious patch just got stuck:
https://lore.kernel.org/linux-media/1277054487-14384-1-gi...

Those two files were merged with the rest of the driver, but never ever referenced by anything. Deleting them should be a no-brainer, and would be in any other subsystem.

Instead we still have drivers/media/pci/mantis/mantis_core.h (yes, Mauro moved this stuff around in 2012) in the current kernel. Do a git grep mantis_core.h and notice all the references...

mantis_core.c was finally removed by 519648bed470 ("media: mantis: remove orphan mantis_core.c") in 2020. After 10 years of blind patching of dead code.

Sure, dead code in an obscure driver is a minor issue. Unfortunately, I belive this is symptomatic for Mauros "maintenance" of the DVB subsystem. I fully understand Soerens frustration. I was lucky enough that I didn't have to care, and could just move on to other subsystems. Playing with DVB could have been fun. But it was definitely not worth the frustrations dealing with the linux-media subsystem and dead-end mailing list.

Media subsystem

Posted Aug 27, 2021 15:27 UTC (Fri) by corbet (editor, #1) [Link]

So I was pretty active in the media subsystem 10+ years ago too, and was paying attention for longer. My experience is that, under Mauro's maintainership (and with a lot of help from people like Hans) it has gone from a toxic wild west to a smoothly functioning development community. All is not perfect — it never is — but I believe it to be a well-maintained subsystem for the most part. To me, this episode looks a bit like a holdover from the bad old days.

(Just my own opinion, obviously).


Copyright © 2021, 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