Skip to contentSkip to conversation

MC v2 cleanups

RFC Superseded Sakari Ailus 4 participants 13 messages Feb 21, 2016 – Feb 22, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

cover MC v2 cleanups

Hi all,

I have a few RFC patches to clean up the recent MC v2 API additions.

Let me know what you think.

At least the compat IOCTL handling requires some work still in general (MC v2 or not).

Signature · 2 lines
Kind regards,
Sakari
author maintainer
#1 lore raw

RFC 1/4 media: Sanitise the reserved fields of the G_TOPOLOGY IOCTL arguments

From: Sakari Ailus <[email protected]>

Align them up to a power of two.

---
 include/uapi/linux/media.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/uapi/linux/media.h +4 -4
index 6aac2f0..008d077 100644
@@ -302,7 +302,7 @@ struct media_v2_entity {
 	__u32 id;
 	char name[64];		/* FIXME: move to a property? (RFC says so) */
 	__u32 function;		/* Main function of the entity */
-	__u16 reserved[12];
+	__u32 reserved[14];
 };
 
 /* Should match the specific fields at media_intf_devnode */
@@ -315,7 +315,7 @@ struct media_v2_interface {
 	__u32 id;
 	__u32 intf_type;
 	__u32 flags;
-	__u32 reserved[9];
+	__u32 reserved[13];
 
 	union {
 		struct media_v2_intf_devnode devnode;
@@ -327,7 +327,7 @@ struct media_v2_pad {
 	__u32 id;
 	__u32 entity_id;
 	__u32 flags;
-	__u16 reserved[9];
+	__u32 reserved[5];
 };
 
 struct media_v2_link {
@@ -335,7 +335,7 @@ struct media_v2_link {
 	__u32 source_id;
 	__u32 sink_id;
 	__u32 flags;
-	__u32 reserved[5];
+	__u32 reserved[4];
 };
 
 struct media_v2_topology {
Signature · 1 line
2.1.4
author maintainer
#6 lore raw

RFC 2/4 media: Rearrange the fields in the G_TOPOLOGY IOCTL argument

In reply to Sakari Ailus

From: Sakari Ailus <[email protected]>

This avoids having multiple reserved fields in the struct. Reserved fields are added in order to align the struct size to a power of two as well.

---
 include/uapi/linux/media.h | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
include/uapi/linux/media.h +5 -10
index 008d077..77a95db 100644
@@ -341,21 +341,16 @@ struct media_v2_link {
 struct media_v2_topology {
 	__u64 topology_version;
 
-	__u32 num_entities;
-	__u32 reserved1;
 	__u64 ptr_entities;
-
-	__u32 num_interfaces;
-	__u32 reserved2;
 	__u64 ptr_interfaces;
-
-	__u32 num_pads;
-	__u32 reserved3;
 	__u64 ptr_pads;
+	__u64 ptr_links;
 
+	__u32 num_entities;
+	__u32 num_interfaces;
+	__u32 num_pads;
 	__u32 num_links;
-	__u32 reserved4;
-	__u64 ptr_links;
+	__u32 reserved[18];
 };
 
 static inline void __user *media_get_uptr(__u64 arg)
Signature · 1 line
2.1.4
author maintainer
#8 lore raw

RFC 3/4 media: Properly handle user pointers

In reply to Sakari Ailus

Mark pointers containing user pointers as such.

---
 drivers/media/media-device.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/media-device.c +4 -4
index 5ebb3cd..f001c27 100644
@@ -245,10 +245,10 @@ static long __media_device_get_topology(struct media_device *mdev,
 	struct media_interface *intf;
 	struct media_pad *pad;
 	struct media_link *link;
-	struct media_v2_entity kentity, *uentity;
-	struct media_v2_interface kintf, *uintf;
-	struct media_v2_pad kpad, *upad;
-	struct media_v2_link klink, *ulink;
+	struct media_v2_entity kentity, __user *uentity;
+	struct media_v2_interface kintf, __user *uintf;
+	struct media_v2_pad kpad, __user *upad;
+	struct media_v2_link klink, __user *ulink;
 	unsigned int i;
 	int ret = 0;
 
Signature · 1 line
2.1.4
author maintainer
#10 lore raw

RFC 4/4 media: Drop media_get_uptr() macro

In reply to Sakari Ailus

From: Sakari Ailus <[email protected]>

There's no real need for such a macro, especially not in the user space header.

---
 drivers/media/media-device.c | 8 ++++----
 include/uapi/linux/media.h   | 5 -----
 2 files changed, 4 insertions(+), 9 deletions(-)
drivers/media/media-device.c +4 -4
index f001c27..8a20383 100644
@@ -256,7 +256,7 @@ static long __media_device_get_topology(struct media_device *mdev,
 
 	/* Get entities and number of entities */
 	i = 0;
-	uentity = media_get_uptr(topo->ptr_entities);
+	uentity = (void __user *)(uintptr_t)topo->ptr_entities;
 	media_device_for_each_entity(entity, mdev) {
 		i++;
 		if (ret || !uentity)
@@ -282,7 +282,7 @@ static long __media_device_get_topology(struct media_device *mdev,
 
 	/* Get interfaces and number of interfaces */
 	i = 0;
-	uintf = media_get_uptr(topo->ptr_interfaces);
+	uintf = (void __user *)(uintptr_t)topo->ptr_interfaces;
 	media_device_for_each_intf(intf, mdev) {
 		i++;
 		if (ret || !uintf)
@@ -317,7 +317,7 @@ static long __media_device_get_topology(struct media_device *mdev,
 
 	/* Get pads and number of pads */
 	i = 0;
-	upad = media_get_uptr(topo->ptr_pads);
+	upad = (void __user *)(uintptr_t)topo->ptr_pads;
 	media_device_for_each_pad(pad, mdev) {
 		i++;
 		if (ret || !upad)
@@ -343,7 +343,7 @@ static long __media_device_get_topology(struct media_device *mdev,
 
 	/* Get links and number of links */
 	i = 0;
-	ulink = media_get_uptr(topo->ptr_links);
+	ulink = (void __user *)(uintptr_t)topo->ptr_links;
 	media_device_for_each_link(link, mdev) {
 		if (link->is_backlink)
 			continue;
include/uapi/linux/media.h +0 -5
index 77a95db..f4f7897 100644
@@ -353,11 +353,6 @@ struct media_v2_topology {
 	__u32 reserved[18];
 };
 
-static inline void __user *media_get_uptr(__u64 arg)
-{
-	return (void __user *)(uintptr_t)arg;
-}
-
 /* ioctls */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
Signature · 1 line
2.1.4
#11 lore raw

Re: [RFC 4/4] media: Drop media_get_uptr() macro

Em Sun, 21 Feb 2016 23:36:15 +0200
Sakari Ailus <[email protected]> escreveu:

Quoted 4 lines

From: Sakari Ailus <[email protected]>

There's no real need for such a macro, especially not in the user space header.

Ok, good point, but I would, instead, move the macro to drivers/media/media-device.c. That double-casting is something unusual, and we don't want to start receiving patch from newbie janitors wanting to strip the casts.

Quoted 63 lines
---
 drivers/media/media-device.c | 8 ++++----
 include/uapi/linux/media.h   | 5 -----
 2 files changed, 4 insertions(+), 9 deletions(-)
drivers/media/media-device.c +4 -4
index f001c27..8a20383 100644
@@ -256,7 +256,7 @@ static long __media_device_get_topology(struct media_device *mdev,
 
 	/* Get entities and number of entities */
 	i = 0;
-	uentity = media_get_uptr(topo->ptr_entities);
+	uentity = (void __user *)(uintptr_t)topo->ptr_entities;
 	media_device_for_each_entity(entity, mdev) {
 		i++;
 		if (ret || !uentity)
@@ -282,7 +282,7 @@ static long __media_device_get_topology(struct media_device *mdev,
 
 	/* Get interfaces and number of interfaces */
 	i = 0;
-	uintf = media_get_uptr(topo->ptr_interfaces);
+	uintf = (void __user *)(uintptr_t)topo->ptr_interfaces;
 	media_device_for_each_intf(intf, mdev) {
 		i++;
 		if (ret || !uintf)
@@ -317,7 +317,7 @@ static long __media_device_get_topology(struct media_device *mdev,
 
 	/* Get pads and number of pads */
 	i = 0;
-	upad = media_get_uptr(topo->ptr_pads);
+	upad = (void __user *)(uintptr_t)topo->ptr_pads;
 	media_device_for_each_pad(pad, mdev) {
 		i++;
 		if (ret || !upad)
@@ -343,7 +343,7 @@ static long __media_device_get_topology(struct media_device *mdev,
 
 	/* Get links and number of links */
 	i = 0;
-	ulink = media_get_uptr(topo->ptr_links);
+	ulink = (void __user *)(uintptr_t)topo->ptr_links;
 	media_device_for_each_link(link, mdev) {
 		if (link->is_backlink)
 			continue;
include/uapi/linux/media.h +0 -5
index 77a95db..f4f7897 100644
@@ -353,11 +353,6 @@ struct media_v2_topology {
 	__u32 reserved[18];
 };
 
-static inline void __user *media_get_uptr(__u64 arg)
-{
-	return (void __user *)(uintptr_t)arg;
-}
-
 /* ioctls */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
Signature · 2 lines
Thanks,
Mauro
#7 lore raw

Re: [RFC 2/4] media: Rearrange the fields in the G_TOPOLOGY IOCTL argument

In reply to Sakari Ailus

Em Sun, 21 Feb 2016 23:36:13 +0200
Sakari Ailus <[email protected]> escreveu:

Quoted 29 lines

From: Sakari Ailus <[email protected]>

This avoids having multiple reserved fields in the struct. Reserved fields are added in order to align the struct size to a power of two as well.

---
 include/uapi/linux/media.h | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
include/uapi/linux/media.h +0 -8
index 008d077..77a95db 100644
@@ -341,21 +341,16 @@ struct media_v2_link {
 struct media_v2_topology {
 	__u64 topology_version;
 
-	__u32 num_entities;
-	__u32 reserved1;
 	__u64 ptr_entities;
-
-	__u32 num_interfaces;
-	__u32 reserved2;
 	__u64 ptr_interfaces;
-
-	__u32 num_pads;
-	__u32 reserved3;
 	__u64 ptr_pads;

include/uapi/linux/media.h struct media_v2_link { · line 354

Quoted 10 lines
include/uapi/linux/media.h +5 -2
+	__u64 ptr_links;
 
+	__u32 num_entities;
+	__u32 num_interfaces;
+	__u32 num_pads;
 	__u32 num_links;
-	__u32 reserved4;
-	__u64 ptr_links;
+	__u32 reserved[18];
 };

This patch deserves more discussion. I suggest we discuss it on our next IRC meeting about the MC (likely today).

Quoted 2 lines
include/uapi/linux/media.h +0 -0
 static inline void __user *media_get_uptr(__u64 arg)
Signature · 2 lines
Thanks,
Mauro
#2 lore raw

Re: [RFC 1/4] media: Sanitise the reserved fields of the G_TOPOLOGY IOCTL arguments

In reply to Sakari Ailus

Em Sun, 21 Feb 2016 23:36:12 +0200
Sakari Ailus <[email protected]> escreveu:

Quoted 3 lines

From: Sakari Ailus <[email protected]>

Align them up to a power of two.

Looks OK to me.

Quoted 46 lines
---
 include/uapi/linux/media.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/uapi/linux/media.h +4 -4
index 6aac2f0..008d077 100644
@@ -302,7 +302,7 @@ struct media_v2_entity {
 	__u32 id;
 	char name[64];		/* FIXME: move to a property? (RFC says so) */
 	__u32 function;		/* Main function of the entity */
-	__u16 reserved[12];
+	__u32 reserved[14];
 };
 
 /* Should match the specific fields at media_intf_devnode */
@@ -315,7 +315,7 @@ struct media_v2_interface {
 	__u32 id;
 	__u32 intf_type;
 	__u32 flags;
-	__u32 reserved[9];
+	__u32 reserved[13];
 
 	union {
 		struct media_v2_intf_devnode devnode;
@@ -327,7 +327,7 @@ struct media_v2_pad {
 	__u32 id;
 	__u32 entity_id;
 	__u32 flags;
-	__u16 reserved[9];
+	__u32 reserved[5];
 };
 
 struct media_v2_link {
@@ -335,7 +335,7 @@ struct media_v2_link {
 	__u32 source_id;
 	__u32 sink_id;
 	__u32 flags;
-	__u32 reserved[5];
+	__u32 reserved[4];
 };
 
 struct media_v2_topology {
Signature · 2 lines
Thanks,
Mauro
#3 lore raw

Re: [RFC 1/4] media: Sanitise the reserved fields of the G_TOPOLOGY IOCTL arguments

In reply to Sakari Ailus

Em Sun, 21 Feb 2016 23:36:12 +0200
Sakari Ailus <[email protected]> escreveu:

Quoted 3 lines

From: Sakari Ailus <[email protected]>

Align them up to a power of two.

Looks OK to me, but I would comment that the structs are aligned to 2^n for those structs.

Quoted 46 lines
---
 include/uapi/linux/media.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/uapi/linux/media.h +4 -4
index 6aac2f0..008d077 100644
@@ -302,7 +302,7 @@ struct media_v2_entity {
 	__u32 id;
 	char name[64];		/* FIXME: move to a property? (RFC says so) */
 	__u32 function;		/* Main function of the entity */
-	__u16 reserved[12];
+	__u32 reserved[14];
 };
 
 /* Should match the specific fields at media_intf_devnode */
@@ -315,7 +315,7 @@ struct media_v2_interface {
 	__u32 id;
 	__u32 intf_type;
 	__u32 flags;
-	__u32 reserved[9];
+	__u32 reserved[13];
 
 	union {
 		struct media_v2_intf_devnode devnode;
@@ -327,7 +327,7 @@ struct media_v2_pad {
 	__u32 id;
 	__u32 entity_id;
 	__u32 flags;
-	__u16 reserved[9];
+	__u32 reserved[5];
 };
 
 struct media_v2_link {
@@ -335,7 +335,7 @@ struct media_v2_link {
 	__u32 source_id;
 	__u32 sink_id;
 	__u32 flags;
-	__u32 reserved[5];
+	__u32 reserved[4];
 };
 
 struct media_v2_topology {
Signature · 2 lines
Thanks,
Mauro
#12 lore raw

Re: [RFC 4/4] media: Drop media_get_uptr() macro

In reply to Mauro Carvalho Chehab

Hi Mauro,

Quoted 5 lines · Mauro Carvalho Chehab

Em Sun, 21 Feb 2016 23:36:15 +0200
Sakari Ailus <[email protected]> escreveu:

Quoted 2 lines

From: Sakari Ailus <[email protected]>

Quoted 7 lines
Quoted 2 lines

There's no real need for such a macro, especially not in the user space header.

Ok, good point, but I would, instead, move the macro to drivers/media/media-device.c. That double-casting is something unusual, and we don't want to start receiving patch from newbie janitors wanting to strip the casts.

Ok, I'll move it to media-device.c then.

Signature · 2 lines
Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#4 lore raw

Re: [RFC 1/4] media: Sanitise the reserved fields of the G_TOPOLOGY IOCTL arguments

In reply to Mauro Carvalho Chehab

Em Mon, 22 Feb 2016 07:00:47 -0300
Mauro Carvalho Chehab <[email protected]> escreveu:

Quoted 9 lines

Em Sun, 21 Feb 2016 23:36:12 +0200
Sakari Ailus <[email protected]> escreveu:

Quoted 3 lines

From: Sakari Ailus <[email protected]>

Align them up to a power of two.

Looks OK to me, but I would comment that the structs are aligned to 2^n for those structs.

Hmm... on a second tought, I don't think this patch makes any sense. As those structs will be part of an array at media_v2_topology, this won't be aligned to a power of two, as we don't require that the number of links, entities, etc.. to be a aligned.

Regards,
Mauro

Quoted 49 lines
Quoted 47 lines
---
 include/uapi/linux/media.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/uapi/linux/media.h +4 -4
index 6aac2f0..008d077 100644
@@ -302,7 +302,7 @@ struct media_v2_entity {
 	__u32 id;
 	char name[64];		/* FIXME: move to a property? (RFC says so) */
 	__u32 function;		/* Main function of the entity */
-	__u16 reserved[12];
+	__u32 reserved[14];
 };
 
 /* Should match the specific fields at media_intf_devnode */
@@ -315,7 +315,7 @@ struct media_v2_interface {
 	__u32 id;
 	__u32 intf_type;
 	__u32 flags;
-	__u32 reserved[9];
+	__u32 reserved[13];
 
 	union {
 		struct media_v2_intf_devnode devnode;
@@ -327,7 +327,7 @@ struct media_v2_pad {
 	__u32 id;
 	__u32 entity_id;
 	__u32 flags;
-	__u16 reserved[9];
+	__u32 reserved[5];
 };
 
 struct media_v2_link {
@@ -335,7 +335,7 @@ struct media_v2_link {
 	__u32 source_id;
 	__u32 sink_id;
 	__u32 flags;
-	__u32 reserved[5];
+	__u32 reserved[4];
 };
 
 struct media_v2_topology {  
Signature · 2 lines
Thanks,
Mauro
maintainer Acked-by on v1 3/4
#9 lore raw

Re: [RFC 3/4] media: Properly handle user pointers

In reply to Sakari Ailus

Hi Sakari,

Thank you for the patch.

Quoted 3 lines · On Sunday 21 February 2016 23:36:14 Sakari Ailus wrote:

Mark pointers containing user pointers as such.

Quoted 22 lines
---
 drivers/media/media-device.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/media-device.c +4 -4
index 5ebb3cd..f001c27 100644
@@ -245,10 +245,10 @@ static long __media_device_get_topology(struct
 media_device *mdev, struct media_interface *intf;
 	struct media_pad *pad;
 	struct media_link *link;
-	struct media_v2_entity kentity, *uentity;
-	struct media_v2_interface kintf, *uintf;
-	struct media_v2_pad kpad, *upad;
-	struct media_v2_link klink, *ulink;
+	struct media_v2_entity kentity, __user *uentity;
+	struct media_v2_interface kintf, __user *uintf;
+	struct media_v2_pad kpad, __user *upad;
+	struct media_v2_link klink, __user *ulink;
 	unsigned int i;
 	int ret = 0;
Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw

Re: [RFC 1/4] media: Sanitise the reserved fields of the G_TOPOLOGY IOCTL arguments

In reply to Mauro Carvalho Chehab

Hi Mauro,

Quoted 10 lines · Mauro Carvalho Chehab

Em Mon, 22 Feb 2016 07:00:47 -0300
Mauro Carvalho Chehab <[email protected]> escreveu:

Quoted 7 lines

Em Sun, 21 Feb 2016 23:36:12 +0200
Sakari Ailus <[email protected]> escreveu:

Quoted 3 lines

From: Sakari Ailus <[email protected]>

Align them up to a power of two.

Quoted 7 lines
Quoted 2 lines

Looks OK to me, but I would comment that the structs are aligned to 2^n for those structs.

Hmm... on a second tought, I don't think this patch makes any sense. As those structs will be part of an array at media_v2_topology, this won't be aligned to a power of two, as we don't require that the number of links, entities, etc.. to be a aligned.

Well... that's a valid point indeed. Still I think the reserved fields do need some changes, at least aligning the size to the common ABI alignment (e.g. 8 bytes) rather than relying on the compiler to do it.

Signature · 2 lines
Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]