Commit 822cfbff authored by Chandra Seetharaman's avatar Chandra Seetharaman Committed by Linus Torvalds

[PATCH] Process Events: Fix biarch compatibility issue. use __u64 timestamp

Events sent by Process Events Connector from a 64-bit kernel are not binary
compatible with a 32-bit userspace program because the "timestamp" field
(struct timespec) is not arch independent.  This affects the fields that
follow "timestamp" as they will be be off by 8 bytes.

This is a problem for 32-bit userspace programs running with 64-bit kernels
on ppc64, s390, x86-64..  any "biarch" system.

Matt had submitted a different solution to lkml as an RFC earlier.  We have
since switched to a solution recommended by Evgeniy Polyakov.

This patch fixes the problem by changing the timestamp to be a __u64, which
stores the number of nanoseconds.

Tested on a x86_64 system with both 32 bit application and 64 bit
application and on a i386 system.
Signed-off-by: default avatarChandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: default avatarMatt Helsley <matthltc@us.ibm.com>
Cc: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Cc: Guillaume Thouvenin <guillaume.thouvenin@bull.net>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 2ccb48eb
...@@ -51,6 +51,7 @@ void proc_fork_connector(struct task_struct *task) ...@@ -51,6 +51,7 @@ void proc_fork_connector(struct task_struct *task)
struct cn_msg *msg; struct cn_msg *msg;
struct proc_event *ev; struct proc_event *ev;
__u8 buffer[CN_PROC_MSG_SIZE]; __u8 buffer[CN_PROC_MSG_SIZE];
struct timespec ts;
if (atomic_read(&proc_event_num_listeners) < 1) if (atomic_read(&proc_event_num_listeners) < 1)
return; return;
...@@ -58,7 +59,8 @@ void proc_fork_connector(struct task_struct *task) ...@@ -58,7 +59,8 @@ void proc_fork_connector(struct task_struct *task)
msg = (struct cn_msg*)buffer; msg = (struct cn_msg*)buffer;
ev = (struct proc_event*)msg->data; ev = (struct proc_event*)msg->data;
get_seq(&msg->seq, &ev->cpu); get_seq(&msg->seq, &ev->cpu);
ktime_get_ts(&ev->timestamp); /* get high res monotonic timestamp */ ktime_get_ts(&ts); /* get high res monotonic timestamp */
ev->timestamp_ns = timespec_to_ns(&ts);
ev->what = PROC_EVENT_FORK; ev->what = PROC_EVENT_FORK;
ev->event_data.fork.parent_pid = task->real_parent->pid; ev->event_data.fork.parent_pid = task->real_parent->pid;
ev->event_data.fork.parent_tgid = task->real_parent->tgid; ev->event_data.fork.parent_tgid = task->real_parent->tgid;
...@@ -76,6 +78,7 @@ void proc_exec_connector(struct task_struct *task) ...@@ -76,6 +78,7 @@ void proc_exec_connector(struct task_struct *task)
{ {
struct cn_msg *msg; struct cn_msg *msg;
struct proc_event *ev; struct proc_event *ev;
struct timespec ts;
__u8 buffer[CN_PROC_MSG_SIZE]; __u8 buffer[CN_PROC_MSG_SIZE];
if (atomic_read(&proc_event_num_listeners) < 1) if (atomic_read(&proc_event_num_listeners) < 1)
...@@ -84,7 +87,8 @@ void proc_exec_connector(struct task_struct *task) ...@@ -84,7 +87,8 @@ void proc_exec_connector(struct task_struct *task)
msg = (struct cn_msg*)buffer; msg = (struct cn_msg*)buffer;
ev = (struct proc_event*)msg->data; ev = (struct proc_event*)msg->data;
get_seq(&msg->seq, &ev->cpu); get_seq(&msg->seq, &ev->cpu);
ktime_get_ts(&ev->timestamp); ktime_get_ts(&ts); /* get high res monotonic timestamp */
ev->timestamp_ns = timespec_to_ns(&ts);
ev->what = PROC_EVENT_EXEC; ev->what = PROC_EVENT_EXEC;
ev->event_data.exec.process_pid = task->pid; ev->event_data.exec.process_pid = task->pid;
ev->event_data.exec.process_tgid = task->tgid; ev->event_data.exec.process_tgid = task->tgid;
...@@ -100,6 +104,7 @@ void proc_id_connector(struct task_struct *task, int which_id) ...@@ -100,6 +104,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
struct cn_msg *msg; struct cn_msg *msg;
struct proc_event *ev; struct proc_event *ev;
__u8 buffer[CN_PROC_MSG_SIZE]; __u8 buffer[CN_PROC_MSG_SIZE];
struct timespec ts;
if (atomic_read(&proc_event_num_listeners) < 1) if (atomic_read(&proc_event_num_listeners) < 1)
return; return;
...@@ -118,7 +123,8 @@ void proc_id_connector(struct task_struct *task, int which_id) ...@@ -118,7 +123,8 @@ void proc_id_connector(struct task_struct *task, int which_id)
} else } else
return; return;
get_seq(&msg->seq, &ev->cpu); get_seq(&msg->seq, &ev->cpu);
ktime_get_ts(&ev->timestamp); ktime_get_ts(&ts); /* get high res monotonic timestamp */
ev->timestamp_ns = timespec_to_ns(&ts);
memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
msg->ack = 0; /* not used */ msg->ack = 0; /* not used */
...@@ -131,6 +137,7 @@ void proc_exit_connector(struct task_struct *task) ...@@ -131,6 +137,7 @@ void proc_exit_connector(struct task_struct *task)
struct cn_msg *msg; struct cn_msg *msg;
struct proc_event *ev; struct proc_event *ev;
__u8 buffer[CN_PROC_MSG_SIZE]; __u8 buffer[CN_PROC_MSG_SIZE];
struct timespec ts;
if (atomic_read(&proc_event_num_listeners) < 1) if (atomic_read(&proc_event_num_listeners) < 1)
return; return;
...@@ -138,7 +145,8 @@ void proc_exit_connector(struct task_struct *task) ...@@ -138,7 +145,8 @@ void proc_exit_connector(struct task_struct *task)
msg = (struct cn_msg*)buffer; msg = (struct cn_msg*)buffer;
ev = (struct proc_event*)msg->data; ev = (struct proc_event*)msg->data;
get_seq(&msg->seq, &ev->cpu); get_seq(&msg->seq, &ev->cpu);
ktime_get_ts(&ev->timestamp); ktime_get_ts(&ts); /* get high res monotonic timestamp */
ev->timestamp_ns = timespec_to_ns(&ts);
ev->what = PROC_EVENT_EXIT; ev->what = PROC_EVENT_EXIT;
ev->event_data.exit.process_pid = task->pid; ev->event_data.exit.process_pid = task->pid;
ev->event_data.exit.process_tgid = task->tgid; ev->event_data.exit.process_tgid = task->tgid;
...@@ -164,6 +172,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack) ...@@ -164,6 +172,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
struct cn_msg *msg; struct cn_msg *msg;
struct proc_event *ev; struct proc_event *ev;
__u8 buffer[CN_PROC_MSG_SIZE]; __u8 buffer[CN_PROC_MSG_SIZE];
struct timespec ts;
if (atomic_read(&proc_event_num_listeners) < 1) if (atomic_read(&proc_event_num_listeners) < 1)
return; return;
...@@ -171,7 +180,8 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack) ...@@ -171,7 +180,8 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
msg = (struct cn_msg*)buffer; msg = (struct cn_msg*)buffer;
ev = (struct proc_event*)msg->data; ev = (struct proc_event*)msg->data;
msg->seq = rcvd_seq; msg->seq = rcvd_seq;
ktime_get_ts(&ev->timestamp); ktime_get_ts(&ts); /* get high res monotonic timestamp */
ev->timestamp_ns = timespec_to_ns(&ts);
ev->cpu = -1; ev->cpu = -1;
ev->what = PROC_EVENT_NONE; ev->what = PROC_EVENT_NONE;
ev->event_data.ack.err = err; ev->event_data.ack.err = err;
......
...@@ -57,7 +57,8 @@ struct proc_event { ...@@ -57,7 +57,8 @@ struct proc_event {
PROC_EVENT_EXIT = 0x80000000 PROC_EVENT_EXIT = 0x80000000
} what; } what;
__u32 cpu; __u32 cpu;
struct timespec timestamp; __u64 __attribute__((aligned(8))) timestamp_ns;
/* Number of nano seconds since system boot */
union { /* must be last field of proc_event struct */ union { /* must be last field of proc_event struct */
struct { struct {
__u32 err; __u32 err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment