From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: "Rémi Denis-Courmont" <remi@remlab.net>
Cc: mchehab@infradead.org, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org, Alan Cox <alan@lxorguk.ukuu.org.uk>,
Hans Verkuil <hverkuil@xs4all.nl>
Subject: Re: [RFC] [PATCH] v4l2: use unsigned rather than enums in ioctl() structs
Date: Wed, 11 Apr 2012 16:53:23 -0300 [thread overview]
Message-ID: <4F85E133.4030404@redhat.com> (raw)
In-Reply-To: <201204112147.55348.remi@remlab.net>
Em 11-04-2012 15:47, Rémi Denis-Courmont escreveu:
> Hello,
>
> Le mercredi 11 avril 2012 20:02:00 Mauro Carvalho Chehab, vous avez écrit :
>> Using unsigned instead of enum is not a good idea, from API POV, as
>> unsigned has different sizes on 32 bits and 64 bits.
>
> Fair enough. But then we can do that instead:
> typedef XXX __enum_t;
> where XXX is the unsigned integer with the right number of bits. Since Linux
> does not use short enums, this ought to work fine.
>
>> Yet, using enum was really a very bad idea, and, on all new stuff,
>> we're not accepting any new enum field.
>
> That is unfortunately not true. You do follow that rule for new fields to
> existing V4L2 structure.
Yes, that's what I meant.
> But you have been royally ignoring that rule when it
> comes to extending existing enumerations:
The existing enumerations can be extended, by adding new values for unused
values, otherwise API functionality can't be extended. Yet, except
for a gcc bug (or weird optimize option), I fail to see why this would break
the ABI.
If this is all about some gcc optimization with newer gcc versions, then maybe
the solution may be to add some pragmas at the code to disable such optimization
when compiling the structs with enum's at videodev2.h.
> linux-media does regularly add new enum values to existing enums. That is new
> stuff too, and every single time you do that, you do BREAK THE USERSPACE ABI.
> This is entirely unacceptable and against established kernel development
> policies.
>
> For instance, in Linux 3.1, V4L2_CTRL_TYPE_BITMASK was added. This broke
> userspace.
The patch is:
commit fa4d7096d1fb7c012ebaacefee132007a21e0965
Author: Hans Verkuil <hans.verkuil@cisco.com>
Date: Mon May 23 04:07:05 2011 -0300
[media] v4l2-ctrls: add new bitmask control type
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
...
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index f002006..148d1a5 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -1040,6 +1040,7 @@ enum v4l2_ctrl_type {
V4L2_CTRL_TYPE_INTEGER64 = 5,
V4L2_CTRL_TYPE_CTRL_CLASS = 6,
V4L2_CTRL_TYPE_STRING = 7,
+ V4L2_CTRL_TYPE_BITMASK = 8,
};
/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
This doesn't change the existing v4l2_ctrl_type codes. So, it shouldn't be
producing any harm at the existing code.
> And there are some pending patches adding more of the same thing...
> And V4L2_MEMORY_DMABUF will similarly break the user-to-kernel interface,
> which is yet worse.
>
>> That's said, a patch like that were proposed in the past. See:
>> http://www.spinics.net/lists/vfl/msg25686.html
>>
>> Alan said there [1] that:
>> "Its a fundamental change to a public structure from enum to u32. I think
>> you are right but this change seems too late by several years."
>
> I cannot see how the kernel is protected against userspace injecting error
> values into enums. For all I know, depending how the kernel is compiled,
> userspace might be able to trigger "undefined" behavior in kernel space.
>
> Is it be several years too late to fix a bug?
No, but causing an ABI breakage like what it would happen by replacing
"enums" by u32 would break all binaries on x86_64 kernels (and vice-versa
if using u64, breaking all i386 binaries).
>From what I remember from the 2006 discussions, even using "unsigned" may
lead into breakages on some non-x86 architectures that use u16 for enums,
as, on those archs, unsigned is 32 bits.
>
> (...)
>> I don't think anything has changed since then that would make it easier
>> to apply a change like that.
>
> OK. But then you cannot update extend existing enums... No DMA buffers, no
> integer menu controls...
>
Regards,
Mauro
next prev parent reply other threads:[~2012-04-11 19:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-05 17:52 [RFC] [PATCH] v4l2: use unsigned rather than enums in ioctl() structs Rémi Denis-Courmont
2012-04-11 17:02 ` Mauro Carvalho Chehab
2012-04-11 18:47 ` Rémi Denis-Courmont
2012-04-11 19:53 ` Mauro Carvalho Chehab [this message]
2012-04-11 20:32 ` Rémi Denis-Courmont
2012-04-12 17:22 ` Nick Bowler
2012-04-11 20:08 ` Mauro Carvalho Chehab
2012-04-12 8:04 ` James Courtier-Dutton
2012-04-12 14:55 ` Mauro Carvalho Chehab
2012-04-12 15:41 ` Rémi Denis-Courmont
2012-04-17 17:50 ` Mauro Carvalho Chehab
2012-04-27 8:24 ` [RFC 1/1] v4l: Implement compat handlers for ioctls containing enums Sakari Ailus
2012-04-13 8:25 ` [RFC] [PATCH] v4l2: use unsigned rather than enums in ioctl() structs James Courtier-Dutton
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=4F85E133.4030404@redhat.com \
--to=mchehab@redhat.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=hverkuil@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@infradead.org \
--cc=remi@remlab.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