Skip to contentSkip to conversation

Extract the bitmask of FDs set in select syscall

RFC PATCH Mathieu Desnoyers 3 participants 7 messages Oct 2, 2015 – Oct 8, 2015 5 messages not in the archive

lore
Share & tools
lore

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

#1 lore raw
Quoted 36 lines · ----- On Oct 2, 2015, at 7:01 PM, Julien Desfossez [email protected]…

Instead of extracting the user-space pointers of the 3 fd_set, we now extract the bitmask of the FDs in the sets (in, out, ex) in the form of an array of unsigned long (1024 FDs is the limit in the kernel).

In this example, we select in input FDs 3, 5 and 10 (0x428), it returns that one FD is ready: FD 10 (0x400).

syscall_entry_select: { n = 11,

	_fdset_in_length = 1, fdset_in = [ [0] = 0x428 ],
	_fdset_out_length = 1, fdset_out = [ [0] = 0x0 ],
	_fdset_ex_length = 0, fdset_ex = [ ],
	tvp = 0
}
syscall_exit_select: { ret = 1,
	_fdset_in_length = 1, fdset_in = [ [0] = 0x400 ],
	_fdset_out_length = 1, fdset_out = [ [0] = 0x0 ],
	_fdset_ex_length = 0, fdset_ex = [ ],
	tvp = 0
}

---
.../x86-64-syscalls-3.10.0-rc7_pointers_override.h | 56 ++++++++++++++++++++++

1 file changed, 56 insertions(+)

diff --git a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h index 702cfb5..23ffbdd 100644
---
a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h
+++
b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h

(quoted diff) +0 -0
@@ -115,6 +115,62 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe,
 	)
 )

Review SC_LTTNG_TRACEPOINT_EVENT(pipe, · line 126

Quoted 10 lines
(quoted diff) +9 -0
 
+#define OVERRIDE_64_select
+SC_LTTNG_TRACEPOINT_EVENT_CODE(select,
+	TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+		fd_set __user * exp, struct timeval * tvp),
+	TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp),
+	TP_locvar(
+		unsigned long fds_in[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_out[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_ex[__FD_SETSIZE / (8 * sizeof(long))];

I expect this to break apart on kernels with 4kB stack configuration.

How much stack does this use ? We might want to consider temporarily allocating memory for this. This is OK since we know we are in a syscall context.

Thanks,

Mathieu

Quoted 52 lines
(quoted diff) +47 -1
+		int nb_in, nb_out, nb_ex;
+	),
+	TP_code(
+		sc_inout(
+		{
+			unsigned long nr;
+			int ret;
+
+			nr = FDS_BYTES(n);
+			tp_locvar->nb_in = 0;
+			tp_locvar->nb_out = 0;
+			tp_locvar->nb_ex = 0;
+			if (inp) {
+				ret = copy_from_user(tp_locvar->fds_in, inp, nr);
+				if (ret < 0)
+					goto skip_code;
+				tp_locvar->nb_in = nr/sizeof(long);
+			}
+			if (outp) {
+				ret = copy_from_user(tp_locvar->fds_out, outp, nr);
+				if (ret < 0)
+				goto skip_code;
+				tp_locvar->nb_out = nr/sizeof(long);
+			}
+			if (exp) {
+				ret = copy_from_user(tp_locvar->fds_ex, exp, nr);
+				if (ret < 0)
+					goto skip_code;
+				tp_locvar->nb_ex = nr/sizeof(long);
+			}
+		}
+		skip_code:
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_in,
+				&tp_locvar->fds_in, unsigned long, tp_locvar->nb_in))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_out,
+				&tp_locvar->fds_out, unsigned long, tp_locvar->nb_out))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_ex,
+				&tp_locvar->fds_ex, unsigned long, tp_locvar->nb_ex))
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+	)
+)
+
 #else	/* CREATE_SYSCALL_TABLE */
 
 #define OVERRIDE_TABLE_64_clone
--

1.9.1

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

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

#3 lore raw
Quoted 51 lines · Mathieu Desnoyers
Quoted 36 lines · ----- On Oct 2, 2015, at 7:01 PM, Julien Desfossez [email protected]…

Instead of extracting the user-space pointers of the 3 fd_set, we now extract the bitmask of the FDs in the sets (in, out, ex) in the form of an array of unsigned long (1024 FDs is the limit in the kernel).

In this example, we select in input FDs 3, 5 and 10 (0x428), it returns that one FD is ready: FD 10 (0x400).

syscall_entry_select: { n = 11,

	_fdset_in_length = 1, fdset_in = [ [0] = 0x428 ],
	_fdset_out_length = 1, fdset_out = [ [0] = 0x0 ],
	_fdset_ex_length = 0, fdset_ex = [ ],
	tvp = 0
}
syscall_exit_select: { ret = 1,
	_fdset_in_length = 1, fdset_in = [ [0] = 0x400 ],
	_fdset_out_length = 1, fdset_out = [ [0] = 0x0 ],
	_fdset_ex_length = 0, fdset_ex = [ ],
	tvp = 0
}

---
.../x86-64-syscalls-3.10.0-rc7_pointers_override.h | 56 ++++++++++++++++++++++

1 file changed, 56 insertions(+)

diff --git a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h index 702cfb5..23ffbdd 100644
---
a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h
+++
b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h

(quoted diff) +0 -0
@@ -115,6 +115,62 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe,
 	)
 )

Review SC_LTTNG_TRACEPOINT_EVENT(pipe, · line 126

Quoted 10 lines
(quoted diff) +9 -0
 
+#define OVERRIDE_64_select
+SC_LTTNG_TRACEPOINT_EVENT_CODE(select,
+	TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+		fd_set __user * exp, struct timeval * tvp),
+	TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp),
+	TP_locvar(
+		unsigned long fds_in[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_out[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_ex[__FD_SETSIZE / (8 * sizeof(long))];

I expect this to break apart on kernels with 4kB stack configuration.

Quoted 3 lines

How much stack does this use ? We might want to consider temporarily allocating memory for this. This is OK since we know we are in a syscall context.

Indeed that's the main reason it is a RFC patch. __FD_SETSIZE == 1024, so it allocates 3 * 8 * (1024/(8*8)) = 384 bytes. Is it too much ?

If you prefer an alloc/free, I'll replace that.

Thanks,

Julien

Quoted 67 lines

Thanks,

Mathieu

Quoted 52 lines
(quoted diff) +47 -1
+		int nb_in, nb_out, nb_ex;
+	),
+	TP_code(
+		sc_inout(
+		{
+			unsigned long nr;
+			int ret;
+
+			nr = FDS_BYTES(n);
+			tp_locvar->nb_in = 0;
+			tp_locvar->nb_out = 0;
+			tp_locvar->nb_ex = 0;
+			if (inp) {
+				ret = copy_from_user(tp_locvar->fds_in, inp, nr);
+				if (ret < 0)
+					goto skip_code;
+				tp_locvar->nb_in = nr/sizeof(long);
+			}
+			if (outp) {
+				ret = copy_from_user(tp_locvar->fds_out, outp, nr);
+				if (ret < 0)
+				goto skip_code;
+				tp_locvar->nb_out = nr/sizeof(long);
+			}
+			if (exp) {
+				ret = copy_from_user(tp_locvar->fds_ex, exp, nr);
+				if (ret < 0)
+					goto skip_code;
+				tp_locvar->nb_ex = nr/sizeof(long);
+			}
+		}
+		skip_code:
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_in,
+				&tp_locvar->fds_in, unsigned long, tp_locvar->nb_in))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_out,
+				&tp_locvar->fds_out, unsigned long, tp_locvar->nb_out))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_ex,
+				&tp_locvar->fds_ex, unsigned long, tp_locvar->nb_ex))
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+	)
+)
+
 #else	/* CREATE_SYSCALL_TABLE */
 
 #define OVERRIDE_TABLE_64_clone
--

1.9.1

Signature · 8 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): 20151002235817.GD3571@sinkpad

#5 lore raw
Quoted 53 lines · ----- On Oct 2, 2015, at 7:58 PM, Julien Desfossez [email protected]…
Quoted 52 lines · Mathieu Desnoyers

----- On Oct 2, 2015, at 7:01 PM, Julien Desfossez [email protected]

Quoted 36 lines · wrote:

Instead of extracting the user-space pointers of the 3 fd_set, we now extract the bitmask of the FDs in the sets (in, out, ex) in the form of an array of unsigned long (1024 FDs is the limit in the kernel).

In this example, we select in input FDs 3, 5 and 10 (0x428), it returns that one FD is ready: FD 10 (0x400).

syscall_entry_select: { n = 11,

	_fdset_in_length = 1, fdset_in = [ [0] = 0x428 ],
	_fdset_out_length = 1, fdset_out = [ [0] = 0x0 ],
	_fdset_ex_length = 0, fdset_ex = [ ],
	tvp = 0
}
syscall_exit_select: { ret = 1,
	_fdset_in_length = 1, fdset_in = [ [0] = 0x400 ],
	_fdset_out_length = 1, fdset_out = [ [0] = 0x0 ],
	_fdset_ex_length = 0, fdset_ex = [ ],
	tvp = 0
}

---
.../x86-64-syscalls-3.10.0-rc7_pointers_override.h | 56 ++++++++++++++++++++++

1 file changed, 56 insertions(+)

diff --git a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h index 702cfb5..23ffbdd 100644
---
a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h
+++
b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h

(quoted diff) +0 -0
@@ -115,6 +115,62 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe,
 	)
 )

Review SC_LTTNG_TRACEPOINT_EVENT(pipe, · line 126

Quoted 10 lines
(quoted diff) +9 -0
 
+#define OVERRIDE_64_select
+SC_LTTNG_TRACEPOINT_EVENT_CODE(select,
+	TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+		fd_set __user * exp, struct timeval * tvp),
+	TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp),
+	TP_locvar(
+		unsigned long fds_in[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_out[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_ex[__FD_SETSIZE / (8 * sizeof(long))];

I expect this to break apart on kernels with 4kB stack configuration.

Quoted 8 lines
Quoted 3 lines

How much stack does this use ? We might want to consider temporarily allocating memory for this. This is OK since we know we are in a syscall context.

Indeed that's the main reason it is a RFC patch. __FD_SETSIZE == 1024, so it allocates 3 * 8 * (1024/(8*8)) = 384 bytes. Is it too much ?

If you prefer an alloc/free, I'll replace that.

The "free" is not necessarily easy to implement, because we could need to add a new "TP_code_after()" which has code to be executed after the data serialization.

384 bytes is not as bad as I initially anticipated, this could be OK, especially since we are in a syscall context, and therefore the kernel stack is nearly empty when we are called.

You might want to try it in a few loads on a kernel configured with 4k stacks, and with kernel hacking options to track stack overflow and usage, just to be on the safe side.

Thanks,

Mathieu

Quoted 73 lines

Thanks,

Julien

Quoted 67 lines

Thanks,

Mathieu

Quoted 51 lines
(quoted diff) +47 -1
+		int nb_in, nb_out, nb_ex;
+	),
+	TP_code(
+		sc_inout(
+		{
+			unsigned long nr;
+			int ret;
+
+			nr = FDS_BYTES(n);
+			tp_locvar->nb_in = 0;
+			tp_locvar->nb_out = 0;
+			tp_locvar->nb_ex = 0;
+			if (inp) {
+				ret = copy_from_user(tp_locvar->fds_in, inp, nr);
+				if (ret < 0)
+					goto skip_code;
+				tp_locvar->nb_in = nr/sizeof(long);
+			}
+			if (outp) {
+				ret = copy_from_user(tp_locvar->fds_out, outp, nr);
+				if (ret < 0)
+				goto skip_code;
+				tp_locvar->nb_out = nr/sizeof(long);
+			}
+			if (exp) {
+				ret = copy_from_user(tp_locvar->fds_ex, exp, nr);
+				if (ret < 0)
+					goto skip_code;
+				tp_locvar->nb_ex = nr/sizeof(long);
+			}
+		}
+		skip_code:
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_in,
+				&tp_locvar->fds_in, unsigned long, tp_locvar->nb_in))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_out,
+				&tp_locvar->fds_out, unsigned long, tp_locvar->nb_out))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_ex,
+				&tp_locvar->fds_ex, unsigned long, tp_locvar->nb_ex))
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+	)
+)
+
 #else	/* CREATE_SYSCALL_TABLE */
 
 #define OVERRIDE_TABLE_64_clone
--
Quoted 1 line

1.9.1

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

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

#7 lore raw
Quoted 68 lines · Mathieu Desnoyers
Quoted 53 lines · ----- On Oct 2, 2015, at 7:58 PM, Julien Desfossez [email protected]…
Quoted 52 lines · Mathieu Desnoyers

----- On Oct 2, 2015, at 7:01 PM, Julien Desfossez [email protected]

Quoted 36 lines · wrote:

Instead of extracting the user-space pointers of the 3 fd_set, we now extract the bitmask of the FDs in the sets (in, out, ex) in the form of an array of unsigned long (1024 FDs is the limit in the kernel).

In this example, we select in input FDs 3, 5 and 10 (0x428), it returns that one FD is ready: FD 10 (0x400).

syscall_entry_select: { n = 11,

	_fdset_in_length = 1, fdset_in = [ [0] = 0x428 ],
	_fdset_out_length = 1, fdset_out = [ [0] = 0x0 ],
	_fdset_ex_length = 0, fdset_ex = [ ],
	tvp = 0
}
syscall_exit_select: { ret = 1,
	_fdset_in_length = 1, fdset_in = [ [0] = 0x400 ],
	_fdset_out_length = 1, fdset_out = [ [0] = 0x0 ],
	_fdset_ex_length = 0, fdset_ex = [ ],
	tvp = 0
}

---
.../x86-64-syscalls-3.10.0-rc7_pointers_override.h | 56 ++++++++++++++++++++++

1 file changed, 56 insertions(+)

diff --git a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h index 702cfb5..23ffbdd 100644
---
a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h
+++
b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h

(quoted diff) +0 -0
@@ -115,6 +115,62 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe,
 	)
 )

Review SC_LTTNG_TRACEPOINT_EVENT(pipe, · line 126

Quoted 10 lines
(quoted diff) +9 -0
 
+#define OVERRIDE_64_select
+SC_LTTNG_TRACEPOINT_EVENT_CODE(select,
+	TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+		fd_set __user * exp, struct timeval * tvp),
+	TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp),
+	TP_locvar(
+		unsigned long fds_in[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_out[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_ex[__FD_SETSIZE / (8 * sizeof(long))];

I expect this to break apart on kernels with 4kB stack configuration.

Quoted 8 lines
Quoted 3 lines

How much stack does this use ? We might want to consider temporarily allocating memory for this. This is OK since we know we are in a syscall context.

Indeed that's the main reason it is a RFC patch. __FD_SETSIZE == 1024, so it allocates 3 * 8 * (1024/(8*8)) = 384 bytes. Is it too much ?

If you prefer an alloc/free, I'll replace that.

The "free" is not necessarily easy to implement, because we could need to add a new "TP_code_after()" which has code to be executed after the data serialization.

Quoted 7 lines

384 bytes is not as bad as I initially anticipated, this could be OK, especially since we are in a syscall context, and therefore the kernel stack is nearly empty when we are called.

You might want to try it in a few loads on a kernel configured with 4k stacks, and with kernel hacking options to track stack overflow and usage, just to be on the safe side.

I compiled it with CONFIG_FRAME_WARN=1024 and don't see any warning and I'm running it with CONFIG_CC_STACKPROTECTOR=y, no sign of trouble so far. Also, apparently it is not possible to have 4k stacks since 2.6.37 (commit dcfa726280116dd31adad37da940f542663567d0), since we start our support at 2.6.38 we are good on this side too.

Thanks,

Julien

Quoted 88 lines

Thanks,

Mathieu

Quoted 73 lines

Thanks,

Julien

Quoted 67 lines

Thanks,

Mathieu

Quoted 51 lines
(quoted diff) +47 -1
+		int nb_in, nb_out, nb_ex;
+	),
+	TP_code(
+		sc_inout(
+		{
+			unsigned long nr;
+			int ret;
+
+			nr = FDS_BYTES(n);
+			tp_locvar->nb_in = 0;
+			tp_locvar->nb_out = 0;
+			tp_locvar->nb_ex = 0;
+			if (inp) {
+				ret = copy_from_user(tp_locvar->fds_in, inp, nr);
+				if (ret < 0)
+					goto skip_code;
+				tp_locvar->nb_in = nr/sizeof(long);
+			}
+			if (outp) {
+				ret = copy_from_user(tp_locvar->fds_out, outp, nr);
+				if (ret < 0)
+				goto skip_code;
+				tp_locvar->nb_out = nr/sizeof(long);
+			}
+			if (exp) {
+				ret = copy_from_user(tp_locvar->fds_ex, exp, nr);
+				if (ret < 0)
+					goto skip_code;
+				tp_locvar->nb_ex = nr/sizeof(long);
+			}
+		}
+		skip_code:
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_in,
+				&tp_locvar->fds_in, unsigned long, tp_locvar->nb_in))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_out,
+				&tp_locvar->fds_out, unsigned long, tp_locvar->nb_out))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_ex,
+				&tp_locvar->fds_ex, unsigned long, tp_locvar->nb_ex))
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+	)
+)
+
 #else	/* CREATE_SYSCALL_TABLE */
 
 #define OVERRIDE_TABLE_64_clone
--
Quoted 1 line

1.9.1

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Signature · 8 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#8 lore raw
In reply to a message not in the archive
Quoted 20 lines · ----- On Oct 2, 2015, at 7:01 PM, Julien Desfossez [email protected]…

Instead of extracting the user-space pointers of the 3 fd_set, we now extract the bitmask of the FDs in the sets (in, out, ex) in the form of an array of unsigned long (1024 FDs is the limit in the kernel).

In this example, we select in input FDs 3, 5 and 10 (0x428), it returns that one FD is ready: FD 10 (0x400).

syscall_entry_select: { n = 11,

	_fdset_in_length = 1, fdset_in = [ [0] = 0x428 ],
	_fdset_out_length = 1, fdset_out = [ [0] = 0x0 ],
	_fdset_ex_length = 0, fdset_ex = [ ],
	tvp = 0
}
syscall_exit_select: { ret = 1,
	_fdset_in_length = 1, fdset_in = [ [0] = 0x400 ],
	_fdset_out_length = 1, fdset_out = [ [0] = 0x0 ],
	_fdset_ex_length = 0, fdset_ex = [ ],
	tvp = 0
}
Quoted 3 lines

---
.../x86-64-syscalls-3.10.0-rc7_pointers_override.h | 56 ++++++++++++++++++++++

Does it have to be a x86-64 specific override, or it could be used as an override for all architectures ?

(more below)

Quoted 25 lines
1 file changed, 56 insertions(+)

diff --git a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h index 702cfb5..23ffbdd 100644
---
a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h
+++
b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h

(quoted diff) +11 -0
@@ -115,6 +115,62 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe,
 	)
 )
 
+#define OVERRIDE_64_select
+SC_LTTNG_TRACEPOINT_EVENT_CODE(select,
+	TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+		fd_set __user * exp, struct timeval * tvp),
+	TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp),
+	TP_locvar(
+		unsigned long fds_in[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_out[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_ex[__FD_SETSIZE / (8 * sizeof(long))];
+		int nb_in, nb_out, nb_ex;
+	),

Review SC_LTTNG_TRACEPOINT_EVENT(pipe, · line 138

Quoted 10 lines
(quoted diff) +10 -0
+	TP_code(
+		sc_inout(
+		{
+			unsigned long nr;
+			int ret;
+
+			nr = FDS_BYTES(n);
+			tp_locvar->nb_in = 0;
+			tp_locvar->nb_out = 0;
+			tp_locvar->nb_ex = 0;

You could initialize them to 0 in TP_locvar (definition).

Review SC_LTTNG_TRACEPOINT_EVENT(pipe, · line 140

Quoted 2 lines
(quoted diff) +2 -0
+			if (inp) {
+				ret = copy_from_user(tp_locvar->fds_in, inp, nr);

Why use copy_from_user() here rather than get_fd_set() ?

Review SC_LTTNG_TRACEPOINT_EVENT(pipe, · line 146

Quoted 6 lines
(quoted diff) +6 -0
+				if (ret < 0)
+					goto skip_code;
+				tp_locvar->nb_in = nr/sizeof(long);
+			}
+			if (outp) {
+				ret = copy_from_user(tp_locvar->fds_out, outp, nr);

Ditto.

Review SC_LTTNG_TRACEPOINT_EVENT(pipe, · line 152

Quoted 6 lines
(quoted diff) +6 -0
+				if (ret < 0)
+				goto skip_code;
+				tp_locvar->nb_out = nr/sizeof(long);
+			}
+			if (exp) {
+				ret = copy_from_user(tp_locvar->fds_ex, exp, nr);

Ditto.

Review SC_LTTNG_TRACEPOINT_EVENT(pipe, · line 165

Quoted 13 lines
(quoted diff) +13 -0
+				if (ret < 0)
+					goto skip_code;
+				tp_locvar->nb_ex = nr/sizeof(long);
+			}
+		}
+		skip_code:
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_in,
+				&tp_locvar->fds_in, unsigned long, tp_locvar->nb_in))

If we want to make this code portable, is it really an array of unsigned long in the trace ? What is the layout on a 32-bit architecture ?

Thanks,

Mathieu

Quoted 13 lines
(quoted diff) +8 -1
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_out,
+				&tp_locvar->fds_out, unsigned long, tp_locvar->nb_out))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_ex,
+				&tp_locvar->fds_ex, unsigned long, tp_locvar->nb_ex))
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+	)
+)
+
 #else	/* CREATE_SYSCALL_TABLE */
 
 #define OVERRIDE_TABLE_64_clone
--

1.9.1

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

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

#10 lore raw
Quoted 4 lines
Quoted 1 line

.../x86-64-syscalls-3.10.0-rc7_pointers_override.h | 56 ++++++++++++++++++++++

Does it have to be a x86-64 specific override, or it could be used as an override for all architectures ?

Indeed I will move it as an override for all architectures.

Quoted 4 lines
Quoted 4 lines
(quoted diff) +4 -0
+	TP_code(
+		sc_inout(
+		{
+			unsigned long nr;
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+			int ret;
+
+			nr = FDS_BYTES(n);
+			tp_locvar->nb_in = 0;
+			tp_locvar->nb_out = 0;
+			tp_locvar->nb_ex = 0;

You could initialize them to 0 in TP_locvar (definition).

Good point.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+			if (inp) {
+				ret = copy_from_user(tp_locvar->fds_in, inp, nr);

Why use copy_from_user() here rather than get_fd_set() ?

I had a problem with the memset to 0 on error, I don't remember why, I'll try again with that.

Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_inout(ctf_sequence_hex(unsigned long, fdset_in,
+				&tp_locvar->fds_in, unsigned long, tp_locvar->nb_in))

If we want to make this code portable, is it really an array of unsigned long in the trace ? What is the layout on a 32-bit architecture ?

This way of working is what is done by select() itself. On 64-bit we have a maximum of 16 unsigned longs (to handle up to 16*8 = 1024 FDs), on 32-bit it is 32 unsigned longs (32 * 4 = 1024).

I would also prefer a way to extract a clean list of FDs instead of a bitmask and potentially waste stack space, but I don't see how without needing to allocate/free memory or have an arbitrary limit.

Thanks

Julien

#11 lore raw
In reply to a message not in the archive
Quoted 15 lines
Quoted 15 lines
(quoted diff) +15 -0
+#define OVERRIDE_64_select
+SC_LTTNG_TRACEPOINT_EVENT_CODE(select,
+	TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+		fd_set __user * exp, struct timeval * tvp),
+	TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp),
+	TP_locvar(
+		unsigned long fds_in[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_out[__FD_SETSIZE / (8 * sizeof(long))],
+			fds_ex[__FD_SETSIZE / (8 * sizeof(long))];
+		int nb_in, nb_out, nb_ex;
+	),
+	TP_code(
+		sc_inout(
+		{
+			unsigned long nr;
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+			int ret;
+
+			nr = FDS_BYTES(n);
+			tp_locvar->nb_in = 0;
+			tp_locvar->nb_out = 0;
+			tp_locvar->nb_ex = 0;

You could initialize them to 0 in TP_locvar (definition).

Hum apparently I can't do anything other than just declaring variables in the TP_locvar section. Assigning a value to it (at declare time or afterward) generates a lot of errors.

Julien