Skip to contentSkip to conversation

Process events biarch bug: Name process event data union type and annotate for compatibility.

RFC PATCH In review Matt Helsley 3 participants 9 messages Jun 27, 2006 – Jun 30, 2006 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

RFC PATCH 1/3 Process events biarch bug: Name process event data union type and annotate for compatibility.

This patch adds an explicit type to the process events union structure so the type may be reused.

---
 include/linux/cn_proc.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/cn_proc.h +1 -1
Index: linux-2.6.17-mm3-biarch/include/linux/cn_proc.h
===================================================================
@@ -56,11 +56,11 @@ struct proc_event {
 		/* "last" is the last process event: exit */
 		PROC_EVENT_EXIT = 0x80000000
 	} what;
 	__u32 cpu;
 	struct timespec timestamp;
-	union { /* must be last field of proc_event struct */
+	union process_event_data { /* must be last field of proc_event struct */
 		struct {
 			__u32 err;
 		} ack;
 
 		struct fork_proc_event {

--

#2 lore raw

RFC PATCH 2/3 Process events biarch bug: Process events timestamp bug

In reply to a message not in the archive

The event sent by Process Events from a 64-bit kernel is not compatible with what a 32-bit userspace program would expect to recieve because the timespec struct (used to send a timestamp) is not the same. This means that fields stored after the timestamp are offset and programs that don't take this into account break under these circumstances.

This is a problem on ppc64, s390, x86-64.. any "biarch" system where it's possible for a 64-bit kernel to run 32-bit userspace programs.

This patch adds a comment highlighting the problem and a Documentation file showing a userspace workaround.

---
 Documentation/connector/process_events.txt |   75 +++++++++++++++++++++++++++++
 drivers/connector/Kconfig                  |    3 +
 include/linux/cn_proc.h                    |    7 ++
 3 files changed, 85 insertions(+)
include/linux/cn_proc.h +7 -0
Index: linux-2.6.17-mm3-biarch/include/linux/cn_proc.h
===================================================================
@@ -55,11 +55,18 @@ struct proc_event {
 		/* "next" should be 0x00000400 */
 		/* "last" is the last process event: exit */
 		PROC_EVENT_EXIT = 0x80000000
 	} what;
 	__u32 cpu;
+
+ 	/*
+ 	 * UGH! timespec is biarch incompatible. See
+ 	 * Documentation/connector/process_events.txt if you're going to listen
+ 	 * for process events in userspace.
+ 	 */
 	struct timespec timestamp;
+
 	union process_event_data { /* must be last field of proc_event struct */
 		struct {
 			__u32 err;
 		} ack;
 
Documentation/connector/process_events.txt new file +75 -0

75 lines not on this page · raw message

drivers/connector/Kconfig +3 -0
Index: linux-2.6.17-mm3-biarch/drivers/connector/Kconfig
===================================================================
@@ -16,6 +16,9 @@ config PROC_EVENTS
 	depends on CONNECTOR
 	help
 	  Provide a connector that reports process events to userspace. Send
 	  events such as fork, exec, id change (uid, gid, suid, etc), and exit.
 
+	  See Documentation/connector/process_events.txt if you're going to
+	  listen for process events in userspace.
+
 endmenu

--

#3 lore raw

RFC PATCH 3/3 Process events biarch bug: New process events connector value

In reply to a message not in the archive

"Deprecate" existing Process Events connector interface and add a new one that works cleanly on biarch platforms.

Any expansion of the previous event structure would break userspace's ability to workaround the biarch incompatibility problem. Hence this patch creates a new interface and generates events (for both when necessary).

---
 drivers/connector/cn_proc.c |   65 +++++++++++++++++++++++++++++---------------
 include/linux/cn_proc.h     |   23 ++++++++++-----
 include/linux/connector.h   |    3 +-
 3 files changed, 61 insertions(+), 30 deletions(-)
include/linux/connector.h +2 -1
Index: linux-2.6.17-mm3-biarch/include/linux/connector.h
===================================================================
@@ -29,11 +29,12 @@
 
 /*
  * Process Events connector unique ids -- used for message routing
  */
 #define CN_IDX_PROC			0x1
-#define CN_VAL_PROC			0x1
+#define CN_VAL_PROC_DEPRECATED		0x1 /* deprecated */
+#define CN_VAL_PROC			0x2
 #define CN_IDX_CIFS			0x2
 #define CN_VAL_CIFS                     0x1
 #define CN_W1_IDX			0x3	/* w1 communication */
 #define CN_W1_VAL			0x1
 
drivers/connector/cn_proc.c +44 -21

162 lines not on this page · raw message

include/linux/cn_proc.h +15 -8
Index: linux-2.6.17-mm3-biarch/include/linux/cn_proc.h
===================================================================
@@ -55,18 +55,11 @@ struct proc_event {
 		/* "next" should be 0x00000400 */
 		/* "last" is the last process event: exit */
 		PROC_EVENT_EXIT = 0x80000000
 	} what;
 	__u32 cpu;
-
- 	/*
- 	 * UGH! timespec is biarch incompatible. See
- 	 * Documentation/connector/process_events.txt if you're going to listen
- 	 * for process events in userspace.
- 	 */
-	struct timespec timestamp;
-
+	__u64 timestamp_ns;
 	union process_event_data { /* must be last field of proc_event struct */
 		struct {
 			__u32 err;
 		} ack;
 
@@ -100,6 +93,20 @@ struct proc_event {
 			pid_t process_tgid;
 			__u32 exit_code, exit_signal;
 		} exit;
 	} event_data;
 };
+
+struct proc_event_deprecated {
+	enum what what;
+	__u32 cpu;
+
+	/*
+	 * UGH! timespec is biarch incompatible. See
+	 * Documentation/connector/process_events.txt if you're going to listen
+	 * for process events in userspace.
+	 */
+	struct timespec timestamp;
+	union process_event_data event_data;
+};
+
 #endif	/* CN_PROC_H */

--

#4 lore raw

Re: [RFC][PATCH 3/3] Process events biarch bug: New process events connector value

Quoted 6 lines · Matt Helsley

"Deprecate" existing Process Events connector interface and add a new one that works cleanly on biarch platforms.

Any expansion of the previous event structure would break userspace's ability to workaround the biarch incompatibility problem. Hence this patch creates a new interface and generates events (for both when necessary).

Is there a reason why the # of listeners part is removed (basically the LISTEN/IGNORE) ? and why as part of this patch ?

<snip>

Quoted 28 lines
drivers/connector/cn_proc.c +4 -4
@@ -158,16 +164,15 @@ static int cn_proc_watch_task(struct not
 			      void *t)
 {
 	struct task_struct *task = t;
 	struct cn_msg *msg;
 	struct proc_event *ev;
+	struct proc_event_deprecated *ev_old;
+	struct timespec timestamp;
 	__u8 buffer[CN_PROC_MSG_SIZE];
 	int rc = NOTIFY_OK;
 
-	if (atomic_read(&proc_event_num_listeners) < 1)
-		return rc;
-
 	msg = (struct cn_msg*)buffer;
 	ev = (struct proc_event*)msg->data;
 	switch (get_watch_event(val)) {
 	case WATCH_TASK_CLONE:
 		proc_fork_connector(task, ev);
@@ -189,16 +194,26 @@ static int cn_proc_watch_task(struct not
 		break;
 	}
 	if (rc != NOTIFY_OK)
 		return rc;
 	get_seq(&msg->seq, &ev->cpu);
-	ktime_get_ts(&ev->timestamp); /* get high res monotonic timestamp */
+	ktime_get_ts(&timestamp); /* get high res monotonic timestamp */
+	ev->timestamp_ns = ((__u64)timestamp.tv_sec*(__u64)NSEC_PER_SEC) + (__u64)timestamp.tv_nsec;

drivers/connector/cn_proc.c static int cn_proc_watch_task(struct not · line 210

Quoted 10 lines
drivers/connector/cn_proc.c +5 -0
 	memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
 	msg->ack = 0; /* not used */
 	msg->len = sizeof(*ev);
 	cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
 	/* If cn_netlink_send() fails, drop data */
+
+	if (atomic_read(&proc_event_num_old_listeners) < 1)
+		return rc;
+	ev_old = (struct proc_event_deprecated*)msg->data;
+	msg->len = sizeof(*ev_old);

A comment saying the fields cpu, what, and ack are filled above and is valid as is would help.

Quoted 17 lines
drivers/connector/cn_proc.c +4 -2
+	memmove(&ev_old->event_data, &ev->event_data, sizeof(ev->event_data));
+	memcpy(&ev_old->timestamp, &timestamp, sizeof(timestamp));
+	cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
+	/* If cn_netlink_send() fails, drop data */
 	return rc;
 }
 
 static struct notifier_block __read_mostly cn_proc_nb = {
 	.notifier_call = cn_proc_watch_task,
@@ -211,20 +226,27 @@ static struct notifier_block __read_most
  */
 static int __init cn_proc_init(void)
 {
 	int err;
 
-	if ((err = cn_add_callback(&cn_proc_event_id, "cn_proc",
-	 			   &cn_proc_mcast_ctl))) {

drivers/connector/cn_proc.c static struct notifier_block __read_most · line 237

Quoted 10 lines
drivers/connector/cn_proc.c +5 -3
-		printk(KERN_WARNING "cn_proc failed to register\n");
-		goto out;
-	}
+	err = cn_add_callback(&cn_proc_event_deprecated_id, "cn_proc_old",
+			      &cn_proc_mcast_old_ctl);
+	if (err)
+		goto error_old;
 
 
+	err = cn_add_callback(&cn_proc_event_id, "cn_proc", NULL);

is this needed if you are not going to have the callback ?

Review static struct notifier_block __read_most · line 239

Quoted 2 lines
(quoted diff) +2 -0
+	if (err)
+		goto error;

should not try to cn_del_callback(&cn_proc_event_id) ?! (goto error_old; perhaps)

Quoted 16 lines
drivers/connector/cn_proc.c +8 -3
 	err = register_task_watcher(&cn_proc_nb);
-	if (err != 0)
-		cn_del_callback(&cn_proc_event_id);
-out:
+	if (err)
+		goto error;
+	return err;
+error:
+	cn_del_callback(&cn_proc_event_id);
+error_old:
+	cn_del_callback(&cn_proc_event_deprecated_id);
+	printk(KERN_WARNING "cn_proc failed to register\n");
 	return err;
 }
 

<snip>

Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#5 lore raw

Re: [RFC][PATCH 3/3] Process events biarch bug: New process events connector value

Quoted 10 lines · Chandra Seetharaman
Quoted 6 lines · Matt Helsley

"Deprecate" existing Process Events connector interface and add a new one that works cleanly on biarch platforms.

Any expansion of the previous event structure would break userspace's ability to workaround the biarch incompatibility problem. Hence this patch creates a new interface and generates events (for both when necessary).

Is there a reason why the # of listeners part is removed (basically the LISTEN/IGNORE) ? and why as part of this patch ?

Michael Kerrisk had some objections to LISTEN/IGNORE and I've been
looking into making a connector function that would replace them. They exist primarily to improve performance by avoiding the memory allocation in cn_netlink_send() when there are no listeners.

Quoted 35 lines

<snip>

Quoted 33 lines
drivers/connector/cn_proc.c +4 -4
@@ -158,16 +164,15 @@ static int cn_proc_watch_task(struct not
 			      void *t)
 {
 	struct task_struct *task = t;
 	struct cn_msg *msg;
 	struct proc_event *ev;
+	struct proc_event_deprecated *ev_old;
+	struct timespec timestamp;
 	__u8 buffer[CN_PROC_MSG_SIZE];
 	int rc = NOTIFY_OK;
 
-	if (atomic_read(&proc_event_num_listeners) < 1)
-		return rc;
-
 	msg = (struct cn_msg*)buffer;
 	ev = (struct proc_event*)msg->data;
 	switch (get_watch_event(val)) {
 	case WATCH_TASK_CLONE:
 		proc_fork_connector(task, ev);
@@ -189,16 +194,26 @@ static int cn_proc_watch_task(struct not
 		break;
 	}
 	if (rc != NOTIFY_OK)
 		return rc;
 	get_seq(&msg->seq, &ev->cpu);
-	ktime_get_ts(&ev->timestamp); /* get high res monotonic timestamp */
+	ktime_get_ts(&timestamp); /* get high res monotonic timestamp */
+	ev->timestamp_ns = ((__u64)timestamp.tv_sec*(__u64)NSEC_PER_SEC) + (__u64)timestamp.tv_nsec;
 	memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
 	msg->ack = 0; /* not used */
 	msg->len = sizeof(*ev);
 	cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
 	/* If cn_netlink_send() fails, drop data */
Quoted 8 lines

drivers/connector/cn_proc.c static int cn_proc_watch_task(struct not · line 210

Quoted 5 lines
drivers/connector/cn_proc.c +5 -0
+
+	if (atomic_read(&proc_event_num_old_listeners) < 1)
+		return rc;
+	ev_old = (struct proc_event_deprecated*)msg->data;
+	msg->len = sizeof(*ev_old);

A comment saying the fields cpu, what, and ack are filled above and is valid as is would help.

OK, good idea.

Quoted 26 lines
Quoted 24 lines
drivers/connector/cn_proc.c +8 -5
+	memmove(&ev_old->event_data, &ev->event_data, sizeof(ev->event_data));
+	memcpy(&ev_old->timestamp, &timestamp, sizeof(timestamp));
+	cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
+	/* If cn_netlink_send() fails, drop data */
 	return rc;
 }
 
 static struct notifier_block __read_mostly cn_proc_nb = {
 	.notifier_call = cn_proc_watch_task,
@@ -211,20 +226,27 @@ static struct notifier_block __read_most
  */
 static int __init cn_proc_init(void)
 {
 	int err;
 
-	if ((err = cn_add_callback(&cn_proc_event_id, "cn_proc",
-	 			   &cn_proc_mcast_ctl))) {
-		printk(KERN_WARNING "cn_proc failed to register\n");
-		goto out;
-	}
+	err = cn_add_callback(&cn_proc_event_deprecated_id, "cn_proc_old",
+			      &cn_proc_mcast_old_ctl);
+	if (err)
+		goto error_old;
Quoted 3 lines

drivers/connector/cn_proc.c static struct notifier_block __read_most · line 235

Quoted 1 line
drivers/connector/cn_proc.c +1 -0
+	err = cn_add_callback(&cn_proc_event_id, "cn_proc", NULL);

is this needed if you are not going to have the callback ?

I believe so. Evgeniy?

Quoted 4 lines

Review static struct notifier_block __read_most · line 237

Quoted 2 lines
(quoted diff) +2 -0
+	if (err)
+		goto error;

should not try to cn_del_callback(&cn_proc_event_id) ?! (goto error_old; perhaps)

Ack! Good catch.

Thanks,
-Matt Helsley

#6 lore raw

Re: [RFC][PATCH 3/3] Process events biarch bug: New process events connector value

Quoted 9 lines · Matt Helsley
Quoted 8 lines · Chandra Seetharaman
Quoted 6 lines · Matt Helsley

"Deprecate" existing Process Events connector interface and add a new one that works cleanly on biarch platforms.

Any expansion of the previous event structure would break userspace's ability to workaround the biarch incompatibility problem. Hence this patch creates a new interface and generates events (for both when necessary).

Quoted 7 lines
Quoted 2 lines

Is there a reason why the # of listeners part is removed (basically the LISTEN/IGNORE) ? and why as part of this patch ?

Michael Kerrisk had some objections to LISTEN/IGNORE and I've been
looking into making a connector function that would replace them. They exist primarily to improve performance by avoiding the memory allocation in cn_netlink_send() when there are no listeners.

If it not related this bug, can you please separate them.

<snip>

Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#7 lore raw

Re: [RFC][PATCH 3/3] Process events biarch bug: New process events connector value

Quoted 2 lines · Chandra Seetharaman
Quoted 1 line · Matt Helsley

On Tue, 2006-06-27 at 12:14 -0700, Chandra Seetharaman wrote:

<snip>

Quoted 11 lines
Quoted 7 lines
Quoted 2 lines

Is there a reason why the # of listeners part is removed (basically the LISTEN/IGNORE) ? and why as part of this patch ?

Michael Kerrisk had some objections to LISTEN/IGNORE and I've been
looking into making a connector function that would replace them. They exist primarily to improve performance by avoiding the memory allocation in cn_netlink_send() when there are no listeners.

If it not related this bug, can you please separate them.

<snip>

OK, I'll separate it for the next submission.

Cheers,
-Matt Helsley

#8 lore raw

Re: [RFC][PATCH 3/3] Process events biarch bug: New process events connector value

In reply to Matt Helsley
Quoted 7 lines · Matt Helsley
Quoted 2 lines

Is there a reason why the # of listeners part is removed (basically the LISTEN/IGNORE) ? and why as part of this patch ?

Michael Kerrisk had some objections to LISTEN/IGNORE and I've been
looking into making a connector function that would replace them. They exist primarily to improve performance by avoiding the memory allocation in cn_netlink_send() when there are no listeners.

Connector supports check for listeners before allocation quite long ago.

Quoted 5 lines
Quoted 3 lines

drivers/connector/cn_proc.c static struct notifier_block __read_most · line 235

Quoted 1 line
drivers/connector/cn_proc.c +1 -0
+	err = cn_add_callback(&cn_proc_event_id, "cn_proc", NULL);

is this needed if you are not going to have the callback ?

I believe so. Evgeniy?

Depending on how are you going to use it.
It is obviously required for receiving data from userspace, but if you only want to send data from kernelspace you can use cn_netlink_send() without registering callback, but in that case you must provide group number to cn_netlink_send().

Quoted 2 lines

Thanks,
-Matt Helsley

Signature · 1 line
	Evgeniy Polyakov
#9 lore raw

Re: [RFC][PATCH 3/3] Process events biarch bug: New process events connector value

Quoted 8 lines · Albert Cahalan

I haven't yet seen a good explanation of what this is or does, but I suspect it may be useful for the "top" program or for a debugger. In either case, I am a highly interested party. I maintain top as part of the procps package. People pay me to hack on debuggers.

Mind pointing me to some documentation and an explanation of why the feature was added? Is there a man page? (there should be)

There are a lot of goodies for process accounting there. One can find initial draft with detailed description of the project goals at http://lwn.net/Articles/153694/

Signature · 1 line
	Evgeniy Polyakov